summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 0c1e3e4..3d2de61 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,187 +1,245 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "todo.h" 25#include "todo.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Todo::Todo(): Incidence() 29Todo::Todo(): Incidence()
30{ 30{
31// mStatus = TENTATIVE; 31// mStatus = TENTATIVE;
32 32
33 mHasDueDate = false; 33 mHasDueDate = false;
34 setHasStartDate( false ); 34 setHasStartDate( false );
35 mCompleted = getEvenTime(QDateTime::currentDateTime()); 35 mCompleted = getEvenTime(QDateTime::currentDateTime());
36 mHasCompletedDate = false; 36 mHasCompletedDate = false;
37 mPercentComplete = 0; 37 mPercentComplete = 0;
38} 38}
39 39
40Todo::Todo(const Todo &t) : Incidence(t) 40Todo::Todo(const Todo &t) : Incidence(t)
41{ 41{
42 mDtDue = t.mDtDue; 42 mDtDue = t.mDtDue;
43 mHasDueDate = t.mHasDueDate; 43 mHasDueDate = t.mHasDueDate;
44 mCompleted = t.mCompleted; 44 mCompleted = t.mCompleted;
45 mHasCompletedDate = t.mHasCompletedDate; 45 mHasCompletedDate = t.mHasCompletedDate;
46 mPercentComplete = t.mPercentComplete; 46 mPercentComplete = t.mPercentComplete;
47} 47}
48 48
49Todo::~Todo() 49Todo::~Todo()
50{ 50{
51 51
52} 52}
53 53
54Incidence *Todo::clone() 54Incidence *Todo::clone()
55{ 55{
56 return new Todo(*this); 56 return new Todo(*this);
57} 57}
58 58
59bool Todo::contains ( Todo* from )
60{
59 61
62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() ))
64 return false;
65 if ( from->hasStartDate() ) {
66 if ( !hasStartDate() )
67 return false;
68 if ( from->dtStart() != dtStart())
69 return false;
70 }
71 if ( from->hasDueDate() ){
72 if ( !hasDueDate() )
73 return false;
74 if ( from->dtDue() != dtDue())
75 return false;
76 }
77 if ( !from->location().isEmpty() )
78 if ( !location().startsWith( from->location() ) )
79 return false;
80 if ( !from->description().isEmpty() )
81 if ( !description().startsWith( from->description() ))
82 return false;
83 if ( from->alarms().count() ) {
84 Alarm *a = from->alarms().first();
85 if ( a->enabled() ){
86 if ( !alarms().count() )
87 return false;
88 Alarm *b = alarms().first();
89 if( ! b->enabled() )
90 return false;
91 if ( ! (a->offset() == b->offset() ))
92 return false;
93 }
94 }
95
96 QStringList cat = categories();
97 QStringList catFrom = from->categories();
98 QString nCat;
99 int iii;
100 for ( iii = 0; iii < catFrom.count();++iii ) {
101 nCat = catFrom[iii];
102 if ( !nCat.isEmpty() )
103 if ( !cat.contains( nCat )) {
104 return false;
105 }
106 }
107 if ( from->isCompleted() ) {
108 if ( !isCompleted() )
109 return false;
110 }
111 if( priority() != from->priority() )
112 return false;
113
114
115 return true;
116
117}
60bool KCal::operator==( const Todo& t1, const Todo& t2 ) 118bool KCal::operator==( const Todo& t1, const Todo& t2 )
61{ 119{
62 120
63 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
64 if ( ! ret ) 122 if ( ! ret )
65 return false; 123 return false;
66 if ( t1.hasDueDate() == t2.hasDueDate() ) { 124 if ( t1.hasDueDate() == t2.hasDueDate() ) {
67 if ( t1.hasDueDate() ) { 125 if ( t1.hasDueDate() ) {
68 if ( t1.doesFloat() == t2.doesFloat() ) { 126 if ( t1.doesFloat() == t2.doesFloat() ) {
69 if ( t1.doesFloat() ) { 127 if ( t1.doesFloat() ) {
70 if ( t1.dtDue().date() != t2.dtDue().date() ) 128 if ( t1.dtDue().date() != t2.dtDue().date() )
71 return false; 129 return false;
72 } else 130 } else
73 if ( t1.dtDue() != t2.dtDue() ) 131 if ( t1.dtDue() != t2.dtDue() )
74 return false; 132 return false;
75 } else 133 } else
76 return false;// float != 134 return false;// float !=
77 } 135 }
78 136
79 } else 137 } else
80 return false; 138 return false;
81 if ( t1.percentComplete() != t2.percentComplete() ) 139 if ( t1.percentComplete() != t2.percentComplete() )
82 return false; 140 return false;
83 if ( t1.isCompleted() ) { 141 if ( t1.isCompleted() ) {
84 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
85 if ( t1.hasCompletedDate() ) { 143 if ( t1.hasCompletedDate() ) {
86 if ( t1.completed() != t2.completed() ) 144 if ( t1.completed() != t2.completed() )
87 return false; 145 return false;
88 } 146 }
89 147
90 } else 148 } else
91 return false; 149 return false;
92 } 150 }
93 return true; 151 return true;
94 152
95} 153}
96 154
97void Todo::setDtDue(const QDateTime &dtDue) 155void Todo::setDtDue(const QDateTime &dtDue)
98{ 156{
99 //int diffsecs = mDtDue.secsTo(dtDue); 157 //int diffsecs = mDtDue.secsTo(dtDue);
100 158
101 /*if (mReadOnly) return; 159 /*if (mReadOnly) return;
102 const QPtrList<Alarm>& alarms = alarms(); 160 const QPtrList<Alarm>& alarms = alarms();
103 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
104 if (alarm->enabled()) { 162 if (alarm->enabled()) {
105 alarm->setTime(alarm->time().addSecs(diffsecs)); 163 alarm->setTime(alarm->time().addSecs(diffsecs));
106 } 164 }
107 }*/ 165 }*/
108 mDtDue = getEvenTime(dtDue); 166 mDtDue = getEvenTime(dtDue);
109 167
110 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
111 169
112 /*const QPtrList<Alarm>& alarms = alarms(); 170 /*const QPtrList<Alarm>& alarms = alarms();
113 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
114 alarm->setAlarmStart(mDtDue);*/ 172 alarm->setAlarmStart(mDtDue);*/
115 173
116 updated(); 174 updated();
117} 175}
118 176
119QDateTime Todo::dtDue() const 177QDateTime Todo::dtDue() const
120{ 178{
121 return mDtDue; 179 return mDtDue;
122} 180}
123 181
124QString Todo::dtDueTimeStr() const 182QString Todo::dtDueTimeStr() const
125{ 183{
126 return KGlobal::locale()->formatTime(mDtDue.time()); 184 return KGlobal::locale()->formatTime(mDtDue.time());
127} 185}
128 186
129QString Todo::dtDueDateStr(bool shortfmt) const 187QString Todo::dtDueDateStr(bool shortfmt) const
130{ 188{
131 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
132} 190}
133 191
134QString Todo::dtDueStr(bool shortfmt) const 192QString Todo::dtDueStr(bool shortfmt) const
135{ 193{
136 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
137} 195}
138 196
139bool Todo::hasDueDate() const 197bool Todo::hasDueDate() const
140{ 198{
141 return mHasDueDate; 199 return mHasDueDate;
142} 200}
143 201
144void Todo::setHasDueDate(bool f) 202void Todo::setHasDueDate(bool f)
145{ 203{
146 if (mReadOnly) return; 204 if (mReadOnly) return;
147 mHasDueDate = f; 205 mHasDueDate = f;
148 updated(); 206 updated();
149} 207}
150 208
151 209
152#if 0 210#if 0
153void Todo::setStatus(const QString &statStr) 211void Todo::setStatus(const QString &statStr)
154{ 212{
155 if (mReadOnly) return; 213 if (mReadOnly) return;
156 QString ss(statStr.upper()); 214 QString ss(statStr.upper());
157 215
158 if (ss == "X-ACTION") 216 if (ss == "X-ACTION")
159 mStatus = NEEDS_ACTION; 217 mStatus = NEEDS_ACTION;
160 else if (ss == "NEEDS ACTION") 218 else if (ss == "NEEDS ACTION")
161 mStatus = NEEDS_ACTION; 219 mStatus = NEEDS_ACTION;
162 else if (ss == "ACCEPTED") 220 else if (ss == "ACCEPTED")
163 mStatus = ACCEPTED; 221 mStatus = ACCEPTED;
164 else if (ss == "SENT") 222 else if (ss == "SENT")
165 mStatus = SENT; 223 mStatus = SENT;
166 else if (ss == "TENTATIVE") 224 else if (ss == "TENTATIVE")
167 mStatus = TENTATIVE; 225 mStatus = TENTATIVE;
168 else if (ss == "CONFIRMED") 226 else if (ss == "CONFIRMED")
169 mStatus = CONFIRMED; 227 mStatus = CONFIRMED;
170 else if (ss == "DECLINED") 228 else if (ss == "DECLINED")
171 mStatus = DECLINED; 229 mStatus = DECLINED;
172 else if (ss == "COMPLETED") 230 else if (ss == "COMPLETED")
173 mStatus = COMPLETED; 231 mStatus = COMPLETED;
174 else if (ss == "DELEGATED") 232 else if (ss == "DELEGATED")
175 mStatus = DELEGATED; 233 mStatus = DELEGATED;
176 234
177 updated(); 235 updated();
178} 236}
179 237
180void Todo::setStatus(int status) 238void Todo::setStatus(int status)
181{ 239{
182 if (mReadOnly) return; 240 if (mReadOnly) return;
183 mStatus = status; 241 mStatus = status;
184 updated(); 242 updated();
185} 243}
186 244
187int Todo::status() const 245int Todo::status() const