summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-12-08 15:56:09 (UTC)
committer mickeyl <mickeyl>2003-12-08 15:56:09 (UTC)
commit466d396717be9ec10bdc1472bce5e733cd268ce4 (patch) (unidiff)
tree29490045306e1241ba315d789cfb6632e20587dd
parent8753d6a11a4e837df09f4fb2474cfae84d28320a (diff)
downloadopie-466d396717be9ec10bdc1472bce5e733cd268ce4.zip
opie-466d396717be9ec10bdc1472bce5e733cd268ce4.tar.gz
opie-466d396717be9ec10bdc1472bce5e733cd268ce4.tar.bz2
work around sucky gcc2, which doesn't understand when the two arguments
for ? need an implicit type conversion
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/oevent.cpp2
-rw-r--r--libopie2/opiepim/oevent.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp
index c916297..ec05e77 100644
--- a/libopie/pim/oevent.cpp
+++ b/libopie/pim/oevent.cpp
@@ -1,704 +1,704 @@
1#include <qshared.h> 1#include <qshared.h>
2#include <qarray.h> 2#include <qarray.h>
3 3
4#include <qpe/palmtopuidgen.h> 4#include <qpe/palmtopuidgen.h>
5#include <qpe/categories.h> 5#include <qpe/categories.h>
6#include <qpe/stringutil.h> 6#include <qpe/stringutil.h>
7 7
8#include "orecur.h" 8#include "orecur.h"
9#include "opimresolver.h" 9#include "opimresolver.h"
10#include "opimnotifymanager.h" 10#include "opimnotifymanager.h"
11 11
12#include "oevent.h" 12#include "oevent.h"
13 13
14int OCalendarHelper::week( const QDate& date) { 14int OCalendarHelper::week( const QDate& date) {
15 // Calculates the week this date is in within that 15 // Calculates the week this date is in within that
16 // month. Equals the "row" is is in in the month view 16 // month. Equals the "row" is is in in the month view
17 int week = 1; 17 int week = 1;
18 QDate tmp( date.year(), date.month(), 1 ); 18 QDate tmp( date.year(), date.month(), 1 );
19 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 19 if ( date.dayOfWeek() < tmp.dayOfWeek() )
20 ++week; 20 ++week;
21 21
22 week += ( date.day() - 1 ) / 7; 22 week += ( date.day() - 1 ) / 7;
23 23
24 return week; 24 return week;
25} 25}
26int OCalendarHelper::ocurrence( const QDate& date) { 26int OCalendarHelper::ocurrence( const QDate& date) {
27 // calculates the number of occurrances of this day of the 27 // calculates the number of occurrances of this day of the
28 // week till the given date (e.g 3rd Wednesday of the month) 28 // week till the given date (e.g 3rd Wednesday of the month)
29 return ( date.day() - 1 ) / 7 + 1; 29 return ( date.day() - 1 ) / 7 + 1;
30} 30}
31int OCalendarHelper::dayOfWeek( char day ) { 31int OCalendarHelper::dayOfWeek( char day ) {
32 int dayOfWeek = 1; 32 int dayOfWeek = 1;
33 char i = ORecur::MON; 33 char i = ORecur::MON;
34 while ( !( i & day ) && i <= ORecur::SUN ) { 34 while ( !( i & day ) && i <= ORecur::SUN ) {
35 i <<= 1; 35 i <<= 1;
36 ++dayOfWeek; 36 ++dayOfWeek;
37 } 37 }
38 return dayOfWeek; 38 return dayOfWeek;
39} 39}
40int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 40int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
41 return ( second.year() - first.year() ) * 12 + 41 return ( second.year() - first.year() ) * 12 +
42 second.month() - first.month(); 42 second.month() - first.month();
43} 43}
44 44
45struct OEvent::Data : public QShared { 45struct OEvent::Data : public QShared {
46 Data() : QShared() { 46 Data() : QShared() {
47 child = 0; 47 child = 0;
48 recur = 0; 48 recur = 0;
49 manager = 0; 49 manager = 0;
50 isAllDay = false; 50 isAllDay = false;
51 parent = 0; 51 parent = 0;
52 } 52 }
53 ~Data() { 53 ~Data() {
54 delete manager; 54 delete manager;
55 delete recur; 55 delete recur;
56 } 56 }
57 QString description; 57 QString description;
58 QString location; 58 QString location;
59 OPimNotifyManager* manager; 59 OPimNotifyManager* manager;
60 ORecur* recur; 60 ORecur* recur;
61 QString note; 61 QString note;
62 QDateTime created; 62 QDateTime created;
63 QDateTime start; 63 QDateTime start;
64 QDateTime end; 64 QDateTime end;
65 bool isAllDay : 1; 65 bool isAllDay : 1;
66 QString timezone; 66 QString timezone;
67 QArray<int>* child; 67 QArray<int>* child;
68 int parent; 68 int parent;
69}; 69};
70 70
71OEvent::OEvent( int uid ) 71OEvent::OEvent( int uid )
72 : OPimRecord( uid ) { 72 : OPimRecord( uid ) {
73 data = new Data; 73 data = new Data;
74} 74}
75OEvent::OEvent( const OEvent& ev) 75OEvent::OEvent( const OEvent& ev)
76 : OPimRecord( ev ), data( ev.data ) 76 : OPimRecord( ev ), data( ev.data )
77{ 77{
78 data->ref(); 78 data->ref();
79} 79}
80OEvent::~OEvent() { 80OEvent::~OEvent() {
81 if ( data->deref() ) { 81 if ( data->deref() ) {
82 delete data; 82 delete data;
83 data = 0; 83 data = 0;
84 } 84 }
85} 85}
86OEvent& OEvent::operator=( const OEvent& ev) { 86OEvent& OEvent::operator=( const OEvent& ev) {
87 if ( this == &ev ) return *this; 87 if ( this == &ev ) return *this;
88 88
89 OPimRecord::operator=( ev ); 89 OPimRecord::operator=( ev );
90 ev.data->ref(); 90 ev.data->ref();
91 deref(); 91 deref();
92 data = ev.data; 92 data = ev.data;
93 93
94 94
95 return *this; 95 return *this;
96} 96}
97QString OEvent::description()const { 97QString OEvent::description()const {
98 return data->description; 98 return data->description;
99} 99}
100void OEvent::setDescription( const QString& description ) { 100void OEvent::setDescription( const QString& description ) {
101 changeOrModify(); 101 changeOrModify();
102 data->description = description; 102 data->description = description;
103} 103}
104void OEvent::setLocation( const QString& loc ) { 104void OEvent::setLocation( const QString& loc ) {
105 changeOrModify(); 105 changeOrModify();
106 data->location = loc; 106 data->location = loc;
107} 107}
108QString OEvent::location()const { 108QString OEvent::location()const {
109 return data->location; 109 return data->location;
110} 110}
111OPimNotifyManager &OEvent::notifiers()const { 111OPimNotifyManager &OEvent::notifiers()const {
112 // I hope we can skip the changeOrModify here 112 // I hope we can skip the changeOrModify here
113 // the notifier should take care of it 113 // the notifier should take care of it
114 // and OPimNotify is shared too 114 // and OPimNotify is shared too
115 if (!data->manager ) 115 if (!data->manager )
116 data->manager = new OPimNotifyManager; 116 data->manager = new OPimNotifyManager;
117 117
118 return *data->manager; 118 return *data->manager;
119} 119}
120bool OEvent::hasNotifiers()const { 120bool OEvent::hasNotifiers()const {
121 if (!data->manager ) 121 if (!data->manager )
122 return false; 122 return false;
123 if (data->manager->reminders().isEmpty() && 123 if (data->manager->reminders().isEmpty() &&
124 data->manager->alarms().isEmpty() ) 124 data->manager->alarms().isEmpty() )
125 return false; 125 return false;
126 126
127 return true; 127 return true;
128} 128}
129ORecur OEvent::recurrence()const { 129ORecur OEvent::recurrence()const {
130 if (!data->recur) 130 if (!data->recur)
131 data->recur = new ORecur; 131 data->recur = new ORecur;
132 132
133 return *data->recur; 133 return *data->recur;
134} 134}
135void OEvent::setRecurrence( const ORecur& rec) { 135void OEvent::setRecurrence( const ORecur& rec) {
136 changeOrModify(); 136 changeOrModify();
137 if (data->recur ) 137 if (data->recur )
138 (*data->recur) = rec; 138 (*data->recur) = rec;
139 else 139 else
140 data->recur = new ORecur( rec ); 140 data->recur = new ORecur( rec );
141} 141}
142bool OEvent::hasRecurrence()const { 142bool OEvent::hasRecurrence()const {
143 if (!data->recur ) return false; 143 if (!data->recur ) return false;
144 return data->recur->doesRecur(); 144 return data->recur->doesRecur();
145} 145}
146QString OEvent::note()const { 146QString OEvent::note()const {
147 return data->note; 147 return data->note;
148} 148}
149void OEvent::setNote( const QString& note ) { 149void OEvent::setNote( const QString& note ) {
150 changeOrModify(); 150 changeOrModify();
151 data->note = note; 151 data->note = note;
152} 152}
153QDateTime OEvent::createdDateTime()const { 153QDateTime OEvent::createdDateTime()const {
154 return data->created; 154 return data->created;
155} 155}
156void OEvent::setCreatedDateTime( const QDateTime& time ) { 156void OEvent::setCreatedDateTime( const QDateTime& time ) {
157 changeOrModify(); 157 changeOrModify();
158 data->created = time; 158 data->created = time;
159} 159}
160QDateTime OEvent::startDateTime()const { 160QDateTime OEvent::startDateTime()const {
161 if ( data->isAllDay ) 161 if ( data->isAllDay )
162 return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); 162 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
163 return data->start; 163 return data->start;
164} 164}
165QDateTime OEvent::startDateTimeInZone()const { 165QDateTime OEvent::startDateTimeInZone()const {
166 /* if no timezone, or all day event or if the current and this timeZone match... */ 166 /* if no timezone, or all day event or if the current and this timeZone match... */
167 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); 167 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
168 168
169 OTimeZone zone(data->timezone ); 169 OTimeZone zone(data->timezone );
170 return zone.toDateTime( data->start, OTimeZone::current() ); 170 return zone.toDateTime( data->start, OTimeZone::current() );
171} 171}
172void OEvent::setStartDateTime( const QDateTime& dt ) { 172void OEvent::setStartDateTime( const QDateTime& dt ) {
173 changeOrModify(); 173 changeOrModify();
174 data->start = dt; 174 data->start = dt;
175} 175}
176QDateTime OEvent::endDateTime()const { 176QDateTime OEvent::endDateTime()const {
177 /* 177 /*
178 * if all Day event the end time needs 178 * if all Day event the end time needs
179 * to be on the same day as the start 179 * to be on the same day as the start
180 */ 180 */
181 if ( data->isAllDay ) 181 if ( data->isAllDay )
182 return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); 182 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
183 return data->end; 183 return data->end;
184} 184}
185QDateTime OEvent::endDateTimeInZone()const { 185QDateTime OEvent::endDateTimeInZone()const {
186 /* if no timezone, or all day event or if the current and this timeZone match... */ 186 /* if no timezone, or all day event or if the current and this timeZone match... */
187 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); 187 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
188 188
189 OTimeZone zone(data->timezone ); 189 OTimeZone zone(data->timezone );
190 return zone.toDateTime( data->end, OTimeZone::current() ); 190 return zone.toDateTime( data->end, OTimeZone::current() );
191} 191}
192void OEvent::setEndDateTime( const QDateTime& dt ) { 192void OEvent::setEndDateTime( const QDateTime& dt ) {
193 changeOrModify(); 193 changeOrModify();
194 data->end = dt; 194 data->end = dt;
195} 195}
196bool OEvent::isMultipleDay()const { 196bool OEvent::isMultipleDay()const {
197 return data->end.date().day() - data->start.date().day(); 197 return data->end.date().day() - data->start.date().day();
198} 198}
199bool OEvent::isAllDay()const { 199bool OEvent::isAllDay()const {
200 return data->isAllDay; 200 return data->isAllDay;
201} 201}
202void OEvent::setAllDay( bool allDay ) { 202void OEvent::setAllDay( bool allDay ) {
203 changeOrModify(); 203 changeOrModify();
204 data->isAllDay = allDay; 204 data->isAllDay = allDay;
205 if (allDay ) data->timezone = "UTC"; 205 if (allDay ) data->timezone = "UTC";
206} 206}
207void OEvent::setTimeZone( const QString& tz ) { 207void OEvent::setTimeZone( const QString& tz ) {
208 changeOrModify(); 208 changeOrModify();
209 data->timezone = tz; 209 data->timezone = tz;
210} 210}
211QString OEvent::timeZone()const { 211QString OEvent::timeZone()const {
212 if (data->isAllDay ) return QString::fromLatin1("UTC"); 212 if (data->isAllDay ) return QString::fromLatin1("UTC");
213 return data->timezone; 213 return data->timezone;
214} 214}
215bool OEvent::match( const QRegExp& re )const { 215bool OEvent::match( const QRegExp& re )const {
216 if ( re.match( data->description ) != -1 ){ 216 if ( re.match( data->description ) != -1 ){
217 setLastHitField( Qtopia::DatebookDescription ); 217 setLastHitField( Qtopia::DatebookDescription );
218 return true; 218 return true;
219 } 219 }
220 if ( re.match( data->note ) != -1 ){ 220 if ( re.match( data->note ) != -1 ){
221 setLastHitField( Qtopia::Note ); 221 setLastHitField( Qtopia::Note );
222 return true; 222 return true;
223 } 223 }
224 if ( re.match( data->location ) != -1 ){ 224 if ( re.match( data->location ) != -1 ){
225 setLastHitField( Qtopia::Location ); 225 setLastHitField( Qtopia::Location );
226 return true; 226 return true;
227 } 227 }
228 if ( re.match( data->start.toString() ) != -1 ){ 228 if ( re.match( data->start.toString() ) != -1 ){
229 setLastHitField( Qtopia::StartDateTime ); 229 setLastHitField( Qtopia::StartDateTime );
230 return true; 230 return true;
231 } 231 }
232 if ( re.match( data->end.toString() ) != -1 ){ 232 if ( re.match( data->end.toString() ) != -1 ){
233 setLastHitField( Qtopia::EndDateTime ); 233 setLastHitField( Qtopia::EndDateTime );
234 return true; 234 return true;
235 } 235 }
236 return false; 236 return false;
237} 237}
238QString OEvent::toRichText()const { 238QString OEvent::toRichText()const {
239 QString text, value; 239 QString text, value;
240 240
241 // description 241 // description
242 text += "<b><h3><img src=\"datebook/DateBook\">"; 242 text += "<b><h3><img src=\"datebook/DateBook\">";
243 if ( !description().isEmpty() ) { 243 if ( !description().isEmpty() ) {
244 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" ); 244 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" );
245 } 245 }
246 text += "</h3></b><br><hr><br>"; 246 text += "</h3></b><br><hr><br>";
247 247
248 // location 248 // location
249 if ( !(value = location()).isEmpty() ) { 249 if ( !(value = location()).isEmpty() ) {
250 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 250 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
251 text += Qtopia::escapeString(value) + "<br>"; 251 text += Qtopia::escapeString(value) + "<br>";
252 } 252 }
253 253
254 // all day event 254 // all day event
255 if ( isAllDay() ) { 255 if ( isAllDay() ) {
256 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 256 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
257 } 257 }
258 // multiple day event 258 // multiple day event
259 else if ( isMultipleDay () ) { 259 else if ( isMultipleDay () ) {
260 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 260 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
261 } 261 }
262 // start & end times 262 // start & end times
263 else { 263 else {
264 // start time 264 // start time
265 if ( startDateTime().isValid() ) { 265 if ( startDateTime().isValid() ) {
266 text += "<b>" + QObject::tr( "Start:") + "</b> "; 266 text += "<b>" + QObject::tr( "Start:") + "</b> ";
267 text += Qtopia::escapeString(startDateTime().toString() ). 267 text += Qtopia::escapeString(startDateTime().toString() ).
268 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 268 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
269 } 269 }
270 270
271 // end time 271 // end time
272 if ( endDateTime().isValid() ) { 272 if ( endDateTime().isValid() ) {
273 text += "<b>" + QObject::tr( "End:") + "</b> "; 273 text += "<b>" + QObject::tr( "End:") + "</b> ";
274 text += Qtopia::escapeString(endDateTime().toString() ). 274 text += Qtopia::escapeString(endDateTime().toString() ).
275 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 275 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
276 } 276 }
277 } 277 }
278 278
279 // categories 279 // categories
280 if ( categoryNames("Calendar").count() ){ 280 if ( categoryNames("Calendar").count() ){
281 text += "<b>" + QObject::tr( "Category:") + "</b> "; 281 text += "<b>" + QObject::tr( "Category:") + "</b> ";
282 text += categoryNames("Calendar").join(", "); 282 text += categoryNames("Calendar").join(", ");
283 text += "<br>"; 283 text += "<br>";
284 } 284 }
285 285
286 //notes 286 //notes
287 if ( !note().isEmpty() ) { 287 if ( !note().isEmpty() ) {
288 text += "<b>" + QObject::tr( "Note:") + "</b><br>"; 288 text += "<b>" + QObject::tr( "Note:") + "</b><br>";
289 text += note(); 289 text += note();
290// text += Qtopia::escapeString(note() ). 290// text += Qtopia::escapeString(note() ).
291// replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 291// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
292 } 292 }
293 return text; 293 return text;
294} 294}
295QString OEvent::toShortText()const { 295QString OEvent::toShortText()const {
296 QString text; 296 QString text;
297 text += QString::number( startDateTime().date().day() ); 297 text += QString::number( startDateTime().date().day() );
298 text += "."; 298 text += ".";
299 text += QString::number( startDateTime().date().month() ); 299 text += QString::number( startDateTime().date().month() );
300 text += "."; 300 text += ".";
301 text += QString::number( startDateTime().date().year() ); 301 text += QString::number( startDateTime().date().year() );
302 text += " "; 302 text += " ";
303 text += QString::number( startDateTime().time().hour() ); 303 text += QString::number( startDateTime().time().hour() );
304 text += ":"; 304 text += ":";
305 text += QString::number( startDateTime().time().minute() ); 305 text += QString::number( startDateTime().time().minute() );
306 text += " - "; 306 text += " - ";
307 text += description(); 307 text += description();
308 return text; 308 return text;
309} 309}
310QString OEvent::type()const { 310QString OEvent::type()const {
311 return QString::fromLatin1("OEvent"); 311 return QString::fromLatin1("OEvent");
312} 312}
313QString OEvent::recordField( int /*id */ )const { 313QString OEvent::recordField( int /*id */ )const {
314 return QString::null; 314 return QString::null;
315} 315}
316int OEvent::rtti() { 316int OEvent::rtti() {
317 return OPimResolver::DateBook; 317 return OPimResolver::DateBook;
318} 318}
319bool OEvent::loadFromStream( QDataStream& ) { 319bool OEvent::loadFromStream( QDataStream& ) {
320 return true; 320 return true;
321} 321}
322bool OEvent::saveToStream( QDataStream& )const { 322bool OEvent::saveToStream( QDataStream& )const {
323 return true; 323 return true;
324} 324}
325void OEvent::changeOrModify() { 325void OEvent::changeOrModify() {
326 if ( data->count != 1 ) { 326 if ( data->count != 1 ) {
327 data->deref(); 327 data->deref();
328 Data* d2 = new Data; 328 Data* d2 = new Data;
329 d2->description = data->description; 329 d2->description = data->description;
330 d2->location = data->location; 330 d2->location = data->location;
331 331
332 if (data->manager ) 332 if (data->manager )
333 d2->manager = new OPimNotifyManager( *data->manager ); 333 d2->manager = new OPimNotifyManager( *data->manager );
334 334
335 if ( data->recur ) 335 if ( data->recur )
336 d2->recur = new ORecur( *data->recur ); 336 d2->recur = new ORecur( *data->recur );
337 337
338 d2->note = data->note; 338 d2->note = data->note;
339 d2->created = data->created; 339 d2->created = data->created;
340 d2->start = data->start; 340 d2->start = data->start;
341 d2->end = data->end; 341 d2->end = data->end;
342 d2->isAllDay = data->isAllDay; 342 d2->isAllDay = data->isAllDay;
343 d2->timezone = data->timezone; 343 d2->timezone = data->timezone;
344 d2->parent = data->parent; 344 d2->parent = data->parent;
345 345
346 if ( data->child ) { 346 if ( data->child ) {
347 d2->child = new QArray<int>( *data->child ); 347 d2->child = new QArray<int>( *data->child );
348 d2->child->detach(); 348 d2->child->detach();
349 } 349 }
350 350
351 data = d2; 351 data = d2;
352 } 352 }
353} 353}
354void OEvent::deref() { 354void OEvent::deref() {
355 if ( data->deref() ) { 355 if ( data->deref() ) {
356 delete data; 356 delete data;
357 data = 0; 357 data = 0;
358 } 358 }
359} 359}
360// Exporting Event data to map. Using the same 360// Exporting Event data to map. Using the same
361// encoding as ODateBookAccessBackend_xml does.. 361// encoding as ODateBookAccessBackend_xml does..
362// Thus, we could remove the stuff there and use this 362// Thus, we could remove the stuff there and use this
363// for it and for all other places.. 363// for it and for all other places..
364// Encoding should happen at one place, only ! (eilers) 364// Encoding should happen at one place, only ! (eilers)
365QMap<int, QString> OEvent::toMap()const { 365QMap<int, QString> OEvent::toMap()const {
366 QMap<int, QString> retMap; 366 QMap<int, QString> retMap;
367 367
368 retMap.insert( OEvent::FUid, QString::number( uid() ) ); 368 retMap.insert( OEvent::FUid, QString::number( uid() ) );
369 retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) )); 369 retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ));
370 retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) ); 370 retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) );
371 retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) ); 371 retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) );
372 retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" ); 372 retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" );
373 OPimAlarm alarm = notifiers().alarms()[0]; 373 OPimAlarm alarm = notifiers().alarms()[0];
374 retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 374 retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
375 retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" ); 375 retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" );
376 376
377 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); 377 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
378 retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OTimeZone::utc() ) ) ) ); 378 retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OTimeZone::utc() ) ) ) );
379 retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OTimeZone::utc() ) ) ) ); 379 retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OTimeZone::utc() ) ) ) );
380 retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) ); 380 retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) );
381 retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? "None" : timeZone() ); 381 retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
382 if( parent() ) 382 if( parent() )
383 retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); 383 retMap.insert( OEvent::FRecParent, QString::number( parent() ) );
384 if( children().count() ){ 384 if( children().count() ){
385 QArray<int> childr = children(); 385 QArray<int> childr = children();
386 QString buf; 386 QString buf;
387 for ( uint i = 0; i < childr.count(); i++ ) { 387 for ( uint i = 0; i < childr.count(); i++ ) {
388 if ( i != 0 ) buf += " "; 388 if ( i != 0 ) buf += " ";
389 buf += QString::number( childr[i] ); 389 buf += QString::number( childr[i] );
390 } 390 }
391 retMap.insert( OEvent::FRecChildren, buf ); 391 retMap.insert( OEvent::FRecChildren, buf );
392 } 392 }
393 393
394 // Add recurrence stuff 394 // Add recurrence stuff
395 if( hasRecurrence() ){ 395 if( hasRecurrence() ){
396 ORecur recur = recurrence(); 396 ORecur recur = recurrence();
397 QMap<int, QString> recFields = recur.toMap(); 397 QMap<int, QString> recFields = recur.toMap();
398 retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); 398 retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
399 retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] ); 399 retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] );
400 retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] ); 400 retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] );
401 retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] ); 401 retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] );
402 retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); 402 retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] );
403 retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); 403 retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
404 retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); 404 retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
405 retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); 405 retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
406 } 406 }
407 407
408 return retMap; 408 return retMap;
409} 409}
410 410
411void OEvent::fromMap( const QMap<int, QString>& map ) 411void OEvent::fromMap( const QMap<int, QString>& map )
412{ 412{
413 413
414 // We just want to set the UID if it is really stored. 414 // We just want to set the UID if it is really stored.
415 if ( !map[OEvent::FUid].isEmpty() ) 415 if ( !map[OEvent::FUid].isEmpty() )
416 setUid( map[OEvent::FUid].toInt() ); 416 setUid( map[OEvent::FUid].toInt() );
417 417
418 setCategories( idsFromString( map[OEvent::FCategories] ) ); 418 setCategories( idsFromString( map[OEvent::FCategories] ) );
419 setDescription( map[OEvent::FDescription] ); 419 setDescription( map[OEvent::FDescription] );
420 setLocation( map[OEvent::FLocation] ); 420 setLocation( map[OEvent::FLocation] );
421 421
422 if ( map[OEvent::FType] == "AllDay" ) 422 if ( map[OEvent::FType] == "AllDay" )
423 setAllDay( true ); 423 setAllDay( true );
424 else 424 else
425 setAllDay( false ); 425 setAllDay( false );
426 426
427 int alarmTime = -1; 427 int alarmTime = -1;
428 if( !map[OEvent::FAlarm].isEmpty() ) 428 if( !map[OEvent::FAlarm].isEmpty() )
429 alarmTime = map[OEvent::FAlarm].toInt(); 429 alarmTime = map[OEvent::FAlarm].toInt();
430 430
431 int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 431 int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
432 if ( ( alarmTime != -1 ) ){ 432 if ( ( alarmTime != -1 ) ){
433 QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); 433 QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 );
434 OPimAlarm al( sound , dt ); 434 OPimAlarm al( sound , dt );
435 notifiers().add( al ); 435 notifiers().add( al );
436 } 436 }
437 if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ 437 if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){
438 setTimeZone( map[OEvent::FTimeZone] ); 438 setTimeZone( map[OEvent::FTimeZone] );
439 } 439 }
440 440
441 time_t start = (time_t) map[OEvent::FStart].toLong(); 441 time_t start = (time_t) map[OEvent::FStart].toLong();
442 time_t end = (time_t) map[OEvent::FEnd].toLong(); 442 time_t end = (time_t) map[OEvent::FEnd].toLong();
443 443
444 /* AllDay is always in UTC */ 444 /* AllDay is always in UTC */
445 if ( isAllDay() ) { 445 if ( isAllDay() ) {
446 OTimeZone utc = OTimeZone::utc(); 446 OTimeZone utc = OTimeZone::utc();
447 setStartDateTime( utc.fromUTCDateTime( start ) ); 447 setStartDateTime( utc.fromUTCDateTime( start ) );
448 setEndDateTime ( utc.fromUTCDateTime( end ) ); 448 setEndDateTime ( utc.fromUTCDateTime( end ) );
449 setTimeZone( "UTC"); // make sure it is really utc 449 setTimeZone( "UTC"); // make sure it is really utc
450 }else { 450 }else {
451 /* to current date time */ 451 /* to current date time */
452 // qWarning(" Start is %d", start ); 452 // qWarning(" Start is %d", start );
453 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); 453 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
454 QDateTime date = zone.toDateTime( start ); 454 QDateTime date = zone.toDateTime( start );
455 qWarning(" Start is %s", date.toString().latin1() ); 455 qWarning(" Start is %s", date.toString().latin1() );
456 setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); 456 setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );
457 457
458 date = zone.toDateTime( end ); 458 date = zone.toDateTime( end );
459 setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); 459 setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) );
460 } 460 }
461 461
462 if ( !map[OEvent::FRecParent].isEmpty() ) 462 if ( !map[OEvent::FRecParent].isEmpty() )
463 setParent( map[OEvent::FRecParent].toInt() ); 463 setParent( map[OEvent::FRecParent].toInt() );
464 464
465 if ( !map[OEvent::FRecChildren].isEmpty() ){ 465 if ( !map[OEvent::FRecChildren].isEmpty() ){
466 QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); 466 QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] );
467 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 467 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
468 addChild( (*it).toInt() ); 468 addChild( (*it).toInt() );
469 } 469 }
470 } 470 }
471 471
472 // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. 472 // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap..
473 if( !map[OEvent::FRType].isEmpty() ){ 473 if( !map[OEvent::FRType].isEmpty() ){
474 QMap<int, QString> recFields; 474 QMap<int, QString> recFields;
475 recFields.insert( ORecur::RType, map[OEvent::FRType] ); 475 recFields.insert( ORecur::RType, map[OEvent::FRType] );
476 recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] ); 476 recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] );
477 recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] ); 477 recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] );
478 recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] ); 478 recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] );
479 recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] ); 479 recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] );
480 recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] ); 480 recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] );
481 recFields.insert( ORecur::Created, map[OEvent::FRCreated] ); 481 recFields.insert( ORecur::Created, map[OEvent::FRCreated] );
482 recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] ); 482 recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] );
483 ORecur recur( recFields ); 483 ORecur recur( recFields );
484 setRecurrence( recur ); 484 setRecurrence( recur );
485 } 485 }
486 486
487} 487}
488 488
489 489
490int OEvent::parent()const { 490int OEvent::parent()const {
491 return data->parent; 491 return data->parent;
492} 492}
493void OEvent::setParent( int uid ) { 493void OEvent::setParent( int uid ) {
494 changeOrModify(); 494 changeOrModify();
495 data->parent = uid; 495 data->parent = uid;
496} 496}
497QArray<int> OEvent::children() const{ 497QArray<int> OEvent::children() const{
498 if (!data->child) return QArray<int>(); 498 if (!data->child) return QArray<int>();
499 else 499 else
500 return data->child->copy(); 500 return data->child->copy();
501} 501}
502void OEvent::setChildren( const QArray<int>& arr ) { 502void OEvent::setChildren( const QArray<int>& arr ) {
503 changeOrModify(); 503 changeOrModify();
504 if (data->child) delete data->child; 504 if (data->child) delete data->child;
505 505
506 data->child = new QArray<int>( arr ); 506 data->child = new QArray<int>( arr );
507 data->child->detach(); 507 data->child->detach();
508} 508}
509void OEvent::addChild( int uid ) { 509void OEvent::addChild( int uid ) {
510 changeOrModify(); 510 changeOrModify();
511 if (!data->child ) { 511 if (!data->child ) {
512 data->child = new QArray<int>(1); 512 data->child = new QArray<int>(1);
513 (*data->child)[0] = uid; 513 (*data->child)[0] = uid;
514 }else{ 514 }else{
515 int count = data->child->count(); 515 int count = data->child->count();
516 data->child->resize( count + 1 ); 516 data->child->resize( count + 1 );
517 (*data->child)[count] = uid; 517 (*data->child)[count] = uid;
518 } 518 }
519} 519}
520void OEvent::removeChild( int uid ) { 520void OEvent::removeChild( int uid ) {
521 if (!data->child || !data->child->contains( uid ) ) return; 521 if (!data->child || !data->child->contains( uid ) ) return;
522 changeOrModify(); 522 changeOrModify();
523 QArray<int> newAr( data->child->count() - 1 ); 523 QArray<int> newAr( data->child->count() - 1 );
524 int j = 0; 524 int j = 0;
525 uint count = data->child->count(); 525 uint count = data->child->count();
526 for ( uint i = 0; i < count; i++ ) { 526 for ( uint i = 0; i < count; i++ ) {
527 if ( (*data->child)[i] != uid ) { 527 if ( (*data->child)[i] != uid ) {
528 newAr[j] = (*data->child)[i]; 528 newAr[j] = (*data->child)[i];
529 j++; 529 j++;
530 } 530 }
531 } 531 }
532 (*data->child) = newAr; 532 (*data->child) = newAr;
533} 533}
534struct OEffectiveEvent::Data : public QShared { 534struct OEffectiveEvent::Data : public QShared {
535 Data() : QShared() { 535 Data() : QShared() {
536 } 536 }
537 OEvent event; 537 OEvent event;
538 QDate date; 538 QDate date;
539 QTime start, end; 539 QTime start, end;
540 QDate startDate, endDate; 540 QDate startDate, endDate;
541 bool dates : 1; 541 bool dates : 1;
542}; 542};
543 543
544OEffectiveEvent::OEffectiveEvent() { 544OEffectiveEvent::OEffectiveEvent() {
545 data = new Data; 545 data = new Data;
546 data->date = QDate::currentDate(); 546 data->date = QDate::currentDate();
547 data->start = data->end = QTime::currentTime(); 547 data->start = data->end = QTime::currentTime();
548 data->dates = false; 548 data->dates = false;
549} 549}
550OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 550OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
551 Position pos ) { 551 Position pos ) {
552 data = new Data; 552 data = new Data;
553 data->event = ev; 553 data->event = ev;
554 data->date = startDate; 554 data->date = startDate;
555 if ( pos & Start ) 555 if ( pos & Start )
556 data->start = ev.startDateTime().time(); 556 data->start = ev.startDateTime().time();
557 else 557 else
558 data->start = QTime( 0, 0, 0 ); 558 data->start = QTime( 0, 0, 0 );
559 559
560 if ( pos & End ) 560 if ( pos & End )
561 data->end = ev.endDateTime().time(); 561 data->end = ev.endDateTime().time();
562 else 562 else
563 data->end = QTime( 23, 59, 59 ); 563 data->end = QTime( 23, 59, 59 );
564 564
565 data->dates = false; 565 data->dates = false;
566} 566}
567OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 567OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
568 data = ev.data; 568 data = ev.data;
569 data->ref(); 569 data->ref();
570} 570}
571OEffectiveEvent::~OEffectiveEvent() { 571OEffectiveEvent::~OEffectiveEvent() {
572 if ( data->deref() ) { 572 if ( data->deref() ) {
573 delete data; 573 delete data;
574 data = 0; 574 data = 0;
575 } 575 }
576} 576}
577OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 577OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
578 if ( *this == ev ) return *this; 578 if ( *this == ev ) return *this;
579 579
580 ev.data->ref(); 580 ev.data->ref();
581 deref(); 581 deref();
582 data = ev.data; 582 data = ev.data;
583 583
584 return *this; 584 return *this;
585} 585}
586 586
587void OEffectiveEvent::setStartTime( const QTime& ti) { 587void OEffectiveEvent::setStartTime( const QTime& ti) {
588 changeOrModify(); 588 changeOrModify();
589 data->start = ti; 589 data->start = ti;
590} 590}
591void OEffectiveEvent::setEndTime( const QTime& en) { 591void OEffectiveEvent::setEndTime( const QTime& en) {
592 changeOrModify(); 592 changeOrModify();
593 data->end = en; 593 data->end = en;
594} 594}
595void OEffectiveEvent::setEvent( const OEvent& ev) { 595void OEffectiveEvent::setEvent( const OEvent& ev) {
596 changeOrModify(); 596 changeOrModify();
597 data->event = ev; 597 data->event = ev;
598} 598}
599void OEffectiveEvent::setDate( const QDate& da) { 599void OEffectiveEvent::setDate( const QDate& da) {
600 changeOrModify(); 600 changeOrModify();
601 data->date = da; 601 data->date = da;
602} 602}
603void OEffectiveEvent::setEffectiveDates( const QDate& from, 603void OEffectiveEvent::setEffectiveDates( const QDate& from,
604 const QDate& to ) { 604 const QDate& to ) {
605 if (!from.isValid() ) { 605 if (!from.isValid() ) {
606 data->dates = false; 606 data->dates = false;
607 return; 607 return;
608 } 608 }
609 609
610 data->startDate = from; 610 data->startDate = from;
611 data->endDate = to; 611 data->endDate = to;
612} 612}
613QString OEffectiveEvent::description()const { 613QString OEffectiveEvent::description()const {
614 return data->event.description(); 614 return data->event.description();
615} 615}
616QString OEffectiveEvent::location()const { 616QString OEffectiveEvent::location()const {
617 return data->event.location(); 617 return data->event.location();
618} 618}
619QString OEffectiveEvent::note()const { 619QString OEffectiveEvent::note()const {
620 return data->event.note(); 620 return data->event.note();
621} 621}
622OEvent OEffectiveEvent::event()const { 622OEvent OEffectiveEvent::event()const {
623 return data->event; 623 return data->event;
624} 624}
625QTime OEffectiveEvent::startTime()const { 625QTime OEffectiveEvent::startTime()const {
626 return data->start; 626 return data->start;
627} 627}
628QTime OEffectiveEvent::endTime()const { 628QTime OEffectiveEvent::endTime()const {
629 return data->end; 629 return data->end;
630} 630}
631QDate OEffectiveEvent::date()const { 631QDate OEffectiveEvent::date()const {
632 return data->date; 632 return data->date;
633} 633}
634int OEffectiveEvent::length()const { 634int OEffectiveEvent::length()const {
635 return (data->end.hour() * 60 - data->start.hour() * 60) 635 return (data->end.hour() * 60 - data->start.hour() * 60)
636 + QABS(data->start.minute() - data->end.minute() ); 636 + QABS(data->start.minute() - data->end.minute() );
637} 637}
638int OEffectiveEvent::size()const { 638int OEffectiveEvent::size()const {
639 return ( data->end.hour() - data->start.hour() ) * 3600 639 return ( data->end.hour() - data->start.hour() ) * 3600
640 + (data->end.minute() - data->start.minute() * 60 640 + (data->end.minute() - data->start.minute() * 60
641 + data->end.second() - data->start.second() ); 641 + data->end.second() - data->start.second() );
642} 642}
643QDate OEffectiveEvent::startDate()const { 643QDate OEffectiveEvent::startDate()const {
644 if ( data->dates ) 644 if ( data->dates )
645 return data->startDate; 645 return data->startDate;
646 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 646 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
647 return data->date; 647 return data->date;
648 else 648 else
649 return data->event.startDateTime().date(); 649 return data->event.startDateTime().date();
650} 650}
651QDate OEffectiveEvent::endDate()const { 651QDate OEffectiveEvent::endDate()const {
652 if ( data->dates ) 652 if ( data->dates )
653 return data->endDate; 653 return data->endDate;
654 else if ( data->event.hasRecurrence() ) 654 else if ( data->event.hasRecurrence() )
655 return data->date; 655 return data->date;
656 else 656 else
657 return data->event.endDateTime().date(); 657 return data->event.endDateTime().date();
658} 658}
659void OEffectiveEvent::deref() { 659void OEffectiveEvent::deref() {
660 if ( data->deref() ) { 660 if ( data->deref() ) {
661 delete data; 661 delete data;
662 data = 0; 662 data = 0;
663 } 663 }
664} 664}
665void OEffectiveEvent::changeOrModify() { 665void OEffectiveEvent::changeOrModify() {
666 if ( data->count != 1 ) { 666 if ( data->count != 1 ) {
667 data->deref(); 667 data->deref();
668 Data* d2 = new Data; 668 Data* d2 = new Data;
669 d2->event = data->event; 669 d2->event = data->event;
670 d2->date = data->date; 670 d2->date = data->date;
671 d2->start = data->start; 671 d2->start = data->start;
672 d2->end = data->end; 672 d2->end = data->end;
673 d2->startDate = data->startDate; 673 d2->startDate = data->startDate;
674 d2->endDate = data->endDate; 674 d2->endDate = data->endDate;
675 d2->dates = data->dates; 675 d2->dates = data->dates;
676 data = d2; 676 data = d2;
677 } 677 }
678} 678}
679bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ 679bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
680 if ( data->date < e.date() ) 680 if ( data->date < e.date() )
681 return TRUE; 681 return TRUE;
682 if ( data->date == e.date() ) 682 if ( data->date == e.date() )
683 return ( startTime() < e.startTime() ); 683 return ( startTime() < e.startTime() );
684 else 684 else
685 return FALSE; 685 return FALSE;
686} 686}
687bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ 687bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
688 return (data->date <= e.date() ); 688 return (data->date <= e.date() );
689} 689}
690bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { 690bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
691 return ( date() == e.date() 691 return ( date() == e.date()
692 && startTime() == e.startTime() 692 && startTime() == e.startTime()
693 && endTime()== e.endTime() 693 && endTime()== e.endTime()
694 && event() == e.event() ); 694 && event() == e.event() );
695} 695}
696bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { 696bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
697 return !(*this == e ); 697 return !(*this == e );
698} 698}
699bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { 699bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
700 return !(*this <= e ); 700 return !(*this <= e );
701} 701}
702bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { 702bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
703 return !(*this < e); 703 return !(*this < e);
704} 704}
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index c916297..ec05e77 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -1,704 +1,704 @@
1#include <qshared.h> 1#include <qshared.h>
2#include <qarray.h> 2#include <qarray.h>
3 3
4#include <qpe/palmtopuidgen.h> 4#include <qpe/palmtopuidgen.h>
5#include <qpe/categories.h> 5#include <qpe/categories.h>
6#include <qpe/stringutil.h> 6#include <qpe/stringutil.h>
7 7
8#include "orecur.h" 8#include "orecur.h"
9#include "opimresolver.h" 9#include "opimresolver.h"
10#include "opimnotifymanager.h" 10#include "opimnotifymanager.h"
11 11
12#include "oevent.h" 12#include "oevent.h"
13 13
14int OCalendarHelper::week( const QDate& date) { 14int OCalendarHelper::week( const QDate& date) {
15 // Calculates the week this date is in within that 15 // Calculates the week this date is in within that
16 // month. Equals the "row" is is in in the month view 16 // month. Equals the "row" is is in in the month view
17 int week = 1; 17 int week = 1;
18 QDate tmp( date.year(), date.month(), 1 ); 18 QDate tmp( date.year(), date.month(), 1 );
19 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 19 if ( date.dayOfWeek() < tmp.dayOfWeek() )
20 ++week; 20 ++week;
21 21
22 week += ( date.day() - 1 ) / 7; 22 week += ( date.day() - 1 ) / 7;
23 23
24 return week; 24 return week;
25} 25}
26int OCalendarHelper::ocurrence( const QDate& date) { 26int OCalendarHelper::ocurrence( const QDate& date) {
27 // calculates the number of occurrances of this day of the 27 // calculates the number of occurrances of this day of the
28 // week till the given date (e.g 3rd Wednesday of the month) 28 // week till the given date (e.g 3rd Wednesday of the month)
29 return ( date.day() - 1 ) / 7 + 1; 29 return ( date.day() - 1 ) / 7 + 1;
30} 30}
31int OCalendarHelper::dayOfWeek( char day ) { 31int OCalendarHelper::dayOfWeek( char day ) {
32 int dayOfWeek = 1; 32 int dayOfWeek = 1;
33 char i = ORecur::MON; 33 char i = ORecur::MON;
34 while ( !( i & day ) && i <= ORecur::SUN ) { 34 while ( !( i & day ) && i <= ORecur::SUN ) {
35 i <<= 1; 35 i <<= 1;
36 ++dayOfWeek; 36 ++dayOfWeek;
37 } 37 }
38 return dayOfWeek; 38 return dayOfWeek;
39} 39}
40int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 40int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
41 return ( second.year() - first.year() ) * 12 + 41 return ( second.year() - first.year() ) * 12 +
42 second.month() - first.month(); 42 second.month() - first.month();
43} 43}
44 44
45struct OEvent::Data : public QShared { 45struct OEvent::Data : public QShared {
46 Data() : QShared() { 46 Data() : QShared() {
47 child = 0; 47 child = 0;
48 recur = 0; 48 recur = 0;
49 manager = 0; 49 manager = 0;
50 isAllDay = false; 50 isAllDay = false;
51 parent = 0; 51 parent = 0;
52 } 52 }
53 ~Data() { 53 ~Data() {
54 delete manager; 54 delete manager;
55 delete recur; 55 delete recur;
56 } 56 }
57 QString description; 57 QString description;
58 QString location; 58 QString location;
59 OPimNotifyManager* manager; 59 OPimNotifyManager* manager;
60 ORecur* recur; 60 ORecur* recur;
61 QString note; 61 QString note;
62 QDateTime created; 62 QDateTime created;
63 QDateTime start; 63 QDateTime start;
64 QDateTime end; 64 QDateTime end;
65 bool isAllDay : 1; 65 bool isAllDay : 1;
66 QString timezone; 66 QString timezone;
67 QArray<int>* child; 67 QArray<int>* child;
68 int parent; 68 int parent;
69}; 69};
70 70
71OEvent::OEvent( int uid ) 71OEvent::OEvent( int uid )
72 : OPimRecord( uid ) { 72 : OPimRecord( uid ) {
73 data = new Data; 73 data = new Data;
74} 74}
75OEvent::OEvent( const OEvent& ev) 75OEvent::OEvent( const OEvent& ev)
76 : OPimRecord( ev ), data( ev.data ) 76 : OPimRecord( ev ), data( ev.data )
77{ 77{
78 data->ref(); 78 data->ref();
79} 79}
80OEvent::~OEvent() { 80OEvent::~OEvent() {
81 if ( data->deref() ) { 81 if ( data->deref() ) {
82 delete data; 82 delete data;
83 data = 0; 83 data = 0;
84 } 84 }
85} 85}
86OEvent& OEvent::operator=( const OEvent& ev) { 86OEvent& OEvent::operator=( const OEvent& ev) {
87 if ( this == &ev ) return *this; 87 if ( this == &ev ) return *this;
88 88
89 OPimRecord::operator=( ev ); 89 OPimRecord::operator=( ev );
90 ev.data->ref(); 90 ev.data->ref();
91 deref(); 91 deref();
92 data = ev.data; 92 data = ev.data;
93 93
94 94
95 return *this; 95 return *this;
96} 96}
97QString OEvent::description()const { 97QString OEvent::description()const {
98 return data->description; 98 return data->description;
99} 99}
100void OEvent::setDescription( const QString& description ) { 100void OEvent::setDescription( const QString& description ) {
101 changeOrModify(); 101 changeOrModify();
102 data->description = description; 102 data->description = description;
103} 103}
104void OEvent::setLocation( const QString& loc ) { 104void OEvent::setLocation( const QString& loc ) {
105 changeOrModify(); 105 changeOrModify();
106 data->location = loc; 106 data->location = loc;
107} 107}
108QString OEvent::location()const { 108QString OEvent::location()const {
109 return data->location; 109 return data->location;
110} 110}
111OPimNotifyManager &OEvent::notifiers()const { 111OPimNotifyManager &OEvent::notifiers()const {
112 // I hope we can skip the changeOrModify here 112 // I hope we can skip the changeOrModify here
113 // the notifier should take care of it 113 // the notifier should take care of it
114 // and OPimNotify is shared too 114 // and OPimNotify is shared too
115 if (!data->manager ) 115 if (!data->manager )
116 data->manager = new OPimNotifyManager; 116 data->manager = new OPimNotifyManager;
117 117
118 return *data->manager; 118 return *data->manager;
119} 119}
120bool OEvent::hasNotifiers()const { 120bool OEvent::hasNotifiers()const {
121 if (!data->manager ) 121 if (!data->manager )
122 return false; 122 return false;
123 if (data->manager->reminders().isEmpty() && 123 if (data->manager->reminders().isEmpty() &&
124 data->manager->alarms().isEmpty() ) 124 data->manager->alarms().isEmpty() )
125 return false; 125 return false;
126 126
127 return true; 127 return true;
128} 128}
129ORecur OEvent::recurrence()const { 129ORecur OEvent::recurrence()const {
130 if (!data->recur) 130 if (!data->recur)
131 data->recur = new ORecur; 131 data->recur = new ORecur;
132 132
133 return *data->recur; 133 return *data->recur;
134} 134}
135void OEvent::setRecurrence( const ORecur& rec) { 135void OEvent::setRecurrence( const ORecur& rec) {
136 changeOrModify(); 136 changeOrModify();
137 if (data->recur ) 137 if (data->recur )
138 (*data->recur) = rec; 138 (*data->recur) = rec;
139 else 139 else
140 data->recur = new ORecur( rec ); 140 data->recur = new ORecur( rec );
141} 141}
142bool OEvent::hasRecurrence()const { 142bool OEvent::hasRecurrence()const {
143 if (!data->recur ) return false; 143 if (!data->recur ) return false;
144 return data->recur->doesRecur(); 144 return data->recur->doesRecur();
145} 145}
146QString OEvent::note()const { 146QString OEvent::note()const {
147 return data->note; 147 return data->note;
148} 148}
149void OEvent::setNote( const QString& note ) { 149void OEvent::setNote( const QString& note ) {
150 changeOrModify(); 150 changeOrModify();
151 data->note = note; 151 data->note = note;
152} 152}
153QDateTime OEvent::createdDateTime()const { 153QDateTime OEvent::createdDateTime()const {
154 return data->created; 154 return data->created;
155} 155}
156void OEvent::setCreatedDateTime( const QDateTime& time ) { 156void OEvent::setCreatedDateTime( const QDateTime& time ) {
157 changeOrModify(); 157 changeOrModify();
158 data->created = time; 158 data->created = time;
159} 159}
160QDateTime OEvent::startDateTime()const { 160QDateTime OEvent::startDateTime()const {
161 if ( data->isAllDay ) 161 if ( data->isAllDay )
162 return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); 162 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
163 return data->start; 163 return data->start;
164} 164}
165QDateTime OEvent::startDateTimeInZone()const { 165QDateTime OEvent::startDateTimeInZone()const {
166 /* if no timezone, or all day event or if the current and this timeZone match... */ 166 /* if no timezone, or all day event or if the current and this timeZone match... */
167 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); 167 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
168 168
169 OTimeZone zone(data->timezone ); 169 OTimeZone zone(data->timezone );
170 return zone.toDateTime( data->start, OTimeZone::current() ); 170 return zone.toDateTime( data->start, OTimeZone::current() );
171} 171}
172void OEvent::setStartDateTime( const QDateTime& dt ) { 172void OEvent::setStartDateTime( const QDateTime& dt ) {
173 changeOrModify(); 173 changeOrModify();
174 data->start = dt; 174 data->start = dt;
175} 175}
176QDateTime OEvent::endDateTime()const { 176QDateTime OEvent::endDateTime()const {
177 /* 177 /*
178 * if all Day event the end time needs 178 * if all Day event the end time needs
179 * to be on the same day as the start 179 * to be on the same day as the start
180 */ 180 */
181 if ( data->isAllDay ) 181 if ( data->isAllDay )
182 return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); 182 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
183 return data->end; 183 return data->end;
184} 184}
185QDateTime OEvent::endDateTimeInZone()const { 185QDateTime OEvent::endDateTimeInZone()const {
186 /* if no timezone, or all day event or if the current and this timeZone match... */ 186 /* if no timezone, or all day event or if the current and this timeZone match... */
187 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); 187 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
188 188
189 OTimeZone zone(data->timezone ); 189 OTimeZone zone(data->timezone );
190 return zone.toDateTime( data->end, OTimeZone::current() ); 190 return zone.toDateTime( data->end, OTimeZone::current() );
191} 191}
192void OEvent::setEndDateTime( const QDateTime& dt ) { 192void OEvent::setEndDateTime( const QDateTime& dt ) {
193 changeOrModify(); 193 changeOrModify();
194 data->end = dt; 194 data->end = dt;
195} 195}
196bool OEvent::isMultipleDay()const { 196bool OEvent::isMultipleDay()const {
197 return data->end.date().day() - data->start.date().day(); 197 return data->end.date().day() - data->start.date().day();
198} 198}
199bool OEvent::isAllDay()const { 199bool OEvent::isAllDay()const {
200 return data->isAllDay; 200 return data->isAllDay;
201} 201}
202void OEvent::setAllDay( bool allDay ) { 202void OEvent::setAllDay( bool allDay ) {
203 changeOrModify(); 203 changeOrModify();
204 data->isAllDay = allDay; 204 data->isAllDay = allDay;
205 if (allDay ) data->timezone = "UTC"; 205 if (allDay ) data->timezone = "UTC";
206} 206}
207void OEvent::setTimeZone( const QString& tz ) { 207void OEvent::setTimeZone( const QString& tz ) {
208 changeOrModify(); 208 changeOrModify();
209 data->timezone = tz; 209 data->timezone = tz;
210} 210}
211QString OEvent::timeZone()const { 211QString OEvent::timeZone()const {
212 if (data->isAllDay ) return QString::fromLatin1("UTC"); 212 if (data->isAllDay ) return QString::fromLatin1("UTC");
213 return data->timezone; 213 return data->timezone;
214} 214}
215bool OEvent::match( const QRegExp& re )const { 215bool OEvent::match( const QRegExp& re )const {
216 if ( re.match( data->description ) != -1 ){ 216 if ( re.match( data->description ) != -1 ){
217 setLastHitField( Qtopia::DatebookDescription ); 217 setLastHitField( Qtopia::DatebookDescription );
218 return true; 218 return true;
219 } 219 }
220 if ( re.match( data->note ) != -1 ){ 220 if ( re.match( data->note ) != -1 ){
221 setLastHitField( Qtopia::Note ); 221 setLastHitField( Qtopia::Note );
222 return true; 222 return true;
223 } 223 }
224 if ( re.match( data->location ) != -1 ){ 224 if ( re.match( data->location ) != -1 ){
225 setLastHitField( Qtopia::Location ); 225 setLastHitField( Qtopia::Location );
226 return true; 226 return true;
227 } 227 }
228 if ( re.match( data->start.toString() ) != -1 ){ 228 if ( re.match( data->start.toString() ) != -1 ){
229 setLastHitField( Qtopia::StartDateTime ); 229 setLastHitField( Qtopia::StartDateTime );
230 return true; 230 return true;
231 } 231 }
232 if ( re.match( data->end.toString() ) != -1 ){ 232 if ( re.match( data->end.toString() ) != -1 ){
233 setLastHitField( Qtopia::EndDateTime ); 233 setLastHitField( Qtopia::EndDateTime );
234 return true; 234 return true;
235 } 235 }
236 return false; 236 return false;
237} 237}
238QString OEvent::toRichText()const { 238QString OEvent::toRichText()const {
239 QString text, value; 239 QString text, value;
240 240
241 // description 241 // description
242 text += "<b><h3><img src=\"datebook/DateBook\">"; 242 text += "<b><h3><img src=\"datebook/DateBook\">";
243 if ( !description().isEmpty() ) { 243 if ( !description().isEmpty() ) {
244 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" ); 244 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" );
245 } 245 }
246 text += "</h3></b><br><hr><br>"; 246 text += "</h3></b><br><hr><br>";
247 247
248 // location 248 // location
249 if ( !(value = location()).isEmpty() ) { 249 if ( !(value = location()).isEmpty() ) {
250 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 250 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
251 text += Qtopia::escapeString(value) + "<br>"; 251 text += Qtopia::escapeString(value) + "<br>";
252 } 252 }
253 253
254 // all day event 254 // all day event
255 if ( isAllDay() ) { 255 if ( isAllDay() ) {
256 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 256 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
257 } 257 }
258 // multiple day event 258 // multiple day event
259 else if ( isMultipleDay () ) { 259 else if ( isMultipleDay () ) {
260 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 260 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
261 } 261 }
262 // start & end times 262 // start & end times
263 else { 263 else {
264 // start time 264 // start time
265 if ( startDateTime().isValid() ) { 265 if ( startDateTime().isValid() ) {
266 text += "<b>" + QObject::tr( "Start:") + "</b> "; 266 text += "<b>" + QObject::tr( "Start:") + "</b> ";
267 text += Qtopia::escapeString(startDateTime().toString() ). 267 text += Qtopia::escapeString(startDateTime().toString() ).
268 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 268 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
269 } 269 }
270 270
271 // end time 271 // end time
272 if ( endDateTime().isValid() ) { 272 if ( endDateTime().isValid() ) {
273 text += "<b>" + QObject::tr( "End:") + "</b> "; 273 text += "<b>" + QObject::tr( "End:") + "</b> ";
274 text += Qtopia::escapeString(endDateTime().toString() ). 274 text += Qtopia::escapeString(endDateTime().toString() ).
275 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 275 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
276 } 276 }
277 } 277 }
278 278
279 // categories 279 // categories
280 if ( categoryNames("Calendar").count() ){ 280 if ( categoryNames("Calendar").count() ){
281 text += "<b>" + QObject::tr( "Category:") + "</b> "; 281 text += "<b>" + QObject::tr( "Category:") + "</b> ";
282 text += categoryNames("Calendar").join(", "); 282 text += categoryNames("Calendar").join(", ");
283 text += "<br>"; 283 text += "<br>";
284 } 284 }
285 285
286 //notes 286 //notes
287 if ( !note().isEmpty() ) { 287 if ( !note().isEmpty() ) {
288 text += "<b>" + QObject::tr( "Note:") + "</b><br>"; 288 text += "<b>" + QObject::tr( "Note:") + "</b><br>";
289 text += note(); 289 text += note();
290// text += Qtopia::escapeString(note() ). 290// text += Qtopia::escapeString(note() ).
291// replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 291// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
292 } 292 }
293 return text; 293 return text;
294} 294}
295QString OEvent::toShortText()const { 295QString OEvent::toShortText()const {
296 QString text; 296 QString text;
297 text += QString::number( startDateTime().date().day() ); 297 text += QString::number( startDateTime().date().day() );
298 text += "."; 298 text += ".";
299 text += QString::number( startDateTime().date().month() ); 299 text += QString::number( startDateTime().date().month() );
300 text += "."; 300 text += ".";
301 text += QString::number( startDateTime().date().year() ); 301 text += QString::number( startDateTime().date().year() );
302 text += " "; 302 text += " ";
303 text += QString::number( startDateTime().time().hour() ); 303 text += QString::number( startDateTime().time().hour() );
304 text += ":"; 304 text += ":";
305 text += QString::number( startDateTime().time().minute() ); 305 text += QString::number( startDateTime().time().minute() );
306 text += " - "; 306 text += " - ";
307 text += description(); 307 text += description();
308 return text; 308 return text;
309} 309}
310QString OEvent::type()const { 310QString OEvent::type()const {
311 return QString::fromLatin1("OEvent"); 311 return QString::fromLatin1("OEvent");
312} 312}
313QString OEvent::recordField( int /*id */ )const { 313QString OEvent::recordField( int /*id */ )const {
314 return QString::null; 314 return QString::null;
315} 315}
316int OEvent::rtti() { 316int OEvent::rtti() {
317 return OPimResolver::DateBook; 317 return OPimResolver::DateBook;
318} 318}
319bool OEvent::loadFromStream( QDataStream& ) { 319bool OEvent::loadFromStream( QDataStream& ) {
320 return true; 320 return true;
321} 321}
322bool OEvent::saveToStream( QDataStream& )const { 322bool OEvent::saveToStream( QDataStream& )const {
323 return true; 323 return true;
324} 324}
325void OEvent::changeOrModify() { 325void OEvent::changeOrModify() {
326 if ( data->count != 1 ) { 326 if ( data->count != 1 ) {
327 data->deref(); 327 data->deref();
328 Data* d2 = new Data; 328 Data* d2 = new Data;
329 d2->description = data->description; 329 d2->description = data->description;
330 d2->location = data->location; 330 d2->location = data->location;
331 331
332 if (data->manager ) 332 if (data->manager )
333 d2->manager = new OPimNotifyManager( *data->manager ); 333 d2->manager = new OPimNotifyManager( *data->manager );
334 334
335 if ( data->recur ) 335 if ( data->recur )
336 d2->recur = new ORecur( *data->recur ); 336 d2->recur = new ORecur( *data->recur );
337 337
338 d2->note = data->note; 338 d2->note = data->note;
339 d2->created = data->created; 339 d2->created = data->created;
340 d2->start = data->start; 340 d2->start = data->start;
341 d2->end = data->end; 341 d2->end = data->end;
342 d2->isAllDay = data->isAllDay; 342 d2->isAllDay = data->isAllDay;
343 d2->timezone = data->timezone; 343 d2->timezone = data->timezone;
344 d2->parent = data->parent; 344 d2->parent = data->parent;
345 345
346 if ( data->child ) { 346 if ( data->child ) {
347 d2->child = new QArray<int>( *data->child ); 347 d2->child = new QArray<int>( *data->child );
348 d2->child->detach(); 348 d2->child->detach();
349 } 349 }
350 350
351 data = d2; 351 data = d2;
352 } 352 }
353} 353}
354void OEvent::deref() { 354void OEvent::deref() {
355 if ( data->deref() ) { 355 if ( data->deref() ) {
356 delete data; 356 delete data;
357 data = 0; 357 data = 0;
358 } 358 }
359} 359}
360// Exporting Event data to map. Using the same 360// Exporting Event data to map. Using the same
361// encoding as ODateBookAccessBackend_xml does.. 361// encoding as ODateBookAccessBackend_xml does..
362// Thus, we could remove the stuff there and use this 362// Thus, we could remove the stuff there and use this
363// for it and for all other places.. 363// for it and for all other places..
364// Encoding should happen at one place, only ! (eilers) 364// Encoding should happen at one place, only ! (eilers)
365QMap<int, QString> OEvent::toMap()const { 365QMap<int, QString> OEvent::toMap()const {
366 QMap<int, QString> retMap; 366 QMap<int, QString> retMap;
367 367
368 retMap.insert( OEvent::FUid, QString::number( uid() ) ); 368 retMap.insert( OEvent::FUid, QString::number( uid() ) );
369 retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) )); 369 retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ));
370 retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) ); 370 retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) );
371 retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) ); 371 retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) );
372 retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" ); 372 retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" );
373 OPimAlarm alarm = notifiers().alarms()[0]; 373 OPimAlarm alarm = notifiers().alarms()[0];
374 retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 374 retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
375 retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" ); 375 retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" );
376 376
377 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); 377 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
378 retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OTimeZone::utc() ) ) ) ); 378 retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OTimeZone::utc() ) ) ) );
379 retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OTimeZone::utc() ) ) ) ); 379 retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OTimeZone::utc() ) ) ) );
380 retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) ); 380 retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) );
381 retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? "None" : timeZone() ); 381 retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
382 if( parent() ) 382 if( parent() )
383 retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); 383 retMap.insert( OEvent::FRecParent, QString::number( parent() ) );
384 if( children().count() ){ 384 if( children().count() ){
385 QArray<int> childr = children(); 385 QArray<int> childr = children();
386 QString buf; 386 QString buf;
387 for ( uint i = 0; i < childr.count(); i++ ) { 387 for ( uint i = 0; i < childr.count(); i++ ) {
388 if ( i != 0 ) buf += " "; 388 if ( i != 0 ) buf += " ";
389 buf += QString::number( childr[i] ); 389 buf += QString::number( childr[i] );
390 } 390 }
391 retMap.insert( OEvent::FRecChildren, buf ); 391 retMap.insert( OEvent::FRecChildren, buf );
392 } 392 }
393 393
394 // Add recurrence stuff 394 // Add recurrence stuff
395 if( hasRecurrence() ){ 395 if( hasRecurrence() ){
396 ORecur recur = recurrence(); 396 ORecur recur = recurrence();
397 QMap<int, QString> recFields = recur.toMap(); 397 QMap<int, QString> recFields = recur.toMap();
398 retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); 398 retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
399 retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] ); 399 retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] );
400 retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] ); 400 retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] );
401 retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] ); 401 retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] );
402 retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); 402 retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] );
403 retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); 403 retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
404 retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); 404 retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
405 retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); 405 retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
406 } 406 }
407 407
408 return retMap; 408 return retMap;
409} 409}
410 410
411void OEvent::fromMap( const QMap<int, QString>& map ) 411void OEvent::fromMap( const QMap<int, QString>& map )
412{ 412{
413 413
414 // We just want to set the UID if it is really stored. 414 // We just want to set the UID if it is really stored.
415 if ( !map[OEvent::FUid].isEmpty() ) 415 if ( !map[OEvent::FUid].isEmpty() )
416 setUid( map[OEvent::FUid].toInt() ); 416 setUid( map[OEvent::FUid].toInt() );
417 417
418 setCategories( idsFromString( map[OEvent::FCategories] ) ); 418 setCategories( idsFromString( map[OEvent::FCategories] ) );
419 setDescription( map[OEvent::FDescription] ); 419 setDescription( map[OEvent::FDescription] );
420 setLocation( map[OEvent::FLocation] ); 420 setLocation( map[OEvent::FLocation] );
421 421
422 if ( map[OEvent::FType] == "AllDay" ) 422 if ( map[OEvent::FType] == "AllDay" )
423 setAllDay( true ); 423 setAllDay( true );
424 else 424 else
425 setAllDay( false ); 425 setAllDay( false );
426 426
427 int alarmTime = -1; 427 int alarmTime = -1;
428 if( !map[OEvent::FAlarm].isEmpty() ) 428 if( !map[OEvent::FAlarm].isEmpty() )
429 alarmTime = map[OEvent::FAlarm].toInt(); 429 alarmTime = map[OEvent::FAlarm].toInt();
430 430
431 int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 431 int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
432 if ( ( alarmTime != -1 ) ){ 432 if ( ( alarmTime != -1 ) ){
433 QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); 433 QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 );
434 OPimAlarm al( sound , dt ); 434 OPimAlarm al( sound , dt );
435 notifiers().add( al ); 435 notifiers().add( al );
436 } 436 }
437 if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ 437 if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){
438 setTimeZone( map[OEvent::FTimeZone] ); 438 setTimeZone( map[OEvent::FTimeZone] );
439 } 439 }
440 440
441 time_t start = (time_t) map[OEvent::FStart].toLong(); 441 time_t start = (time_t) map[OEvent::FStart].toLong();
442 time_t end = (time_t) map[OEvent::FEnd].toLong(); 442 time_t end = (time_t) map[OEvent::FEnd].toLong();
443 443
444 /* AllDay is always in UTC */ 444 /* AllDay is always in UTC */
445 if ( isAllDay() ) { 445 if ( isAllDay() ) {
446 OTimeZone utc = OTimeZone::utc(); 446 OTimeZone utc = OTimeZone::utc();
447 setStartDateTime( utc.fromUTCDateTime( start ) ); 447 setStartDateTime( utc.fromUTCDateTime( start ) );
448 setEndDateTime ( utc.fromUTCDateTime( end ) ); 448 setEndDateTime ( utc.fromUTCDateTime( end ) );
449 setTimeZone( "UTC"); // make sure it is really utc 449 setTimeZone( "UTC"); // make sure it is really utc
450 }else { 450 }else {
451 /* to current date time */ 451 /* to current date time */
452 // qWarning(" Start is %d", start ); 452 // qWarning(" Start is %d", start );
453 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); 453 OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
454 QDateTime date = zone.toDateTime( start ); 454 QDateTime date = zone.toDateTime( start );
455 qWarning(" Start is %s", date.toString().latin1() ); 455 qWarning(" Start is %s", date.toString().latin1() );
456 setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); 456 setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) );
457 457
458 date = zone.toDateTime( end ); 458 date = zone.toDateTime( end );
459 setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); 459 setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) );
460 } 460 }
461 461
462 if ( !map[OEvent::FRecParent].isEmpty() ) 462 if ( !map[OEvent::FRecParent].isEmpty() )
463 setParent( map[OEvent::FRecParent].toInt() ); 463 setParent( map[OEvent::FRecParent].toInt() );
464 464
465 if ( !map[OEvent::FRecChildren].isEmpty() ){ 465 if ( !map[OEvent::FRecChildren].isEmpty() ){
466 QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); 466 QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] );
467 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 467 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
468 addChild( (*it).toInt() ); 468 addChild( (*it).toInt() );
469 } 469 }
470 } 470 }
471 471
472 // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. 472 // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap..
473 if( !map[OEvent::FRType].isEmpty() ){ 473 if( !map[OEvent::FRType].isEmpty() ){
474 QMap<int, QString> recFields; 474 QMap<int, QString> recFields;
475 recFields.insert( ORecur::RType, map[OEvent::FRType] ); 475 recFields.insert( ORecur::RType, map[OEvent::FRType] );
476 recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] ); 476 recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] );
477 recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] ); 477 recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] );
478 recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] ); 478 recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] );
479 recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] ); 479 recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] );
480 recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] ); 480 recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] );
481 recFields.insert( ORecur::Created, map[OEvent::FRCreated] ); 481 recFields.insert( ORecur::Created, map[OEvent::FRCreated] );
482 recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] ); 482 recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] );
483 ORecur recur( recFields ); 483 ORecur recur( recFields );
484 setRecurrence( recur ); 484 setRecurrence( recur );
485 } 485 }
486 486
487} 487}
488 488
489 489
490int OEvent::parent()const { 490int OEvent::parent()const {
491 return data->parent; 491 return data->parent;
492} 492}
493void OEvent::setParent( int uid ) { 493void OEvent::setParent( int uid ) {
494 changeOrModify(); 494 changeOrModify();
495 data->parent = uid; 495 data->parent = uid;
496} 496}
497QArray<int> OEvent::children() const{ 497QArray<int> OEvent::children() const{
498 if (!data->child) return QArray<int>(); 498 if (!data->child) return QArray<int>();
499 else 499 else
500 return data->child->copy(); 500 return data->child->copy();
501} 501}
502void OEvent::setChildren( const QArray<int>& arr ) { 502void OEvent::setChildren( const QArray<int>& arr ) {
503 changeOrModify(); 503 changeOrModify();
504 if (data->child) delete data->child; 504 if (data->child) delete data->child;
505 505
506 data->child = new QArray<int>( arr ); 506 data->child = new QArray<int>( arr );
507 data->child->detach(); 507 data->child->detach();
508} 508}
509void OEvent::addChild( int uid ) { 509void OEvent::addChild( int uid ) {
510 changeOrModify(); 510 changeOrModify();
511 if (!data->child ) { 511 if (!data->child ) {
512 data->child = new QArray<int>(1); 512 data->child = new QArray<int>(1);
513 (*data->child)[0] = uid; 513 (*data->child)[0] = uid;
514 }else{ 514 }else{
515 int count = data->child->count(); 515 int count = data->child->count();
516 data->child->resize( count + 1 ); 516 data->child->resize( count + 1 );
517 (*data->child)[count] = uid; 517 (*data->child)[count] = uid;
518 } 518 }
519} 519}
520void OEvent::removeChild( int uid ) { 520void OEvent::removeChild( int uid ) {
521 if (!data->child || !data->child->contains( uid ) ) return; 521 if (!data->child || !data->child->contains( uid ) ) return;
522 changeOrModify(); 522 changeOrModify();
523 QArray<int> newAr( data->child->count() - 1 ); 523 QArray<int> newAr( data->child->count() - 1 );
524 int j = 0; 524 int j = 0;
525 uint count = data->child->count(); 525 uint count = data->child->count();
526 for ( uint i = 0; i < count; i++ ) { 526 for ( uint i = 0; i < count; i++ ) {
527 if ( (*data->child)[i] != uid ) { 527 if ( (*data->child)[i] != uid ) {
528 newAr[j] = (*data->child)[i]; 528 newAr[j] = (*data->child)[i];
529 j++; 529 j++;
530 } 530 }
531 } 531 }
532 (*data->child) = newAr; 532 (*data->child) = newAr;
533} 533}
534struct OEffectiveEvent::Data : public QShared { 534struct OEffectiveEvent::Data : public QShared {
535 Data() : QShared() { 535 Data() : QShared() {
536 } 536 }
537 OEvent event; 537 OEvent event;
538 QDate date; 538 QDate date;
539 QTime start, end; 539 QTime start, end;
540 QDate startDate, endDate; 540 QDate startDate, endDate;
541 bool dates : 1; 541 bool dates : 1;
542}; 542};
543 543
544OEffectiveEvent::OEffectiveEvent() { 544OEffectiveEvent::OEffectiveEvent() {
545 data = new Data; 545 data = new Data;
546 data->date = QDate::currentDate(); 546 data->date = QDate::currentDate();
547 data->start = data->end = QTime::currentTime(); 547 data->start = data->end = QTime::currentTime();
548 data->dates = false; 548 data->dates = false;
549} 549}
550OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 550OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
551 Position pos ) { 551 Position pos ) {
552 data = new Data; 552 data = new Data;
553 data->event = ev; 553 data->event = ev;
554 data->date = startDate; 554 data->date = startDate;
555 if ( pos & Start ) 555 if ( pos & Start )
556 data->start = ev.startDateTime().time(); 556 data->start = ev.startDateTime().time();
557 else 557 else
558 data->start = QTime( 0, 0, 0 ); 558 data->start = QTime( 0, 0, 0 );
559 559
560 if ( pos & End ) 560 if ( pos & End )
561 data->end = ev.endDateTime().time(); 561 data->end = ev.endDateTime().time();
562 else 562 else
563 data->end = QTime( 23, 59, 59 ); 563 data->end = QTime( 23, 59, 59 );
564 564
565 data->dates = false; 565 data->dates = false;
566} 566}
567OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 567OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
568 data = ev.data; 568 data = ev.data;
569 data->ref(); 569 data->ref();
570} 570}
571OEffectiveEvent::~OEffectiveEvent() { 571OEffectiveEvent::~OEffectiveEvent() {
572 if ( data->deref() ) { 572 if ( data->deref() ) {
573 delete data; 573 delete data;
574 data = 0; 574 data = 0;
575 } 575 }
576} 576}
577OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 577OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
578 if ( *this == ev ) return *this; 578 if ( *this == ev ) return *this;
579 579
580 ev.data->ref(); 580 ev.data->ref();
581 deref(); 581 deref();
582 data = ev.data; 582 data = ev.data;
583 583
584 return *this; 584 return *this;
585} 585}
586 586
587void OEffectiveEvent::setStartTime( const QTime& ti) { 587void OEffectiveEvent::setStartTime( const QTime& ti) {
588 changeOrModify(); 588 changeOrModify();
589 data->start = ti; 589 data->start = ti;
590} 590}
591void OEffectiveEvent::setEndTime( const QTime& en) { 591void OEffectiveEvent::setEndTime( const QTime& en) {
592 changeOrModify(); 592 changeOrModify();
593 data->end = en; 593 data->end = en;
594} 594}
595void OEffectiveEvent::setEvent( const OEvent& ev) { 595void OEffectiveEvent::setEvent( const OEvent& ev) {
596 changeOrModify(); 596 changeOrModify();
597 data->event = ev; 597 data->event = ev;
598} 598}
599void OEffectiveEvent::setDate( const QDate& da) { 599void OEffectiveEvent::setDate( const QDate& da) {
600 changeOrModify(); 600 changeOrModify();
601 data->date = da; 601 data->date = da;
602} 602}
603void OEffectiveEvent::setEffectiveDates( const QDate& from, 603void OEffectiveEvent::setEffectiveDates( const QDate& from,
604 const QDate& to ) { 604 const QDate& to ) {
605 if (!from.isValid() ) { 605 if (!from.isValid() ) {
606 data->dates = false; 606 data->dates = false;
607 return; 607 return;
608 } 608 }
609 609
610 data->startDate = from; 610 data->startDate = from;
611 data->endDate = to; 611 data->endDate = to;
612} 612}
613QString OEffectiveEvent::description()const { 613QString OEffectiveEvent::description()const {
614 return data->event.description(); 614 return data->event.description();
615} 615}
616QString OEffectiveEvent::location()const { 616QString OEffectiveEvent::location()const {
617 return data->event.location(); 617 return data->event.location();
618} 618}
619QString OEffectiveEvent::note()const { 619QString OEffectiveEvent::note()const {
620 return data->event.note(); 620 return data->event.note();
621} 621}
622OEvent OEffectiveEvent::event()const { 622OEvent OEffectiveEvent::event()const {
623 return data->event; 623 return data->event;
624} 624}
625QTime OEffectiveEvent::startTime()const { 625QTime OEffectiveEvent::startTime()const {
626 return data->start; 626 return data->start;
627} 627}
628QTime OEffectiveEvent::endTime()const { 628QTime OEffectiveEvent::endTime()const {
629 return data->end; 629 return data->end;
630} 630}
631QDate OEffectiveEvent::date()const { 631QDate OEffectiveEvent::date()const {
632 return data->date; 632 return data->date;
633} 633}
634int OEffectiveEvent::length()const { 634int OEffectiveEvent::length()const {
635 return (data->end.hour() * 60 - data->start.hour() * 60) 635 return (data->end.hour() * 60 - data->start.hour() * 60)
636 + QABS(data->start.minute() - data->end.minute() ); 636 + QABS(data->start.minute() - data->end.minute() );
637} 637}
638int OEffectiveEvent::size()const { 638int OEffectiveEvent::size()const {
639 return ( data->end.hour() - data->start.hour() ) * 3600 639 return ( data->end.hour() - data->start.hour() ) * 3600
640 + (data->end.minute() - data->start.minute() * 60 640 + (data->end.minute() - data->start.minute() * 60
641 + data->end.second() - data->start.second() ); 641 + data->end.second() - data->start.second() );
642} 642}
643QDate OEffectiveEvent::startDate()const { 643QDate OEffectiveEvent::startDate()const {
644 if ( data->dates ) 644 if ( data->dates )
645 return data->startDate; 645 return data->startDate;
646 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 646 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
647 return data->date; 647 return data->date;
648 else 648 else
649 return data->event.startDateTime().date(); 649 return data->event.startDateTime().date();
650} 650}
651QDate OEffectiveEvent::endDate()const { 651QDate OEffectiveEvent::endDate()const {
652 if ( data->dates ) 652 if ( data->dates )
653 return data->endDate; 653 return data->endDate;
654 else if ( data->event.hasRecurrence() ) 654 else if ( data->event.hasRecurrence() )
655 return data->date; 655 return data->date;
656 else 656 else
657 return data->event.endDateTime().date(); 657 return data->event.endDateTime().date();
658} 658}
659void OEffectiveEvent::deref() { 659void OEffectiveEvent::deref() {
660 if ( data->deref() ) { 660 if ( data->deref() ) {
661 delete data; 661 delete data;
662 data = 0; 662 data = 0;
663 } 663 }
664} 664}
665void OEffectiveEvent::changeOrModify() { 665void OEffectiveEvent::changeOrModify() {
666 if ( data->count != 1 ) { 666 if ( data->count != 1 ) {
667 data->deref(); 667 data->deref();
668 Data* d2 = new Data; 668 Data* d2 = new Data;
669 d2->event = data->event; 669 d2->event = data->event;
670 d2->date = data->date; 670 d2->date = data->date;
671 d2->start = data->start; 671 d2->start = data->start;
672 d2->end = data->end; 672 d2->end = data->end;
673 d2->startDate = data->startDate; 673 d2->startDate = data->startDate;
674 d2->endDate = data->endDate; 674 d2->endDate = data->endDate;
675 d2->dates = data->dates; 675 d2->dates = data->dates;
676 data = d2; 676 data = d2;
677 } 677 }
678} 678}
679bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ 679bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
680 if ( data->date < e.date() ) 680 if ( data->date < e.date() )
681 return TRUE; 681 return TRUE;
682 if ( data->date == e.date() ) 682 if ( data->date == e.date() )
683 return ( startTime() < e.startTime() ); 683 return ( startTime() < e.startTime() );
684 else 684 else
685 return FALSE; 685 return FALSE;
686} 686}
687bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ 687bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
688 return (data->date <= e.date() ); 688 return (data->date <= e.date() );
689} 689}
690bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { 690bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
691 return ( date() == e.date() 691 return ( date() == e.date()
692 && startTime() == e.startTime() 692 && startTime() == e.startTime()
693 && endTime()== e.endTime() 693 && endTime()== e.endTime()
694 && event() == e.event() ); 694 && event() == e.event() );
695} 695}
696bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { 696bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
697 return !(*this == e ); 697 return !(*this == e );
698} 698}
699bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { 699bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
700 return !(*this <= e ); 700 return !(*this <= e );
701} 701}
702bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { 702bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
703 return !(*this < e); 703 return !(*this < e);
704} 704}