summaryrefslogtreecommitdiff
path: root/library/datebookdb.cpp
Unidiff
Diffstat (limited to 'library/datebookdb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookdb.cpp5
1 files changed, 0 insertions, 5 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp
index 188d8e1..e4ec2bf 100644
--- a/library/datebookdb.cpp
+++ b/library/datebookdb.cpp
@@ -1,417 +1,412 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qasciidict.h> 21#include <qasciidict.h>
22#include <qfile.h>
23#include <qmessagebox.h> 22#include <qmessagebox.h>
24#include <qstring.h>
25#include <qtextcodec.h>
26#include <qtextstream.h>
27#include <qtl.h> 23#include <qtl.h>
28 24
29#include <qpe/alarmserver.h> 25#include <qpe/alarmserver.h>
30#include <qpe/global.h> 26#include <qpe/global.h>
31#include "datebookdb.h" 27#include "datebookdb.h"
32#include <qpe/stringutil.h> 28#include <qpe/stringutil.h>
33#include <qpe/timeconversion.h>
34 29
35#include <errno.h> 30#include <errno.h>
36#include <stdlib.h> 31#include <stdlib.h>
37 32
38 33
39class DateBookDBPrivate 34class DateBookDBPrivate
40{ 35{
41public: 36public:
42 bool clean; // indcate whether we need to write to disk... 37 bool clean; // indcate whether we need to write to disk...
43}; 38};
44 39
45 40
46// Helper functions 41// Helper functions
47 42
48static QString dateBookJournalFile() 43static QString dateBookJournalFile()
49{ 44{
50 QString str = getenv("HOME"); 45 QString str = getenv("HOME");
51 return QString( str +"/.caljournal" ); 46 return QString( str +"/.caljournal" );
52} 47}
53 48
54static QString dateBookFilename() 49static QString dateBookFilename()
55{ 50{
56 return Global::applicationFileName("datebook","datebook.xml"); 51 return Global::applicationFileName("datebook","datebook.xml");
57} 52}
58 53
59/* Calculating the next event of a recuring event is actually 54/* Calculating the next event of a recuring event is actually
60 computationally inexpensive, esp. compared to checking each day 55 computationally inexpensive, esp. compared to checking each day
61 individually. There are bad worse cases for say the 29th of 56 individually. There are bad worse cases for say the 29th of
62 february or the 31st of some other months. However 57 february or the 31st of some other months. However
63 these are still bounded */ 58 these are still bounded */
64bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) 59bool nextOccurance(const Event &e, const QDate &from, QDateTime &next)
65{ 60{
66 // easy checks, first are we too far in the future or too far in the past? 61 // easy checks, first are we too far in the future or too far in the past?
67 QDate tmpDate; 62 QDate tmpDate;
68 int freq = e.repeatPattern().frequency; 63 int freq = e.repeatPattern().frequency;
69 int diff, diff2, a; 64 int diff, diff2, a;
70 int iday, imonth, iyear; 65 int iday, imonth, iyear;
71 int dayOfWeek = 0; 66 int dayOfWeek = 0;
72 int firstOfWeek = 0; 67 int firstOfWeek = 0;
73 int weekOfMonth; 68 int weekOfMonth;
74 69
75 70
76 if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from) 71 if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from)
77 return FALSE; 72 return FALSE;
78 73
79 if (e.start() >= from) { 74 if (e.start() >= from) {
80 next = e.start(); 75 next = e.start();
81 return TRUE; 76 return TRUE;
82 } 77 }
83 78
84 switch ( e.repeatPattern().type ) { 79 switch ( e.repeatPattern().type ) {
85 case Event::Weekly: 80 case Event::Weekly:
86 /* weekly is just daily by 7 */ 81 /* weekly is just daily by 7 */
87 /* first convert the repeatPattern.Days() mask to the next 82 /* first convert the repeatPattern.Days() mask to the next
88 day of week valid after from */ 83 day of week valid after from */
89 dayOfWeek = from.dayOfWeek(); 84 dayOfWeek = from.dayOfWeek();
90 dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ 85 dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */
91 86
92 /* this is done in case freq > 1 and from in week not 87 /* this is done in case freq > 1 and from in week not
93 for this round */ 88 for this round */
94 // firstOfWeek = 0; this is already done at decl. 89 // firstOfWeek = 0; this is already done at decl.
95 while(!((1 << firstOfWeek) & e.repeatPattern().days)) 90 while(!((1 << firstOfWeek) & e.repeatPattern().days))
96 firstOfWeek++; 91 firstOfWeek++;
97 92
98 93
99 94
100 /* there is at least one 'day', or there would be no event */ 95 /* there is at least one 'day', or there would be no event */
101 while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days)) 96 while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days))
102 dayOfWeek++; 97 dayOfWeek++;
103 98
104 99
105 dayOfWeek = dayOfWeek % 7; /* the actual day of week */ 100 dayOfWeek = dayOfWeek % 7; /* the actual day of week */
106 dayOfWeek -= e.start().date().dayOfWeek() -1; 101 dayOfWeek -= e.start().date().dayOfWeek() -1;
107 102
108 firstOfWeek = firstOfWeek % 7; /* the actual first of week */ 103 firstOfWeek = firstOfWeek % 7; /* the actual first of week */
109 firstOfWeek -= e.start().date().dayOfWeek() -1; 104 firstOfWeek -= e.start().date().dayOfWeek() -1;
110 105
111 // dayOfWeek may be negitive now 106 // dayOfWeek may be negitive now
112 // day of week is number of days to add to start day 107 // day of week is number of days to add to start day
113 108
114 freq *= 7; 109 freq *= 7;
115 // FALL-THROUGH !!!!! 110 // FALL-THROUGH !!!!!
116 case Event::Daily: 111 case Event::Daily:
117 // the add is for the possible fall through from weekly */ 112 // the add is for the possible fall through from weekly */
118 if(e.start().date().addDays(dayOfWeek) > from) { 113 if(e.start().date().addDays(dayOfWeek) > from) {
119 /* first week exception */ 114 /* first week exception */
120 next = QDateTime(e.start().date().addDays(dayOfWeek), 115 next = QDateTime(e.start().date().addDays(dayOfWeek),
121 e.start().time()); 116 e.start().time());
122 if ((next.date() > e.repeatPattern().endDate()) 117 if ((next.date() > e.repeatPattern().endDate())
123 && e.repeatPattern().hasEndDate) 118 && e.repeatPattern().hasEndDate)
124 return FALSE; 119 return FALSE;
125 return TRUE; 120 return TRUE;
126 } 121 }
127 /* if from is middle of a non-week */ 122 /* if from is middle of a non-week */
128 123
129 diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq; 124 diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq;
130 diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq; 125 diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq;
131 126
132 if(diff != 0) 127 if(diff != 0)
133 diff = freq - diff; 128 diff = freq - diff;
134 if(diff2 != 0) 129 if(diff2 != 0)
135 diff2 = freq - diff2; 130 diff2 = freq - diff2;
136 diff = QMIN(diff, diff2); 131 diff = QMIN(diff, diff2);
137 132
138 next = QDateTime(from.addDays(diff), e.start().time()); 133 next = QDateTime(from.addDays(diff), e.start().time());
139 if ( (next.date() > e.repeatPattern().endDate()) 134 if ( (next.date() > e.repeatPattern().endDate())
140 && e.repeatPattern().hasEndDate ) 135 && e.repeatPattern().hasEndDate )
141 return FALSE; 136 return FALSE;
142 return TRUE; 137 return TRUE;
143 case Event::MonthlyDay: 138 case Event::MonthlyDay:
144 iday = from.day(); 139 iday = from.day();
145 iyear = from.year(); 140 iyear = from.year();
146 imonth = from.month(); 141 imonth = from.month();
147 /* find equivelent day of month for this month */ 142 /* find equivelent day of month for this month */
148 dayOfWeek = e.start().date().dayOfWeek(); 143 dayOfWeek = e.start().date().dayOfWeek();
149 weekOfMonth = (e.start().date().day() - 1) / 7; 144 weekOfMonth = (e.start().date().day() - 1) / 7;
150 145
151 /* work out when the next valid month is */ 146 /* work out when the next valid month is */
152 a = from.year() - e.start().date().year(); 147 a = from.year() - e.start().date().year();
153 a *= 12; 148 a *= 12;
154 a = a + (imonth - e.start().date().month()); 149 a = a + (imonth - e.start().date().month());
155 /* a is e.start()monthsFrom(from); */ 150 /* a is e.start()monthsFrom(from); */
156 if(a % freq) { 151 if(a % freq) {
157 a = freq - (a % freq); 152 a = freq - (a % freq);
158 imonth = from.month() + a; 153 imonth = from.month() + a;
159 if (imonth > 12) { 154 if (imonth > 12) {
160 imonth--; 155 imonth--;
161 iyear += imonth / 12; 156 iyear += imonth / 12;
162 imonth = imonth % 12; 157 imonth = imonth % 12;
163 imonth++; 158 imonth++;
164 } 159 }
165 } 160 }
166 /* imonth is now the first month after or on 161 /* imonth is now the first month after or on
167 from that matches the frequency given */ 162 from that matches the frequency given */
168 163
169 /* find for this month */ 164 /* find for this month */
170 tmpDate = QDate( iyear, imonth, 1 ); 165 tmpDate = QDate( iyear, imonth, 1 );
171 166
172 iday = 1; 167 iday = 1;
173 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; 168 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
174 iday += 7 * weekOfMonth; 169 iday += 7 * weekOfMonth;
175 while (iday > tmpDate.daysInMonth()) { 170 while (iday > tmpDate.daysInMonth()) {
176 imonth += freq; 171 imonth += freq;
177 if (imonth > 12) { 172 if (imonth > 12) {
178 imonth--; 173 imonth--;
179 iyear += imonth / 12; 174 iyear += imonth / 12;
180 imonth = imonth % 12; 175 imonth = imonth % 12;
181 imonth++; 176 imonth++;
182 } 177 }
183 tmpDate = QDate( iyear, imonth, 1 ); 178 tmpDate = QDate( iyear, imonth, 1 );
184 /* these loops could go for a while, check end case now */ 179 /* these loops could go for a while, check end case now */
185 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 180 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
186 return FALSE; 181 return FALSE;
187 iday = 1; 182 iday = 1;
188 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; 183 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
189 iday += 7 * weekOfMonth; 184 iday += 7 * weekOfMonth;
190 } 185 }
191 tmpDate = QDate(iyear, imonth, iday); 186 tmpDate = QDate(iyear, imonth, iday);
192 187
193 if (tmpDate >= from) { 188 if (tmpDate >= from) {
194 next = QDateTime(tmpDate, e.start().time()); 189 next = QDateTime(tmpDate, e.start().time());
195 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 190 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
196 return FALSE; 191 return FALSE;
197 return TRUE; 192 return TRUE;
198 } 193 }
199 194
200 /* need to find the next iteration */ 195 /* need to find the next iteration */
201 do { 196 do {
202 imonth += freq; 197 imonth += freq;
203 if (imonth > 12) { 198 if (imonth > 12) {
204 imonth--; 199 imonth--;
205 iyear += imonth / 12; 200 iyear += imonth / 12;
206 imonth = imonth % 12; 201 imonth = imonth % 12;
207 imonth++; 202 imonth++;
208 } 203 }
209 tmpDate = QDate( iyear, imonth, 1 ); 204 tmpDate = QDate( iyear, imonth, 1 );
210 /* these loops could go for a while, check end case now */ 205 /* these loops could go for a while, check end case now */
211 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 206 if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
212 return FALSE; 207 return FALSE;
213 iday = 1; 208 iday = 1;
214 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; 209 iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
215 iday += 7 * weekOfMonth; 210 iday += 7 * weekOfMonth;
216 } while (iday > tmpDate.daysInMonth()); 211 } while (iday > tmpDate.daysInMonth());
217 tmpDate = QDate(iyear, imonth, iday); 212 tmpDate = QDate(iyear, imonth, iday);
218 213
219 next = QDateTime(tmpDate, e.start().time()); 214 next = QDateTime(tmpDate, e.start().time());
220 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 215 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
221 return FALSE; 216 return FALSE;
222 return TRUE; 217 return TRUE;
223 case Event::MonthlyDate: 218 case Event::MonthlyDate:
224 iday = e.start().date().day(); 219 iday = e.start().date().day();
225 iyear = from.year(); 220 iyear = from.year();
226 imonth = from.month(); 221 imonth = from.month();
227 222
228 a = from.year() - e.start().date().year(); 223 a = from.year() - e.start().date().year();
229 a *= 12; 224 a *= 12;
230 a = a + (imonth - e.start().date().month()); 225 a = a + (imonth - e.start().date().month());
231 /* a is e.start()monthsFrom(from); */ 226 /* a is e.start()monthsFrom(from); */
232 if(a % freq) { 227 if(a % freq) {
233 a = freq - (a % freq); 228 a = freq - (a % freq);
234 imonth = from.month() + a; 229 imonth = from.month() + a;
235 if (imonth > 12) { 230 if (imonth > 12) {
236 imonth--; 231 imonth--;
237 iyear += imonth / 12; 232 iyear += imonth / 12;
238 imonth = imonth % 12; 233 imonth = imonth % 12;
239 imonth++; 234 imonth++;
240 } 235 }
241 } 236 }
242 /* imonth is now the first month after or on 237 /* imonth is now the first month after or on
243 from that matches the frequencey given */ 238 from that matches the frequencey given */
244 239
245 /* this could go for a while, worse case, 4*12 iterations, probably */ 240 /* this could go for a while, worse case, 4*12 iterations, probably */
246 while(!QDate::isValid(iyear, imonth, iday) ) { 241 while(!QDate::isValid(iyear, imonth, iday) ) {
247 imonth += freq; 242 imonth += freq;
248 if (imonth > 12) { 243 if (imonth > 12) {
249 imonth--; 244 imonth--;
250 iyear += imonth / 12; 245 iyear += imonth / 12;
251 imonth = imonth % 12; 246 imonth = imonth % 12;
252 imonth++; 247 imonth++;
253 } 248 }
254 /* these loops could go for a while, check end case now */ 249 /* these loops could go for a while, check end case now */
255 if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 250 if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
256 return FALSE; 251 return FALSE;
257 } 252 }
258 253
259 if(QDate(iyear, imonth, iday) >= from) { 254 if(QDate(iyear, imonth, iday) >= from) {
260 /* done */ 255 /* done */
261 next = QDateTime(QDate(iyear, imonth, iday), 256 next = QDateTime(QDate(iyear, imonth, iday),
262 e.start().time()); 257 e.start().time());
263 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 258 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
264 return FALSE; 259 return FALSE;
265 return TRUE; 260 return TRUE;
266 } 261 }
267 262
268 /* ok, need to cycle */ 263 /* ok, need to cycle */
269 imonth += freq; 264 imonth += freq;
270 imonth--; 265 imonth--;
271 iyear += imonth / 12; 266 iyear += imonth / 12;
272 imonth = imonth % 12; 267 imonth = imonth % 12;
273 imonth++; 268 imonth++;
274 269
275 while(!QDate::isValid(iyear, imonth, iday) ) { 270 while(!QDate::isValid(iyear, imonth, iday) ) {
276 imonth += freq; 271 imonth += freq;
277 imonth--; 272 imonth--;
278 iyear += imonth / 12; 273 iyear += imonth / 12;
279 imonth = imonth % 12; 274 imonth = imonth % 12;
280 imonth++; 275 imonth++;
281 if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 276 if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
282 return FALSE; 277 return FALSE;
283 } 278 }
284 279
285 next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); 280 next = QDateTime(QDate(iyear, imonth, iday), e.start().time());
286 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 281 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
287 return FALSE; 282 return FALSE;
288 return TRUE; 283 return TRUE;
289 case Event::Yearly: 284 case Event::Yearly:
290 iday = e.start().date().day(); 285 iday = e.start().date().day();
291 imonth = e.start().date().month(); 286 imonth = e.start().date().month();
292 iyear = from.year(); // after all, we want to start in this year 287 iyear = from.year(); // after all, we want to start in this year
293 288
294 diff = 1; 289 diff = 1;
295 if(imonth == 2 && iday > 28) { 290 if(imonth == 2 && iday > 28) {
296 /* leap year, and it counts, calculate actual frequency */ 291 /* leap year, and it counts, calculate actual frequency */
297 if(freq % 4) 292 if(freq % 4)
298 if (freq % 2) 293 if (freq % 2)
299 freq = freq * 4; 294 freq = freq * 4;
300 else 295 else
301 freq = freq * 2; 296 freq = freq * 2;
302 /* else divides by 4 already, leave freq alone */ 297 /* else divides by 4 already, leave freq alone */
303 diff = 4; 298 diff = 4;
304 } 299 }
305 300
306 a = from.year() - e.start().date().year(); 301 a = from.year() - e.start().date().year();
307 if(a % freq) { 302 if(a % freq) {
308 a = freq - (a % freq); 303 a = freq - (a % freq);
309 iyear = iyear + a; 304 iyear = iyear + a;
310 } 305 }
311 306
312 /* under the assumption we won't hit one of the special not-leap years twice */ 307 /* under the assumption we won't hit one of the special not-leap years twice */
313 if(!QDate::isValid(iyear, imonth, iday)) { 308 if(!QDate::isValid(iyear, imonth, iday)) {
314 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ 309 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
315 iyear += freq; 310 iyear += freq;
316 } 311 }
317 312
318 if(QDate(iyear, imonth, iday) >= from) { 313 if(QDate(iyear, imonth, iday) >= from) {
319 next = QDateTime(QDate(iyear, imonth, iday), 314 next = QDateTime(QDate(iyear, imonth, iday),
320 e.start().time()); 315 e.start().time());
321 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 316 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
322 return FALSE; 317 return FALSE;
323 return TRUE; 318 return TRUE;
324 } 319 }
325 /* iyear == from.year(), need to advance again */ 320 /* iyear == from.year(), need to advance again */
326 iyear += freq; 321 iyear += freq;
327 /* under the assumption we won't hit one of the special not-leap years twice */ 322 /* under the assumption we won't hit one of the special not-leap years twice */
328 if(!QDate::isValid(iyear, imonth, iday)) { 323 if(!QDate::isValid(iyear, imonth, iday)) {
329 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ 324 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
330 iyear += freq; 325 iyear += freq;
331 } 326 }
332 327
333 next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); 328 next = QDateTime(QDate(iyear, imonth, iday), e.start().time());
334 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) 329 if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
335 return FALSE; 330 return FALSE;
336 return TRUE; 331 return TRUE;
337 default: 332 default:
338 return FALSE; 333 return FALSE;
339 } 334 }
340} 335}
341 336
342static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) 337static bool nextAlarm( const Event &ev, QDateTime& when, int& warn)
343{ 338{
344 QDateTime now = QDateTime::currentDateTime(); 339 QDateTime now = QDateTime::currentDateTime();
345 if ( ev.hasRepeat() ) { 340 if ( ev.hasRepeat() ) {
346 QDateTime ralarm; 341 QDateTime ralarm;
347 if (nextOccurance(ev, now.date(), ralarm)) { 342 if (nextOccurance(ev, now.date(), ralarm)) {
348 ralarm = ralarm.addSecs(-ev.alarmTime()*60); 343 ralarm = ralarm.addSecs(-ev.alarmTime()*60);
349 if ( ralarm > now ) { 344 if ( ralarm > now ) {
350 when = ralarm; 345 when = ralarm;
351 warn = ev.alarmTime(); 346 warn = ev.alarmTime();
352 } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { 347 } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) {
353 ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); 348 ralarm = ralarm.addSecs( -ev.alarmTime()*60 );
354 if ( ralarm > now ) { 349 if ( ralarm > now ) {
355 when = ralarm; 350 when = ralarm;
356 warn = ev.alarmTime(); 351 warn = ev.alarmTime();
357 } 352 }
358 } 353 }
359 } 354 }
360 } else { 355 } else {
361 warn = ev.alarmTime(); 356 warn = ev.alarmTime();
362 when = ev.start().addSecs( -ev.alarmTime()*60 ); 357 when = ev.start().addSecs( -ev.alarmTime()*60 );
363 } 358 }
364 return when > now; 359 return when > now;
365} 360}
366 361
367static void addEventAlarm( const Event &ev ) 362static void addEventAlarm( const Event &ev )
368{ 363{
369 QDateTime when; 364 QDateTime when;
370 int warn; 365 int warn;
371 if ( nextAlarm(ev,when,warn) ) 366 if ( nextAlarm(ev,when,warn) )
372 AlarmServer::addAlarm( when, 367 AlarmServer::addAlarm( when,
373 "QPE/Application/datebook", 368 "QPE/Application/datebook",
374 "alarm(QDateTime,int)", warn ); 369 "alarm(QDateTime,int)", warn );
375} 370}
376 371
377static void delEventAlarm( const Event &ev ) 372static void delEventAlarm( const Event &ev )
378{ 373{
379 QDateTime when; 374 QDateTime when;
380 int warn; 375 int warn;
381 if ( nextAlarm(ev,when,warn) ) 376 if ( nextAlarm(ev,when,warn) )
382 AlarmServer::deleteAlarm( when, 377 AlarmServer::deleteAlarm( when,
383 "QPE/Application/datebook", 378 "QPE/Application/datebook",
384 "alarm(QDateTime,int)", warn ); 379 "alarm(QDateTime,int)", warn );
385} 380}
386 381
387 382
388DateBookDB::DateBookDB() 383DateBookDB::DateBookDB()
389{ 384{
390 init(); 385 init();
391} 386}
392 387
393DateBookDB::~DateBookDB() 388DateBookDB::~DateBookDB()
394{ 389{
395 save(); 390 save();
396 eventList.clear(); 391 eventList.clear();
397 repeatEvents.clear(); 392 repeatEvents.clear();
398} 393}
399 394
400 395
401//#### Why is this code duplicated in getEffectiveEvents ????? 396//#### Why is this code duplicated in getEffectiveEvents ?????
402//#### Addendum. Don't use this function, lets faze it out if we can. 397//#### Addendum. Don't use this function, lets faze it out if we can.
403QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) 398QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to )
404{ 399{
405 QValueList<Event> tmpList; 400 QValueList<Event> tmpList;
406 tmpList = getNonRepeatingEvents( from, to ); 401 tmpList = getNonRepeatingEvents( from, to );
407 402
408 // check for repeating events... 403 // check for repeating events...
409 for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); 404 for (QValueList<Event>::ConstIterator it = repeatEvents.begin();
410 it != repeatEvents.end(); ++it) { 405 it != repeatEvents.end(); ++it) {
411 QDate itDate = from; 406 QDate itDate = from;
412 QDateTime due; 407 QDateTime due;
413 408
414 /* create a false end date, to short circuit on hard 409 /* create a false end date, to short circuit on hard
415 MonthlyDay recurences */ 410 MonthlyDay recurences */
416 Event dummy_event = *it; 411 Event dummy_event = *it;
417 Event::RepeatPattern r = dummy_event.repeatPattern(); 412 Event::RepeatPattern r = dummy_event.repeatPattern();