Merge lp:~signor-hyde/ubuntu-clock-app/ubuntu-clock-app into lp:ubuntu-clock-app/saucy
- ubuntu-clock-app
- Merge into saucy
Proposed by
Alessandro Pozzi
Status: | Rejected |
---|---|
Rejected by: | Nekhelesh Ramananthan |
Proposed branch: | lp:~signor-hyde/ubuntu-clock-app/ubuntu-clock-app |
Merge into: | lp:ubuntu-clock-app/saucy |
Diff against target: |
325 lines (+303/-0) 2 files modified
alarm/AlarmStorage.qml (+2/-0) alarm/AlarmStorage.qml.autosave (+301/-0) |
To merge this branch: | bzr merge lp:~signor-hyde/ubuntu-clock-app/ubuntu-clock-app |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nekhelesh Ramananthan | Disapprove | ||
Review via email: mp+162501@code.launchpad.net |
Commit message
Solve bug read alarm db
Description of the change
To post a comment you must log in.
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'alarm/AlarmStorage.qml' |
2 | --- alarm/AlarmStorage.qml 2013-04-29 18:56:21 +0000 |
3 | +++ alarm/AlarmStorage.qml 2013-05-04 00:20:32 +0000 |
4 | @@ -257,6 +257,7 @@ |
5 | |
6 | var today = new Date(); |
7 | var chkday = today.getDay() + 1; |
8 | + chkday = (chkday == 7) ? 0 : chkday; |
9 | var days = new Array("sun", "mon", "tue", "wed", "thu", "fri", "sat"); |
10 | var numdays = 0; |
11 | var result; |
12 | @@ -265,6 +266,7 @@ |
13 | db.readTransaction( |
14 | function(tx){ |
15 | result = new Array(); |
16 | + console.log("checkday: " + chkday); |
17 | var resnextweek = tx.executeSql('SELECT * FROM Alarm WHERE ' + days[chkday] + ' = ? AND act = ? ORDER BY hou, min', [1, 1]); |
18 | if (resnextweek.rows.length > 0) { |
19 | for (var i = 0; i < resnextweek.rows.length; i++) { |
20 | |
21 | === added file 'alarm/AlarmStorage.qml.autosave' |
22 | --- alarm/AlarmStorage.qml.autosave 1970-01-01 00:00:00 +0000 |
23 | +++ alarm/AlarmStorage.qml.autosave 2013-05-04 00:20:32 +0000 |
24 | @@ -0,0 +1,301 @@ |
25 | +/* |
26 | + * Copyright (C) 2013 Canonical Ltd |
27 | + * |
28 | + * This program is free software: you can redistribute it and/or modify |
29 | + * it under the terms of the GNU General Public License version 3 as |
30 | + * published by the Free Software Foundation. |
31 | + * |
32 | + * This program is distributed in the hope that it will be useful, |
33 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
34 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
35 | + * GNU General Public License for more details. |
36 | + * |
37 | + * You should have received a copy of the GNU General Public License |
38 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
39 | + * |
40 | + * Authored by: Alessandro Pozzi <signor.hyde@gmail.com> |
41 | + */ |
42 | + |
43 | +import QtQuick 2.0 |
44 | +import QtQuick.LocalStorage 2.0 |
45 | +import "../common/ClockUtils.js" as Utils |
46 | + |
47 | +QtObject { |
48 | + id: alarmStorage |
49 | + |
50 | + property var db: null |
51 | + |
52 | + Component.onCompleted: { |
53 | + Utils.log("AlarmStorage loaded") |
54 | + openDB(); |
55 | + } |
56 | + |
57 | + // Opens the local db if not already open. On the first call creates the tables |
58 | + function openDB () { |
59 | + if(db !== null) return; |
60 | + |
61 | + db = LocalStorage.openDatabaseSync("ubuntu-clock-app", "0.1", "Default Ubuntu touch clock", 1000); |
62 | + |
63 | + try { |
64 | + db.transaction(function(tx){ |
65 | + tx.executeSql('CREATE TABLE IF NOT EXISTS Alarm(key INTEGER PRIMARY KEY, hou INTEGER, min INTEGER, mon INTEGER, tue INTEGER, wed INTEGER, thu INTEGER, fri INTEGER, sat INTEGER, sun INTEGER, ton INTEGER, vib INTEGER, act INTEGER)'); |
66 | + }); |
67 | + } catch (err) { |
68 | + Utils.error("Error creating table in db"); |
69 | + } |
70 | + } |
71 | + |
72 | + //Read alarm from database |
73 | + function getAlarmValue () { |
74 | + openDB(); |
75 | + |
76 | + var result = new Array(); |
77 | + try { |
78 | + db.readTransaction( |
79 | + function(tx){ |
80 | + var res = tx.executeSql('SELECT * FROM Alarm ORDER BY hou, min'); |
81 | + if (res.rows.length > 0) { |
82 | + for (var i = 0; i < res.rows.length; i++) { |
83 | + result[i] = new Array(); |
84 | + result[i][0] = res.rows.item(i).key; |
85 | + result[i][1] = res.rows.item(i).hou; |
86 | + result[i][2] = res.rows.item(i).min; |
87 | + result[i][3] = res.rows.item(i).mon; |
88 | + result[i][4] = res.rows.item(i).tue; |
89 | + result[i][5] = res.rows.item(i).wed; |
90 | + result[i][6] = res.rows.item(i).thu; |
91 | + result[i][7] = res.rows.item(i).fri; |
92 | + result[i][8] = res.rows.item(i).sat; |
93 | + result[i][9] = res.rows.item(i).sun; |
94 | + result[i][10] = res.rows.item(i).ton; |
95 | + result[i][11] = res.rows.item(i).vib; |
96 | + result[i][12] = res.rows.item(i).act; |
97 | + } |
98 | + } |
99 | + }); |
100 | + } catch (err) { |
101 | + Utils.error("Error getting timer: " + err); |
102 | + } |
103 | + return result; |
104 | + } |
105 | + |
106 | + //Read single alarm from database |
107 | + function getSingleAlarmValue (alarmkey) { |
108 | + openDB(); |
109 | + |
110 | + var result = new Array(); |
111 | + try { |
112 | + db.readTransaction( |
113 | + function(tx){ |
114 | + var res = tx.executeSql('SELECT * FROM Alarm WHERE key = ? ORDER BY hou, min', [alarmkey]); |
115 | + if (res.rows.length > 0) { |
116 | + result[0] = new Array(); |
117 | + result[0][0] = res.rows.item(0).key; |
118 | + result[0][1] = res.rows.item(0).hou; |
119 | + result[0][2] = res.rows.item(0).min; |
120 | + result[0][3] = res.rows.item(0).mon; |
121 | + result[0][4] = res.rows.item(0).tue; |
122 | + result[0][5] = res.rows.item(0).wed; |
123 | + result[0][6] = res.rows.item(0).thu; |
124 | + result[0][7] = res.rows.item(0).fri; |
125 | + result[0][8] = res.rows.item(0).sat; |
126 | + result[0][9] = res.rows.item(0).sun; |
127 | + result[0][10] = res.rows.item(0).ton; |
128 | + result[0][11] = res.rows.item(0).vib; |
129 | + result[0][12] = res.rows.item(0).act; |
130 | + } |
131 | + }); |
132 | + } catch (err) { |
133 | + Utils.error("Error getting single timer: " + err); |
134 | + } |
135 | + return result; |
136 | + } |
137 | + |
138 | + //Write alarm to database |
139 | + function setAlarmValue ( hou, min, mon, tue, wed, thu, fri, sat, sun, ton, vib ) { |
140 | + openDB(); |
141 | + |
142 | + try { |
143 | + db.transaction(function(tx){ |
144 | + var res = tx.executeSql('INSERT INTO Alarm VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [null, hou, min, mon, tue, wed, thu, fri, sat, sun, ton, vib, 1]); |
145 | + }); |
146 | + } catch (err) { |
147 | + Utils.error("Error setting alarm " + hou + "." + min + ": " + err); |
148 | + } |
149 | + } |
150 | + |
151 | + //Update alarm to database |
152 | + function updateAlarmValue ( key, hou, min, mon, tue, wed, thu, fri, sat, sun, ton, vib ) { |
153 | + openDB(); |
154 | + |
155 | + try { |
156 | + db.transaction(function(tx){ |
157 | + var res = tx.executeSql('UPDATE Alarm SET hou = ?, min = ?, mon = ?, tue = ?, wed = ?, thu = ?, fri = ?, sat = ?, sun = ?, ton = ?, vib = ? WHERE key = ?', [hou, min, mon, tue, wed, thu, fri, sat, sun, ton, vib, key]); |
158 | + }); |
159 | + } catch (err) { |
160 | + Utils.error("Error update alarm " + key + ": " + err); |
161 | + } |
162 | + } |
163 | + |
164 | + //Enabled/Disabled alarm |
165 | + function setStateAlarmValue ( keyalarm , alarmstate ) { |
166 | + openDB(); |
167 | + try { |
168 | + db.transaction(function(tx){ |
169 | + var res = tx.executeSql('UPDATE Alarm SET act = ? WHERE key = ?', [alarmstate, keyalarm]); |
170 | + }); |
171 | + } catch (err) { |
172 | + Utils.error("Error change state alarm " + keyalarm + ": " + err); |
173 | + } |
174 | + } |
175 | + |
176 | + // Delete table |
177 | + function deleteTable ( table ) { |
178 | + openDB(); |
179 | + |
180 | + try { |
181 | + db.transaction( |
182 | + function(tx){ |
183 | + tx.executeSql("DROP TABLE " + table); |
184 | + }); |
185 | + } catch (err) { |
186 | + Utils.error("Error delete table '" + table + "': " + err); |
187 | + } |
188 | + } |
189 | + |
190 | + //Delete alarm on database |
191 | + function delAlarmValue ( key ) { |
192 | + openDB(); |
193 | + |
194 | + try { |
195 | + db.transaction( |
196 | + function(tx){ |
197 | + tx.executeSql('DELETE FROM Alarm WHERE key = ?', [key]); |
198 | + }); |
199 | + } catch (err) { |
200 | + Utils.error("Error delete Alarm: " + err); |
201 | + } |
202 | + } |
203 | + |
204 | + //Read alarm set from database |
205 | + function getActiveAlarm () { |
206 | + openDB(); |
207 | + |
208 | + var today = new Date(); |
209 | + var hoursnow = Qt.formatDateTime(new Date(), "hh"); |
210 | + var minutesnow = Qt.formatDateTime(new Date(), "mm"); |
211 | + var days = new Array("sun", "mon", "tue", "wed", "thu", "fri", "sat"); |
212 | + var result = new Array(); |
213 | + var numrowsafter; |
214 | + var numrowsbefore; |
215 | + try { |
216 | + db.readTransaction( |
217 | + function(tx){ |
218 | + var resafter = tx.executeSql('SELECT * FROM Alarm WHERE ((mon = ? AND tue = ? AND wed = ? AND thu = ? AND fri = ? AND sat = ? AND sun = ?) OR ' + days[today.getDay()] + ' = ?) AND act = ? AND ((hou > ' + hoursnow + ') OR (hou = ' + hoursnow + ' AND min > ' + minutesnow + ')) ORDER BY hou, min', [0, 0, 0, 0, 0, 0, 0, 1, 1]); |
219 | + numrowsafter = (resafter.rows.length > 0) ? resafter.rows.length : 0; |
220 | + if (resafter.rows.length > 0) { |
221 | + for (var i = 0; i < resafter.rows.length; i++) { |
222 | + result[i] = new Array(); |
223 | + result[i][0] = resafter.rows.item(i).key; |
224 | + result[i][1] = resafter.rows.item(i).hou; |
225 | + result[i][2] = resafter.rows.item(i).min; |
226 | + result[i][3] = resafter.rows.item(i).ton; |
227 | + result[i][4] = resafter.rows.item(i).vib; |
228 | + result[i][5] = resafter.rows.item(i).act; |
229 | + result[i][6] = resafter.rows.item(i).mon; |
230 | + result[i][7] = resafter.rows.item(i).tue; |
231 | + result[i][8] = resafter.rows.item(i).wed; |
232 | + result[i][9] = resafter.rows.item(i).thu; |
233 | + result[i][10] = resafter.rows.item(i).fri; |
234 | + result[i][11] = resafter.rows.item(i).sat; |
235 | + result[i][12] = resafter.rows.item(i).sun; |
236 | + result[i][13] = 0; |
237 | + } |
238 | + } |
239 | + }); |
240 | + } catch (err) { |
241 | + Utils.error("Error getting alarm rep: " + err); |
242 | + } |
243 | + try { |
244 | + db.readTransaction( |
245 | + function(tx){ |
246 | + var resbefore = tx.executeSql('SELECT * FROM Alarm WHERE ((mon = ? AND tue = ? AND wed = ? AND thu = ? AND fri = ? AND sat = ? AND sun = ?) OR ' + days[today.getDay()] + ' = ?) AND act = ? AND ((hou < ' + hoursnow + ') OR (hou = ' + hoursnow + ' AND min < ' + minutesnow + ')) ORDER BY hou, min', [0, 0, 0, 0, 0, 0, 0, 1, 1]); |
247 | + numrowsbefore = (resbefore.rows.length > 0) ? resbefore.rows.length : 0; |
248 | + if (resbefore.rows.length > 0) { |
249 | + for (var x = numrowsafter; x < resbefore.rows.length; x++) { |
250 | + result[x] = new Array(); |
251 | + result[x][0] = resbefore.rows.item(x).key; |
252 | + result[x][1] = resbefore.rows.item(x).hou; |
253 | + result[x][2] = resbefore.rows.item(x).min; |
254 | + result[x][3] = resbefore.rows.item(x).ton; |
255 | + result[x][4] = resbefore.rows.item(x).vib; |
256 | + result[x][5] = resbefore.rows.item(x).act; |
257 | + result[x][6] = resbefore.rows.item(x).mon; |
258 | + result[x][7] = resbefore.rows.item(x).tue; |
259 | + result[x][8] = resbefore.rows.item(x).wed; |
260 | + result[x][9] = resbefore.rows.item(x).thu; |
261 | + result[x][10] = resbefore.rows.item(x).fri; |
262 | + result[x][11] = resbefore.rows.item(x).sat; |
263 | + result[x][12] = resbefore.rows.item(x).sun; |
264 | + result[x][13] = 0; |
265 | + } |
266 | + } |
267 | + }); |
268 | + } catch (err) { |
269 | + Utils.error("Error getting alarm rep: " + err); |
270 | + } |
271 | + if (numrowsafter > 0 || numrowsbefore > 0) { |
272 | + return result; |
273 | + } else { |
274 | + return getNextWeekAlarm(); |
275 | + } |
276 | + } |
277 | + |
278 | + //if there isn't an alarm in current day read alarms in the next dayset from database |
279 | + function getNextWeekAlarm () { |
280 | + openDB(); |
281 | + |
282 | + var today = new Date(); |
283 | + var chkday = today.getDay() + 1; |
284 | + chkday = (chkday == 7) ? 0 : chkday; |
285 | + var days = new Array("sun", "mon", "tue", "wed", "thu", "fri", "sat"); |
286 | + var numdays = 0; |
287 | + var result; |
288 | + while (chkday != today.getDay()) { |
289 | + try { |
290 | + db.readTransaction( |
291 | + function(tx){ |
292 | + result = new Array(); |
293 | + var resnextweek = tx.executeSql('SELECT * FROM Alarm WHERE ' + days[chkday] + ' = ? AND act = ? ORDER BY hou, min', [1, 1]); |
294 | + if (resnextweek.rows.length > 0) { |
295 | + for (var i = 0; i < resnextweek.rows.length; i++) { |
296 | + result[i] = new Array(); |
297 | + result[i][0] = resnextweek.rows.item(i).key; |
298 | + result[i][1] = resnextweek.rows.item(i).hou; |
299 | + result[i][2] = resnextweek.rows.item(i).min; |
300 | + result[i][3] = resnextweek.rows.item(i).ton; |
301 | + result[i][4] = resnextweek.rows.item(i).vib; |
302 | + result[i][5] = resnextweek.rows.item(i).act; |
303 | + result[i][6] = resnextweek.rows.item(i).mon; |
304 | + result[i][7] = resnextweek.rows.item(i).tue; |
305 | + result[i][8] = resnextweek.rows.item(i).wed; |
306 | + result[i][9] = resnextweek.rows.item(i).thu; |
307 | + result[i][10] = resnextweek.rows.item(i).fri; |
308 | + result[i][11] = resnextweek.rows.item(i).sat; |
309 | + result[i][12] = resnextweek.rows.item(i).sun; |
310 | + result[i][13] = 24 * numdays; |
311 | + } |
312 | + chkday = today.getDay(); |
313 | + } else { |
314 | + chkday++; |
315 | + numdays++; |
316 | + chkday = (chkday == 7) ? 0 : chkday; |
317 | + } |
318 | + }); |
319 | + } catch (err) { |
320 | + Utils.error("Error getting alarm rep2: " + err); |
321 | + } |
322 | + } |
323 | + return result; |
324 | + } |
325 | +} |
1. Please give it a proper branch name since using a generic name pulls unnecessary bug reports as you can see above. for instance here you could name the branch fix-alarm-error or something
2. The file AlarmStorage. qml.autosave has been added by mistake.