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