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