File: errormessage.cpp

package info (click to toggle)
tipp10 3.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,984 kB
  • sloc: cpp: 8,343; xml: 70; ansic: 60; makefile: 11
file content (254 lines) | stat: -rw-r--r-- 10,148 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
Copyright (c) 2006-2009, Tom Thielicke IT Solutions

SPDX-License-Identifier: GPL-2.0-only
*/

/****************************************************************
**
** Implementation of the ErrorMessage class
** File name: errormessage.cpp
**
****************************************************************/

#include <QMessageBox>

#include "def/defines.h"
#include "errormessage.h"

ErrorMessage::ErrorMessage(QWidget* parent)
    : QWidget(parent)
{
}

void ErrorMessage::showMessage(
    Error errorNo, Type errorType, Cancel cancelProcedure, QString addon)
{
    QString message;
    // First generate the error text
    message = getErrorText(errorNo);
    // If exist, append an additional text
    if (addon != "") {
        message.append("\n" + addon);
    }
    /*if (cancelProcedure != ErrorMessage::Cancel::No) {
            // Append fix text
            message.append(tr("\n\nBitte melden Sie den Fehler "
                    "(Fehlernummer) und die Umstaende unter denen er aufgetreten
    " "ist im Internet unter: ") + t10::app_url
                    + tr("\nSo kann ") + t10::app_name
                    + tr(" verbessert werden. Danke!"));
    }*/

    // Append, what the program do now
    message.append("\n\n" + getCancelText(cancelProcedure));

    // Choose a message style
    switch (errorType) {
    case Type::Info:
        QMessageBox::information(nullptr, t10::app_name, message);
        break;
    case Type::Warning:
        QMessageBox::warning(nullptr, t10::app_name, message);
        break;
    case Type::Critical:
        QMessageBox::critical(nullptr, t10::app_name, message);
        break;
    }
}

QString ErrorMessage::getCancelText(Cancel type)
{
    QString cancelText = "";
    switch (type) {
    case Cancel::No:
        cancelText = "";
        break;
    case Cancel::Operation:
        cancelText = tr("The process will be aborted.");
        break;
    case Cancel::Update:
        cancelText = tr("The update will be aborted.");
        break;
    case Cancel::Program:
        cancelText = tr("The program will be aborted.");
        break;
    }
    return cancelText;
}

QString ErrorMessage::getErrorText(Error number)
{
    QString errorText = "";
    switch (number) {
    case Error::logo_pic:
        errorText = tr("Cannot load the program logo.");
        break;
    case Error::key_pic:
        errorText = tr("Cannot load the keyboard bitmap.");
        break;
    case Error::ticker_pic:
        errorText = tr("Cannot load the timer background.");
        break;
    case Error::status_pic:
        errorText = tr("Cannot load the status bar background.");
        break;

    case Error::sql_db_app_exist:
        errorText
            = tr("Cannot find the database %1. The file could not be "
                 "imported.\nPlease check whether it is a readable text file.")
                  .arg(t10::app_db);
        break;
    case Error::sql_db_user_exist:
        errorText = tr("Cannot find the database in the specified "
                       "directory.\nTIPP10 is trying to create a new, empty "
                       "database in the specified directory.\n");
        break;
    case Error::sql_db_app_copy:
        errorText = tr(
            "Cannot create the user database in your AppData directory. There "
            "may be no permission to write.\nTIPP10 is trying to use the "
            "original database in the program directory.\n");
        break;
    case Error::sql_db_user_copy:
        errorText = tr("Cannot create the user database in the specified "
                       "directory. There may be no directory or no permission "
                       "to write.\nTIPP10 is trying to create a new, empty "
                       "database in your AppData directory.\n");
        break;
    case Error::sql_connection:
        errorText = tr("Connection to the database failed.");
        break;

    case Error::db_version_exist:
        errorText = tr("Connection to the database failed.");
        break;
    case Error::user_lessons_flush:
        errorText = tr("The user table with lesson data  cannot be "
                       "emptied.\nSQL statement failed.");
        break;
    case Error::user_errors_flush:
        errorText = tr("The user table with error data cannot be emptied.\nSQL "
                       "statement failed.");
        break;
    case Error::lessons_exist:
        errorText = tr("No lessons exist.");
        break;
    case Error::lessons_selected:
        errorText = tr("No lesson selected.\nPlease select a lesson.");
        break;
    case Error::lessons_creation:
        errorText = tr("Cannot create the lesson.\nSQL statement failed.");
        break;
    case Error::lessons_update:
        errorText
            = tr("The lesson could not be updated because there is no\naccess "
                 "to the database.\n\nIf this problem only occurred after the "
                 "software had been\nrunning smoothly for some time, the "
                 "database is expected\nto have been damaged (eg crashing of "
                 "the computer).\nTo check whether or not the database has "
                 "been damaged,\nyou can rename the database file \"%1\" and "
                 "restart the software (it\nwill create a new, empty database "
                 "automatically).\n\nIf this problem occurred after the "
                 "first time the software was\nstarted, please check the write "
                 "privileges on the database\nfile.")
                  .arg(t10::app_user_db);
        break;
    case Error::user_errors_refresh:
        errorText
            = tr("The user typing errors could not be updated because\nthere "
                 "is no access to the database.\n\nIf this problem only "
                 "occurred after the software had been\nrunning smoothly for "
                 "some time, the database is expected\nto have been damaged "
                 "(eg crashing of the computer).\nTo check whether or not the "
                 "database has been damaged,\nyou can rename the database file "
                 "\"%1\" and restart the software (it\nwill create a new, "
                 "empty database automatically).\n\nIf this problem occurred "
                 "after the first time the software was\nstarted, please check "
                 "the write privileges on the database\nfile.")
                  .arg(t10::app_user_db);
        break;
    case Error::user_lessons_refresh:
        errorText
            = tr("The user lesson data could not be updated because\nthere is "
                 "no access to the database.\n\nIf this problem only occurred "
                 "after the software had been\nrunning smoothly for some time, "
                 "the database is expected\nto have been damaged (eg crashing "
                 "of the computer).\nTo check whether or not the database has "
                 "been damaged,\nyou can rename the database file \"%1\" and "
                 "restart the software (it\nwill create a new, empty database "
                 "automatically).\n\nIf this problem occurred after the "
                 "first time the software was\nstarted, please check the write "
                 "privileges on the database\nfile.")
                  .arg(t10::app_user_db);
        break;
    case Error::user_lesson_add:
        errorText = tr("Cannot save the lesson.\nSQL statement failed.");
        break;
    case Error::user_lesson_get:
        errorText = tr("Cannot retrieve the lesson.\nSQL statement failed.");
        break;
    case Error::user_lesson_analyze:
        errorText = tr("Cannot analyze the lesson.\nSQL statement failed.");
        break;
    case Error::user_import_read:
        errorText = tr("The file could not be imported.\nPlease check whether "
                       "it is a readable text file.\n");
        break;
    case Error::user_import_empty:
        errorText
            = tr("The file could not be imported because it is empty.\nPlease "
                 "check whether it is a readable text file with content.\n");
        break;
    case Error::user_download_execution:
        errorText
            = tr("The file could not be imported.\nPlease check the spelling "
                 "of the web address;\nit must be a valid URL and a readable "
                 "text file.\nPlease also check your internet connection.");
        break;
    case Error::user_export_write:
        errorText = tr("The file could not be exported.\nPlease check to see "
                       "whether it is a writable text file.\n");
        break;
    case Error::temp_file_creation:
        errorText = tr("Cannot create temporary file.");
        break;
    case Error::update_execution:
        errorText = tr("Cannot execute the update process.\nPlease check your "
                       "internet connection and proxy settings.");
        break;
    case Error::online_version_readable:
        errorText = tr("Cannot read the online update version.");
        break;
    case Error::db_version_readable:
        errorText = tr("Cannot read the database update version.");
        break;
    case Error::update_sql_execution:
        errorText = tr("Cannot execute the SQL statement.");
        break;
    case Error::error_defines_exist:
        errorText = tr("Cannot find typing mistake definitions.");
        break;
    case Error::lesson_content_exist:
        errorText = tr("Cannot create temporary file.\nUpdate failed.");
        break;
    case Error::analyze_table_creation:
        errorText = tr("Cannot create analysis table.");
        break;
    case Error::analyze_index_creation:
        errorText = tr("Cannot create analysis index.");
        break;
    case Error::analyze_table_fill:
        errorText = tr("Cannot fill analysis table with values.");
        break;

    default:
        errorText = tr("An error has occured.");
        break;
    }
    // Append the error number
    errorText.append(tr("\n(Error number: %1)\n")
                         .arg(QString::number(static_cast<int>(number))));
    return errorText;
}