summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/oevent.cpp20
-rw-r--r--libopie/pim/otodo.cpp12
-rw-r--r--libopie2/opiepim/oevent.cpp20
-rw-r--r--libopie2/opiepim/otodo.cpp12
4 files changed, 46 insertions, 18 deletions
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp
index cda12f9..2b138c0 100644
--- a/libopie/pim/oevent.cpp
+++ b/libopie/pim/oevent.cpp
@@ -1,480 +1,490 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qpe/palmtopuidgen.h> 3#include <qpe/palmtopuidgen.h>
4#include <qpe/categories.h> 4#include <qpe/categories.h>
5#include <qpe/stringutil.h> 5#include <qpe/stringutil.h>
6 6
7#include "orecur.h" 7#include "orecur.h"
8#include "opimresolver.h" 8#include "opimresolver.h"
9#include "opimnotifymanager.h" 9#include "opimnotifymanager.h"
10 10
11#include "oevent.h" 11#include "oevent.h"
12 12
13int OCalendarHelper::week( const QDate& date) { 13int OCalendarHelper::week( const QDate& date) {
14 // Calculates the week this date is in within that 14 // Calculates the week this date is in within that
15 // month. Equals the "row" is is in in the month view 15 // month. Equals the "row" is is in in the month view
16 int week = 1; 16 int week = 1;
17 QDate tmp( date.year(), date.month(), 1 ); 17 QDate tmp( date.year(), date.month(), 1 );
18 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 18 if ( date.dayOfWeek() < tmp.dayOfWeek() )
19 ++week; 19 ++week;
20 20
21 week += ( date.day() - 1 ) / 7; 21 week += ( date.day() - 1 ) / 7;
22 22
23 return week; 23 return week;
24} 24}
25int OCalendarHelper::ocurrence( const QDate& date) { 25int OCalendarHelper::ocurrence( const QDate& date) {
26 // calculates the number of occurrances of this day of the 26 // calculates the number of occurrances of this day of the
27 // week till the given date (e.g 3rd Wednesday of the month) 27 // week till the given date (e.g 3rd Wednesday of the month)
28 return ( date.day() - 1 ) / 7 + 1; 28 return ( date.day() - 1 ) / 7 + 1;
29} 29}
30int OCalendarHelper::dayOfWeek( char day ) { 30int OCalendarHelper::dayOfWeek( char day ) {
31 int dayOfWeek = 1; 31 int dayOfWeek = 1;
32 char i = ORecur::MON; 32 char i = ORecur::MON;
33 while ( !( i & day ) && i <= ORecur::SUN ) { 33 while ( !( i & day ) && i <= ORecur::SUN ) {
34 i <<= 1; 34 i <<= 1;
35 ++dayOfWeek; 35 ++dayOfWeek;
36 } 36 }
37 return dayOfWeek; 37 return dayOfWeek;
38} 38}
39int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 39int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
40 return ( second.year() - first.year() ) * 12 + 40 return ( second.year() - first.year() ) * 12 +
41 second.month() - first.month(); 41 second.month() - first.month();
42} 42}
43 43
44struct OEvent::Data : public QShared { 44struct OEvent::Data : public QShared {
45 Data() : QShared() { 45 Data() : QShared() {
46 child = 0; 46 child = 0;
47 recur = 0; 47 recur = 0;
48 manager = 0; 48 manager = 0;
49 isAllDay = false; 49 isAllDay = false;
50 parent = 0; 50 parent = 0;
51 } 51 }
52 ~Data() { 52 ~Data() {
53 delete manager; 53 delete manager;
54 delete recur; 54 delete recur;
55 } 55 }
56 QString description; 56 QString description;
57 QString location; 57 QString location;
58 OPimNotifyManager* manager; 58 OPimNotifyManager* manager;
59 ORecur* recur; 59 ORecur* recur;
60 QString note; 60 QString note;
61 QDateTime created; 61 QDateTime created;
62 QDateTime start; 62 QDateTime start;
63 QDateTime end; 63 QDateTime end;
64 bool isAllDay : 1; 64 bool isAllDay : 1;
65 QString timezone; 65 QString timezone;
66 QArray<int>* child; 66 QArray<int>* child;
67 int parent; 67 int parent;
68}; 68};
69 69
70OEvent::OEvent( int uid ) 70OEvent::OEvent( int uid )
71 : OPimRecord( uid ) { 71 : OPimRecord( uid ) {
72 data = new Data; 72 data = new Data;
73} 73}
74OEvent::OEvent( const OEvent& ev) 74OEvent::OEvent( const OEvent& ev)
75 : OPimRecord( ev ), data( ev.data ) 75 : OPimRecord( ev ), data( ev.data )
76{ 76{
77 data->ref(); 77 data->ref();
78} 78}
79OEvent::~OEvent() { 79OEvent::~OEvent() {
80 if ( data->deref() ) { 80 if ( data->deref() ) {
81 delete data; 81 delete data;
82 data = 0; 82 data = 0;
83 } 83 }
84} 84}
85OEvent& OEvent::operator=( const OEvent& ev) { 85OEvent& OEvent::operator=( const OEvent& ev) {
86 if ( this == &ev ) return *this; 86 if ( this == &ev ) return *this;
87 87
88 OPimRecord::operator=( ev ); 88 OPimRecord::operator=( ev );
89 ev.data->ref(); 89 ev.data->ref();
90 deref(); 90 deref();
91 data = ev.data; 91 data = ev.data;
92 92
93 93
94 return *this; 94 return *this;
95} 95}
96QString OEvent::description()const { 96QString OEvent::description()const {
97 return data->description; 97 return data->description;
98} 98}
99void OEvent::setDescription( const QString& description ) { 99void OEvent::setDescription( const QString& description ) {
100 changeOrModify(); 100 changeOrModify();
101 data->description = description; 101 data->description = description;
102} 102}
103void OEvent::setLocation( const QString& loc ) { 103void OEvent::setLocation( const QString& loc ) {
104 changeOrModify(); 104 changeOrModify();
105 data->location = loc; 105 data->location = loc;
106} 106}
107QString OEvent::location()const { 107QString OEvent::location()const {
108 return data->location; 108 return data->location;
109} 109}
110OPimNotifyManager &OEvent::notifiers()const { 110OPimNotifyManager &OEvent::notifiers()const {
111 // I hope we can skip the changeOrModify here 111 // I hope we can skip the changeOrModify here
112 // the notifier should take care of it 112 // the notifier should take care of it
113 // and OPimNotify is shared too 113 // and OPimNotify is shared too
114 if (!data->manager ) 114 if (!data->manager )
115 data->manager = new OPimNotifyManager; 115 data->manager = new OPimNotifyManager;
116 116
117 return *data->manager; 117 return *data->manager;
118} 118}
119bool OEvent::hasNotifiers()const { 119bool OEvent::hasNotifiers()const {
120 if (!data->manager ) 120 if (!data->manager )
121 return false; 121 return false;
122 if (data->manager->reminders().isEmpty() && 122 if (data->manager->reminders().isEmpty() &&
123 data->manager->alarms().isEmpty() ) 123 data->manager->alarms().isEmpty() )
124 return false; 124 return false;
125 125
126 return true; 126 return true;
127} 127}
128ORecur OEvent::recurrence()const { 128ORecur OEvent::recurrence()const {
129 if (!data->recur) 129 if (!data->recur)
130 data->recur = new ORecur; 130 data->recur = new ORecur;
131 131
132 return *data->recur; 132 return *data->recur;
133} 133}
134void OEvent::setRecurrence( const ORecur& rec) { 134void OEvent::setRecurrence( const ORecur& rec) {
135 changeOrModify(); 135 changeOrModify();
136 if (data->recur ) 136 if (data->recur )
137 (*data->recur) = rec; 137 (*data->recur) = rec;
138 else 138 else
139 data->recur = new ORecur( rec ); 139 data->recur = new ORecur( rec );
140} 140}
141bool OEvent::hasRecurrence()const { 141bool OEvent::hasRecurrence()const {
142 if (!data->recur ) return false; 142 if (!data->recur ) return false;
143 return data->recur->doesRecur(); 143 return data->recur->doesRecur();
144} 144}
145QString OEvent::note()const { 145QString OEvent::note()const {
146 return data->note; 146 return data->note;
147} 147}
148void OEvent::setNote( const QString& note ) { 148void OEvent::setNote( const QString& note ) {
149 changeOrModify(); 149 changeOrModify();
150 data->note = note; 150 data->note = note;
151} 151}
152QDateTime OEvent::createdDateTime()const { 152QDateTime OEvent::createdDateTime()const {
153 return data->created; 153 return data->created;
154} 154}
155void OEvent::setCreatedDateTime( const QDateTime& time ) { 155void OEvent::setCreatedDateTime( const QDateTime& time ) {
156 changeOrModify(); 156 changeOrModify();
157 data->created = time; 157 data->created = time;
158} 158}
159QDateTime OEvent::startDateTime()const { 159QDateTime OEvent::startDateTime()const {
160 if ( data->isAllDay ) 160 if ( data->isAllDay )
161 return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); 161 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
162 return data->start; 162 return data->start;
163} 163}
164QDateTime OEvent::startDateTimeInZone()const { 164QDateTime OEvent::startDateTimeInZone()const {
165 /* if no timezone, or all day event or if the current and this timeZone match... */ 165 /* if no timezone, or all day event or if the current and this timeZone match... */
166 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); 166 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
167 167
168 OTimeZone zone(data->timezone ); 168 OTimeZone zone(data->timezone );
169 return zone.toDateTime( data->start, OTimeZone::current() ); 169 return zone.toDateTime( data->start, OTimeZone::current() );
170} 170}
171void OEvent::setStartDateTime( const QDateTime& dt ) { 171void OEvent::setStartDateTime( const QDateTime& dt ) {
172 changeOrModify(); 172 changeOrModify();
173 data->start = dt; 173 data->start = dt;
174} 174}
175QDateTime OEvent::endDateTime()const { 175QDateTime OEvent::endDateTime()const {
176 /* 176 /*
177 * if all Day event the end time needs 177 * if all Day event the end time needs
178 * to be on the same day as the start 178 * to be on the same day as the start
179 */ 179 */
180 if ( data->isAllDay ) 180 if ( data->isAllDay )
181 return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); 181 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
182 return data->end; 182 return data->end;
183} 183}
184QDateTime OEvent::endDateTimeInZone()const { 184QDateTime OEvent::endDateTimeInZone()const {
185 /* if no timezone, or all day event or if the current and this timeZone match... */ 185 /* if no timezone, or all day event or if the current and this timeZone match... */
186 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); 186 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
187 187
188 OTimeZone zone(data->timezone ); 188 OTimeZone zone(data->timezone );
189 return zone.toDateTime( data->end, OTimeZone::current() ); 189 return zone.toDateTime( data->end, OTimeZone::current() );
190} 190}
191void OEvent::setEndDateTime( const QDateTime& dt ) { 191void OEvent::setEndDateTime( const QDateTime& dt ) {
192 changeOrModify(); 192 changeOrModify();
193 data->end = dt; 193 data->end = dt;
194} 194}
195bool OEvent::isMultipleDay()const { 195bool OEvent::isMultipleDay()const {
196 return data->end.date().day() - data->start.date().day(); 196 return data->end.date().day() - data->start.date().day();
197} 197}
198bool OEvent::isAllDay()const { 198bool OEvent::isAllDay()const {
199 return data->isAllDay; 199 return data->isAllDay;
200} 200}
201void OEvent::setAllDay( bool allDay ) { 201void OEvent::setAllDay( bool allDay ) {
202 changeOrModify(); 202 changeOrModify();
203 data->isAllDay = allDay; 203 data->isAllDay = allDay;
204 if (allDay ) data->timezone = "UTC"; 204 if (allDay ) data->timezone = "UTC";
205} 205}
206void OEvent::setTimeZone( const QString& tz ) { 206void OEvent::setTimeZone( const QString& tz ) {
207 changeOrModify(); 207 changeOrModify();
208 data->timezone = tz; 208 data->timezone = tz;
209} 209}
210QString OEvent::timeZone()const { 210QString OEvent::timeZone()const {
211 if (data->isAllDay ) return QString::fromLatin1("UTC"); 211 if (data->isAllDay ) return QString::fromLatin1("UTC");
212 return data->timezone; 212 return data->timezone;
213} 213}
214bool OEvent::match( const QRegExp& re )const { 214bool OEvent::match( const QRegExp& re )const {
215 if ( re.match( data->description ) != -1 ) 215 if ( re.match( data->description ) != -1 ){
216 setLastHitField( DatebookDescription );
216 return true; 217 return true;
217 if ( re.match( data->note ) != -1 ) 218 }
219 if ( re.match( data->note ) != -1 ){
220 setLastHitField( Note );
218 return true; 221 return true;
219 if ( re.match( data->location ) != -1 ) 222 }
223 if ( re.match( data->location ) != -1 ){
224 setLastHitField( Location );
220 return true; 225 return true;
221 if ( re.match( data->start.toString() ) != -1 ) 226 }
227 if ( re.match( data->start.toString() ) != -1 ){
228 setLastHitField( StartDateTime );
222 return true; 229 return true;
223 if ( re.match( data->end.toString() ) != -1 ) 230 }
231 if ( re.match( data->end.toString() ) != -1 ){
232 setLastHitField( EndDateTime );
224 return true; 233 return true;
234 }
225 return false; 235 return false;
226} 236}
227QString OEvent::toRichText()const { 237QString OEvent::toRichText()const {
228 QString text; 238 QString text;
229 if ( !description().isEmpty() ) { 239 if ( !description().isEmpty() ) {
230 text += "<b>" + QObject::tr( "Description:") + "</b><br>"; 240 text += "<b>" + QObject::tr( "Description:") + "</b><br>";
231 text += Qtopia::escapeString(description() ). 241 text += Qtopia::escapeString(description() ).
232 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 242 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
233 } 243 }
234 if ( startDateTime().isValid() ) { 244 if ( startDateTime().isValid() ) {
235 text += "<b>" + QObject::tr( "Start:") + "</b> "; 245 text += "<b>" + QObject::tr( "Start:") + "</b> ";
236 text += Qtopia::escapeString(startDateTime().toString() ). 246 text += Qtopia::escapeString(startDateTime().toString() ).
237 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 247 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
238 } 248 }
239 if ( endDateTime().isValid() ) { 249 if ( endDateTime().isValid() ) {
240 text += "<b>" + QObject::tr( "End:") + "</b> "; 250 text += "<b>" + QObject::tr( "End:") + "</b> ";
241 text += Qtopia::escapeString(endDateTime().toString() ). 251 text += Qtopia::escapeString(endDateTime().toString() ).
242 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 252 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
243 } 253 }
244 if ( !note().isEmpty() ) { 254 if ( !note().isEmpty() ) {
245 text += "<b>" + QObject::tr( "Note:") + "</b><br>"; 255 text += "<b>" + QObject::tr( "Note:") + "</b><br>";
246 text += note(); 256 text += note();
247// text += Qtopia::escapeString(note() ). 257// text += Qtopia::escapeString(note() ).
248// replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 258// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
249 } 259 }
250 return text; 260 return text;
251} 261}
252QString OEvent::toShortText()const { 262QString OEvent::toShortText()const {
253 QString text; 263 QString text;
254 text += QString::number( startDateTime().date().day() ); 264 text += QString::number( startDateTime().date().day() );
255 text += "."; 265 text += ".";
256 text += QString::number( startDateTime().date().month() ); 266 text += QString::number( startDateTime().date().month() );
257 text += "."; 267 text += ".";
258 text += QString::number( startDateTime().date().year() ); 268 text += QString::number( startDateTime().date().year() );
259 text += " "; 269 text += " ";
260 text += QString::number( startDateTime().time().hour() ); 270 text += QString::number( startDateTime().time().hour() );
261 text += ":"; 271 text += ":";
262 text += QString::number( startDateTime().time().minute() ); 272 text += QString::number( startDateTime().time().minute() );
263 text += " - "; 273 text += " - ";
264 text += description(); 274 text += description();
265 return text; 275 return text;
266} 276}
267QString OEvent::type()const { 277QString OEvent::type()const {
268 return QString::fromLatin1("OEvent"); 278 return QString::fromLatin1("OEvent");
269} 279}
270QString OEvent::recordField( int /*id */ )const { 280QString OEvent::recordField( int /*id */ )const {
271 return QString::null; 281 return QString::null;
272} 282}
273int OEvent::rtti() { 283int OEvent::rtti() {
274 return OPimResolver::DateBook; 284 return OPimResolver::DateBook;
275} 285}
276bool OEvent::loadFromStream( QDataStream& ) { 286bool OEvent::loadFromStream( QDataStream& ) {
277 return true; 287 return true;
278} 288}
279bool OEvent::saveToStream( QDataStream& )const { 289bool OEvent::saveToStream( QDataStream& )const {
280 return true; 290 return true;
281} 291}
282void OEvent::changeOrModify() { 292void OEvent::changeOrModify() {
283 if ( data->count != 1 ) { 293 if ( data->count != 1 ) {
284 data->deref(); 294 data->deref();
285 Data* d2 = new Data; 295 Data* d2 = new Data;
286 d2->description = data->description; 296 d2->description = data->description;
287 d2->location = data->location; 297 d2->location = data->location;
288 298
289 if (data->manager ) 299 if (data->manager )
290 d2->manager = new OPimNotifyManager( *data->manager ); 300 d2->manager = new OPimNotifyManager( *data->manager );
291 301
292 if ( data->recur ) 302 if ( data->recur )
293 d2->recur = new ORecur( *data->recur ); 303 d2->recur = new ORecur( *data->recur );
294 304
295 d2->note = data->note; 305 d2->note = data->note;
296 d2->created = data->created; 306 d2->created = data->created;
297 d2->start = data->start; 307 d2->start = data->start;
298 d2->end = data->end; 308 d2->end = data->end;
299 d2->isAllDay = data->isAllDay; 309 d2->isAllDay = data->isAllDay;
300 d2->timezone = data->timezone; 310 d2->timezone = data->timezone;
301 d2->parent = data->parent; 311 d2->parent = data->parent;
302 312
303 if ( data->child ) { 313 if ( data->child ) {
304 d2->child = new QArray<int>( *data->child ); 314 d2->child = new QArray<int>( *data->child );
305 d2->child->detach(); 315 d2->child->detach();
306 } 316 }
307 317
308 data = d2; 318 data = d2;
309 } 319 }
310} 320}
311void OEvent::deref() { 321void OEvent::deref() {
312 if ( data->deref() ) { 322 if ( data->deref() ) {
313 delete data; 323 delete data;
314 data = 0; 324 data = 0;
315 } 325 }
316} 326}
317// FIXME 327// FIXME
318QMap<int, QString> OEvent::toMap()const { 328QMap<int, QString> OEvent::toMap()const {
319 return QMap<int, QString>(); 329 return QMap<int, QString>();
320} 330}
321QMap<QString, QString> OEvent::toExtraMap()const { 331QMap<QString, QString> OEvent::toExtraMap()const {
322 return QMap<QString, QString>(); 332 return QMap<QString, QString>();
323} 333}
324int OEvent::parent()const { 334int OEvent::parent()const {
325 return data->parent; 335 return data->parent;
326} 336}
327void OEvent::setParent( int uid ) { 337void OEvent::setParent( int uid ) {
328 changeOrModify(); 338 changeOrModify();
329 data->parent = uid; 339 data->parent = uid;
330} 340}
331QArray<int> OEvent::children() const{ 341QArray<int> OEvent::children() const{
332 if (!data->child) return QArray<int>(); 342 if (!data->child) return QArray<int>();
333 else 343 else
334 return data->child->copy(); 344 return data->child->copy();
335} 345}
336void OEvent::setChildren( const QArray<int>& arr ) { 346void OEvent::setChildren( const QArray<int>& arr ) {
337 changeOrModify(); 347 changeOrModify();
338 if (data->child) delete data->child; 348 if (data->child) delete data->child;
339 349
340 data->child = new QArray<int>( arr ); 350 data->child = new QArray<int>( arr );
341 data->child->detach(); 351 data->child->detach();
342} 352}
343void OEvent::addChild( int uid ) { 353void OEvent::addChild( int uid ) {
344 changeOrModify(); 354 changeOrModify();
345 if (!data->child ) { 355 if (!data->child ) {
346 data->child = new QArray<int>(1); 356 data->child = new QArray<int>(1);
347 (*data->child)[0] = uid; 357 (*data->child)[0] = uid;
348 }else{ 358 }else{
349 int count = data->child->count(); 359 int count = data->child->count();
350 data->child->resize( count + 1 ); 360 data->child->resize( count + 1 );
351 (*data->child)[count] = uid; 361 (*data->child)[count] = uid;
352 } 362 }
353} 363}
354void OEvent::removeChild( int uid ) { 364void OEvent::removeChild( int uid ) {
355 if (!data->child || !data->child->contains( uid ) ) return; 365 if (!data->child || !data->child->contains( uid ) ) return;
356 changeOrModify(); 366 changeOrModify();
357 QArray<int> newAr( data->child->count() - 1 ); 367 QArray<int> newAr( data->child->count() - 1 );
358 int j = 0; 368 int j = 0;
359 uint count = data->child->count(); 369 uint count = data->child->count();
360 for ( uint i = 0; i < count; i++ ) { 370 for ( uint i = 0; i < count; i++ ) {
361 if ( (*data->child)[i] != uid ) { 371 if ( (*data->child)[i] != uid ) {
362 newAr[j] = (*data->child)[i]; 372 newAr[j] = (*data->child)[i];
363 j++; 373 j++;
364 } 374 }
365 } 375 }
366 (*data->child) = newAr; 376 (*data->child) = newAr;
367} 377}
368struct OEffectiveEvent::Data : public QShared { 378struct OEffectiveEvent::Data : public QShared {
369 Data() : QShared() { 379 Data() : QShared() {
370 } 380 }
371 OEvent event; 381 OEvent event;
372 QDate date; 382 QDate date;
373 QTime start, end; 383 QTime start, end;
374 QDate startDate, endDate; 384 QDate startDate, endDate;
375 bool dates : 1; 385 bool dates : 1;
376}; 386};
377 387
378OEffectiveEvent::OEffectiveEvent() { 388OEffectiveEvent::OEffectiveEvent() {
379 data = new Data; 389 data = new Data;
380 data->date = QDate::currentDate(); 390 data->date = QDate::currentDate();
381 data->start = data->end = QTime::currentTime(); 391 data->start = data->end = QTime::currentTime();
382 data->dates = false; 392 data->dates = false;
383} 393}
384OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 394OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
385 Position pos ) { 395 Position pos ) {
386 data = new Data; 396 data = new Data;
387 data->event = ev; 397 data->event = ev;
388 data->date = startDate; 398 data->date = startDate;
389 if ( pos & Start ) 399 if ( pos & Start )
390 data->start = ev.startDateTime().time(); 400 data->start = ev.startDateTime().time();
391 else 401 else
392 data->start = QTime( 0, 0, 0 ); 402 data->start = QTime( 0, 0, 0 );
393 403
394 if ( pos & End ) 404 if ( pos & End )
395 data->end = ev.endDateTime().time(); 405 data->end = ev.endDateTime().time();
396 else 406 else
397 data->end = QTime( 23, 59, 59 ); 407 data->end = QTime( 23, 59, 59 );
398 408
399 data->dates = false; 409 data->dates = false;
400} 410}
401OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 411OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
402 data = ev.data; 412 data = ev.data;
403 data->ref(); 413 data->ref();
404} 414}
405OEffectiveEvent::~OEffectiveEvent() { 415OEffectiveEvent::~OEffectiveEvent() {
406 if ( data->deref() ) { 416 if ( data->deref() ) {
407 delete data; 417 delete data;
408 data = 0; 418 data = 0;
409 } 419 }
410} 420}
411OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 421OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
412 if ( *this == ev ) return *this; 422 if ( *this == ev ) return *this;
413 423
414 ev.data->ref(); 424 ev.data->ref();
415 deref(); 425 deref();
416 data = ev.data; 426 data = ev.data;
417 427
418 return *this; 428 return *this;
419} 429}
420 430
421void OEffectiveEvent::setStartTime( const QTime& ti) { 431void OEffectiveEvent::setStartTime( const QTime& ti) {
422 changeOrModify(); 432 changeOrModify();
423 data->start = ti; 433 data->start = ti;
424} 434}
425void OEffectiveEvent::setEndTime( const QTime& en) { 435void OEffectiveEvent::setEndTime( const QTime& en) {
426 changeOrModify(); 436 changeOrModify();
427 data->end = en; 437 data->end = en;
428} 438}
429void OEffectiveEvent::setEvent( const OEvent& ev) { 439void OEffectiveEvent::setEvent( const OEvent& ev) {
430 changeOrModify(); 440 changeOrModify();
431 data->event = ev; 441 data->event = ev;
432} 442}
433void OEffectiveEvent::setDate( const QDate& da) { 443void OEffectiveEvent::setDate( const QDate& da) {
434 changeOrModify(); 444 changeOrModify();
435 data->date = da; 445 data->date = da;
436} 446}
437void OEffectiveEvent::setEffectiveDates( const QDate& from, 447void OEffectiveEvent::setEffectiveDates( const QDate& from,
438 const QDate& to ) { 448 const QDate& to ) {
439 if (!from.isValid() ) { 449 if (!from.isValid() ) {
440 data->dates = false; 450 data->dates = false;
441 return; 451 return;
442 } 452 }
443 453
444 data->startDate = from; 454 data->startDate = from;
445 data->endDate = to; 455 data->endDate = to;
446} 456}
447QString OEffectiveEvent::description()const { 457QString OEffectiveEvent::description()const {
448 return data->event.description(); 458 return data->event.description();
449} 459}
450QString OEffectiveEvent::location()const { 460QString OEffectiveEvent::location()const {
451 return data->event.location(); 461 return data->event.location();
452} 462}
453QString OEffectiveEvent::note()const { 463QString OEffectiveEvent::note()const {
454 return data->event.note(); 464 return data->event.note();
455} 465}
456OEvent OEffectiveEvent::event()const { 466OEvent OEffectiveEvent::event()const {
457 return data->event; 467 return data->event;
458} 468}
459QTime OEffectiveEvent::startTime()const { 469QTime OEffectiveEvent::startTime()const {
460 return data->start; 470 return data->start;
461} 471}
462QTime OEffectiveEvent::endTime()const { 472QTime OEffectiveEvent::endTime()const {
463 return data->end; 473 return data->end;
464} 474}
465QDate OEffectiveEvent::date()const { 475QDate OEffectiveEvent::date()const {
466 return data->date; 476 return data->date;
467} 477}
468int OEffectiveEvent::length()const { 478int OEffectiveEvent::length()const {
469 return (data->end.hour() * 60 - data->start.hour() * 60) 479 return (data->end.hour() * 60 - data->start.hour() * 60)
470 + QABS(data->start.minute() - data->end.minute() ); 480 + QABS(data->start.minute() - data->end.minute() );
471} 481}
472int OEffectiveEvent::size()const { 482int OEffectiveEvent::size()const {
473 return ( data->end.hour() - data->start.hour() ) * 3600 483 return ( data->end.hour() - data->start.hour() ) * 3600
474 + (data->end.minute() - data->start.minute() * 60 484 + (data->end.minute() - data->start.minute() * 60
475 + data->end.second() - data->start.second() ); 485 + data->end.second() - data->start.second() );
476} 486}
477QDate OEffectiveEvent::startDate()const { 487QDate OEffectiveEvent::startDate()const {
478 if ( data->dates ) 488 if ( data->dates )
479 return data->startDate; 489 return data->startDate;
480 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 490 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index a29d88e..e087a00 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,370 +1,374 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h" 19#include "opimresolver.h"
20 20
21#include "otodo.h" 21#include "otodo.h"
22 22
23 23
24struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
25 OTodoData() : QShared() { 25 OTodoData() : QShared() {
26 recur = 0; 26 recur = 0;
27 state = 0; 27 state = 0;
28 maintainer = 0; 28 maintainer = 0;
29 notifiers = 0; 29 notifiers = 0;
30 }; 30 };
31 31
32 QDate date; 32 QDate date;
33 bool isCompleted:1; 33 bool isCompleted:1;
34 bool hasDate:1; 34 bool hasDate:1;
35 int priority; 35 int priority;
36 QString desc; 36 QString desc;
37 QString sum; 37 QString sum;
38 QMap<QString, QString> extra; 38 QMap<QString, QString> extra;
39 ushort prog; 39 ushort prog;
40 OPimState *state; 40 OPimState *state;
41 ORecur *recur; 41 ORecur *recur;
42 OPimMaintainer *maintainer; 42 OPimMaintainer *maintainer;
43 QDate start; 43 QDate start;
44 QDate completed; 44 QDate completed;
45 OPimNotifyManager *notifiers; 45 OPimNotifyManager *notifiers;
46}; 46};
47 47
48OTodo::OTodo(const OTodo &event ) 48OTodo::OTodo(const OTodo &event )
49 : OPimRecord( event ), data( event.data ) 49 : OPimRecord( event ), data( event.data )
50{ 50{
51 data->ref(); 51 data->ref();
52// qWarning("ref up"); 52// qWarning("ref up");
53} 53}
54OTodo::~OTodo() { 54OTodo::~OTodo() {
55 55
56// qWarning("~OTodo " ); 56// qWarning("~OTodo " );
57 if ( data->deref() ) { 57 if ( data->deref() ) {
58// qWarning("OTodo::dereffing"); 58// qWarning("OTodo::dereffing");
59 delete data; 59 delete data;
60 data = 0l; 60 data = 0l;
61 } 61 }
62} 62}
63OTodo::OTodo(bool completed, int priority, 63OTodo::OTodo(bool completed, int priority,
64 const QArray<int> &category, 64 const QArray<int> &category,
65 const QString& summary, 65 const QString& summary,
66 const QString &description, 66 const QString &description,
67 ushort progress, 67 ushort progress,
68 bool hasDate, QDate date, int uid ) 68 bool hasDate, QDate date, int uid )
69 : OPimRecord( uid ) 69 : OPimRecord( uid )
70{ 70{
71// qWarning("OTodoData " + summary); 71// qWarning("OTodoData " + summary);
72 setCategories( category ); 72 setCategories( category );
73 73
74 data = new OTodoData; 74 data = new OTodoData;
75 75
76 data->date = date; 76 data->date = date;
77 data->isCompleted = completed; 77 data->isCompleted = completed;
78 data->hasDate = hasDate; 78 data->hasDate = hasDate;
79 data->priority = priority; 79 data->priority = priority;
80 data->sum = summary; 80 data->sum = summary;
81 data->prog = progress; 81 data->prog = progress;
82 data->desc = Qtopia::simplifyMultiLineSpace(description ); 82 data->desc = Qtopia::simplifyMultiLineSpace(description );
83} 83}
84OTodo::OTodo(bool completed, int priority, 84OTodo::OTodo(bool completed, int priority,
85 const QStringList &category, 85 const QStringList &category,
86 const QString& summary, 86 const QString& summary,
87 const QString &description, 87 const QString &description,
88 ushort progress, 88 ushort progress,
89 bool hasDate, QDate date, int uid ) 89 bool hasDate, QDate date, int uid )
90 : OPimRecord( uid ) 90 : OPimRecord( uid )
91{ 91{
92// qWarning("OTodoData" + summary); 92// qWarning("OTodoData" + summary);
93 setCategories( idsFromString( category.join(";") ) ); 93 setCategories( idsFromString( category.join(";") ) );
94 94
95 data = new OTodoData; 95 data = new OTodoData;
96 96
97 data->date = date; 97 data->date = date;
98 data->isCompleted = completed; 98 data->isCompleted = completed;
99 data->hasDate = hasDate; 99 data->hasDate = hasDate;
100 data->priority = priority; 100 data->priority = priority;
101 data->sum = summary; 101 data->sum = summary;
102 data->prog = progress; 102 data->prog = progress;
103 data->desc = Qtopia::simplifyMultiLineSpace(description ); 103 data->desc = Qtopia::simplifyMultiLineSpace(description );
104} 104}
105bool OTodo::match( const QRegExp &regExp )const 105bool OTodo::match( const QRegExp &regExp )const
106{ 106{
107 if( QString::number( data->priority ).find( regExp ) != -1 ){ 107 if( QString::number( data->priority ).find( regExp ) != -1 ){
108 return true; 108 setLastHitField( Priority );
109 return true;
109 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 110 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
110 return true; 111 setLastHitField( HasDate );
112 return true;
111 }else if(data->desc.find( regExp ) != -1 ){ 113 }else if(data->desc.find( regExp ) != -1 ){
112 return true; 114 setLastHitField( Description );
115 return true;
113 }else if(data->sum.find( regExp ) != -1 ) { 116 }else if(data->sum.find( regExp ) != -1 ) {
114 return true; 117 setLastHitField( Summary );
118 return true;
115 } 119 }
116 return false; 120 return false;
117} 121}
118bool OTodo::isCompleted() const 122bool OTodo::isCompleted() const
119{ 123{
120 return data->isCompleted; 124 return data->isCompleted;
121} 125}
122bool OTodo::hasDueDate() const 126bool OTodo::hasDueDate() const
123{ 127{
124 return data->hasDate; 128 return data->hasDate;
125} 129}
126bool OTodo::hasStartDate()const { 130bool OTodo::hasStartDate()const {
127 return data->start.isValid(); 131 return data->start.isValid();
128} 132}
129bool OTodo::hasCompletedDate()const { 133bool OTodo::hasCompletedDate()const {
130 return data->completed.isValid(); 134 return data->completed.isValid();
131} 135}
132int OTodo::priority()const 136int OTodo::priority()const
133{ 137{
134 return data->priority; 138 return data->priority;
135} 139}
136QString OTodo::summary() const 140QString OTodo::summary() const
137{ 141{
138 return data->sum; 142 return data->sum;
139} 143}
140ushort OTodo::progress() const 144ushort OTodo::progress() const
141{ 145{
142 return data->prog; 146 return data->prog;
143} 147}
144QDate OTodo::dueDate()const 148QDate OTodo::dueDate()const
145{ 149{
146 return data->date; 150 return data->date;
147} 151}
148QDate OTodo::startDate()const { 152QDate OTodo::startDate()const {
149 return data->start; 153 return data->start;
150} 154}
151QDate OTodo::completedDate()const { 155QDate OTodo::completedDate()const {
152 return data->completed; 156 return data->completed;
153} 157}
154QString OTodo::description()const 158QString OTodo::description()const
155{ 159{
156 return data->desc; 160 return data->desc;
157} 161}
158bool OTodo::hasState() const{ 162bool OTodo::hasState() const{
159 if (!data->state ) return false; 163 if (!data->state ) return false;
160 return ( data->state->state() != OPimState::Undefined ); 164 return ( data->state->state() != OPimState::Undefined );
161} 165}
162OPimState OTodo::state()const { 166OPimState OTodo::state()const {
163 if (!data->state ) { 167 if (!data->state ) {
164 OPimState state; 168 OPimState state;
165 return state; 169 return state;
166 } 170 }
167 171
168 return (*data->state); 172 return (*data->state);
169} 173}
170bool OTodo::hasRecurrence()const { 174bool OTodo::hasRecurrence()const {
171 if (!data->recur) return false; 175 if (!data->recur) return false;
172 return data->recur->doesRecur(); 176 return data->recur->doesRecur();
173} 177}
174ORecur OTodo::recurrence()const { 178ORecur OTodo::recurrence()const {
175 if (!data->recur) return ORecur(); 179 if (!data->recur) return ORecur();
176 180
177 return (*data->recur); 181 return (*data->recur);
178} 182}
179bool OTodo::hasMaintainer()const { 183bool OTodo::hasMaintainer()const {
180 if (!data->maintainer) return false; 184 if (!data->maintainer) return false;
181 185
182 return (data->maintainer->mode() != OPimMaintainer::Undefined ); 186 return (data->maintainer->mode() != OPimMaintainer::Undefined );
183} 187}
184OPimMaintainer OTodo::maintainer()const { 188OPimMaintainer OTodo::maintainer()const {
185 if (!data->maintainer) return OPimMaintainer(); 189 if (!data->maintainer) return OPimMaintainer();
186 190
187 return (*data->maintainer); 191 return (*data->maintainer);
188} 192}
189void OTodo::setCompleted( bool completed ) 193void OTodo::setCompleted( bool completed )
190{ 194{
191 changeOrModify(); 195 changeOrModify();
192 data->isCompleted = completed; 196 data->isCompleted = completed;
193} 197}
194void OTodo::setHasDueDate( bool hasDate ) 198void OTodo::setHasDueDate( bool hasDate )
195{ 199{
196 changeOrModify(); 200 changeOrModify();
197 data->hasDate = hasDate; 201 data->hasDate = hasDate;
198} 202}
199void OTodo::setDescription(const QString &desc ) 203void OTodo::setDescription(const QString &desc )
200{ 204{
201// qWarning( "desc " + desc ); 205// qWarning( "desc " + desc );
202 changeOrModify(); 206 changeOrModify();
203 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 207 data->desc = Qtopia::simplifyMultiLineSpace(desc );
204} 208}
205void OTodo::setSummary( const QString& sum ) 209void OTodo::setSummary( const QString& sum )
206{ 210{
207 changeOrModify(); 211 changeOrModify();
208 data->sum = sum; 212 data->sum = sum;
209} 213}
210void OTodo::setPriority(int prio ) 214void OTodo::setPriority(int prio )
211{ 215{
212 changeOrModify(); 216 changeOrModify();
213 data->priority = prio; 217 data->priority = prio;
214} 218}
215void OTodo::setDueDate( const QDate& date ) 219void OTodo::setDueDate( const QDate& date )
216{ 220{
217 changeOrModify(); 221 changeOrModify();
218 data->date = date; 222 data->date = date;
219} 223}
220void OTodo::setStartDate( const QDate& date ) { 224void OTodo::setStartDate( const QDate& date ) {
221 changeOrModify(); 225 changeOrModify();
222 data->start = date; 226 data->start = date;
223} 227}
224void OTodo::setCompletedDate( const QDate& date ) { 228void OTodo::setCompletedDate( const QDate& date ) {
225 changeOrModify(); 229 changeOrModify();
226 data->completed = date; 230 data->completed = date;
227} 231}
228void OTodo::setState( const OPimState& state ) { 232void OTodo::setState( const OPimState& state ) {
229 changeOrModify(); 233 changeOrModify();
230 if (data->state ) 234 if (data->state )
231 (*data->state) = state; 235 (*data->state) = state;
232 else 236 else
233 data->state = new OPimState( state ); 237 data->state = new OPimState( state );
234} 238}
235void OTodo::setRecurrence( const ORecur& rec) { 239void OTodo::setRecurrence( const ORecur& rec) {
236 changeOrModify(); 240 changeOrModify();
237 if (data->recur ) 241 if (data->recur )
238 (*data->recur) = rec; 242 (*data->recur) = rec;
239 else 243 else
240 data->recur = new ORecur( rec ); 244 data->recur = new ORecur( rec );
241} 245}
242void OTodo::setMaintainer( const OPimMaintainer& pim ) { 246void OTodo::setMaintainer( const OPimMaintainer& pim ) {
243 changeOrModify(); 247 changeOrModify();
244 248
245 if (data->maintainer ) 249 if (data->maintainer )
246 (*data->maintainer) = pim; 250 (*data->maintainer) = pim;
247 else 251 else
248 data->maintainer = new OPimMaintainer( pim ); 252 data->maintainer = new OPimMaintainer( pim );
249} 253}
250bool OTodo::isOverdue( ) 254bool OTodo::isOverdue( )
251{ 255{
252 if( data->hasDate && !data->isCompleted) 256 if( data->hasDate && !data->isCompleted)
253 return QDate::currentDate() > data->date; 257 return QDate::currentDate() > data->date;
254 return false; 258 return false;
255} 259}
256void OTodo::setProgress(ushort progress ) 260void OTodo::setProgress(ushort progress )
257{ 261{
258 changeOrModify(); 262 changeOrModify();
259 data->prog = progress; 263 data->prog = progress;
260} 264}
261QString OTodo::toShortText() const { 265QString OTodo::toShortText() const {
262 return summary(); 266 return summary();
263} 267}
264/*! 268/*!
265 Returns a richt text string 269 Returns a richt text string
266*/ 270*/
267QString OTodo::toRichText() const 271QString OTodo::toRichText() const
268{ 272{
269 QString text; 273 QString text;
270 QStringList catlist; 274 QStringList catlist;
271 275
272 // Description of the todo 276 // Description of the todo
273 if ( !summary().isEmpty() ) { 277 if ( !summary().isEmpty() ) {
274 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 278 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
275 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
276 } 280 }
277 if( !description().isEmpty() ){ 281 if( !description().isEmpty() ){
278 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 282 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
279 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 283 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
280 } 284 }
281 text += "<br><br><br>"; 285 text += "<br><br><br>";
282 286
283 text += "<b>" + QObject::tr( "Priority:") +" </b>" 287 text += "<b>" + QObject::tr( "Priority:") +" </b>"
284 + QString::number( priority() ) + " <br>"; 288 + QString::number( priority() ) + " <br>";
285 text += "<b>" + QObject::tr( "Progress:") + " </b>" 289 text += "<b>" + QObject::tr( "Progress:") + " </b>"
286 + QString::number( progress() ) + " %<br>"; 290 + QString::number( progress() ) + " %<br>";
287 if (hasDueDate() ){ 291 if (hasDueDate() ){
288 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 292 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
289 text += dueDate().toString(); 293 text += dueDate().toString();
290 text += "<br>"; 294 text += "<br>";
291 } 295 }
292 296
293 text += "<b>" + QObject::tr( "Category:") + "</b> "; 297 text += "<b>" + QObject::tr( "Category:") + "</b> ";
294 text += categoryNames( "Todo List" ).join(", "); 298 text += categoryNames( "Todo List" ).join(", ");
295 text += "<br>"; 299 text += "<br>";
296 300
297 return text; 301 return text;
298} 302}
299bool OTodo::hasNotifiers()const { 303bool OTodo::hasNotifiers()const {
300 if (!data->notifiers) return false; 304 if (!data->notifiers) return false;
301 return !data->notifiers->isEmpty(); 305 return !data->notifiers->isEmpty();
302} 306}
303OPimNotifyManager& OTodo::notifiers() { 307OPimNotifyManager& OTodo::notifiers() {
304 if (!data->notifiers ) 308 if (!data->notifiers )
305 data->notifiers = new OPimNotifyManager; 309 data->notifiers = new OPimNotifyManager;
306 return (*data->notifiers); 310 return (*data->notifiers);
307} 311}
308const OPimNotifyManager& OTodo::notifiers()const{ 312const OPimNotifyManager& OTodo::notifiers()const{
309 if (!data->notifiers ) 313 if (!data->notifiers )
310 data->notifiers = new OPimNotifyManager; 314 data->notifiers = new OPimNotifyManager;
311 315
312 return (*data->notifiers); 316 return (*data->notifiers);
313} 317}
314 318
315bool OTodo::operator<( const OTodo &toDoEvent )const{ 319bool OTodo::operator<( const OTodo &toDoEvent )const{
316 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 320 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
317 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 321 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
318 if( hasDueDate() && toDoEvent.hasDueDate() ){ 322 if( hasDueDate() && toDoEvent.hasDueDate() ){
319 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 323 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
320 return priority() < toDoEvent.priority(); 324 return priority() < toDoEvent.priority();
321 }else{ 325 }else{
322 return dueDate() < toDoEvent.dueDate(); 326 return dueDate() < toDoEvent.dueDate();
323 } 327 }
324 } 328 }
325 return false; 329 return false;
326} 330}
327bool OTodo::operator<=(const OTodo &toDoEvent )const 331bool OTodo::operator<=(const OTodo &toDoEvent )const
328{ 332{
329 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 333 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
330 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 334 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
331 if( hasDueDate() && toDoEvent.hasDueDate() ){ 335 if( hasDueDate() && toDoEvent.hasDueDate() ){
332 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 336 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
333 return priority() <= toDoEvent.priority(); 337 return priority() <= toDoEvent.priority();
334 }else{ 338 }else{
335 return dueDate() <= toDoEvent.dueDate(); 339 return dueDate() <= toDoEvent.dueDate();
336 } 340 }
337 } 341 }
338 return true; 342 return true;
339} 343}
340bool OTodo::operator>(const OTodo &toDoEvent )const 344bool OTodo::operator>(const OTodo &toDoEvent )const
341{ 345{
342 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 346 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
343 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 347 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
344 if( hasDueDate() && toDoEvent.hasDueDate() ){ 348 if( hasDueDate() && toDoEvent.hasDueDate() ){
345 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 349 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
346 return priority() > toDoEvent.priority(); 350 return priority() > toDoEvent.priority();
347 }else{ 351 }else{
348 return dueDate() > toDoEvent.dueDate(); 352 return dueDate() > toDoEvent.dueDate();
349 } 353 }
350 } 354 }
351 return false; 355 return false;
352} 356}
353bool OTodo::operator>=(const OTodo &toDoEvent )const 357bool OTodo::operator>=(const OTodo &toDoEvent )const
354{ 358{
355 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 359 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
356 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 360 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
357 if( hasDueDate() && toDoEvent.hasDueDate() ){ 361 if( hasDueDate() && toDoEvent.hasDueDate() ){
358 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 362 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
359 return priority() > toDoEvent.priority(); 363 return priority() > toDoEvent.priority();
360 }else{ 364 }else{
361 return dueDate() > toDoEvent.dueDate(); 365 return dueDate() > toDoEvent.dueDate();
362 } 366 }
363 } 367 }
364 return true; 368 return true;
365} 369}
366bool OTodo::operator==(const OTodo &toDoEvent )const 370bool OTodo::operator==(const OTodo &toDoEvent )const
367{ 371{
368 if ( data->priority != toDoEvent.data->priority ) return false; 372 if ( data->priority != toDoEvent.data->priority ) return false;
369 if ( data->priority != toDoEvent.data->prog ) return false; 373 if ( data->priority != toDoEvent.data->prog ) return false;
370 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 374 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index cda12f9..2b138c0 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -1,480 +1,490 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qpe/palmtopuidgen.h> 3#include <qpe/palmtopuidgen.h>
4#include <qpe/categories.h> 4#include <qpe/categories.h>
5#include <qpe/stringutil.h> 5#include <qpe/stringutil.h>
6 6
7#include "orecur.h" 7#include "orecur.h"
8#include "opimresolver.h" 8#include "opimresolver.h"
9#include "opimnotifymanager.h" 9#include "opimnotifymanager.h"
10 10
11#include "oevent.h" 11#include "oevent.h"
12 12
13int OCalendarHelper::week( const QDate& date) { 13int OCalendarHelper::week( const QDate& date) {
14 // Calculates the week this date is in within that 14 // Calculates the week this date is in within that
15 // month. Equals the "row" is is in in the month view 15 // month. Equals the "row" is is in in the month view
16 int week = 1; 16 int week = 1;
17 QDate tmp( date.year(), date.month(), 1 ); 17 QDate tmp( date.year(), date.month(), 1 );
18 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 18 if ( date.dayOfWeek() < tmp.dayOfWeek() )
19 ++week; 19 ++week;
20 20
21 week += ( date.day() - 1 ) / 7; 21 week += ( date.day() - 1 ) / 7;
22 22
23 return week; 23 return week;
24} 24}
25int OCalendarHelper::ocurrence( const QDate& date) { 25int OCalendarHelper::ocurrence( const QDate& date) {
26 // calculates the number of occurrances of this day of the 26 // calculates the number of occurrances of this day of the
27 // week till the given date (e.g 3rd Wednesday of the month) 27 // week till the given date (e.g 3rd Wednesday of the month)
28 return ( date.day() - 1 ) / 7 + 1; 28 return ( date.day() - 1 ) / 7 + 1;
29} 29}
30int OCalendarHelper::dayOfWeek( char day ) { 30int OCalendarHelper::dayOfWeek( char day ) {
31 int dayOfWeek = 1; 31 int dayOfWeek = 1;
32 char i = ORecur::MON; 32 char i = ORecur::MON;
33 while ( !( i & day ) && i <= ORecur::SUN ) { 33 while ( !( i & day ) && i <= ORecur::SUN ) {
34 i <<= 1; 34 i <<= 1;
35 ++dayOfWeek; 35 ++dayOfWeek;
36 } 36 }
37 return dayOfWeek; 37 return dayOfWeek;
38} 38}
39int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 39int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
40 return ( second.year() - first.year() ) * 12 + 40 return ( second.year() - first.year() ) * 12 +
41 second.month() - first.month(); 41 second.month() - first.month();
42} 42}
43 43
44struct OEvent::Data : public QShared { 44struct OEvent::Data : public QShared {
45 Data() : QShared() { 45 Data() : QShared() {
46 child = 0; 46 child = 0;
47 recur = 0; 47 recur = 0;
48 manager = 0; 48 manager = 0;
49 isAllDay = false; 49 isAllDay = false;
50 parent = 0; 50 parent = 0;
51 } 51 }
52 ~Data() { 52 ~Data() {
53 delete manager; 53 delete manager;
54 delete recur; 54 delete recur;
55 } 55 }
56 QString description; 56 QString description;
57 QString location; 57 QString location;
58 OPimNotifyManager* manager; 58 OPimNotifyManager* manager;
59 ORecur* recur; 59 ORecur* recur;
60 QString note; 60 QString note;
61 QDateTime created; 61 QDateTime created;
62 QDateTime start; 62 QDateTime start;
63 QDateTime end; 63 QDateTime end;
64 bool isAllDay : 1; 64 bool isAllDay : 1;
65 QString timezone; 65 QString timezone;
66 QArray<int>* child; 66 QArray<int>* child;
67 int parent; 67 int parent;
68}; 68};
69 69
70OEvent::OEvent( int uid ) 70OEvent::OEvent( int uid )
71 : OPimRecord( uid ) { 71 : OPimRecord( uid ) {
72 data = new Data; 72 data = new Data;
73} 73}
74OEvent::OEvent( const OEvent& ev) 74OEvent::OEvent( const OEvent& ev)
75 : OPimRecord( ev ), data( ev.data ) 75 : OPimRecord( ev ), data( ev.data )
76{ 76{
77 data->ref(); 77 data->ref();
78} 78}
79OEvent::~OEvent() { 79OEvent::~OEvent() {
80 if ( data->deref() ) { 80 if ( data->deref() ) {
81 delete data; 81 delete data;
82 data = 0; 82 data = 0;
83 } 83 }
84} 84}
85OEvent& OEvent::operator=( const OEvent& ev) { 85OEvent& OEvent::operator=( const OEvent& ev) {
86 if ( this == &ev ) return *this; 86 if ( this == &ev ) return *this;
87 87
88 OPimRecord::operator=( ev ); 88 OPimRecord::operator=( ev );
89 ev.data->ref(); 89 ev.data->ref();
90 deref(); 90 deref();
91 data = ev.data; 91 data = ev.data;
92 92
93 93
94 return *this; 94 return *this;
95} 95}
96QString OEvent::description()const { 96QString OEvent::description()const {
97 return data->description; 97 return data->description;
98} 98}
99void OEvent::setDescription( const QString& description ) { 99void OEvent::setDescription( const QString& description ) {
100 changeOrModify(); 100 changeOrModify();
101 data->description = description; 101 data->description = description;
102} 102}
103void OEvent::setLocation( const QString& loc ) { 103void OEvent::setLocation( const QString& loc ) {
104 changeOrModify(); 104 changeOrModify();
105 data->location = loc; 105 data->location = loc;
106} 106}
107QString OEvent::location()const { 107QString OEvent::location()const {
108 return data->location; 108 return data->location;
109} 109}
110OPimNotifyManager &OEvent::notifiers()const { 110OPimNotifyManager &OEvent::notifiers()const {
111 // I hope we can skip the changeOrModify here 111 // I hope we can skip the changeOrModify here
112 // the notifier should take care of it 112 // the notifier should take care of it
113 // and OPimNotify is shared too 113 // and OPimNotify is shared too
114 if (!data->manager ) 114 if (!data->manager )
115 data->manager = new OPimNotifyManager; 115 data->manager = new OPimNotifyManager;
116 116
117 return *data->manager; 117 return *data->manager;
118} 118}
119bool OEvent::hasNotifiers()const { 119bool OEvent::hasNotifiers()const {
120 if (!data->manager ) 120 if (!data->manager )
121 return false; 121 return false;
122 if (data->manager->reminders().isEmpty() && 122 if (data->manager->reminders().isEmpty() &&
123 data->manager->alarms().isEmpty() ) 123 data->manager->alarms().isEmpty() )
124 return false; 124 return false;
125 125
126 return true; 126 return true;
127} 127}
128ORecur OEvent::recurrence()const { 128ORecur OEvent::recurrence()const {
129 if (!data->recur) 129 if (!data->recur)
130 data->recur = new ORecur; 130 data->recur = new ORecur;
131 131
132 return *data->recur; 132 return *data->recur;
133} 133}
134void OEvent::setRecurrence( const ORecur& rec) { 134void OEvent::setRecurrence( const ORecur& rec) {
135 changeOrModify(); 135 changeOrModify();
136 if (data->recur ) 136 if (data->recur )
137 (*data->recur) = rec; 137 (*data->recur) = rec;
138 else 138 else
139 data->recur = new ORecur( rec ); 139 data->recur = new ORecur( rec );
140} 140}
141bool OEvent::hasRecurrence()const { 141bool OEvent::hasRecurrence()const {
142 if (!data->recur ) return false; 142 if (!data->recur ) return false;
143 return data->recur->doesRecur(); 143 return data->recur->doesRecur();
144} 144}
145QString OEvent::note()const { 145QString OEvent::note()const {
146 return data->note; 146 return data->note;
147} 147}
148void OEvent::setNote( const QString& note ) { 148void OEvent::setNote( const QString& note ) {
149 changeOrModify(); 149 changeOrModify();
150 data->note = note; 150 data->note = note;
151} 151}
152QDateTime OEvent::createdDateTime()const { 152QDateTime OEvent::createdDateTime()const {
153 return data->created; 153 return data->created;
154} 154}
155void OEvent::setCreatedDateTime( const QDateTime& time ) { 155void OEvent::setCreatedDateTime( const QDateTime& time ) {
156 changeOrModify(); 156 changeOrModify();
157 data->created = time; 157 data->created = time;
158} 158}
159QDateTime OEvent::startDateTime()const { 159QDateTime OEvent::startDateTime()const {
160 if ( data->isAllDay ) 160 if ( data->isAllDay )
161 return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); 161 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
162 return data->start; 162 return data->start;
163} 163}
164QDateTime OEvent::startDateTimeInZone()const { 164QDateTime OEvent::startDateTimeInZone()const {
165 /* if no timezone, or all day event or if the current and this timeZone match... */ 165 /* if no timezone, or all day event or if the current and this timeZone match... */
166 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); 166 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
167 167
168 OTimeZone zone(data->timezone ); 168 OTimeZone zone(data->timezone );
169 return zone.toDateTime( data->start, OTimeZone::current() ); 169 return zone.toDateTime( data->start, OTimeZone::current() );
170} 170}
171void OEvent::setStartDateTime( const QDateTime& dt ) { 171void OEvent::setStartDateTime( const QDateTime& dt ) {
172 changeOrModify(); 172 changeOrModify();
173 data->start = dt; 173 data->start = dt;
174} 174}
175QDateTime OEvent::endDateTime()const { 175QDateTime OEvent::endDateTime()const {
176 /* 176 /*
177 * if all Day event the end time needs 177 * if all Day event the end time needs
178 * to be on the same day as the start 178 * to be on the same day as the start
179 */ 179 */
180 if ( data->isAllDay ) 180 if ( data->isAllDay )
181 return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); 181 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
182 return data->end; 182 return data->end;
183} 183}
184QDateTime OEvent::endDateTimeInZone()const { 184QDateTime OEvent::endDateTimeInZone()const {
185 /* if no timezone, or all day event or if the current and this timeZone match... */ 185 /* if no timezone, or all day event or if the current and this timeZone match... */
186 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); 186 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
187 187
188 OTimeZone zone(data->timezone ); 188 OTimeZone zone(data->timezone );
189 return zone.toDateTime( data->end, OTimeZone::current() ); 189 return zone.toDateTime( data->end, OTimeZone::current() );
190} 190}
191void OEvent::setEndDateTime( const QDateTime& dt ) { 191void OEvent::setEndDateTime( const QDateTime& dt ) {
192 changeOrModify(); 192 changeOrModify();
193 data->end = dt; 193 data->end = dt;
194} 194}
195bool OEvent::isMultipleDay()const { 195bool OEvent::isMultipleDay()const {
196 return data->end.date().day() - data->start.date().day(); 196 return data->end.date().day() - data->start.date().day();
197} 197}
198bool OEvent::isAllDay()const { 198bool OEvent::isAllDay()const {
199 return data->isAllDay; 199 return data->isAllDay;
200} 200}
201void OEvent::setAllDay( bool allDay ) { 201void OEvent::setAllDay( bool allDay ) {
202 changeOrModify(); 202 changeOrModify();
203 data->isAllDay = allDay; 203 data->isAllDay = allDay;
204 if (allDay ) data->timezone = "UTC"; 204 if (allDay ) data->timezone = "UTC";
205} 205}
206void OEvent::setTimeZone( const QString& tz ) { 206void OEvent::setTimeZone( const QString& tz ) {
207 changeOrModify(); 207 changeOrModify();
208 data->timezone = tz; 208 data->timezone = tz;
209} 209}
210QString OEvent::timeZone()const { 210QString OEvent::timeZone()const {
211 if (data->isAllDay ) return QString::fromLatin1("UTC"); 211 if (data->isAllDay ) return QString::fromLatin1("UTC");
212 return data->timezone; 212 return data->timezone;
213} 213}
214bool OEvent::match( const QRegExp& re )const { 214bool OEvent::match( const QRegExp& re )const {
215 if ( re.match( data->description ) != -1 ) 215 if ( re.match( data->description ) != -1 ){
216 setLastHitField( DatebookDescription );
216 return true; 217 return true;
217 if ( re.match( data->note ) != -1 ) 218 }
219 if ( re.match( data->note ) != -1 ){
220 setLastHitField( Note );
218 return true; 221 return true;
219 if ( re.match( data->location ) != -1 ) 222 }
223 if ( re.match( data->location ) != -1 ){
224 setLastHitField( Location );
220 return true; 225 return true;
221 if ( re.match( data->start.toString() ) != -1 ) 226 }
227 if ( re.match( data->start.toString() ) != -1 ){
228 setLastHitField( StartDateTime );
222 return true; 229 return true;
223 if ( re.match( data->end.toString() ) != -1 ) 230 }
231 if ( re.match( data->end.toString() ) != -1 ){
232 setLastHitField( EndDateTime );
224 return true; 233 return true;
234 }
225 return false; 235 return false;
226} 236}
227QString OEvent::toRichText()const { 237QString OEvent::toRichText()const {
228 QString text; 238 QString text;
229 if ( !description().isEmpty() ) { 239 if ( !description().isEmpty() ) {
230 text += "<b>" + QObject::tr( "Description:") + "</b><br>"; 240 text += "<b>" + QObject::tr( "Description:") + "</b><br>";
231 text += Qtopia::escapeString(description() ). 241 text += Qtopia::escapeString(description() ).
232 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 242 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
233 } 243 }
234 if ( startDateTime().isValid() ) { 244 if ( startDateTime().isValid() ) {
235 text += "<b>" + QObject::tr( "Start:") + "</b> "; 245 text += "<b>" + QObject::tr( "Start:") + "</b> ";
236 text += Qtopia::escapeString(startDateTime().toString() ). 246 text += Qtopia::escapeString(startDateTime().toString() ).
237 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 247 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
238 } 248 }
239 if ( endDateTime().isValid() ) { 249 if ( endDateTime().isValid() ) {
240 text += "<b>" + QObject::tr( "End:") + "</b> "; 250 text += "<b>" + QObject::tr( "End:") + "</b> ";
241 text += Qtopia::escapeString(endDateTime().toString() ). 251 text += Qtopia::escapeString(endDateTime().toString() ).
242 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 252 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
243 } 253 }
244 if ( !note().isEmpty() ) { 254 if ( !note().isEmpty() ) {
245 text += "<b>" + QObject::tr( "Note:") + "</b><br>"; 255 text += "<b>" + QObject::tr( "Note:") + "</b><br>";
246 text += note(); 256 text += note();
247// text += Qtopia::escapeString(note() ). 257// text += Qtopia::escapeString(note() ).
248// replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 258// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
249 } 259 }
250 return text; 260 return text;
251} 261}
252QString OEvent::toShortText()const { 262QString OEvent::toShortText()const {
253 QString text; 263 QString text;
254 text += QString::number( startDateTime().date().day() ); 264 text += QString::number( startDateTime().date().day() );
255 text += "."; 265 text += ".";
256 text += QString::number( startDateTime().date().month() ); 266 text += QString::number( startDateTime().date().month() );
257 text += "."; 267 text += ".";
258 text += QString::number( startDateTime().date().year() ); 268 text += QString::number( startDateTime().date().year() );
259 text += " "; 269 text += " ";
260 text += QString::number( startDateTime().time().hour() ); 270 text += QString::number( startDateTime().time().hour() );
261 text += ":"; 271 text += ":";
262 text += QString::number( startDateTime().time().minute() ); 272 text += QString::number( startDateTime().time().minute() );
263 text += " - "; 273 text += " - ";
264 text += description(); 274 text += description();
265 return text; 275 return text;
266} 276}
267QString OEvent::type()const { 277QString OEvent::type()const {
268 return QString::fromLatin1("OEvent"); 278 return QString::fromLatin1("OEvent");
269} 279}
270QString OEvent::recordField( int /*id */ )const { 280QString OEvent::recordField( int /*id */ )const {
271 return QString::null; 281 return QString::null;
272} 282}
273int OEvent::rtti() { 283int OEvent::rtti() {
274 return OPimResolver::DateBook; 284 return OPimResolver::DateBook;
275} 285}
276bool OEvent::loadFromStream( QDataStream& ) { 286bool OEvent::loadFromStream( QDataStream& ) {
277 return true; 287 return true;
278} 288}
279bool OEvent::saveToStream( QDataStream& )const { 289bool OEvent::saveToStream( QDataStream& )const {
280 return true; 290 return true;
281} 291}
282void OEvent::changeOrModify() { 292void OEvent::changeOrModify() {
283 if ( data->count != 1 ) { 293 if ( data->count != 1 ) {
284 data->deref(); 294 data->deref();
285 Data* d2 = new Data; 295 Data* d2 = new Data;
286 d2->description = data->description; 296 d2->description = data->description;
287 d2->location = data->location; 297 d2->location = data->location;
288 298
289 if (data->manager ) 299 if (data->manager )
290 d2->manager = new OPimNotifyManager( *data->manager ); 300 d2->manager = new OPimNotifyManager( *data->manager );
291 301
292 if ( data->recur ) 302 if ( data->recur )
293 d2->recur = new ORecur( *data->recur ); 303 d2->recur = new ORecur( *data->recur );
294 304
295 d2->note = data->note; 305 d2->note = data->note;
296 d2->created = data->created; 306 d2->created = data->created;
297 d2->start = data->start; 307 d2->start = data->start;
298 d2->end = data->end; 308 d2->end = data->end;
299 d2->isAllDay = data->isAllDay; 309 d2->isAllDay = data->isAllDay;
300 d2->timezone = data->timezone; 310 d2->timezone = data->timezone;
301 d2->parent = data->parent; 311 d2->parent = data->parent;
302 312
303 if ( data->child ) { 313 if ( data->child ) {
304 d2->child = new QArray<int>( *data->child ); 314 d2->child = new QArray<int>( *data->child );
305 d2->child->detach(); 315 d2->child->detach();
306 } 316 }
307 317
308 data = d2; 318 data = d2;
309 } 319 }
310} 320}
311void OEvent::deref() { 321void OEvent::deref() {
312 if ( data->deref() ) { 322 if ( data->deref() ) {
313 delete data; 323 delete data;
314 data = 0; 324 data = 0;
315 } 325 }
316} 326}
317// FIXME 327// FIXME
318QMap<int, QString> OEvent::toMap()const { 328QMap<int, QString> OEvent::toMap()const {
319 return QMap<int, QString>(); 329 return QMap<int, QString>();
320} 330}
321QMap<QString, QString> OEvent::toExtraMap()const { 331QMap<QString, QString> OEvent::toExtraMap()const {
322 return QMap<QString, QString>(); 332 return QMap<QString, QString>();
323} 333}
324int OEvent::parent()const { 334int OEvent::parent()const {
325 return data->parent; 335 return data->parent;
326} 336}
327void OEvent::setParent( int uid ) { 337void OEvent::setParent( int uid ) {
328 changeOrModify(); 338 changeOrModify();
329 data->parent = uid; 339 data->parent = uid;
330} 340}
331QArray<int> OEvent::children() const{ 341QArray<int> OEvent::children() const{
332 if (!data->child) return QArray<int>(); 342 if (!data->child) return QArray<int>();
333 else 343 else
334 return data->child->copy(); 344 return data->child->copy();
335} 345}
336void OEvent::setChildren( const QArray<int>& arr ) { 346void OEvent::setChildren( const QArray<int>& arr ) {
337 changeOrModify(); 347 changeOrModify();
338 if (data->child) delete data->child; 348 if (data->child) delete data->child;
339 349
340 data->child = new QArray<int>( arr ); 350 data->child = new QArray<int>( arr );
341 data->child->detach(); 351 data->child->detach();
342} 352}
343void OEvent::addChild( int uid ) { 353void OEvent::addChild( int uid ) {
344 changeOrModify(); 354 changeOrModify();
345 if (!data->child ) { 355 if (!data->child ) {
346 data->child = new QArray<int>(1); 356 data->child = new QArray<int>(1);
347 (*data->child)[0] = uid; 357 (*data->child)[0] = uid;
348 }else{ 358 }else{
349 int count = data->child->count(); 359 int count = data->child->count();
350 data->child->resize( count + 1 ); 360 data->child->resize( count + 1 );
351 (*data->child)[count] = uid; 361 (*data->child)[count] = uid;
352 } 362 }
353} 363}
354void OEvent::removeChild( int uid ) { 364void OEvent::removeChild( int uid ) {
355 if (!data->child || !data->child->contains( uid ) ) return; 365 if (!data->child || !data->child->contains( uid ) ) return;
356 changeOrModify(); 366 changeOrModify();
357 QArray<int> newAr( data->child->count() - 1 ); 367 QArray<int> newAr( data->child->count() - 1 );
358 int j = 0; 368 int j = 0;
359 uint count = data->child->count(); 369 uint count = data->child->count();
360 for ( uint i = 0; i < count; i++ ) { 370 for ( uint i = 0; i < count; i++ ) {
361 if ( (*data->child)[i] != uid ) { 371 if ( (*data->child)[i] != uid ) {
362 newAr[j] = (*data->child)[i]; 372 newAr[j] = (*data->child)[i];
363 j++; 373 j++;
364 } 374 }
365 } 375 }
366 (*data->child) = newAr; 376 (*data->child) = newAr;
367} 377}
368struct OEffectiveEvent::Data : public QShared { 378struct OEffectiveEvent::Data : public QShared {
369 Data() : QShared() { 379 Data() : QShared() {
370 } 380 }
371 OEvent event; 381 OEvent event;
372 QDate date; 382 QDate date;
373 QTime start, end; 383 QTime start, end;
374 QDate startDate, endDate; 384 QDate startDate, endDate;
375 bool dates : 1; 385 bool dates : 1;
376}; 386};
377 387
378OEffectiveEvent::OEffectiveEvent() { 388OEffectiveEvent::OEffectiveEvent() {
379 data = new Data; 389 data = new Data;
380 data->date = QDate::currentDate(); 390 data->date = QDate::currentDate();
381 data->start = data->end = QTime::currentTime(); 391 data->start = data->end = QTime::currentTime();
382 data->dates = false; 392 data->dates = false;
383} 393}
384OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 394OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
385 Position pos ) { 395 Position pos ) {
386 data = new Data; 396 data = new Data;
387 data->event = ev; 397 data->event = ev;
388 data->date = startDate; 398 data->date = startDate;
389 if ( pos & Start ) 399 if ( pos & Start )
390 data->start = ev.startDateTime().time(); 400 data->start = ev.startDateTime().time();
391 else 401 else
392 data->start = QTime( 0, 0, 0 ); 402 data->start = QTime( 0, 0, 0 );
393 403
394 if ( pos & End ) 404 if ( pos & End )
395 data->end = ev.endDateTime().time(); 405 data->end = ev.endDateTime().time();
396 else 406 else
397 data->end = QTime( 23, 59, 59 ); 407 data->end = QTime( 23, 59, 59 );
398 408
399 data->dates = false; 409 data->dates = false;
400} 410}
401OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 411OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
402 data = ev.data; 412 data = ev.data;
403 data->ref(); 413 data->ref();
404} 414}
405OEffectiveEvent::~OEffectiveEvent() { 415OEffectiveEvent::~OEffectiveEvent() {
406 if ( data->deref() ) { 416 if ( data->deref() ) {
407 delete data; 417 delete data;
408 data = 0; 418 data = 0;
409 } 419 }
410} 420}
411OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 421OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
412 if ( *this == ev ) return *this; 422 if ( *this == ev ) return *this;
413 423
414 ev.data->ref(); 424 ev.data->ref();
415 deref(); 425 deref();
416 data = ev.data; 426 data = ev.data;
417 427
418 return *this; 428 return *this;
419} 429}
420 430
421void OEffectiveEvent::setStartTime( const QTime& ti) { 431void OEffectiveEvent::setStartTime( const QTime& ti) {
422 changeOrModify(); 432 changeOrModify();
423 data->start = ti; 433 data->start = ti;
424} 434}
425void OEffectiveEvent::setEndTime( const QTime& en) { 435void OEffectiveEvent::setEndTime( const QTime& en) {
426 changeOrModify(); 436 changeOrModify();
427 data->end = en; 437 data->end = en;
428} 438}
429void OEffectiveEvent::setEvent( const OEvent& ev) { 439void OEffectiveEvent::setEvent( const OEvent& ev) {
430 changeOrModify(); 440 changeOrModify();
431 data->event = ev; 441 data->event = ev;
432} 442}
433void OEffectiveEvent::setDate( const QDate& da) { 443void OEffectiveEvent::setDate( const QDate& da) {
434 changeOrModify(); 444 changeOrModify();
435 data->date = da; 445 data->date = da;
436} 446}
437void OEffectiveEvent::setEffectiveDates( const QDate& from, 447void OEffectiveEvent::setEffectiveDates( const QDate& from,
438 const QDate& to ) { 448 const QDate& to ) {
439 if (!from.isValid() ) { 449 if (!from.isValid() ) {
440 data->dates = false; 450 data->dates = false;
441 return; 451 return;
442 } 452 }
443 453
444 data->startDate = from; 454 data->startDate = from;
445 data->endDate = to; 455 data->endDate = to;
446} 456}
447QString OEffectiveEvent::description()const { 457QString OEffectiveEvent::description()const {
448 return data->event.description(); 458 return data->event.description();
449} 459}
450QString OEffectiveEvent::location()const { 460QString OEffectiveEvent::location()const {
451 return data->event.location(); 461 return data->event.location();
452} 462}
453QString OEffectiveEvent::note()const { 463QString OEffectiveEvent::note()const {
454 return data->event.note(); 464 return data->event.note();
455} 465}
456OEvent OEffectiveEvent::event()const { 466OEvent OEffectiveEvent::event()const {
457 return data->event; 467 return data->event;
458} 468}
459QTime OEffectiveEvent::startTime()const { 469QTime OEffectiveEvent::startTime()const {
460 return data->start; 470 return data->start;
461} 471}
462QTime OEffectiveEvent::endTime()const { 472QTime OEffectiveEvent::endTime()const {
463 return data->end; 473 return data->end;
464} 474}
465QDate OEffectiveEvent::date()const { 475QDate OEffectiveEvent::date()const {
466 return data->date; 476 return data->date;
467} 477}
468int OEffectiveEvent::length()const { 478int OEffectiveEvent::length()const {
469 return (data->end.hour() * 60 - data->start.hour() * 60) 479 return (data->end.hour() * 60 - data->start.hour() * 60)
470 + QABS(data->start.minute() - data->end.minute() ); 480 + QABS(data->start.minute() - data->end.minute() );
471} 481}
472int OEffectiveEvent::size()const { 482int OEffectiveEvent::size()const {
473 return ( data->end.hour() - data->start.hour() ) * 3600 483 return ( data->end.hour() - data->start.hour() ) * 3600
474 + (data->end.minute() - data->start.minute() * 60 484 + (data->end.minute() - data->start.minute() * 60
475 + data->end.second() - data->start.second() ); 485 + data->end.second() - data->start.second() );
476} 486}
477QDate OEffectiveEvent::startDate()const { 487QDate OEffectiveEvent::startDate()const {
478 if ( data->dates ) 488 if ( data->dates )
479 return data->startDate; 489 return data->startDate;
480 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 490 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp
index a29d88e..e087a00 100644
--- a/libopie2/opiepim/otodo.cpp
+++ b/libopie2/opiepim/otodo.cpp
@@ -1,370 +1,374 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h" 19#include "opimresolver.h"
20 20
21#include "otodo.h" 21#include "otodo.h"
22 22
23 23
24struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
25 OTodoData() : QShared() { 25 OTodoData() : QShared() {
26 recur = 0; 26 recur = 0;
27 state = 0; 27 state = 0;
28 maintainer = 0; 28 maintainer = 0;
29 notifiers = 0; 29 notifiers = 0;
30 }; 30 };
31 31
32 QDate date; 32 QDate date;
33 bool isCompleted:1; 33 bool isCompleted:1;
34 bool hasDate:1; 34 bool hasDate:1;
35 int priority; 35 int priority;
36 QString desc; 36 QString desc;
37 QString sum; 37 QString sum;
38 QMap<QString, QString> extra; 38 QMap<QString, QString> extra;
39 ushort prog; 39 ushort prog;
40 OPimState *state; 40 OPimState *state;
41 ORecur *recur; 41 ORecur *recur;
42 OPimMaintainer *maintainer; 42 OPimMaintainer *maintainer;
43 QDate start; 43 QDate start;
44 QDate completed; 44 QDate completed;
45 OPimNotifyManager *notifiers; 45 OPimNotifyManager *notifiers;
46}; 46};
47 47
48OTodo::OTodo(const OTodo &event ) 48OTodo::OTodo(const OTodo &event )
49 : OPimRecord( event ), data( event.data ) 49 : OPimRecord( event ), data( event.data )
50{ 50{
51 data->ref(); 51 data->ref();
52// qWarning("ref up"); 52// qWarning("ref up");
53} 53}
54OTodo::~OTodo() { 54OTodo::~OTodo() {
55 55
56// qWarning("~OTodo " ); 56// qWarning("~OTodo " );
57 if ( data->deref() ) { 57 if ( data->deref() ) {
58// qWarning("OTodo::dereffing"); 58// qWarning("OTodo::dereffing");
59 delete data; 59 delete data;
60 data = 0l; 60 data = 0l;
61 } 61 }
62} 62}
63OTodo::OTodo(bool completed, int priority, 63OTodo::OTodo(bool completed, int priority,
64 const QArray<int> &category, 64 const QArray<int> &category,
65 const QString& summary, 65 const QString& summary,
66 const QString &description, 66 const QString &description,
67 ushort progress, 67 ushort progress,
68 bool hasDate, QDate date, int uid ) 68 bool hasDate, QDate date, int uid )
69 : OPimRecord( uid ) 69 : OPimRecord( uid )
70{ 70{
71// qWarning("OTodoData " + summary); 71// qWarning("OTodoData " + summary);
72 setCategories( category ); 72 setCategories( category );
73 73
74 data = new OTodoData; 74 data = new OTodoData;
75 75
76 data->date = date; 76 data->date = date;
77 data->isCompleted = completed; 77 data->isCompleted = completed;
78 data->hasDate = hasDate; 78 data->hasDate = hasDate;
79 data->priority = priority; 79 data->priority = priority;
80 data->sum = summary; 80 data->sum = summary;
81 data->prog = progress; 81 data->prog = progress;
82 data->desc = Qtopia::simplifyMultiLineSpace(description ); 82 data->desc = Qtopia::simplifyMultiLineSpace(description );
83} 83}
84OTodo::OTodo(bool completed, int priority, 84OTodo::OTodo(bool completed, int priority,
85 const QStringList &category, 85 const QStringList &category,
86 const QString& summary, 86 const QString& summary,
87 const QString &description, 87 const QString &description,
88 ushort progress, 88 ushort progress,
89 bool hasDate, QDate date, int uid ) 89 bool hasDate, QDate date, int uid )
90 : OPimRecord( uid ) 90 : OPimRecord( uid )
91{ 91{
92// qWarning("OTodoData" + summary); 92// qWarning("OTodoData" + summary);
93 setCategories( idsFromString( category.join(";") ) ); 93 setCategories( idsFromString( category.join(";") ) );
94 94
95 data = new OTodoData; 95 data = new OTodoData;
96 96
97 data->date = date; 97 data->date = date;
98 data->isCompleted = completed; 98 data->isCompleted = completed;
99 data->hasDate = hasDate; 99 data->hasDate = hasDate;
100 data->priority = priority; 100 data->priority = priority;
101 data->sum = summary; 101 data->sum = summary;
102 data->prog = progress; 102 data->prog = progress;
103 data->desc = Qtopia::simplifyMultiLineSpace(description ); 103 data->desc = Qtopia::simplifyMultiLineSpace(description );
104} 104}
105bool OTodo::match( const QRegExp &regExp )const 105bool OTodo::match( const QRegExp &regExp )const
106{ 106{
107 if( QString::number( data->priority ).find( regExp ) != -1 ){ 107 if( QString::number( data->priority ).find( regExp ) != -1 ){
108 return true; 108 setLastHitField( Priority );
109 return true;
109 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 110 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
110 return true; 111 setLastHitField( HasDate );
112 return true;
111 }else if(data->desc.find( regExp ) != -1 ){ 113 }else if(data->desc.find( regExp ) != -1 ){
112 return true; 114 setLastHitField( Description );
115 return true;
113 }else if(data->sum.find( regExp ) != -1 ) { 116 }else if(data->sum.find( regExp ) != -1 ) {
114 return true; 117 setLastHitField( Summary );
118 return true;
115 } 119 }
116 return false; 120 return false;
117} 121}
118bool OTodo::isCompleted() const 122bool OTodo::isCompleted() const
119{ 123{
120 return data->isCompleted; 124 return data->isCompleted;
121} 125}
122bool OTodo::hasDueDate() const 126bool OTodo::hasDueDate() const
123{ 127{
124 return data->hasDate; 128 return data->hasDate;
125} 129}
126bool OTodo::hasStartDate()const { 130bool OTodo::hasStartDate()const {
127 return data->start.isValid(); 131 return data->start.isValid();
128} 132}
129bool OTodo::hasCompletedDate()const { 133bool OTodo::hasCompletedDate()const {
130 return data->completed.isValid(); 134 return data->completed.isValid();
131} 135}
132int OTodo::priority()const 136int OTodo::priority()const
133{ 137{
134 return data->priority; 138 return data->priority;
135} 139}
136QString OTodo::summary() const 140QString OTodo::summary() const
137{ 141{
138 return data->sum; 142 return data->sum;
139} 143}
140ushort OTodo::progress() const 144ushort OTodo::progress() const
141{ 145{
142 return data->prog; 146 return data->prog;
143} 147}
144QDate OTodo::dueDate()const 148QDate OTodo::dueDate()const
145{ 149{
146 return data->date; 150 return data->date;
147} 151}
148QDate OTodo::startDate()const { 152QDate OTodo::startDate()const {
149 return data->start; 153 return data->start;
150} 154}
151QDate OTodo::completedDate()const { 155QDate OTodo::completedDate()const {
152 return data->completed; 156 return data->completed;
153} 157}
154QString OTodo::description()const 158QString OTodo::description()const
155{ 159{
156 return data->desc; 160 return data->desc;
157} 161}
158bool OTodo::hasState() const{ 162bool OTodo::hasState() const{
159 if (!data->state ) return false; 163 if (!data->state ) return false;
160 return ( data->state->state() != OPimState::Undefined ); 164 return ( data->state->state() != OPimState::Undefined );
161} 165}
162OPimState OTodo::state()const { 166OPimState OTodo::state()const {
163 if (!data->state ) { 167 if (!data->state ) {
164 OPimState state; 168 OPimState state;
165 return state; 169 return state;
166 } 170 }
167 171
168 return (*data->state); 172 return (*data->state);
169} 173}
170bool OTodo::hasRecurrence()const { 174bool OTodo::hasRecurrence()const {
171 if (!data->recur) return false; 175 if (!data->recur) return false;
172 return data->recur->doesRecur(); 176 return data->recur->doesRecur();
173} 177}
174ORecur OTodo::recurrence()const { 178ORecur OTodo::recurrence()const {
175 if (!data->recur) return ORecur(); 179 if (!data->recur) return ORecur();
176 180
177 return (*data->recur); 181 return (*data->recur);
178} 182}
179bool OTodo::hasMaintainer()const { 183bool OTodo::hasMaintainer()const {
180 if (!data->maintainer) return false; 184 if (!data->maintainer) return false;
181 185
182 return (data->maintainer->mode() != OPimMaintainer::Undefined ); 186 return (data->maintainer->mode() != OPimMaintainer::Undefined );
183} 187}
184OPimMaintainer OTodo::maintainer()const { 188OPimMaintainer OTodo::maintainer()const {
185 if (!data->maintainer) return OPimMaintainer(); 189 if (!data->maintainer) return OPimMaintainer();
186 190
187 return (*data->maintainer); 191 return (*data->maintainer);
188} 192}
189void OTodo::setCompleted( bool completed ) 193void OTodo::setCompleted( bool completed )
190{ 194{
191 changeOrModify(); 195 changeOrModify();
192 data->isCompleted = completed; 196 data->isCompleted = completed;
193} 197}
194void OTodo::setHasDueDate( bool hasDate ) 198void OTodo::setHasDueDate( bool hasDate )
195{ 199{
196 changeOrModify(); 200 changeOrModify();
197 data->hasDate = hasDate; 201 data->hasDate = hasDate;
198} 202}
199void OTodo::setDescription(const QString &desc ) 203void OTodo::setDescription(const QString &desc )
200{ 204{
201// qWarning( "desc " + desc ); 205// qWarning( "desc " + desc );
202 changeOrModify(); 206 changeOrModify();
203 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 207 data->desc = Qtopia::simplifyMultiLineSpace(desc );
204} 208}
205void OTodo::setSummary( const QString& sum ) 209void OTodo::setSummary( const QString& sum )
206{ 210{
207 changeOrModify(); 211 changeOrModify();
208 data->sum = sum; 212 data->sum = sum;
209} 213}
210void OTodo::setPriority(int prio ) 214void OTodo::setPriority(int prio )
211{ 215{
212 changeOrModify(); 216 changeOrModify();
213 data->priority = prio; 217 data->priority = prio;
214} 218}
215void OTodo::setDueDate( const QDate& date ) 219void OTodo::setDueDate( const QDate& date )
216{ 220{
217 changeOrModify(); 221 changeOrModify();
218 data->date = date; 222 data->date = date;
219} 223}
220void OTodo::setStartDate( const QDate& date ) { 224void OTodo::setStartDate( const QDate& date ) {
221 changeOrModify(); 225 changeOrModify();
222 data->start = date; 226 data->start = date;
223} 227}
224void OTodo::setCompletedDate( const QDate& date ) { 228void OTodo::setCompletedDate( const QDate& date ) {
225 changeOrModify(); 229 changeOrModify();
226 data->completed = date; 230 data->completed = date;
227} 231}
228void OTodo::setState( const OPimState& state ) { 232void OTodo::setState( const OPimState& state ) {
229 changeOrModify(); 233 changeOrModify();
230 if (data->state ) 234 if (data->state )
231 (*data->state) = state; 235 (*data->state) = state;
232 else 236 else
233 data->state = new OPimState( state ); 237 data->state = new OPimState( state );
234} 238}
235void OTodo::setRecurrence( const ORecur& rec) { 239void OTodo::setRecurrence( const ORecur& rec) {
236 changeOrModify(); 240 changeOrModify();
237 if (data->recur ) 241 if (data->recur )
238 (*data->recur) = rec; 242 (*data->recur) = rec;
239 else 243 else
240 data->recur = new ORecur( rec ); 244 data->recur = new ORecur( rec );
241} 245}
242void OTodo::setMaintainer( const OPimMaintainer& pim ) { 246void OTodo::setMaintainer( const OPimMaintainer& pim ) {
243 changeOrModify(); 247 changeOrModify();
244 248
245 if (data->maintainer ) 249 if (data->maintainer )
246 (*data->maintainer) = pim; 250 (*data->maintainer) = pim;
247 else 251 else
248 data->maintainer = new OPimMaintainer( pim ); 252 data->maintainer = new OPimMaintainer( pim );
249} 253}
250bool OTodo::isOverdue( ) 254bool OTodo::isOverdue( )
251{ 255{
252 if( data->hasDate && !data->isCompleted) 256 if( data->hasDate && !data->isCompleted)
253 return QDate::currentDate() > data->date; 257 return QDate::currentDate() > data->date;
254 return false; 258 return false;
255} 259}
256void OTodo::setProgress(ushort progress ) 260void OTodo::setProgress(ushort progress )
257{ 261{
258 changeOrModify(); 262 changeOrModify();
259 data->prog = progress; 263 data->prog = progress;
260} 264}
261QString OTodo::toShortText() const { 265QString OTodo::toShortText() const {
262 return summary(); 266 return summary();
263} 267}
264/*! 268/*!
265 Returns a richt text string 269 Returns a richt text string
266*/ 270*/
267QString OTodo::toRichText() const 271QString OTodo::toRichText() const
268{ 272{
269 QString text; 273 QString text;
270 QStringList catlist; 274 QStringList catlist;
271 275
272 // Description of the todo 276 // Description of the todo
273 if ( !summary().isEmpty() ) { 277 if ( !summary().isEmpty() ) {
274 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 278 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
275 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
276 } 280 }
277 if( !description().isEmpty() ){ 281 if( !description().isEmpty() ){
278 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 282 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
279 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 283 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
280 } 284 }
281 text += "<br><br><br>"; 285 text += "<br><br><br>";
282 286
283 text += "<b>" + QObject::tr( "Priority:") +" </b>" 287 text += "<b>" + QObject::tr( "Priority:") +" </b>"
284 + QString::number( priority() ) + " <br>"; 288 + QString::number( priority() ) + " <br>";
285 text += "<b>" + QObject::tr( "Progress:") + " </b>" 289 text += "<b>" + QObject::tr( "Progress:") + " </b>"
286 + QString::number( progress() ) + " %<br>"; 290 + QString::number( progress() ) + " %<br>";
287 if (hasDueDate() ){ 291 if (hasDueDate() ){
288 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 292 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
289 text += dueDate().toString(); 293 text += dueDate().toString();
290 text += "<br>"; 294 text += "<br>";
291 } 295 }
292 296
293 text += "<b>" + QObject::tr( "Category:") + "</b> "; 297 text += "<b>" + QObject::tr( "Category:") + "</b> ";
294 text += categoryNames( "Todo List" ).join(", "); 298 text += categoryNames( "Todo List" ).join(", ");
295 text += "<br>"; 299 text += "<br>";
296 300
297 return text; 301 return text;
298} 302}
299bool OTodo::hasNotifiers()const { 303bool OTodo::hasNotifiers()const {
300 if (!data->notifiers) return false; 304 if (!data->notifiers) return false;
301 return !data->notifiers->isEmpty(); 305 return !data->notifiers->isEmpty();
302} 306}
303OPimNotifyManager& OTodo::notifiers() { 307OPimNotifyManager& OTodo::notifiers() {
304 if (!data->notifiers ) 308 if (!data->notifiers )
305 data->notifiers = new OPimNotifyManager; 309 data->notifiers = new OPimNotifyManager;
306 return (*data->notifiers); 310 return (*data->notifiers);
307} 311}
308const OPimNotifyManager& OTodo::notifiers()const{ 312const OPimNotifyManager& OTodo::notifiers()const{
309 if (!data->notifiers ) 313 if (!data->notifiers )
310 data->notifiers = new OPimNotifyManager; 314 data->notifiers = new OPimNotifyManager;
311 315
312 return (*data->notifiers); 316 return (*data->notifiers);
313} 317}
314 318
315bool OTodo::operator<( const OTodo &toDoEvent )const{ 319bool OTodo::operator<( const OTodo &toDoEvent )const{
316 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 320 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
317 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 321 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
318 if( hasDueDate() && toDoEvent.hasDueDate() ){ 322 if( hasDueDate() && toDoEvent.hasDueDate() ){
319 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 323 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
320 return priority() < toDoEvent.priority(); 324 return priority() < toDoEvent.priority();
321 }else{ 325 }else{
322 return dueDate() < toDoEvent.dueDate(); 326 return dueDate() < toDoEvent.dueDate();
323 } 327 }
324 } 328 }
325 return false; 329 return false;
326} 330}
327bool OTodo::operator<=(const OTodo &toDoEvent )const 331bool OTodo::operator<=(const OTodo &toDoEvent )const
328{ 332{
329 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 333 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
330 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 334 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
331 if( hasDueDate() && toDoEvent.hasDueDate() ){ 335 if( hasDueDate() && toDoEvent.hasDueDate() ){
332 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 336 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
333 return priority() <= toDoEvent.priority(); 337 return priority() <= toDoEvent.priority();
334 }else{ 338 }else{
335 return dueDate() <= toDoEvent.dueDate(); 339 return dueDate() <= toDoEvent.dueDate();
336 } 340 }
337 } 341 }
338 return true; 342 return true;
339} 343}
340bool OTodo::operator>(const OTodo &toDoEvent )const 344bool OTodo::operator>(const OTodo &toDoEvent )const
341{ 345{
342 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 346 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
343 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 347 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
344 if( hasDueDate() && toDoEvent.hasDueDate() ){ 348 if( hasDueDate() && toDoEvent.hasDueDate() ){
345 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 349 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
346 return priority() > toDoEvent.priority(); 350 return priority() > toDoEvent.priority();
347 }else{ 351 }else{
348 return dueDate() > toDoEvent.dueDate(); 352 return dueDate() > toDoEvent.dueDate();
349 } 353 }
350 } 354 }
351 return false; 355 return false;
352} 356}
353bool OTodo::operator>=(const OTodo &toDoEvent )const 357bool OTodo::operator>=(const OTodo &toDoEvent )const
354{ 358{
355 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 359 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
356 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 360 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
357 if( hasDueDate() && toDoEvent.hasDueDate() ){ 361 if( hasDueDate() && toDoEvent.hasDueDate() ){
358 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 362 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
359 return priority() > toDoEvent.priority(); 363 return priority() > toDoEvent.priority();
360 }else{ 364 }else{
361 return dueDate() > toDoEvent.dueDate(); 365 return dueDate() > toDoEvent.dueDate();
362 } 366 }
363 } 367 }
364 return true; 368 return true;
365} 369}
366bool OTodo::operator==(const OTodo &toDoEvent )const 370bool OTodo::operator==(const OTodo &toDoEvent )const
367{ 371{
368 if ( data->priority != toDoEvent.data->priority ) return false; 372 if ( data->priority != toDoEvent.data->priority ) return false;
369 if ( data->priority != toDoEvent.data->prog ) return false; 373 if ( data->priority != toDoEvent.data->prog ) return false;
370 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 374 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;