summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-03-07 18:08:51 (UTC)
committer zautrix <zautrix>2005-03-07 18:08:51 (UTC)
commit668f49ee87c1b3b51e103ed8bb570a035c96b546 (patch) (unidiff)
tree9310b2a5f19589641c7bab924e87599c021141a1 /libkcal
parent55c82dcc9b3c04c06b4eb73654d2b7f09a2e502c (diff)
downloadkdepimpi-668f49ee87c1b3b51e103ed8bb570a035c96b546.zip
kdepimpi-668f49ee87c1b3b51e103ed8bb570a035c96b546.tar.gz
kdepimpi-668f49ee87c1b3b51e103ed8bb570a035c96b546.tar.bz2
start datetime fix for float
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidencebase.cpp4
-rw-r--r--libkcal/todo.cpp4
2 files changed, 6 insertions, 2 deletions
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 1e99082..b5fe2e6 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,427 +1,429 @@
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#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47} 47}
48 48
49IncidenceBase::IncidenceBase(const IncidenceBase &i) : 49IncidenceBase::IncidenceBase(const IncidenceBase &i) :
50 CustomProperties( i ) 50 CustomProperties( i )
51{ 51{
52 mReadOnly = i.mReadOnly; 52 mReadOnly = i.mReadOnly;
53 mDtStart = i.mDtStart; 53 mDtStart = i.mDtStart;
54 mDuration = i.mDuration; 54 mDuration = i.mDuration;
55 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
56 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
57 mUid = i.mUid; 57 mUid = i.mUid;
58 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
60 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
61 } 61 }
62 mFloats = i.mFloats; 62 mFloats = i.mFloats;
63 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
64 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
65 mTempSyncStat = i.mTempSyncStat; 65 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 66 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 67 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 68 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 69 // of the original object.
70 mObservers.clear(); 70 mObservers.clear();
71 71
72 mAttendees.setAutoDelete( true ); 72 mAttendees.setAutoDelete( true );
73} 73}
74 74
75IncidenceBase::~IncidenceBase() 75IncidenceBase::~IncidenceBase()
76{ 76{
77} 77}
78 78
79 79
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 81{
82 // do not compare mSyncStatus and mExternalId 82 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 83 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 84 return false; // no need to check further
85 } 85 }
86 if ( i1.attendees().count() > 0 ) { 86 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 88 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 89 if ( !( (*a1) == (*a2)) )
90 { 90 {
91 //qDebug("Attendee not equal "); 91 //qDebug("Attendee not equal ");
92 return false; 92 return false;
93 } 93 }
94 a1 = i1.attendees().next(); 94 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 95 a2 = i2.attendees().next();
96 } 96 }
97 } 97 }
98 //if ( i1.dtStart() != i2.dtStart() ) 98 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 99 // return false;
100#if 0 100#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 102 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 106 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 107
108#endif 108#endif
109 if ( i1.hasDuration() == i2.hasDuration() ) { 109 if ( i1.hasDuration() == i2.hasDuration() ) {
110 if ( i1.hasDuration() ) { 110 if ( i1.hasDuration() ) {
111 if ( i1.duration() != i2.duration() ) 111 if ( i1.duration() != i2.duration() )
112 return false; 112 return false;
113 } 113 }
114 } else { 114 } else {
115 return false; 115 return false;
116 } 116 }
117 117
118 return ( i1.organizer() == i2.organizer() && 118 return ( i1.organizer() == i2.organizer() &&
119 // i1.uid() == i2.uid() && 119 // i1.uid() == i2.uid() &&
120 // Don't compare lastModified, otherwise the operator is not 120 // Don't compare lastModified, otherwise the operator is not
121 // of much use. We are not comparing for identity, after all. 121 // of much use. We are not comparing for identity, after all.
122 i1.doesFloat() == i2.doesFloat() && 122 i1.doesFloat() == i2.doesFloat() &&
123 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 123 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
124 // no need to compare mObserver 124 // no need to compare mObserver
125} 125}
126 126
127 127
128QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 128QDateTime IncidenceBase::getEvenTime( QDateTime dt )
129{ 129{
130 QTime t = dt.time(); 130 QTime t = dt.time();
131 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 131 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
132 return dt; 132 return dt;
133} 133}
134 134
135 135
136void IncidenceBase::setUid(const QString &uid) 136void IncidenceBase::setUid(const QString &uid)
137{ 137{
138 mUid = uid; 138 mUid = uid;
139 updated(); 139 updated();
140} 140}
141 141
142QString IncidenceBase::uid() const 142QString IncidenceBase::uid() const
143{ 143{
144 return mUid; 144 return mUid;
145} 145}
146 146
147void IncidenceBase::setLastModified(const QDateTime &lm) 147void IncidenceBase::setLastModified(const QDateTime &lm)
148{ 148{
149 // DON'T! updated() because we call this from 149 // DON'T! updated() because we call this from
150 // Calendar::updateEvent(). 150 // Calendar::updateEvent().
151 mLastModified = getEvenTime(lm); 151 mLastModified = getEvenTime(lm);
152 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 152 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
153} 153}
154 154
155QDateTime IncidenceBase::lastModified() const 155QDateTime IncidenceBase::lastModified() const
156{ 156{
157 return mLastModified; 157 return mLastModified;
158} 158}
159 159
160void IncidenceBase::setOrganizer(const QString &o) 160void IncidenceBase::setOrganizer(const QString &o)
161{ 161{
162 // we don't check for readonly here, because it is 162 // we don't check for readonly here, because it is
163 // possible that by setting the organizer we are changing 163 // possible that by setting the organizer we are changing
164 // the event's readonly status... 164 // the event's readonly status...
165 mOrganizer = o; 165 mOrganizer = o;
166 if (mOrganizer.left(7).upper() == "MAILTO:") 166 if (mOrganizer.left(7).upper() == "MAILTO:")
167 mOrganizer = mOrganizer.remove(0,7); 167 mOrganizer = mOrganizer.remove(0,7);
168 168
169 updated(); 169 updated();
170} 170}
171 171
172QString IncidenceBase::organizer() const 172QString IncidenceBase::organizer() const
173{ 173{
174 return mOrganizer; 174 return mOrganizer;
175} 175}
176 176
177void IncidenceBase::setReadOnly( bool readOnly ) 177void IncidenceBase::setReadOnly( bool readOnly )
178{ 178{
179 mReadOnly = readOnly; 179 mReadOnly = readOnly;
180} 180}
181 181
182void IncidenceBase::setDtStart(const QDateTime &dtStart) 182void IncidenceBase::setDtStart(const QDateTime &dtStart)
183{ 183{
184// if (mReadOnly) return; 184// if (mReadOnly) return;
185 mDtStart = getEvenTime(dtStart); 185 mDtStart = getEvenTime(dtStart);
186 updated(); 186 updated();
187} 187}
188 188
189 189
190QDateTime IncidenceBase::dtStart() const 190QDateTime IncidenceBase::dtStart() const
191{ 191{
192 return mDtStart; 192 return mDtStart;
193} 193}
194 194
195QString IncidenceBase::dtStartTimeStr() const 195QString IncidenceBase::dtStartTimeStr() const
196{ 196{
197 return KGlobal::locale()->formatTime(dtStart().time()); 197 return KGlobal::locale()->formatTime(dtStart().time());
198} 198}
199 199
200QString IncidenceBase::dtStartDateStr(bool shortfmt) const 200QString IncidenceBase::dtStartDateStr(bool shortfmt) const
201{ 201{
202 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 202 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
203} 203}
204 204
205QString IncidenceBase::dtStartStr(bool shortfmt) const 205QString IncidenceBase::dtStartStr(bool shortfmt) const
206{ 206{
207 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 207 if ( doesFloat() )
208 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
209 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
208} 210}
209 211
210 212
211bool IncidenceBase::doesFloat() const 213bool IncidenceBase::doesFloat() const
212{ 214{
213 return mFloats; 215 return mFloats;
214} 216}
215 217
216void IncidenceBase::setFloats(bool f) 218void IncidenceBase::setFloats(bool f)
217{ 219{
218 if (mReadOnly) return; 220 if (mReadOnly) return;
219 mFloats = f; 221 mFloats = f;
220 updated(); 222 updated();
221} 223}
222 224
223 225
224bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 226bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
225{ 227{
226 if (mReadOnly) return false; 228 if (mReadOnly) return false;
227 if (a->name().left(7).upper() == "MAILTO:") 229 if (a->name().left(7).upper() == "MAILTO:")
228 a->setName(a->name().remove(0,7)); 230 a->setName(a->name().remove(0,7));
229 231
230 QPtrListIterator<Attendee> qli(mAttendees); 232 QPtrListIterator<Attendee> qli(mAttendees);
231 233
232 qli.toFirst(); 234 qli.toFirst();
233 while (qli) { 235 while (qli) {
234 if (*qli.current() == *a) 236 if (*qli.current() == *a)
235 return false; 237 return false;
236 ++qli; 238 ++qli;
237 } 239 }
238 mAttendees.append(a); 240 mAttendees.append(a);
239 if (doupdate) updated(); 241 if (doupdate) updated();
240 return true; 242 return true;
241} 243}
242 244
243#if 0 245#if 0
244void IncidenceBase::removeAttendee(Attendee *a) 246void IncidenceBase::removeAttendee(Attendee *a)
245{ 247{
246 if (mReadOnly) return; 248 if (mReadOnly) return;
247 mAttendees.removeRef(a); 249 mAttendees.removeRef(a);
248 updated(); 250 updated();
249} 251}
250 252
251void IncidenceBase::removeAttendee(const char *n) 253void IncidenceBase::removeAttendee(const char *n)
252{ 254{
253 Attendee *a; 255 Attendee *a;
254 256
255 if (mReadOnly) return; 257 if (mReadOnly) return;
256 for (a = mAttendees.first(); a; a = mAttendees.next()) 258 for (a = mAttendees.first(); a; a = mAttendees.next())
257 if (a->getName() == n) { 259 if (a->getName() == n) {
258 mAttendees.remove(); 260 mAttendees.remove();
259 break; 261 break;
260 } 262 }
261} 263}
262#endif 264#endif
263 265
264void IncidenceBase::clearAttendees() 266void IncidenceBase::clearAttendees()
265{ 267{
266 if (mReadOnly) return; 268 if (mReadOnly) return;
267 mAttendees.clear(); 269 mAttendees.clear();
268} 270}
269 271
270#if 0 272#if 0
271Attendee *IncidenceBase::getAttendee(const char *n) const 273Attendee *IncidenceBase::getAttendee(const char *n) const
272{ 274{
273 QPtrListIterator<Attendee> qli(mAttendees); 275 QPtrListIterator<Attendee> qli(mAttendees);
274 276
275 qli.toFirst(); 277 qli.toFirst();
276 while (qli) { 278 while (qli) {
277 if (qli.current()->getName() == n) 279 if (qli.current()->getName() == n)
278 return qli.current(); 280 return qli.current();
279 ++qli; 281 ++qli;
280 } 282 }
281 return 0L; 283 return 0L;
282} 284}
283#endif 285#endif
284 286
285Attendee *IncidenceBase::attendeeByMail(const QString &email) 287Attendee *IncidenceBase::attendeeByMail(const QString &email)
286{ 288{
287 QPtrListIterator<Attendee> qli(mAttendees); 289 QPtrListIterator<Attendee> qli(mAttendees);
288 290
289 qli.toFirst(); 291 qli.toFirst();
290 while (qli) { 292 while (qli) {
291 if (qli.current()->email().lower() == email.lower()) 293 if (qli.current()->email().lower() == email.lower())
292 return qli.current(); 294 return qli.current();
293 ++qli; 295 ++qli;
294 } 296 }
295 return 0L; 297 return 0L;
296} 298}
297 299
298Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 300Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
299{ 301{
300 QPtrListIterator<Attendee> qli(mAttendees); 302 QPtrListIterator<Attendee> qli(mAttendees);
301 303
302 QStringList mails = emails; 304 QStringList mails = emails;
303 if (!email.isEmpty()) { 305 if (!email.isEmpty()) {
304 mails.append(email); 306 mails.append(email);
305 } 307 }
306 qli.toFirst(); 308 qli.toFirst();
307 while (qli) { 309 while (qli) {
308 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 310 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
309 if (qli.current()->email().lower() == (*it).lower()) 311 if (qli.current()->email().lower() == (*it).lower())
310 return qli.current(); 312 return qli.current();
311 } 313 }
312 314
313 ++qli; 315 ++qli;
314 } 316 }
315 return 0L; 317 return 0L;
316} 318}
317 319
318void IncidenceBase::setDuration(int seconds) 320void IncidenceBase::setDuration(int seconds)
319{ 321{
320 mDuration = seconds; 322 mDuration = seconds;
321 setHasDuration(true); 323 setHasDuration(true);
322} 324}
323 325
324int IncidenceBase::duration() const 326int IncidenceBase::duration() const
325{ 327{
326 return mDuration; 328 return mDuration;
327} 329}
328 330
329void IncidenceBase::setHasDuration(bool b) 331void IncidenceBase::setHasDuration(bool b)
330{ 332{
331 mHasDuration = b; 333 mHasDuration = b;
332} 334}
333 335
334bool IncidenceBase::hasDuration() const 336bool IncidenceBase::hasDuration() const
335{ 337{
336 return mHasDuration; 338 return mHasDuration;
337} 339}
338 340
339void IncidenceBase::setSyncStatus(int stat) 341void IncidenceBase::setSyncStatus(int stat)
340{ 342{
341 if (mReadOnly) return; 343 if (mReadOnly) return;
342 mSyncStatus = stat; 344 mSyncStatus = stat;
343} 345}
344 346
345int IncidenceBase::syncStatus() const 347int IncidenceBase::syncStatus() const
346{ 348{
347 return mSyncStatus; 349 return mSyncStatus;
348} 350}
349 351
350void IncidenceBase::setPilotId( int id ) 352void IncidenceBase::setPilotId( int id )
351{ 353{
352 if (mReadOnly) return; 354 if (mReadOnly) return;
353 mPilotId = id; 355 mPilotId = id;
354} 356}
355 357
356int IncidenceBase::pilotId() const 358int IncidenceBase::pilotId() const
357{ 359{
358 return mPilotId; 360 return mPilotId;
359} 361}
360 362
361int IncidenceBase::tempSyncStat() const 363int IncidenceBase::tempSyncStat() const
362{ 364{
363 return mTempSyncStat; 365 return mTempSyncStat;
364} 366}
365void IncidenceBase::setTempSyncStat( int id ) 367void IncidenceBase::setTempSyncStat( int id )
366{ 368{
367 if (mReadOnly) return; 369 if (mReadOnly) return;
368 mTempSyncStat = id; 370 mTempSyncStat = id;
369} 371}
370 372
371void IncidenceBase::removeID(const QString &prof) 373void IncidenceBase::removeID(const QString &prof)
372{ 374{
373 if ( prof.isEmpty() ) 375 if ( prof.isEmpty() )
374 mExternalId = ":"; 376 mExternalId = ":";
375 else 377 else
376 mExternalId = KIdManager::removeId ( mExternalId, prof); 378 mExternalId = KIdManager::removeId ( mExternalId, prof);
377 379
378} 380}
379void IncidenceBase::setID( const QString & prof , const QString & id ) 381void IncidenceBase::setID( const QString & prof , const QString & id )
380{ 382{
381 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 383 mExternalId = KIdManager::setId ( mExternalId, prof, id );
382} 384}
383QString IncidenceBase::getID( const QString & prof) 385QString IncidenceBase::getID( const QString & prof)
384{ 386{
385 return KIdManager::getId ( mExternalId, prof ); 387 return KIdManager::getId ( mExternalId, prof );
386} 388}
387 389
388// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 390// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
389// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 391// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
390void IncidenceBase::setCsum( const QString & prof , const QString & id ) 392void IncidenceBase::setCsum( const QString & prof , const QString & id )
391{ 393{
392 mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); 394 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
393} 395}
394QString IncidenceBase::getCsum( const QString & prof) 396QString IncidenceBase::getCsum( const QString & prof)
395{ 397{
396 return KIdManager::getCsum ( mExternalId, prof ); 398 return KIdManager::getCsum ( mExternalId, prof );
397} 399}
398 400
399void IncidenceBase::setIDStr( const QString & s ) 401void IncidenceBase::setIDStr( const QString & s )
400{ 402{
401 if (mReadOnly) return; 403 if (mReadOnly) return;
402 mExternalId = s; 404 mExternalId = s;
403} 405}
404 406
405QString IncidenceBase::IDStr() const 407QString IncidenceBase::IDStr() const
406{ 408{
407 return mExternalId ; 409 return mExternalId ;
408} 410}
409void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 411void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
410{ 412{
411 if( !mObservers.contains(observer) ) mObservers.append( observer ); 413 if( !mObservers.contains(observer) ) mObservers.append( observer );
412} 414}
413 415
414void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 416void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
415{ 417{
416 mObservers.remove( observer ); 418 mObservers.remove( observer );
417} 419}
418 420
419void IncidenceBase::updated() 421void IncidenceBase::updated()
420{ 422{
421 QPtrListIterator<Observer> it(mObservers); 423 QPtrListIterator<Observer> it(mObservers);
422 while( it.current() ) { 424 while( it.current() ) {
423 Observer *o = it.current(); 425 Observer *o = it.current();
424 ++it; 426 ++it;
425 o->incidenceUpdated( this ); 427 o->incidenceUpdated( this );
426 } 428 }
427} 429}
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 39d16b6..a496404 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,457 +1,459 @@
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 ) 59bool Todo::contains ( Todo* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->hasStartDate() ) { 65 if ( from->hasStartDate() ) {
66 if ( !hasStartDate() ) 66 if ( !hasStartDate() )
67 return false; 67 return false;
68 if ( from->dtStart() != dtStart()) 68 if ( from->dtStart() != dtStart())
69 return false; 69 return false;
70 } 70 }
71 if ( from->hasDueDate() ){ 71 if ( from->hasDueDate() ){
72 if ( !hasDueDate() ) 72 if ( !hasDueDate() )
73 return false; 73 return false;
74 if ( from->dtDue() != dtDue()) 74 if ( from->dtDue() != dtDue())
75 return false; 75 return false;
76 } 76 }
77 if ( !from->location().isEmpty() ) 77 if ( !from->location().isEmpty() )
78 if ( !location().startsWith( from->location() ) ) 78 if ( !location().startsWith( from->location() ) )
79 return false; 79 return false;
80 if ( !from->description().isEmpty() ) 80 if ( !from->description().isEmpty() )
81 if ( !description().startsWith( from->description() )) 81 if ( !description().startsWith( from->description() ))
82 return false; 82 return false;
83 if ( from->alarms().count() ) { 83 if ( from->alarms().count() ) {
84 Alarm *a = from->alarms().first(); 84 Alarm *a = from->alarms().first();
85 if ( a->enabled() ){ 85 if ( a->enabled() ){
86 if ( !alarms().count() ) 86 if ( !alarms().count() )
87 return false; 87 return false;
88 Alarm *b = alarms().first(); 88 Alarm *b = alarms().first();
89 if( ! b->enabled() ) 89 if( ! b->enabled() )
90 return false; 90 return false;
91 if ( ! (a->offset() == b->offset() )) 91 if ( ! (a->offset() == b->offset() ))
92 return false; 92 return false;
93 } 93 }
94 } 94 }
95 95
96 QStringList cat = categories(); 96 QStringList cat = categories();
97 QStringList catFrom = from->categories(); 97 QStringList catFrom = from->categories();
98 QString nCat; 98 QString nCat;
99 unsigned int iii; 99 unsigned int iii;
100 for ( iii = 0; iii < catFrom.count();++iii ) { 100 for ( iii = 0; iii < catFrom.count();++iii ) {
101 nCat = catFrom[iii]; 101 nCat = catFrom[iii];
102 if ( !nCat.isEmpty() ) 102 if ( !nCat.isEmpty() )
103 if ( !cat.contains( nCat )) { 103 if ( !cat.contains( nCat )) {
104 return false; 104 return false;
105 } 105 }
106 } 106 }
107 if ( from->isCompleted() ) { 107 if ( from->isCompleted() ) {
108 if ( !isCompleted() ) 108 if ( !isCompleted() )
109 return false; 109 return false;
110 } 110 }
111 if( priority() != from->priority() ) 111 if( priority() != from->priority() )
112 return false; 112 return false;
113 113
114 114
115 return true; 115 return true;
116 116
117} 117}
118bool KCal::operator==( const Todo& t1, const Todo& t2 ) 118bool KCal::operator==( const Todo& t1, const Todo& t2 )
119{ 119{
120 120
121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 121 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
122 if ( ! ret ) 122 if ( ! ret )
123 return false; 123 return false;
124 if ( t1.hasDueDate() == t2.hasDueDate() ) { 124 if ( t1.hasDueDate() == t2.hasDueDate() ) {
125 if ( t1.hasDueDate() ) { 125 if ( t1.hasDueDate() ) {
126 if ( t1.doesFloat() == t2.doesFloat() ) { 126 if ( t1.doesFloat() == t2.doesFloat() ) {
127 if ( t1.doesFloat() ) { 127 if ( t1.doesFloat() ) {
128 if ( t1.dtDue().date() != t2.dtDue().date() ) 128 if ( t1.dtDue().date() != t2.dtDue().date() )
129 return false; 129 return false;
130 } else 130 } else
131 if ( t1.dtDue() != t2.dtDue() ) 131 if ( t1.dtDue() != t2.dtDue() )
132 return false; 132 return false;
133 } else 133 } else
134 return false;// float != 134 return false;// float !=
135 } 135 }
136 136
137 } else 137 } else
138 return false; 138 return false;
139 if ( t1.percentComplete() != t2.percentComplete() ) 139 if ( t1.percentComplete() != t2.percentComplete() )
140 return false; 140 return false;
141 if ( t1.isCompleted() ) { 141 if ( t1.isCompleted() ) {
142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 142 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
143 if ( t1.hasCompletedDate() ) { 143 if ( t1.hasCompletedDate() ) {
144 if ( t1.completed() != t2.completed() ) 144 if ( t1.completed() != t2.completed() )
145 return false; 145 return false;
146 } 146 }
147 147
148 } else 148 } else
149 return false; 149 return false;
150 } 150 }
151 return true; 151 return true;
152 152
153} 153}
154 154
155void Todo::setDtDue(const QDateTime &dtDue) 155void Todo::setDtDue(const QDateTime &dtDue)
156{ 156{
157 //int diffsecs = mDtDue.secsTo(dtDue); 157 //int diffsecs = mDtDue.secsTo(dtDue);
158 158
159 /*if (mReadOnly) return; 159 /*if (mReadOnly) return;
160 const QPtrList<Alarm>& alarms = alarms(); 160 const QPtrList<Alarm>& alarms = alarms();
161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 161 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
162 if (alarm->enabled()) { 162 if (alarm->enabled()) {
163 alarm->setTime(alarm->time().addSecs(diffsecs)); 163 alarm->setTime(alarm->time().addSecs(diffsecs));
164 } 164 }
165 }*/ 165 }*/
166 mDtDue = getEvenTime(dtDue); 166 mDtDue = getEvenTime(dtDue);
167 167
168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 168 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
169 169
170 /*const QPtrList<Alarm>& alarms = alarms(); 170 /*const QPtrList<Alarm>& alarms = alarms();
171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 171 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
172 alarm->setAlarmStart(mDtDue);*/ 172 alarm->setAlarmStart(mDtDue);*/
173 173
174 updated(); 174 updated();
175} 175}
176 176
177QDateTime Todo::dtDue() const 177QDateTime Todo::dtDue() const
178{ 178{
179 return mDtDue; 179 return mDtDue;
180} 180}
181 181
182QString Todo::dtDueTimeStr() const 182QString Todo::dtDueTimeStr() const
183{ 183{
184 return KGlobal::locale()->formatTime(mDtDue.time()); 184 return KGlobal::locale()->formatTime(mDtDue.time());
185} 185}
186 186
187QString Todo::dtDueDateStr(bool shortfmt) const 187QString Todo::dtDueDateStr(bool shortfmt) const
188{ 188{
189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 189 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
190} 190}
191 191
192QString Todo::dtDueStr(bool shortfmt) const 192QString Todo::dtDueStr(bool shortfmt) const
193{ 193{
194 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 194 if ( doesFloat() )
195 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
196 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
195} 197}
196// retval 0 : no found 198// retval 0 : no found
197// 1 : due for date found 199// 1 : due for date found
198// 2 : overdue for date found 200// 2 : overdue for date found
199int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 201int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
200{ 202{
201 int retval = 0; 203 int retval = 0;
202 if ( isCompleted() ) 204 if ( isCompleted() )
203 return 0; 205 return 0;
204 if ( hasDueDate() ) { 206 if ( hasDueDate() ) {
205 if ( dtDue().date() < date ) 207 if ( dtDue().date() < date )
206 return 2; 208 return 2;
207 // we do not return, because we may find an overdue sub todo 209 // we do not return, because we may find an overdue sub todo
208 if ( dtDue().date() == date ) 210 if ( dtDue().date() == date )
209 retval = 1; 211 retval = 1;
210 } 212 }
211 if ( checkSubtodos ) { 213 if ( checkSubtodos ) {
212 Incidence *aTodo; 214 Incidence *aTodo;
213 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 215 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
214 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 216 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
215 if ( ret == 2 ) 217 if ( ret == 2 )
216 return 2; 218 return 2;
217 if ( ret == 1) 219 if ( ret == 1)
218 retval = 1; 220 retval = 1;
219 } 221 }
220 } 222 }
221 return retval; 223 return retval;
222} 224}
223int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 225int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
224{ 226{
225 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 227 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
226} 228}
227bool Todo::hasDueDate() const 229bool Todo::hasDueDate() const
228{ 230{
229 return mHasDueDate; 231 return mHasDueDate;
230} 232}
231 233
232void Todo::setHasDueDate(bool f) 234void Todo::setHasDueDate(bool f)
233{ 235{
234 if (mReadOnly) return; 236 if (mReadOnly) return;
235 mHasDueDate = f; 237 mHasDueDate = f;
236 updated(); 238 updated();
237} 239}
238 240
239 241
240#if 0 242#if 0
241void Todo::setStatus(const QString &statStr) 243void Todo::setStatus(const QString &statStr)
242{ 244{
243 if (mReadOnly) return; 245 if (mReadOnly) return;
244 QString ss(statStr.upper()); 246 QString ss(statStr.upper());
245 247
246 if (ss == "X-ACTION") 248 if (ss == "X-ACTION")
247 mStatus = NEEDS_ACTION; 249 mStatus = NEEDS_ACTION;
248 else if (ss == "NEEDS ACTION") 250 else if (ss == "NEEDS ACTION")
249 mStatus = NEEDS_ACTION; 251 mStatus = NEEDS_ACTION;
250 else if (ss == "ACCEPTED") 252 else if (ss == "ACCEPTED")
251 mStatus = ACCEPTED; 253 mStatus = ACCEPTED;
252 else if (ss == "SENT") 254 else if (ss == "SENT")
253 mStatus = SENT; 255 mStatus = SENT;
254 else if (ss == "TENTATIVE") 256 else if (ss == "TENTATIVE")
255 mStatus = TENTATIVE; 257 mStatus = TENTATIVE;
256 else if (ss == "CONFIRMED") 258 else if (ss == "CONFIRMED")
257 mStatus = CONFIRMED; 259 mStatus = CONFIRMED;
258 else if (ss == "DECLINED") 260 else if (ss == "DECLINED")
259 mStatus = DECLINED; 261 mStatus = DECLINED;
260 else if (ss == "COMPLETED") 262 else if (ss == "COMPLETED")
261 mStatus = COMPLETED; 263 mStatus = COMPLETED;
262 else if (ss == "DELEGATED") 264 else if (ss == "DELEGATED")
263 mStatus = DELEGATED; 265 mStatus = DELEGATED;
264 266
265 updated(); 267 updated();
266} 268}
267 269
268void Todo::setStatus(int status) 270void Todo::setStatus(int status)
269{ 271{
270 if (mReadOnly) return; 272 if (mReadOnly) return;
271 mStatus = status; 273 mStatus = status;
272 updated(); 274 updated();
273} 275}
274 276
275int Todo::status() const 277int Todo::status() const
276{ 278{
277 return mStatus; 279 return mStatus;
278} 280}
279 281
280QString Todo::statusStr() const 282QString Todo::statusStr() const
281{ 283{
282 switch(mStatus) { 284 switch(mStatus) {
283 case NEEDS_ACTION: 285 case NEEDS_ACTION:
284 return QString("NEEDS ACTION"); 286 return QString("NEEDS ACTION");
285 break; 287 break;
286 case ACCEPTED: 288 case ACCEPTED:
287 return QString("ACCEPTED"); 289 return QString("ACCEPTED");
288 break; 290 break;
289 case SENT: 291 case SENT:
290 return QString("SENT"); 292 return QString("SENT");
291 break; 293 break;
292 case TENTATIVE: 294 case TENTATIVE:
293 return QString("TENTATIVE"); 295 return QString("TENTATIVE");
294 break; 296 break;
295 case CONFIRMED: 297 case CONFIRMED:
296 return QString("CONFIRMED"); 298 return QString("CONFIRMED");
297 break; 299 break;
298 case DECLINED: 300 case DECLINED:
299 return QString("DECLINED"); 301 return QString("DECLINED");
300 break; 302 break;
301 case COMPLETED: 303 case COMPLETED:
302 return QString("COMPLETED"); 304 return QString("COMPLETED");
303 break; 305 break;
304 case DELEGATED: 306 case DELEGATED:
305 return QString("DELEGATED"); 307 return QString("DELEGATED");
306 break; 308 break;
307 } 309 }
308 return QString(""); 310 return QString("");
309} 311}
310#endif 312#endif
311 313
312bool Todo::isCompleted() const 314bool Todo::isCompleted() const
313{ 315{
314 if (mPercentComplete == 100) { 316 if (mPercentComplete == 100) {
315 return true; 317 return true;
316 } 318 }
317 else return false; 319 else return false;
318} 320}
319 321
320void Todo::setCompleted(bool completed) 322void Todo::setCompleted(bool completed)
321{ 323{
322 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 324 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
323 if ( !setRecurDates() ) 325 if ( !setRecurDates() )
324 completed = false; 326 completed = false;
325 } 327 }
326 if (completed) mPercentComplete = 100; 328 if (completed) mPercentComplete = 100;
327 else { 329 else {
328 mPercentComplete = 0; 330 mPercentComplete = 0;
329 mHasCompletedDate = false; 331 mHasCompletedDate = false;
330 } 332 }
331 updated(); 333 updated();
332} 334}
333 335
334QDateTime Todo::completed() const 336QDateTime Todo::completed() const
335{ 337{
336 return mCompleted; 338 return mCompleted;
337} 339}
338 340
339QString Todo::completedStr( bool shortF ) const 341QString Todo::completedStr( bool shortF ) const
340{ 342{
341 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 343 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
342} 344}
343 345
344void Todo::setCompleted(const QDateTime &completed) 346void Todo::setCompleted(const QDateTime &completed)
345{ 347{
346 //qDebug("Todo::setCompleted "); 348 //qDebug("Todo::setCompleted ");
347 if ( mHasCompletedDate ) { 349 if ( mHasCompletedDate ) {
348 // qDebug("has completed data - return "); 350 // qDebug("has completed data - return ");
349 return; 351 return;
350 } 352 }
351 mHasCompletedDate = true; 353 mHasCompletedDate = true;
352 mPercentComplete = 100; 354 mPercentComplete = 100;
353 mCompleted = getEvenTime(completed); 355 mCompleted = getEvenTime(completed);
354 updated(); 356 updated();
355} 357}
356 358
357bool Todo::hasCompletedDate() const 359bool Todo::hasCompletedDate() const
358{ 360{
359 return mHasCompletedDate; 361 return mHasCompletedDate;
360} 362}
361 363
362int Todo::percentComplete() const 364int Todo::percentComplete() const
363{ 365{
364 return mPercentComplete; 366 return mPercentComplete;
365} 367}
366bool Todo::setRecurDates() 368bool Todo::setRecurDates()
367{ 369{
368 if ( !mHasRecurrenceID ) 370 if ( !mHasRecurrenceID )
369 return true; 371 return true;
370 int secs = mDtStart.secsTo( dtDue() ); 372 int secs = mDtStart.secsTo( dtDue() );
371 bool ok; 373 bool ok;
372 qDebug("T:setRecurDates() "); 374 qDebug("T:setRecurDates() ");
373 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 375 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
374 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 376 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
375 if ( ok ) { 377 if ( ok ) {
376 mRecurrenceID = next; 378 mRecurrenceID = next;
377 mDtStart = next; 379 mDtStart = next;
378 setDtDue( next.addSecs( secs ) ); 380 setDtDue( next.addSecs( secs ) );
379 if ( QDateTime::currentDateTime() > next) 381 if ( QDateTime::currentDateTime() > next)
380 return false; 382 return false;
381 } else { 383 } else {
382 setHasRecurrenceID( false ); 384 setHasRecurrenceID( false );
383 recurrence()->unsetRecurs(); 385 recurrence()->unsetRecurs();
384 } 386 }
385 return true; 387 return true;
386} 388}
387void Todo::setPercentComplete(int v) 389void Todo::setPercentComplete(int v)
388{ 390{
389 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 391 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
390 if ( !setRecurDates() ) 392 if ( !setRecurDates() )
391 v = 0; 393 v = 0;
392 } 394 }
393 mPercentComplete = v; 395 mPercentComplete = v;
394 if ( v != 100 ) 396 if ( v != 100 )
395 mHasCompletedDate = false; 397 mHasCompletedDate = false;
396 updated(); 398 updated();
397} 399}
398QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const 400QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const
399{ 401{
400 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 402 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
401 *ok = false; 403 *ok = false;
402 return QDateTime (); 404 return QDateTime ();
403 } 405 }
404 QDateTime incidenceStart; 406 QDateTime incidenceStart;
405 incidenceStart = dtDue(); 407 incidenceStart = dtDue();
406 bool enabled = false; 408 bool enabled = false;
407 Alarm* alarm; 409 Alarm* alarm;
408 int off = 0; 410 int off = 0;
409 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 411 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
410 // if ( QDateTime::currentDateTime() > incidenceStart ){ 412 // if ( QDateTime::currentDateTime() > incidenceStart ){
411// *ok = false; 413// *ok = false;
412// return incidenceStart; 414// return incidenceStart;
413// } 415// }
414 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 416 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
415 if (alarm->enabled()) { 417 if (alarm->enabled()) {
416 if ( alarm->hasTime () ) { 418 if ( alarm->hasTime () ) {
417 if ( alarm->time() < alarmStart ) { 419 if ( alarm->time() < alarmStart ) {
418 alarmStart = alarm->time(); 420 alarmStart = alarm->time();
419 enabled = true; 421 enabled = true;
420 off = alarmStart.secsTo( incidenceStart ); 422 off = alarmStart.secsTo( incidenceStart );
421 } 423 }
422 424
423 } else { 425 } else {
424 int secs = alarm->startOffset().asSeconds(); 426 int secs = alarm->startOffset().asSeconds();
425 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 427 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
426 alarmStart = incidenceStart.addSecs( secs ); 428 alarmStart = incidenceStart.addSecs( secs );
427 enabled = true; 429 enabled = true;
428 off = -secs; 430 off = -secs;
429 } 431 }
430 } 432 }
431 } 433 }
432 } 434 }
433 if ( enabled ) { 435 if ( enabled ) {
434 if ( alarmStart > QDateTime::currentDateTime() ) { 436 if ( alarmStart > QDateTime::currentDateTime() ) {
435 *ok = true; 437 *ok = true;
436 * offset = off; 438 * offset = off;
437 return alarmStart; 439 return alarmStart;
438 } 440 }
439 } 441 }
440 *ok = false; 442 *ok = false;
441 return QDateTime (); 443 return QDateTime ();
442 444
443} 445}
444 446
445void Todo::checkSetCompletedFalse() 447void Todo::checkSetCompletedFalse()
446{ 448{
447 if ( !hasRecurrenceID() ) { 449 if ( !hasRecurrenceID() ) {
448 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 450 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
449 } 451 }
450 // qDebug("Todo::checkSetCompletedFalse()"); 452 // qDebug("Todo::checkSetCompletedFalse()");
451 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 453 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
452 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { 454 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) {
453 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 455 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
454 setCompleted( false ); 456 setCompleted( false );
455 qDebug("Todo::checkSetCompletedFalse "); 457 qDebug("Todo::checkSetCompletedFalse ");
456 } 458 }
457} 459}