author | eilers <eilers> | 2003-12-08 15:18:10 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-12-08 15:18:10 (UTC) |
commit | 6974a4bbdc674a2a5d41d801f80035a183faedb5 (patch) (unidiff) | |
tree | 09a719ef263047e92ffb866da13168b7f7d41f23 /libopie2/opiepim/oevent.cpp | |
parent | 7f2f736597490fd1592d7ed1f40e4abf824673c0 (diff) | |
download | opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.zip opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.tar.gz opie-6974a4bbdc674a2a5d41d801f80035a183faedb5.tar.bz2 |
Committing unfinished sql implementation before merging to libopie2 starts..
-rw-r--r-- | libopie2/opiepim/oevent.cpp | 131 |
1 files changed, 129 insertions, 2 deletions
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp index 7bcf944..c916297 100644 --- a/libopie2/opiepim/oevent.cpp +++ b/libopie2/opiepim/oevent.cpp | |||
@@ -1,33 +1,34 @@ | |||
1 | #include <qshared.h> | 1 | #include <qshared.h> |
2 | #include <qarray.h> | ||
2 | 3 | ||
3 | #include <qpe/palmtopuidgen.h> | 4 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/categories.h> | 5 | #include <qpe/categories.h> |
5 | #include <qpe/stringutil.h> | 6 | #include <qpe/stringutil.h> |
6 | 7 | ||
7 | #include "orecur.h" | 8 | #include "orecur.h" |
8 | #include "opimresolver.h" | 9 | #include "opimresolver.h" |
9 | #include "opimnotifymanager.h" | 10 | #include "opimnotifymanager.h" |
10 | 11 | ||
11 | #include "oevent.h" | 12 | #include "oevent.h" |
12 | 13 | ||
13 | int OCalendarHelper::week( const QDate& date) { | 14 | int OCalendarHelper::week( const QDate& date) { |
14 | // Calculates the week this date is in within that | 15 | // Calculates the week this date is in within that |
15 | // month. Equals the "row" is is in in the month view | 16 | // month. Equals the "row" is is in in the month view |
16 | int week = 1; | 17 | int week = 1; |
17 | QDate tmp( date.year(), date.month(), 1 ); | 18 | QDate tmp( date.year(), date.month(), 1 ); |
18 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) | 19 | if ( date.dayOfWeek() < tmp.dayOfWeek() ) |
19 | ++week; | 20 | ++week; |
20 | 21 | ||
21 | week += ( date.day() - 1 ) / 7; | 22 | week += ( date.day() - 1 ) / 7; |
22 | 23 | ||
23 | return week; | 24 | return week; |
24 | } | 25 | } |
25 | int OCalendarHelper::ocurrence( const QDate& date) { | 26 | int OCalendarHelper::ocurrence( const QDate& date) { |
26 | // calculates the number of occurrances of this day of the | 27 | // calculates the number of occurrances of this day of the |
27 | // 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) |
28 | return ( date.day() - 1 ) / 7 + 1; | 29 | return ( date.day() - 1 ) / 7 + 1; |
29 | } | 30 | } |
30 | int OCalendarHelper::dayOfWeek( char day ) { | 31 | int OCalendarHelper::dayOfWeek( char day ) { |
31 | int dayOfWeek = 1; | 32 | int dayOfWeek = 1; |
32 | char i = ORecur::MON; | 33 | char i = ORecur::MON; |
33 | while ( !( i & day ) && i <= ORecur::SUN ) { | 34 | while ( !( i & day ) && i <= ORecur::SUN ) { |
@@ -327,68 +328,194 @@ void OEvent::changeOrModify() { | |||
327 | Data* d2 = new Data; | 328 | Data* d2 = new Data; |
328 | d2->description = data->description; | 329 | d2->description = data->description; |
329 | d2->location = data->location; | 330 | d2->location = data->location; |
330 | 331 | ||
331 | if (data->manager ) | 332 | if (data->manager ) |
332 | d2->manager = new OPimNotifyManager( *data->manager ); | 333 | d2->manager = new OPimNotifyManager( *data->manager ); |
333 | 334 | ||
334 | if ( data->recur ) | 335 | if ( data->recur ) |
335 | d2->recur = new ORecur( *data->recur ); | 336 | d2->recur = new ORecur( *data->recur ); |
336 | 337 | ||
337 | d2->note = data->note; | 338 | d2->note = data->note; |
338 | d2->created = data->created; | 339 | d2->created = data->created; |
339 | d2->start = data->start; | 340 | d2->start = data->start; |
340 | d2->end = data->end; | 341 | d2->end = data->end; |
341 | d2->isAllDay = data->isAllDay; | 342 | d2->isAllDay = data->isAllDay; |
342 | d2->timezone = data->timezone; | 343 | d2->timezone = data->timezone; |
343 | d2->parent = data->parent; | 344 | d2->parent = data->parent; |
344 | 345 | ||
345 | if ( data->child ) { | 346 | if ( data->child ) { |
346 | d2->child = new QArray<int>( *data->child ); | 347 | d2->child = new QArray<int>( *data->child ); |
347 | d2->child->detach(); | 348 | d2->child->detach(); |
348 | } | 349 | } |
349 | 350 | ||
350 | data = d2; | 351 | data = d2; |
351 | } | 352 | } |
352 | } | 353 | } |
353 | void OEvent::deref() { | 354 | void OEvent::deref() { |
354 | if ( data->deref() ) { | 355 | if ( data->deref() ) { |
355 | delete data; | 356 | delete data; |
356 | data = 0; | 357 | data = 0; |
357 | } | 358 | } |
358 | } | 359 | } |
359 | // FIXME | 360 | // Exporting Event data to map. Using the same |
361 | // encoding as ODateBookAccessBackend_xml does.. | ||
362 | // Thus, we could remove the stuff there and use this | ||
363 | // for it and for all other places.. | ||
364 | // Encoding should happen at one place, only ! (eilers) | ||
360 | QMap<int, QString> OEvent::toMap()const { | 365 | QMap<int, QString> OEvent::toMap()const { |
361 | return QMap<int, QString>(); | 366 | QMap<int, QString> retMap; |
367 | |||
368 | retMap.insert( OEvent::FUid, QString::number( uid() ) ); | ||
369 | retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) )); | ||
370 | retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) ); | ||
371 | retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) ); | ||
372 | retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" ); | ||
373 | OPimAlarm alarm = notifiers().alarms()[0]; | ||
374 | retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); | ||
375 | retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" ); | ||
376 | |||
377 | OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); | ||
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() ) ) ) ); | ||
380 | retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) ); | ||
381 | retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? "None" : timeZone() ); | ||
382 | if( parent() ) | ||
383 | retMap.insert( OEvent::FRecParent, QString::number( parent() ) ); | ||
384 | if( children().count() ){ | ||
385 | QArray<int> childr = children(); | ||
386 | QString buf; | ||
387 | for ( uint i = 0; i < childr.count(); i++ ) { | ||
388 | if ( i != 0 ) buf += " "; | ||
389 | buf += QString::number( childr[i] ); | ||
390 | } | ||
391 | retMap.insert( OEvent::FRecChildren, buf ); | ||
392 | } | ||
393 | |||
394 | // Add recurrence stuff | ||
395 | if( hasRecurrence() ){ | ||
396 | ORecur recur = recurrence(); | ||
397 | QMap<int, QString> recFields = recur.toMap(); | ||
398 | retMap.insert( OEvent::FRType, recFields[ORecur::RType] ); | ||
399 | retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] ); | ||
400 | retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] ); | ||
401 | retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] ); | ||
402 | retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] ); | ||
403 | retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] ); | ||
404 | retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] ); | ||
405 | retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] ); | ||
406 | } | ||
407 | |||
408 | return retMap; | ||
409 | } | ||
410 | |||
411 | void OEvent::fromMap( const QMap<int, QString>& map ) | ||
412 | { | ||
413 | |||
414 | // We just want to set the UID if it is really stored. | ||
415 | if ( !map[OEvent::FUid].isEmpty() ) | ||
416 | setUid( map[OEvent::FUid].toInt() ); | ||
417 | |||
418 | setCategories( idsFromString( map[OEvent::FCategories] ) ); | ||
419 | setDescription( map[OEvent::FDescription] ); | ||
420 | setLocation( map[OEvent::FLocation] ); | ||
421 | |||
422 | if ( map[OEvent::FType] == "AllDay" ) | ||
423 | setAllDay( true ); | ||
424 | else | ||
425 | setAllDay( false ); | ||
426 | |||
427 | int alarmTime = -1; | ||
428 | if( !map[OEvent::FAlarm].isEmpty() ) | ||
429 | alarmTime = map[OEvent::FAlarm].toInt(); | ||
430 | |||
431 | int sound = ( ( map[OEvent::FSound] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); | ||
432 | if ( ( alarmTime != -1 ) ){ | ||
433 | QDateTime dt = startDateTime().addSecs( -1*alarmTime*60 ); | ||
434 | OPimAlarm al( sound , dt ); | ||
435 | notifiers().add( al ); | ||
436 | } | ||
437 | if ( !map[OEvent::FTimeZone].isEmpty() && ( map[OEvent::FTimeZone] != "None" ) ){ | ||
438 | setTimeZone( map[OEvent::FTimeZone] ); | ||
439 | } | ||
440 | |||
441 | time_t start = (time_t) map[OEvent::FStart].toLong(); | ||
442 | time_t end = (time_t) map[OEvent::FEnd].toLong(); | ||
443 | |||
444 | /* AllDay is always in UTC */ | ||
445 | if ( isAllDay() ) { | ||
446 | OTimeZone utc = OTimeZone::utc(); | ||
447 | setStartDateTime( utc.fromUTCDateTime( start ) ); | ||
448 | setEndDateTime ( utc.fromUTCDateTime( end ) ); | ||
449 | setTimeZone( "UTC"); // make sure it is really utc | ||
450 | }else { | ||
451 | /* to current date time */ | ||
452 | // qWarning(" Start is %d", start ); | ||
453 | OTimeZone zone( timeZone().isEmpty() ? OTimeZone::current() : timeZone() ); | ||
454 | QDateTime date = zone.toDateTime( start ); | ||
455 | qWarning(" Start is %s", date.toString().latin1() ); | ||
456 | setStartDateTime( zone.toDateTime( date, OTimeZone::current() ) ); | ||
457 | |||
458 | date = zone.toDateTime( end ); | ||
459 | setEndDateTime ( zone.toDateTime( date, OTimeZone::current() ) ); | ||
460 | } | ||
461 | |||
462 | if ( !map[OEvent::FRecParent].isEmpty() ) | ||
463 | setParent( map[OEvent::FRecParent].toInt() ); | ||
464 | |||
465 | if ( !map[OEvent::FRecChildren].isEmpty() ){ | ||
466 | QStringList list = QStringList::split(' ', map[OEvent::FRecChildren] ); | ||
467 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
468 | addChild( (*it).toInt() ); | ||
469 | } | ||
470 | } | ||
471 | |||
472 | // Fill recurrence stuff and put it directly into the ORecur-Object using fromMap.. | ||
473 | if( !map[OEvent::FRType].isEmpty() ){ | ||
474 | QMap<int, QString> recFields; | ||
475 | recFields.insert( ORecur::RType, map[OEvent::FRType] ); | ||
476 | recFields.insert( ORecur::RWeekdays, map[OEvent::FRWeekdays] ); | ||
477 | recFields.insert( ORecur::RPosition, map[OEvent::FRPosition] ); | ||
478 | recFields.insert( ORecur::RFreq, map[OEvent::FRFreq] ); | ||
479 | recFields.insert( ORecur::RHasEndDate, map[OEvent::FRHasEndDate] ); | ||
480 | recFields.insert( ORecur::EndDate, map[OEvent::FREndDate] ); | ||
481 | recFields.insert( ORecur::Created, map[OEvent::FRCreated] ); | ||
482 | recFields.insert( ORecur::Exceptions, map[OEvent::FRExceptions] ); | ||
483 | ORecur recur( recFields ); | ||
484 | setRecurrence( recur ); | ||
485 | } | ||
486 | |||
362 | } | 487 | } |
488 | |||
489 | |||
363 | int OEvent::parent()const { | 490 | int OEvent::parent()const { |
364 | return data->parent; | 491 | return data->parent; |
365 | } | 492 | } |
366 | void OEvent::setParent( int uid ) { | 493 | void OEvent::setParent( int uid ) { |
367 | changeOrModify(); | 494 | changeOrModify(); |
368 | data->parent = uid; | 495 | data->parent = uid; |
369 | } | 496 | } |
370 | QArray<int> OEvent::children() const{ | 497 | QArray<int> OEvent::children() const{ |
371 | if (!data->child) return QArray<int>(); | 498 | if (!data->child) return QArray<int>(); |
372 | else | 499 | else |
373 | return data->child->copy(); | 500 | return data->child->copy(); |
374 | } | 501 | } |
375 | void OEvent::setChildren( const QArray<int>& arr ) { | 502 | void OEvent::setChildren( const QArray<int>& arr ) { |
376 | changeOrModify(); | 503 | changeOrModify(); |
377 | if (data->child) delete data->child; | 504 | if (data->child) delete data->child; |
378 | 505 | ||
379 | data->child = new QArray<int>( arr ); | 506 | data->child = new QArray<int>( arr ); |
380 | data->child->detach(); | 507 | data->child->detach(); |
381 | } | 508 | } |
382 | void OEvent::addChild( int uid ) { | 509 | void OEvent::addChild( int uid ) { |
383 | changeOrModify(); | 510 | changeOrModify(); |
384 | if (!data->child ) { | 511 | if (!data->child ) { |
385 | data->child = new QArray<int>(1); | 512 | data->child = new QArray<int>(1); |
386 | (*data->child)[0] = uid; | 513 | (*data->child)[0] = uid; |
387 | }else{ | 514 | }else{ |
388 | int count = data->child->count(); | 515 | int count = data->child->count(); |
389 | data->child->resize( count + 1 ); | 516 | data->child->resize( count + 1 ); |
390 | (*data->child)[count] = uid; | 517 | (*data->child)[count] = uid; |
391 | } | 518 | } |
392 | } | 519 | } |
393 | void OEvent::removeChild( int uid ) { | 520 | void OEvent::removeChild( int uid ) { |
394 | if (!data->child || !data->child->contains( uid ) ) return; | 521 | if (!data->child || !data->child->contains( uid ) ) return; |