Diffstat (limited to 'libopie2/opiepim/core/opimtodo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimtodo.cpp | 127 |
1 files changed, 112 insertions, 15 deletions
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp index 27b36a6..16ca987 100644 --- a/libopie2/opiepim/core/opimtodo.cpp +++ b/libopie2/opiepim/core/opimtodo.cpp | |||
@@ -19,226 +19,242 @@ | |||
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 | ||
50 | namespace Opie | 50 | namespace Opie |
51 | { | 51 | { |
52 | 52 | ||
53 | struct OPimTodo::OPimTodoData : public QShared | 53 | struct 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 | } | 68 | } |
68 | 69 | ||
69 | QDate date; | 70 | QDate date; |
70 | bool isCompleted: 1; | 71 | bool isCompleted: 1; |
71 | bool hasDate: 1; | 72 | bool hasDate: 1; |
72 | int priority; | 73 | int priority; |
73 | QString desc; | 74 | QString desc; |
74 | QString sum; | 75 | QString sum; |
75 | QMap<QString, QString> extra; | 76 | QMap<QString, QString> extra; |
76 | ushort prog; | 77 | ushort prog; |
77 | OPimState *state; | 78 | OPimState *state; |
78 | OPimRecurrence *recur; | 79 | OPimRecurrence *recur; |
79 | OPimMaintainer *maintainer; | 80 | OPimMaintainer *maintainer; |
80 | QDate start; | 81 | QDate start; |
81 | QDate completed; | 82 | QDate completed; |
82 | OPimNotifyManager *notifiers; | 83 | OPimNotifyManager *notifiers; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | 86 | ||
86 | OPimTodo::OPimTodo( const OPimTodo &event ) | 87 | OPimTodo::OPimTodo( const OPimTodo &event ) |
87 | : OPimRecord( event ), data( event.data ) | 88 | : OPimRecord( event ), data( event.data ) |
88 | { | 89 | { |
89 | data->ref(); | 90 | data->ref(); |
90 | // owarn << "ref up" << oendl; | ||
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | OPimTodo::~OPimTodo() | 94 | OPimTodo::~OPimTodo() |
95 | { | 95 | { |
96 | 96 | ||
97 | // owarn << "~OPimTodo " << oendl; | ||
98 | if ( data->deref() ) | 97 | if ( data->deref() ) |
99 | { | 98 | { |
100 | // owarn << "OPimTodo::dereffing" << oendl; | ||
101 | delete data; | 99 | delete data; |
102 | data = 0l; | 100 | data = 0l; |
103 | } | 101 | } |
104 | } | 102 | } |
105 | 103 | ||
106 | 104 | ||
107 | OPimTodo::OPimTodo( bool completed, int priority, | 105 | OPimTodo::OPimTodo( bool completed, int priority, |
108 | const QArray<int> &category, | 106 | const QArray<int> &category, |
109 | const QString& summary, | 107 | const QString& summary, |
110 | const QString &description, | 108 | const QString &description, |
111 | ushort progress, | 109 | ushort progress, |
112 | bool hasDate, QDate date, int uid ) | 110 | bool hasDate, QDate date, int uid ) |
113 | : OPimRecord( uid ) | 111 | : OPimRecord( uid ) |
114 | { | 112 | { |
115 | // owarn << "OPimTodoData " + summary << oendl; | ||
116 | setCategories( category ); | 113 | setCategories( category ); |
117 | 114 | ||
118 | data = new OPimTodoData; | 115 | data = new OPimTodoData; |
119 | 116 | ||
120 | data->date = date; | 117 | data->date = date; |
121 | data->isCompleted = completed; | 118 | data->isCompleted = completed; |
122 | data->hasDate = hasDate; | 119 | data->hasDate = hasDate; |
123 | data->priority = priority; | 120 | data->priority = priority; |
124 | data->sum = summary; | 121 | data->sum = summary; |
125 | data->prog = progress; | 122 | data->prog = progress; |
126 | data->desc = Qtopia::simplifyMultiLineSpace( description ); | 123 | data->desc = Qtopia::simplifyMultiLineSpace( description ); |
127 | } | 124 | } |
128 | 125 | ||
129 | 126 | ||
130 | OPimTodo::OPimTodo( bool completed, int priority, | 127 | OPimTodo::OPimTodo( bool completed, int priority, |
131 | const QStringList &category, | 128 | const QStringList &category, |
132 | const QString& summary, | 129 | const QString& summary, |
133 | const QString &description, | 130 | const QString &description, |
134 | ushort progress, | 131 | ushort progress, |
135 | bool hasDate, QDate date, int uid ) | 132 | bool hasDate, QDate date, int uid ) |
136 | : OPimRecord( uid ) | 133 | : OPimRecord( uid ) |
137 | { | 134 | { |
138 | // owarn << "OPimTodoData" + summary << oendl; | ||
139 | setCategories( idsFromString( category.join( ";" ) ) ); | 135 | setCategories( idsFromString( category.join( ";" ) ) ); |
140 | 136 | ||
141 | data = new OPimTodoData; | 137 | data = new OPimTodoData; |
142 | 138 | ||
143 | data->date = date; | 139 | data->date = date; |
144 | data->isCompleted = completed; | 140 | data->isCompleted = completed; |
145 | data->hasDate = hasDate; | 141 | data->hasDate = hasDate; |
146 | data->priority = priority; | 142 | data->priority = priority; |
147 | data->sum = summary; | 143 | data->sum = summary; |
148 | data->prog = progress; | 144 | data->prog = progress; |
149 | data->desc = Qtopia::simplifyMultiLineSpace( description ); | 145 | data->desc = Qtopia::simplifyMultiLineSpace( description ); |
150 | } | 146 | } |
151 | 147 | ||
152 | 148 | ||
153 | bool OPimTodo::match( const QRegExp ®Exp ) const | 149 | bool OPimTodo::match( const QRegExp ®Exp ) const |
154 | { | 150 | { |
155 | if ( QString::number( data->priority ).find( regExp ) != -1 ) | 151 | if ( QString::number( data->priority ).find( regExp ) != -1 ) |
156 | { | 152 | { |
157 | setLastHitField( Priority ); | 153 | setLastHitField( Priority ); |
158 | return true; | 154 | return true; |
159 | } | 155 | } |
160 | else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) | 156 | else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) |
161 | { | 157 | { |
162 | setLastHitField( HasDate ); | 158 | setLastHitField( HasDate ); |
163 | return true; | 159 | return true; |
164 | } | 160 | } |
165 | else if ( data->desc.find( regExp ) != -1 ) | 161 | else if ( data->desc.find( regExp ) != -1 ) |
166 | { | 162 | { |
167 | setLastHitField( Description ); | 163 | setLastHitField( Description ); |
168 | return true; | 164 | return true; |
169 | } | 165 | } |
170 | else if ( data->sum.find( regExp ) != -1 ) | 166 | else if ( data->sum.find( regExp ) != -1 ) |
171 | { | 167 | { |
172 | setLastHitField( Summary ); | 168 | setLastHitField( Summary ); |
173 | return true; | 169 | return true; |
174 | } | 170 | } |
175 | return false; | 171 | return false; |
176 | } | 172 | } |
177 | 173 | ||
178 | 174 | ||
179 | bool OPimTodo::isCompleted() const | 175 | bool OPimTodo::isCompleted() const |
180 | { | 176 | { |
181 | return data->isCompleted; | 177 | return data->isCompleted; |
182 | } | 178 | } |
183 | 179 | ||
184 | 180 | ||
185 | bool OPimTodo::hasDueDate() const | 181 | bool OPimTodo::hasDueDate() const |
186 | { | 182 | { |
187 | return data->hasDate; | 183 | return data->hasDate; |
188 | } | 184 | } |
189 | 185 | ||
190 | 186 | /** | |
187 | * \brief Does this Todo have a start date | ||
188 | * | ||
189 | * Does this Todo have a start date. The decision | ||
190 | * is based on if the internal startDate isValid | ||
191 | * in the sense of QDate::isValid. | ||
192 | * | ||
193 | * @return True if the startDate isValid | ||
194 | * @see startDate | ||
195 | * @see setStartDate | ||
196 | * @see QDate::isValid() | ||
197 | */ | ||
191 | bool OPimTodo::hasStartDate() const | 198 | bool OPimTodo::hasStartDate() const |
192 | { | 199 | { |
193 | return data->start.isValid(); | 200 | return data->start.isValid(); |
194 | } | 201 | } |
195 | 202 | ||
196 | 203 | /** | |
204 | * \brief Does this Todo have a Date when it was completed | ||
205 | * | ||
206 | * As in \sa hasStartDate() it is determined if there | ||
207 | * is a completed date by looking if the internal date | ||
208 | * isValid \sa QDate::isValid. | ||
209 | * | ||
210 | * @see hasStartDate | ||
211 | * @return True if the completedDate is set and valid. | ||
212 | */ | ||
197 | bool OPimTodo::hasCompletedDate() const | 213 | bool OPimTodo::hasCompletedDate() const |
198 | { | 214 | { |
199 | return data->completed.isValid(); | 215 | return data->completed.isValid(); |
200 | } | 216 | } |
201 | 217 | ||
202 | 218 | ||
203 | int OPimTodo::priority() const | 219 | int OPimTodo::priority() const |
204 | { | 220 | { |
205 | return data->priority; | 221 | return data->priority; |
206 | } | 222 | } |
207 | 223 | ||
208 | 224 | ||
209 | QString OPimTodo::summary() const | 225 | QString OPimTodo::summary() const |
210 | { | 226 | { |
211 | return data->sum; | 227 | return data->sum; |
212 | } | 228 | } |
213 | 229 | ||
214 | 230 | ||
215 | ushort OPimTodo::progress() const | 231 | ushort OPimTodo::progress() const |
216 | { | 232 | { |
217 | return data->prog; | 233 | return data->prog; |
218 | } | 234 | } |
219 | 235 | ||
220 | 236 | ||
221 | QDate OPimTodo::dueDate() const | 237 | QDate OPimTodo::dueDate() const |
222 | { | 238 | { |
223 | return data->date; | 239 | return data->date; |
224 | } | 240 | } |
225 | 241 | ||
226 | 242 | ||
227 | QDate OPimTodo::startDate() const | 243 | QDate OPimTodo::startDate() const |
228 | { | 244 | { |
229 | return data->start; | 245 | return data->start; |
230 | } | 246 | } |
231 | 247 | ||
232 | 248 | ||
233 | QDate OPimTodo::completedDate() const | 249 | QDate OPimTodo::completedDate() const |
234 | { | 250 | { |
235 | return data->completed; | 251 | return data->completed; |
236 | } | 252 | } |
237 | 253 | ||
238 | 254 | ||
239 | QString OPimTodo::description() const | 255 | QString OPimTodo::description() const |
240 | { | 256 | { |
241 | return data->desc; | 257 | return data->desc; |
242 | } | 258 | } |
243 | 259 | ||
244 | 260 | ||
@@ -263,169 +279,168 @@ OPimState OPimTodo::state() const | |||
263 | 279 | ||
264 | bool OPimTodo::hasRecurrence() const | 280 | bool OPimTodo::hasRecurrence() const |
265 | { | 281 | { |
266 | if ( !data->recur ) return false; | 282 | if ( !data->recur ) return false; |
267 | return data->recur->doesRecur(); | 283 | return data->recur->doesRecur(); |
268 | } | 284 | } |
269 | 285 | ||
270 | 286 | ||
271 | OPimRecurrence OPimTodo::recurrence() const | 287 | OPimRecurrence OPimTodo::recurrence() const |
272 | { | 288 | { |
273 | if ( !data->recur ) return OPimRecurrence(); | 289 | if ( !data->recur ) return OPimRecurrence(); |
274 | 290 | ||
275 | return ( *data->recur ); | 291 | return ( *data->recur ); |
276 | } | 292 | } |
277 | 293 | ||
278 | 294 | ||
279 | bool OPimTodo::hasMaintainer() const | 295 | bool OPimTodo::hasMaintainer() const |
280 | { | 296 | { |
281 | if ( !data->maintainer ) return false; | 297 | if ( !data->maintainer ) return false; |
282 | 298 | ||
283 | return ( data->maintainer->mode() != OPimMaintainer::Undefined ); | 299 | return ( data->maintainer->mode() != OPimMaintainer::Undefined ); |
284 | } | 300 | } |
285 | 301 | ||
286 | 302 | ||
287 | OPimMaintainer OPimTodo::maintainer() const | 303 | OPimMaintainer OPimTodo::maintainer() const |
288 | { | 304 | { |
289 | if ( !data->maintainer ) return OPimMaintainer(); | 305 | if ( !data->maintainer ) return OPimMaintainer(); |
290 | 306 | ||
291 | return ( *data->maintainer ); | 307 | return ( *data->maintainer ); |
292 | } | 308 | } |
293 | 309 | ||
294 | 310 | ||
295 | void OPimTodo::setCompleted( bool completed ) | 311 | void OPimTodo::setCompleted( bool completed ) |
296 | { | 312 | { |
297 | changeOrModify(); | 313 | changeOrModify(); |
298 | data->isCompleted = completed; | 314 | data->isCompleted = completed; |
299 | } | 315 | } |
300 | 316 | ||
301 | 317 | ||
302 | void OPimTodo::setHasDueDate( bool hasDate ) | 318 | void OPimTodo::setHasDueDate( bool hasDate ) |
303 | { | 319 | { |
304 | changeOrModify(); | 320 | changeOrModify(); |
305 | data->hasDate = hasDate; | 321 | data->hasDate = hasDate; |
306 | } | 322 | } |
307 | 323 | ||
308 | 324 | ||
309 | void OPimTodo::setDescription( const QString &desc ) | 325 | void OPimTodo::setDescription( const QString &desc ) |
310 | { | 326 | { |
311 | // owarn << "desc " + desc << oendl; | ||
312 | changeOrModify(); | 327 | changeOrModify(); |
313 | data->desc = Qtopia::simplifyMultiLineSpace( desc ); | 328 | data->desc = Qtopia::simplifyMultiLineSpace( desc ); |
314 | } | 329 | } |
315 | 330 | ||
316 | 331 | ||
317 | void OPimTodo::setSummary( const QString& sum ) | 332 | void OPimTodo::setSummary( const QString& sum ) |
318 | { | 333 | { |
319 | changeOrModify(); | 334 | changeOrModify(); |
320 | data->sum = sum; | 335 | data->sum = sum; |
321 | } | 336 | } |
322 | 337 | ||
323 | 338 | ||
324 | void OPimTodo::setPriority( int prio ) | 339 | void OPimTodo::setPriority( int prio ) |
325 | { | 340 | { |
326 | changeOrModify(); | 341 | changeOrModify(); |
327 | data->priority = prio; | 342 | data->priority = prio; |
328 | } | 343 | } |
329 | 344 | ||
330 | 345 | ||
331 | void OPimTodo::setDueDate( const QDate& date ) | 346 | void OPimTodo::setDueDate( const QDate& date ) |
332 | { | 347 | { |
333 | changeOrModify(); | 348 | changeOrModify(); |
334 | data->date = date; | 349 | data->date = date; |
335 | } | 350 | } |
336 | 351 | ||
337 | 352 | ||
338 | void OPimTodo::setStartDate( const QDate& date ) | 353 | void OPimTodo::setStartDate( const QDate& date ) |
339 | { | 354 | { |
340 | changeOrModify(); | 355 | changeOrModify(); |
341 | data->start = date; | 356 | data->start = date; |
342 | } | 357 | } |
343 | 358 | ||
344 | 359 | ||
345 | void OPimTodo::setCompletedDate( const QDate& date ) | 360 | void OPimTodo::setCompletedDate( const QDate& date ) |
346 | { | 361 | { |
347 | changeOrModify(); | 362 | changeOrModify(); |
348 | data->completed = date; | 363 | data->completed = date; |
349 | } | 364 | } |
350 | 365 | ||
351 | 366 | ||
352 | void OPimTodo::setState( const OPimState& state ) | 367 | void OPimTodo::setState( const OPimState& state ) |
353 | { | 368 | { |
354 | changeOrModify(); | 369 | changeOrModify(); |
355 | if ( data->state ) | 370 | if ( data->state ) |
356 | ( *data->state ) = state; | 371 | ( *data->state ) = state; |
357 | else | 372 | else |
358 | data->state = new OPimState( state ); | 373 | data->state = new OPimState( state ); |
359 | } | 374 | } |
360 | 375 | ||
361 | 376 | ||
362 | void OPimTodo::setRecurrence( const OPimRecurrence& rec ) | 377 | void OPimTodo::setRecurrence( const OPimRecurrence& rec ) |
363 | { | 378 | { |
364 | changeOrModify(); | 379 | changeOrModify(); |
365 | if ( data->recur ) | 380 | if ( data->recur ) |
366 | ( *data->recur ) = rec; | 381 | ( *data->recur ) = rec; |
367 | else | 382 | else |
368 | data->recur = new OPimRecurrence( rec ); | 383 | data->recur = new OPimRecurrence( rec ); |
369 | } | 384 | } |
370 | 385 | ||
371 | 386 | ||
372 | void OPimTodo::setMaintainer( const OPimMaintainer& pim ) | 387 | void OPimTodo::setMaintainer( const OPimMaintainer& pim ) |
373 | { | 388 | { |
374 | changeOrModify(); | 389 | changeOrModify(); |
375 | 390 | ||
376 | if ( data->maintainer ) | 391 | if ( data->maintainer ) |
377 | ( *data->maintainer ) = pim; | 392 | ( *data->maintainer ) = pim; |
378 | else | 393 | else |
379 | data->maintainer = new OPimMaintainer( pim ); | 394 | data->maintainer = new OPimMaintainer( pim ); |
380 | } | 395 | } |
381 | 396 | ||
382 | 397 | ||
383 | bool OPimTodo::isOverdue( ) | 398 | bool OPimTodo::isOverdue( )const |
384 | { | 399 | { |
385 | if ( data->hasDate && !data->isCompleted ) | 400 | if ( data->hasDate && !data->isCompleted ) |
386 | return QDate::currentDate() > data->date; | 401 | return QDate::currentDate() > data->date; |
387 | return false; | 402 | return false; |
388 | } | 403 | } |
389 | 404 | ||
390 | 405 | ||
391 | void OPimTodo::setProgress( ushort progress ) | 406 | void OPimTodo::setProgress( ushort progress ) |
392 | { | 407 | { |
393 | changeOrModify(); | 408 | changeOrModify(); |
394 | data->prog = progress; | 409 | data->prog = progress; |
395 | } | 410 | } |
396 | 411 | ||
397 | 412 | ||
398 | QString OPimTodo::toShortText() const | 413 | QString OPimTodo::toShortText() const |
399 | { | 414 | { |
400 | return summary(); | 415 | return summary(); |
401 | } | 416 | } |
402 | 417 | ||
403 | 418 | ||
404 | /*! | 419 | /*! |
405 | Returns a richt text string | 420 | Returns a richt text string |
406 | */ | 421 | */ |
407 | QString OPimTodo::toRichText() const | 422 | QString OPimTodo::toRichText() const |
408 | { | 423 | { |
409 | QString text; | 424 | QString text; |
410 | QStringList catlist; | 425 | QStringList catlist; |
411 | 426 | ||
412 | // summary | 427 | // summary |
413 | text += "<b><h3><img src=\"todo/TodoList\"> "; | 428 | text += "<b><h3><img src=\"todo/TodoList\"> "; |
414 | if ( !summary().isEmpty() ) | 429 | if ( !summary().isEmpty() ) |
415 | { | 430 | { |
416 | text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); | 431 | text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); |
417 | } | 432 | } |
418 | text += "</h3></b><br><hr><br>"; | 433 | text += "</h3></b><br><hr><br>"; |
419 | 434 | ||
420 | // description | 435 | // description |
421 | if ( !description().isEmpty() ) | 436 | if ( !description().isEmpty() ) |
422 | { | 437 | { |
423 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | 438 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; |
424 | text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; | 439 | text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; |
425 | } | 440 | } |
426 | 441 | ||
427 | // priority | 442 | // priority |
428 | int priorityval = priority(); | 443 | int priorityval = priority(); |
429 | text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" + | 444 | text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" + |
430 | QString::number( priorityval ) + "\"> "; | 445 | QString::number( priorityval ) + "\"> "; |
431 | 446 | ||
@@ -548,166 +563,248 @@ bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const | |||
548 | } | 563 | } |
549 | else | 564 | else |
550 | { | 565 | { |
551 | return dueDate() > toDoEvent.dueDate(); | 566 | return dueDate() > toDoEvent.dueDate(); |
552 | } | 567 | } |
553 | } | 568 | } |
554 | return false; | 569 | return false; |
555 | } | 570 | } |
556 | 571 | ||
557 | 572 | ||
558 | bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const | 573 | bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const |
559 | { | 574 | { |
560 | if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 575 | if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
561 | if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 576 | if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
562 | if ( hasDueDate() && toDoEvent.hasDueDate() ) | 577 | if ( hasDueDate() && toDoEvent.hasDueDate() ) |
563 | { | 578 | { |
564 | if ( dueDate() == toDoEvent.dueDate() ) | 579 | if ( dueDate() == toDoEvent.dueDate() ) |
565 | { // let's the priority decide | 580 | { // let's the priority decide |
566 | return priority() > toDoEvent.priority(); | 581 | return priority() > toDoEvent.priority(); |
567 | } | 582 | } |
568 | else | 583 | else |
569 | { | 584 | { |
570 | return dueDate() > toDoEvent.dueDate(); | 585 | return dueDate() > toDoEvent.dueDate(); |
571 | } | 586 | } |
572 | } | 587 | } |
573 | return true; | 588 | return true; |
574 | } | 589 | } |
575 | 590 | ||
576 | 591 | ||
577 | bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const | 592 | bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const |
578 | { | 593 | { |
579 | if ( data->priority != toDoEvent.data->priority ) return false; | 594 | if ( data->priority != toDoEvent.data->priority ) return false; |
580 | if ( data->priority != toDoEvent.data->prog ) return false; | 595 | if ( data->priority != toDoEvent.data->prog ) return false; |
581 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 596 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
582 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 597 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
583 | if ( data->date != toDoEvent.data->date ) return false; | 598 | if ( data->date != toDoEvent.data->date ) return false; |
584 | if ( data->sum != toDoEvent.data->sum ) return false; | 599 | if ( data->sum != toDoEvent.data->sum ) return false; |
585 | if ( data->desc != toDoEvent.data->desc ) return false; | 600 | if ( data->desc != toDoEvent.data->desc ) return false; |
586 | if ( data->maintainer != toDoEvent.data->maintainer ) | 601 | if ( data->maintainer != toDoEvent.data->maintainer ) |
587 | return false; | 602 | return false; |
588 | 603 | ||
589 | return OPimRecord::operator==( toDoEvent ); | 604 | return OPimRecord::operator==( toDoEvent ); |
590 | } | 605 | } |
591 | 606 | ||
592 | 607 | ||
593 | void OPimTodo::deref() | 608 | void OPimTodo::deref() |
594 | { | 609 | { |
595 | 610 | ||
596 | // owarn << "deref in ToDoEvent" << oendl; | ||
597 | if ( data->deref() ) | 611 | if ( data->deref() ) |
598 | { | 612 | { |
599 | // owarn << "deleting" << oendl; | ||
600 | delete data; | 613 | delete data; |
601 | data = 0; | 614 | data = 0; |
602 | } | 615 | } |
603 | } | 616 | } |
604 | 617 | ||
605 | 618 | ||
606 | OPimTodo &OPimTodo::operator=( const OPimTodo &item ) | 619 | OPimTodo &OPimTodo::operator=( const OPimTodo &item ) |
607 | { | 620 | { |
608 | if ( this == &item ) return * this; | 621 | if ( this == &item ) return * this; |
609 | 622 | ||
610 | OPimRecord::operator=( item ); | 623 | OPimRecord::operator=( item ); |
611 | //owarn << "operator= ref " << oendl; | ||
612 | item.data->ref(); | 624 | item.data->ref(); |
613 | deref(); | 625 | deref(); |
614 | data = item.data; | 626 | data = item.data; |
615 | 627 | ||
616 | return *this; | 628 | return *this; |
617 | } | 629 | } |
618 | 630 | ||
619 | 631 | ||
620 | QMap<int, QString> OPimTodo::toMap() const | 632 | QMap<int, QString> OPimTodo::toMap() const |
621 | { | 633 | { |
622 | QMap<int, QString> map; | 634 | QMap<int, QString> map; |
623 | 635 | ||
624 | map.insert( Uid, QString::number( uid() ) ); | 636 | map.insert( Uid, QString::number( uid() ) ); |
625 | map.insert( Category, idsToString( categories() ) ); | 637 | map.insert( Category, idsToString( categories() ) ); |
626 | map.insert( HasDate, QString::number( data->hasDate ) ); | 638 | map.insert( HasDate, QString::number( data->hasDate ) ); |
627 | map.insert( Completed, QString::number( data->isCompleted ) ); | 639 | map.insert( Completed, QString::number( data->isCompleted ) ); |
628 | map.insert( Description, data->desc ); | 640 | map.insert( Description, data->desc ); |
629 | map.insert( Summary, data->sum ); | 641 | map.insert( Summary, data->sum ); |
630 | map.insert( Priority, QString::number( data->priority ) ); | 642 | map.insert( Priority, QString::number( data->priority ) ); |
631 | map.insert( DateDay, QString::number( data->date.day() ) ); | 643 | map.insert( DateDay, QString::number( data->date.day() ) ); |
632 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 644 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
633 | map.insert( DateYear, QString::number( data->date.year() ) ); | 645 | map.insert( DateYear, QString::number( data->date.year() ) ); |
634 | map.insert( Progress, QString::number( data->prog ) ); | 646 | map.insert( Progress, QString::number( data->prog ) ); |
635 | // map.insert( CrossReference, crossToString() ); | 647 | // map.insert( CrossReference, crossToString() ); |
636 | /* FIXME!!! map.insert( State, ); | 648 | /* FIXME!!! map.insert( State, ); |
637 | map.insert( Recurrence, ); | 649 | map.insert( Recurrence, ); |
638 | map.insert( Reminders, ); | 650 | map.insert( Reminders, ); |
639 | map. | 651 | map. |
640 | */ | 652 | */ |
641 | return map; | 653 | return map; |
642 | } | 654 | } |
643 | 655 | ||
644 | 656 | ||
645 | /** | 657 | /** |
646 | * change or modify looks at the ref count and either | 658 | * change or modify looks at the ref count and either |
647 | * creates a new QShared Object or it can modify it | 659 | * creates a new QShared Object or it can modify it |
648 | * right in place | 660 | * right in place |
649 | */ | 661 | */ |
650 | void OPimTodo::changeOrModify() | 662 | void OPimTodo::changeOrModify() |
651 | { | 663 | { |
652 | if ( data->count != 1 ) | 664 | if ( data->count != 1 ) |
653 | { | 665 | { |
654 | owarn << "changeOrModify" << oendl; | ||
655 | data->deref(); | 666 | data->deref(); |
656 | OPimTodoData* d2 = new OPimTodoData(); | 667 | OPimTodoData* d2 = new OPimTodoData(); |
657 | copy( data, d2 ); | 668 | copy( data, d2 ); |
658 | data = d2; | 669 | data = d2; |
659 | } | 670 | } |
660 | } | 671 | } |
661 | 672 | ||
662 | 673 | ||
663 | // WATCHOUT | 674 | // WATCHOUT |
664 | /* | 675 | /* |
665 | * if you add something to the Data struct | 676 | * if you add something to the Data struct |
666 | * be sure to copy it here | 677 | * be sure to copy it here |
667 | */ | 678 | */ |
668 | void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) | 679 | void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) |
669 | { | 680 | { |
670 | dest->date = src->date; | 681 | dest->date = src->date; |
671 | dest->isCompleted = src->isCompleted; | 682 | dest->isCompleted = src->isCompleted; |
672 | dest->hasDate = src->hasDate; | 683 | dest->hasDate = src->hasDate; |
673 | dest->priority = src->priority; | 684 | dest->priority = src->priority; |
674 | dest->desc = src->desc; | 685 | dest->desc = src->desc; |
675 | dest->sum = src->sum; | 686 | dest->sum = src->sum; |
676 | dest->extra = src->extra; | 687 | dest->extra = src->extra; |
677 | dest->prog = src->prog; | 688 | dest->prog = src->prog; |
678 | 689 | ||
679 | if ( src->state ) | 690 | if ( src->state ) |
680 | dest->state = new OPimState( *src->state ); | 691 | dest->state = new OPimState( *src->state ); |
681 | 692 | ||
682 | if ( src->recur ) | 693 | if ( src->recur ) |
683 | dest->recur = new OPimRecurrence( *src->recur ); | 694 | dest->recur = new OPimRecurrence( *src->recur ); |
684 | 695 | ||
685 | if ( src->maintainer ) | 696 | if ( src->maintainer ) |
686 | dest->maintainer = new OPimMaintainer( *src->maintainer ) | 697 | dest->maintainer = new OPimMaintainer( *src->maintainer ) |
687 | ; | 698 | ; |
688 | dest->start = src->start; | 699 | dest->start = src->start; |
689 | dest->completed = src->completed; | 700 | dest->completed = src->completed; |
690 | 701 | ||
691 | if ( src->notifiers ) | 702 | if ( src->notifiers ) |
692 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | 703 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); |
693 | } | 704 | } |
694 | 705 | ||
695 | 706 | ||
696 | QString OPimTodo::type() const | 707 | QString OPimTodo::type() const |
697 | { | 708 | { |
698 | return QString::fromLatin1( "OPimTodo" ); | 709 | return QString::fromLatin1( "OPimTodo" ); |
699 | } | 710 | } |
700 | 711 | ||
701 | 712 | ||
702 | QString OPimTodo::recordField( int /*id*/ ) const | 713 | QString OPimTodo::recordField( int id) const |
703 | { | 714 | { |
704 | return QString::null; | 715 | QString res; |
716 | Q_UNUSED( id ) | ||
717 | #if 0 | ||
718 | switch( id ) { | ||
719 | case HasDate: | ||
720 | res = (hasDueDate() ? | ||
721 | QObject::tr( "Has a due-date" ) | ||
722 | : QObject::tr( "No due-date" )); | ||
723 | break; | ||
724 | case Completed: | ||
725 | res = ( isCompleted() ? | ||
726 | QObject::tr( "Completed" ) : | ||
727 | QObject::tr( "Not completed" )); | ||
728 | break; | ||
729 | case Description: | ||
730 | res = description(); | ||
731 | break; | ||
732 | case Summary: | ||
733 | res = summary(); | ||
734 | break; | ||
735 | case Priority: | ||
736 | res = QString::number( priority() ); | ||
737 | break; | ||
738 | case DateDay: | ||
739 | res = QString::number( dueDate().day() ); | ||
740 | break; | ||
741 | case DateMonth: | ||
742 | res = QString::number( dueDate().month() ); | ||
743 | break; | ||
744 | case DateYear: | ||
745 | res = QString::number( dueDate().year() ); | ||
746 | break; | ||
747 | case Progress: | ||
748 | res = QString::number( progress() ); | ||
749 | break; | ||
750 | case State: | ||
751 | res = QString::number( state().state() ); | ||
752 | break; | ||
753 | case Recurrence: | ||
754 | res = ( hasRecurrence() ? | ||
755 | QString::null /*recurrence().summary()*/ : | ||
756 | QObject::tr("No reccurrence")); | ||
757 | break; | ||
758 | case Alarms: | ||
759 | break; | ||
760 | case Reminders: | ||
761 | break; | ||
762 | case Maintainer: | ||
763 | break; | ||
764 | case StartDate: | ||
765 | res = ( hasStartDate() ? | ||
766 | /*TimeString::()*/ QString::null : | ||
767 | QObject::tr( "No start-date" ) ); | ||
768 | break; | ||
769 | case CompletedDate: | ||
770 | res = ( hasCompletedDate() ? | ||
771 | /*TimeString::()*/ QString::null : | ||
772 | QObject::tr( "No completed-date" ) ); | ||
773 | break; | ||
774 | case DueDate: | ||
775 | res = ( hasDueDate() ? | ||
776 | /*TimeString::()*/ QString::null : | ||
777 | QObject::tr( "No due-date" ); | ||
778 | break; | ||
779 | default: | ||
780 | res = OPimRecord::recordField( id ); | ||
781 | } | ||
782 | |||
783 | #endif | ||
784 | return res; | ||
705 | } | 785 | } |
706 | 786 | ||
707 | 787 | ||
708 | int OPimTodo::rtti() const | 788 | int OPimTodo::rtti() const |
709 | { | 789 | { |
710 | return OPimResolver::TodoList; | 790 | return OPimResolver::TodoList; |
711 | } | 791 | } |
712 | 792 | ||
793 | /** | ||
794 | * \brief Provide a SafeCast to OPimTodo from a OPimRecord | ||
795 | * | ||
796 | * Provide a safe cast that will return 0 if the record | ||
797 | * type is not OPimTodo. In the other case it will | ||
798 | * be casted to OPimTodo and returned | ||
799 | * | ||
800 | * @param rec The OPimRecord to be casted | ||
801 | * | ||
802 | * @return a pointer to OPimTodo or 0l | ||
803 | */ | ||
804 | OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) { | ||
805 | return (rec && rec->rtti() == OPimResolver::TodoList ) ? | ||
806 | static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) : | ||
807 | 0l; | ||
808 | } | ||
809 | |||
713 | } | 810 | } |