summaryrefslogtreecommitdiff
authordrw <drw>2005-02-16 19:45:54 (UTC)
committer drw <drw>2005-02-16 19:45:54 (UTC)
commit28feca2d605de0bd5a1ccf2217dfef2a17466307 (patch) (unidiff)
tree0badbaa8bbbecfbe0541f1686572e12c2b8f383a
parent5ad21664e5db417a18682903a660f4651c68ff12 (diff)
downloadopie-28feca2d605de0bd5a1ccf2217dfef2a17466307.zip
opie-28feca2d605de0bd5a1ccf2217dfef2a17466307.tar.gz
opie-28feca2d605de0bd5a1ccf2217dfef2a17466307.tar.bz2
Fix for bug #1542 - todo crashes when priority < 1 or > 5
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
index 16ca987..5bdc648 100644
--- a/libopie2/opiepim/core/opimtodo.cpp
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -1,810 +1,822 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimtodo.h" 30#include "opimtodo.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimstate.h> 33#include <opie2/opimstate.h>
34#include <opie2/opimrecurrence.h> 34#include <opie2/opimrecurrence.h>
35#include <opie2/opimmaintainer.h> 35#include <opie2/opimmaintainer.h>
36#include <opie2/opimnotifymanager.h> 36#include <opie2/opimnotifymanager.h>
37#include <opie2/opimresolver.h> 37#include <opie2/opimresolver.h>
38#include <opie2/odebug.h> 38#include <opie2/odebug.h>
39 39
40#include <qpe/palmtopuidgen.h> 40#include <qpe/palmtopuidgen.h>
41#include <qpe/palmtoprecord.h> 41#include <qpe/palmtoprecord.h>
42#include <qpe/categories.h> 42#include <qpe/categories.h>
43#include <qpe/categoryselect.h> 43#include <qpe/categoryselect.h>
44#include <qpe/stringutil.h> 44#include <qpe/stringutil.h>
45 45
46/* QT */ 46/* QT */
47#include <qobject.h> 47#include <qobject.h>
48#include <qshared.h> 48#include <qshared.h>
49 49
50namespace Opie 50namespace Opie
51{ 51{
52 52
53struct OPimTodo::OPimTodoData : public QShared 53struct OPimTodo::OPimTodoData : public QShared
54{ 54{
55 OPimTodoData() : QShared() 55 OPimTodoData() : QShared()
56 { 56 {
57 recur = 0; 57 recur = 0;
58 state = 0; 58 state = 0;
59 maintainer = 0; 59 maintainer = 0;
60 notifiers = 0; 60 notifiers = 0;
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 delete state;
68 } 68 }
69 69
70 QDate date; 70 QDate date;
71 bool isCompleted: 1; 71 bool isCompleted: 1;
72 bool hasDate: 1; 72 bool hasDate: 1;
73 int priority; 73 int priority;
74 QString desc; 74 QString desc;
75 QString sum; 75 QString sum;
76 QMap<QString, QString> extra; 76 QMap<QString, QString> extra;
77 ushort prog; 77 ushort prog;
78 OPimState *state; 78 OPimState *state;
79 OPimRecurrence *recur; 79 OPimRecurrence *recur;
80 OPimMaintainer *maintainer; 80 OPimMaintainer *maintainer;
81 QDate start; 81 QDate start;
82 QDate completed; 82 QDate completed;
83 OPimNotifyManager *notifiers; 83 OPimNotifyManager *notifiers;
84}; 84};
85 85
86 86
87OPimTodo::OPimTodo( const OPimTodo &event ) 87OPimTodo::OPimTodo( const OPimTodo &event )
88 : OPimRecord( event ), data( event.data ) 88 : OPimRecord( event ), data( event.data )
89{ 89{
90 data->ref(); 90 data->ref();
91} 91}
92 92
93 93
94OPimTodo::~OPimTodo() 94OPimTodo::~OPimTodo()
95{ 95{
96 96
97 if ( data->deref() ) 97 if ( data->deref() )
98 { 98 {
99 delete data; 99 delete data;
100 data = 0l; 100 data = 0l;
101 } 101 }
102} 102}
103 103
104 104
105OPimTodo::OPimTodo( bool completed, int priority, 105OPimTodo::OPimTodo( bool completed, int priority,
106 const QArray<int> &category, 106 const QArray<int> &category,
107 const QString& summary, 107 const QString& summary,
108 const QString &description, 108 const QString &description,
109 ushort progress, 109 ushort progress,
110 bool hasDate, QDate date, int uid ) 110 bool hasDate, QDate date, int uid )
111 : OPimRecord( uid ) 111 : OPimRecord( uid )
112{ 112{
113 setCategories( category ); 113 setCategories( category );
114 114
115 data = new OPimTodoData; 115 data = new OPimTodoData;
116 116
117 data->date = date; 117 data->date = date;
118 data->isCompleted = completed; 118 data->isCompleted = completed;
119 data->hasDate = hasDate; 119 data->hasDate = hasDate;
120 if ( priority < 1 )
121 priority = 1;
122 else if ( priority > 5 )
123 priority = 5;
120 data->priority = priority; 124 data->priority = priority;
121 data->sum = summary; 125 data->sum = summary;
122 data->prog = progress; 126 data->prog = progress;
123 data->desc = Qtopia::simplifyMultiLineSpace( description ); 127 data->desc = Qtopia::simplifyMultiLineSpace( description );
124} 128}
125 129
126 130
127OPimTodo::OPimTodo( bool completed, int priority, 131OPimTodo::OPimTodo( bool completed, int priority,
128 const QStringList &category, 132 const QStringList &category,
129 const QString& summary, 133 const QString& summary,
130 const QString &description, 134 const QString &description,
131 ushort progress, 135 ushort progress,
132 bool hasDate, QDate date, int uid ) 136 bool hasDate, QDate date, int uid )
133 : OPimRecord( uid ) 137 : OPimRecord( uid )
134{ 138{
135 setCategories( idsFromString( category.join( ";" ) ) ); 139 setCategories( idsFromString( category.join( ";" ) ) );
136 140
137 data = new OPimTodoData; 141 data = new OPimTodoData;
138 142
139 data->date = date; 143 data->date = date;
140 data->isCompleted = completed; 144 data->isCompleted = completed;
141 data->hasDate = hasDate; 145 data->hasDate = hasDate;
146 if ( priority < 1 )
147 priority = 1;
148 else if ( priority > 5 )
149 priority = 5;
142 data->priority = priority; 150 data->priority = priority;
143 data->sum = summary; 151 data->sum = summary;
144 data->prog = progress; 152 data->prog = progress;
145 data->desc = Qtopia::simplifyMultiLineSpace( description ); 153 data->desc = Qtopia::simplifyMultiLineSpace( description );
146} 154}
147 155
148 156
149bool OPimTodo::match( const QRegExp &regExp ) const 157bool OPimTodo::match( const QRegExp &regExp ) const
150{ 158{
151 if ( QString::number( data->priority ).find( regExp ) != -1 ) 159 if ( QString::number( data->priority ).find( regExp ) != -1 )
152 { 160 {
153 setLastHitField( Priority ); 161 setLastHitField( Priority );
154 return true; 162 return true;
155 } 163 }
156 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) 164 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 )
157 { 165 {
158 setLastHitField( HasDate ); 166 setLastHitField( HasDate );
159 return true; 167 return true;
160 } 168 }
161 else if ( data->desc.find( regExp ) != -1 ) 169 else if ( data->desc.find( regExp ) != -1 )
162 { 170 {
163 setLastHitField( Description ); 171 setLastHitField( Description );
164 return true; 172 return true;
165 } 173 }
166 else if ( data->sum.find( regExp ) != -1 ) 174 else if ( data->sum.find( regExp ) != -1 )
167 { 175 {
168 setLastHitField( Summary ); 176 setLastHitField( Summary );
169 return true; 177 return true;
170 } 178 }
171 return false; 179 return false;
172} 180}
173 181
174 182
175bool OPimTodo::isCompleted() const 183bool OPimTodo::isCompleted() const
176{ 184{
177 return data->isCompleted; 185 return data->isCompleted;
178} 186}
179 187
180 188
181bool OPimTodo::hasDueDate() const 189bool OPimTodo::hasDueDate() const
182{ 190{
183 return data->hasDate; 191 return data->hasDate;
184} 192}
185 193
186/** 194/**
187 * \brief Does this Todo have a start date 195 * \brief Does this Todo have a start date
188 * 196 *
189 * Does this Todo have a start date. The decision 197 * Does this Todo have a start date. The decision
190 * is based on if the internal startDate isValid 198 * is based on if the internal startDate isValid
191 * in the sense of QDate::isValid. 199 * in the sense of QDate::isValid.
192 * 200 *
193 * @return True if the startDate isValid 201 * @return True if the startDate isValid
194 * @see startDate 202 * @see startDate
195 * @see setStartDate 203 * @see setStartDate
196 * @see QDate::isValid() 204 * @see QDate::isValid()
197 */ 205 */
198bool OPimTodo::hasStartDate() const 206bool OPimTodo::hasStartDate() const
199{ 207{
200 return data->start.isValid(); 208 return data->start.isValid();
201} 209}
202 210
203/** 211/**
204 * \brief Does this Todo have a Date when it was completed 212 * \brief Does this Todo have a Date when it was completed
205 * 213 *
206 * As in \sa hasStartDate() it is determined if there 214 * As in \sa hasStartDate() it is determined if there
207 * is a completed date by looking if the internal date 215 * is a completed date by looking if the internal date
208 * isValid \sa QDate::isValid. 216 * isValid \sa QDate::isValid.
209 * 217 *
210 * @see hasStartDate 218 * @see hasStartDate
211 * @return True if the completedDate is set and valid. 219 * @return True if the completedDate is set and valid.
212 */ 220 */
213bool OPimTodo::hasCompletedDate() const 221bool OPimTodo::hasCompletedDate() const
214{ 222{
215 return data->completed.isValid(); 223 return data->completed.isValid();
216} 224}
217 225
218 226
219int OPimTodo::priority() const 227int OPimTodo::priority() const
220{ 228{
221 return data->priority; 229 return data->priority;
222} 230}
223 231
224 232
225QString OPimTodo::summary() const 233QString OPimTodo::summary() const
226{ 234{
227 return data->sum; 235 return data->sum;
228} 236}
229 237
230 238
231ushort OPimTodo::progress() const 239ushort OPimTodo::progress() const
232{ 240{
233 return data->prog; 241 return data->prog;
234} 242}
235 243
236 244
237QDate OPimTodo::dueDate() const 245QDate OPimTodo::dueDate() const
238{ 246{
239 return data->date; 247 return data->date;
240} 248}
241 249
242 250
243QDate OPimTodo::startDate() const 251QDate OPimTodo::startDate() const
244{ 252{
245 return data->start; 253 return data->start;
246} 254}
247 255
248 256
249QDate OPimTodo::completedDate() const 257QDate OPimTodo::completedDate() const
250{ 258{
251 return data->completed; 259 return data->completed;
252} 260}
253 261
254 262
255QString OPimTodo::description() const 263QString OPimTodo::description() const
256{ 264{
257 return data->desc; 265 return data->desc;
258} 266}
259 267
260 268
261bool OPimTodo::hasState() const 269bool OPimTodo::hasState() const
262{ 270{
263 if ( !data->state ) return false; 271 if ( !data->state ) return false;
264 return ( data->state->state() != OPimState::Undefined ); 272 return ( data->state->state() != OPimState::Undefined );
265} 273}
266 274
267 275
268OPimState OPimTodo::state() const 276OPimState OPimTodo::state() const
269{ 277{
270 if ( !data->state ) 278 if ( !data->state )
271 { 279 {
272 OPimState state; 280 OPimState state;
273 return state; 281 return state;
274 } 282 }
275 283
276 return ( *data->state ); 284 return ( *data->state );
277} 285}
278 286
279 287
280bool OPimTodo::hasRecurrence() const 288bool OPimTodo::hasRecurrence() const
281{ 289{
282 if ( !data->recur ) return false; 290 if ( !data->recur ) return false;
283 return data->recur->doesRecur(); 291 return data->recur->doesRecur();
284} 292}
285 293
286 294
287OPimRecurrence OPimTodo::recurrence() const 295OPimRecurrence OPimTodo::recurrence() const
288{ 296{
289 if ( !data->recur ) return OPimRecurrence(); 297 if ( !data->recur ) return OPimRecurrence();
290 298
291 return ( *data->recur ); 299 return ( *data->recur );
292} 300}
293 301
294 302
295bool OPimTodo::hasMaintainer() const 303bool OPimTodo::hasMaintainer() const
296{ 304{
297 if ( !data->maintainer ) return false; 305 if ( !data->maintainer ) return false;
298 306
299 return ( data->maintainer->mode() != OPimMaintainer::Undefined ); 307 return ( data->maintainer->mode() != OPimMaintainer::Undefined );
300} 308}
301 309
302 310
303OPimMaintainer OPimTodo::maintainer() const 311OPimMaintainer OPimTodo::maintainer() const
304{ 312{
305 if ( !data->maintainer ) return OPimMaintainer(); 313 if ( !data->maintainer ) return OPimMaintainer();
306 314
307 return ( *data->maintainer ); 315 return ( *data->maintainer );
308} 316}
309 317
310 318
311void OPimTodo::setCompleted( bool completed ) 319void OPimTodo::setCompleted( bool completed )
312{ 320{
313 changeOrModify(); 321 changeOrModify();
314 data->isCompleted = completed; 322 data->isCompleted = completed;
315} 323}
316 324
317 325
318void OPimTodo::setHasDueDate( bool hasDate ) 326void OPimTodo::setHasDueDate( bool hasDate )
319{ 327{
320 changeOrModify(); 328 changeOrModify();
321 data->hasDate = hasDate; 329 data->hasDate = hasDate;
322} 330}
323 331
324 332
325void OPimTodo::setDescription( const QString &desc ) 333void OPimTodo::setDescription( const QString &desc )
326{ 334{
327 changeOrModify(); 335 changeOrModify();
328 data->desc = Qtopia::simplifyMultiLineSpace( desc ); 336 data->desc = Qtopia::simplifyMultiLineSpace( desc );
329} 337}
330 338
331 339
332void OPimTodo::setSummary( const QString& sum ) 340void OPimTodo::setSummary( const QString& sum )
333{ 341{
334 changeOrModify(); 342 changeOrModify();
335 data->sum = sum; 343 data->sum = sum;
336} 344}
337 345
338 346
339void OPimTodo::setPriority( int prio ) 347void OPimTodo::setPriority( int prio )
340{ 348{
341 changeOrModify(); 349 changeOrModify();
350 if ( prio < 1 )
351 prio = 1;
352 else if ( prio > 5 )
353 prio = 5;
342 data->priority = prio; 354 data->priority = prio;
343} 355}
344 356
345 357
346void OPimTodo::setDueDate( const QDate& date ) 358void OPimTodo::setDueDate( const QDate& date )
347{ 359{
348 changeOrModify(); 360 changeOrModify();
349 data->date = date; 361 data->date = date;
350} 362}
351 363
352 364
353void OPimTodo::setStartDate( const QDate& date ) 365void OPimTodo::setStartDate( const QDate& date )
354{ 366{
355 changeOrModify(); 367 changeOrModify();
356 data->start = date; 368 data->start = date;
357} 369}
358 370
359 371
360void OPimTodo::setCompletedDate( const QDate& date ) 372void OPimTodo::setCompletedDate( const QDate& date )
361{ 373{
362 changeOrModify(); 374 changeOrModify();
363 data->completed = date; 375 data->completed = date;
364} 376}
365 377
366 378
367void OPimTodo::setState( const OPimState& state ) 379void OPimTodo::setState( const OPimState& state )
368{ 380{
369 changeOrModify(); 381 changeOrModify();
370 if ( data->state ) 382 if ( data->state )
371 ( *data->state ) = state; 383 ( *data->state ) = state;
372 else 384 else
373 data->state = new OPimState( state ); 385 data->state = new OPimState( state );
374} 386}
375 387
376 388
377void OPimTodo::setRecurrence( const OPimRecurrence& rec ) 389void OPimTodo::setRecurrence( const OPimRecurrence& rec )
378{ 390{
379 changeOrModify(); 391 changeOrModify();
380 if ( data->recur ) 392 if ( data->recur )
381 ( *data->recur ) = rec; 393 ( *data->recur ) = rec;
382 else 394 else
383 data->recur = new OPimRecurrence( rec ); 395 data->recur = new OPimRecurrence( rec );
384} 396}
385 397
386 398
387void OPimTodo::setMaintainer( const OPimMaintainer& pim ) 399void OPimTodo::setMaintainer( const OPimMaintainer& pim )
388{ 400{
389 changeOrModify(); 401 changeOrModify();
390 402
391 if ( data->maintainer ) 403 if ( data->maintainer )
392 ( *data->maintainer ) = pim; 404 ( *data->maintainer ) = pim;
393 else 405 else
394 data->maintainer = new OPimMaintainer( pim ); 406 data->maintainer = new OPimMaintainer( pim );
395} 407}
396 408
397 409
398bool OPimTodo::isOverdue( )const 410bool OPimTodo::isOverdue( )const
399{ 411{
400 if ( data->hasDate && !data->isCompleted ) 412 if ( data->hasDate && !data->isCompleted )
401 return QDate::currentDate() > data->date; 413 return QDate::currentDate() > data->date;
402 return false; 414 return false;
403} 415}
404 416
405 417
406void OPimTodo::setProgress( ushort progress ) 418void OPimTodo::setProgress( ushort progress )
407{ 419{
408 changeOrModify(); 420 changeOrModify();
409 data->prog = progress; 421 data->prog = progress;
410} 422}
411 423
412 424
413QString OPimTodo::toShortText() const 425QString OPimTodo::toShortText() const
414{ 426{
415 return summary(); 427 return summary();
416} 428}
417 429
418 430
419/*! 431/*!
420 Returns a richt text string 432 Returns a richt text string
421*/ 433*/
422QString OPimTodo::toRichText() const 434QString OPimTodo::toRichText() const
423{ 435{
424 QString text; 436 QString text;
425 QStringList catlist; 437 QStringList catlist;
426 438
427 // summary 439 // summary
428 text += "<b><h3><img src=\"todo/TodoList\"> "; 440 text += "<b><h3><img src=\"todo/TodoList\"> ";
429 if ( !summary().isEmpty() ) 441 if ( !summary().isEmpty() )
430 { 442 {
431 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); 443 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" );
432 } 444 }
433 text += "</h3></b><br><hr><br>"; 445 text += "</h3></b><br><hr><br>";
434 446
435 // description 447 // description
436 if ( !description().isEmpty() ) 448 if ( !description().isEmpty() )
437 { 449 {
438 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 450 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
439 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 451 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
440 } 452 }
441 453
442 // priority 454 // priority
443 int priorityval = priority(); 455 int priorityval = priority();
444 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" + 456 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" +
445 QString::number( priorityval ) + "\"> "; 457 QString::number( priorityval ) + "\"> ";
446 458
447 switch ( priorityval ) 459 switch ( priorityval )
448 { 460 {
449 case 1 : text += QObject::tr( "Very high" ); 461 case 1 : text += QObject::tr( "Very high" );
450 break; 462 break;
451 case 2 : text += QObject::tr( "High" ); 463 case 2 : text += QObject::tr( "High" );
452 break; 464 break;
453 case 3 : text += QObject::tr( "Normal" ); 465 case 3 : text += QObject::tr( "Normal" );
454 break; 466 break;
455 case 4 : text += QObject::tr( "Low" ); 467 case 4 : text += QObject::tr( "Low" );
456 break; 468 break;
457 case 5 : text += QObject::tr( "Very low" ); 469 case 5 : text += QObject::tr( "Very low" );
458 break; 470 break;
459 }; 471 };
460 text += "<br>"; 472 text += "<br>";
461 473
462 // progress 474 // progress
463 text += "<b>" + QObject::tr( "Progress:" ) + " </b>" 475 text += "<b>" + QObject::tr( "Progress:" ) + " </b>"
464 + QString::number( progress() ) + " %<br>"; 476 + QString::number( progress() ) + " %<br>";
465 477
466 // due date 478 // due date
467 if ( hasDueDate() ) 479 if ( hasDueDate() )
468 { 480 {
469 QDate dd = dueDate(); 481 QDate dd = dueDate();
470 int off = QDate::currentDate().daysTo( dd ); 482 int off = QDate::currentDate().daysTo( dd );
471 483
472 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 484 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
473 if ( off < 0 ) 485 if ( off < 0 )
474 text += "#FF0000"; 486 text += "#FF0000";
475 else if ( off == 0 ) 487 else if ( off == 0 )
476 text += "#FFFF00"; 488 text += "#FFFF00";
477 else if ( off > 0 ) 489 else if ( off > 0 )
478 text += "#00FF00"; 490 text += "#00FF00";
479 491
480 text += "\">" + dd.toString() + "</font><br>"; 492 text += "\">" + dd.toString() + "</font><br>";
481 } 493 }
482 494
483 // categories 495 // categories
484 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 496 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
485 text += categoryNames( "Todo List" ).join( ", " ); 497 text += categoryNames( "Todo List" ).join( ", " );
486 text += "<br>"; 498 text += "<br>";
487 499
488 return text; 500 return text;
489} 501}
490 502
491 503
492bool OPimTodo::hasNotifiers() const 504bool OPimTodo::hasNotifiers() const
493{ 505{
494 if ( !data->notifiers ) return false; 506 if ( !data->notifiers ) return false;
495 return !data->notifiers->isEmpty(); 507 return !data->notifiers->isEmpty();
496} 508}
497 509
498 510
499OPimNotifyManager& OPimTodo::notifiers() 511OPimNotifyManager& OPimTodo::notifiers()
500{ 512{
501 if ( !data->notifiers ) 513 if ( !data->notifiers )
502 data->notifiers = new OPimNotifyManager; 514 data->notifiers = new OPimNotifyManager;
503 return ( *data->notifiers ); 515 return ( *data->notifiers );
504} 516}
505 517
506 518
507const OPimNotifyManager& OPimTodo::notifiers() const 519const OPimNotifyManager& OPimTodo::notifiers() const
508{ 520{
509 if ( !data->notifiers ) 521 if ( !data->notifiers )
510 data->notifiers = new OPimNotifyManager; 522 data->notifiers = new OPimNotifyManager;
511 523
512 return ( *data->notifiers ); 524 return ( *data->notifiers );
513} 525}
514 526
515 527
516bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const 528bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const
517{ 529{
518 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 530 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
519 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 531 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
520 if ( hasDueDate() && toDoEvent.hasDueDate() ) 532 if ( hasDueDate() && toDoEvent.hasDueDate() )
521 { 533 {
522 if ( dueDate() == toDoEvent.dueDate() ) 534 if ( dueDate() == toDoEvent.dueDate() )
523 { // let's the priority decide 535 { // let's the priority decide
524 return priority() < toDoEvent.priority(); 536 return priority() < toDoEvent.priority();
525 } 537 }
526 else 538 else
527 { 539 {
528 return dueDate() < toDoEvent.dueDate(); 540 return dueDate() < toDoEvent.dueDate();
529 } 541 }
530 } 542 }
531 return false; 543 return false;
532} 544}
533 545
534 546
535bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const 547bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const
536{ 548{
537 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 549 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
538 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 550 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
539 if ( hasDueDate() && toDoEvent.hasDueDate() ) 551 if ( hasDueDate() && toDoEvent.hasDueDate() )
540 { 552 {
541 if ( dueDate() == toDoEvent.dueDate() ) 553 if ( dueDate() == toDoEvent.dueDate() )
542 { // let's the priority decide 554 { // let's the priority decide
543 return priority() <= toDoEvent.priority(); 555 return priority() <= toDoEvent.priority();
544 } 556 }
545 else 557 else
546 { 558 {
547 return dueDate() <= toDoEvent.dueDate(); 559 return dueDate() <= toDoEvent.dueDate();
548 } 560 }
549 } 561 }
550 return true; 562 return true;
551} 563}
552 564
553 565
554bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const 566bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const
555{ 567{
556 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 568 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
557 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 569 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
558 if ( hasDueDate() && toDoEvent.hasDueDate() ) 570 if ( hasDueDate() && toDoEvent.hasDueDate() )
559 { 571 {
560 if ( dueDate() == toDoEvent.dueDate() ) 572 if ( dueDate() == toDoEvent.dueDate() )
561 { // let's the priority decide 573 { // let's the priority decide
562 return priority() > toDoEvent.priority(); 574 return priority() > toDoEvent.priority();
563 } 575 }
564 else 576 else
565 { 577 {
566 return dueDate() > toDoEvent.dueDate(); 578 return dueDate() > toDoEvent.dueDate();
567 } 579 }
568 } 580 }
569 return false; 581 return false;
570} 582}
571 583
572 584
573bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const 585bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const
574{ 586{
575 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 587 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
576 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 588 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
577 if ( hasDueDate() && toDoEvent.hasDueDate() ) 589 if ( hasDueDate() && toDoEvent.hasDueDate() )
578 { 590 {
579 if ( dueDate() == toDoEvent.dueDate() ) 591 if ( dueDate() == toDoEvent.dueDate() )
580 { // let's the priority decide 592 { // let's the priority decide
581 return priority() > toDoEvent.priority(); 593 return priority() > toDoEvent.priority();
582 } 594 }
583 else 595 else
584 { 596 {
585 return dueDate() > toDoEvent.dueDate(); 597 return dueDate() > toDoEvent.dueDate();
586 } 598 }
587 } 599 }
588 return true; 600 return true;
589} 601}
590 602
591 603
592bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const 604bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
593{ 605{
594 if ( data->priority != toDoEvent.data->priority ) return false; 606 if ( data->priority != toDoEvent.data->priority ) return false;
595 if ( data->priority != toDoEvent.data->prog ) return false; 607 if ( data->priority != toDoEvent.data->prog ) return false;
596 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 608 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
597 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 609 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
598 if ( data->date != toDoEvent.data->date ) return false; 610 if ( data->date != toDoEvent.data->date ) return false;
599 if ( data->sum != toDoEvent.data->sum ) return false; 611 if ( data->sum != toDoEvent.data->sum ) return false;
600 if ( data->desc != toDoEvent.data->desc ) return false; 612 if ( data->desc != toDoEvent.data->desc ) return false;
601 if ( data->maintainer != toDoEvent.data->maintainer ) 613 if ( data->maintainer != toDoEvent.data->maintainer )
602 return false; 614 return false;
603 615
604 return OPimRecord::operator==( toDoEvent ); 616 return OPimRecord::operator==( toDoEvent );
605} 617}
606 618
607 619
608void OPimTodo::deref() 620void OPimTodo::deref()
609{ 621{
610 622
611 if ( data->deref() ) 623 if ( data->deref() )
612 { 624 {
613 delete data; 625 delete data;
614 data = 0; 626 data = 0;
615 } 627 }
616} 628}
617 629
618 630
619OPimTodo &OPimTodo::operator=( const OPimTodo &item ) 631OPimTodo &OPimTodo::operator=( const OPimTodo &item )
620{ 632{
621 if ( this == &item ) return * this; 633 if ( this == &item ) return * this;
622 634
623 OPimRecord::operator=( item ); 635 OPimRecord::operator=( item );
624 item.data->ref(); 636 item.data->ref();
625 deref(); 637 deref();
626 data = item.data; 638 data = item.data;
627 639
628 return *this; 640 return *this;
629} 641}
630 642
631 643
632QMap<int, QString> OPimTodo::toMap() const 644QMap<int, QString> OPimTodo::toMap() const
633{ 645{
634 QMap<int, QString> map; 646 QMap<int, QString> map;
635 647
636 map.insert( Uid, QString::number( uid() ) ); 648 map.insert( Uid, QString::number( uid() ) );
637 map.insert( Category, idsToString( categories() ) ); 649 map.insert( Category, idsToString( categories() ) );
638 map.insert( HasDate, QString::number( data->hasDate ) ); 650 map.insert( HasDate, QString::number( data->hasDate ) );
639 map.insert( Completed, QString::number( data->isCompleted ) ); 651 map.insert( Completed, QString::number( data->isCompleted ) );
640 map.insert( Description, data->desc ); 652 map.insert( Description, data->desc );
641 map.insert( Summary, data->sum ); 653 map.insert( Summary, data->sum );
642 map.insert( Priority, QString::number( data->priority ) ); 654 map.insert( Priority, QString::number( data->priority ) );
643 map.insert( DateDay, QString::number( data->date.day() ) ); 655 map.insert( DateDay, QString::number( data->date.day() ) );
644 map.insert( DateMonth, QString::number( data->date.month() ) ); 656 map.insert( DateMonth, QString::number( data->date.month() ) );
645 map.insert( DateYear, QString::number( data->date.year() ) ); 657 map.insert( DateYear, QString::number( data->date.year() ) );
646 map.insert( Progress, QString::number( data->prog ) ); 658 map.insert( Progress, QString::number( data->prog ) );
647 // map.insert( CrossReference, crossToString() ); 659 // map.insert( CrossReference, crossToString() );
648 /* FIXME!!! map.insert( State, ); 660 /* FIXME!!! map.insert( State, );
649 map.insert( Recurrence, ); 661 map.insert( Recurrence, );
650 map.insert( Reminders, ); 662 map.insert( Reminders, );
651 map. 663 map.
652 */ 664 */
653 return map; 665 return map;
654} 666}
655 667
656 668
657/** 669/**
658 * change or modify looks at the ref count and either 670 * change or modify looks at the ref count and either
659 * creates a new QShared Object or it can modify it 671 * creates a new QShared Object or it can modify it
660 * right in place 672 * right in place
661 */ 673 */
662void OPimTodo::changeOrModify() 674void OPimTodo::changeOrModify()
663{ 675{
664 if ( data->count != 1 ) 676 if ( data->count != 1 )
665 { 677 {
666 data->deref(); 678 data->deref();
667 OPimTodoData* d2 = new OPimTodoData(); 679 OPimTodoData* d2 = new OPimTodoData();
668 copy( data, d2 ); 680 copy( data, d2 );
669 data = d2; 681 data = d2;
670 } 682 }
671} 683}
672 684
673 685
674// WATCHOUT 686// WATCHOUT
675/* 687/*
676 * if you add something to the Data struct 688 * if you add something to the Data struct
677 * be sure to copy it here 689 * be sure to copy it here
678 */ 690 */
679void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) 691void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest )
680{ 692{
681 dest->date = src->date; 693 dest->date = src->date;
682 dest->isCompleted = src->isCompleted; 694 dest->isCompleted = src->isCompleted;
683 dest->hasDate = src->hasDate; 695 dest->hasDate = src->hasDate;
684 dest->priority = src->priority; 696 dest->priority = src->priority;
685 dest->desc = src->desc; 697 dest->desc = src->desc;
686 dest->sum = src->sum; 698 dest->sum = src->sum;
687 dest->extra = src->extra; 699 dest->extra = src->extra;
688 dest->prog = src->prog; 700 dest->prog = src->prog;
689 701
690 if ( src->state ) 702 if ( src->state )
691 dest->state = new OPimState( *src->state ); 703 dest->state = new OPimState( *src->state );
692 704
693 if ( src->recur ) 705 if ( src->recur )
694 dest->recur = new OPimRecurrence( *src->recur ); 706 dest->recur = new OPimRecurrence( *src->recur );
695 707
696 if ( src->maintainer ) 708 if ( src->maintainer )
697 dest->maintainer = new OPimMaintainer( *src->maintainer ) 709 dest->maintainer = new OPimMaintainer( *src->maintainer )
698 ; 710 ;
699 dest->start = src->start; 711 dest->start = src->start;
700 dest->completed = src->completed; 712 dest->completed = src->completed;
701 713
702 if ( src->notifiers ) 714 if ( src->notifiers )
703 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 715 dest->notifiers = new OPimNotifyManager( *src->notifiers );
704} 716}
705 717
706 718
707QString OPimTodo::type() const 719QString OPimTodo::type() const
708{ 720{
709 return QString::fromLatin1( "OPimTodo" ); 721 return QString::fromLatin1( "OPimTodo" );
710} 722}
711 723
712 724
713QString OPimTodo::recordField( int id) const 725QString OPimTodo::recordField( int id) const
714{ 726{
715 QString res; 727 QString res;
716 Q_UNUSED( id ) 728 Q_UNUSED( id )
717#if 0 729#if 0
718 switch( id ) { 730 switch( id ) {
719 case HasDate: 731 case HasDate:
720 res = (hasDueDate() ? 732 res = (hasDueDate() ?
721 QObject::tr( "Has a due-date" ) 733 QObject::tr( "Has a due-date" )
722 : QObject::tr( "No due-date" )); 734 : QObject::tr( "No due-date" ));
723 break; 735 break;
724 case Completed: 736 case Completed:
725 res = ( isCompleted() ? 737 res = ( isCompleted() ?
726 QObject::tr( "Completed" ) : 738 QObject::tr( "Completed" ) :
727 QObject::tr( "Not completed" )); 739 QObject::tr( "Not completed" ));
728 break; 740 break;
729 case Description: 741 case Description:
730 res = description(); 742 res = description();
731 break; 743 break;
732 case Summary: 744 case Summary:
733 res = summary(); 745 res = summary();
734 break; 746 break;
735 case Priority: 747 case Priority:
736 res = QString::number( priority() ); 748 res = QString::number( priority() );
737 break; 749 break;
738 case DateDay: 750 case DateDay:
739 res = QString::number( dueDate().day() ); 751 res = QString::number( dueDate().day() );
740 break; 752 break;
741 case DateMonth: 753 case DateMonth:
742 res = QString::number( dueDate().month() ); 754 res = QString::number( dueDate().month() );
743 break; 755 break;
744 case DateYear: 756 case DateYear:
745 res = QString::number( dueDate().year() ); 757 res = QString::number( dueDate().year() );
746 break; 758 break;
747 case Progress: 759 case Progress:
748 res = QString::number( progress() ); 760 res = QString::number( progress() );
749 break; 761 break;
750 case State: 762 case State:
751 res = QString::number( state().state() ); 763 res = QString::number( state().state() );
752 break; 764 break;
753 case Recurrence: 765 case Recurrence:
754 res = ( hasRecurrence() ? 766 res = ( hasRecurrence() ?
755 QString::null /*recurrence().summary()*/ : 767 QString::null /*recurrence().summary()*/ :
756 QObject::tr("No reccurrence")); 768 QObject::tr("No reccurrence"));
757 break; 769 break;
758 case Alarms: 770 case Alarms:
759 break; 771 break;
760 case Reminders: 772 case Reminders:
761 break; 773 break;
762 case Maintainer: 774 case Maintainer:
763 break; 775 break;
764 case StartDate: 776 case StartDate:
765 res = ( hasStartDate() ? 777 res = ( hasStartDate() ?
766 /*TimeString::()*/ QString::null : 778 /*TimeString::()*/ QString::null :
767 QObject::tr( "No start-date" ) ); 779 QObject::tr( "No start-date" ) );
768 break; 780 break;
769 case CompletedDate: 781 case CompletedDate:
770 res = ( hasCompletedDate() ? 782 res = ( hasCompletedDate() ?
771 /*TimeString::()*/ QString::null : 783 /*TimeString::()*/ QString::null :
772 QObject::tr( "No completed-date" ) ); 784 QObject::tr( "No completed-date" ) );
773 break; 785 break;
774 case DueDate: 786 case DueDate:
775 res = ( hasDueDate() ? 787 res = ( hasDueDate() ?
776 /*TimeString::()*/ QString::null : 788 /*TimeString::()*/ QString::null :
777 QObject::tr( "No due-date" ); 789 QObject::tr( "No due-date" );
778 break; 790 break;
779 default: 791 default:
780 res = OPimRecord::recordField( id ); 792 res = OPimRecord::recordField( id );
781 } 793 }
782 794
783#endif 795#endif
784 return res; 796 return res;
785} 797}
786 798
787 799
788int OPimTodo::rtti() const 800int OPimTodo::rtti() const
789{ 801{
790 return OPimResolver::TodoList; 802 return OPimResolver::TodoList;
791} 803}
792 804
793/** 805/**
794 * \brief Provide a SafeCast to OPimTodo from a OPimRecord 806 * \brief Provide a SafeCast to OPimTodo from a OPimRecord
795 * 807 *
796 * Provide a safe cast that will return 0 if the record 808 * Provide a safe cast that will return 0 if the record
797 * type is not OPimTodo. In the other case it will 809 * type is not OPimTodo. In the other case it will
798 * be casted to OPimTodo and returned 810 * be casted to OPimTodo and returned
799 * 811 *
800 * @param rec The OPimRecord to be casted 812 * @param rec The OPimRecord to be casted
801 * 813 *
802 * @return a pointer to OPimTodo or 0l 814 * @return a pointer to OPimTodo or 0l
803 */ 815 */
804OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) { 816OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) {
805 return (rec && rec->rtti() == OPimResolver::TodoList ) ? 817 return (rec && rec->rtti() == OPimResolver::TodoList ) ?
806 static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) : 818 static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) :
807 0l; 819 0l;
808} 820}
809 821
810} 822}