Diffstat (limited to 'libopie2/opiepim/core/opimtodo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimtodo.cpp | 127 |
1 files changed, 112 insertions, 15 deletions
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp index 27b36a6..16ca987 100644 --- a/libopie2/opiepim/core/opimtodo.cpp +++ b/libopie2/opiepim/core/opimtodo.cpp | |||
@@ -55,96 +55,92 @@ struct OPimTodo::OPimTodoData : public QShared | |||
55 | OPimTodoData() : QShared() | 55 | OPimTodoData() : QShared() |
56 | { | 56 | { |
57 | recur = 0; | 57 | recur = 0; |
58 | state = 0; | 58 | state = 0; |
59 | maintainer = 0; | 59 | maintainer = 0; |
60 | notifiers = 0; | 60 | notifiers = 0; |
61 | }; | 61 | }; |
62 | ~OPimTodoData() | 62 | ~OPimTodoData() |
63 | { | 63 | { |
64 | delete recur; | 64 | delete recur; |
65 | delete maintainer; | 65 | delete maintainer; |
66 | delete notifiers; | 66 | delete notifiers; |
67 | delete state; | ||
67 | } | 68 | } |
68 | 69 | ||
69 | QDate date; | 70 | QDate date; |
70 | bool isCompleted: 1; | 71 | bool isCompleted: 1; |
71 | bool hasDate: 1; | 72 | bool hasDate: 1; |
72 | int priority; | 73 | int priority; |
73 | QString desc; | 74 | QString desc; |
74 | QString sum; | 75 | QString sum; |
75 | QMap<QString, QString> extra; | 76 | QMap<QString, QString> extra; |
76 | ushort prog; | 77 | ushort prog; |
77 | OPimState *state; | 78 | OPimState *state; |
78 | OPimRecurrence *recur; | 79 | OPimRecurrence *recur; |
79 | OPimMaintainer *maintainer; | 80 | OPimMaintainer *maintainer; |
80 | QDate start; | 81 | QDate start; |
81 | QDate completed; | 82 | QDate completed; |
82 | OPimNotifyManager *notifiers; | 83 | OPimNotifyManager *notifiers; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | 86 | ||
86 | OPimTodo::OPimTodo( const OPimTodo &event ) | 87 | OPimTodo::OPimTodo( const OPimTodo &event ) |
87 | : OPimRecord( event ), data( event.data ) | 88 | : OPimRecord( event ), data( event.data ) |
88 | { | 89 | { |
89 | data->ref(); | 90 | data->ref(); |
90 | // owarn << "ref up" << oendl; | ||
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | OPimTodo::~OPimTodo() | 94 | OPimTodo::~OPimTodo() |
95 | { | 95 | { |
96 | 96 | ||
97 | // owarn << "~OPimTodo " << oendl; | ||
98 | if ( data->deref() ) | 97 | if ( data->deref() ) |
99 | { | 98 | { |
100 | // owarn << "OPimTodo::dereffing" << oendl; | ||
101 | delete data; | 99 | delete data; |
102 | data = 0l; | 100 | data = 0l; |
103 | } | 101 | } |
104 | } | 102 | } |
105 | 103 | ||
106 | 104 | ||
107 | OPimTodo::OPimTodo( bool completed, int priority, | 105 | OPimTodo::OPimTodo( bool completed, int priority, |
108 | const QArray<int> &category, | 106 | const QArray<int> &category, |
109 | const QString& summary, | 107 | const QString& summary, |
110 | const QString &description, | 108 | const QString &description, |
111 | ushort progress, | 109 | ushort progress, |
112 | bool hasDate, QDate date, int uid ) | 110 | bool hasDate, QDate date, int uid ) |
113 | : OPimRecord( uid ) | 111 | : OPimRecord( uid ) |
114 | { | 112 | { |
115 | // owarn << "OPimTodoData " + summary << oendl; | ||
116 | setCategories( category ); | 113 | setCategories( category ); |
117 | 114 | ||
118 | data = new OPimTodoData; | 115 | data = new OPimTodoData; |
119 | 116 | ||
120 | data->date = date; | 117 | data->date = date; |
121 | data->isCompleted = completed; | 118 | data->isCompleted = completed; |
122 | data->hasDate = hasDate; | 119 | data->hasDate = hasDate; |
123 | data->priority = priority; | 120 | data->priority = priority; |
124 | data->sum = summary; | 121 | data->sum = summary; |
125 | data->prog = progress; | 122 | data->prog = progress; |
126 | data->desc = Qtopia::simplifyMultiLineSpace( description ); | 123 | data->desc = Qtopia::simplifyMultiLineSpace( description ); |
127 | } | 124 | } |
128 | 125 | ||
129 | 126 | ||
130 | OPimTodo::OPimTodo( bool completed, int priority, | 127 | OPimTodo::OPimTodo( bool completed, int priority, |
131 | const QStringList &category, | 128 | const QStringList &category, |
132 | const QString& summary, | 129 | const QString& summary, |
133 | const QString &description, | 130 | const QString &description, |
134 | ushort progress, | 131 | ushort progress, |
135 | bool hasDate, QDate date, int uid ) | 132 | bool hasDate, QDate date, int uid ) |
136 | : OPimRecord( uid ) | 133 | : OPimRecord( uid ) |
137 | { | 134 | { |
138 | // owarn << "OPimTodoData" + summary << oendl; | ||
139 | setCategories( idsFromString( category.join( ";" ) ) ); | 135 | setCategories( idsFromString( category.join( ";" ) ) ); |
140 | 136 | ||
141 | data = new OPimTodoData; | 137 | data = new OPimTodoData; |
142 | 138 | ||
143 | data->date = date; | 139 | data->date = date; |
144 | data->isCompleted = completed; | 140 | data->isCompleted = completed; |
145 | data->hasDate = hasDate; | 141 | data->hasDate = hasDate; |
146 | data->priority = priority; | 142 | data->priority = priority; |
147 | data->sum = summary; | 143 | data->sum = summary; |
148 | data->prog = progress; | 144 | data->prog = progress; |
149 | data->desc = Qtopia::simplifyMultiLineSpace( description ); | 145 | data->desc = Qtopia::simplifyMultiLineSpace( description ); |
150 | } | 146 | } |
@@ -178,31 +174,51 @@ bool OPimTodo::match( const QRegExp ®Exp ) const | |||
178 | 174 | ||
179 | bool OPimTodo::isCompleted() const | 175 | bool OPimTodo::isCompleted() const |
180 | { | 176 | { |
181 | return data->isCompleted; | 177 | return data->isCompleted; |
182 | } | 178 | } |
183 | 179 | ||
184 | 180 | ||
185 | bool OPimTodo::hasDueDate() const | 181 | bool OPimTodo::hasDueDate() const |
186 | { | 182 | { |
187 | return data->hasDate; | 183 | return data->hasDate; |
188 | } | 184 | } |
189 | 185 | ||
190 | 186 | /** | |
187 | * \brief Does this Todo have a start date | ||
188 | * | ||
189 | * Does this Todo have a start date. The decision | ||
190 | * is based on if the internal startDate isValid | ||
191 | * in the sense of QDate::isValid. | ||
192 | * | ||
193 | * @return True if the startDate isValid | ||
194 | * @see startDate | ||
195 | * @see setStartDate | ||
196 | * @see QDate::isValid() | ||
197 | */ | ||
191 | bool OPimTodo::hasStartDate() const | 198 | bool OPimTodo::hasStartDate() const |
192 | { | 199 | { |
193 | return data->start.isValid(); | 200 | return data->start.isValid(); |
194 | } | 201 | } |
195 | 202 | ||
196 | 203 | /** | |
204 | * \brief Does this Todo have a Date when it was completed | ||
205 | * | ||
206 | * As in \sa hasStartDate() it is determined if there | ||
207 | * is a completed date by looking if the internal date | ||
208 | * isValid \sa QDate::isValid. | ||
209 | * | ||
210 | * @see hasStartDate | ||
211 | * @return True if the completedDate is set and valid. | ||
212 | */ | ||
197 | bool OPimTodo::hasCompletedDate() const | 213 | bool OPimTodo::hasCompletedDate() const |
198 | { | 214 | { |
199 | return data->completed.isValid(); | 215 | return data->completed.isValid(); |
200 | } | 216 | } |
201 | 217 | ||
202 | 218 | ||
203 | int OPimTodo::priority() const | 219 | int OPimTodo::priority() const |
204 | { | 220 | { |
205 | return data->priority; | 221 | return data->priority; |
206 | } | 222 | } |
207 | 223 | ||
208 | 224 | ||
@@ -299,25 +315,24 @@ void OPimTodo::setCompleted( bool completed ) | |||
299 | } | 315 | } |
300 | 316 | ||
301 | 317 | ||
302 | void OPimTodo::setHasDueDate( bool hasDate ) | 318 | void OPimTodo::setHasDueDate( bool hasDate ) |
303 | { | 319 | { |
304 | changeOrModify(); | 320 | changeOrModify(); |
305 | data->hasDate = hasDate; | 321 | data->hasDate = hasDate; |
306 | } | 322 | } |
307 | 323 | ||
308 | 324 | ||
309 | void OPimTodo::setDescription( const QString &desc ) | 325 | void OPimTodo::setDescription( const QString &desc ) |
310 | { | 326 | { |
311 | // owarn << "desc " + desc << oendl; | ||
312 | changeOrModify(); | 327 | changeOrModify(); |
313 | data->desc = Qtopia::simplifyMultiLineSpace( desc ); | 328 | data->desc = Qtopia::simplifyMultiLineSpace( desc ); |
314 | } | 329 | } |
315 | 330 | ||
316 | 331 | ||
317 | void OPimTodo::setSummary( const QString& sum ) | 332 | void OPimTodo::setSummary( const QString& sum ) |
318 | { | 333 | { |
319 | changeOrModify(); | 334 | changeOrModify(); |
320 | data->sum = sum; | 335 | data->sum = sum; |
321 | } | 336 | } |
322 | 337 | ||
323 | 338 | ||
@@ -371,25 +386,25 @@ void OPimTodo::setRecurrence( const OPimRecurrence& rec ) | |||
371 | 386 | ||
372 | void OPimTodo::setMaintainer( const OPimMaintainer& pim ) | 387 | void OPimTodo::setMaintainer( const OPimMaintainer& pim ) |
373 | { | 388 | { |
374 | changeOrModify(); | 389 | changeOrModify(); |
375 | 390 | ||
376 | if ( data->maintainer ) | 391 | if ( data->maintainer ) |
377 | ( *data->maintainer ) = pim; | 392 | ( *data->maintainer ) = pim; |
378 | else | 393 | else |
379 | data->maintainer = new OPimMaintainer( pim ); | 394 | data->maintainer = new OPimMaintainer( pim ); |
380 | } | 395 | } |
381 | 396 | ||
382 | 397 | ||
383 | bool OPimTodo::isOverdue( ) | 398 | bool OPimTodo::isOverdue( )const |
384 | { | 399 | { |
385 | if ( data->hasDate && !data->isCompleted ) | 400 | if ( data->hasDate && !data->isCompleted ) |
386 | return QDate::currentDate() > data->date; | 401 | return QDate::currentDate() > data->date; |
387 | return false; | 402 | return false; |
388 | } | 403 | } |
389 | 404 | ||
390 | 405 | ||
391 | void OPimTodo::setProgress( ushort progress ) | 406 | void OPimTodo::setProgress( ushort progress ) |
392 | { | 407 | { |
393 | changeOrModify(); | 408 | changeOrModify(); |
394 | data->prog = progress; | 409 | data->prog = progress; |
395 | } | 410 | } |
@@ -584,40 +599,37 @@ bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const | |||
584 | if ( data->sum != toDoEvent.data->sum ) return false; | 599 | if ( data->sum != toDoEvent.data->sum ) return false; |
585 | if ( data->desc != toDoEvent.data->desc ) return false; | 600 | if ( data->desc != toDoEvent.data->desc ) return false; |
586 | if ( data->maintainer != toDoEvent.data->maintainer ) | 601 | if ( data->maintainer != toDoEvent.data->maintainer ) |
587 | return false; | 602 | return false; |
588 | 603 | ||
589 | return OPimRecord::operator==( toDoEvent ); | 604 | return OPimRecord::operator==( toDoEvent ); |
590 | } | 605 | } |
591 | 606 | ||
592 | 607 | ||
593 | void OPimTodo::deref() | 608 | void OPimTodo::deref() |
594 | { | 609 | { |
595 | 610 | ||
596 | // owarn << "deref in ToDoEvent" << oendl; | ||
597 | if ( data->deref() ) | 611 | if ( data->deref() ) |
598 | { | 612 | { |
599 | // owarn << "deleting" << oendl; | ||
600 | delete data; | 613 | delete data; |
601 | data = 0; | 614 | data = 0; |
602 | } | 615 | } |
603 | } | 616 | } |
604 | 617 | ||
605 | 618 | ||
606 | OPimTodo &OPimTodo::operator=( const OPimTodo &item ) | 619 | OPimTodo &OPimTodo::operator=( const OPimTodo &item ) |
607 | { | 620 | { |
608 | if ( this == &item ) return * this; | 621 | if ( this == &item ) return * this; |
609 | 622 | ||
610 | OPimRecord::operator=( item ); | 623 | OPimRecord::operator=( item ); |
611 | //owarn << "operator= ref " << oendl; | ||
612 | item.data->ref(); | 624 | item.data->ref(); |
613 | deref(); | 625 | deref(); |
614 | data = item.data; | 626 | data = item.data; |
615 | 627 | ||
616 | return *this; | 628 | return *this; |
617 | } | 629 | } |
618 | 630 | ||
619 | 631 | ||
620 | QMap<int, QString> OPimTodo::toMap() const | 632 | QMap<int, QString> OPimTodo::toMap() const |
621 | { | 633 | { |
622 | QMap<int, QString> map; | 634 | QMap<int, QString> map; |
623 | 635 | ||
@@ -642,25 +654,24 @@ QMap<int, QString> OPimTodo::toMap() const | |||
642 | } | 654 | } |
643 | 655 | ||
644 | 656 | ||
645 | /** | 657 | /** |
646 | * change or modify looks at the ref count and either | 658 | * change or modify looks at the ref count and either |
647 | * creates a new QShared Object or it can modify it | 659 | * creates a new QShared Object or it can modify it |
648 | * right in place | 660 | * right in place |
649 | */ | 661 | */ |
650 | void OPimTodo::changeOrModify() | 662 | void OPimTodo::changeOrModify() |
651 | { | 663 | { |
652 | if ( data->count != 1 ) | 664 | if ( data->count != 1 ) |
653 | { | 665 | { |
654 | owarn << "changeOrModify" << oendl; | ||
655 | data->deref(); | 666 | data->deref(); |
656 | OPimTodoData* d2 = new OPimTodoData(); | 667 | OPimTodoData* d2 = new OPimTodoData(); |
657 | copy( data, d2 ); | 668 | copy( data, d2 ); |
658 | data = d2; | 669 | data = d2; |
659 | } | 670 | } |
660 | } | 671 | } |
661 | 672 | ||
662 | 673 | ||
663 | // WATCHOUT | 674 | // WATCHOUT |
664 | /* | 675 | /* |
665 | * if you add something to the Data struct | 676 | * if you add something to the Data struct |
666 | * be sure to copy it here | 677 | * be sure to copy it here |
@@ -690,24 +701,110 @@ void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) | |||
690 | 701 | ||
691 | if ( src->notifiers ) | 702 | if ( src->notifiers ) |
692 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | 703 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); |
693 | } | 704 | } |
694 | 705 | ||
695 | 706 | ||
696 | QString OPimTodo::type() const | 707 | QString OPimTodo::type() const |
697 | { | 708 | { |
698 | return QString::fromLatin1( "OPimTodo" ); | 709 | return QString::fromLatin1( "OPimTodo" ); |
699 | } | 710 | } |
700 | 711 | ||
701 | 712 | ||
702 | QString OPimTodo::recordField( int /*id*/ ) const | 713 | QString OPimTodo::recordField( int id) const |
703 | { | 714 | { |
704 | return QString::null; | 715 | QString res; |
716 | Q_UNUSED( id ) | ||
717 | #if 0 | ||
718 | switch( id ) { | ||
719 | case HasDate: | ||
720 | res = (hasDueDate() ? | ||
721 | QObject::tr( "Has a due-date" ) | ||
722 | : QObject::tr( "No due-date" )); | ||
723 | break; | ||
724 | case Completed: | ||
725 | res = ( isCompleted() ? | ||
726 | QObject::tr( "Completed" ) : | ||
727 | QObject::tr( "Not completed" )); | ||
728 | break; | ||
729 | case Description: | ||
730 | res = description(); | ||
731 | break; | ||
732 | case Summary: | ||
733 | res = summary(); | ||
734 | break; | ||
735 | case Priority: | ||
736 | res = QString::number( priority() ); | ||
737 | break; | ||
738 | case DateDay: | ||
739 | res = QString::number( dueDate().day() ); | ||
740 | break; | ||
741 | case DateMonth: | ||
742 | res = QString::number( dueDate().month() ); | ||
743 | break; | ||
744 | case DateYear: | ||
745 | res = QString::number( dueDate().year() ); | ||
746 | break; | ||
747 | case Progress: | ||
748 | res = QString::number( progress() ); | ||
749 | break; | ||
750 | case State: | ||
751 | res = QString::number( state().state() ); | ||
752 | break; | ||
753 | case Recurrence: | ||
754 | res = ( hasRecurrence() ? | ||
755 | QString::null /*recurrence().summary()*/ : | ||
756 | QObject::tr("No reccurrence")); | ||
757 | break; | ||
758 | case Alarms: | ||
759 | break; | ||
760 | case Reminders: | ||
761 | break; | ||
762 | case Maintainer: | ||
763 | break; | ||
764 | case StartDate: | ||
765 | res = ( hasStartDate() ? | ||
766 | /*TimeString::()*/ QString::null : | ||
767 | QObject::tr( "No start-date" ) ); | ||
768 | break; | ||
769 | case CompletedDate: | ||
770 | res = ( hasCompletedDate() ? | ||
771 | /*TimeString::()*/ QString::null : | ||
772 | QObject::tr( "No completed-date" ) ); | ||
773 | break; | ||
774 | case DueDate: | ||
775 | res = ( hasDueDate() ? | ||
776 | /*TimeString::()*/ QString::null : | ||
777 | QObject::tr( "No due-date" ); | ||
778 | break; | ||
779 | default: | ||
780 | res = OPimRecord::recordField( id ); | ||
781 | } | ||
782 | |||
783 | #endif | ||
784 | return res; | ||
705 | } | 785 | } |
706 | 786 | ||
707 | 787 | ||
708 | int OPimTodo::rtti() const | 788 | int OPimTodo::rtti() const |
709 | { | 789 | { |
710 | return OPimResolver::TodoList; | 790 | return OPimResolver::TodoList; |
711 | } | 791 | } |
712 | 792 | ||
793 | /** | ||
794 | * \brief Provide a SafeCast to OPimTodo from a OPimRecord | ||
795 | * | ||
796 | * Provide a safe cast that will return 0 if the record | ||
797 | * type is not OPimTodo. In the other case it will | ||
798 | * be casted to OPimTodo and returned | ||
799 | * | ||
800 | * @param rec The OPimRecord to be casted | ||
801 | * | ||
802 | * @return a pointer to OPimTodo or 0l | ||
803 | */ | ||
804 | OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) { | ||
805 | return (rec && rec->rtti() == OPimResolver::TodoList ) ? | ||
806 | static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) : | ||
807 | 0l; | ||
808 | } | ||
809 | |||
713 | } | 810 | } |