summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp316
1 files changed, 316 insertions, 0 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
new file mode 100644
index 0000000..0c1e3e4
--- a/dev/null
+++ b/libkcal/todo.cpp
@@ -0,0 +1,316 @@
1/*
2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
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
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <kglobal.h>
22#include <klocale.h>
23#include <kdebug.h>
24
25#include "todo.h"
26
27using namespace KCal;
28
29Todo::Todo(): Incidence()
30{
31// mStatus = TENTATIVE;
32
33 mHasDueDate = false;
34 setHasStartDate( false );
35 mCompleted = getEvenTime(QDateTime::currentDateTime());
36 mHasCompletedDate = false;
37 mPercentComplete = 0;
38}
39
40Todo::Todo(const Todo &t) : Incidence(t)
41{
42 mDtDue = t.mDtDue;
43 mHasDueDate = t.mHasDueDate;
44 mCompleted = t.mCompleted;
45 mHasCompletedDate = t.mHasCompletedDate;
46 mPercentComplete = t.mPercentComplete;
47}
48
49Todo::~Todo()
50{
51
52}
53
54Incidence *Todo::clone()
55{
56 return new Todo(*this);
57}
58
59
60bool KCal::operator==( const Todo& t1, const Todo& t2 )
61{
62
63 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
64 if ( ! ret )
65 return false;
66 if ( t1.hasDueDate() == t2.hasDueDate() ) {
67 if ( t1.hasDueDate() ) {
68 if ( t1.doesFloat() == t2.doesFloat() ) {
69 if ( t1.doesFloat() ) {
70 if ( t1.dtDue().date() != t2.dtDue().date() )
71 return false;
72 } else
73 if ( t1.dtDue() != t2.dtDue() )
74 return false;
75 } else
76 return false;// float !=
77 }
78
79 } else
80 return false;
81 if ( t1.percentComplete() != t2.percentComplete() )
82 return false;
83 if ( t1.isCompleted() ) {
84 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
85 if ( t1.hasCompletedDate() ) {
86 if ( t1.completed() != t2.completed() )
87 return false;
88 }
89
90 } else
91 return false;
92 }
93 return true;
94
95}
96
97void Todo::setDtDue(const QDateTime &dtDue)
98{
99 //int diffsecs = mDtDue.secsTo(dtDue);
100
101 /*if (mReadOnly) return;
102 const QPtrList<Alarm>& alarms = alarms();
103 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
104 if (alarm->enabled()) {
105 alarm->setTime(alarm->time().addSecs(diffsecs));
106 }
107 }*/
108 mDtDue = getEvenTime(dtDue);
109
110 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
111
112 /*const QPtrList<Alarm>& alarms = alarms();
113 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
114 alarm->setAlarmStart(mDtDue);*/
115
116 updated();
117}
118
119QDateTime Todo::dtDue() const
120{
121 return mDtDue;
122}
123
124QString Todo::dtDueTimeStr() const
125{
126 return KGlobal::locale()->formatTime(mDtDue.time());
127}
128
129QString Todo::dtDueDateStr(bool shortfmt) const
130{
131 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
132}
133
134QString Todo::dtDueStr(bool shortfmt) const
135{
136 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
137}
138
139bool Todo::hasDueDate() const
140{
141 return mHasDueDate;
142}
143
144void Todo::setHasDueDate(bool f)
145{
146 if (mReadOnly) return;
147 mHasDueDate = f;
148 updated();
149}
150
151
152#if 0
153void Todo::setStatus(const QString &statStr)
154{
155 if (mReadOnly) return;
156 QString ss(statStr.upper());
157
158 if (ss == "X-ACTION")
159 mStatus = NEEDS_ACTION;
160 else if (ss == "NEEDS ACTION")
161 mStatus = NEEDS_ACTION;
162 else if (ss == "ACCEPTED")
163 mStatus = ACCEPTED;
164 else if (ss == "SENT")
165 mStatus = SENT;
166 else if (ss == "TENTATIVE")
167 mStatus = TENTATIVE;
168 else if (ss == "CONFIRMED")
169 mStatus = CONFIRMED;
170 else if (ss == "DECLINED")
171 mStatus = DECLINED;
172 else if (ss == "COMPLETED")
173 mStatus = COMPLETED;
174 else if (ss == "DELEGATED")
175 mStatus = DELEGATED;
176
177 updated();
178}
179
180void Todo::setStatus(int status)
181{
182 if (mReadOnly) return;
183 mStatus = status;
184 updated();
185}
186
187int Todo::status() const
188{
189 return mStatus;
190}
191
192QString Todo::statusStr() const
193{
194 switch(mStatus) {
195 case NEEDS_ACTION:
196 return QString("NEEDS ACTION");
197 break;
198 case ACCEPTED:
199 return QString("ACCEPTED");
200 break;
201 case SENT:
202 return QString("SENT");
203 break;
204 case TENTATIVE:
205 return QString("TENTATIVE");
206 break;
207 case CONFIRMED:
208 return QString("CONFIRMED");
209 break;
210 case DECLINED:
211 return QString("DECLINED");
212 break;
213 case COMPLETED:
214 return QString("COMPLETED");
215 break;
216 case DELEGATED:
217 return QString("DELEGATED");
218 break;
219 }
220 return QString("");
221}
222#endif
223
224bool Todo::isCompleted() const
225{
226 if (mPercentComplete == 100) return true;
227 else return false;
228}
229
230void Todo::setCompleted(bool completed)
231{
232 if (completed) mPercentComplete = 100;
233 else mPercentComplete = 0;
234 updated();
235}
236
237QDateTime Todo::completed() const
238{
239 return mCompleted;
240}
241
242QString Todo::completedStr() const
243{
244 return KGlobal::locale()->formatDateTime(mCompleted);
245}
246
247void Todo::setCompleted(const QDateTime &completed)
248{
249 mHasCompletedDate = true;
250 mPercentComplete = 100;
251 mCompleted = getEvenTime(completed);
252 updated();
253}
254
255bool Todo::hasCompletedDate() const
256{
257 return mHasCompletedDate;
258}
259
260int Todo::percentComplete() const
261{
262 return mPercentComplete;
263}
264
265void Todo::setPercentComplete(int v)
266{
267 mPercentComplete = v;
268 updated();
269}
270QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
271{
272 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
273 *ok = false;
274 return QDateTime ();
275 }
276 QDateTime incidenceStart;
277 incidenceStart = dtDue();
278 bool enabled = false;
279 Alarm* alarm;
280 int off;
281 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
282 // if ( QDateTime::currentDateTime() > incidenceStart ){
283// *ok = false;
284// return incidenceStart;
285// }
286 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
287 if (alarm->enabled()) {
288 if ( alarm->hasTime () ) {
289 if ( alarm->time() < alarmStart ) {
290 alarmStart = alarm->time();
291 enabled = true;
292 off = alarmStart.secsTo( incidenceStart );
293 }
294
295 } else {
296 int secs = alarm->startOffset().asSeconds();
297 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
298 alarmStart = incidenceStart.addSecs( secs );
299 enabled = true;
300 off = -secs;
301 }
302 }
303 }
304 }
305 if ( enabled ) {
306 if ( alarmStart > QDateTime::currentDateTime() ) {
307 *ok = true;
308 * offset = off;
309 return alarmStart;
310 }
311 }
312 *ok = false;
313 return QDateTime ();
314
315}
316