Merge lp:~fredoust/sudoku-app/profiles into lp:sudoku-app
- profiles
- Merge into trunk
Proposed by
Frédéric Delgado
Status: | Merged |
---|---|
Approved by: | Dinko Osmankovic |
Approved revision: | 66 |
Merged at revision: | 67 |
Proposed branch: | lp:~fredoust/sudoku-app/profiles |
Merge into: | lp:sudoku-app |
Diff against target: |
755 lines (+547/-42) 6 files modified
components/AddProfileDialog.qml (+97/-0) components/ManageProfileDialog.qml (+115/-0) components/SudokuDialogButton.qml (+3/-3) js/SudokuCU.js (+0/-7) js/localStorage.js (+112/-0) sudoku-app.qml (+220/-32) |
To merge this branch: | bzr merge lp:~fredoust/sudoku-app/profiles |
Related bugs: | |
Related blueprints: |
User profiles in Sudoku app
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Dinko Osmankovic | Approve | ||
Review via email: mp+173681@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Dinko Osmankovic (dinko-metalac) : | # |
review:
Approve
lp:~fredoust/sudoku-app/profiles
updated
- 67. By Frédéric Delgado
-
Clean code
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'components/AddProfileDialog.qml' | |||
2 | --- components/AddProfileDialog.qml 1970-01-01 00:00:00 +0000 | |||
3 | +++ components/AddProfileDialog.qml 2013-07-09 09:59:26 +0000 | |||
4 | @@ -0,0 +1,97 @@ | |||
5 | 1 | import QtQuick 2.0 | ||
6 | 2 | import Ubuntu.Components 0.1 | ||
7 | 3 | import Ubuntu.Components.Popups 0.1 | ||
8 | 4 | import "../js/localStorage.js" as Settings | ||
9 | 5 | import QtQuick.LocalStorage 2.0 | ||
10 | 6 | |||
11 | 7 | Component { | ||
12 | 8 | id: addProfileDialog | ||
13 | 9 | |||
14 | 10 | Dialog { | ||
15 | 11 | id: addProfileDialogue | ||
16 | 12 | title: i18n.tr("Add new profile") | ||
17 | 13 | width: parent.width | ||
18 | 14 | |||
19 | 15 | |||
20 | 16 | Column { | ||
21 | 17 | width: parent.width | ||
22 | 18 | spacing: units.gu(2) | ||
23 | 19 | |||
24 | 20 | Rectangle{ | ||
25 | 21 | width: units.gu(25) | ||
26 | 22 | height: units.gu(4) | ||
27 | 23 | radius: 9 | ||
28 | 24 | anchors.horizontalCenter: parent.horizontalCenter | ||
29 | 25 | TextField { | ||
30 | 26 | id:lastnameField | ||
31 | 27 | |||
32 | 28 | placeholderText: i18n.tr("Lastname") | ||
33 | 29 | |||
34 | 30 | } | ||
35 | 31 | } | ||
36 | 32 | Rectangle{ | ||
37 | 33 | width: units.gu(25) | ||
38 | 34 | height: units.gu(4) | ||
39 | 35 | radius: 9 | ||
40 | 36 | anchors.horizontalCenter: parent.horizontalCenter | ||
41 | 37 | TextField { | ||
42 | 38 | id:firstnameField | ||
43 | 39 | anchors.horizontalCenter: parent.horizontalCenter | ||
44 | 40 | placeholderText: i18n.tr("Firstname") | ||
45 | 41 | } | ||
46 | 42 | } | ||
47 | 43 | |||
48 | 44 | |||
49 | 45 | Row{ | ||
50 | 46 | width: parent.width | ||
51 | 47 | spacing: units.gu(1) | ||
52 | 48 | |||
53 | 49 | SudokuDialogButton{ | ||
54 | 50 | id:okButton | ||
55 | 51 | buttonText: i18n.tr("OK") | ||
56 | 52 | width: parent.width/2; | ||
57 | 53 | size: units.gu(5) | ||
58 | 54 | onTriggered: { | ||
59 | 55 | |||
60 | 56 | if(lastnameField.text!="" && firstnameField.text!="") | ||
61 | 57 | { | ||
62 | 58 | |||
63 | 59 | if(!Settings.existProfile(lastnameField.text, firstnameField.text)) | ||
64 | 60 | { | ||
65 | 61 | |||
66 | 62 | Settings.insertProfile(lastnameField.text, firstnameField.text); | ||
67 | 63 | PopupUtils.close(addProfileDialogue) | ||
68 | 64 | }else{ | ||
69 | 65 | mainView.showAlert(i18n.tr("Warning"), i18n.tr("User already exist."), okButton) | ||
70 | 66 | } | ||
71 | 67 | |||
72 | 68 | |||
73 | 69 | } else{ | ||
74 | 70 | mainView.showAlert(i18n.tr("Warning"), i18n.tr("Lastname and firstname must not be empty."), okButton) | ||
75 | 71 | } | ||
76 | 72 | |||
77 | 73 | |||
78 | 74 | |||
79 | 75 | |||
80 | 76 | |||
81 | 77 | } | ||
82 | 78 | } | ||
83 | 79 | |||
84 | 80 | SudokuDialogButton{ | ||
85 | 81 | buttonText: i18n.tr("Cancel") | ||
86 | 82 | width: parent.width/2; | ||
87 | 83 | size: units.gu(5) | ||
88 | 84 | onTriggered: { | ||
89 | 85 | PopupUtils.close(addProfileDialogue) | ||
90 | 86 | } | ||
91 | 87 | } | ||
92 | 88 | } | ||
93 | 89 | |||
94 | 90 | |||
95 | 91 | |||
96 | 92 | } | ||
97 | 93 | |||
98 | 94 | |||
99 | 95 | } | ||
100 | 96 | } | ||
101 | 97 | |||
102 | 0 | 98 | ||
103 | === added file 'components/ManageProfileDialog.qml' | |||
104 | --- components/ManageProfileDialog.qml 1970-01-01 00:00:00 +0000 | |||
105 | +++ components/ManageProfileDialog.qml 2013-07-09 09:59:26 +0000 | |||
106 | @@ -0,0 +1,115 @@ | |||
107 | 1 | import QtQuick 2.0 | ||
108 | 2 | import Ubuntu.Components 0.1 | ||
109 | 3 | import Ubuntu.Components.Popups 0.1 | ||
110 | 4 | import "../js/localStorage.js" as Settings | ||
111 | 5 | import QtQuick.LocalStorage 2.0 | ||
112 | 6 | |||
113 | 7 | Component { | ||
114 | 8 | id: editProfileDialog | ||
115 | 9 | |||
116 | 10 | Dialog { | ||
117 | 11 | id: editProfileDialogue | ||
118 | 12 | title: i18n.tr("Edit profile") | ||
119 | 13 | width: parent.width | ||
120 | 14 | |||
121 | 15 | |||
122 | 16 | Column { | ||
123 | 17 | width: parent.width | ||
124 | 18 | spacing: units.gu(2) | ||
125 | 19 | |||
126 | 20 | Rectangle{ | ||
127 | 21 | width: 200 | ||
128 | 22 | height: 32 | ||
129 | 23 | radius: 9 | ||
130 | 24 | anchors.horizontalCenter: parent.horizontalCenter | ||
131 | 25 | TextField { | ||
132 | 26 | id:lastnameField | ||
133 | 27 | text: Settings.getUserLastName(editUserId) | ||
134 | 28 | placeholderText: i18n.tr("Lastname") | ||
135 | 29 | |||
136 | 30 | } | ||
137 | 31 | } | ||
138 | 32 | Rectangle{ | ||
139 | 33 | width: 200 | ||
140 | 34 | height: 32 | ||
141 | 35 | radius: 9 | ||
142 | 36 | anchors.horizontalCenter: parent.horizontalCenter | ||
143 | 37 | TextField { | ||
144 | 38 | id:firstnameField | ||
145 | 39 | anchors.horizontalCenter: parent.horizontalCenter | ||
146 | 40 | placeholderText: i18n.tr("Firstname") | ||
147 | 41 | text: Settings.getUserFirstName(editUserId) | ||
148 | 42 | } | ||
149 | 43 | } | ||
150 | 44 | |||
151 | 45 | |||
152 | 46 | Row{ | ||
153 | 47 | width: parent.width | ||
154 | 48 | spacing: units.gu(1) | ||
155 | 49 | |||
156 | 50 | SudokuDialogButton{ | ||
157 | 51 | id:okButton | ||
158 | 52 | buttonText: i18n.tr("OK") | ||
159 | 53 | width: parent.width/2; | ||
160 | 54 | size: units.gu(5) | ||
161 | 55 | onTriggered: { | ||
162 | 56 | |||
163 | 57 | if(lastnameField.text!="" && firstnameField.text!="") | ||
164 | 58 | { | ||
165 | 59 | |||
166 | 60 | if(!Settings.existProfile( lastnameField.text, firstnameField.text)) | ||
167 | 61 | { | ||
168 | 62 | |||
169 | 63 | Settings.updateProfile(editUserId, lastnameField.text, firstnameField.text); | ||
170 | 64 | var userId = currentUserId | ||
171 | 65 | currentUserId = -1 | ||
172 | 66 | currentUserId = userId | ||
173 | 67 | |||
174 | 68 | PopupUtils.close(editProfileDialogue) | ||
175 | 69 | }else{ | ||
176 | 70 | PopupUtils.close(editProfileDialogue) | ||
177 | 71 | } | ||
178 | 72 | |||
179 | 73 | |||
180 | 74 | } else{ | ||
181 | 75 | mainView.showAlert(i18n.tr("Warning"), i18n.tr("Lastname and firstname must not be empty."), okButton) | ||
182 | 76 | } | ||
183 | 77 | |||
184 | 78 | |||
185 | 79 | |||
186 | 80 | |||
187 | 81 | |||
188 | 82 | } | ||
189 | 83 | } | ||
190 | 84 | |||
191 | 85 | SudokuDialogButton{ | ||
192 | 86 | buttonText: i18n.tr("Delete") | ||
193 | 87 | width: parent.width/2; | ||
194 | 88 | size: units.gu(5) | ||
195 | 89 | onTriggered: { | ||
196 | 90 | Settings.deleteProfile(editUserId) | ||
197 | 91 | if(editUserId == currentUserId) | ||
198 | 92 | currentUserId = -1 | ||
199 | 93 | |||
200 | 94 | |||
201 | 95 | PopupUtils.close(editProfileDialogue) | ||
202 | 96 | } | ||
203 | 97 | } | ||
204 | 98 | } | ||
205 | 99 | SudokuDialogButton{ | ||
206 | 100 | anchors.horizontalCenter: parent.horizontalCenter | ||
207 | 101 | buttonText: i18n.tr("Cancel") | ||
208 | 102 | width: parent.width/2; | ||
209 | 103 | size: units.gu(5) | ||
210 | 104 | onTriggered: { | ||
211 | 105 | PopupUtils.close(editProfileDialogue) | ||
212 | 106 | } | ||
213 | 107 | } | ||
214 | 108 | |||
215 | 109 | |||
216 | 110 | } | ||
217 | 111 | |||
218 | 112 | |||
219 | 113 | } | ||
220 | 114 | } | ||
221 | 115 | |||
222 | 0 | 116 | ||
223 | === modified file 'components/SudokuDialogButton.qml' | |||
224 | --- components/SudokuDialogButton.qml 2013-07-05 21:36:31 +0000 | |||
225 | +++ components/SudokuDialogButton.qml 2013-07-09 09:59:26 +0000 | |||
226 | @@ -3,9 +3,9 @@ | |||
227 | 3 | 3 | ||
228 | 4 | SudokuButton { | 4 | SudokuButton { |
229 | 5 | id: dialogButton | 5 | id: dialogButton |
231 | 6 | border.color: defaultBorderColor | 6 | border.color: sudokuBlocksGrid.defaultBorderColor |
232 | 7 | //border.width: 3 | 7 | //border.width: 3 |
234 | 8 | textColor: defaultTextColor; | 8 | textColor: sudokuBlocksGrid.defaultTextColor; |
235 | 9 | 9 | ||
236 | 10 | signal triggered; | 10 | signal triggered; |
237 | 11 | 11 | ||
238 | @@ -43,5 +43,5 @@ | |||
239 | 43 | animateDialogButton.start(); | 43 | animateDialogButton.start(); |
240 | 44 | } | 44 | } |
241 | 45 | } | 45 | } |
243 | 46 | buttonColor: buttonMouseArea.pressed ? String(Qt.darker(defaultColor,1.2)):defaultColor | 46 | buttonColor: buttonMouseArea.pressed ? String(Qt.darker(sudokuBlocksGrid.defaultColor,1.2)):sudokuBlocksGrid.defaultColor |
244 | 47 | } | 47 | } |
245 | 48 | 48 | ||
246 | === modified file 'js/SudokuCU.js' | |||
247 | --- js/SudokuCU.js 2013-07-03 17:08:32 +0000 | |||
248 | +++ js/SudokuCU.js 2013-07-09 09:59:26 +0000 | |||
249 | @@ -159,20 +159,17 @@ | |||
250 | 159 | if(value == 0) | 159 | if(value == 0) |
251 | 160 | return false; | 160 | return false; |
252 | 161 | 161 | ||
253 | 162 | console.log("test for "+value) | ||
254 | 163 | for(var i = 0; i < 9; i++) | 162 | for(var i = 0; i < 9; i++) |
255 | 164 | { | 163 | { |
256 | 165 | console.log("test with col"+this.rows[i][column]) | 164 | console.log("test with col"+this.rows[i][column]) |
257 | 166 | if(i != row && this.rows[i][column] == value) | 165 | if(i != row && this.rows[i][column] == value) |
258 | 167 | { | 166 | { |
259 | 168 | console.log("find row") | ||
260 | 169 | return true; | 167 | return true; |
261 | 170 | } | 168 | } |
262 | 171 | 169 | ||
263 | 172 | // console.log("test with row"+this.rows[row][i]) | 170 | // console.log("test with row"+this.rows[row][i]) |
264 | 173 | if(i != column && this.rows[row][i] == value) | 171 | if(i != column && this.rows[row][i] == value) |
265 | 174 | { | 172 | { |
266 | 175 | console.log("find col") | ||
267 | 176 | return true; | 173 | return true; |
268 | 177 | } | 174 | } |
269 | 178 | } | 175 | } |
270 | @@ -209,8 +206,6 @@ | |||
271 | 209 | if(value == 0) | 206 | if(value == 0) |
272 | 210 | continue; | 207 | continue; |
273 | 211 | 208 | ||
274 | 212 | console.log("test minigrid "+value) | ||
275 | 213 | |||
276 | 214 | //if(App.Utils.arrayContains(numbers, value)) | 209 | //if(App.Utils.arrayContains(numbers, value)) |
277 | 215 | // return false; | 210 | // return false; |
278 | 216 | if (numbers.indexOf(value) != -1 ) | 211 | if (numbers.indexOf(value) != -1 ) |
279 | @@ -252,8 +247,6 @@ | |||
280 | 252 | if(value == 0) | 247 | if(value == 0) |
281 | 253 | continue; | 248 | continue; |
282 | 254 | 249 | ||
283 | 255 | console.log("test minigrid "+value) | ||
284 | 256 | |||
285 | 257 | //if(App.Utils.arrayContains(numbers, value)) | 250 | //if(App.Utils.arrayContains(numbers, value)) |
286 | 258 | // return false; | 251 | // return false; |
287 | 259 | if (numbers.indexOf(value) != -1 && value == val) | 252 | if (numbers.indexOf(value) != -1 && value == val) |
288 | 260 | 253 | ||
289 | === modified file 'js/localStorage.js' | |||
290 | --- js/localStorage.js 2013-07-06 06:18:26 +0000 | |||
291 | +++ js/localStorage.js 2013-07-09 09:59:26 +0000 | |||
292 | @@ -12,14 +12,19 @@ | |||
293 | 12 | // Create the settings table if it doesn't already exist | 12 | // Create the settings table if it doesn't already exist |
294 | 13 | // If the table exists, this is skipped | 13 | // If the table exists, this is skipped |
295 | 14 | tx.executeSql('PRAGMA foreign_keys = ON;'); | 14 | tx.executeSql('PRAGMA foreign_keys = ON;'); |
296 | 15 | |||
297 | 16 | |||
298 | 15 | tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)'); | 17 | tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)'); |
299 | 16 | print("setting table created.") | 18 | print("setting table created.") |
300 | 17 | tx.executeSql('CREATE TABLE IF NOT EXISTS profiles(id INTEGER PRIMARY KEY AUTOINCREMENT, first_name TEXT, last_name TEXT, UNIQUE(first_name, last_name) ON CONFLICT ROLLBACK)'); | 19 | tx.executeSql('CREATE TABLE IF NOT EXISTS profiles(id INTEGER PRIMARY KEY AUTOINCREMENT, first_name TEXT, last_name TEXT, UNIQUE(first_name, last_name) ON CONFLICT ROLLBACK)'); |
301 | 18 | print("profile table created.") | 20 | print("profile table created.") |
302 | 21 | |||
303 | 19 | tx.executeSql('INSERT OR IGNORE INTO profiles VALUES (null,?,?);', ["Sudoku","User"]); | 22 | tx.executeSql('INSERT OR IGNORE INTO profiles VALUES (null,?,?);', ["Sudoku","User"]); |
304 | 20 | tx.executeSql('CREATE TABLE IF NOT EXISTS scores(id INTEGER PRIMARY KEY AUTOINCREMENT, profile_id INTEGER, score INTEGER NOT NULL, game_date DATE, FOREIGN KEY(profile_id) REFERENCES profiles(id))'); | 23 | tx.executeSql('CREATE TABLE IF NOT EXISTS scores(id INTEGER PRIMARY KEY AUTOINCREMENT, profile_id INTEGER, score INTEGER NOT NULL, game_date DATE, FOREIGN KEY(profile_id) REFERENCES profiles(id))'); |
305 | 21 | print("scores table created.") | 24 | print("scores table created.") |
306 | 22 | 25 | ||
307 | 26 | |||
308 | 27 | |||
309 | 23 | }); | 28 | }); |
310 | 24 | } | 29 | } |
311 | 25 | function setSetting(setting, value) { | 30 | function setSetting(setting, value) { |
312 | @@ -113,6 +118,113 @@ | |||
313 | 113 | return res; | 118 | return res; |
314 | 114 | } | 119 | } |
315 | 115 | 120 | ||
316 | 121 | function printObject(o) | ||
317 | 122 | { | ||
318 | 123 | var out = ''; | ||
319 | 124 | for(var p in o){ | ||
320 | 125 | out+=p+': '+o[p]+'\n'; | ||
321 | 126 | } | ||
322 | 127 | console.log(out) | ||
323 | 128 | } | ||
324 | 129 | |||
325 | 130 | function getAllProfiles() | ||
326 | 131 | { | ||
327 | 132 | var db = getDatabase(); | ||
328 | 133 | var res=new Array(); | ||
329 | 134 | |||
330 | 135 | print("GETTING ALL PROFILES") | ||
331 | 136 | db.transaction( function(tx) { | ||
332 | 137 | var rs = tx.executeSql("SELECT * FROM profiles limit 10;"); | ||
333 | 138 | for(var i = 0; i < rs.rows.length; i++) { | ||
334 | 139 | var dbItem = rs.rows.item(i); | ||
335 | 140 | var o = new Object(); | ||
336 | 141 | o["id"] = dbItem.id; | ||
337 | 142 | o["lastname"] = dbItem.last_name; | ||
338 | 143 | o["firstname"] = dbItem.first_name; | ||
339 | 144 | res.push(o) | ||
340 | 145 | } | ||
341 | 146 | }); | ||
342 | 147 | print(res); | ||
343 | 148 | return res; | ||
344 | 149 | } | ||
345 | 150 | |||
346 | 151 | |||
347 | 152 | function deleteProfile(id) | ||
348 | 153 | { | ||
349 | 154 | |||
350 | 155 | var db = getDatabase(); | ||
351 | 156 | var res=""; | ||
352 | 157 | db.transaction(function(tx) { | ||
353 | 158 | var rs = tx.executeSql('DELETE FROM profiles WHERE id=? ;', [id]); | ||
354 | 159 | |||
355 | 160 | if (rs.rowsAffected > 0) { | ||
356 | 161 | res = "OK"; | ||
357 | 162 | } else { | ||
358 | 163 | res = "Error"; | ||
359 | 164 | } | ||
360 | 165 | } | ||
361 | 166 | ); | ||
362 | 167 | // The function returns “OK” if it was successful, or “Error” if it wasn't | ||
363 | 168 | return res; | ||
364 | 169 | } | ||
365 | 170 | |||
366 | 171 | |||
367 | 172 | function updateProfile(id, lastname, firstname) | ||
368 | 173 | { | ||
369 | 174 | |||
370 | 175 | var db = getDatabase(); | ||
371 | 176 | var res=""; | ||
372 | 177 | db.transaction(function(tx) { | ||
373 | 178 | var rs = tx.executeSql('UPDATE profiles SET first_name=?, last_name=? WHERE id=? ;', [firstname, lastname, id]); | ||
374 | 179 | |||
375 | 180 | if (rs.rowsAffected > 0) { | ||
376 | 181 | res = "OK"; | ||
377 | 182 | } else { | ||
378 | 183 | res = "Error"; | ||
379 | 184 | } | ||
380 | 185 | } | ||
381 | 186 | ); | ||
382 | 187 | // The function returns “OK” if it was successful, or “Error” if it wasn't | ||
383 | 188 | return res; | ||
384 | 189 | } | ||
385 | 190 | |||
386 | 191 | function insertProfile(lastname, firstname) | ||
387 | 192 | { | ||
388 | 193 | |||
389 | 194 | var db = getDatabase(); | ||
390 | 195 | var res=""; | ||
391 | 196 | db.transaction(function(tx) { | ||
392 | 197 | var rs = tx.executeSql('INSERT OR IGNORE INTO profiles VALUES (null,?,?);', [firstname, lastname]); | ||
393 | 198 | |||
394 | 199 | if (rs.rowsAffected > 0) { | ||
395 | 200 | res = "OK"; | ||
396 | 201 | } else { | ||
397 | 202 | res = "Error"; | ||
398 | 203 | } | ||
399 | 204 | } | ||
400 | 205 | ); | ||
401 | 206 | // The function returns “OK” if it was successful, or “Error” if it wasn't | ||
402 | 207 | return res; | ||
403 | 208 | } | ||
404 | 209 | |||
405 | 210 | function existProfile(lastname, firstname) | ||
406 | 211 | { | ||
407 | 212 | var db = getDatabase(); | ||
408 | 213 | var res=""; | ||
409 | 214 | |||
410 | 215 | db.transaction(function(tx) { | ||
411 | 216 | var rs = tx.executeSql('SELECT id FROM profiles WHERE last_name=? AND first_name=?;', [lastname, firstname]); | ||
412 | 217 | if (rs.rows.length > 0) { | ||
413 | 218 | res = true | ||
414 | 219 | } else { | ||
415 | 220 | res = false | ||
416 | 221 | } | ||
417 | 222 | }) | ||
418 | 223 | |||
419 | 224 | |||
420 | 225 | return res | ||
421 | 226 | } | ||
422 | 227 | |||
423 | 116 | function getUserFirstName(profile_id) | 228 | function getUserFirstName(profile_id) |
424 | 117 | { | 229 | { |
425 | 118 | var db = getDatabase(); | 230 | var db = getDatabase(); |
426 | 119 | 231 | ||
427 | === modified file 'sudoku-app.qml' | |||
428 | --- sudoku-app.qml 2013-07-08 09:38:32 +0000 | |||
429 | +++ sudoku-app.qml 2013-07-09 09:59:26 +0000 | |||
430 | @@ -2,6 +2,7 @@ | |||
431 | 2 | import Ubuntu.Components 0.1 | 2 | import Ubuntu.Components 0.1 |
432 | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem | 3 | import Ubuntu.Components.ListItems 0.1 as ListItem |
433 | 4 | import QtQuick.LocalStorage 2.0 | 4 | import QtQuick.LocalStorage 2.0 |
434 | 5 | import Ubuntu.Components.Popups 0.1 | ||
435 | 5 | import "js/localStorage.js" as Settings | 6 | import "js/localStorage.js" as Settings |
436 | 6 | import "components" | 7 | import "components" |
437 | 7 | 8 | ||
438 | @@ -17,12 +18,21 @@ | |||
439 | 17 | property real blockDistance: pageWidth/200; | 18 | property real blockDistance: pageWidth/200; |
440 | 18 | property bool alreadyCreated: false; | 19 | property bool alreadyCreated: false; |
441 | 19 | property bool gridLoaded: false; | 20 | property bool gridLoaded: false; |
443 | 20 | property int currentUserId: 1; | 21 | property int currentUserId: -1; |
444 | 21 | property string highscoresHeaderText: i18n.tr("<b>Best scores for all players</b>") | 22 | property string highscoresHeaderText: i18n.tr("<b>Best scores for all players</b>") |
445 | 22 | 23 | ||
446 | 24 | property string alertTitle: "" | ||
447 | 25 | property string alertText : "" | ||
448 | 26 | |||
449 | 27 | property int editUserId : -1; | ||
450 | 28 | |||
451 | 23 | width: pageWidth; | 29 | width: pageWidth; |
452 | 24 | height: pageHeight; | 30 | height: pageHeight; |
453 | 25 | 31 | ||
454 | 32 | onCurrentUserIdChanged: { | ||
455 | 33 | Settings.setSetting("currentUserId", currentUserId) | ||
456 | 34 | } | ||
457 | 35 | |||
458 | 26 | function newSize(width, height) { | 36 | function newSize(width, height) { |
459 | 27 | pageWidth = width; | 37 | pageWidth = width; |
460 | 28 | pageHeight = height; | 38 | pageHeight = height; |
461 | @@ -58,6 +68,36 @@ | |||
462 | 58 | //buttonsGridPublic.update(); | 68 | //buttonsGridPublic.update(); |
463 | 59 | } | 69 | } |
464 | 60 | 70 | ||
465 | 71 | |||
466 | 72 | Component { | ||
467 | 73 | id: alertDialog | ||
468 | 74 | Dialog { | ||
469 | 75 | id: alertDialogue | ||
470 | 76 | title: alertTitle | ||
471 | 77 | text: alertText | ||
472 | 78 | |||
473 | 79 | SudokuDialogButton{ | ||
474 | 80 | buttonText: i18n.tr("OK") | ||
475 | 81 | width: parent.width/2; | ||
476 | 82 | size: units.gu(5) | ||
477 | 83 | onTriggered: { | ||
478 | 84 | PopupUtils.close(alertDialogue) | ||
479 | 85 | } | ||
480 | 86 | } | ||
481 | 87 | |||
482 | 88 | } | ||
483 | 89 | } | ||
484 | 90 | |||
485 | 91 | function showAlert(title, text, caller) | ||
486 | 92 | { | ||
487 | 93 | alertTitle = title | ||
488 | 94 | alertText = text | ||
489 | 95 | PopupUtils.open(alertDialog, caller) | ||
490 | 96 | |||
491 | 97 | } | ||
492 | 98 | |||
493 | 99 | |||
494 | 100 | |||
495 | 61 | onHeightChanged: { | 101 | onHeightChanged: { |
496 | 62 | if (!gridLoaded) | 102 | if (!gridLoaded) |
497 | 63 | return; | 103 | return; |
498 | @@ -98,6 +138,14 @@ | |||
499 | 98 | 'lastname': lastName, | 138 | 'lastname': lastName, |
500 | 99 | 'score': rowItem[1] }); | 139 | 'score': rowItem[1] }); |
501 | 100 | } | 140 | } |
502 | 141 | |||
503 | 142 | if(Settings.getSetting("currentUserId")=="Unknown") | ||
504 | 143 | currentUserId = -1; | ||
505 | 144 | else | ||
506 | 145 | { | ||
507 | 146 | currentUserId = Settings.getSetting("currentUserId") | ||
508 | 147 | } | ||
509 | 148 | |||
510 | 101 | } | 149 | } |
511 | 102 | 150 | ||
512 | 103 | Tabs { | 151 | Tabs { |
513 | @@ -259,6 +307,7 @@ | |||
514 | 259 | SudokuBlocksGrid { | 307 | SudokuBlocksGrid { |
515 | 260 | id: sudokuBlocksGrid; | 308 | id: sudokuBlocksGrid; |
516 | 261 | } | 309 | } |
517 | 310 | |||
518 | 262 | } | 311 | } |
519 | 263 | } | 312 | } |
520 | 264 | 313 | ||
521 | @@ -364,19 +413,102 @@ | |||
522 | 364 | property alias difficultyIndex: difficultySelector.selectedIndex; | 413 | property alias difficultyIndex: difficultySelector.selectedIndex; |
523 | 365 | property alias themeIndex: themeSelector.selectedIndex; | 414 | property alias themeIndex: themeSelector.selectedIndex; |
524 | 366 | 415 | ||
525 | 416 | |||
526 | 417 | |||
527 | 367 | title: i18n.tr("Settings") | 418 | title: i18n.tr("Settings") |
539 | 368 | page: Page { | 419 | page: |
540 | 369 | /* | 420 | |
541 | 370 | tools: ToolbarActions { | 421 | Page { |
542 | 371 | 422 | ||
532 | 372 | Action { | ||
533 | 373 | iconSource: Qt.resolvedUrl("icons/close.svg") | ||
534 | 374 | text: i18n.tr("Close"); | ||
535 | 375 | onTriggered: Qt.quit() | ||
536 | 376 | } | ||
537 | 377 | } | ||
538 | 378 | */ | ||
543 | 379 | Column { | 423 | Column { |
544 | 424 | |||
545 | 425 | Component { | ||
546 | 426 | id: profileSelector | ||
547 | 427 | DefaultSheet { | ||
548 | 428 | title: i18n.tr("Select profile") | ||
549 | 429 | contentsHeight: mainView.height | ||
550 | 430 | |||
551 | 431 | /* | ||
552 | 432 | Column { | ||
553 | 433 | anchors { | ||
554 | 434 | top: parent.top | ||
555 | 435 | left: parent.left | ||
556 | 436 | right: parent.right | ||
557 | 437 | } | ||
558 | 438 | height: mainColumnSettings.height | ||
559 | 439 | |||
560 | 440 | ListItem.Header { | ||
561 | 441 | id: header | ||
562 | 442 | text: i18n.tr("Select profile") | ||
563 | 443 | } | ||
564 | 444 | */ | ||
565 | 445 | |||
566 | 446 | |||
567 | 447 | |||
568 | 448 | ListView { | ||
569 | 449 | height: mainColumnSettings.height | ||
570 | 450 | id: profileListView | ||
571 | 451 | clip: true | ||
572 | 452 | width: parent.width | ||
573 | 453 | // height: parent.height - header.height | ||
574 | 454 | model: profilesModel | ||
575 | 455 | |||
576 | 456 | delegate: | ||
577 | 457 | ListItem.Standard { | ||
578 | 458 | |||
579 | 459 | text: firstname + " " + lastname | ||
580 | 460 | progression: true | ||
581 | 461 | onTriggered: { | ||
582 | 462 | console.log("clicked "+index) | ||
583 | 463 | currentUserId = profileId; | ||
584 | 464 | hide() | ||
585 | 465 | } | ||
586 | 466 | } | ||
587 | 467 | |||
588 | 468 | } | ||
589 | 469 | } | ||
590 | 470 | // } | ||
591 | 471 | } | ||
592 | 472 | |||
593 | 473 | Component { | ||
594 | 474 | id: manageProfileSelector | ||
595 | 475 | DefaultSheet { | ||
596 | 476 | title: i18n.tr("Select profile") | ||
597 | 477 | contentsHeight: mainView.height | ||
598 | 478 | |||
599 | 479 | |||
600 | 480 | |||
601 | 481 | ListView { | ||
602 | 482 | id: manageProfileListView | ||
603 | 483 | clip: true | ||
604 | 484 | width: parent.width | ||
605 | 485 | height: mainColumnSettings.height | ||
606 | 486 | model: profilesModel | ||
607 | 487 | |||
608 | 488 | delegate: | ||
609 | 489 | |||
610 | 490 | ListItem.Standard { | ||
611 | 491 | |||
612 | 492 | text: firstname + " " + lastname | ||
613 | 493 | |||
614 | 494 | progression: true | ||
615 | 495 | onTriggered: { | ||
616 | 496 | hide() | ||
617 | 497 | editUserId = profileId | ||
618 | 498 | PopupUtils.open(manageProfileDialog, selectorProfile) | ||
619 | 499 | } | ||
620 | 500 | } | ||
621 | 501 | |||
622 | 502 | |||
623 | 503 | |||
624 | 504 | } | ||
625 | 505 | } | ||
626 | 506 | } | ||
627 | 507 | |||
628 | 508 | ListModel{ | ||
629 | 509 | id: profilesModel | ||
630 | 510 | } | ||
631 | 511 | |||
632 | 380 | id: mainColumnSettings; | 512 | id: mainColumnSettings; |
633 | 381 | //width: settingsTab.width; | 513 | //width: settingsTab.width; |
634 | 382 | //height: settingsTab.height; | 514 | //height: settingsTab.height; |
635 | @@ -460,9 +592,76 @@ | |||
636 | 460 | } | 592 | } |
637 | 461 | } | 593 | } |
638 | 462 | } | 594 | } |
639 | 595 | ListItem.Header { | ||
640 | 596 | text: i18n.tr("<b>Profiles settings</b>") | ||
641 | 597 | } | ||
642 | 598 | ListItem.SingleValue { | ||
643 | 599 | text: "Current profile" | ||
644 | 600 | id: selectorProfile | ||
645 | 601 | value: { | ||
646 | 602 | if(currentUserId==-1) | ||
647 | 603 | return i18n.tr("None") | ||
648 | 604 | else | ||
649 | 605 | return Settings.getUserFirstName(currentUserId)+" "+Settings.getUserLastName(currentUserId); | ||
650 | 606 | |||
651 | 607 | } | ||
652 | 608 | |||
653 | 609 | onClicked: { | ||
654 | 610 | |||
655 | 611 | var allProfiles = new Array(); | ||
656 | 612 | allProfiles = Settings.getAllProfiles() | ||
657 | 613 | |||
658 | 614 | profilesModel.clear() | ||
659 | 615 | |||
660 | 616 | for(var i = 0; i < allProfiles.length; i++) | ||
661 | 617 | { | ||
662 | 618 | profilesModel.append({"profileId":allProfiles[i].id,"lastname":allProfiles[i].lastname, "firstname":allProfiles[i].firstname}) | ||
663 | 619 | } | ||
664 | 620 | PopupUtils.open(profileSelector, selectorProfile) | ||
665 | 621 | } | ||
666 | 622 | } | ||
667 | 623 | |||
668 | 624 | AddProfileDialog{ | ||
669 | 625 | id:addProfileDialog | ||
670 | 626 | } | ||
671 | 627 | |||
672 | 628 | ManageProfileDialog{ | ||
673 | 629 | id:manageProfileDialog | ||
674 | 630 | } | ||
675 | 631 | |||
676 | 632 | |||
677 | 633 | ListItem.SingleValue { | ||
678 | 634 | id:addSingleValue | ||
679 | 635 | text: i18n.tr("Add profile") | ||
680 | 636 | onClicked: { | ||
681 | 637 | PopupUtils.open(addProfileDialog, addSingleValue); | ||
682 | 638 | } | ||
683 | 639 | } | ||
684 | 640 | |||
685 | 641 | ListItem.SingleValue { | ||
686 | 642 | id:manageProfileSingleValue | ||
687 | 643 | text: i18n.tr("Manage profiles") | ||
688 | 644 | onClicked: { | ||
689 | 645 | |||
690 | 646 | var allProfiles = new Array(); | ||
691 | 647 | allProfiles = Settings.getAllProfiles() | ||
692 | 648 | |||
693 | 649 | profilesModel.clear() | ||
694 | 650 | |||
695 | 651 | for(var i = 0; i < allProfiles.length; i++) | ||
696 | 652 | { | ||
697 | 653 | profilesModel.append({"profileId":allProfiles[i].id,"lastname":allProfiles[i].lastname, "firstname":allProfiles[i].firstname}) | ||
698 | 654 | } | ||
699 | 655 | |||
700 | 656 | PopupUtils.open(manageProfileSelector, manageProfileSingleValue) | ||
701 | 657 | } | ||
702 | 658 | } | ||
703 | 659 | |||
704 | 660 | |||
705 | 463 | } | 661 | } |
706 | 464 | } | 662 | } |
707 | 465 | 663 | ||
708 | 664 | |||
709 | 466 | } | 665 | } |
710 | 467 | 666 | ||
711 | 468 | Tab { | 667 | Tab { |
712 | @@ -470,18 +669,7 @@ | |||
713 | 470 | objectName: "aboutTab" | 669 | objectName: "aboutTab" |
714 | 471 | title: i18n.tr("About") | 670 | title: i18n.tr("About") |
715 | 472 | page: Page { | 671 | page: Page { |
728 | 473 | /* | 672 | |
717 | 474 | tools: ToolbarActions { | ||
718 | 475 | |||
719 | 476 | |||
720 | 477 | Action { | ||
721 | 478 | iconSource: Qt.resolvedUrl("icons/close.svg"); | ||
722 | 479 | text: i18n.tr("Close"); | ||
723 | 480 | onTriggered: Qt.quit() | ||
724 | 481 | } | ||
725 | 482 | |||
726 | 483 | } | ||
727 | 484 | */ | ||
729 | 485 | Column { | 673 | Column { |
730 | 486 | id: aboutColumn; | 674 | id: aboutColumn; |
731 | 487 | spacing: 5; | 675 | spacing: 5; |
732 | @@ -489,15 +677,15 @@ | |||
733 | 489 | anchors.horizontalCenter: parent.horizontalCenter; | 677 | anchors.horizontalCenter: parent.horizontalCenter; |
734 | 490 | y: units.gu(8); | 678 | y: units.gu(8); |
735 | 491 | Image { | 679 | Image { |
743 | 492 | property real maxWidth: units.gu(100) | 680 | property real maxWidth: units.gu(100) |
744 | 493 | anchors.horizontalCenter: parent.horizontalCenter | 681 | anchors.horizontalCenter: parent.horizontalCenter |
745 | 494 | width: Math.min(mainView.width, maxWidth)/1.75 | 682 | width: Math.min(mainView.width, maxWidth)/1.75 |
746 | 495 | //height: width | 683 | //height: width |
747 | 496 | source: "icons/sudoko-vector-about.svg" | 684 | source: "icons/sudoko-vector-about.svg" |
748 | 497 | smooth: true | 685 | smooth: true |
749 | 498 | fillMode: Image.PreserveAspectFit | 686 | fillMode: Image.PreserveAspectFit |
750 | 499 | 687 | ||
752 | 500 | } | 688 | } |
753 | 501 | Row { | 689 | Row { |
754 | 502 | //anchors.horizontalCenter: parent.horizontalCenter; | 690 | //anchors.horizontalCenter: parent.horizontalCenter; |
755 | 503 | anchors.left: aboutColumn.left | 691 | anchors.left: aboutColumn.left |