-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimevent.cpp | 36 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimevent.h | 2 |
3 files changed, 24 insertions, 16 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp index 6c32b40..f4f3c94 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp | |||
@@ -93,97 +93,97 @@ ODateBookAccessBackend_SQL::ODateBookAccessBackend_SQL( const QString& , | |||
93 | : ODateBookAccessBackend(), m_driver( NULL ) | 93 | : ODateBookAccessBackend(), m_driver( NULL ) |
94 | { | 94 | { |
95 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; | 95 | m_fileName = fileName.isEmpty() ? Global::applicationFileName( "datebook", "datebook.db" ) : fileName; |
96 | 96 | ||
97 | // Get the standart sql-driver from the OSQLManager.. | 97 | // Get the standart sql-driver from the OSQLManager.. |
98 | OSQLManager man; | 98 | OSQLManager man; |
99 | m_driver = man.standard(); | 99 | m_driver = man.standard(); |
100 | m_driver->setUrl( m_fileName ); | 100 | m_driver->setUrl( m_fileName ); |
101 | 101 | ||
102 | initFields(); | 102 | initFields(); |
103 | 103 | ||
104 | load(); | 104 | load(); |
105 | } | 105 | } |
106 | 106 | ||
107 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { | 107 | ODateBookAccessBackend_SQL::~ODateBookAccessBackend_SQL() { |
108 | if( m_driver ) | 108 | if( m_driver ) |
109 | delete m_driver; | 109 | delete m_driver; |
110 | } | 110 | } |
111 | 111 | ||
112 | void ODateBookAccessBackend_SQL::initFields() | 112 | void ODateBookAccessBackend_SQL::initFields() |
113 | { | 113 | { |
114 | 114 | ||
115 | // This map contains the translation of the fieldtype id's to | 115 | // This map contains the translation of the fieldtype id's to |
116 | // the names of the table columns | 116 | // the names of the table columns |
117 | m_fieldMap.insert( OPimEvent::FUid, "uid" ); | 117 | m_fieldMap.insert( OPimEvent::FUid, "uid" ); |
118 | m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); | 118 | m_fieldMap.insert( OPimEvent::FCategories, "Categories" ); |
119 | m_fieldMap.insert( OPimEvent::FDescription, "Description" ); | 119 | m_fieldMap.insert( OPimEvent::FDescription, "Description" ); |
120 | m_fieldMap.insert( OPimEvent::FLocation, "Location" ); | 120 | m_fieldMap.insert( OPimEvent::FLocation, "Location" ); |
121 | m_fieldMap.insert( OPimEvent::FType, "Type" ); | 121 | m_fieldMap.insert( OPimEvent::FType, "Type" ); |
122 | m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); | 122 | m_fieldMap.insert( OPimEvent::FAlarm, "Alarm" ); |
123 | m_fieldMap.insert( OPimEvent::FSound, "Sound" ); | 123 | m_fieldMap.insert( OPimEvent::FSound, "Sound" ); |
124 | m_fieldMap.insert( OPimEvent::FRType, "RType" ); | 124 | m_fieldMap.insert( OPimEvent::FRType, "RType" ); |
125 | m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); | 125 | m_fieldMap.insert( OPimEvent::FRWeekdays, "RWeekdays" ); |
126 | m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); | 126 | m_fieldMap.insert( OPimEvent::FRPosition, "RPosition" ); |
127 | m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); | 127 | m_fieldMap.insert( OPimEvent::FRFreq, "RFreq" ); |
128 | m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); | 128 | m_fieldMap.insert( OPimEvent::FRHasEndDate, "RHasEndDate" ); |
129 | m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); | 129 | m_fieldMap.insert( OPimEvent::FREndDate, "REndDate" ); |
130 | m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); | 130 | m_fieldMap.insert( OPimEvent::FRCreated, "RCreated" ); |
131 | m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); | 131 | m_fieldMap.insert( OPimEvent::FRExceptions, "RExceptions" ); |
132 | m_fieldMap.insert( OPimEvent::FStart, "Start" ); | 132 | m_fieldMap.insert( OPimEvent::FStart, "Start" ); |
133 | m_fieldMap.insert( OPimEvent::FEnd, "End" ); | 133 | m_fieldMap.insert( OPimEvent::FEnd, "End" ); |
134 | m_fieldMap.insert( OPimEvent::FNote, "Note" ); | 134 | m_fieldMap.insert( OPimEvent::FNote, "Note" ); |
135 | m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); | 135 | m_fieldMap.insert( OPimEvent::FTimeZone, "TimeZone" ); |
136 | m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" ); | 136 | m_fieldMap.insert( OPimEvent::FRecParent, "RecParent" ); |
137 | m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" ); | 137 | m_fieldMap.insert( OPimEvent::FRecChildren, "Recchildren" ); |
138 | 138 | ||
139 | // Create a map that maps the column name to the id | 139 | // Create a map that maps the column name to the id |
140 | QMapConstIterator<int, QString> it; | 140 | QMapConstIterator<int, QString> it; |
141 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 141 | for ( it = m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
142 | m_reverseFieldMap.insert( it.data(), it.key() ); | 142 | m_reverseFieldMap.insert( it.data(), it.key() ); |
143 | } | 143 | } |
144 | 144 | ||
145 | } | 145 | } |
146 | 146 | ||
147 | bool ODateBookAccessBackend_SQL::load() | 147 | bool ODateBookAccessBackend_SQL::load() |
148 | { | 148 | { |
149 | if (!m_driver->open() ) | 149 | if (!m_driver->open() ) |
150 | return false; | 150 | return false; |
151 | 151 | ||
152 | // Don't expect that the database exists. | 152 | // Don't expect that the database exists. |
153 | // It is save here to create the table, even if it | 153 | // It is save here to create the table, even if it |
154 | // do exist. ( Is that correct for all databases ?? ) | 154 | // do exist. ( Is that correct for all databases ?? ) |
155 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; | 155 | QStringqu = "create table datebook( uid INTEGER PRIMARY KEY "; |
156 | 156 | ||
157 | QMap<int, QString>::Iterator it; | 157 | QMap<int, QString>::Iterator it; |
158 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ | 158 | for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){ |
159 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); | 159 | qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() ); |
160 | } | 160 | } |
161 | qu += " );"; | 161 | qu += " );"; |
162 | 162 | ||
163 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 163 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
164 | 164 | ||
165 | qWarning( "command: %s", qu.latin1() ); | 165 | qWarning( "command: %s", qu.latin1() ); |
166 | 166 | ||
167 | OSQLRawQuery raw( qu ); | 167 | OSQLRawQuery raw( qu ); |
168 | OSQLResult res = m_driver->query( &raw ); | 168 | OSQLResult res = m_driver->query( &raw ); |
169 | if ( res.state() != OSQLResult::Success ) | 169 | if ( res.state() != OSQLResult::Success ) |
170 | return false; | 170 | return false; |
171 | 171 | ||
172 | update(); | 172 | update(); |
173 | 173 | ||
174 | return true; | 174 | return true; |
175 | } | 175 | } |
176 | 176 | ||
177 | void ODateBookAccessBackend_SQL::update() | 177 | void ODateBookAccessBackend_SQL::update() |
178 | { | 178 | { |
179 | 179 | ||
180 | QString qu = "select uid from datebook"; | 180 | QString qu = "select uid from datebook"; |
181 | OSQLRawQuery raw( qu ); | 181 | OSQLRawQuery raw( qu ); |
182 | OSQLResult res = m_driver->query( &raw ); | 182 | OSQLResult res = m_driver->query( &raw ); |
183 | if ( res.state() != OSQLResult::Success ){ | 183 | if ( res.state() != OSQLResult::Success ){ |
184 | // m_uids.clear(); | 184 | // m_uids.clear(); |
185 | return; | 185 | return; |
186 | } | 186 | } |
187 | 187 | ||
188 | m_uids = extractUids( res ); | 188 | m_uids = extractUids( res ); |
189 | 189 | ||
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp index 8bf8b25..9d46651 100644 --- a/libopie2/opiepim/core/opimevent.cpp +++ b/libopie2/opiepim/core/opimevent.cpp | |||
@@ -510,200 +510,208 @@ void OPimEvent::changeOrModify() | |||
510 | 510 | ||
511 | if ( data->manager ) | 511 | if ( data->manager ) |
512 | d2->manager = new OPimNotifyManager( *data->manager ); | 512 | d2->manager = new OPimNotifyManager( *data->manager ); |
513 | 513 | ||
514 | if ( data->recur ) | 514 | if ( data->recur ) |
515 | d2->recur = new OPimRecurrence( *data->recur ); | 515 | d2->recur = new OPimRecurrence( *data->recur ); |
516 | 516 | ||
517 | d2->note = data->note; | 517 | d2->note = data->note; |
518 | d2->created = data->created; | 518 | d2->created = data->created; |
519 | d2->start = data->start; | 519 | d2->start = data->start; |
520 | d2->end = data->end; | 520 | d2->end = data->end; |
521 | d2->isAllDay = data->isAllDay; | 521 | d2->isAllDay = data->isAllDay; |
522 | d2->timezone = data->timezone; | 522 | d2->timezone = data->timezone; |
523 | d2->parent = data->parent; | 523 | d2->parent = data->parent; |
524 | 524 | ||
525 | if ( data->child ) | 525 | if ( data->child ) |
526 | { | 526 | { |
527 | d2->child = new QArray<int>( *data->child ); | 527 | d2->child = new QArray<int>( *data->child ); |
528 | d2->child->detach(); | 528 | d2->child->detach(); |
529 | } | 529 | } |
530 | 530 | ||
531 | data = d2; | 531 | data = d2; |
532 | } | 532 | } |
533 | } | 533 | } |
534 | 534 | ||
535 | 535 | ||
536 | void OPimEvent::deref() | 536 | void OPimEvent::deref() |
537 | { | 537 | { |
538 | if ( data->deref() ) | 538 | if ( data->deref() ) |
539 | { | 539 | { |
540 | delete data; | 540 | delete data; |
541 | data = 0; | 541 | data = 0; |
542 | } | 542 | } |
543 | } | 543 | } |
544 | // Exporting Event data to map. Using the same | 544 | // Exporting Event data to map. Using the same |
545 | // encoding as ODateBookAccessBackend_xml does.. | 545 | // encoding as ODateBookAccessBackend_xml does.. |
546 | // Thus, we could remove the stuff there and use this | 546 | // Thus, we could remove the stuff there and use this |
547 | // for it and for all other places.. | 547 | // for it and for all other places.. |
548 | // Encoding should happen at one place, only ! (eilers) | 548 | // Encoding should happen at one place, only ! (eilers) |
549 | QMap<int, QString> OPimEvent::toMap() const | 549 | QMap<int, QString> OPimEvent::toMap() const |
550 | { | 550 | { |
551 | QMap<int, QString> retMap; | 551 | QMap<int, QString> retMap; |
552 | 552 | ||
553 | retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); | 553 | retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); |
554 | retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); | 554 | retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); |
555 | retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); | 555 | retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); |
556 | retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); | 556 | retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); |
557 | retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); | 557 | retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); |
558 | OPimAlarm alarm = notifiers().alarms() [ 0 ]; | 558 | if ( notifiers().alarms().count() ){ |
559 | retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); | 559 | // Currently we just support one alarm.. (eilers) |
560 | retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); | 560 | OPimAlarm alarm = notifiers().alarms() [ 0 ]; |
561 | retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); | ||
562 | retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); | ||
563 | } | ||
561 | 564 | ||
562 | OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); | 565 | OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); |
563 | retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); | 566 | retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); |
564 | retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); | 567 | retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); |
565 | retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); | 568 | retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); |
566 | retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); | 569 | retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); |
567 | if ( parent() ) | 570 | if ( parent() ) |
568 | retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); | 571 | retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); |
569 | if ( children().count() ) | 572 | if ( children().count() ) |
570 | { | 573 | { |
571 | QArray<int> childr = children(); | 574 | QArray<int> childr = children(); |
572 | QString buf; | 575 | QString buf; |
573 | for ( uint i = 0; i < childr.count(); i++ ) | 576 | for ( uint i = 0; i < childr.count(); i++ ) |
574 | { | 577 | { |
575 | if ( i != 0 ) buf += " "; | 578 | if ( i != 0 ) buf += " "; |
576 | buf += QString::number( childr[ i ] ); | 579 | buf += QString::number( childr[ i ] ); |
577 | } | 580 | } |
578 | retMap.insert( OPimEvent::FRecChildren, buf ); | 581 | retMap.insert( OPimEvent::FRecChildren, buf ); |
579 | } | 582 | } |
580 | 583 | ||
581 | // Add recurrence stuff | 584 | // Add recurrence stuff |
582 | if ( hasRecurrence() ) | 585 | if ( hasRecurrence() ) |
583 | { | 586 | { |
584 | OPimRecurrence recur = recurrence(); | 587 | OPimRecurrence recur = recurrence(); |
585 | QMap<int, QString> recFields = recur.toMap(); | 588 | QMap<int, QString> recFields = recur.toMap(); |
586 | retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); | 589 | retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); |
587 | retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); | 590 | retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); |
588 | retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); | 591 | retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); |
589 | retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); | 592 | retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); |
590 | retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); | 593 | retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); |
591 | retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); | 594 | retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); |
592 | retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); | 595 | retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); |
593 | retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); | 596 | retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); |
594 | } | 597 | } |
595 | else | 598 | else |
596 | { | 599 | { |
597 | OPimRecurrence recur = recurrence(); | 600 | OPimRecurrence recur = recurrence(); |
598 | QMap<int, QString> recFields = recur.toMap(); | 601 | QMap<int, QString> recFields = recur.toMap(); |
599 | retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); | 602 | retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); |
600 | } | 603 | } |
601 | 604 | ||
602 | return retMap; | 605 | return retMap; |
603 | } | 606 | } |
604 | 607 | ||
605 | 608 | ||
606 | void OPimEvent::fromMap( const QMap<int, QString>& map ) | 609 | void OPimEvent::fromMap( const QMap<int, QString>& map ) |
607 | { | 610 | { |
608 | 611 | ||
609 | // We just want to set the UID if it is really stored. | 612 | // We just want to set the UID if it is really stored. |
610 | if ( !map[ OPimEvent::FUid ].isEmpty() ) | 613 | if ( !map[ OPimEvent::FUid ].isEmpty() ) |
611 | setUid( map[ OPimEvent::FUid ].toInt() ); | 614 | setUid( map[ OPimEvent::FUid ].toInt() ); |
612 | 615 | ||
613 | setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); | 616 | setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); |
614 | setDescription( map[ OPimEvent::FDescription ] ); | 617 | setDescription( map[ OPimEvent::FDescription ] ); |
615 | setLocation( map[ OPimEvent::FLocation ] ); | 618 | setLocation( map[ OPimEvent::FLocation ] ); |
616 | 619 | ||
617 | if ( map[ OPimEvent::FType ] == "AllDay" ) | 620 | if ( map[ OPimEvent::FType ] == "AllDay" ) |
618 | setAllDay( true ); | 621 | setAllDay( true ); |
619 | else | 622 | else |
620 | setAllDay( false ); | 623 | setAllDay( false ); |
621 | 624 | ||
622 | int alarmTime = -1; | ||
623 | if ( !map[ OPimEvent::FAlarm ].isEmpty() ) | ||
624 | alarmTime = map[ OPimEvent::FAlarm ].toInt(); | ||
625 | |||
626 | int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); | ||
627 | if ( ( alarmTime != -1 ) ) | ||
628 | { | ||
629 | QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); | ||
630 | OPimAlarm al( sound , dt ); | ||
631 | notifiers().add( al ); | ||
632 | } | ||
633 | if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) | 625 | if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) |
634 | { | 626 | { |
635 | setTimeZone( map[ OPimEvent::FTimeZone ] ); | 627 | setTimeZone( map[ OPimEvent::FTimeZone ] ); |
636 | } | 628 | } |
637 | 629 | ||
638 | time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); | 630 | time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); |
639 | time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); | 631 | time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); |
640 | 632 | ||
641 | /* AllDay is always in UTC */ | 633 | /* AllDay is always in UTC */ |
642 | if ( isAllDay() ) | 634 | if ( isAllDay() ) |
643 | { | 635 | { |
644 | OPimTimeZone utc = OPimTimeZone::utc(); | 636 | OPimTimeZone utc = OPimTimeZone::utc(); |
645 | setStartDateTime( utc.fromUTCDateTime( start ) ); | 637 | setStartDateTime( utc.fromUTCDateTime( start ) ); |
646 | setEndDateTime ( utc.fromUTCDateTime( end ) ); | 638 | setEndDateTime ( utc.fromUTCDateTime( end ) ); |
647 | setTimeZone( "UTC" ); // make sure it is really utc | 639 | setTimeZone( "UTC" ); // make sure it is really utc |
648 | } | 640 | } |
649 | else | 641 | else |
650 | { | 642 | { |
651 | /* to current date time */ | 643 | /* to current date time */ |
652 | // qWarning(" Start is %d", start ); | 644 | // qWarning(" Start is %d", start ); |
653 | OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); | 645 | OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); |
654 | QDateTime date = zone.toDateTime( start ); | 646 | QDateTime date = zone.toDateTime( start ); |
655 | qWarning( " Start is %s", date.toString().latin1() ); | 647 | qWarning( " Start is %s", date.toString().latin1() ); |
656 | setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); | 648 | setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); |
657 | 649 | ||
658 | date = zone.toDateTime( end ); | 650 | date = zone.toDateTime( end ); |
659 | setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); | 651 | setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); |
660 | } | 652 | } |
661 | 653 | ||
654 | int alarmTime = -1; | ||
655 | if ( !map[ OPimEvent::FAlarm ].isEmpty() ) | ||
656 | alarmTime = map[ OPimEvent::FAlarm ].toInt(); | ||
657 | |||
658 | int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); | ||
659 | if ( ( alarmTime != -1 ) ) | ||
660 | { | ||
661 | QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); | ||
662 | OPimAlarm al( sound , dt ); | ||
663 | notifiers().add( al ); | ||
664 | } | ||
665 | |||
666 | |||
667 | if ( !map[ OPimEvent::FNote ].isEmpty() ) | ||
668 | setNote( map[ OPimEvent::FNote ] ); | ||
669 | |||
662 | if ( !map[ OPimEvent::FRecParent ].isEmpty() ) | 670 | if ( !map[ OPimEvent::FRecParent ].isEmpty() ) |
663 | setParent( map[ OPimEvent::FRecParent ].toInt() ); | 671 | setParent( map[ OPimEvent::FRecParent ].toInt() ); |
664 | 672 | ||
665 | if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) | 673 | if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) |
666 | { | 674 | { |
667 | QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); | 675 | QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); |
668 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | 676 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) |
669 | { | 677 | { |
670 | addChild( ( *it ).toInt() ); | 678 | addChild( ( *it ).toInt() ); |
671 | } | 679 | } |
672 | } | 680 | } |
673 | 681 | ||
674 | // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. | 682 | // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. |
675 | if ( !map[ OPimEvent::FRType ].isEmpty() ) | 683 | if ( !map[ OPimEvent::FRType ].isEmpty() ) |
676 | { | 684 | { |
677 | QMap<int, QString> recFields; | 685 | QMap<int, QString> recFields; |
678 | recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); | 686 | recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); |
679 | recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); | 687 | recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); |
680 | recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); | 688 | recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); |
681 | recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); | 689 | recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); |
682 | recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); | 690 | recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); |
683 | recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); | 691 | recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); |
684 | recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); | 692 | recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); |
685 | recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); | 693 | recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); |
686 | OPimRecurrence recur( recFields ); | 694 | OPimRecurrence recur( recFields ); |
687 | setRecurrence( recur ); | 695 | setRecurrence( recur ); |
688 | } | 696 | } |
689 | 697 | ||
690 | } | 698 | } |
691 | 699 | ||
692 | 700 | ||
693 | int OPimEvent::parent() const | 701 | int OPimEvent::parent() const |
694 | { | 702 | { |
695 | return data->parent; | 703 | return data->parent; |
696 | } | 704 | } |
697 | 705 | ||
698 | 706 | ||
699 | void OPimEvent::setParent( int uid ) | 707 | void OPimEvent::setParent( int uid ) |
700 | { | 708 | { |
701 | changeOrModify(); | 709 | changeOrModify(); |
702 | data->parent = uid; | 710 | data->parent = uid; |
703 | } | 711 | } |
704 | 712 | ||
705 | 713 | ||
706 | QArray<int> OPimEvent::children() const | 714 | QArray<int> OPimEvent::children() const |
707 | { | 715 | { |
708 | if ( !data->child ) return QArray<int>(); | 716 | if ( !data->child ) return QArray<int>(); |
709 | else | 717 | else |
diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h index 56fe917..5553cac 100644 --- a/libopie2/opiepim/core/opimevent.h +++ b/libopie2/opiepim/core/opimevent.h | |||
@@ -34,97 +34,97 @@ | |||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/opimtimezone.h> | 35 | #include <opie2/opimtimezone.h> |
36 | #include <opie2/opimrecord.h> | 36 | #include <opie2/opimrecord.h> |
37 | #include <qpe/recordfields.h> | 37 | #include <qpe/recordfields.h> |
38 | #include <qpe/palmtopuidgen.h> | 38 | #include <qpe/palmtopuidgen.h> |
39 | 39 | ||
40 | /* QT */ | 40 | /* QT */ |
41 | #include <qstring.h> | 41 | #include <qstring.h> |
42 | #include <qdatetime.h> | 42 | #include <qdatetime.h> |
43 | #include <qvaluelist.h> | 43 | #include <qvaluelist.h> |
44 | 44 | ||
45 | namespace Opie | 45 | namespace Opie |
46 | { | 46 | { |
47 | struct OCalendarHelper | 47 | struct OCalendarHelper |
48 | { | 48 | { |
49 | /** calculate the week number of the date */ | 49 | /** calculate the week number of the date */ |
50 | static int week( const QDate& ); | 50 | static int week( const QDate& ); |
51 | /** calculate the occurence of week days since the start of the month */ | 51 | /** calculate the occurence of week days since the start of the month */ |
52 | static int ocurrence( const QDate& ); | 52 | static int ocurrence( const QDate& ); |
53 | 53 | ||
54 | // returns the dayOfWeek for the *first* day it finds (ignores | 54 | // returns the dayOfWeek for the *first* day it finds (ignores |
55 | // any further days!). Returns 1 (Monday) if there isn't any day found | 55 | // any further days!). Returns 1 (Monday) if there isn't any day found |
56 | static int dayOfWeek( char day ); | 56 | static int dayOfWeek( char day ); |
57 | 57 | ||
58 | /** returns the diff of month */ | 58 | /** returns the diff of month */ |
59 | static int monthDiff( const QDate& first, const QDate& second ); | 59 | static int monthDiff( const QDate& first, const QDate& second ); |
60 | 60 | ||
61 | }; | 61 | }; |
62 | 62 | ||
63 | class OPimNotifyManager; | 63 | class OPimNotifyManager; |
64 | class OPimRecurrence; | 64 | class OPimRecurrence; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * This is the container for all Events. It encapsules all | 67 | * This is the container for all Events. It encapsules all |
68 | * available information for a single Event | 68 | * available information for a single Event |
69 | * @short container for events. | 69 | * @short container for events. |
70 | */ | 70 | */ |
71 | class OPimEvent : public OPimRecord | 71 | class OPimEvent : public OPimRecord |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | typedef QValueList<OPimEvent> ValueList; | 74 | typedef QValueList<OPimEvent> ValueList; |
75 | /** | 75 | /** |
76 | * RecordFields contain possible attributes | 76 | * RecordFields contain possible attributes |
77 | * used in the Results of toMap().. | 77 | * used in the Results of toMap().. |
78 | */ | 78 | */ |
79 | enum RecordFields { | 79 | enum RecordFields { |
80 | FUid = Qtopia::UID_ID, | 80 | FUid = Qtopia::UID_ID, |
81 | FCategories = Qtopia::CATEGORY_ID, | 81 | FCategories = Qtopia::CATEGORY_ID, |
82 | FDescription = 0, | 82 | FDescription /* = 0 Why this ? (eilers) */, |
83 | FLocation, | 83 | FLocation, |
84 | FType, | 84 | FType, |
85 | FAlarm, | 85 | FAlarm, |
86 | FSound, | 86 | FSound, |
87 | FRType, | 87 | FRType, |
88 | FRWeekdays, | 88 | FRWeekdays, |
89 | FRPosition, | 89 | FRPosition, |
90 | FRFreq, | 90 | FRFreq, |
91 | FRHasEndDate, | 91 | FRHasEndDate, |
92 | FREndDate, | 92 | FREndDate, |
93 | FRCreated, | 93 | FRCreated, |
94 | FRExceptions, | 94 | FRExceptions, |
95 | FStart, | 95 | FStart, |
96 | FEnd, | 96 | FEnd, |
97 | FNote, | 97 | FNote, |
98 | FTimeZone, | 98 | FTimeZone, |
99 | FRecParent, | 99 | FRecParent, |
100 | FRecChildren, | 100 | FRecChildren, |
101 | }; | 101 | }; |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Start with an Empty OPimEvent. UID == 0 means that it is empty | 104 | * Start with an Empty OPimEvent. UID == 0 means that it is empty |
105 | */ | 105 | */ |
106 | OPimEvent( int uid = 0 ); | 106 | OPimEvent( int uid = 0 ); |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * copy c'tor | 109 | * copy c'tor |
110 | */ | 110 | */ |
111 | OPimEvent( const OPimEvent& ); | 111 | OPimEvent( const OPimEvent& ); |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Create OPimEvent, initialized by map | 114 | * Create OPimEvent, initialized by map |
115 | * @see enum RecordFields | 115 | * @see enum RecordFields |
116 | */ | 116 | */ |
117 | OPimEvent( const QMap<int, QString> map ); | 117 | OPimEvent( const QMap<int, QString> map ); |
118 | ~OPimEvent(); | 118 | ~OPimEvent(); |
119 | OPimEvent &operator=( const OPimEvent& ); | 119 | OPimEvent &operator=( const OPimEvent& ); |
120 | 120 | ||
121 | QString description() const; | 121 | QString description() const; |
122 | void setDescription( const QString& description ); | 122 | void setDescription( const QString& description ); |
123 | 123 | ||
124 | QString location() const; | 124 | QString location() const; |
125 | void setLocation( const QString& loc ); | 125 | void setLocation( const QString& loc ); |
126 | 126 | ||
127 | bool hasNotifiers() const; | 127 | bool hasNotifiers() const; |
128 | OPimNotifyManager ¬ifiers() const; | 128 | OPimNotifyManager ¬ifiers() const; |
129 | 129 | ||
130 | OPimRecurrence recurrence() const; | 130 | OPimRecurrence recurrence() const; |