Diffstat (limited to 'libopie2/opiepim/core/orecur.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index daf3506..e6a4787 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -1,102 +1,104 @@ | |||
1 | #include <qshared.h> | 1 | #include <qshared.h> |
2 | 2 | ||
3 | #include <qtopia/timeconversion.h> | 3 | #include <qtopia/timeconversion.h> |
4 | 4 | ||
5 | #include "orecur.h" | 5 | #include "orecur.h" |
6 | 6 | ||
7 | struct ORecur::Data : public QShared { | 7 | struct ORecur::Data : public QShared { |
8 | Data() : QShared() { | 8 | Data() : QShared() { |
9 | type = ORecur::NoRepeat; | 9 | type = ORecur::NoRepeat; |
10 | freq = -1; | 10 | freq = -1; |
11 | days = 0; | 11 | days = 0; |
12 | pos = 0; | 12 | pos = 0; |
13 | create = -1; | 13 | create = QDateTime::currentDateTime(); |
14 | hasEnd = FALSE; | 14 | hasEnd = FALSE; |
15 | end = 0; | 15 | end = QDate::currentDate(); |
16 | } | 16 | } |
17 | char days; // Q_UINT8 for 8 seven days;) | 17 | char days; // Q_UINT8 for 8 seven days;) |
18 | ORecur::RepeatType type; | 18 | ORecur::RepeatType type; |
19 | int freq; | 19 | int freq; |
20 | int pos; | 20 | int pos; |
21 | bool hasEnd : 1; | 21 | bool hasEnd : 1; |
22 | time_t end; | 22 | QDate end; |
23 | time_t create; | 23 | QDateTime create; |
24 | int rep; | 24 | int rep; |
25 | QString app; | 25 | QString app; |
26 | ExceptionList list; | 26 | ExceptionList list; |
27 | QDate start; | 27 | QDate start; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | 30 | ||
31 | ORecur::ORecur() { | 31 | ORecur::ORecur() { |
32 | data = new Data; | 32 | data = new Data; |
33 | } | 33 | } |
34 | ORecur::ORecur( const ORecur& rec) | 34 | ORecur::ORecur( const ORecur& rec) |
35 | : data( rec.data ) | 35 | : data( rec.data ) |
36 | { | 36 | { |
37 | data->ref(); | 37 | data->ref(); |
38 | } | 38 | } |
39 | ORecur::~ORecur() { | 39 | ORecur::~ORecur() { |
40 | if ( data->deref() ) { | 40 | if ( data->deref() ) { |
41 | delete data; | 41 | delete data; |
42 | data = 0l; | 42 | data = 0l; |
43 | } | 43 | } |
44 | } | 44 | } |
45 | void ORecur::deref() { | 45 | void ORecur::deref() { |
46 | if ( data->deref() ) { | 46 | if ( data->deref() ) { |
47 | delete data; | 47 | delete data; |
48 | data = 0l; | 48 | data = 0l; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | bool ORecur::operator==( const ORecur& )const { | 51 | bool ORecur::operator==( const ORecur& )const { |
52 | return false; | 52 | return false; |
53 | } | 53 | } |
54 | ORecur &ORecur::operator=( const ORecur& re) { | 54 | ORecur &ORecur::operator=( const ORecur& re) { |
55 | if ( *this == re ) return *this; | ||
56 | |||
55 | re.data->ref(); | 57 | re.data->ref(); |
56 | deref(); | 58 | deref(); |
57 | data = re.data; | 59 | data = re.data; |
58 | 60 | ||
59 | return *this; | 61 | return *this; |
60 | } | 62 | } |
61 | bool ORecur::doesRecur()const { | 63 | bool ORecur::doesRecur()const { |
62 | return !( type() == NoRepeat ); | 64 | return !( type() == NoRepeat ); |
63 | } | 65 | } |
64 | /* | 66 | /* |
65 | * we try to be smart here | 67 | * we try to be smart here |
66 | * | 68 | * |
67 | */ | 69 | */ |
68 | bool ORecur::doesRecur( const QDate& date ) { | 70 | bool ORecur::doesRecur( const QDate& date ) { |
69 | /* the day before the recurrance */ | 71 | /* the day before the recurrance */ |
70 | QDate da = date.addDays(-1); | 72 | QDate da = date.addDays(-1); |
71 | 73 | ||
72 | QDate recur; | 74 | QDate recur; |
73 | if (!nextOcurrence( da, recur ) ) | 75 | if (!nextOcurrence( da, recur ) ) |
74 | return false; | 76 | return false; |
75 | 77 | ||
76 | return (recur == date); | 78 | return (recur == date); |
77 | } | 79 | } |
78 | // FIXME unuglify! | 80 | // FIXME unuglify! |
79 | // GPL from Datebookdb.cpp | 81 | // GPL from Datebookdb.cpp |
80 | // FIXME exception list! | 82 | // FIXME exception list! |
81 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | 83 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { |
82 | 84 | ||
83 | // easy checks, first are we too far in the future or too far in the past? | 85 | // easy checks, first are we too far in the future or too far in the past? |
84 | QDate tmpDate; | 86 | QDate tmpDate; |
85 | int freq = frequency(); | 87 | int freq = frequency(); |
86 | int diff, diff2, a; | 88 | int diff, diff2, a; |
87 | int iday, imonth, iyear; | 89 | int iday, imonth, iyear; |
88 | int dayOfWeek = 0; | 90 | int dayOfWeek = 0; |
89 | int firstOfWeek = 0; | 91 | int firstOfWeek = 0; |
90 | int weekOfMonth; | 92 | int weekOfMonth; |
91 | 93 | ||
92 | 94 | ||
93 | if (hasEndDate() && endDate() < from) | 95 | if (hasEndDate() && endDate() < from) |
94 | return FALSE; | 96 | return FALSE; |
95 | 97 | ||
96 | if (start() >= from) { | 98 | if (start() >= from) { |
97 | next = start(); | 99 | next = start(); |
98 | return TRUE; | 100 | return TRUE; |
99 | } | 101 | } |
100 | 102 | ||
101 | switch ( type() ) { | 103 | switch ( type() ) { |
102 | case Weekly: | 104 | case Weekly: |
@@ -321,131 +323,124 @@ bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | |||
321 | iyear = iyear + a; | 323 | iyear = iyear + a; |
322 | } | 324 | } |
323 | 325 | ||
324 | /* under the assumption we won't hit one of the special not-leap years twice */ | 326 | /* under the assumption we won't hit one of the special not-leap years twice */ |
325 | if(!QDate::isValid(iyear, imonth, iday)) { | 327 | if(!QDate::isValid(iyear, imonth, iday)) { |
326 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 328 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
327 | iyear += freq; | 329 | iyear += freq; |
328 | } | 330 | } |
329 | 331 | ||
330 | if(QDate(iyear, imonth, iday) >= from) { | 332 | if(QDate(iyear, imonth, iday) >= from) { |
331 | next = QDate(iyear, imonth, iday); | 333 | next = QDate(iyear, imonth, iday); |
332 | 334 | ||
333 | if ((next > endDate()) && hasEndDate() ) | 335 | if ((next > endDate()) && hasEndDate() ) |
334 | return FALSE; | 336 | return FALSE; |
335 | return TRUE; | 337 | return TRUE; |
336 | } | 338 | } |
337 | /* iyear == from.year(), need to advance again */ | 339 | /* iyear == from.year(), need to advance again */ |
338 | iyear += freq; | 340 | iyear += freq; |
339 | /* under the assumption we won't hit one of the special not-leap years twice */ | 341 | /* under the assumption we won't hit one of the special not-leap years twice */ |
340 | if(!QDate::isValid(iyear, imonth, iday)) { | 342 | if(!QDate::isValid(iyear, imonth, iday)) { |
341 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 343 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
342 | iyear += freq; | 344 | iyear += freq; |
343 | } | 345 | } |
344 | 346 | ||
345 | next = QDate(iyear, imonth, iday); | 347 | next = QDate(iyear, imonth, iday); |
346 | if ((next > endDate()) && hasEndDate() ) | 348 | if ((next > endDate()) && hasEndDate() ) |
347 | return FALSE; | 349 | return FALSE; |
348 | return TRUE; | 350 | return TRUE; |
349 | default: | 351 | default: |
350 | return FALSE; | 352 | return FALSE; |
351 | } | 353 | } |
352 | } | 354 | } |
353 | ORecur::RepeatType ORecur::type()const{ | 355 | ORecur::RepeatType ORecur::type()const{ |
354 | return data->type; | 356 | return data->type; |
355 | } | 357 | } |
356 | int ORecur::frequency()const { | 358 | int ORecur::frequency()const { |
357 | return data->freq; | 359 | return data->freq; |
358 | } | 360 | } |
359 | int ORecur::position()const { | 361 | int ORecur::position()const { |
360 | return data->pos; | 362 | return data->pos; |
361 | } | 363 | } |
362 | char ORecur::days() const{ | 364 | char ORecur::days() const{ |
363 | return data->days; | 365 | return data->days; |
364 | } | 366 | } |
365 | bool ORecur::hasEndDate()const { | 367 | bool ORecur::hasEndDate()const { |
366 | return data->hasEnd; | 368 | return data->hasEnd; |
367 | } | 369 | } |
368 | QDate ORecur::endDate()const { | 370 | QDate ORecur::endDate()const { |
369 | return TimeConversion::fromUTC( data->end ).date(); | 371 | return data->end; |
370 | } | 372 | } |
371 | QDate ORecur::start()const{ | 373 | QDate ORecur::start()const{ |
372 | return data->start; | 374 | return data->start; |
373 | } | 375 | } |
374 | time_t ORecur::endDateUTC()const { | 376 | QDateTime ORecur::createdDateTime()const { |
375 | return data->end; | ||
376 | } | ||
377 | time_t ORecur::createTime()const { | ||
378 | return data->create; | 377 | return data->create; |
379 | } | 378 | } |
380 | int ORecur::repetition()const { | 379 | int ORecur::repetition()const { |
381 | return data->rep; | 380 | return data->rep; |
382 | } | 381 | } |
383 | QString ORecur::service()const { | 382 | QString ORecur::service()const { |
384 | return data->app; | 383 | return data->app; |
385 | } | 384 | } |
386 | ORecur::ExceptionList& ORecur::exceptions() { | 385 | ORecur::ExceptionList& ORecur::exceptions() { |
387 | return data->list; | 386 | return data->list; |
388 | } | 387 | } |
389 | void ORecur::setType( const RepeatType& z) { | 388 | void ORecur::setType( const RepeatType& z) { |
390 | checkOrModify(); | 389 | checkOrModify(); |
391 | data->type = z; | 390 | data->type = z; |
392 | } | 391 | } |
393 | void ORecur::setFrequency( int freq ) { | 392 | void ORecur::setFrequency( int freq ) { |
394 | checkOrModify(); | 393 | checkOrModify(); |
395 | data->freq = freq; | 394 | data->freq = freq; |
396 | } | 395 | } |
397 | void ORecur::setPosition( int pos ) { | 396 | void ORecur::setPosition( int pos ) { |
398 | checkOrModify(); | 397 | checkOrModify(); |
399 | data->pos = pos; | 398 | data->pos = pos; |
400 | } | 399 | } |
401 | void ORecur::setDays( char c ) { | 400 | void ORecur::setDays( char c ) { |
402 | checkOrModify(); | 401 | checkOrModify(); |
403 | data->days = c; | 402 | data->days = c; |
404 | } | 403 | } |
405 | void ORecur::setEndDate( const QDate& dt) { | 404 | void ORecur::setEndDate( const QDate& dt) { |
406 | checkOrModify(); | 405 | checkOrModify(); |
407 | data->end = TimeConversion::toUTC( dt ); | 406 | data->end = dt; |
408 | } | ||
409 | void ORecur::setEndDateUTC( time_t t) { | ||
410 | checkOrModify(); | ||
411 | data->end = t; | ||
412 | } | 407 | } |
413 | void ORecur::setCreateTime( time_t t) { | 408 | void ORecur::setCreatedDateTime( const QDateTime& t) { |
414 | checkOrModify(); | 409 | checkOrModify(); |
415 | data->create = t; | 410 | data->create = t; |
416 | } | 411 | } |
417 | void ORecur::setHasEndDate( bool b) { | 412 | void ORecur::setHasEndDate( bool b) { |
418 | checkOrModify(); | 413 | checkOrModify(); |
419 | data->hasEnd = b; | 414 | data->hasEnd = b; |
420 | } | 415 | } |
421 | void ORecur::setRepitition( int rep ) { | 416 | void ORecur::setRepitition( int rep ) { |
422 | checkOrModify(); | 417 | checkOrModify(); |
423 | data->rep = rep; | 418 | data->rep = rep; |
424 | } | 419 | } |
425 | void ORecur::setService( const QString& app ) { | 420 | void ORecur::setService( const QString& app ) { |
426 | checkOrModify(); | 421 | checkOrModify(); |
427 | data->app = app; | 422 | data->app = app; |
428 | } | 423 | } |
429 | void ORecur::setStart( const QDate& dt ) { | 424 | void ORecur::setStart( const QDate& dt ) { |
430 | checkOrModify(); | 425 | checkOrModify(); |
431 | data->start = dt; | 426 | data->start = dt; |
432 | } | 427 | } |
433 | void ORecur::checkOrModify() { | 428 | void ORecur::checkOrModify() { |
434 | if ( data->count != 1 ) { | 429 | if ( data->count != 1 ) { |
435 | data->deref(); | 430 | data->deref(); |
436 | Data* d2 = new Data; | 431 | Data* d2 = new Data; |
437 | d2->days = data->days; | 432 | d2->days = data->days; |
438 | d2->type = data->type; | 433 | d2->type = data->type; |
439 | d2->freq = data->freq; | 434 | d2->freq = data->freq; |
440 | d2->pos = data->pos; | 435 | d2->pos = data->pos; |
441 | d2->hasEnd = data->hasEnd; | 436 | d2->hasEnd = data->hasEnd; |
442 | d2->end = data->end; | 437 | d2->end = data->end; |
443 | d2->create = data->create; | 438 | d2->create = data->create; |
444 | d2->rep = data->rep; | 439 | d2->rep = data->rep; |
445 | d2->app = data->app; | 440 | d2->app = data->app; |
446 | d2->list = data->list; | 441 | d2->list = data->list; |
447 | d2->start = data->start; | 442 | d2->start = data->start; |
448 | data = d2; | 443 | data = d2; |
449 | } | 444 | } |
450 | } | 445 | } |
451 | 446 | ||