-rw-r--r-- | libopie2/opiepim/oevent.cpp | 534 |
1 files changed, 405 insertions, 129 deletions
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp index de5e30b..d9cee2b 100644 --- a/libopie2/opiepim/oevent.cpp +++ b/libopie2/opiepim/oevent.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | 3 | Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
@@ -27,20 +27,24 @@ | |||
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #include <qshared.h> | ||
30 | #include <qarray.h> | ||
31 | 29 | ||
32 | #include <qpe/palmtopuidgen.h> | 30 | #include "oevent.h" |
33 | #include <qpe/categories.h> | ||
34 | #include <qpe/stringutil.h> | ||
35 | 31 | ||
32 | /* OPIE */ | ||
36 | #include <opie2/orecur.h> | 33 | #include <opie2/orecur.h> |
37 | #include <opie2/opimresolver.h> | 34 | #include <opie2/opimresolver.h> |
38 | #include <opie2/opimnotifymanager.h> | 35 | #include <opie2/opimnotifymanager.h> |
36 | #include <qpe/categories.h> | ||
37 | #include <qpe/palmtopuidgen.h> | ||
38 | #include <qpe/stringutil.h> | ||
39 | 39 | ||
40 | #include <opie2/oevent.h> | 40 | /* QT */ |
41 | #include <qshared.h> | ||
42 | #include <qarray.h> | ||
41 | 43 | ||
42 | namespace Opie { | 44 | namespace Opie |
45 | { | ||
43 | 46 | ||
44 | int OCalendarHelper::week( const QDate& date) { | 47 | int OCalendarHelper::week( const QDate& date ) |
48 | { | ||
45 | // Calculates the week this date is in within that | 49 | // Calculates the week this date is in within that |
46 | // month. Equals the "row" is is in in the month view | 50 | // month. Equals the "row" is is in in the month view |
@@ -54,13 +58,20 @@ int OCalendarHelper::week( const QDate& date) { | |||
54 | return week; | 58 | return week; |
55 | } | 59 | } |
56 | int OCalendarHelper::ocurrence( const QDate& date) { | 60 | |
61 | |||
62 | int OCalendarHelper::ocurrence( const QDate& date ) | ||
63 | { | ||
57 | // calculates the number of occurrances of this day of the | 64 | // calculates the number of occurrances of this day of the |
58 | // week till the given date (e.g 3rd Wednesday of the month) | 65 | // week till the given date (e.g 3rd Wednesday of the month) |
59 | return ( date.day() - 1 ) / 7 + 1; | 66 | return ( date.day() - 1 ) / 7 + 1; |
60 | } | 67 | } |
61 | int OCalendarHelper::dayOfWeek( char day ) { | 68 | |
69 | |||
70 | int OCalendarHelper::dayOfWeek( char day ) | ||
71 | { | ||
62 | int dayOfWeek = 1; | 72 | int dayOfWeek = 1; |
63 | char i = ORecur::MON; | 73 | char i = ORecur::MON; |
64 | while ( !( i & day ) && i <= ORecur::SUN ) { | 74 | while ( !( i & day ) && i <= ORecur::SUN ) |
75 | { | ||
65 | i <<= 1; | 76 | i <<= 1; |
66 | ++dayOfWeek; | 77 | ++dayOfWeek; |
@@ -68,11 +79,17 @@ int OCalendarHelper::dayOfWeek( char day ) { | |||
68 | return dayOfWeek; | 79 | return dayOfWeek; |
69 | } | 80 | } |
70 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { | 81 | |
82 | |||
83 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) | ||
84 | { | ||
71 | return ( second.year() - first.year() ) * 12 + | 85 | return ( second.year() - first.year() ) * 12 + |
72 | second.month() - first.month(); | 86 | second.month() - first.month(); |
73 | } | 87 | } |
74 | 88 | ||
75 | struct OEvent::Data : public QShared { | 89 | |
76 | Data() : QShared() { | 90 | struct OEvent::Data : public QShared |
91 | { | ||
92 | Data() : QShared() | ||
93 | { | ||
77 | child = 0; | 94 | child = 0; |
78 | recur = 0; | 95 | recur = 0; |
@@ -81,5 +98,6 @@ struct OEvent::Data : public QShared { | |||
81 | parent = 0; | 98 | parent = 0; |
82 | } | 99 | } |
83 | ~Data() { | 100 | ~Data() |
101 | { | ||
84 | delete manager; | 102 | delete manager; |
85 | delete recur; | 103 | delete recur; |
@@ -99,8 +117,12 @@ struct OEvent::Data : public QShared { | |||
99 | }; | 117 | }; |
100 | 118 | ||
119 | |||
101 | OEvent::OEvent( int uid ) | 120 | OEvent::OEvent( int uid ) |
102 | : OPimRecord( uid ) { | 121 | : OPimRecord( uid ) |
122 | { | ||
103 | data = new Data; | 123 | data = new Data; |
104 | } | 124 | } |
125 | |||
126 | |||
105 | OEvent::OEvent( const OEvent& ev) | 127 | OEvent::OEvent( const OEvent& ev) |
106 | : OPimRecord( ev ), data( ev.data ) | 128 | : OPimRecord( ev ), data( ev.data ) |
@@ -109,4 +131,5 @@ OEvent::OEvent( const OEvent& ev) | |||
109 | } | 131 | } |
110 | 132 | ||
133 | |||
111 | OEvent::OEvent( const QMap<int, QString> map ) | 134 | OEvent::OEvent( const QMap<int, QString> map ) |
112 | : OPimRecord( 0 ) | 135 | : OPimRecord( 0 ) |
@@ -117,11 +140,17 @@ OEvent::OEvent( const QMap<int, QString> map ) | |||
117 | } | 140 | } |
118 | 141 | ||
119 | OEvent::~OEvent() { | 142 | |
120 | if ( data->deref() ) { | 143 | OEvent::~OEvent() |
144 | { | ||
145 | if ( data->deref() ) | ||
146 | { | ||
121 | delete data; | 147 | delete data; |
122 | data = 0; | 148 | data = 0; |
123 | } | 149 | } |
124 | } | 150 | } |
125 | OEvent& OEvent::operator=( const OEvent& ev) { | 151 | |
152 | |||
153 | OEvent& OEvent::operator=( const OEvent& ev ) | ||
154 | { | ||
126 | if ( this == &ev ) return *this; | 155 | if ( this == &ev ) return *this; |
127 | 156 | ||
@@ -134,19 +163,34 @@ OEvent& OEvent::operator=( const OEvent& ev) { | |||
134 | return *this; | 163 | return *this; |
135 | } | 164 | } |
136 | QString OEvent::description()const { | 165 | |
166 | |||
167 | QString OEvent::description() const | ||
168 | { | ||
137 | return data->description; | 169 | return data->description; |
138 | } | 170 | } |
139 | void OEvent::setDescription( const QString& description ) { | 171 | |
172 | |||
173 | void OEvent::setDescription( const QString& description ) | ||
174 | { | ||
140 | changeOrModify(); | 175 | changeOrModify(); |
141 | data->description = description; | 176 | data->description = description; |
142 | } | 177 | } |
143 | void OEvent::setLocation( const QString& loc ) { | 178 | |
179 | |||
180 | void OEvent::setLocation( const QString& loc ) | ||
181 | { | ||
144 | changeOrModify(); | 182 | changeOrModify(); |
145 | data->location = loc; | 183 | data->location = loc; |
146 | } | 184 | } |
147 | QString OEvent::location()const { | 185 | |
186 | |||
187 | QString OEvent::location() const | ||
188 | { | ||
148 | return data->location; | 189 | return data->location; |
149 | } | 190 | } |
150 | OPimNotifyManager &OEvent::notifiers()const { | 191 | |
192 | |||
193 | OPimNotifyManager &OEvent::notifiers() const | ||
194 | { | ||
151 | // I hope we can skip the changeOrModify here | 195 | // I hope we can skip the changeOrModify here |
152 | // the notifier should take care of it | 196 | // the notifier should take care of it |
@@ -157,5 +201,8 @@ OPimNotifyManager &OEvent::notifiers()const { | |||
157 | return *data->manager; | 201 | return *data->manager; |
158 | } | 202 | } |
159 | bool OEvent::hasNotifiers()const { | 203 | |
204 | |||
205 | bool OEvent::hasNotifiers() const | ||
206 | { | ||
160 | if (!data->manager ) | 207 | if (!data->manager ) |
161 | return false; | 208 | return false; |
@@ -166,5 +213,8 @@ bool OEvent::hasNotifiers()const { | |||
166 | return true; | 213 | return true; |
167 | } | 214 | } |
168 | ORecur OEvent::recurrence()const { | 215 | |
216 | |||
217 | ORecur OEvent::recurrence() const | ||
218 | { | ||
169 | if (!data->recur) | 219 | if (!data->recur) |
170 | data->recur = new ORecur; | 220 | data->recur = new ORecur; |
@@ -172,5 +222,8 @@ ORecur OEvent::recurrence()const { | |||
172 | return *data->recur; | 222 | return *data->recur; |
173 | } | 223 | } |
174 | void OEvent::setRecurrence( const ORecur& rec) { | 224 | |
225 | |||
226 | void OEvent::setRecurrence( const ORecur& rec ) | ||
227 | { | ||
175 | changeOrModify(); | 228 | changeOrModify(); |
176 | if (data->recur ) | 229 | if (data->recur ) |
@@ -179,28 +232,49 @@ void OEvent::setRecurrence( const ORecur& rec) { | |||
179 | data->recur = new ORecur( rec ); | 232 | data->recur = new ORecur( rec ); |
180 | } | 233 | } |
181 | bool OEvent::hasRecurrence()const { | 234 | |
235 | |||
236 | bool OEvent::hasRecurrence() const | ||
237 | { | ||
182 | if (!data->recur ) return false; | 238 | if (!data->recur ) return false; |
183 | return data->recur->doesRecur(); | 239 | return data->recur->doesRecur(); |
184 | } | 240 | } |
185 | QString OEvent::note()const { | 241 | |
242 | |||
243 | QString OEvent::note() const | ||
244 | { | ||
186 | return data->note; | 245 | return data->note; |
187 | } | 246 | } |
188 | void OEvent::setNote( const QString& note ) { | 247 | |
248 | |||
249 | void OEvent::setNote( const QString& note ) | ||
250 | { | ||
189 | changeOrModify(); | 251 | changeOrModify(); |
190 | data->note = note; | 252 | data->note = note; |
191 | } | 253 | } |
192 | QDateTime OEvent::createdDateTime()const { | 254 | |
255 | |||
256 | QDateTime OEvent::createdDateTime() const | ||
257 | { | ||
193 | return data->created; | 258 | return data->created; |
194 | } | 259 | } |
195 | void OEvent::setCreatedDateTime( const QDateTime& time ) { | 260 | |
261 | |||
262 | void OEvent::setCreatedDateTime( const QDateTime& time ) | ||
263 | { | ||
196 | changeOrModify(); | 264 | changeOrModify(); |
197 | data->created = time; | 265 | data->created = time; |
198 | } | 266 | } |
199 | QDateTime OEvent::startDateTime()const { | 267 | |
268 | |||
269 | QDateTime OEvent::startDateTime() const | ||
270 | { | ||
200 | if ( data->isAllDay ) | 271 | if ( data->isAllDay ) |
201 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); | 272 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); |
202 | return data->start; | 273 | return data->start; |
203 | } | 274 | } |
204 | QDateTime OEvent::startDateTimeInZone()const { | 275 | |
276 | |||
277 | QDateTime OEvent::startDateTimeInZone() const | ||
278 | { | ||
205 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 279 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
206 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); | 280 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); |
@@ -209,9 +283,15 @@ QDateTime OEvent::startDateTimeInZone()const { | |||
209 | return zone.toDateTime( data->start, OTimeZone::current() ); | 283 | return zone.toDateTime( data->start, OTimeZone::current() ); |
210 | } | 284 | } |
211 | void OEvent::setStartDateTime( const QDateTime& dt ) { | 285 | |
286 | |||
287 | void OEvent::setStartDateTime( const QDateTime& dt ) | ||
288 | { | ||
212 | changeOrModify(); | 289 | changeOrModify(); |
213 | data->start = dt; | 290 | data->start = dt; |
214 | } | 291 | } |
215 | QDateTime OEvent::endDateTime()const { | 292 | |
293 | |||
294 | QDateTime OEvent::endDateTime() const | ||
295 | { | ||
216 | /* | 296 | /* |
217 | * if all Day event the end time needs | 297 | * if all Day event the end time needs |
@@ -222,5 +302,8 @@ QDateTime OEvent::endDateTime()const { | |||
222 | return data->end; | 302 | return data->end; |
223 | } | 303 | } |
224 | QDateTime OEvent::endDateTimeInZone()const { | 304 | |
305 | |||
306 | QDateTime OEvent::endDateTimeInZone() const | ||
307 | { | ||
225 | /* if no timezone, or all day event or if the current and this timeZone match... */ | 308 | /* if no timezone, or all day event or if the current and this timeZone match... */ |
226 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); | 309 | if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); |
@@ -229,45 +312,71 @@ QDateTime OEvent::endDateTimeInZone()const { | |||
229 | return zone.toDateTime( data->end, OTimeZone::current() ); | 312 | return zone.toDateTime( data->end, OTimeZone::current() ); |
230 | } | 313 | } |
231 | void OEvent::setEndDateTime( const QDateTime& dt ) { | 314 | |
315 | |||
316 | void OEvent::setEndDateTime( const QDateTime& dt ) | ||
317 | { | ||
232 | changeOrModify(); | 318 | changeOrModify(); |
233 | data->end = dt; | 319 | data->end = dt; |
234 | } | 320 | } |
235 | bool OEvent::isMultipleDay()const { | 321 | |
322 | |||
323 | bool OEvent::isMultipleDay() const | ||
324 | { | ||
236 | return data->end.date().day() - data->start.date().day(); | 325 | return data->end.date().day() - data->start.date().day(); |
237 | } | 326 | } |
238 | bool OEvent::isAllDay()const { | 327 | |
328 | |||
329 | bool OEvent::isAllDay() const | ||
330 | { | ||
239 | return data->isAllDay; | 331 | return data->isAllDay; |
240 | } | 332 | } |
241 | void OEvent::setAllDay( bool allDay ) { | 333 | |
334 | |||
335 | void OEvent::setAllDay( bool allDay ) | ||
336 | { | ||
242 | changeOrModify(); | 337 | changeOrModify(); |
243 | data->isAllDay = allDay; | 338 | data->isAllDay = allDay; |
244 | if (allDay ) data->timezone = "UTC"; | 339 | if (allDay ) data->timezone = "UTC"; |
245 | } | 340 | } |
246 | void OEvent::setTimeZone( const QString& tz ) { | 341 | |
342 | |||
343 | void OEvent::setTimeZone( const QString& tz ) | ||
344 | { | ||
247 | changeOrModify(); | 345 | changeOrModify(); |
248 | data->timezone = tz; | 346 | data->timezone = tz; |
249 | } | 347 | } |
250 | QString OEvent::timeZone()const { | 348 | |
349 | |||
350 | QString OEvent::timeZone() const | ||
351 | { | ||
251 | if (data->isAllDay ) return QString::fromLatin1("UTC"); | 352 | if (data->isAllDay ) return QString::fromLatin1("UTC"); |
252 | return data->timezone; | 353 | return data->timezone; |
253 | } | 354 | } |
254 | bool OEvent::match( const QRegExp& re )const { | 355 | |
255 | if ( re.match( data->description ) != -1 ){ | 356 | |
357 | bool OEvent::match( const QRegExp& re ) const | ||
358 | { | ||
359 | if ( re.match( data->description ) != -1 ) | ||
360 | { | ||
256 | setLastHitField( Qtopia::DatebookDescription ); | 361 | setLastHitField( Qtopia::DatebookDescription ); |
257 | return true; | 362 | return true; |
258 | } | 363 | } |
259 | if ( re.match( data->note ) != -1 ){ | 364 | if ( re.match( data->note ) != -1 ) |
365 | { | ||
260 | setLastHitField( Qtopia::Note ); | 366 | setLastHitField( Qtopia::Note ); |
261 | return true; | 367 | return true; |
262 | } | 368 | } |
263 | if ( re.match( data->location ) != -1 ){ | 369 | if ( re.match( data->location ) != -1 ) |
370 | { | ||
264 | setLastHitField( Qtopia::Location ); | 371 | setLastHitField( Qtopia::Location ); |
265 | return true; | 372 | return true; |
266 | } | 373 | } |
267 | if ( re.match( data->start.toString() ) != -1 ){ | 374 | if ( re.match( data->start.toString() ) != -1 ) |
375 | { | ||
268 | setLastHitField( Qtopia::StartDateTime ); | 376 | setLastHitField( Qtopia::StartDateTime ); |
269 | return true; | 377 | return true; |
270 | } | 378 | } |
271 | if ( re.match( data->end.toString() ) != -1 ){ | 379 | if ( re.match( data->end.toString() ) != -1 ) |
380 | { | ||
272 | setLastHitField( Qtopia::EndDateTime ); | 381 | setLastHitField( Qtopia::EndDateTime ); |
273 | return true; | 382 | return true; |
@@ -275,10 +384,14 @@ bool OEvent::match( const QRegExp& re )const { | |||
275 | return false; | 384 | return false; |
276 | } | 385 | } |
277 | QString OEvent::toRichText()const { | 386 | |
387 | |||
388 | QString OEvent::toRichText() const | ||
389 | { | ||
278 | QString text, value; | 390 | QString text, value; |
279 | 391 | ||
280 | // description | 392 | // description |
281 | text += "<b><h3><img src=\"datebook/DateBook\">"; | 393 | text += "<b><h3><img src=\"datebook/DateBook\">"; |
282 | if ( !description().isEmpty() ) { | 394 | if ( !description().isEmpty() ) |
395 | { | ||
283 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" ); | 396 | text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" ); |
284 | } | 397 | } |
@@ -286,5 +399,6 @@ QString OEvent::toRichText()const { | |||
286 | 399 | ||
287 | // location | 400 | // location |
288 | if ( !(value = location()).isEmpty() ) { | 401 | if ( !( value = location() ).isEmpty() ) |
402 | { | ||
289 | text += "<b>" + QObject::tr( "Location:" ) + "</b> "; | 403 | text += "<b>" + QObject::tr( "Location:" ) + "</b> "; |
290 | text += Qtopia::escapeString(value) + "<br>"; | 404 | text += Qtopia::escapeString(value) + "<br>"; |
@@ -292,15 +406,19 @@ QString OEvent::toRichText()const { | |||
292 | 406 | ||
293 | // all day event | 407 | // all day event |
294 | if ( isAllDay() ) { | 408 | if ( isAllDay() ) |
409 | { | ||
295 | text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; | 410 | text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; |
296 | } | 411 | } |
297 | // multiple day event | 412 | // multiple day event |
298 | else if ( isMultipleDay () ) { | 413 | else if ( isMultipleDay () ) |
414 | { | ||
299 | text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; | 415 | text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; |
300 | } | 416 | } |
301 | // start & end times | 417 | // start & end times |
302 | else { | 418 | else |
419 | { | ||
303 | // start time | 420 | // start time |
304 | if ( startDateTime().isValid() ) { | 421 | if ( startDateTime().isValid() ) |
422 | { | ||
305 | text += "<b>" + QObject::tr( "Start:") + "</b> "; | 423 | text += "<b>" + QObject::tr( "Start:") + "</b> "; |
306 | text += Qtopia::escapeString(startDateTime().toString() ). | 424 | text += Qtopia::escapeString(startDateTime().toString() ). |
@@ -309,5 +427,6 @@ QString OEvent::toRichText()const { | |||
309 | 427 | ||
310 | // end time | 428 | // end time |
311 | if ( endDateTime().isValid() ) { | 429 | if ( endDateTime().isValid() ) |
430 | { | ||
312 | text += "<b>" + QObject::tr( "End:") + "</b> "; | 431 | text += "<b>" + QObject::tr( "End:") + "</b> "; |
313 | text += Qtopia::escapeString(endDateTime().toString() ). | 432 | text += Qtopia::escapeString(endDateTime().toString() ). |
@@ -317,5 +436,6 @@ QString OEvent::toRichText()const { | |||
317 | 436 | ||
318 | // categories | 437 | // categories |
319 | if ( categoryNames("Calendar").count() ){ | 438 | if ( categoryNames( "Calendar" ).count() ) |
439 | { | ||
320 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 440 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
321 | text += categoryNames("Calendar").join(", "); | 441 | text += categoryNames("Calendar").join(", "); |
@@ -324,5 +444,6 @@ QString OEvent::toRichText()const { | |||
324 | 444 | ||
325 | //notes | 445 | //notes |
326 | if ( !note().isEmpty() ) { | 446 | if ( !note().isEmpty() ) |
447 | { | ||
327 | text += "<b>" + QObject::tr( "Note:") + "</b><br>"; | 448 | text += "<b>" + QObject::tr( "Note:") + "</b><br>"; |
328 | text += note(); | 449 | text += note(); |
@@ -332,5 +453,8 @@ QString OEvent::toRichText()const { | |||
332 | return text; | 453 | return text; |
333 | } | 454 | } |
334 | QString OEvent::toShortText()const { | 455 | |
456 | |||
457 | QString OEvent::toShortText() const | ||
458 | { | ||
335 | QString text; | 459 | QString text; |
336 | text += QString::number( startDateTime().date().day() ); | 460 | text += QString::number( startDateTime().date().day() ); |
@@ -347,21 +471,40 @@ QString OEvent::toShortText()const { | |||
347 | return text; | 471 | return text; |
348 | } | 472 | } |
349 | QString OEvent::type()const { | 473 | |
474 | |||
475 | QString OEvent::type() const | ||
476 | { | ||
350 | return QString::fromLatin1("OEvent"); | 477 | return QString::fromLatin1("OEvent"); |
351 | } | 478 | } |
352 | QString OEvent::recordField( int /*id */ )const { | 479 | |
480 | |||
481 | QString OEvent::recordField( int /*id */ ) const | ||
482 | { | ||
353 | return QString::null; | 483 | return QString::null; |
354 | } | 484 | } |
355 | int OEvent::rtti() { | 485 | |
486 | |||
487 | int OEvent::rtti() | ||
488 | { | ||
356 | return OPimResolver::DateBook; | 489 | return OPimResolver::DateBook; |
357 | } | 490 | } |
358 | bool OEvent::loadFromStream( QDataStream& ) { | 491 | |
492 | |||
493 | bool OEvent::loadFromStream( QDataStream& ) | ||
494 | { | ||
359 | return true; | 495 | return true; |
360 | } | 496 | } |
361 | bool OEvent::saveToStream( QDataStream& )const { | 497 | |
498 | |||
499 | bool OEvent::saveToStream( QDataStream& ) const | ||
500 | { | ||
362 | return true; | 501 | return true; |
363 | } | 502 | } |
364 | void OEvent::changeOrModify() { | 503 | |
365 | if ( data->count != 1 ) { | 504 | |
505 | void OEvent::changeOrModify() | ||
506 | { | ||
507 | if ( data->count != 1 ) | ||
508 | { | ||
366 | data->deref(); | 509 | data->deref(); |
367 | Data* d2 = new Data; | 510 | Data* d2 = new Data; |
@@ -383,5 +526,6 @@ void OEvent::changeOrModify() { | |||
383 | d2->parent = data->parent; | 526 | d2->parent = data->parent; |
384 | 527 | ||
385 | if ( data->child ) { | 528 | if ( data->child ) |
529 | { | ||
386 | d2->child = new QArray<int>( *data->child ); | 530 | d2->child = new QArray<int>( *data->child ); |
387 | d2->child->detach(); | 531 | d2->child->detach(); |
@@ -391,6 +535,10 @@ void OEvent::changeOrModify() { | |||
391 | } | 535 | } |
392 | } | 536 | } |
393 | void OEvent::deref() { | 537 | |
394 | if ( data->deref() ) { | 538 | |
539 | void OEvent::deref() | ||
540 | { | ||
541 | if ( data->deref() ) | ||
542 | { | ||
395 | delete data; | 543 | delete data; |
396 | data = 0; | 544 | data = 0; |
@@ -402,5 +550,6 @@ void OEvent::deref() { | |||
402 | // for it and for all other places.. | 550 | // for it and for all other places.. |
403 | // Encoding should happen at one place, only ! (eilers) | 551 | // Encoding should happen at one place, only ! (eilers) |
404 | QMap<int, QString> OEvent::toMap()const { | 552 | QMap<int, QString> OEvent::toMap() const |
553 | { | ||
405 | QMap<int, QString> retMap; | 554 | QMap<int, QString> retMap; |
406 | 555 | ||
@@ -421,8 +570,10 @@ QMap<int, QString> OEvent::toMap()const { | |||
421 | if( parent() ) | 570 | if( parent() ) |
422 | retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); | 571 | retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); |
423 | if( children().count() ){ | 572 | if ( children().count() ) |
573 | { | ||
424 | QArray<int> childr = children(); | 574 | QArray<int> childr = children(); |
425 | QString buf; | 575 | QString buf; |
426 | for ( uint i = 0; i < childr.count(); i++ ) { | 576 | for ( uint i = 0; i < childr.count(); i++ ) |
577 | { | ||
427 | if ( i != 0 ) buf += " "; | 578 | if ( i != 0 ) buf += " "; |
428 | buf += QString::number( childr[i] ); | 579 | buf += QString::number( childr[i] ); |
@@ -432,5 +583,6 @@ QMap<int, QString> OEvent::toMap()const { | |||
432 | 583 | ||
433 | // Add recurrence stuff | 584 | // Add recurrence stuff |
434 | if( hasRecurrence() ){ | 585 | if ( hasRecurrence() ) |
586 | { | ||
435 | ORecur recur = recurrence(); | 587 | ORecur recur = recurrence(); |
436 | QMap<int, QString> recFields = recur.toMap(); | 588 | QMap<int, QString> recFields = recur.toMap(); |
@@ -443,5 +595,7 @@ QMap<int, QString> OEvent::toMap()const { | |||
443 | retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); | 595 | retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); |
444 | retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); | 596 | retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); |
445 | } else { | 597 | } |
598 | else | ||
599 | { | ||
446 | ORecur recur = recurrence(); | 600 | ORecur recur = recurrence(); |
447 | QMap<int, QString> recFields = recur.toMap(); | 601 | QMap<int, QString> recFields = recur.toMap(); |
@@ -452,4 +606,5 @@ QMap<int, QString> OEvent::toMap()const { | |||
452 | } | 606 | } |
453 | 607 | ||
608 | |||
454 | void OEvent::fromMap( const QMap<int, QString>& map ) | 609 | void OEvent::fromMap( const QMap<int, QString>& map ) |
455 | { | 610 | { |
@@ -473,10 +628,12 @@ void OEvent::fromMap( const QMap<int, QString>& map ) | |||
473 | 628 | ||
474 | int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); | 629 | int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); |
475 | if ( ( alarmTime != -1 ) ){ | 630 | if ( ( alarmTime != -1 ) ) |
631 | { | ||
476 | QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); | 632 | QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); |
477 | OPimAlarm al( sound , dt ); | 633 | OPimAlarm al( sound , dt ); |
478 | notifiers().add( al ); | 634 | notifiers().add( al ); |
479 | } | 635 | } |
480 | if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ | 636 | if ( !map[ OEvent::FTimeZone ].isEmpty() && ( map[ OEvent::FTimeZone ] != "None" ) ) |
637 | { | ||
481 | setTimeZone( map[OEvent::FTimeZone] ); | 638 | setTimeZone( map[OEvent::FTimeZone] ); |
482 | } | 639 | } |
@@ -486,10 +643,13 @@ void OEvent::fromMap( const QMap<int, QString>& map ) | |||
486 | 643 | ||
487 | /* AllDay is always in UTC */ | 644 | /* AllDay is always in UTC */ |
488 | if ( isAllDay() ) { | 645 | if ( isAllDay() ) |
646 | { | ||
489 | OTimeZone utc = OTimeZone::utc(); | 647 | OTimeZone utc = OTimeZone::utc(); |
490 | setStartDateTime( utc.fromUTCDateTime( start ) ); | 648 | setStartDateTime( utc.fromUTCDateTime( start ) ); |
491 | setEndDateTime ( utc.fromUTCDateTime( end ) ); | 649 | setEndDateTime ( utc.fromUTCDateTime( end ) ); |
492 | setTimeZone( "UTC"); // make sure it is really utc | 650 | setTimeZone( "UTC"); // make sure it is really utc |
493 | }else { | 651 | } |
652 | else | ||
653 | { | ||
494 | /* to current date time */ | 654 | /* to current date time */ |
495 | // qWarning(" Start is %d", start ); | 655 | // qWarning(" Start is %d", start ); |
@@ -506,7 +666,9 @@ void OEvent::fromMap( const QMap<int, QString>& map ) | |||
506 | setParent( map[OEvent::FRecParent].toInt() ); | 666 | setParent( map[OEvent::FRecParent].toInt() ); |
507 | 667 | ||
508 | if ( !map[OEvent::FRecChildren].isEmpty() ){ | 668 | if ( !map[ OEvent::FRecChildren ].isEmpty() ) |
669 | { | ||
509 | QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); | 670 | QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); |
510 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 671 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
672 | { | ||
511 | addChild( (*it).toInt() ); | 673 | addChild( (*it).toInt() ); |
512 | } | 674 | } |
@@ -514,5 +676,6 @@ void OEvent::fromMap( const QMap<int, QString>& map ) | |||
514 | 676 | ||
515 | // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. | 677 | // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. |
516 | if( !map[OEvent::FRType].isEmpty() ){ | 678 | if ( !map[ OEvent::FRType ].isEmpty() ) |
679 | { | ||
517 | QMap<int, QString> recFields; | 680 | QMap<int, QString> recFields; |
518 | recFields.insert( ORecur::RType, map[OEvent::FRType] ); | 681 | recFields.insert( ORecur::RType, map[OEvent::FRType] ); |
@@ -531,17 +694,27 @@ void OEvent::fromMap( const QMap<int, QString>& map ) | |||
531 | 694 | ||
532 | 695 | ||
533 | int OEvent::parent()const { | 696 | int OEvent::parent() const |
697 | { | ||
534 | return data->parent; | 698 | return data->parent; |
535 | } | 699 | } |
536 | void OEvent::setParent( int uid ) { | 700 | |
701 | |||
702 | void OEvent::setParent( int uid ) | ||
703 | { | ||
537 | changeOrModify(); | 704 | changeOrModify(); |
538 | data->parent = uid; | 705 | data->parent = uid; |
539 | } | 706 | } |
540 | QArray<int> OEvent::children() const{ | 707 | |
708 | |||
709 | QArray<int> OEvent::children() const | ||
710 | { | ||
541 | if (!data->child) return QArray<int>(); | 711 | if (!data->child) return QArray<int>(); |
542 | else | 712 | else |
543 | return data->child->copy(); | 713 | return data->child->copy(); |
544 | } | 714 | } |
545 | void OEvent::setChildren( const QArray<int>& arr ) { | 715 | |
716 | |||
717 | void OEvent::setChildren( const QArray<int>& arr ) | ||
718 | { | ||
546 | changeOrModify(); | 719 | changeOrModify(); |
547 | if (data->child) delete data->child; | 720 | if (data->child) delete data->child; |
@@ -550,10 +723,16 @@ void OEvent::setChildren( const QArray<int>& arr ) { | |||
550 | data->child->detach(); | 723 | data->child->detach(); |
551 | } | 724 | } |
552 | void OEvent::addChild( int uid ) { | 725 | |
726 | |||
727 | void OEvent::addChild( int uid ) | ||
728 | { | ||
553 | changeOrModify(); | 729 | changeOrModify(); |
554 | if (!data->child ) { | 730 | if ( !data->child ) |
731 | { | ||
555 | data->child = new QArray<int>(1); | 732 | data->child = new QArray<int>(1); |
556 | (*data->child)[0] = uid; | 733 | (*data->child)[0] = uid; |
557 | }else{ | 734 | } |
735 | else | ||
736 | { | ||
558 | int count = data->child->count(); | 737 | int count = data->child->count(); |
559 | data->child->resize( count + 1 ); | 738 | data->child->resize( count + 1 ); |
@@ -561,5 +740,8 @@ void OEvent::addChild( int uid ) { | |||
561 | } | 740 | } |
562 | } | 741 | } |
563 | void OEvent::removeChild( int uid ) { | 742 | |
743 | |||
744 | void OEvent::removeChild( int uid ) | ||
745 | { | ||
564 | if (!data->child || !data->child->contains( uid ) ) return; | 746 | if (!data->child || !data->child->contains( uid ) ) return; |
565 | changeOrModify(); | 747 | changeOrModify(); |
@@ -567,6 +749,8 @@ void OEvent::removeChild( int uid ) { | |||
567 | int j = 0; | 749 | int j = 0; |
568 | uint count = data->child->count(); | 750 | uint count = data->child->count(); |
569 | for ( uint i = 0; i < count; i++ ) { | 751 | for ( uint i = 0; i < count; i++ ) |
570 | if ( (*data->child)[i] != uid ) { | 752 | { |
753 | if ( ( *data->child ) [ i ] != uid ) | ||
754 | { | ||
571 | newAr[j] = (*data->child)[i]; | 755 | newAr[j] = (*data->child)[i]; |
572 | j++; | 756 | j++; |
@@ -575,7 +759,10 @@ void OEvent::removeChild( int uid ) { | |||
575 | (*data->child) = newAr; | 759 | (*data->child) = newAr; |
576 | } | 760 | } |
577 | struct OEffectiveEvent::Data : public QShared { | 761 | |
578 | Data() : QShared() { | 762 | |
579 | } | 763 | struct OEffectiveEvent::Data : public QShared |
764 | { | ||
765 | Data() : QShared() | ||
766 | {} | ||
580 | OEvent event; | 767 | OEvent event; |
581 | QDate date; | 768 | QDate date; |
@@ -585,5 +772,7 @@ struct OEffectiveEvent::Data : public QShared { | |||
585 | }; | 772 | }; |
586 | 773 | ||
587 | OEffectiveEvent::OEffectiveEvent() { | 774 | |
775 | OEffectiveEvent::OEffectiveEvent() | ||
776 | { | ||
588 | data = new Data; | 777 | data = new Data; |
589 | data->date = QDate::currentDate(); | 778 | data->date = QDate::currentDate(); |
@@ -591,6 +780,9 @@ OEffectiveEvent::OEffectiveEvent() { | |||
591 | data->dates = false; | 780 | data->dates = false; |
592 | } | 781 | } |
782 | |||
783 | |||
593 | OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, | 784 | OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, |
594 | Position pos ) { | 785 | Position pos ) |
786 | { | ||
595 | data = new Data; | 787 | data = new Data; |
596 | data->event = ev; | 788 | data->event = ev; |
@@ -608,15 +800,25 @@ OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, | |||
608 | data->dates = false; | 800 | data->dates = false; |
609 | } | 801 | } |
610 | OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { | 802 | |
803 | |||
804 | OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) | ||
805 | { | ||
611 | data = ev.data; | 806 | data = ev.data; |
612 | data->ref(); | 807 | data->ref(); |
613 | } | 808 | } |
614 | OEffectiveEvent::~OEffectiveEvent() { | 809 | |
615 | if ( data->deref() ) { | 810 | |
811 | OEffectiveEvent::~OEffectiveEvent() | ||
812 | { | ||
813 | if ( data->deref() ) | ||
814 | { | ||
616 | delete data; | 815 | delete data; |
617 | data = 0; | 816 | data = 0; |
618 | } | 817 | } |
619 | } | 818 | } |
620 | OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { | 819 | |
820 | |||
821 | OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) | ||
822 | { | ||
621 | if ( *this == ev ) return *this; | 823 | if ( *this == ev ) return *this; |
622 | 824 | ||
@@ -628,23 +830,38 @@ OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { | |||
628 | } | 830 | } |
629 | 831 | ||
630 | void OEffectiveEvent::setStartTime( const QTime& ti) { | 832 | |
833 | void OEffectiveEvent::setStartTime( const QTime& ti ) | ||
834 | { | ||
631 | changeOrModify(); | 835 | changeOrModify(); |
632 | data->start = ti; | 836 | data->start = ti; |
633 | } | 837 | } |
634 | void OEffectiveEvent::setEndTime( const QTime& en) { | 838 | |
839 | |||
840 | void OEffectiveEvent::setEndTime( const QTime& en ) | ||
841 | { | ||
635 | changeOrModify(); | 842 | changeOrModify(); |
636 | data->end = en; | 843 | data->end = en; |
637 | } | 844 | } |
638 | void OEffectiveEvent::setEvent( const OEvent& ev) { | 845 | |
846 | |||
847 | void OEffectiveEvent::setEvent( const OEvent& ev ) | ||
848 | { | ||
639 | changeOrModify(); | 849 | changeOrModify(); |
640 | data->event = ev; | 850 | data->event = ev; |
641 | } | 851 | } |
642 | void OEffectiveEvent::setDate( const QDate& da) { | 852 | |
853 | |||
854 | void OEffectiveEvent::setDate( const QDate& da ) | ||
855 | { | ||
643 | changeOrModify(); | 856 | changeOrModify(); |
644 | data->date = da; | 857 | data->date = da; |
645 | } | 858 | } |
859 | |||
860 | |||
646 | void OEffectiveEvent::setEffectiveDates( const QDate& from, | 861 | void OEffectiveEvent::setEffectiveDates( const QDate& from, |
647 | const QDate& to ) { | 862 | const QDate& to ) |
648 | if (!from.isValid() ) { | 863 | { |
864 | if ( !from.isValid() ) | ||
865 | { | ||
649 | data->dates = false; | 866 | data->dates = false; |
650 | return; | 867 | return; |
@@ -654,35 +871,65 @@ void OEffectiveEvent::setEffectiveDates( const QDate& from, | |||
654 | data->endDate = to; | 871 | data->endDate = to; |
655 | } | 872 | } |
656 | QString OEffectiveEvent::description()const { | 873 | |
874 | |||
875 | QString OEffectiveEvent::description() const | ||
876 | { | ||
657 | return data->event.description(); | 877 | return data->event.description(); |
658 | } | 878 | } |
659 | QString OEffectiveEvent::location()const { | 879 | |
880 | |||
881 | QString OEffectiveEvent::location() const | ||
882 | { | ||
660 | return data->event.location(); | 883 | return data->event.location(); |
661 | } | 884 | } |
662 | QString OEffectiveEvent::note()const { | 885 | |
886 | |||
887 | QString OEffectiveEvent::note() const | ||
888 | { | ||
663 | return data->event.note(); | 889 | return data->event.note(); |
664 | } | 890 | } |
665 | OEvent OEffectiveEvent::event()const { | 891 | |
892 | |||
893 | OEvent OEffectiveEvent::event() const | ||
894 | { | ||
666 | return data->event; | 895 | return data->event; |
667 | } | 896 | } |
668 | QTime OEffectiveEvent::startTime()const { | 897 | |
898 | |||
899 | QTime OEffectiveEvent::startTime() const | ||
900 | { | ||
669 | return data->start; | 901 | return data->start; |
670 | } | 902 | } |
671 | QTime OEffectiveEvent::endTime()const { | 903 | |
904 | |||
905 | QTime OEffectiveEvent::endTime() const | ||
906 | { | ||
672 | return data->end; | 907 | return data->end; |
673 | } | 908 | } |
674 | QDate OEffectiveEvent::date()const { | 909 | |
910 | |||
911 | QDate OEffectiveEvent::date() const | ||
912 | { | ||
675 | return data->date; | 913 | return data->date; |
676 | } | 914 | } |
677 | int OEffectiveEvent::length()const { | 915 | |
916 | |||
917 | int OEffectiveEvent::length() const | ||
918 | { | ||
678 | return (data->end.hour() * 60 - data->start.hour() * 60) | 919 | return (data->end.hour() * 60 - data->start.hour() * 60) |
679 | + QABS(data->start.minute() - data->end.minute() ); | 920 | + QABS(data->start.minute() - data->end.minute() ); |
680 | } | 921 | } |
681 | int OEffectiveEvent::size()const { | 922 | |
923 | |||
924 | int OEffectiveEvent::size() const | ||
925 | { | ||
682 | return ( data->end.hour() - data->start.hour() ) * 3600 | 926 | return ( data->end.hour() - data->start.hour() ) * 3600 |
683 | + (data->end.minute() - data->start.minute() * 60 | 927 | + (data->end.minute() - data->start.minute() * 60 |
684 | + data->end.second() - data->start.second() ); | 928 | + data->end.second() - data->start.second() ); |
685 | } | 929 | } |
686 | QDate OEffectiveEvent::startDate()const { | 930 | |
931 | |||
932 | QDate OEffectiveEvent::startDate() const | ||
933 | { | ||
687 | if ( data->dates ) | 934 | if ( data->dates ) |
688 | return data->startDate; | 935 | return data->startDate; |
@@ -692,5 +939,8 @@ QDate OEffectiveEvent::startDate()const { | |||
692 | return data->event.startDateTime().date(); | 939 | return data->event.startDateTime().date(); |
693 | } | 940 | } |
694 | QDate OEffectiveEvent::endDate()const { | 941 | |
942 | |||
943 | QDate OEffectiveEvent::endDate() const | ||
944 | { | ||
695 | if ( data->dates ) | 945 | if ( data->dates ) |
696 | return data->endDate; | 946 | return data->endDate; |
@@ -700,12 +950,20 @@ QDate OEffectiveEvent::endDate()const { | |||
700 | return data->event.endDateTime().date(); | 950 | return data->event.endDateTime().date(); |
701 | } | 951 | } |
702 | void OEffectiveEvent::deref() { | 952 | |
703 | if ( data->deref() ) { | 953 | |
954 | void OEffectiveEvent::deref() | ||
955 | { | ||
956 | if ( data->deref() ) | ||
957 | { | ||
704 | delete data; | 958 | delete data; |
705 | data = 0; | 959 | data = 0; |
706 | } | 960 | } |
707 | } | 961 | } |
708 | void OEffectiveEvent::changeOrModify() { | 962 | |
709 | if ( data->count != 1 ) { | 963 | |
964 | void OEffectiveEvent::changeOrModify() | ||
965 | { | ||
966 | if ( data->count != 1 ) | ||
967 | { | ||
710 | data->deref(); | 968 | data->deref(); |
711 | Data* d2 = new Data; | 969 | Data* d2 = new Data; |
@@ -720,5 +978,8 @@ void OEffectiveEvent::changeOrModify() { | |||
720 | } | 978 | } |
721 | } | 979 | } |
722 | bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ | 980 | |
981 | |||
982 | bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const | ||
983 | { | ||
723 | if ( data->date < e.date() ) | 984 | if ( data->date < e.date() ) |
724 | return TRUE; | 985 | return TRUE; |
@@ -728,8 +989,14 @@ bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ | |||
728 | return FALSE; | 989 | return FALSE; |
729 | } | 990 | } |
730 | bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ | 991 | |
992 | |||
993 | bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const | ||
994 | { | ||
731 | return (data->date <= e.date() ); | 995 | return (data->date <= e.date() ); |
732 | } | 996 | } |
733 | bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { | 997 | |
998 | |||
999 | bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const | ||
1000 | { | ||
734 | return ( date() == e.date() | 1001 | return ( date() == e.date() |
735 | && startTime() == e.startTime() | 1002 | && startTime() == e.startTime() |
@@ -737,11 +1004,20 @@ bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { | |||
737 | && event() == e.event() ); | 1004 | && event() == e.event() ); |
738 | } | 1005 | } |
739 | bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { | 1006 | |
1007 | |||
1008 | bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const | ||
1009 | { | ||
740 | return !(*this == e ); | 1010 | return !(*this == e ); |
741 | } | 1011 | } |
742 | bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { | 1012 | |
1013 | |||
1014 | bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const | ||
1015 | { | ||
743 | return !(*this <= e ); | 1016 | return !(*this <= e ); |
744 | } | 1017 | } |
745 | bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { | 1018 | |
1019 | |||
1020 | bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const | ||
1021 | { | ||
746 | return !(*this < e); | 1022 | return !(*this < e); |
747 | } | 1023 | } |