-rw-r--r-- | libopie/pim/oevent.cpp | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp index ada596c..c3eeee2 100644 --- a/libopie/pim/oevent.cpp +++ b/libopie/pim/oevent.cpp | |||
@@ -39,15 +39,17 @@ int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { | |||
39 | return ( second.year() - first.year() ) * 12 + | 39 | return ( second.year() - first.year() ) * 12 + |
40 | second.month() - first.month(); | 40 | second.month() - first.month(); |
41 | } | 41 | } |
42 | 42 | ||
43 | struct OEvent::Data : public QShared { | 43 | struct OEvent::Data : public QShared { |
44 | Data() : QShared() { | 44 | Data() : QShared() { |
45 | child = 0; | ||
45 | recur = 0; | 46 | recur = 0; |
46 | manager = 0; | 47 | manager = 0; |
47 | isAllDay = false; | 48 | isAllDay = false; |
49 | parent = 0; | ||
48 | } | 50 | } |
49 | ~Data() { | 51 | ~Data() { |
50 | delete manager; | 52 | delete manager; |
51 | delete recur; | 53 | delete recur; |
52 | } | 54 | } |
53 | QString description; | 55 | QString description; |
@@ -57,12 +59,14 @@ struct OEvent::Data : public QShared { | |||
57 | QString note; | 59 | QString note; |
58 | QDateTime created; | 60 | QDateTime created; |
59 | QDateTime start; | 61 | QDateTime start; |
60 | QDateTime end; | 62 | QDateTime end; |
61 | bool isAllDay : 1; | 63 | bool isAllDay : 1; |
62 | QString timezone; | 64 | QString timezone; |
65 | QArray<int>* child; | ||
66 | int parent; | ||
63 | }; | 67 | }; |
64 | 68 | ||
65 | OEvent::OEvent( int uid ) | 69 | OEvent::OEvent( int uid ) |
66 | : OPimRecord( uid ) { | 70 | : OPimRecord( uid ) { |
67 | data = new Data; | 71 | data = new Data; |
68 | } | 72 | } |
@@ -99,23 +103,29 @@ void OEvent::setLocation( const QString& loc ) { | |||
99 | changeOrModify(); | 103 | changeOrModify(); |
100 | data->location = loc; | 104 | data->location = loc; |
101 | } | 105 | } |
102 | QString OEvent::location()const { | 106 | QString OEvent::location()const { |
103 | return data->location; | 107 | return data->location; |
104 | } | 108 | } |
105 | OPimNotifyManager &OEvent::notifiers() { | 109 | OPimNotifyManager &OEvent::notifiers()const { |
106 | // I hope we can skip the changeOrModify here | 110 | // I hope we can skip the changeOrModify here |
107 | // the notifier should take care of it | 111 | // the notifier should take care of it |
108 | // and OPimNotify is shared too | 112 | // and OPimNotify is shared too |
109 | if (!data->manager ) | 113 | if (!data->manager ) |
110 | data->manager = new OPimNotifyManager; | 114 | data->manager = new OPimNotifyManager; |
111 | 115 | ||
112 | return *data->manager; | 116 | return *data->manager; |
113 | } | 117 | } |
114 | bool OEvent::hasNotifiers()const { | 118 | bool OEvent::hasNotifiers()const { |
115 | return ( data->manager); | 119 | if (!data->manager ) |
120 | return false; | ||
121 | if (data->manager->reminders().isEmpty() && | ||
122 | data->manager->alarms().isEmpty() ) | ||
123 | return false; | ||
124 | |||
125 | return true; | ||
116 | } | 126 | } |
117 | ORecur OEvent::recurrence()const { | 127 | ORecur OEvent::recurrence()const { |
118 | if (!data->recur) | 128 | if (!data->recur) |
119 | data->recur = new ORecur; | 129 | data->recur = new ORecur; |
120 | 130 | ||
121 | return *data->recur; | 131 | return *data->recur; |
@@ -194,12 +204,13 @@ void OEvent::setAllDay( bool allDay ) { | |||
194 | } | 204 | } |
195 | void OEvent::setTimeZone( const QString& tz ) { | 205 | void OEvent::setTimeZone( const QString& tz ) { |
196 | changeOrModify(); | 206 | changeOrModify(); |
197 | data->timezone = tz; | 207 | data->timezone = tz; |
198 | } | 208 | } |
199 | QString OEvent::timeZone()const { | 209 | QString OEvent::timeZone()const { |
210 | if (data->isAllDay ) return QString::fromLatin1("UTC"); | ||
200 | return data->timezone; | 211 | return data->timezone; |
201 | } | 212 | } |
202 | bool OEvent::match( const QRegExp& )const { | 213 | bool OEvent::match( const QRegExp& )const { |
203 | // FIXME | 214 | // FIXME |
204 | return false; | 215 | return false; |
205 | } | 216 | } |
@@ -236,12 +247,17 @@ void OEvent::changeOrModify() { | |||
236 | d2->note = data->note; | 247 | d2->note = data->note; |
237 | d2->created = data->created; | 248 | d2->created = data->created; |
238 | d2->start = data->start; | 249 | d2->start = data->start; |
239 | d2->end = data->end; | 250 | d2->end = data->end; |
240 | d2->isAllDay = data->isAllDay; | 251 | d2->isAllDay = data->isAllDay; |
241 | d2->timezone = data->timezone; | 252 | d2->timezone = data->timezone; |
253 | d2->parent = data->parent; | ||
254 | d2->child = data->child; | ||
255 | |||
256 | if (d2->child ) | ||
257 | d2->child->detach(); | ||
242 | 258 | ||
243 | data = d2; | 259 | data = d2; |
244 | } | 260 | } |
245 | } | 261 | } |
246 | void OEvent::deref() { | 262 | void OEvent::deref() { |
247 | if ( data->deref() ) { | 263 | if ( data->deref() ) { |
@@ -253,14 +269,56 @@ void OEvent::deref() { | |||
253 | QMap<int, QString> OEvent::toMap()const { | 269 | QMap<int, QString> OEvent::toMap()const { |
254 | return QMap<int, QString>(); | 270 | return QMap<int, QString>(); |
255 | } | 271 | } |
256 | QMap<QString, QString> OEvent::toExtraMap()const { | 272 | QMap<QString, QString> OEvent::toExtraMap()const { |
257 | return QMap<QString, QString>(); | 273 | return QMap<QString, QString>(); |
258 | } | 274 | } |
275 | int OEvent::parent()const { | ||
276 | return data->parent; | ||
277 | } | ||
278 | void OEvent::setParent( int uid ) { | ||
279 | changeOrModify(); | ||
280 | data->parent = uid; | ||
281 | } | ||
282 | QArray<int> OEvent::children() const{ | ||
283 | if (!data->child) return QArray<int>(); | ||
284 | else | ||
285 | return data->child->copy(); | ||
286 | } | ||
287 | void OEvent::setChildren( const QArray<int>& arr ) { | ||
288 | changeOrModify(); | ||
289 | if (data->child) delete data->child; | ||
259 | 290 | ||
260 | 291 | data->child = new QArray<int>( arr ); | |
292 | data->child->detach(); | ||
293 | } | ||
294 | void OEvent::addChild( int uid ) { | ||
295 | changeOrModify(); | ||
296 | if (!data->child ) { | ||
297 | data->child = new QArray<int>(1); | ||
298 | (*data->child)[0] = uid; | ||
299 | }else{ | ||
300 | int count = data->child->count(); | ||
301 | data->child->resize( count + 1 ); | ||
302 | (*data->child)[count] = uid; | ||
303 | } | ||
304 | } | ||
305 | void OEvent::removeChild( int uid ) { | ||
306 | if (!data->child || !data->child->contains( uid ) ) return; | ||
307 | changeOrModify(); | ||
308 | QArray<int> newAr( data->child->count() - 1 ); | ||
309 | int j = 0; | ||
310 | uint count = data->child->count(); | ||
311 | for ( uint i = 0; i < count; i++ ) { | ||
312 | if ( (*data->child)[i] != uid ) { | ||
313 | newAr[j] = (*data->child)[i]; | ||
314 | j++; | ||
315 | } | ||
316 | } | ||
317 | (*data->child) = newAr; | ||
318 | } | ||
261 | struct OEffectiveEvent::Data : public QShared { | 319 | struct OEffectiveEvent::Data : public QShared { |
262 | Data() : QShared() { | 320 | Data() : QShared() { |
263 | } | 321 | } |
264 | OEvent event; | 322 | OEvent event; |
265 | QDate date; | 323 | QDate date; |
266 | QTime start, end; | 324 | QTime start, end; |