Diffstat (limited to 'libopie2/opiepim/core/opimtodo.cpp') (more/less context) (show 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 | |||
@@ -61,12 +61,13 @@ struct OPimTodo::OPimTodoData : public QShared | |||
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; |
@@ -84,23 +85,20 @@ struct OPimTodo::OPimTodoData : public QShared | |||
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 | ||
@@ -109,13 +107,12 @@ OPimTodo::OPimTodo( bool completed, int priority, | |||
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; |
@@ -132,13 +129,12 @@ OPimTodo::OPimTodo( bool completed, int priority, | |||
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; |
@@ -184,19 +180,39 @@ bool OPimTodo::isCompleted() const | |||
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 | ||
@@ -305,13 +321,12 @@ void OPimTodo::setHasDueDate( bool hasDate ) | |||
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 ) |
@@ -377,13 +392,13 @@ void OPimTodo::setMaintainer( const OPimMaintainer& pim ) | |||
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 | ||
@@ -590,28 +605,25 @@ bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const | |||
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 | } |
@@ -648,13 +660,12 @@ QMap<int, QString> OPimTodo::toMap() const | |||
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 | } |
@@ -696,18 +707,104 @@ void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) | |||
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 | } |