summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/orecur.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/orecur.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/orecur.cpp76
1 files changed, 71 insertions, 5 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp
index 033f264..5e2da25 100644
--- a/libopie2/opiepim/core/orecur.cpp
+++ b/libopie2/opiepim/core/orecur.cpp
@@ -18,34 +18,38 @@
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include <time.h> 30#include "orecur.h"
31 31
32#include <qshared.h> 32/* OPIE */
33#include <opie2/otimezone.h>
34#include <qpe/timeconversion.h>
33 35
34#include <qtopia/timeconversion.h> 36/* QT */
37#include <qshared.h>
35 38
36#include <opie2/otimezone.h> 39/* STD */
37#include <opie2/orecur.h> 40#include <time.h>
38 41
39namespace Opie { 42namespace Opie {
43
40struct ORecur::Data : public QShared { 44struct ORecur::Data : public QShared {
41 Data() : QShared() { 45 Data() : QShared() {
42 type = ORecur::NoRepeat; 46 type = ORecur::NoRepeat;
43 freq = -1; 47 freq = -1;
44 days = 0; 48 days = 0;
45 pos = 0; 49 pos = 0;
46 create = QDateTime::currentDateTime(); 50 create = QDateTime::currentDateTime();
47 hasEnd = FALSE; 51 hasEnd = FALSE;
48 end = QDate::currentDate(); 52 end = QDate::currentDate();
49 } 53 }
50 char days; // Q_UINT8 for 8 seven days;) 54 char days; // Q_UINT8 for 8 seven days;)
51 ORecur::RepeatType type; 55 ORecur::RepeatType type;
@@ -68,76 +72,92 @@ ORecur::ORecur() {
68ORecur::ORecur( const QMap<int, QString>& map ) 72ORecur::ORecur( const QMap<int, QString>& map )
69{ 73{
70 ORecur(); 74 ORecur();
71 fromMap( map ); 75 fromMap( map );
72} 76}
73 77
74 78
75ORecur::ORecur( const ORecur& rec) 79ORecur::ORecur( const ORecur& rec)
76 : data( rec.data ) 80 : data( rec.data )
77{ 81{
78 data->ref(); 82 data->ref();
79} 83}
84
85
80ORecur::~ORecur() { 86ORecur::~ORecur() {
81 if ( data->deref() ) { 87 if ( data->deref() ) {
82 delete data; 88 delete data;
83 data = 0l; 89 data = 0l;
84 } 90 }
85} 91}
92
93
86void ORecur::deref() { 94void ORecur::deref() {
87 if ( data->deref() ) { 95 if ( data->deref() ) {
88 delete data; 96 delete data;
89 data = 0l; 97 data = 0l;
90 } 98 }
91} 99}
100
101
92bool ORecur::operator==( const ORecur& )const { 102bool ORecur::operator==( const ORecur& )const {
93 return false; 103 return false;
94} 104}
105
106
95ORecur &ORecur::operator=( const ORecur& re) { 107ORecur &ORecur::operator=( const ORecur& re) {
96 if ( *this == re ) return *this; 108 if ( *this == re ) return *this;
97 109
98 re.data->ref(); 110 re.data->ref();
99 deref(); 111 deref();
100 data = re.data; 112 data = re.data;
101 113
102 return *this; 114 return *this;
103} 115}
116
117
104bool ORecur::doesRecur()const { 118bool ORecur::doesRecur()const {
105 return !( type() == NoRepeat ); 119 return !( type() == NoRepeat );
106} 120}
121
122
107/* 123/*
108 * we try to be smart here 124 * we try to be smart here
109 * 125 *
110 */ 126 */
111bool ORecur::doesRecur( const QDate& date ) { 127bool ORecur::doesRecur( const QDate& date ) {
112 /* the day before the recurrance */ 128 /* the day before the recurrance */
113 QDate da = date.addDays(-1); 129 QDate da = date.addDays(-1);
114 130
115 QDate recur; 131 QDate recur;
116 if (!nextOcurrence( da, recur ) ) 132 if (!nextOcurrence( da, recur ) )
117 return false; 133 return false;
118 134
119 return (recur == date); 135 return (recur == date);
120} 136}
137
138
121// FIXME unuglify! 139// FIXME unuglify!
122// GPL from Datebookdb.cpp 140// GPL from Datebookdb.cpp
123// FIXME exception list! 141// FIXME exception list!
124bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { 142bool ORecur::nextOcurrence( const QDate& from, QDate& next ) {
125 bool stillLooking; 143 bool stillLooking;
126 stillLooking = p_nextOccurrence( from, next ); 144 stillLooking = p_nextOccurrence( from, next );
127 while ( stillLooking && data->list.contains(next) ) 145 while ( stillLooking && data->list.contains(next) )
128 stillLooking = p_nextOccurrence( next.addDays(1), next ); 146 stillLooking = p_nextOccurrence( next.addDays(1), next );
129 147
130 return stillLooking; 148 return stillLooking;
131} 149}
150
151
132bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { 152bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) {
133 153
134 // easy checks, first are we too far in the future or too far in the past? 154 // easy checks, first are we too far in the future or too far in the past?
135 QDate tmpDate; 155 QDate tmpDate;
136 int freq = frequency(); 156 int freq = frequency();
137 int diff, diff2, a; 157 int diff, diff2, a;
138 int iday, imonth, iyear; 158 int iday, imonth, iyear;
139 int dayOfWeek = 0; 159 int dayOfWeek = 0;
140 int firstOfWeek = 0; 160 int firstOfWeek = 0;
141 int weekOfMonth; 161 int weekOfMonth;
142 162
143 163
@@ -392,115 +412,161 @@ bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) {
392 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ 412 /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
393 iyear += freq; 413 iyear += freq;
394 } 414 }
395 415
396 next = QDate(iyear, imonth, iday); 416 next = QDate(iyear, imonth, iday);
397 if ((next > endDate()) && hasEndDate() ) 417 if ((next > endDate()) && hasEndDate() )
398 return FALSE; 418 return FALSE;
399 return TRUE; 419 return TRUE;
400 default: 420 default:
401 return FALSE; 421 return FALSE;
402 } 422 }
403} 423}
424
425
404ORecur::RepeatType ORecur::type()const{ 426ORecur::RepeatType ORecur::type()const{
405 return data->type; 427 return data->type;
406} 428}
429
430
407int ORecur::frequency()const { 431int ORecur::frequency()const {
408 return data->freq; 432 return data->freq;
409} 433}
434
435
410int ORecur::position()const { 436int ORecur::position()const {
411 return data->pos; 437 return data->pos;
412} 438}
439
440
413char ORecur::days() const{ 441char ORecur::days() const{
414 return data->days; 442 return data->days;
415} 443}
444
445
416bool ORecur::hasEndDate()const { 446bool ORecur::hasEndDate()const {
417 return data->hasEnd; 447 return data->hasEnd;
418} 448}
449
450
419QDate ORecur::endDate()const { 451QDate ORecur::endDate()const {
420 return data->end; 452 return data->end;
421} 453}
454
455
422QDate ORecur::start()const{ 456QDate ORecur::start()const{
423 return data->start; 457 return data->start;
424} 458}
459
460
425QDateTime ORecur::createdDateTime()const { 461QDateTime ORecur::createdDateTime()const {
426 return data->create; 462 return data->create;
427} 463}
464
465
428int ORecur::repetition()const { 466int ORecur::repetition()const {
429 return data->rep; 467 return data->rep;
430} 468}
469
470
431QString ORecur::service()const { 471QString ORecur::service()const {
432 return data->app; 472 return data->app;
433} 473}
474
475
434ORecur::ExceptionList& ORecur::exceptions() { 476ORecur::ExceptionList& ORecur::exceptions() {
435 return data->list; 477 return data->list;
436} 478}
479
480
437void ORecur::setType( const RepeatType& z) { 481void ORecur::setType( const RepeatType& z) {
438 checkOrModify(); 482 checkOrModify();
439 data->type = z; 483 data->type = z;
440} 484}
485
486
441void ORecur::setFrequency( int freq ) { 487void ORecur::setFrequency( int freq ) {
442 checkOrModify(); 488 checkOrModify();
443 data->freq = freq; 489 data->freq = freq;
444} 490}
491
492
445void ORecur::setPosition( int pos ) { 493void ORecur::setPosition( int pos ) {
446 checkOrModify(); 494 checkOrModify();
447 data->pos = pos; 495 data->pos = pos;
448} 496}
497
498
449void ORecur::setDays( char c ) { 499void ORecur::setDays( char c ) {
450 checkOrModify(); 500 checkOrModify();
451 data->days = c; 501 data->days = c;
452} 502}
503
504
453void ORecur::setEndDate( const QDate& dt) { 505void ORecur::setEndDate( const QDate& dt) {
454 checkOrModify(); 506 checkOrModify();
455 data->end = dt; 507 data->end = dt;
456} 508}
509
510
457void ORecur::setCreatedDateTime( const QDateTime& t) { 511void ORecur::setCreatedDateTime( const QDateTime& t) {
458 checkOrModify(); 512 checkOrModify();
459 data->create = t; 513 data->create = t;
460} 514}
515
516
461void ORecur::setHasEndDate( bool b) { 517void ORecur::setHasEndDate( bool b) {
462 checkOrModify(); 518 checkOrModify();
463 data->hasEnd = b; 519 data->hasEnd = b;
464} 520}
521
522
465void ORecur::setRepitition( int rep ) { 523void ORecur::setRepitition( int rep ) {
466 checkOrModify(); 524 checkOrModify();
467 data->rep = rep; 525 data->rep = rep;
468} 526}
527
528
469void ORecur::setService( const QString& app ) { 529void ORecur::setService( const QString& app ) {
470 checkOrModify(); 530 checkOrModify();
471 data->app = app; 531 data->app = app;
472} 532}
533
534
473void ORecur::setStart( const QDate& dt ) { 535void ORecur::setStart( const QDate& dt ) {
474 checkOrModify(); 536 checkOrModify();
475 data->start = dt; 537 data->start = dt;
476} 538}
539
540
477void ORecur::checkOrModify() { 541void ORecur::checkOrModify() {
478 if ( data->count != 1 ) { 542 if ( data->count != 1 ) {
479 data->deref(); 543 data->deref();
480 Data* d2 = new Data; 544 Data* d2 = new Data;
481 d2->days = data->days; 545 d2->days = data->days;
482 d2->type = data->type; 546 d2->type = data->type;
483 d2->freq = data->freq; 547 d2->freq = data->freq;
484 d2->pos = data->pos; 548 d2->pos = data->pos;
485 d2->hasEnd = data->hasEnd; 549 d2->hasEnd = data->hasEnd;
486 d2->end = data->end; 550 d2->end = data->end;
487 d2->create = data->create; 551 d2->create = data->create;
488 d2->rep = data->rep; 552 d2->rep = data->rep;
489 d2->app = data->app; 553 d2->app = data->app;
490 d2->list = data->list; 554 d2->list = data->list;
491 d2->start = data->start; 555 d2->start = data->start;
492 data = d2; 556 data = d2;
493 } 557 }
494} 558}
559
560
495QString ORecur::toString()const { 561QString ORecur::toString()const {
496 QString buf; 562 QString buf;
497 QMap<int, QString> recMap = toMap(); 563 QMap<int, QString> recMap = toMap();
498 564
499 buf += " rtype=\""; 565 buf += " rtype=\"";
500 buf += recMap[ORecur::RType]; 566 buf += recMap[ORecur::RType];
501 buf += "\""; 567 buf += "\"";
502 if (data->days > 0 ) 568 if (data->days > 0 )
503 buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\""; 569 buf += " rweekdays=\"" + recMap[ORecur::RWeekdays] + "\"";
504 if ( data->pos != 0 ) 570 if ( data->pos != 0 )
505 buf += " rposition=\"" + recMap[ORecur::RPosition] + "\""; 571 buf += " rposition=\"" + recMap[ORecur::RPosition] + "\"";
506 572