-rw-r--r-- | libopie/pim/orecordlist.h | 7 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 1 | ||||
-rw-r--r-- | libopie/pim/otodoaccess.cpp | 8 | ||||
-rw-r--r-- | libopie/pim/otodoaccess.h | 16 | ||||
-rw-r--r-- | libopie/pim/otodoaccessbackend.h | 2 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 145 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.h | 2 |
7 files changed, 178 insertions, 3 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index c63d813..1fd0741 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -104,12 +104,13 @@ public: | |||
104 | 104 | ||
105 | /** | 105 | /** |
106 | * the number of items in the list | 106 | * the number of items in the list |
107 | */ | 107 | */ |
108 | uint count()const; | 108 | uint count()const; |
109 | 109 | ||
110 | T operator[]( uint i ); | ||
110 | // FIXME implemenent remove | 111 | // FIXME implemenent remove |
111 | /* | 112 | /* |
112 | ConstIterator begin()const; | 113 | ConstIterator begin()const; |
113 | ConstIterator end()const; | 114 | ConstIterator end()const; |
114 | */ | 115 | */ |
115 | private: | 116 | private: |
@@ -143,13 +144,13 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | |||
143 | template <class T> | 144 | template <class T> |
144 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 145 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
145 | m_uids = it.m_uids; | 146 | m_uids = it.m_uids; |
146 | m_current = it.m_current; | 147 | m_current = it.m_current; |
147 | m_temp = it.m_temp; | 148 | m_temp = it.m_temp; |
148 | m_end = it.m_end; | 149 | m_end = it.m_end; |
149 | // m_record = it.m_record; | 150 | m_record = it.m_record; |
150 | 151 | ||
151 | return *this; | 152 | return *this; |
152 | } | 153 | } |
153 | 154 | ||
154 | template <class T> | 155 | template <class T> |
155 | T ORecordListIterator<T>::operator*() { | 156 | T ORecordListIterator<T>::operator*() { |
@@ -249,7 +250,11 @@ ORecordList<T>::Iterator ORecordList<T>::end() { | |||
249 | return it; | 250 | return it; |
250 | } | 251 | } |
251 | template <class T> | 252 | template <class T> |
252 | uint ORecordList<T>::count()const { | 253 | uint ORecordList<T>::count()const { |
253 | return m_ids.count(); | 254 | return m_ids.count(); |
254 | } | 255 | } |
256 | template <class T> | ||
257 | T ORecordList<T>::operator[]( uint i ) { | ||
258 | return m_acc->find( m_ids[i] ); | ||
259 | } | ||
255 | #endif | 260 | #endif |
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index 6dd4c0e..eb9dad3 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp | |||
@@ -169,12 +169,13 @@ void OTodo::setSummary( const QString& sum ) | |||
169 | { | 169 | { |
170 | changeOrModify(); | 170 | changeOrModify(); |
171 | data->sum = sum; | 171 | data->sum = sum; |
172 | } | 172 | } |
173 | void OTodo::setPriority(int prio ) | 173 | void OTodo::setPriority(int prio ) |
174 | { | 174 | { |
175 | qWarning("set priority %d", prio); | ||
175 | changeOrModify(); | 176 | changeOrModify(); |
176 | data->priority = prio; | 177 | data->priority = prio; |
177 | } | 178 | } |
178 | void OTodo::setDueDate( QDate date ) | 179 | void OTodo::setDueDate( QDate date ) |
179 | { | 180 | { |
180 | changeOrModify(); | 181 | changeOrModify(); |
diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp index 8ec09bc..f51da29 100644 --- a/libopie/pim/otodoaccess.cpp +++ b/libopie/pim/otodoaccess.cpp | |||
@@ -65,7 +65,13 @@ void OTodoAccess::delAlarm( int uid) { | |||
65 | // it should be fine -zecke | 65 | // it should be fine -zecke |
66 | // qWarning("Removing alarm for event with uid %d", uid ); | 66 | // qWarning("Removing alarm for event with uid %d", uid ); |
67 | AlarmServer::deleteAlarm( schedule , | 67 | AlarmServer::deleteAlarm( schedule , |
68 | "QPE/Application/todolist", | 68 | "QPE/Application/todolist", |
69 | "alarm(QDateTime,int)", uid ); | 69 | "alarm(QDateTime,int)", uid ); |
70 | } | 70 | } |
71 | 71 | /* sort order */ | |
72 | OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { | ||
73 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, | ||
74 | filter, cat ); | ||
75 | OTodoAccess::List list( ints, this ); | ||
76 | return list; | ||
77 | } | ||
diff --git a/libopie/pim/otodoaccess.h b/libopie/pim/otodoaccess.h index c43efe9..12997aa 100644 --- a/libopie/pim/otodoaccess.h +++ b/libopie/pim/otodoaccess.h | |||
@@ -14,16 +14,23 @@ | |||
14 | * the class to get access to | 14 | * the class to get access to |
15 | * the todolist | 15 | * the todolist |
16 | */ | 16 | */ |
17 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { | 17 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | public: | 19 | public: |
20 | enum SortOrder { Completed = 0, | ||
21 | Priority, | ||
22 | Description, | ||
23 | Deadline }; | ||
24 | enum SortFilter{ ShowOverdue = 0, | ||
25 | Category =1, | ||
26 | OnlyOverDue= 2 }; | ||
20 | /** | 27 | /** |
21 | * if you use 0l | 28 | * if you use 0l |
22 | * the default resource will be | 29 | * the default resource will be |
23 | * icked up | 30 | * picked up |
24 | */ | 31 | */ |
25 | OTodoAccess( OTodoAccessBackend* = 0l); | 32 | OTodoAccess( OTodoAccessBackend* = 0l); |
26 | ~OTodoAccess(); | 33 | ~OTodoAccess(); |
27 | 34 | ||
28 | 35 | ||
29 | /* our functions here */ | 36 | /* our functions here */ |
@@ -45,12 +52,18 @@ public: | |||
45 | 52 | ||
46 | 53 | ||
47 | /** | 54 | /** |
48 | * return overdue OTodos | 55 | * return overdue OTodos |
49 | */ | 56 | */ |
50 | List overDue(); | 57 | List overDue(); |
58 | |||
59 | /** | ||
60 | * | ||
61 | */ | ||
62 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | ||
63 | |||
51 | /** | 64 | /** |
52 | * merge a list of OTodos into | 65 | * merge a list of OTodos into |
53 | * the resource | 66 | * the resource |
54 | */ | 67 | */ |
55 | void mergeWith( const QValueList<OTodo>& ); | 68 | void mergeWith( const QValueList<OTodo>& ); |
56 | 69 | ||
@@ -68,12 +81,13 @@ public: | |||
68 | signals: | 81 | signals: |
69 | /** | 82 | /** |
70 | * if the OTodoAccess was changed | 83 | * if the OTodoAccess was changed |
71 | */ | 84 | */ |
72 | void signalChanged( const OTodoAccess* ); | 85 | void signalChanged( const OTodoAccess* ); |
73 | private: | 86 | private: |
87 | int m_cat; | ||
74 | OTodoAccessBackend* m_todoBackEnd; | 88 | OTodoAccessBackend* m_todoBackEnd; |
75 | class OTodoAccessPrivate; | 89 | class OTodoAccessPrivate; |
76 | OTodoAccessPrivate* d; | 90 | OTodoAccessPrivate* d; |
77 | }; | 91 | }; |
78 | 92 | ||
79 | #endif | 93 | #endif |
diff --git a/libopie/pim/otodoaccessbackend.h b/libopie/pim/otodoaccessbackend.h index ebe2189..3bad6b7 100644 --- a/libopie/pim/otodoaccessbackend.h +++ b/libopie/pim/otodoaccessbackend.h | |||
@@ -9,10 +9,12 @@ public: | |||
9 | OTodoAccessBackend(); | 9 | OTodoAccessBackend(); |
10 | ~OTodoAccessBackend(); | 10 | ~OTodoAccessBackend(); |
11 | virtual QArray<int> effectiveToDos( const QDate& start, | 11 | virtual QArray<int> effectiveToDos( const QDate& start, |
12 | const QDate& end, | 12 | const QDate& end, |
13 | bool includeNoDates ) = 0; | 13 | bool includeNoDates ) = 0; |
14 | virtual QArray<int> overDue() = 0; | 14 | virtual QArray<int> overDue() = 0; |
15 | virtual QArray<int> sorted( bool asc, int sortOrder, int sortFilter, | ||
16 | int cat ) = 0; | ||
15 | 17 | ||
16 | }; | 18 | }; |
17 | 19 | ||
18 | #endif | 20 | #endif |
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 5fe733c..692483e 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -1,7 +1,8 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qvector.h> | ||
2 | 3 | ||
3 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
4 | #include <qpe/stringutil.h> | 5 | #include <qpe/stringutil.h> |
5 | #include <qpe/timeconversion.h> | 6 | #include <qpe/timeconversion.h> |
6 | 7 | ||
7 | #include <opie/xmltree.h> | 8 | #include <opie/xmltree.h> |
@@ -253,12 +254,13 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con | |||
253 | ev.setDescription( it.data() ); | 254 | ev.setDescription( it.data() ); |
254 | break; | 255 | break; |
255 | case OTodo::Summary: | 256 | case OTodo::Summary: |
256 | ev.setSummary( it.data() ); | 257 | ev.setSummary( it.data() ); |
257 | break; | 258 | break; |
258 | case OTodo::Priority: | 259 | case OTodo::Priority: |
260 | qWarning("ParsePriority " + it.data() ); | ||
259 | ev.setPriority( it.data().toInt() ); | 261 | ev.setPriority( it.data().toInt() ); |
260 | break; | 262 | break; |
261 | case OTodo::DateDay: | 263 | case OTodo::DateDay: |
262 | day = it.data().toInt(); | 264 | day = it.data().toInt(); |
263 | break; | 265 | break; |
264 | case OTodo::DateMonth: | 266 | case OTodo::DateMonth: |
@@ -361,6 +363,149 @@ QString OTodoAccessXML::toString( const OTodo& ev )const { | |||
361 | 363 | ||
362 | return str; | 364 | return str; |
363 | } | 365 | } |
364 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 366 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
365 | return Qtopia::Record::idsToString( ints ); | 367 | return Qtopia::Record::idsToString( ints ); |
366 | } | 368 | } |
369 | |||
370 | /* internal class for sorting */ | ||
371 | |||
372 | struct OTodoXMLContainer { | ||
373 | OTodo todo; | ||
374 | }; | ||
375 | /* | ||
376 | * Returns: | ||
377 | * 0 if item1 == item2 | ||
378 | * | ||
379 | * non-zero if item1 != item2 | ||
380 | * | ||
381 | * This function returns int rather than bool so that reimplementations | ||
382 | * can return one of three values and use it to sort by: | ||
383 | * | ||
384 | * 0 if item1 == item2 | ||
385 | * | ||
386 | * > 0 (positive integer) if item1 > item2 | ||
387 | * | ||
388 | * < 0 (negative integer) if item1 < item2 | ||
389 | * | ||
390 | */ | ||
391 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { | ||
392 | public: | ||
393 | OTodoXMLVector(int size, bool asc, int sort) | ||
394 | : QVector<OTodoXMLContainer>( size ) | ||
395 | { | ||
396 | setAutoDelete( true ); | ||
397 | m_asc = asc; | ||
398 | m_sort = sort; | ||
399 | } | ||
400 | /* return the summary/description */ | ||
401 | QString string( const OTodo& todo) { | ||
402 | return todo.summary().isEmpty() ? | ||
403 | todo.description().left(20 ) : | ||
404 | todo.summary(); | ||
405 | } | ||
406 | /** | ||
407 | * we take the sortorder( switch on it ) | ||
408 | * | ||
409 | */ | ||
410 | int compareItems( Item d1, Item d2 ) { | ||
411 | qWarning("compare items"); | ||
412 | int ret =0; | ||
413 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | ||
414 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | ||
415 | |||
416 | /* same item */ | ||
417 | if ( con1->todo.uid() == con2->todo.uid() ) | ||
418 | return 0; | ||
419 | qWarning("m_sort %d", m_sort ); | ||
420 | |||
421 | switch ( m_sort ) { | ||
422 | /* completed */ | ||
423 | case 0: { | ||
424 | ret = 0; | ||
425 | if ( con1->todo.isCompleted() ) ret++; | ||
426 | if ( con2->todo.isCompleted() ) ret--; | ||
427 | break; | ||
428 | } | ||
429 | /* priority */ | ||
430 | case 1: { | ||
431 | ret = con1->todo.priority() - con2->todo.priority(); | ||
432 | qWarning(" priority %d %d %d", ret, | ||
433 | con1->todo.priority(), | ||
434 | con2->todo.priority() | ||
435 | ); | ||
436 | break; | ||
437 | } | ||
438 | /* description */ | ||
439 | case 2: { | ||
440 | QString str1 = string( con1->todo ); | ||
441 | QString str2 = string( con2->todo ); | ||
442 | ret = QString::compare( str1, str2 ); | ||
443 | break; | ||
444 | } | ||
445 | /* deadline */ | ||
446 | case 3: { | ||
447 | /* either bot got a dueDate | ||
448 | * or one of them got one | ||
449 | */ | ||
450 | if ( con1->todo.hasDueDate() && | ||
451 | con2->todo.hasDueDate() ) | ||
452 | ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); | ||
453 | else if ( con1->todo.hasDueDate() ) | ||
454 | ret = -1; | ||
455 | else if ( con2->todo.hasDueDate() ) | ||
456 | ret = 0; | ||
457 | break; | ||
458 | } | ||
459 | default: | ||
460 | ret = 0; | ||
461 | break; | ||
462 | }; | ||
463 | |||
464 | /* twist it we're not ascending*/ | ||
465 | if (!m_asc) | ||
466 | ret = ret * -1; | ||
467 | return ret; | ||
468 | } | ||
469 | private: | ||
470 | bool m_asc; | ||
471 | int m_sort; | ||
472 | |||
473 | }; | ||
474 | |||
475 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | ||
476 | int sortFilter, int cat ) { | ||
477 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | ||
478 | QMap<int, OTodo>::Iterator it; | ||
479 | int item = 0; | ||
480 | |||
481 | bool bCat = sortFilter & 1 ? true : false; | ||
482 | bool bOver = sortFilter & 0 ? true : false; | ||
483 | bool bOnly = split & 2 ? true : false; | ||
484 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | ||
485 | |||
486 | /* show category */ | ||
487 | if ( bCat ) | ||
488 | if (!(*it).categories().contains( cat ) ) | ||
489 | continue; | ||
490 | /* isOverdue but we should not show overdue */ | ||
491 | if ( (*it).isOverdue() && ( !bOver || !bOnly ) ) | ||
492 | continue; | ||
493 | if ( !(*it).isOverdue() && bOnly ) | ||
494 | continue; | ||
495 | |||
496 | |||
497 | OTodoXMLContainer* con = new OTodoXMLContainer(); | ||
498 | con->todo = (*it); | ||
499 | vector.insert(item, con ); | ||
500 | item++; | ||
501 | } | ||
502 | vector.resize( item ); | ||
503 | /* sort it now */ | ||
504 | vector.sort(); | ||
505 | /* now get the uids */ | ||
506 | QArray<int> array( vector.count() ); | ||
507 | for (uint i= 0; i < vector.count(); i++ ) { | ||
508 | array[i] = ( vector.at(i) )->todo.uid(); | ||
509 | } | ||
510 | return array; | ||
511 | }; | ||
diff --git a/libopie/pim/otodoaccessxml.h b/libopie/pim/otodoaccessxml.h index be9109d..6886bab 100644 --- a/libopie/pim/otodoaccessxml.h +++ b/libopie/pim/otodoaccessxml.h | |||
@@ -33,12 +33,14 @@ public: | |||
33 | 33 | ||
34 | /* our functions */ | 34 | /* our functions */ |
35 | QArray<int> effectiveToDos( const QDate& start, | 35 | QArray<int> effectiveToDos( const QDate& start, |
36 | const QDate& end, | 36 | const QDate& end, |
37 | bool includeNoDates ); | 37 | bool includeNoDates ); |
38 | QArray<int> overDue(); | 38 | QArray<int> overDue(); |
39 | QArray<int> sorted( bool asc, int sortOrder, | ||
40 | int sortFilter, int cat ); | ||
39 | private: | 41 | private: |
40 | OTodo todo( QAsciiDict<int>*, Opie::XMLElement* )const; | 42 | OTodo todo( QAsciiDict<int>*, Opie::XMLElement* )const; |
41 | QString toString( const OTodo& )const; | 43 | QString toString( const OTodo& )const; |
42 | QString toString( const QArray<int>& ints ) const; | 44 | QString toString( const QArray<int>& ints ) const; |
43 | QMap<int, OTodo> m_events; | 45 | QMap<int, OTodo> m_events; |
44 | QString m_file; | 46 | QString m_file; |