-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 66 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.h | 4 |
2 files changed, 69 insertions, 1 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index e6a4787..e3b45b4 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -1,10 +1,13 @@ | |||
1 | #include <time.h> | ||
2 | |||
1 | #include <qshared.h> | 3 | #include <qshared.h> |
2 | 4 | ||
3 | #include <qtopia/timeconversion.h> | 5 | #include <qtopia/timeconversion.h> |
4 | 6 | ||
7 | #include "otimezone.h" | ||
5 | #include "orecur.h" | 8 | #include "orecur.h" |
6 | 9 | ||
7 | struct ORecur::Data : public QShared { | 10 | struct ORecur::Data : public QShared { |
8 | Data() : QShared() { | 11 | Data() : QShared() { |
9 | type = ORecur::NoRepeat; | 12 | type = ORecur::NoRepeat; |
10 | freq = -1; | 13 | freq = -1; |
@@ -78,12 +81,20 @@ bool ORecur::doesRecur( const QDate& date ) { | |||
78 | return (recur == date); | 81 | return (recur == date); |
79 | } | 82 | } |
80 | // FIXME unuglify! | 83 | // FIXME unuglify! |
81 | // GPL from Datebookdb.cpp | 84 | // GPL from Datebookdb.cpp |
82 | // FIXME exception list! | 85 | // FIXME exception list! |
83 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | 86 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { |
87 | bool stillLooking; | ||
88 | stillLooking = p_nextOccurrence( from, next ); | ||
89 | while ( stillLooking && data->list.contains(next) ) | ||
90 | stillLooking = p_nextOccurrence( next.addDays(1), next ); | ||
91 | |||
92 | return stillLooking; | ||
93 | } | ||
94 | bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { | ||
84 | 95 | ||
85 | // easy checks, first are we too far in the future or too far in the past? | 96 | // easy checks, first are we too far in the future or too far in the past? |
86 | QDate tmpDate; | 97 | QDate tmpDate; |
87 | int freq = frequency(); | 98 | int freq = frequency(); |
88 | int diff, diff2, a; | 99 | int diff, diff2, a; |
89 | int iday, imonth, iyear; | 100 | int iday, imonth, iyear; |
@@ -440,7 +451,60 @@ void ORecur::checkOrModify() { | |||
440 | d2->app = data->app; | 451 | d2->app = data->app; |
441 | d2->list = data->list; | 452 | d2->list = data->list; |
442 | d2->start = data->start; | 453 | d2->start = data->start; |
443 | data = d2; | 454 | data = d2; |
444 | } | 455 | } |
445 | } | 456 | } |
446 | 457 | QString ORecur::toString()const { | |
458 | QString buf; | ||
459 | |||
460 | buf += " rtype=\""; | ||
461 | switch ( data->type ) { | ||
462 | case ORecur::Daily: | ||
463 | buf += "Daily"; | ||
464 | break; | ||
465 | case ORecur::Weekly: | ||
466 | buf += "Weekly"; | ||
467 | break; | ||
468 | case ORecur::MonthlyDay: | ||
469 | buf += "MonthlyDay"; | ||
470 | break; | ||
471 | case ORecur::MonthlyDate: | ||
472 | buf += "MonthlyDate"; | ||
473 | break; | ||
474 | case ORecur::Yearly: | ||
475 | buf += "Yearly"; | ||
476 | break; | ||
477 | default: | ||
478 | buf += "NoRepeat"; | ||
479 | break; | ||
480 | } | ||
481 | buf += "\""; | ||
482 | if (data->days > 0 ) | ||
483 | buf += " rweekdays=\"" + QString::number( static_cast<int>( data->days ) ) + "\""; | ||
484 | if ( data->pos != 0 ) | ||
485 | buf += " rposition=\"" + QString::number(data->pos ) + "\""; | ||
486 | |||
487 | buf += " rfreq=\"" + QString::number( data->freq ) + "\""; | ||
488 | buf += " rhasenddate=\"" + QString::number( static_cast<int>( data->hasEnd ) ) + "\""; | ||
489 | if ( data->hasEnd ) | ||
490 | buf += " enddt=\"" | ||
491 | + QString::number( OTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) | ||
492 | + "\""; | ||
493 | buf += " created=\"" + QString::number( OTimeZone::utc().fromUTCDateTime( data->create ) ) + "\""; | ||
494 | |||
495 | if ( data->list.isEmpty() ) return buf; | ||
496 | // save exceptions list here!! | ||
497 | ExceptionList::ConstIterator it; | ||
498 | ExceptionList list = data->list; | ||
499 | buf += " exceptions=\""; | ||
500 | QDate date; | ||
501 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
502 | date = (*it); | ||
503 | if ( it != list.begin() ) buf += " "; | ||
504 | |||
505 | buf += QCString().sprintf("%04d%02d%02d", date.year(), date.month(), date.day() ); | ||
506 | } | ||
507 | buf += "\""; | ||
508 | |||
509 | return buf; | ||
510 | } | ||
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h index 1e0014b..b214b3f 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/orecur.h | |||
@@ -70,13 +70,17 @@ public: | |||
70 | void setStart( const QDate& dt ); | 70 | void setStart( const QDate& dt ); |
71 | void setCreatedDateTime( const QDateTime& ); | 71 | void setCreatedDateTime( const QDateTime& ); |
72 | void setHasEndDate( bool b ); | 72 | void setHasEndDate( bool b ); |
73 | void setRepitition(int ); | 73 | void setRepitition(int ); |
74 | 74 | ||
75 | void setService( const QString& ser ); | 75 | void setService( const QString& ser ); |
76 | |||
77 | /* almost internal */ | ||
78 | QString toString()const; | ||
76 | private: | 79 | private: |
80 | bool p_nextOccurrence( const QDate& from, QDate& next ); | ||
77 | void deref(); | 81 | void deref(); |
78 | inline void checkOrModify(); | 82 | inline void checkOrModify(); |
79 | 83 | ||
80 | 84 | ||
81 | class Data; | 85 | class Data; |
82 | Data* data; | 86 | Data* data; |