summaryrefslogtreecommitdiff
path: root/libopie/pim/otodo.cpp
Unidiff
Diffstat (limited to 'libopie/pim/otodo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/otodo.cpp519
1 files changed, 0 insertions, 519 deletions
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
deleted file mode 100644
index b2c76f8..0000000
--- a/libopie/pim/otodo.cpp
+++ b/dev/null
@@ -1,519 +0,0 @@
1
2#include <qobject.h>
3#include <qshared.h>
4
5
6
7#include <qpe/palmtopuidgen.h>
8#include <qpe/palmtoprecord.h>
9#include <qpe/categories.h>
10#include <qpe/categoryselect.h>
11#include <qpe/stringutil.h>
12
13
14#include "opimstate.h"
15#include "orecur.h"
16#include "opimmaintainer.h"
17#include "opimnotifymanager.h"
18#include "opimresolver.h"
19
20#include "otodo.h"
21
22
23struct OTodo::OTodoData : public QShared {
24 OTodoData() : QShared() {
25 recur = 0;
26 state = 0;
27 maintainer = 0;
28 notifiers = 0;
29 };
30 ~OTodoData() {
31 delete recur;
32 delete maintainer;
33 delete notifiers;
34 }
35
36 QDate date;
37 bool isCompleted:1;
38 bool hasDate:1;
39 int priority;
40 QString desc;
41 QString sum;
42 QMap<QString, QString> extra;
43 ushort prog;
44 OPimState *state;
45 ORecur *recur;
46 OPimMaintainer *maintainer;
47 QDate start;
48 QDate completed;
49 OPimNotifyManager *notifiers;
50};
51
52OTodo::OTodo(const OTodo &event )
53 : OPimRecord( event ), data( event.data )
54{
55 data->ref();
56// qWarning("ref up");
57}
58OTodo::~OTodo() {
59
60// qWarning("~OTodo " );
61 if ( data->deref() ) {
62// qWarning("OTodo::dereffing");
63 delete data;
64 data = 0l;
65 }
66}
67OTodo::OTodo(bool completed, int priority,
68 const QArray<int> &category,
69 const QString& summary,
70 const QString &description,
71 ushort progress,
72 bool hasDate, QDate date, int uid )
73 : OPimRecord( uid )
74{
75// qWarning("OTodoData " + summary);
76 setCategories( category );
77
78 data = new OTodoData;
79
80 data->date = date;
81 data->isCompleted = completed;
82 data->hasDate = hasDate;
83 data->priority = priority;
84 data->sum = summary;
85 data->prog = progress;
86 data->desc = Qtopia::simplifyMultiLineSpace(description );
87}
88OTodo::OTodo(bool completed, int priority,
89 const QStringList &category,
90 const QString& summary,
91 const QString &description,
92 ushort progress,
93 bool hasDate, QDate date, int uid )
94 : OPimRecord( uid )
95{
96// qWarning("OTodoData" + summary);
97 setCategories( idsFromString( category.join(";") ) );
98
99 data = new OTodoData;
100
101 data->date = date;
102 data->isCompleted = completed;
103 data->hasDate = hasDate;
104 data->priority = priority;
105 data->sum = summary;
106 data->prog = progress;
107 data->desc = Qtopia::simplifyMultiLineSpace(description );
108}
109bool OTodo::match( const QRegExp &regExp )const
110{
111 if( QString::number( data->priority ).find( regExp ) != -1 ){
112 setLastHitField( Priority );
113 return true;
114 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
115 setLastHitField( HasDate );
116 return true;
117 }else if(data->desc.find( regExp ) != -1 ){
118 setLastHitField( Description );
119 return true;
120 }else if(data->sum.find( regExp ) != -1 ) {
121 setLastHitField( Summary );
122 return true;
123 }
124 return false;
125}
126bool OTodo::isCompleted() const
127{
128 return data->isCompleted;
129}
130bool OTodo::hasDueDate() const
131{
132 return data->hasDate;
133}
134bool OTodo::hasStartDate()const {
135 return data->start.isValid();
136}
137bool OTodo::hasCompletedDate()const {
138 return data->completed.isValid();
139}
140int OTodo::priority()const
141{
142 return data->priority;
143}
144QString OTodo::summary() const
145{
146 return data->sum;
147}
148ushort OTodo::progress() const
149{
150 return data->prog;
151}
152QDate OTodo::dueDate()const
153{
154 return data->date;
155}
156QDate OTodo::startDate()const {
157 return data->start;
158}
159QDate OTodo::completedDate()const {
160 return data->completed;
161}
162QString OTodo::description()const
163{
164 return data->desc;
165}
166bool OTodo::hasState() const{
167 if (!data->state ) return false;
168 return ( data->state->state() != OPimState::Undefined );
169}
170OPimState OTodo::state()const {
171 if (!data->state ) {
172 OPimState state;
173 return state;
174 }
175
176 return (*data->state);
177}
178bool OTodo::hasRecurrence()const {
179 if (!data->recur) return false;
180 return data->recur->doesRecur();
181}
182ORecur OTodo::recurrence()const {
183 if (!data->recur) return ORecur();
184
185 return (*data->recur);
186}
187bool OTodo::hasMaintainer()const {
188 if (!data->maintainer) return false;
189
190 return (data->maintainer->mode() != OPimMaintainer::Undefined );
191}
192OPimMaintainer OTodo::maintainer()const {
193 if (!data->maintainer) return OPimMaintainer();
194
195 return (*data->maintainer);
196}
197void OTodo::setCompleted( bool completed )
198{
199 changeOrModify();
200 data->isCompleted = completed;
201}
202void OTodo::setHasDueDate( bool hasDate )
203{
204 changeOrModify();
205 data->hasDate = hasDate;
206}
207void OTodo::setDescription(const QString &desc )
208{
209// qWarning( "desc " + desc );
210 changeOrModify();
211 data->desc = Qtopia::simplifyMultiLineSpace(desc );
212}
213void OTodo::setSummary( const QString& sum )
214{
215 changeOrModify();
216 data->sum = sum;
217}
218void OTodo::setPriority(int prio )
219{
220 changeOrModify();
221 data->priority = prio;
222}
223void OTodo::setDueDate( const QDate& date )
224{
225 changeOrModify();
226 data->date = date;
227}
228void OTodo::setStartDate( const QDate& date ) {
229 changeOrModify();
230 data->start = date;
231}
232void OTodo::setCompletedDate( const QDate& date ) {
233 changeOrModify();
234 data->completed = date;
235}
236void OTodo::setState( const OPimState& state ) {
237 changeOrModify();
238 if (data->state )
239 (*data->state) = state;
240 else
241 data->state = new OPimState( state );
242}
243void OTodo::setRecurrence( const ORecur& rec) {
244 changeOrModify();
245 if (data->recur )
246 (*data->recur) = rec;
247 else
248 data->recur = new ORecur( rec );
249}
250void OTodo::setMaintainer( const OPimMaintainer& pim ) {
251 changeOrModify();
252
253 if (data->maintainer )
254 (*data->maintainer) = pim;
255 else
256 data->maintainer = new OPimMaintainer( pim );
257}
258bool OTodo::isOverdue( )
259{
260 if( data->hasDate && !data->isCompleted)
261 return QDate::currentDate() > data->date;
262 return false;
263}
264void OTodo::setProgress(ushort progress )
265{
266 changeOrModify();
267 data->prog = progress;
268}
269QString OTodo::toShortText() const {
270 return summary();
271}
272/*!
273 Returns a richt text string
274*/
275QString OTodo::toRichText() const
276{
277 QString text;
278 QStringList catlist;
279
280 // summary
281 text += "<b><h3><img src=\"todo/TodoList\"> ";
282 if ( !summary().isEmpty() ) {
283 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" );
284 }
285 text += "</h3></b><br><hr><br>";
286
287 // description
288 if( !description().isEmpty() ){
289 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
290 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
291 }
292
293 // priority
294 int priorityval = priority();
295 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" +
296 QString::number( priorityval ) + "\"> ";
297
298 switch ( priorityval )
299 {
300 case 1 : text += QObject::tr( "Very high" );
301 break;
302 case 2 : text += QObject::tr( "High" );
303 break;
304 case 3 : text += QObject::tr( "Normal" );
305 break;
306 case 4 : text += QObject::tr( "Low" );
307 break;
308 case 5 : text += QObject::tr( "Very low" );
309 break;
310 };
311 text += "<br>";
312
313 // progress
314 text += "<b>" + QObject::tr( "Progress:") + " </b>"
315 + QString::number( progress() ) + " %<br>";
316
317 // due date
318 if (hasDueDate() ){
319 QDate dd = dueDate();
320 int off = QDate::currentDate().daysTo( dd );
321
322 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
323 if ( off < 0 )
324 text += "#FF0000";
325 else if ( off == 0 )
326 text += "#FFFF00";
327 else if ( off > 0 )
328 text += "#00FF00";
329
330 text += "\">" + dd.toString() + "</font><br>";
331 }
332
333 // categories
334 text += "<b>" + QObject::tr( "Category:") + "</b> ";
335 text += categoryNames( "Todo List" ).join(", ");
336 text += "<br>";
337
338 return text;
339}
340bool OTodo::hasNotifiers()const {
341 if (!data->notifiers) return false;
342 return !data->notifiers->isEmpty();
343}
344OPimNotifyManager& OTodo::notifiers() {
345 if (!data->notifiers )
346 data->notifiers = new OPimNotifyManager;
347 return (*data->notifiers);
348}
349const OPimNotifyManager& OTodo::notifiers()const{
350 if (!data->notifiers )
351 data->notifiers = new OPimNotifyManager;
352
353 return (*data->notifiers);
354}
355
356bool OTodo::operator<( const OTodo &toDoEvent )const{
357 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
358 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
359 if( hasDueDate() && toDoEvent.hasDueDate() ){
360 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
361 return priority() < toDoEvent.priority();
362 }else{
363 return dueDate() < toDoEvent.dueDate();
364 }
365 }
366 return false;
367}
368bool OTodo::operator<=(const OTodo &toDoEvent )const
369{
370 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
371 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
372 if( hasDueDate() && toDoEvent.hasDueDate() ){
373 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
374 return priority() <= toDoEvent.priority();
375 }else{
376 return dueDate() <= toDoEvent.dueDate();
377 }
378 }
379 return true;
380}
381bool OTodo::operator>(const OTodo &toDoEvent )const
382{
383 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
384 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
385 if( hasDueDate() && toDoEvent.hasDueDate() ){
386 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
387 return priority() > toDoEvent.priority();
388 }else{
389 return dueDate() > toDoEvent.dueDate();
390 }
391 }
392 return false;
393}
394bool OTodo::operator>=(const OTodo &toDoEvent )const
395{
396 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
397 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
398 if( hasDueDate() && toDoEvent.hasDueDate() ){
399 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
400 return priority() > toDoEvent.priority();
401 }else{
402 return dueDate() > toDoEvent.dueDate();
403 }
404 }
405 return true;
406}
407bool OTodo::operator==(const OTodo &toDoEvent )const
408{
409 if ( data->priority != toDoEvent.data->priority ) return false;
410 if ( data->priority != toDoEvent.data->prog ) return false;
411 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
412 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
413 if ( data->date != toDoEvent.data->date ) return false;
414 if ( data->sum != toDoEvent.data->sum ) return false;
415 if ( data->desc != toDoEvent.data->desc ) return false;
416 if ( data->maintainer != toDoEvent.data->maintainer )
417 return false;
418
419 return OPimRecord::operator==( toDoEvent );
420}
421void OTodo::deref() {
422
423// qWarning("deref in ToDoEvent");
424 if ( data->deref() ) {
425// qWarning("deleting");
426 delete data;
427 data= 0;
428 }
429}
430OTodo &OTodo::operator=(const OTodo &item )
431{
432 if ( this == &item ) return *this;
433
434 OPimRecord::operator=( item );
435 //qWarning("operator= ref ");
436 item.data->ref();
437 deref();
438 data = item.data;
439
440 return *this;
441}
442
443QMap<int, QString> OTodo::toMap() const {
444 QMap<int, QString> map;
445
446 map.insert( Uid, QString::number( uid() ) );
447 map.insert( Category, idsToString( categories() ) );
448 map.insert( HasDate, QString::number( data->hasDate ) );
449 map.insert( Completed, QString::number( data->isCompleted ) );
450 map.insert( Description, data->desc );
451 map.insert( Summary, data->sum );
452 map.insert( Priority, QString::number( data->priority ) );
453 map.insert( DateDay, QString::number( data->date.day() ) );
454 map.insert( DateMonth, QString::number( data->date.month() ) );
455 map.insert( DateYear, QString::number( data->date.year() ) );
456 map.insert( Progress, QString::number( data->prog ) );
457// map.insert( CrossReference, crossToString() );
458 /* FIXME!!! map.insert( State, );
459 map.insert( Recurrence, );
460 map.insert( Reminders, );
461 map.
462 */
463 return map;
464}
465
466/**
467 * change or modify looks at the ref count and either
468 * creates a new QShared Object or it can modify it
469 * right in place
470 */
471void OTodo::changeOrModify() {
472 if ( data->count != 1 ) {
473 qWarning("changeOrModify");
474 data->deref();
475 OTodoData* d2 = new OTodoData();
476 copy(data, d2 );
477 data = d2;
478 }
479}
480// WATCHOUT
481/*
482 * if you add something to the Data struct
483 * be sure to copy it here
484 */
485void OTodo::copy( OTodoData* src, OTodoData* dest ) {
486 dest->date = src->date;
487 dest->isCompleted = src->isCompleted;
488 dest->hasDate = src->hasDate;
489 dest->priority = src->priority;
490 dest->desc = src->desc;
491 dest->sum = src->sum;
492 dest->extra = src->extra;
493 dest->prog = src->prog;
494
495 if (src->state )
496 dest->state = new OPimState( *src->state );
497
498 if (src->recur )
499 dest->recur = new ORecur( *src->recur );
500
501 if (src->maintainer )
502 dest->maintainer = new OPimMaintainer( *src->maintainer )
503 ;
504 dest->start = src->start;
505 dest->completed = src->completed;
506
507 if (src->notifiers )
508 dest->notifiers = new OPimNotifyManager( *src->notifiers );
509}
510QString OTodo::type() const {
511 return QString::fromLatin1("OTodo");
512}
513QString OTodo::recordField(int /*id*/ )const {
514 return QString::null;
515}
516
517int OTodo::rtti(){
518 return OPimResolver::TodoList;
519}