Mercurial > hg > syntilista
annotate src/main.cpp @ 249:cfaf03d8d23e
Disable doubleclick edit of users for now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 08 May 2018 13:29:46 +0300 |
parents | 4f947840c806 |
children | 4d2b37a0acf2 |
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" |
246
43a5e09bb832
Split some utility functions to util.{h,cpp}
Matti Hamalainen <ccr@tnsp.org>
parents:
242
diff
changeset
|
17 #include "util.h" |
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 static const SLSQLSchemaDef slSQLSchemaData[] = |
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 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
32 QStringLiteral("people"), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
33 QStringLiteral( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
34 "id INTEGER PRIMARY KEY," |
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 "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
|
37 "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
|
38 "extra_info VARCHAR(" SL_STR(SQL_LEN_EXTRA_INFO) ")," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
39 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
40 "added DATETIME NOT NULL," |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
41 "updated DATETIME NOT NULL" |
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 }, |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
44 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
45 QStringLiteral("transactions"), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
46 QStringLiteral( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
47 "id INTEGER PRIMARY KEY, " |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
48 "person INT NOT NULL, " |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
49 "value REAL, " |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
50 "added DATETIME NOT NULL" |
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 }, |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
53 }; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
54 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
55 static const int nslSQLSchemaData = sizeof(slSQLSchemaData) / sizeof(slSQLSchemaData[0]); |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
56 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
58 void SLPersonInfo::dump() |
5 | 59 { |
126 | 60 printf( |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
61 "SLPersonInfo() #%lld '%s %s' (added=%s, updated=%s, balance %1.2f)\n#%s#\n", |
5 | 62 id, |
63 firstName.toUtf8().constData(), | |
64 lastName.toUtf8().constData(), | |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
65 slDateTimeToStr(added).toUtf8().constData(), |
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
66 slDateTimeToStr(updated).toUtf8().constData(), |
5 | 67 balance, |
68 extraInfo.toUtf8().constData()); | |
69 } | |
70 | |
71 | |
72 // | |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
73 // Get SLPersonInfo record from SQL query object |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
74 // |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
75 void slGetPersonInfoRec(QSqlQuery &query, SLPersonInfo &info) |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
76 { |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
77 info.id = query.value(0).toInt(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
78 info.firstName = query.value(1).toString(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
79 info.lastName = query.value(2).toString(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
80 info.extraInfo = query.value(3).toString(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
81 info.added = query.value(4).toDateTime(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
82 info.updated = query.value(5).toDateTime(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
83 info.balance = query.value(6).toDouble(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
84 } |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
85 |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
86 |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
87 // |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
88 // Get SLPersonInfo record from SQL database for specified person ID # |
5 | 89 // |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
90 bool slGetPersonInfo(qint64 id, SLPersonInfo &info) |
5 | 91 { |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
92 QSqlQuery query; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
93 query.prepare(QStringLiteral( |
5 | 94 "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
|
95 "(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
|
96 "FROM people WHERE id=?")); |
5 | 97 |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
98 query.addBindValue(id); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
99 query.exec(); |
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
100 if (!query.next()) |
5 | 101 return false; |
102 | |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
103 slGetPersonInfoRec(query, info); |
101
2477f46282c8
Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
104 query.finish(); |
5 | 105 return true; |
106 } | |
107 | |
108 | |
156 | 109 // |
110 // Set stylesheet for given QWidget, and scale fonts etc. | |
111 // for some elements based on current UI scale factor. | |
112 // | |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
113 void slSetCommonStyleSheet(QWidget *widget) |
32 | 114 { |
40 | 115 // Clamp scale value |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
116 if (settings.uiScale < 0.5f) |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
117 settings.uiScale = 0.5f; |
103 | 118 |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
119 if (settings.uiScale > 3.0f) |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
120 settings.uiScale = 3.0f; |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
121 |
40 | 122 // Set the stylesheet |
32 | 123 widget->setStyleSheet( |
124 QStringLiteral( | |
125 "* { font-size: %1pt; }" | |
126 "QPushButton { font-size: %2pt; padding: 0.25em; }" | |
40 | 127 "#button_AddDebt[enabled='true'] { font-size: %3pt; background-color: #900; color: white; }" |
128 "#button_PayDebt[enabled='true'] { font-size: %3pt; background-color: #090; color: white; }" | |
129 "#button_PayFullDebt[enabled='true'] { background-color: #060; color: white; }" | |
130 | |
131 "#button_AddDebt[enabled='false'] { font-size: %3pt; background-color: #622; color: black; }" | |
132 "#button_PayDebt[enabled='false'] { font-size: %3pt; background-color: #262; color: black; }" | |
133 "#button_PayFullDebt[enabled='false'] { background-color: #131; color: black; }" | |
134 | |
32 | 135 "#label_PersonName { font-size: %5pt; font-weight: bold; }" |
136 "#label_BalanceValue { font-size: %4pt; font-weight: bold; }" | |
137 "#label_EUR { font-size: %4pt; font-weight: bold; }" | |
138 "#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
|
139 "#label_NumPeopleValue { color: green; }" |
32 | 140 ). |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
141 arg(12 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
142 arg(14 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
143 arg(16 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
144 arg(18 * settings.uiScale). |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
145 arg(20 * settings.uiScale) |
32 | 146 ); |
147 } | |
148 | |
149 | |
156 | 150 // |
151 // Main program begins | |
152 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 int main(int argc, char *argv[]) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 QApplication sapp(argc, argv); |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
156 QSettings tmpst(APP_VENDOR, APP_ID); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
157 |
228
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
158 // 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
|
159 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
|
160 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
|
161 { |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
162 slErrorMsg( |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
163 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
|
164 QObject::tr( |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
165 "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
|
166 "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
|
167 ) |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
168 ); |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
169 return 1; |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
170 } |
37d5f4329449
Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
171 |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
172 // Read configuration settings |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
181 // 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
|
182 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
|
183 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
184 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
|
185 if (argc >= 5) |
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
186 { |
d9b9be9c4788
Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
187 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
|
188 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
|
189 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
190 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
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
|
192 // 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
|
193 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
|
194 { |
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
|
195 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
|
196 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
|
197 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
|
198 } |
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
|
199 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 // |
170
7edbfb2c0089
Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents:
169
diff
changeset
|
201 // 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
|
202 // |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
203 settings.dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
204 QDir path(settings.dataPath); |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
205 if (!path.exists(settings.dataPath)) |
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
206 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
|
207 |
f6685c2eb75d
Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
208 // |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 // Initialize / open SQL database connection |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 // |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
212 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
|
213 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 if (!db.open()) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
216 slErrorMsg( |
9 | 217 QObject::tr("Tietokantaa ei voitu avata"), |
18 | 218 QObject::tr("Yhteyttä SQL-tietokantaan ei saatu.<br><br>Virhe: %1<br><br>"). |
8 | 219 arg(db.lastError().text()) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 ); |
8 | 221 return 1; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
224 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
225 // Create tables |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
226 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
227 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
|
228 { |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
229 const SLSQLSchemaDef &table = slSQLSchemaData[ntable]; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
230 if (!db.tables().contains(table.name)) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
231 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
232 QSqlQuery query; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
233 QString sql = |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
234 QStringLiteral("CREATE TABLE %1 (%2)"). |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
235 arg(table.name). |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
236 arg(table.schema); |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
237 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
238 query.exec(sql); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
240 if (!slCheckAndReportSQLError( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
241 QStringLiteral("CREATE TABLE %1").arg(table.name), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
242 query.lastError(), true)) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
243 { |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
244 slErrorMsg( |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
245 QObject::tr("Tietokantataulua ei voitu luoda"), |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
246 QObject::tr("Virhe: %1<br><br>"). |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
247 arg(db.lastError().text()) |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
248 ); |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
249 return 1; |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
250 } |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
251 |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
252 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
|
253 } |
44
8fb2230fe860
Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
42
diff
changeset
|
254 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 |
239
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
256 // |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
257 // Execute main app |
9626307f3eeb
Streamline SQL table creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
237
diff
changeset
|
258 // |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
259 SyntilistaMainWindow swin; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 swin.show(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 return sapp.exec(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
263 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 // |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 // Main application window code |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 // |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 SyntilistaMainWindow::SyntilistaMainWindow(QWidget *parent) : |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 QMainWindow(parent), |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 ui(new Ui::SyntilistaMainWindow) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 { |
10 | 272 // Setup UI |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 ui->setupUi(this); |
47 | 274 |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
275 // Restore window size and position |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
276 move(settings.uiPos); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
277 resize(settings.uiSize); |
47 | 278 |
122 | 279 // Setup application icon and window title |
203 | 280 setWindowIcon(QIcon(QPixmap(":/icon"))); |
64
73fd86778014
Version number display etc. changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
281 setWindowTitle(tr("%1 versio %3"). |
39 | 282 arg(tr(APP_NAME)). |
204
fd115ca75ce8
Do not use tr() for APP_VERSION.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
283 arg(APP_VERSION)); |
10 | 284 |
122 | 285 // Setup large logo in the main window |
203 | 286 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
|
287 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
|
288 ui->button_LogoImage->setAlignment(Qt::AlignCenter); |
10 | 289 |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
290 slSetCommonStyleSheet(this); |
22 | 291 |
68
597bf29c5898
Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
292 // Validator for amount input |
597bf29c5898
Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
293 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
|
294 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
|
295 |
10 | 296 // Setup person list filtering and sorting |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 peopleSortIndex = 1; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 peopleSortOrder = Qt::AscendingOrder; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 peopleFilter = ""; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
301 model_People = new SLPersonSQLModel(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 updatePersonList(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
304 ui->tableview_People->setModel(model_People); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
305 ui->tableview_People->setColumnHidden(0, true); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
306 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
|
307 ui->tableview_People->verticalHeader()->setVisible(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 ui->tableview_People->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 ui->tableview_People->setSortingEnabled(true); |
25 | 310 ui->tableview_People->sortByColumn(peopleSortIndex, peopleSortOrder); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 |
10 | 312 connect( |
313 ui->tableview_People->selectionModel(), | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), |
10 | 315 this, |
316 SLOT(selectedPersonChanged(const QModelIndex &, const QModelIndex &))); | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
317 |
10 | 318 connect( |
319 ui->tableview_People->horizontalHeader(), | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
320 SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 this, |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
322 SLOT(updateSortOrder(int, Qt::SortOrder))); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 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
|
325 |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
326 model_Latest = new SLTransactionSQLModel(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 ui->tableview_Latest->setModel(model_Latest); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 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
|
329 ui->tableview_Latest->verticalHeader()->setVisible(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 setActivePerson(-1); |
17
d40345d63733
Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
333 |
d40345d63733
Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
334 // Keyboard shortcuts |
63 | 335 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
|
336 new QShortcut(QKeySequence(Qt::Key_F10), this, SLOT(on_button_Quit_clicked())); |
63 | 337 |
178
2155e05bf61c
Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents:
174
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 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
|
342 new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(on_button_ClearFilter_clicked())); |
63 | 343 |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
344 new QShortcut(QKeySequence(QKeySequence::ZoomIn), this, SLOT(changeUIZoomIn())); |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
345 new QShortcut(QKeySequence(QKeySequence::ZoomOut), this, SLOT(changeUIZoomOut())); |
191 | 346 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
|
347 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
|
348 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
|
349 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_0), this, SLOT(changeUIZoomReset())); |
65 | 350 |
351 new QShortcut(QKeySequence(Qt::Key_PageUp), this, SLOT(selectRowPrev())); | |
352 new QShortcut(QKeySequence(Qt::Key_PageDown), this, SLOT(selectRowNext())); | |
353 | |
354 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
|
355 |
a5c8741b8662
Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
356 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
|
357 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
|
358 |
194 | 359 // 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 { |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
366 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
|
367 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
|
368 tr( |
930191210416
Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents:
194
diff
changeset
|
369 "<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
|
370 "<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
|
371 "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
|
372 ). |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
373 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
|
374 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
375 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
376 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
377 |
98 | 378 // |
379 // Application main window destructor | |
380 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
381 SyntilistaMainWindow::~SyntilistaMainWindow() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
382 { |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
383 QSettings tmpst(APP_VENDOR, APP_ID); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
384 |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
385 // Save window size and position |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
386 tmpst.setValue("pos", pos()); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
387 tmpst.setValue("size", size()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
388 |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
389 // Other settings |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
390 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
|
391 tmpst.setValue("dbBackupMode", settings.dbBackupMode); |
139
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
392 tmpst.setValue("dbBackupURL", settings.dbBackupURL); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
393 tmpst.setValue("dbBackupSecret", settings.dbBackupSecret); |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
394 |
d5d1549e47fb
Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
395 // Free resources |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
396 delete ui; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
397 delete model_People; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
398 delete model_Latest; |
134
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
399 |
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
400 // Commit and close database |
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
401 QSqlDatabase::database().commit(); |
478ce4c94f6b
Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
402 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
|
403 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
404 // Back up the database |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
405 if (settings.dbBackupMode != BACKUP_NONE) |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
406 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
|
407 else |
201 | 408 { |
409 slLog("INFO", | |
410 QStringLiteral("Database backup mode is NONE, not performing backup.")); | |
411 } | |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
412 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
413 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
414 |
190
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
415 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
|
416 { |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
417 QSettings tmpst(APP_VENDOR, APP_ID); |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
418 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
|
419 |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
420 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
|
421 } |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
422 |
76afbf6508c8
Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
423 |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
424 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
|
425 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
426 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
|
427 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
|
428 backupDialog = NULL; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
429 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
430 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
|
431 { |
201 | 432 slLog("ERROR", |
433 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
|
434 return; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
435 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
436 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
437 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
|
438 { |
201 | 439 slLog("ERROR", |
440 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
|
441 return; |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
442 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
443 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
444 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
|
445 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
446 #ifdef USE_QTHTTP |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
447 // Check for network access |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
448 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
|
449 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
450 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
|
451 /* |
155 | 452 // NOTE XXX! For some reason the manager returns not accessible under Wine |
453 // and possibly some version(s) of Windows .. not sure why, thus commented | |
454 // out for now. | |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
455 if (manager->networkAccessible() != QNetworkAccessManager::Accessible) |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
456 { |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
457 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
|
458 return; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
459 } |
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
|
460 */ |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
461 |
199 | 462 // Attempt to open the database file |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
463 QFile *file = new QFile(dbFilename); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
464 if (!file->open(QIODevice::ReadOnly)) |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
465 { |
201 | 466 slLog("ERROR", |
467 QStringLiteral("Failed to open database file '%1' for backup."). | |
468 arg(dbFilename)); | |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
469 return; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
470 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
471 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
472 // Okay, we seem to be "go" .. |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
473 slLog("INFO", |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
474 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
|
475 arg(dbFilename).arg(settings.dbBackupURL)); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
476 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
477 // Create the HTTP POST request |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
478 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
|
479 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
480 // The "secret" key as POST parameter |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
481 QHttpPart postPart; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
482 postPart.setHeader(QNetworkRequest::ContentDispositionHeader, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
483 QVariant("form-data; name=\"secret\";")); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
484 postPart.setBody(QByteArray(settings.dbBackupSecret.toUtf8())); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
485 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
486 // Actual data as binary octet-stream |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
487 QHttpPart dataPart; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
488 dataPart.setHeader(QNetworkRequest::ContentTypeHeader, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
489 QVariant("binary/octet-stream")); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
490 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
491 dataPart.setHeader(QNetworkRequest::ContentDispositionHeader, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
492 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
|
493 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
494 dataPart.setBodyDevice(file); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
495 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
|
496 |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
497 multiPart->append(postPart); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
498 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
|
499 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
500 // Attempt to POST the whole thing |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
501 QUrl url(settings.dbBackupURL); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
502 QNetworkRequest request(url); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
503 httpBackupReply = manager->post(request, multiPart); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
504 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
|
505 |
153 | 506 // Connect signals |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
507 connect( |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
508 httpBackupReply, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
509 SIGNAL(finished()), |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
510 this, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
511 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
|
512 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
513 connect( |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
514 httpBackupReply, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
515 SIGNAL(uploadProgress(qint64, qint64)), |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
516 this, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
517 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
|
518 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
519 connect( |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
520 httpBackupReply, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
521 SIGNAL(error(QNetworkReply::NetworkError)), |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
522 this, |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
523 SLOT(httpBackupError(QNetworkReply::NetworkError))); |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
524 #else |
153 | 525 // Disabled |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
526 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
|
527 return; |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
528 #endif |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
529 } |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
530 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
|
531 { |
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
532 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
|
533 return; |
753ae3569cb7
Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
534 } |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
535 |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
536 // 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
|
537 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
|
538 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
|
539 QString(), |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
540 0, |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
541 100, |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
542 this); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
543 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 backupDialog->exec(); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
548 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
549 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
550 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
551 #ifdef USE_QTHTTP |
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
552 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
|
553 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
554 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
|
555 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
556 slLog("INFO", |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
557 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
|
558 arg(bytesSent). |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
559 arg(bytesTotal)); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
560 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
561 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
|
562 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
563 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
564 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
565 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
566 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
|
567 { |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
568 slLog("ERROR", |
147
c722cb0b6662
Remove useless linefeed in an error log message.
Matti Hamalainen <ccr@tnsp.org>
parents:
145
diff
changeset
|
569 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
|
570 arg(code) |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
571 ); |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
572 } |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
573 |
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
574 |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
575 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
|
576 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
577 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
|
578 { |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
579 QVariant status = httpBackupReply->attribute(QNetworkRequest::HttpStatusCodeAttribute); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
580 if (status.isValid()) |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
581 { |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
582 int code = status.toInt(); |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
583 switch (code) |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
584 { |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
585 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
|
586 backupSuccess(); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
587 break; |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
588 |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
589 case 403: |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
590 slLog("ERROR", |
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
591 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
|
592 break; |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
593 |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
594 default: |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
595 slLog("ERROR", |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
596 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
|
597 QString::fromUtf8(httpBackupReply->readAll())); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
598 break; |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
599 } |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
600 } |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
601 } |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
602 else |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
603 { |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
604 slLog("WARNING", |
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
605 QStringLiteral("Backup finished prematurely (failed).")); |
144
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
606 } |
75a4faa219a9
Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
607 |
142
36c9cb759326
Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
608 backupDialog->close(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
609 } |
150
2a8c97753381
Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
610 #endif |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
611 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
612 |
98 | 613 // |
614 // Helper function for showing messages in the statusbar/line | |
615 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
616 void SyntilistaMainWindow::statusMsg(const QString &msg) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
617 { |
133 | 618 slLog("STATUS", msg); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
619 ui->statusbar->showMessage(msg); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
620 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
621 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
622 |
122 | 623 // |
98 | 624 // Window scale / zoom changing |
625 // | |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
626 void SyntilistaMainWindow::changeUIZoomIn() |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
627 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
628 settings.uiScale += 0.1f; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
629 slSetCommonStyleSheet(this); |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
630 } |
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
631 |
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
632 |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
633 void SyntilistaMainWindow::changeUIZoomOut() |
34
87f098892804
Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
634 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
635 settings.uiScale -= 0.1f; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
636 slSetCommonStyleSheet(this); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
637 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
638 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
639 |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
640 void SyntilistaMainWindow::changeUIZoomReset() |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
641 { |
135
45e17cdde93a
Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
642 settings.uiScale = 1.0f; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
643 slSetCommonStyleSheet(this); |
46
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
644 } |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
645 |
372c1be58996
Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
44
diff
changeset
|
646 |
98 | 647 // |
648 // Slot for changed selection of person entry | |
649 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
650 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
|
651 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
652 (void) prev; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
653 int row = curr.row(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
654 if (row >= 0) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
655 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
656 const QAbstractItemModel *model = curr.model(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
657 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
|
658 focusDebtEdit(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
659 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
660 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
661 setActivePerson(-1); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
662 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
663 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
664 |
122 | 665 // |
666 // Set currently active person to given SQL id | |
667 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
668 void SyntilistaMainWindow::setActivePerson(qint64 id) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
669 { |
5 | 670 currPerson.id = id; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
671 |
1
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
672 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
|
673 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
674 if (id >= 0) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
675 { |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
676 if (!slGetPersonInfo(id, currPerson)) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
677 { |
5 | 678 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
|
679 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
680 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
681 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
682 ui->personGB->setEnabled(true); |
5 | 683 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
|
684 |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
685 ui->label_BalanceValue->setText(slMoneyValueToStr(currPerson.balance)); |
5 | 686 ui->label_BalanceValue->setStyleSheet(currPerson.balance < 0 ? "color: red;" : "color: green;"); |
687 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
|
688 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
689 QSqlQuery query; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
690 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
|
691 query.addBindValue(id); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
692 query.exec(); |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
693 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
|
694 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 model_Latest->setQuery(query); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
696 |
5 | 697 model_Latest->setHeaderData(0, Qt::Horizontal, tr("ID")); |
698 model_Latest->setHeaderData(1, Qt::Horizontal, tr("Summa")); | |
699 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
|
700 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
701 ui->tableview_Latest->setModel(model_Latest); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
702 ui->tableview_Latest->setColumnHidden(0, true); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
703 ui->tableview_Latest->verticalHeader()->setVisible(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
704 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
705 |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
706 slSetCommonStyleSheet(this); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 return; // Ugly |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
708 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
709 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
710 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
711 // In case of id < 0 or errors .. |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
712 ui->personGB->setEnabled(false); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
713 ui->edit_Amount->clear(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
714 ui->label_BalanceValue->setText("--"); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
715 ui->label_BalanceValue->setStyleSheet(NULL); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
716 ui->label_PersonName->setText("???"); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
717 ui->tableview_Latest->setModel(NULL); |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
718 slSetCommonStyleSheet(this); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
719 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
720 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
721 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
722 // |
98 | 723 // 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
|
724 // |
98 | 725 void SyntilistaMainWindow::updateSortOrder(int index, Qt::SortOrder order) |
726 { | |
727 peopleSortIndex = index; | |
728 peopleSortOrder = order; | |
729 updatePersonList(); | |
730 } | |
731 | |
732 | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
733 void SyntilistaMainWindow::on_button_Quit_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
734 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
735 close(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 |
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
|
739 void SyntilistaMainWindow::on_button_About_clicked() |
47 | 740 { |
90
efab68769c75
Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
741 new AboutWindow(this); |
74 | 742 } |
743 | |
744 | |
218
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
745 void SyntilistaMainWindow::on_button_ViewTransactions_clicked() |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
746 { |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
747 new ViewTransactions(this); |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
748 } |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
749 |
c3f47d489097
Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
750 |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
751 void SyntilistaMainWindow::on_button_DeletePerson_clicked() |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
752 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
753 if (currPerson.id <= 0) |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
754 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
755 statusMsg(tr("Ei valittua henkilöä!")); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
756 return; |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
757 } |
19 | 758 |
196 | 759 // 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
|
760 SLPersonInfo info; |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
761 if (!slGetPersonInfo(currPerson.id, info)) |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
762 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
763 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
|
764 return; |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
765 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
766 |
196 | 767 // Ask for confirmation |
18 | 768 QMessageBox dlg; |
132
dc9fe580da42
Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
769 slSetCommonStyleSheet(&dlg); |
18 | 770 dlg.setText(tr("Varmistus")); |
201 | 771 dlg.setInformativeText(tr( |
772 "<h3>Haluatko varmasti poistaa henkilön:</h3>" | |
18 | 773 "<br>" |
774 "<b>'%1, %2'</b> <i>(ID #%3)</i>?<br>" | |
775 "<br>" | |
186
cc3d7745e798
Cosmetic adjustments to the delete person confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
776 "<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
|
777 "<br>"). |
18 | 778 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
|
779 |
18 | 780 dlg.setTextFormat(Qt::RichText); |
781 dlg.setIcon(QMessageBox::Question); | |
782 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); | |
71 | 783 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä")); |
784 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta")); | |
18 | 785 dlg.setDefaultButton(QMessageBox::No); |
786 | |
787 if (dlg.exec() == QMessageBox::Yes) | |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
788 { |
13 | 789 int rv = model_People->deletePerson(info.id); |
14 | 790 updatePersonList(); |
24
0e0948aec438
De-select active person when deleting.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
791 setActivePerson(-1); |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
792 if (rv != 0) |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
793 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
794 slErrorMsg(tr("SQL-tietokantavirhe"), |
6
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
795 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1."). |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
796 arg(rv)); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
797 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
798 else |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
799 { |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
800 statusMsg(tr("Henkilö '%1 %2' (ID #%3) poistettu."). |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
801 arg(info.firstName).arg(info.lastName). |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
802 arg(info.id)); |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
803 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
804 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
805 } |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
806 |
0315a3b9f560
Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
807 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
808 void SyntilistaMainWindow::on_button_AddPerson_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
810 EditPerson *person = new EditPerson(this); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
811 person->setPerson(-1); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
812 } |
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 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
815 void SyntilistaMainWindow::on_button_EditPerson_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
816 { |
5 | 817 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
|
818 { |
db8f47446713
Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
819 EditPerson *person = new EditPerson(this); |
5 | 820 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
|
821 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
822 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
823 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
824 |
249
cfaf03d8d23e
Disable doubleclick edit of users for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
248
diff
changeset
|
825 /* |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
826 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
|
827 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
828 int row = curr.row(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
829 if (row >= 0) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
830 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
831 const QAbstractItemModel *model = curr.model(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
832 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
|
833 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
834 EditPerson *person = new EditPerson(this); |
5 | 835 person->setPerson(currPerson.id); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
836 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
837 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
838 setActivePerson(-1); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
839 } |
249
cfaf03d8d23e
Disable doubleclick edit of users for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
248
diff
changeset
|
840 */ |
0
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 void SyntilistaMainWindow::on_button_ClearFilter_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
844 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
845 ui->edit_PersonFilter->clear(); |
65 | 846 ui->edit_PersonFilter->setFocus(Qt::ShortcutFocusReason); |
847 } | |
848 | |
849 | |
850 void SyntilistaMainWindow::focusDebtEdit() | |
851 { | |
852 if (currPerson.id >= 0) | |
853 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason); | |
854 } | |
855 | |
856 | |
211
6585cac42b75
Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
857 void SyntilistaMainWindow::changeSelectedRow(const int delta) |
65 | 858 { |
859 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
|
860 int prow = sel->currentIndex().row(); |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
861 int nrow = prow + delta; |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
862 if (nrow < 0) |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
863 nrow = 0; |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
864 else |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
865 if (nrow >= model_People->rowCount()) |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
866 nrow = model_People->rowCount() - 1; |
65 | 867 |
209
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
868 if (nrow != prow) |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
869 { |
212 | 870 // 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
|
871 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
|
872 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
|
873 |
212 | 874 // The column must be a visible one (not set "hidden", as the ID field is) |
875 // 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
|
876 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
|
877 } |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
878 } |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
879 |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
880 |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
881 void SyntilistaMainWindow::selectRowPrev() |
6f404158ce8c
Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
882 { |
211
6585cac42b75
Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
883 changeSelectedRow(-1); |
65 | 884 } |
885 | |
886 | |
887 void SyntilistaMainWindow::selectRowNext() | |
888 { | |
211
6585cac42b75
Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
889 changeSelectedRow(1); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
890 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
891 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
892 |
4 | 893 // |
894 // Update visible person list/query based on the current | |
895 // filtering and sorting settings. | |
896 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
897 void SyntilistaMainWindow::updatePersonList() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
898 { |
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
|
899 static const QString queryBase = |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
900 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
|
901 "(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
|
902 "updated FROM people"); |
16 | 903 |
4 | 904 QString queryOrderDir, queryOrderBy; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
905 |
4 | 906 // Sort order |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
907 if (peopleSortOrder == Qt::AscendingOrder) |
4 | 908 queryOrderDir = QStringLiteral("ASC"); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
909 else |
4 | 910 queryOrderDir = QStringLiteral("DESC"); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
911 |
4 | 912 // Sort by which column |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
913 switch (peopleSortIndex) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
914 { |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
915 case 1: |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
916 case 2: |
196 | 917 queryOrderBy = |
918 QStringLiteral(" ORDER BY last_name ") + queryOrderDir + | |
919 QStringLiteral(",first_name ") + queryOrderDir; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
920 break; |
19 | 921 |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
922 case 3: |
196 | 923 queryOrderBy = |
924 QStringLiteral(" ORDER BY balance ") + queryOrderDir; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
925 break; |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
926 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
927 case 4: |
196 | 928 queryOrderBy = |
929 QStringLiteral(" ORDER BY updated ") + queryOrderDir; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
930 break; |
19 | 931 |
4 | 932 default: |
933 queryOrderBy = ""; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
934 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
935 |
4 | 936 // Are we filtering or not? |
126 | 937 QSqlQuery query; |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
938 if (peopleFilter != "") |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
939 { |
4 | 940 // Filter by name(s) |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
941 QString tmp = "%"+ peopleFilter +"%"; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
942 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
|
943 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
944 query.addBindValue(tmp); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
945 query.addBindValue(tmp); |
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 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
948 { |
4 | 949 // No filter |
16 | 950 query.prepare(queryBase + queryOrderBy); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
951 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
952 |
4 | 953 // Execute the query and update model |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
954 slCheckAndReportSQLError("updatePersonList() before exec", query.lastError()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
955 query.exec(); |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
956 slCheckAndReportSQLError("updatePersonList() after exec", query.lastError()); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
957 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
958 model_People->setQuery(query); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
959 |
5 | 960 model_People->setHeaderData(0, Qt::Horizontal, tr("ID")); |
961 model_People->setHeaderData(1, Qt::Horizontal, tr("Sukunimi")); | |
962 model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi")); | |
963 model_People->setHeaderData(3, Qt::Horizontal, tr("Tase")); | |
964 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
|
965 |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
966 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
|
967 } |
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
|
968 |
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
|
969 |
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
|
970 // |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
971 // 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
|
972 // |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
973 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
|
974 { |
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
|
975 // 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
|
976 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
|
977 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
|
978 query.exec(); |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
979 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
|
980 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
|
981 { |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
982 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
|
983 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
|
984 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
|
985 } |
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
|
986 |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
987 // Update number of people |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
988 query.finish(); |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
989 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
|
990 query.exec(); |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
991 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
|
992 query.next()) |
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
993 { |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
994 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
|
995 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
|
996 } |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
997 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
998 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
999 |
4 | 1000 // |
1001 // Update the list of people when filter parameter changes | |
1002 // | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1003 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
|
1004 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1005 peopleFilter = slCleanupStr(str); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1006 updatePersonList(); |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1007 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1008 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1009 |
4 | 1010 // |
1011 // Add one transaction to given person id | |
1012 // | |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1013 int SyntilistaMainWindow::addTransaction(qint64 id, double value, SLPersonInfo &info) |
4 | 1014 { |
179 | 1015 // Sanity check: Check if the given person ID exists |
102
064138b6d34e
Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
1016 if (!slGetPersonInfo(id, info)) |
4 | 1017 return -1; |
1018 | |
1019 QSqlDatabase::database().transaction(); | |
1020 | |
179 | 1021 // Add transaction entry |
4 | 1022 QSqlQuery query; |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1023 query.prepare(QStringLiteral("INSERT INTO transactions (person,value,added) VALUES (?,?,?)")); |
4 | 1024 query.addBindValue(id); |
1025 query.addBindValue(value); | |
1026 query.addBindValue(QDateTime::currentDateTimeUtc()); | |
1027 query.exec(); | |
126 | 1028 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
|
1029 { |
4 | 1030 QSqlDatabase::database().rollback(); |
1031 return -2; | |
1032 } | |
1033 | |
179 | 1034 // Update person record timestamp |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1035 query.prepare(QStringLiteral("UPDATE people SET updated=? WHERE id=?")); |
4 | 1036 query.addBindValue(QDateTime::currentDateTimeUtc()); |
1037 query.addBindValue(id); | |
1038 query.exec(); | |
126 | 1039 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError(), true)) |
4 | 1040 { |
1041 QSqlDatabase::database().rollback(); | |
1042 return -3; | |
1043 } | |
1044 | |
1045 QSqlDatabase::database().commit(); | |
1046 | |
145
9f3c0a99bcb1
Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
1047 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
|
1048 |
4 | 1049 return 0; |
1050 } | |
1051 | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1052 |
4 | 1053 int SyntilistaMainWindow::addTransactionGUI(qint64 id, bool debt, double value) |
1054 { | |
174
636a24c76232
Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
1055 SLPersonInfo info; |
4 | 1056 |
8 | 1057 // Check if person is selected |
4 | 1058 if (id <= 0) |
1059 return -1; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1060 |
8 | 1061 // Check value |
4 | 1062 if (value == 0) |
1063 { | |
202
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1064 QString tmp = debt ? tr("lisätty") : tr("vähennetty"); |
4e25db3327a7
Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents:
201
diff
changeset
|
1065 statusMsg(tr("Velkaa ei %1 koska summaa ei määritetty.").arg(tmp)); |
4 | 1066 return 1; |
1067 } | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1068 |
8 | 1069 // Perform transaction insert |
4 | 1070 int ret = addTransaction(id, debt ? -value : value, info); |
1071 if (ret == 0) | |
1072 { | |
8 | 1073 // 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
|
1074 ui->edit_Amount->clear(); |
12 | 1075 if (info.id == currPerson.id) |
1076 setActivePerson(info.id); | |
19 | 1077 |
12 | 1078 model_People->updateModel(); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1079 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1080 if (debt) |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1081 { |
196 | 1082 // Debt was added |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1083 statusMsg( |
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1084 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
|
1085 arg(slMoneyValueToStr(value)). |
4 | 1086 arg(info.firstName). |
1087 arg(info.lastName). | |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1088 arg(info.id)); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1089 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1090 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1091 { |
196 | 1092 // Debt was reduced |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1093 statusMsg( |
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1094 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
|
1095 arg(slMoneyValueToStr(value)). |
4 | 1096 arg(info.firstName). |
1097 arg(info.lastName). | |
216
8b9d55fb8988
Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
213
diff
changeset
|
1098 arg(info.id)); |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1099 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1100 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1101 else |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1102 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1103 slErrorMsg( |
8 | 1104 tr("SQL-tietokantavirhe"), |
1105 tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1."). | |
1106 arg(ret)); | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1107 } |
4 | 1108 |
1109 return ret; | |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1110 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1111 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1112 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1113 void SyntilistaMainWindow::on_button_AddDebt_clicked() |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1114 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1115 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
|
1116 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1117 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1118 |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1119 void SyntilistaMainWindow::on_button_PayDebt_clicked() |
0
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1120 { |
99
7b8755801111
Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1121 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
|
1122 } |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1123 |
fec4d0c461f2
Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1124 |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1125 void SyntilistaMainWindow::on_button_PayFullDebt_clicked() |
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1126 { |
196 | 1127 // 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
|
1128 if (currPerson.id <= 0) |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1129 { |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1130 statusMsg(tr("Ei valittua henkilöä!")); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1131 return; |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1132 } |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1133 |
196 | 1134 // Check the balance .. |
5 | 1135 if (currPerson.balance < 0) |
187
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1136 { |
196 | 1137 // 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
|
1138 QMessageBox dlg; |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1139 slSetCommonStyleSheet(&dlg); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1140 dlg.setText(tr("Varmistus")); |
201 | 1141 dlg.setInformativeText(tr( |
1142 "<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
|
1143 "<br>" |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1144 "<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
|
1145 "<br>"). |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1146 arg(currPerson.lastName).arg(currPerson.firstName). |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1147 arg(slMoneyValueToStr(currPerson.balance))); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1148 |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1149 dlg.setTextFormat(Qt::RichText); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1150 dlg.setIcon(QMessageBox::Question); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1151 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1152 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä")); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1153 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta")); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1154 dlg.setDefaultButton(QMessageBox::No); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1155 |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1156 if (dlg.exec() == QMessageBox::Yes) |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1157 { |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1158 addTransactionGUI(currPerson.id, false, -currPerson.balance); |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1159 } |
7f0a4d5010d1
Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
1160 } |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1161 else |
8 | 1162 { |
1163 statusMsg( | |
1164 tr("Valitulla henkilöllä '%1, %2' ei ole velkaa."). | |
1165 arg(currPerson.lastName). | |
1166 arg(currPerson.firstName)); | |
1167 } | |
2
edc1e8cf6e2c
Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
1168 } |