Mercurial > hg > syntilista
annotate src/main.cpp @ 240:14c6a4d40232
Move settings struct definition to main.h
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 08 May 2018 00:18:34 +0300 |
parents | 9626307f3eeb |
children | ea85ff97a01c |
rev | line source |
---|---|
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
140
783417da6da3
Change the program description to english etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
2 // Syntilista - debt list/management database program |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // Programmed and designed by Matti Hämäläinen <ccr@tnsp.org> |
217 | 4 // (C) Copyright 2017-2018 Tecnic Software productions (TNSP) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // |
57 | 6 // Distributed under 3-clause BSD style license, refer to |
7 // included file "COPYING" for exact terms. | |
8 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include <QApplication> |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include <QMessageBox> |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include <QSettings> |
129
f6685c2eb75d
Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
12 #include <QStandardPaths> |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #include "main.h" |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include "ui_mainwindow.h" |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
15 #include "ui_aboutwindow.h" |
228
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
16 #include "runguard.h" |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
17 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
240
14c6a4d40232
Move settings struct definition to main.h
Matti Hamalainen <ccr@tnsp.org>
parents:
239
diff
changeset
|
19 |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
20 // |
240
14c6a4d40232
Move settings struct definition to main.h
Matti Hamalainen <ccr@tnsp.org>
parents:
239
diff
changeset
|
21 // Global struct for settings |
14c6a4d40232
Move settings struct definition to main.h
Matti Hamalainen <ccr@tnsp.org>
parents:
239
diff
changeset
|
22 // |
14c6a4d40232
Move settings struct definition to main.h
Matti Hamalainen <ccr@tnsp.org>
parents:
239
diff
changeset
|
23 SLAppSettings settings; |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
24 |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
25 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
26 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
27 // SQL schema / table definitions |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
28 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
29 typedef struct |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
30 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
31 QString name; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
32 QString schema; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
33 } SLSQLSchemaDef; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
34 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
35 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
36 static const SLSQLSchemaDef slSQLSchemaData[] = |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
37 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
38 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
39 QStringLiteral("people"), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
40 QStringLiteral( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
41 "id INTEGER PRIMARY KEY," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
42 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
43 "first_name VARCHAR(" SL_STR(SQL_LEN_FIRST_NAME) ") NOT NULL," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
44 "last_name VARCHAR(" SL_STR(SQL_LEN_LAST_NAME) ") NOT NULL," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
45 "extra_info VARCHAR(" SL_STR(SQL_LEN_EXTRA_INFO) ")," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
46 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
47 "added DATETIME NOT NULL," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
48 "updated DATETIME NOT NULL" |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
49 ) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
50 }, |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
51 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
52 QStringLiteral("transactions"), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
53 QStringLiteral( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
54 "id INTEGER PRIMARY KEY, " |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
55 "person INT NOT NULL, " |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
56 "value REAL, " |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
57 "added DATETIME NOT NULL" |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
58 ) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
59 }, |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
60 }; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
61 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
62 static const int nslSQLSchemaData = sizeof(slSQLSchemaData) / sizeof(slSQLSchemaData[0]); |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
63 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
83 | 65 // |
66 // Convert QString to a double value, replacing comma | |
67 // | |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
68 double slMoneyStrToValue(const QString &str) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 QString str2 = str; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 return str2.replace(",", ".").toDouble(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
83 | 75 // |
76 // Convert double value to formatted QString | |
77 // | |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
78 QString slMoneyValueToStr(double val) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 return QStringLiteral("%1").arg(val, 1, 'f', 2); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 |
205
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
84 QString slMoneyValueToStrSign(double val) |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
85 { |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
86 return QStringLiteral("%1%2"). |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
87 arg(val > 0 ? "+" : ""). |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
88 arg(val, 1, 'f', 2); |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
89 } |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
90 |
3d21d789b40b
Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
91 |
83 | 92 // |
93 // Trim and cleanup given QString (removing double whitespace etc.) | |
94 // | |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
95 QString slCleanupStr(const QString &str) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 return str.simplified().trimmed(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
84
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
101 // |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
102 // Manipulate given QDateTime value to get desired |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
103 // correct timestamp. |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
104 // |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
105 const QDateTime slDateTimeToLocal(const QDateTime &val) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 QDateTime tmp = val; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 tmp.setOffsetFromUtc(0); |
84
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
109 return tmp.toLocalTime(); |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
110 } |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
111 |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
112 |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
113 // |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
114 // Return a string representation of given QDateTime |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
115 // converted to local time. |
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
116 // |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
117 const QString slDateTimeToStr(const QDateTime &val) |
84
00db2c012481
Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
83
diff
changeset
|
118 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
119 return slDateTimeToLocal(val).toString(QStringLiteral("yyyy-MM-dd hh:mm")); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 |
83 | 123 // |
128 | 124 // Error logging |
125 // | |
133 | 126 void slLog(const QString &mtype, const QString &msg) |
128 | 127 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
128 QString filename = settings.dataPath + QDir::separator() + APP_LOG_FILE; |
128 | 129 QFile fh(filename); |
129
f6685c2eb75d
Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
130 if (fh.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) |
128 | 131 { |
132 QTextStream out(&fh); | |
133 out << | |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
134 slDateTimeToLocal(QDateTime::currentDateTimeUtc()). |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
135 toString(QStringLiteral("yyyy-MM-dd hh:mm:ss")) |
133 | 136 << " [" << mtype << "]: " << msg << "\n"; |
128 | 137 fh.close(); |
138 } | |
139 } | |
140 | |
141 | |
142 // | |
143 // Display an error dialog with given title and message | |
144 // | |
200 | 145 int slErrorMsg(const QString &title, const QString &msg) |
128 | 146 { |
147 QMessageBox dlg; | |
148 | |
133 | 149 slLog("ERROR", msg); |
128 | 150 |
151 dlg.setText(title); | |
152 dlg.setInformativeText(msg); | |
153 dlg.setTextFormat(Qt::RichText); | |
154 dlg.setIcon(QMessageBox::Critical); | |
155 dlg.setStandardButtons(QMessageBox::Ok); | |
156 dlg.setDefaultButton(QMessageBox::Ok); | |
157 | |
158 return dlg.exec(); | |
159 } | |
160 | |
161 | |
162 // | |
83 | 163 // Check if an SQL error has occured (for given QSqlError) and |
164 // report it to stdout if so. Return "false" if error has occured, | |
165 // true otherwise. | |
166 // | |
157
325e7590f93e
Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
167 bool slCheckAndReportSQLError(const QString where, const QSqlError &err, bool report) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 if (err.isValid()) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 { |
156 | 171 // If an error has occured, log it |
133 | 172 slLog("ERROR", |
173 QStringLiteral("SQL %1: %2"). | |
126 | 174 arg(where).arg(err.text())); |
4 | 175 return false; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 else |
126 | 178 { |
156 | 179 // If no error, but event reporting requested, log it |
126 | 180 if (report) |
133 | 181 { |
182 slLog("NOTE", | |
183 QStringLiteral("SQL OK %1").arg(where)); | |
184 } | |
4 | 185 return true; |
126 | 186 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
190 void SLPersonInfo::dump() |
5 | 191 { |
126 | 192 printf( |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
193 "SLPersonInfo() #%lld '%s %s' (added=%s, updated=%s, balance %1.2f)\n#%s#\n", |
5 | 194 id, |
195 firstName.toUtf8().constData(), | |
196 lastName.toUtf8().constData(), | |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
197 slDateTimeToStr(added).toUtf8().constData(), |
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
198 slDateTimeToStr(updated).toUtf8().constData(), |
5 | 199 balance, |
200 extraInfo.toUtf8().constData()); | |
201 } | |
202 | |
203 | |
204 // | |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
205 // Get SLPersonInfo record from SQL query object |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
206 // |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
207 void slGetPersonInfoRec(QSqlQuery &query, SLPersonInfo &info) |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
208 { |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
209 info.id = query.value(0).toInt(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
210 info.firstName = query.value(1).toString(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
211 info.lastName = query.value(2).toString(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
212 info.extraInfo = query.value(3).toString(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
213 info.added = query.value(4).toDateTime(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
214 info.updated = query.value(5).toDateTime(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
215 info.balance = query.value(6).toDouble(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
216 } |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
217 |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
218 |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
219 // |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
220 // Get SLPersonInfo record from SQL database for specified person ID # |
5 | 221 // |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
222 bool slGetPersonInfo(qint64 id, SLPersonInfo &info) |
5 | 223 { |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
224 QSqlQuery query; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
225 query.prepare(QStringLiteral( |
5 | 226 "SELECT id,first_name,last_name,extra_info,added,updated, " |
107
8ceaafde9b52
Use total() instead of sum() in the SQL queries for better accuracy.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
227 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance " |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
228 "FROM people WHERE id=?")); |
5 | 229 |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
230 query.addBindValue(id); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
231 query.exec(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
232 if (!query.next()) |
5 | 233 return false; |
234 | |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
235 slGetPersonInfoRec(query, info); |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
236 query.finish(); |
5 | 237 return true; |
238 } | |
239 | |
240 | |
156 | 241 // |
242 // Set stylesheet for given QWidget, and scale fonts etc. | |
243 // for some elements based on current UI scale factor. | |
244 // | |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
245 void slSetCommonStyleSheet(QWidget *widget) |
32 | 246 { |
40 | 247 // Clamp scale value |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
248 if (settings.uiScale < 0.5f) |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
249 settings.uiScale = 0.5f; |
103 | 250 |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
251 if (settings.uiScale > 3.0f) |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
252 settings.uiScale = 3.0f; |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
253 |
40 | 254 // Set the stylesheet |
32 | 255 widget->setStyleSheet( |
256 QStringLiteral( | |
257 "* { font-size: %1pt; }" | |
258 "QPushButton { font-size: %2pt; padding: 0.25em; }" | |
40 | 259 "#button_AddDebt[enabled='true'] { font-size: %3pt; background-color: #900; color: white; }" |
260 "#button_PayDebt[enabled='true'] { font-size: %3pt; background-color: #090; color: white; }" | |
261 "#button_PayFullDebt[enabled='true'] { background-color: #060; color: white; }" | |
262 | |
263 "#button_AddDebt[enabled='false'] { font-size: %3pt; background-color: #622; color: black; }" | |
264 "#button_PayDebt[enabled='false'] { font-size: %3pt; background-color: #262; color: black; }" | |
265 "#button_PayFullDebt[enabled='false'] { background-color: #131; color: black; }" | |
266 | |
32 | 267 "#label_PersonName { font-size: %5pt; font-weight: bold; }" |
268 "#label_BalanceValue { font-size: %4pt; font-weight: bold; }" | |
269 "#label_EUR { font-size: %4pt; font-weight: bold; }" | |
270 "#edit_Amount { font-size: %4pt; margin: 0.5em; padding: 0.5em; }" | |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
271 "#label_NumPeopleValue { color: green; }" |
32 | 272 ). |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
273 arg(12 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
274 arg(14 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
275 arg(16 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
276 arg(18 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
277 arg(20 * settings.uiScale) |
32 | 278 ); |
279 } | |
280 | |
281 | |
156 | 282 // |
283 // Main program begins | |
284 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 int main(int argc, char *argv[]) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 QApplication sapp(argc, argv); |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
288 QSettings tmpst(APP_VENDOR, APP_ID); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
289 |
228
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
290 // Check for multiple instances |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
291 RunGuard guard(QStringLiteral(APP_VENDOR) + QStringLiteral(APP_ID)); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
292 if (!guard.tryToRun()) |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
293 { |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
294 slErrorMsg( |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
295 QObject::tr("Virhe!"), |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
296 QObject::tr( |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
297 "Syntilista-sovellus on jo käynnissä. Sulje tämä ikkuna ja " |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
298 "etsi ajossa oleva Syntilista-sovellus tehtäväpalkista." |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
299 ) |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
300 ); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
301 return 1; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
302 } |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
303 |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
304 // Read configuration settings |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
305 settings.uiPos = tmpst.value("pos", QPoint(100, 100)).toPoint(); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
306 settings.uiSize = tmpst.value("size", QSize(1000, 600)).toSize(); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
307 settings.uiScale = tmpst.value("scale", 1.0f).toDouble(); |
151
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
308 settings.dbBackupMode = tmpst.value("dbBackupMode", BACKUP_NONE).toInt(); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
309 settings.dbBackupURL = tmpst.value("dbBackupURL", QString()).toString(); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
310 settings.dbBackupSecret = tmpst.value("dbBackupSecret", QString()).toString(); |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
311 settings.dbLastBackup = tmpst.value("dbLastBackup", QDateTime::fromSecsSinceEpoch(0)).toDateTime(); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
312 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
313 // Check commandline arguments for configuring backup settings |
169
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
314 if (argc >= 2 && strcmp(argv[1], "config") == 0) |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
315 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
316 settings.dbBackupMode = QString(argv[2]).toInt(); |
169
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
317 if (argc >= 5) |
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
318 { |
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
319 settings.dbBackupURL = QString(argv[3]); |
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
320 settings.dbBackupSecret = QString(argv[4]); |
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
321 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
322 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 |
148
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
324 // Also possibility of resetting the UI settings |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
325 if (argc >= 2 && strcmp(argv[1], "reset") == 0) |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
326 { |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
327 settings.uiPos = QPoint(100, 100); |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
328 settings.uiSize = QSize(1000, 600); |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
329 settings.uiScale = 1.0f; |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
330 } |
665421937ec8
Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
331 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 // |
170
7edbfb2c0089
Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents:
169
diff
changeset
|
333 // Create logfile and data directory if they do not already exist |
129
f6685c2eb75d
Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
334 // |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
335 settings.dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
336 QDir path(settings.dataPath); |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
337 if (!path.exists(settings.dataPath)) |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
338 path.mkpath(settings.dataPath); |
129
f6685c2eb75d
Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
339 |
f6685c2eb75d
Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
340 // |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 // Initialize / open SQL database connection |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 // |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
344 db.setDatabaseName(settings.dataPath + QDir::separator() + APP_SQLITE_FILE); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 if (!db.open()) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
348 slErrorMsg( |
9 | 349 QObject::tr("Tietokantaa ei voitu avata"), |
18 | 350 QObject::tr("Yhteyttä SQL-tietokantaan ei saatu.<br><br>Virhe: %1<br><br>"). |
8 | 351 arg(db.lastError().text()) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 ); |
8 | 353 return 1; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
354 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
356 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
357 // Create tables |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
358 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
359 for (int ntable = 0; ntable < nslSQLSchemaData; ntable++) |
44
8fb2230fe860
Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
360 { |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
361 const SLSQLSchemaDef &table = slSQLSchemaData[ntable]; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
362 if (!db.tables().contains(table.name)) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
363 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
364 QSqlQuery query; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
365 QString sql = |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
366 QStringLiteral("CREATE TABLE %1 (%2)"). |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
367 arg(table.name). |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
368 arg(table.schema); |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
369 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
370 query.exec(sql); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
371 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
372 if (!slCheckAndReportSQLError( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
373 QStringLiteral("CREATE TABLE %1").arg(table.name), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
374 query.lastError(), true)) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
375 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
376 slErrorMsg( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
377 QObject::tr("Tietokantataulua ei voitu luoda"), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
378 QObject::tr("Virhe: %1<br><br>"). |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
379 arg(db.lastError().text()) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
380 ); |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
381 return 1; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
382 } |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
383 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
384 query.finish(); |
170
7edbfb2c0089
Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents:
169
diff
changeset
|
385 } |
44
8fb2230fe860
Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
386 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
388 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
389 // Execute main app |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
390 // |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
391 SyntilistaMainWindow swin; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
392 swin.show(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
393 return sapp.exec(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
395 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 // |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 // Main application window code |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
399 // |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 SyntilistaMainWindow::SyntilistaMainWindow(QWidget *parent) : |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
401 QMainWindow(parent), |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
402 ui(new Ui::SyntilistaMainWindow) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
403 { |
10 | 404 // Setup UI |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
405 ui->setupUi(this); |
47 | 406 |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
407 // Restore window size and position |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
408 move(settings.uiPos); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
409 resize(settings.uiSize); |
47 | 410 |
122 | 411 // Setup application icon and window title |
203 | 412 setWindowIcon(QIcon(QPixmap(":/icon"))); |
64
73fd86778014
Version number display etc. changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
413 setWindowTitle(tr("%1 versio %3"). |
39 | 414 arg(tr(APP_NAME)). |
204
fd115ca75ce8
Do not use tr() for APP_VERSION.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
415 arg(APP_VERSION)); |
10 | 416 |
122 | 417 // Setup large logo in the main window |
203 | 418 QPixmap logoImage(":/logo"); |
60
d7a2a48ebe24
Add a separate "About" button, don't use the logo as one. Change logo widget
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
419 ui->button_LogoImage->setPixmap(logoImage); |
d7a2a48ebe24
Add a separate "About" button, don't use the logo as one. Change logo widget
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
420 ui->button_LogoImage->setAlignment(Qt::AlignCenter); |
10 | 421 |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
422 slSetCommonStyleSheet(this); |
22 | 423 |
68
597bf29c5898
Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
424 // Validator for amount input |
597bf29c5898
Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
425 QRegExp vregex("\\d{0,4}[,.]\\d{0,2}|\\d{0,4}"); |
597bf29c5898
Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
426 ui->edit_Amount->setValidator(new QRegExpValidator(vregex, this)); |
597bf29c5898
Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
427 |
10 | 428 // Setup person list filtering and sorting |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
429 peopleSortIndex = 1; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
430 peopleSortOrder = Qt::AscendingOrder; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
431 peopleFilter = ""; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
433 model_People = new SLPersonSQLModel(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
434 updatePersonList(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
435 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 ui->tableview_People->setModel(model_People); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 ui->tableview_People->setColumnHidden(0, true); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 ui->tableview_People->setItemDelegate(new QSqlRelationalDelegate(ui->tableview_People)); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
439 ui->tableview_People->verticalHeader()->setVisible(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 ui->tableview_People->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 ui->tableview_People->setSortingEnabled(true); |
25 | 442 ui->tableview_People->sortByColumn(peopleSortIndex, peopleSortOrder); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
443 |
10 | 444 connect( |
445 ui->tableview_People->selectionModel(), | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), |
10 | 447 this, |
448 SLOT(selectedPersonChanged(const QModelIndex &, const QModelIndex &))); | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
449 |
10 | 450 connect( |
451 ui->tableview_People->horizontalHeader(), | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
452 SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
453 this, |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
454 SLOT(updateSortOrder(int, Qt::SortOrder))); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
455 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
456 ui->tableview_People->horizontalHeader()->setSortIndicator(1, Qt::AscendingOrder); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
457 |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
458 model_Latest = new SLTransactionSQLModel(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 ui->tableview_Latest->setModel(model_Latest); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
460 ui->tableview_Latest->setItemDelegate(new QSqlRelationalDelegate(ui->tableview_Latest)); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
461 ui->tableview_Latest->verticalHeader()->setVisible(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
462 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
464 setActivePerson(-1); |
17
d40345d63733
Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
465 |
d40345d63733
Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
466 // Keyboard shortcuts |
63 | 467 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(on_button_Quit_clicked())); |
178
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
468 new QShortcut(QKeySequence(Qt::Key_F10), this, SLOT(on_button_Quit_clicked())); |
63 | 469 |
178
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
470 new QShortcut(QKeySequence(Qt::Key_F5), this, SLOT(on_button_AddPerson_clicked())); |
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
471 new QShortcut(QKeySequence(Qt::Key_F6), this, SLOT(on_button_EditPerson_clicked())); |
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
472 new QShortcut(QKeySequence(Qt::Key_F8), this, SLOT(on_button_DeletePerson_clicked())); |
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
473 new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(on_button_About_clicked())); |
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
474 new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(on_button_ClearFilter_clicked())); |
63 | 475 |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
476 new QShortcut(QKeySequence(QKeySequence::ZoomIn), this, SLOT(changeUIZoomIn())); |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
477 new QShortcut(QKeySequence(QKeySequence::ZoomOut), this, SLOT(changeUIZoomOut())); |
191 | 478 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_0), this, SLOT(changeUIZoomReset())); |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
479 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_Plus), this, SLOT(changeUIZoomIn())); |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
480 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_Minus), this, SLOT(changeUIZoomOut())); |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
481 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_0), this, SLOT(changeUIZoomReset())); |
65 | 482 |
483 new QShortcut(QKeySequence(Qt::Key_PageUp), this, SLOT(selectRowPrev())); | |
484 new QShortcut(QKeySequence(Qt::Key_PageDown), this, SLOT(selectRowNext())); | |
485 | |
486 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this, SLOT(focusDebtEdit())); | |
114
a5c8741b8662
Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
487 |
a5c8741b8662
Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
488 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_P), this, SLOT(on_button_Print_clicked())); |
222
5406b8664f00
Add keyboard shortcut ctrl+t for opening the transactions list.
Matti Hamalainen <ccr@tnsp.org>
parents:
218
diff
changeset
|
489 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(on_button_ViewTransactions_clicked())); |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
490 |
194 | 491 // Check for latest successful backup time |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
492 qint64 threshold = 7; |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
493 qint64 delta = settings.dbLastBackup.msecsTo(QDateTime::currentDateTimeUtc()); |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
494 if (settings.dbBackupMode != BACKUP_NONE && |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
495 QDateTime::fromSecsSinceEpoch(0).msecsTo(settings.dbLastBackup) > 0 && |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
496 delta > (1000 * 60 * 60 * 24) * threshold) |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
497 { |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
498 slErrorMsg( |
195
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
499 tr("<h1>Huomio!</h1>"), |
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
500 tr( |
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
501 "<p>Edellisestä onnistuneesta tietokannan varmuuskopioinnista on kulunut <b>%1</b> päivää.</p>" |
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
502 "<p>On suositeltavaa että kytket laitteen Kampuksen kiinteään verkkoon, että " |
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
503 "varmuuskopiointi voidaan suorittaa. Varmuuskopiointia ei voida tehdä langattoman verkon kautta.</p>" |
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
504 ). |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
505 arg(delta / (1000 * 60 * 60 * 24))); |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
506 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
507 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
508 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
509 |
98 | 510 // |
511 // Application main window destructor | |
512 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 SyntilistaMainWindow::~SyntilistaMainWindow() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 { |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
515 QSettings tmpst(APP_VENDOR, APP_ID); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
516 |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
517 // Save window size and position |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
518 tmpst.setValue("pos", pos()); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
519 tmpst.setValue("size", size()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
521 // Other settings |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
522 tmpst.setValue("scale", settings.uiScale); |
151
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
523 tmpst.setValue("dbBackupMode", settings.dbBackupMode); |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
524 tmpst.setValue("dbBackupURL", settings.dbBackupURL); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
525 tmpst.setValue("dbBackupSecret", settings.dbBackupSecret); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
526 |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
527 // Free resources |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
528 delete ui; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
529 delete model_People; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
530 delete model_Latest; |
134
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
531 |
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
532 // Commit and close database |
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
533 QSqlDatabase::database().commit(); |
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
534 QSqlDatabase::database().close(); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
535 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
536 // Back up the database |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
537 if (settings.dbBackupMode != BACKUP_NONE) |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
538 backupDatabase(); |
151
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
539 else |
201 | 540 { |
541 slLog("INFO", | |
542 QStringLiteral("Database backup mode is NONE, not performing backup.")); | |
543 } | |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
544 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
545 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
546 |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
547 void SyntilistaMainWindow::backupSuccess() |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
548 { |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
549 QSettings tmpst(APP_VENDOR, APP_ID); |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
550 slLog("INFO", QStringLiteral("Backup successful.")); |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
551 |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
552 tmpst.setValue("dbLastBackup", QDateTime::currentDateTimeUtc()); |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
553 } |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
554 |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
555 |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
556 void SyntilistaMainWindow::backupDatabase() |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
557 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
558 QString dbFilename = settings.dataPath + QDir::separator() + APP_SQLITE_FILE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
559 QString backupFilename = APP_SQLITE_FILE; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
560 backupDialog = NULL; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
561 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
562 if (settings.dbBackupURL == QString() || settings.dbBackupURL == "") |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
563 { |
201 | 564 slLog("ERROR", |
565 QStringLiteral("Database backup URL not set in configuration.")); | |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
566 return; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
567 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
568 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
569 if (settings.dbBackupSecret == QString() || settings.dbBackupSecret == "") |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
570 { |
201 | 571 slLog("ERROR", |
572 QStringLiteral("Database backup secret key not set in configuration.")); | |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
573 return; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
574 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
575 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
576 if (settings.dbBackupMode == BACKUP_HTTP) |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
577 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
578 #ifdef USE_QTHTTP |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
579 // Check for network access |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
580 httpBackupReply = NULL; |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
581 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
582 QNetworkAccessManager *manager = new QNetworkAccessManager(); |
154
ef4edd798a45
Disable network availability check for now, it seems to return false values in some cases.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
583 /* |
155 | 584 // NOTE XXX! For some reason the manager returns not accessible under Wine |
585 // and possibly some version(s) of Windows .. not sure why, thus commented | |
586 // out for now. | |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
587 if (manager->networkAccessible() != QNetworkAccessManager::Accessible) |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
588 { |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
589 slLog("ERROR", QStringLiteral("Network not available, cannot backup the database.")); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
590 return; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
591 } |
154
ef4edd798a45
Disable network availability check for now, it seems to return false values in some cases.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
592 */ |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
593 |
199 | 594 // Attempt to open the database file |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
595 QFile *file = new QFile(dbFilename); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
596 if (!file->open(QIODevice::ReadOnly)) |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
597 { |
201 | 598 slLog("ERROR", |
599 QStringLiteral("Failed to open database file '%1' for backup."). | |
600 arg(dbFilename)); | |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
601 return; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
602 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
603 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
604 // Okay, we seem to be "go" .. |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
605 slLog("INFO", |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
606 QStringLiteral("Attempting database backup from '%1' to '%2'."). |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
607 arg(dbFilename).arg(settings.dbBackupURL)); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
608 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
609 // Create the HTTP POST request |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
610 QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
611 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
612 // The "secret" key as POST parameter |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
613 QHttpPart postPart; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
614 postPart.setHeader(QNetworkRequest::ContentDispositionHeader, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
615 QVariant("form-data; name=\"secret\";")); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
616 postPart.setBody(QByteArray(settings.dbBackupSecret.toUtf8())); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
617 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
618 // Actual data as binary octet-stream |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
619 QHttpPart dataPart; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
620 dataPart.setHeader(QNetworkRequest::ContentTypeHeader, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
621 QVariant("binary/octet-stream")); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
622 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
623 dataPart.setHeader(QNetworkRequest::ContentDispositionHeader, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
624 QVariant("form-data; name=\"file\"; filename=\""+ backupFilename +"\"")); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
625 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
626 dataPart.setBodyDevice(file); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
627 file->setParent(multiPart); // we cannot delete the QFile object now, so delete it with the multiPart |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
628 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
629 multiPart->append(postPart); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
630 multiPart->append(dataPart); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
631 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
632 // Attempt to POST the whole thing |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
633 QUrl url(settings.dbBackupURL); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
634 QNetworkRequest request(url); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
635 httpBackupReply = manager->post(request, multiPart); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
636 multiPart->setParent(httpBackupReply); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
637 |
153 | 638 // Connect signals |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
639 connect( |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
640 httpBackupReply, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
641 SIGNAL(finished()), |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
642 this, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
643 SLOT(httpBackupFinished())); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
644 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
645 connect( |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
646 httpBackupReply, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
647 SIGNAL(uploadProgress(qint64, qint64)), |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
648 this, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
649 SLOT(httpBackupProgress(qint64, qint64))); |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
650 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
651 connect( |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
652 httpBackupReply, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
653 SIGNAL(error(QNetworkReply::NetworkError)), |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
654 this, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
655 SLOT(httpBackupError(QNetworkReply::NetworkError))); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
656 #else |
153 | 657 // Disabled |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
658 slLog("ERROR", QStringLiteral("Backup method is HTTP/HTTPS, but support is not compiled in!")); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
659 return; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
660 #endif |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
661 } |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
662 else |
151
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
663 { |
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
664 slLog("ERROR", QStringLiteral("Database backup mode is INVALID! Not performing backup!")); |
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
665 return; |
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
666 } |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
667 |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
668 // Create progress dialog |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
669 backupDialog = new QProgressDialog( |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
670 tr("Varmuuskopioidaan tietokantaa ..."), |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
671 QString(), |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
672 0, |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
673 100, |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
674 this); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
675 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
676 backupDialog->setAttribute(Qt::WA_DeleteOnClose); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
677 backupDialog->setAutoClose(false); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
678 backupDialog->setWindowModality(Qt::ApplicationModal); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
679 backupDialog->exec(); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
680 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
681 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
682 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
683 #ifdef USE_QTHTTP |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
684 void SyntilistaMainWindow::httpBackupProgress(qint64 bytesSent, qint64 bytesTotal) |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
685 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
686 if (bytesTotal > 0) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
687 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
688 slLog("INFO", |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
689 QStringLiteral("Backup sent %1 / %2 bytes."). |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
690 arg(bytesSent). |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
691 arg(bytesTotal)); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
692 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
693 backupDialog->setValue((bytesSent * 100) / bytesTotal); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
694 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
695 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
696 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
697 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
698 void SyntilistaMainWindow::httpBackupError(QNetworkReply::NetworkError code) |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
699 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
700 slLog("ERROR", |
147
c722cb0b6662
Remove useless linefeed in an error log message.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
701 QStringLiteral("Backup failed with network error %1."). |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
702 arg(code) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
703 ); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
704 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
705 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
706 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
707 void SyntilistaMainWindow::httpBackupFinished() |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
708 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
709 if (httpBackupReply) |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
710 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
711 QVariant status = httpBackupReply->attribute(QNetworkRequest::HttpStatusCodeAttribute); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
712 if (status.isValid()) |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
713 { |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
714 int code = status.toInt(); |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
715 switch (code) |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
716 { |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
717 case 200: |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
718 backupSuccess(); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
719 break; |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
720 |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
721 case 403: |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
722 slLog("ERROR", |
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
723 QStringLiteral("Backup server authentication failed. Wrong secret or other invalid settings.")); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
724 break; |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
725 |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
726 default: |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
727 slLog("ERROR", |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
728 QStringLiteral("Backup server responded with error:\n")+ |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
729 QString::fromUtf8(httpBackupReply->readAll())); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
730 break; |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
731 } |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
732 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
733 } |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
734 else |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
735 { |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
736 slLog("WARNING", |
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
737 QStringLiteral("Backup finished prematurely (failed).")); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
738 } |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
739 |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
740 backupDialog->close(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
741 } |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
742 #endif |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
743 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
744 |
98 | 745 // |
746 // Helper function for showing messages in the statusbar/line | |
747 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
748 void SyntilistaMainWindow::statusMsg(const QString &msg) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
749 { |
133 | 750 slLog("STATUS", msg); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
751 ui->statusbar->showMessage(msg); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
752 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
753 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
754 |
122 | 755 // |
98 | 756 // Window scale / zoom changing |
757 // | |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
758 void SyntilistaMainWindow::changeUIZoomIn() |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
759 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
760 settings.uiScale += 0.1f; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
761 slSetCommonStyleSheet(this); |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
762 } |
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
763 |
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
764 |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
765 void SyntilistaMainWindow::changeUIZoomOut() |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
766 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
767 settings.uiScale -= 0.1f; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
768 slSetCommonStyleSheet(this); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
769 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
770 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
771 |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
772 void SyntilistaMainWindow::changeUIZoomReset() |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
773 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
774 settings.uiScale = 1.0f; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
775 slSetCommonStyleSheet(this); |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
776 } |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
777 |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
778 |
98 | 779 // |
780 // Slot for changed selection of person entry | |
781 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
782 void SyntilistaMainWindow::selectedPersonChanged(const QModelIndex &curr, const QModelIndex &prev) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
783 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
784 (void) prev; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
785 int row = curr.row(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
786 if (row >= 0) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
787 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
788 const QAbstractItemModel *model = curr.model(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
789 setActivePerson(model->data(model->index(row, 0)).toInt()); |
89
8ec1eb6b00b6
Automatically set focus to debt value edit field after selecting a person.
Matti Hamalainen <ccr@tnsp.org>
parents:
84
diff
changeset
|
790 focusDebtEdit(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
791 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
792 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
793 setActivePerson(-1); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
794 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
795 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
796 |
122 | 797 // |
798 // Set currently active person to given SQL id | |
799 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
800 void SyntilistaMainWindow::setActivePerson(qint64 id) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
801 { |
5 | 802 currPerson.id = id; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
803 |
1
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
804 ui->button_EditPerson->setEnabled(id >= 0); |
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
805 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
806 if (id >= 0) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
807 { |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
808 if (!slGetPersonInfo(id, currPerson)) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 { |
5 | 810 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(id)); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
811 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
812 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
813 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
814 ui->personGB->setEnabled(true); |
5 | 815 ui->label_PersonName->setText(currPerson.lastName +", "+ currPerson.firstName); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
816 |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
817 ui->label_BalanceValue->setText(slMoneyValueToStr(currPerson.balance)); |
5 | 818 ui->label_BalanceValue->setStyleSheet(currPerson.balance < 0 ? "color: red;" : "color: green;"); |
819 ui->button_PayFullDebt->setEnabled(currPerson.balance < 0); | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
820 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
821 QSqlQuery query; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
822 query.prepare(QStringLiteral("SELECT id,value,added FROM transactions WHERE person=? ORDER BY added DESC LIMIT 5")); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
823 query.addBindValue(id); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
824 query.exec(); |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
825 slCheckAndReportSQLError("SELECT transactions for tableview_Latest", query.lastError()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
826 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
827 model_Latest->setQuery(query); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
828 |
5 | 829 model_Latest->setHeaderData(0, Qt::Horizontal, tr("ID")); |
830 model_Latest->setHeaderData(1, Qt::Horizontal, tr("Summa")); | |
831 model_Latest->setHeaderData(2, Qt::Horizontal, tr("Aika")); | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
832 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
833 ui->tableview_Latest->setModel(model_Latest); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
834 ui->tableview_Latest->setColumnHidden(0, true); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
835 ui->tableview_Latest->verticalHeader()->setVisible(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
836 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
837 |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
838 slSetCommonStyleSheet(this); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
839 return; // Ugly |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
840 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
841 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
842 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
843 // In case of id < 0 or errors .. |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
844 ui->personGB->setEnabled(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
845 ui->edit_Amount->clear(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
846 ui->label_BalanceValue->setText("--"); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
847 ui->label_BalanceValue->setStyleSheet(NULL); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
848 ui->label_PersonName->setText("???"); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
849 ui->tableview_Latest->setModel(NULL); |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
850 slSetCommonStyleSheet(this); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
851 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
852 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
853 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
854 // |
98 | 855 // Slot for changing person list sort order |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
856 // |
98 | 857 void SyntilistaMainWindow::updateSortOrder(int index, Qt::SortOrder order) |
858 { | |
859 peopleSortIndex = index; | |
860 peopleSortOrder = order; | |
861 updatePersonList(); | |
862 } | |
863 | |
864 | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
865 void SyntilistaMainWindow::on_button_Quit_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
866 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
867 close(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
868 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
869 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
870 |
60
d7a2a48ebe24
Add a separate "About" button, don't use the logo as one. Change logo widget
Matti Hamalainen <ccr@tnsp.org>
parents:
58
diff
changeset
|
871 void SyntilistaMainWindow::on_button_About_clicked() |
47 | 872 { |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
873 new AboutWindow(this); |
74 | 874 } |
875 | |
876 | |
218
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
877 void SyntilistaMainWindow::on_button_ViewTransactions_clicked() |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
878 { |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
879 new ViewTransactions(this); |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
880 } |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
881 |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
882 |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
883 void SyntilistaMainWindow::on_button_DeletePerson_clicked() |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
884 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
885 if (currPerson.id <= 0) |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
886 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
887 statusMsg(tr("Ei valittua henkilöä!")); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
888 return; |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
889 } |
19 | 890 |
196 | 891 // Internal sanity check |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
892 SLPersonInfo info; |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
893 if (!slGetPersonInfo(currPerson.id, info)) |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
894 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
895 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(currPerson.id)); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
896 return; |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
897 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
898 |
196 | 899 // Ask for confirmation |
18 | 900 QMessageBox dlg; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
901 slSetCommonStyleSheet(&dlg); |
18 | 902 dlg.setText(tr("Varmistus")); |
201 | 903 dlg.setInformativeText(tr( |
904 "<h3>Haluatko varmasti poistaa henkilön:</h3>" | |
18 | 905 "<br>" |
906 "<b>'%1, %2'</b> <i>(ID #%3)</i>?<br>" | |
907 "<br>" | |
186
cc3d7745e798
Cosmetic adjustments to the delete person confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
908 "<span style='color:#f00;'>Tämä poistaa sekä henkilön ja hänen koko tapahtumahistoriansa PYSYVÄSTI!</span>" |
cc3d7745e798
Cosmetic adjustments to the delete person confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
909 "<br>"). |
18 | 910 arg(info.lastName).arg(info.firstName).arg(info.id)); |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
911 |
18 | 912 dlg.setTextFormat(Qt::RichText); |
913 dlg.setIcon(QMessageBox::Question); | |
914 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); | |
71 | 915 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä")); |
916 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta")); | |
18 | 917 dlg.setDefaultButton(QMessageBox::No); |
918 | |
919 if (dlg.exec() == QMessageBox::Yes) | |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
920 { |
13 | 921 int rv = model_People->deletePerson(info.id); |
14 | 922 updatePersonList(); |
24
0e0948aec438
De-select active person when deleting.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
923 setActivePerson(-1); |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
924 if (rv != 0) |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
925 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
926 slErrorMsg(tr("SQL-tietokantavirhe"), |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
927 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1."). |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
928 arg(rv)); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
929 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
930 else |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
931 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
932 statusMsg(tr("Henkilö '%1 %2' (ID #%3) poistettu."). |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
933 arg(info.firstName).arg(info.lastName). |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
934 arg(info.id)); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
935 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
936 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
937 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
938 |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
939 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
940 void SyntilistaMainWindow::on_button_AddPerson_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
941 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
942 EditPerson *person = new EditPerson(this); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
943 person->setPerson(-1); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
944 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
945 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
946 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
947 void SyntilistaMainWindow::on_button_EditPerson_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
948 { |
5 | 949 if (currPerson.id >= 0) |
1
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
950 { |
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
951 EditPerson *person = new EditPerson(this); |
5 | 952 person->setPerson(currPerson.id); |
1
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
953 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
954 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
955 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
956 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
957 void SyntilistaMainWindow::on_tableview_People_doubleClicked(const QModelIndex &curr) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
958 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
959 int row = curr.row(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
960 if (row >= 0) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
961 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
962 const QAbstractItemModel *model = curr.model(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
963 setActivePerson(model->data(model->index(row, 0)).toInt()); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
964 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
965 EditPerson *person = new EditPerson(this); |
5 | 966 person->setPerson(currPerson.id); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
967 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
968 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
969 setActivePerson(-1); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
970 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
971 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
972 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
973 void SyntilistaMainWindow::on_button_ClearFilter_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
974 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
975 ui->edit_PersonFilter->clear(); |
65 | 976 ui->edit_PersonFilter->setFocus(Qt::ShortcutFocusReason); |
977 } | |
978 | |
979 | |
980 void SyntilistaMainWindow::focusDebtEdit() | |
981 { | |
982 if (currPerson.id >= 0) | |
983 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason); | |
984 } | |
985 | |
986 | |
211
6585cac42b75
Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
987 void SyntilistaMainWindow::changeSelectedRow(const int delta) |
65 | 988 { |
989 QItemSelectionModel *sel = ui->tableview_People->selectionModel(); | |
209
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
990 int prow = sel->currentIndex().row(); |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
991 int nrow = prow + delta; |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
992 if (nrow < 0) |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
993 nrow = 0; |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
994 else |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
995 if (nrow >= model_People->rowCount()) |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
996 nrow = model_People->rowCount() - 1; |
65 | 997 |
209
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
998 if (nrow != prow) |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
999 { |
212 | 1000 // If row changed, set current index |
209
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1001 sel->setCurrentIndex(model_People->index(nrow, 0), |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1002 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows); |
210
02aae61e807e
Scroll along with the currently selected person in the person list,
Matti Hamalainen <ccr@tnsp.org>
parents:
209
diff
changeset
|
1003 |
212 | 1004 // The column must be a visible one (not set "hidden", as the ID field is) |
1005 // thus we use column index of 1 here for the QModelIndex() | |
210
02aae61e807e
Scroll along with the currently selected person in the person list,
Matti Hamalainen <ccr@tnsp.org>
parents:
209
diff
changeset
|
1006 ui->tableview_People->scrollTo(model_People->index(nrow, 1)); |
209
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1007 } |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1008 } |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1009 |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1010 |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1011 void SyntilistaMainWindow::selectRowPrev() |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1012 { |
211
6585cac42b75
Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1013 changeSelectedRow(-1); |
65 | 1014 } |
1015 | |
1016 | |
1017 void SyntilistaMainWindow::selectRowNext() | |
1018 { | |
211
6585cac42b75
Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1019 changeSelectedRow(1); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1020 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1021 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1022 |
4 | 1023 // |
1024 // Update visible person list/query based on the current | |
1025 // filtering and sorting settings. | |
1026 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1027 void SyntilistaMainWindow::updatePersonList() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1028 { |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1029 static const QString queryBase = |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1030 QStringLiteral("SELECT id,last_name,first_name," |
107
8ceaafde9b52
Use total() instead of sum() in the SQL queries for better accuracy.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1031 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance," |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1032 "updated FROM people"); |
16 | 1033 |
4 | 1034 QString queryOrderDir, queryOrderBy; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1035 |
4 | 1036 // Sort order |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1037 if (peopleSortOrder == Qt::AscendingOrder) |
4 | 1038 queryOrderDir = QStringLiteral("ASC"); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1039 else |
4 | 1040 queryOrderDir = QStringLiteral("DESC"); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1041 |
4 | 1042 // Sort by which column |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1043 switch (peopleSortIndex) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1044 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1045 case 1: |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1046 case 2: |
196 | 1047 queryOrderBy = |
1048 QStringLiteral(" ORDER BY last_name ") + queryOrderDir + | |
1049 QStringLiteral(",first_name ") + queryOrderDir; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1050 break; |
19 | 1051 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1052 case 3: |
196 | 1053 queryOrderBy = |
1054 QStringLiteral(" ORDER BY balance ") + queryOrderDir; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1055 break; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1056 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1057 case 4: |
196 | 1058 queryOrderBy = |
1059 QStringLiteral(" ORDER BY updated ") + queryOrderDir; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1060 break; |
19 | 1061 |
4 | 1062 default: |
1063 queryOrderBy = ""; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1064 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1065 |
4 | 1066 // Are we filtering or not? |
126 | 1067 QSqlQuery query; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1068 if (peopleFilter != "") |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1069 { |
4 | 1070 // Filter by name(s) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1071 QString tmp = "%"+ peopleFilter +"%"; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1072 query.prepare(queryBase + QStringLiteral(" WHERE first_name LIKE ? OR last_name LIKE ?") + queryOrderBy); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1073 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1074 query.addBindValue(tmp); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1075 query.addBindValue(tmp); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1076 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1077 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1078 { |
4 | 1079 // No filter |
16 | 1080 query.prepare(queryBase + queryOrderBy); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1081 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1082 |
4 | 1083 // Execute the query and update model |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1084 slCheckAndReportSQLError("updatePersonList() before exec", query.lastError()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1085 query.exec(); |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1086 slCheckAndReportSQLError("updatePersonList() after exec", query.lastError()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1087 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1088 model_People->setQuery(query); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1089 |
5 | 1090 model_People->setHeaderData(0, Qt::Horizontal, tr("ID")); |
1091 model_People->setHeaderData(1, Qt::Horizontal, tr("Sukunimi")); | |
1092 model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi")); | |
1093 model_People->setHeaderData(3, Qt::Horizontal, tr("Tase")); | |
1094 model_People->setHeaderData(4, Qt::Horizontal, tr("Muutettu")); | |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1095 |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1096 updateMiscValues(); |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1097 } |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1098 |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1099 |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1100 // |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1101 // Update some values in the UI |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1102 // |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1103 void SyntilistaMainWindow::updateMiscValues() |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1104 { |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1105 // Update total balance value |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1106 QSqlQuery query; |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1107 query.prepare(QStringLiteral("SELECT TOTAL(value) FROM transactions AS balance")); |
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1108 query.exec(); |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1109 if (slCheckAndReportSQLError("updateMiscValues() get total balance query", query.lastError()) && |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1110 query.next()) |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1111 { |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1112 totalBalance = query.value(0).toDouble();; |
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1113 ui->label_TotalBalanceValue->setText(slMoneyValueToStr(totalBalance)); |
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1114 ui->label_TotalBalanceValue->setStyleSheet(totalBalance < 0 ? "color: red;" : "color: green;"); |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1115 } |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1116 |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1117 // Update number of people |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1118 query.finish(); |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1119 query.prepare(QStringLiteral("SELECT COUNT(*) FROM people")); |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1120 query.exec(); |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1121 if (slCheckAndReportSQLError("updateMiscValues() get people count", query.lastError()) && |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1122 query.next()) |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1123 { |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1124 totalPeople = query.value(0).toInt(); |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1125 ui->label_NumPeopleValue->setText(query.value(0).toString()); |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1126 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1127 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1128 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1129 |
4 | 1130 // |
1131 // Update the list of people when filter parameter changes | |
1132 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1133 void SyntilistaMainWindow::on_edit_PersonFilter_textChanged(const QString &str) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1134 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1135 peopleFilter = slCleanupStr(str); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1136 updatePersonList(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1137 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1138 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1139 |
4 | 1140 // |
1141 // Add one transaction to given person id | |
1142 // | |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1143 int SyntilistaMainWindow::addTransaction(qint64 id, double value, SLPersonInfo &info) |
4 | 1144 { |
179 | 1145 // Sanity check: Check if the given person ID exists |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
1146 if (!slGetPersonInfo(id, info)) |
4 | 1147 return -1; |
1148 | |
1149 QSqlDatabase::database().transaction(); | |
1150 | |
179 | 1151 // Add transaction entry |
4 | 1152 QSqlQuery query; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1153 query.prepare(QStringLiteral("INSERT INTO transactions (person,value,added) VALUES (?,?,?)")); |
4 | 1154 query.addBindValue(id); |
1155 query.addBindValue(value); | |
1156 query.addBindValue(QDateTime::currentDateTimeUtc()); | |
1157 query.exec(); | |
126 | 1158 if (!slCheckAndReportSQLError(QStringLiteral("addTransaction(%1, %2)").arg(id).arg(value), query.lastError(), true)) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1159 { |
4 | 1160 QSqlDatabase::database().rollback(); |
1161 return -2; | |
1162 } | |
1163 | |
179 | 1164 // Update person record timestamp |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1165 query.prepare(QStringLiteral("UPDATE people SET updated=? WHERE id=?")); |
4 | 1166 query.addBindValue(QDateTime::currentDateTimeUtc()); |
1167 query.addBindValue(id); | |
1168 query.exec(); | |
126 | 1169 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError(), true)) |
4 | 1170 { |
1171 QSqlDatabase::database().rollback(); | |
1172 return -3; | |
1173 } | |
1174 | |
1175 QSqlDatabase::database().commit(); | |
1176 | |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1177 updateMiscValues(); |
130
10c6bd84eb32
Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
1178 |
4 | 1179 return 0; |
1180 } | |
1181 | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1182 |
4 | 1183 int SyntilistaMainWindow::addTransactionGUI(qint64 id, bool debt, double value) |
1184 { | |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1185 SLPersonInfo info; |
4 | 1186 |
8 | 1187 // Check if person is selected |
4 | 1188 if (id <= 0) |
1189 return -1; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1190 |
8 | 1191 // Check value |
4 | 1192 if (value == 0) |
1193 { | |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1194 QString tmp = debt ? tr("lisätty") : tr("vähennetty"); |
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1195 statusMsg(tr("Velkaa ei %1 koska summaa ei määritetty.").arg(tmp)); |
4 | 1196 return 1; |
1197 } | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1198 |
8 | 1199 // Perform transaction insert |
4 | 1200 int ret = addTransaction(id, debt ? -value : value, info); |
1201 if (ret == 0) | |
1202 { | |
8 | 1203 // All ok, clear amount entry and update person data |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1204 ui->edit_Amount->clear(); |
12 | 1205 if (info.id == currPerson.id) |
1206 setActivePerson(info.id); | |
19 | 1207 |
12 | 1208 model_People->updateModel(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1209 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1210 if (debt) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1211 { |
196 | 1212 // Debt was added |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1213 statusMsg( |
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1214 tr("Lisättiin velkaa %1 EUR henkilölle '%2 %3' (#%4)."). |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1215 arg(slMoneyValueToStr(value)). |
4 | 1216 arg(info.firstName). |
1217 arg(info.lastName). | |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1218 arg(info.id)); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1219 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1220 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1221 { |
196 | 1222 // Debt was reduced |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1223 statusMsg( |
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1224 tr("Vähennettiin velkaa %1 EUR henkilöltä '%2 %3' (#%4)."). |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1225 arg(slMoneyValueToStr(value)). |
4 | 1226 arg(info.firstName). |
1227 arg(info.lastName). | |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1228 arg(info.id)); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1229 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1230 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1231 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1232 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1233 slErrorMsg( |
8 | 1234 tr("SQL-tietokantavirhe"), |
1235 tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1."). | |
1236 arg(ret)); | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1237 } |
4 | 1238 |
1239 return ret; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1240 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1241 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1242 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1243 void SyntilistaMainWindow::on_button_AddDebt_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1244 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1245 addTransactionGUI(currPerson.id, true, slMoneyStrToValue(ui->edit_Amount->text())); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1246 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1247 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1248 |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1249 void SyntilistaMainWindow::on_button_PayDebt_clicked() |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1250 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1251 addTransactionGUI(currPerson.id, false, slMoneyStrToValue(ui->edit_Amount->text())); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1252 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1253 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1254 |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1255 void SyntilistaMainWindow::on_button_PayFullDebt_clicked() |
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1256 { |
196 | 1257 // Sanity check that there is a selected person |
187
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1258 if (currPerson.id <= 0) |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1259 { |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1260 statusMsg(tr("Ei valittua henkilöä!")); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1261 return; |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1262 } |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1263 |
196 | 1264 // Check the balance .. |
5 | 1265 if (currPerson.balance < 0) |
187
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1266 { |
196 | 1267 // And ask confirmation that user really wants to clear the full debt |
187
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1268 QMessageBox dlg; |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1269 slSetCommonStyleSheet(&dlg); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1270 dlg.setText(tr("Varmistus")); |
201 | 1271 dlg.setInformativeText(tr( |
1272 "<h3>Haluatko maksaa henkilön koko velan?</h3>" | |
187
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1273 "<br>" |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1274 "<b>'%1, %2'</b>, velka <span style='color:#f00;'><b>%4 EUR</b></span>" |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1275 "<br>"). |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1276 arg(currPerson.lastName).arg(currPerson.firstName). |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1277 arg(slMoneyValueToStr(currPerson.balance))); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1278 |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1279 dlg.setTextFormat(Qt::RichText); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1280 dlg.setIcon(QMessageBox::Question); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1281 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1282 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä")); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1283 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta")); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1284 dlg.setDefaultButton(QMessageBox::No); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1285 |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1286 if (dlg.exec() == QMessageBox::Yes) |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1287 { |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1288 addTransactionGUI(currPerson.id, false, -currPerson.balance); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1289 } |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1290 } |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1291 else |
8 | 1292 { |
1293 statusMsg( | |
1294 tr("Valitulla henkilöllä '%1, %2' ei ole velkaa."). | |
1295 arg(currPerson.lastName). | |
1296 arg(currPerson.firstName)); | |
1297 } | |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1298 } |
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1299 |
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1300 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1301 // |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1302 // About window |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1303 // |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1304 AboutWindow::AboutWindow(QWidget *parent) : |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1305 QDialog(parent), |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1306 ui(new Ui::AboutWindow) |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1307 { |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1308 ui->setupUi(this); |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1309 |
203 | 1310 ui->label_Logo->setPixmap(QPixmap(QStringLiteral(":/icon"))); |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1311 ui->label_Logo->setAlignment(Qt::AlignCenter); |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1312 |
197
f7da0c030262
Show AppDataPath as a link in the about window.
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1313 ui->label_About->setOpenExternalLinks(true); |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1314 ui->label_About->setWordWrap(true); |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1315 ui->label_About->setTextFormat(Qt::RichText); |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1316 ui->label_About->setText(tr( |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1317 "<h1>%1 v%2</h1>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1318 "<p>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1319 "<b>Ohjelmoinut ja kehittänyt Matti Hämäläinen <ccr@tnsp.org><br>" |
217 | 1320 "(C) Copyright 2017-2018 Tecnic Software productions (TNSP)</b>" |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1321 "</p>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1322 "<p>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1323 "Kehitetty Raahen kaupungin Hanketoiminta ja Kehittäminen -yksikön " |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1324 "alaisuudessa Café Kampuksen käyttöön." |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1325 "</p>" |
197
f7da0c030262
Show AppDataPath as a link in the about window.
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1326 "<p>AppDataPath: <a href=\"file:///%3\">%3</a></p>" |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1327 ). |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1328 arg(tr(APP_NAME)). |
137
1a480e947598
Show application data path in the about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
1329 arg(APP_VERSION). |
138
5e6bcabfa380
Oops, old datapath variable used. Fix it.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
1330 arg(settings.dataPath) |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1331 ); |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1332 |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1333 ui->label_ShortCuts->setText(tr( |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1334 "<h1>Pikanäppäimet</h1>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1335 "<table>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1336 "<tr><td><b>F1</b></td><td>Tämä tietoikkuna</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1337 "<tr><td><b>CTRL + Q</b></td><td>Ohjelman lopetus</td></tr>" |
226
c0dfbbd67692
Add information about two keyboard shortcuts to the help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1338 "<tr><td><b>CTRL + P</b></td><td>Henkilölistan tulostus/esikatselu</td></tr>" |
c0dfbbd67692
Add information about two keyboard shortcuts to the help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
1339 "<tr><td><b>CTRL + T</b></td><td>Tapahtumalistaikkuna</td></tr>" |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1340 "<tr><td><b>CTRL + Page Up</b></td><td>Suurenna ohjelman tekstejä/käyttöliittymää</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1341 "<tr><td><b>CTRL + Page Down</b></td><td>Pienennä ohjelman tekstejä/käyttöliittymää</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1342 "<tr></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1343 "<tr><td><b>Esc</b></td><td>Tyhjennä 'Etsi / suodata' kenttä ja siirry siihen</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1344 "<tr><td><b>CTRL + Enter</b></td><td>Siirry summan syöttökenttään</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1345 "<tr><td><b>Page Up</b></td><td>Siirry ylös henkilölistassa</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1346 "<tr><td><b>Page Down</b></td><td>Siirry alas henkilölistassa</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1347 "<tr></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1348 "<tr><td><b>F5</b></td><td>Lisää uusi henkilö</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1349 "<tr><td><b>F6</b></td><td>Muokkaa henkilöä</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1350 "<tr><td><b>F8</b></td><td>Poista henkilö</td></tr>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1351 "</table>" |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1352 )); |
95 | 1353 |
231
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1354 QFile fh(":/license"); |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1355 if (fh.open(QIODevice::ReadOnly | QIODevice::Text)) |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1356 { |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1357 QString text = ""; |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1358 while (!fh.atEnd()) |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1359 text += fh.readLine(); |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1360 |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1361 ui->text_License->setHtml(text); |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1362 fh.close(); |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1363 } |
e90dba0cd12a
Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
1364 |
232
07d837442c55
Open the links in about dialog via external web browser.
Matti Hamalainen <ccr@tnsp.org>
parents:
231
diff
changeset
|
1365 ui->text_License->setOpenExternalLinks(true); |
95 | 1366 setModal(true); |
1367 setAttribute(Qt::WA_DeleteOnClose); | |
1368 show(); | |
1369 activateWindow(); | |
1370 raise(); | |
1371 setFocus(); | |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1372 } |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1373 |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1374 |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1375 AboutWindow::~AboutWindow() |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1376 { |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1377 delete ui; |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1378 } |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1379 |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1380 |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1381 void AboutWindow::on_button_Close_clicked() |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1382 { |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1383 close(); |
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
1384 } |