summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimtodo.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimtodo.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp127
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
@@ -64,6 +64,7 @@ struct OPimTodo::OPimTodoData : public QShared
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;
@@ -87,17 +88,14 @@ 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
94OPimTodo::~OPimTodo() 94OPimTodo::~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 }
@@ -112,7 +110,6 @@ OPimTodo::OPimTodo( bool completed, int priority,
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;
@@ -135,7 +132,6 @@ OPimTodo::OPimTodo( bool completed, int priority,
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;
@@ -187,13 +183,33 @@ bool OPimTodo::hasDueDate() const
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 */
191bool OPimTodo::hasStartDate() const 198bool 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 */
197bool OPimTodo::hasCompletedDate() const 213bool OPimTodo::hasCompletedDate() const
198{ 214{
199 return data->completed.isValid(); 215 return data->completed.isValid();
@@ -308,7 +324,6 @@ void OPimTodo::setHasDueDate( bool hasDate )
308 324
309void OPimTodo::setDescription( const QString &desc ) 325void 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}
@@ -380,7 +395,7 @@ void OPimTodo::setMaintainer( const OPimMaintainer& pim )
380} 395}
381 396
382 397
383bool OPimTodo::isOverdue( ) 398bool 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;
@@ -593,10 +608,8 @@ bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
593void OPimTodo::deref() 608void 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 }
@@ -608,7 +621,6 @@ OPimTodo &OPimTodo::operator=( const OPimTodo &item )
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;
@@ -651,7 +663,6 @@ 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 );
@@ -699,9 +710,78 @@ QString OPimTodo::type() const
699} 710}
700 711
701 712
702QString OPimTodo::recordField( int /*id*/ ) const 713QString 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
@@ -710,4 +790,21 @@ int OPimTodo::rtti() const
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 */
804OPimTodo* 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}