summaryrefslogtreecommitdiff
path: root/libopie/pim
authorzecke <zecke>2002-09-25 11:59:24 (UTC)
committer zecke <zecke>2002-09-25 11:59:24 (UTC)
commit38240090027bd68d8dd15d7d46ecf17792edb732 (patch) (unidiff)
tree589ef486d7169c57592ed8667f6c84d43f882d48 /libopie/pim
parent5f2dd0a2340914b4983ebce3813187034e2cb9dc (diff)
downloadopie-38240090027bd68d8dd15d7d46ecf17792edb732.zip
opie-38240090027bd68d8dd15d7d46ecf17792edb732.tar.gz
opie-38240090027bd68d8dd15d7d46ecf17792edb732.tar.bz2
Add a sort function and filter function to TodoAccess
This would allow us todo a paint hack in QTable
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/orecordlist.h17
-rw-r--r--libopie/pim/otodo.cpp1
-rw-r--r--libopie/pim/otodoaccess.cpp8
-rw-r--r--libopie/pim/otodoaccess.h16
-rw-r--r--libopie/pim/otodoaccessbackend.h2
-rw-r--r--libopie/pim/otodoaccessxml.cpp145
-rw-r--r--libopie/pim/otodoaccessxml.h2
7 files changed, 183 insertions, 8 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
@@ -1,255 +1,260 @@
1 1
2#ifndef OPIE_RECORD_LIST_H 2#ifndef OPIE_RECORD_LIST_H
3#define OPIE_RECORD_LIST_H 3#define OPIE_RECORD_LIST_H
4 4
5#include <qarray.h> 5#include <qarray.h>
6 6
7#include "otemplatebase.h" 7#include "otemplatebase.h"
8#include "opimrecord.h" 8#include "opimrecord.h"
9 9
10/** 10/**
11 * Our List Iterator 11 * Our List Iterator
12 * it behaves like STL or Qt 12 * it behaves like STL or Qt
13 * 13 *
14 * for(it = list.begin(); it != list.end(); ++it ) 14 * for(it = list.begin(); it != list.end(); ++it )
15 * doSomeCoolStuff( (*it) ); 15 * doSomeCoolStuff( (*it) );
16 */ 16 */
17template <class T> class ORecordList; 17template <class T> class ORecordList;
18template <class T = OPimRecord> 18template <class T = OPimRecord>
19class ORecordListIterator { 19class ORecordListIterator {
20 friend class ORecordList<T>; 20 friend class ORecordList<T>;
21public: 21public:
22 typedef OTemplateBase<T> Base; 22 typedef OTemplateBase<T> Base;
23 23
24 /** 24 /**
25 * The c'tor used internally from 25 * The c'tor used internally from
26 * ORecordList 26 * ORecordList
27 */ 27 */
28 ORecordListIterator( const QArray<int>, const Base* ); 28 ORecordListIterator( const QArray<int>, const Base* );
29 29
30 /** 30 /**
31 * The standard c'tor 31 * The standard c'tor
32 */ 32 */
33 ORecordListIterator(); 33 ORecordListIterator();
34 ~ORecordListIterator(); 34 ~ORecordListIterator();
35 35
36 ORecordListIterator( const ORecordListIterator& ); 36 ORecordListIterator( const ORecordListIterator& );
37 ORecordListIterator &operator=(const ORecordListIterator& ); 37 ORecordListIterator &operator=(const ORecordListIterator& );
38 38
39 /** 39 /**
40 * a * operator ;) 40 * a * operator ;)
41 * use it like this T = (*it); 41 * use it like this T = (*it);
42 */ 42 */
43 T operator*(); 43 T operator*();
44 ORecordListIterator &operator++(); 44 ORecordListIterator &operator++();
45 ORecordListIterator &operator--(); 45 ORecordListIterator &operator--();
46 46
47 bool operator==( const ORecordListIterator& it ); 47 bool operator==( const ORecordListIterator& it );
48 bool operator!=( const ORecordListIterator& it ); 48 bool operator!=( const ORecordListIterator& it );
49 49
50 /** 50 /**
51 * the current item 51 * the current item
52 */ 52 */
53 uint current()const; 53 uint current()const;
54 54
55 /** 55 /**
56 * the number of items 56 * the number of items
57 */ 57 */
58 uint count()const; 58 uint count()const;
59 59
60 /** 60 /**
61 * sets the current item 61 * sets the current item
62 */ 62 */
63 void setCurrent( uint cur ); 63 void setCurrent( uint cur );
64 64
65private: 65private:
66 QArray<int> m_uids; 66 QArray<int> m_uids;
67 uint m_current; 67 uint m_current;
68 const Base* m_temp; 68 const Base* m_temp;
69 bool m_end : 1; 69 bool m_end : 1;
70 T m_record; 70 T m_record;
71 71
72 /* d pointer for future versions */ 72 /* d pointer for future versions */
73 class IteratorPrivate; 73 class IteratorPrivate;
74 IteratorPrivate *d; 74 IteratorPrivate *d;
75}; 75};
76/** 76/**
77 * The recordlist used as a return type 77 * The recordlist used as a return type
78 * from OPimAccessTemplate 78 * from OPimAccessTemplate
79 */ 79 */
80template <class T = OPimRecord > 80template <class T = OPimRecord >
81class ORecordList { 81class ORecordList {
82public: 82public:
83 typedef OTemplateBase<T> Base; 83 typedef OTemplateBase<T> Base;
84 typedef ORecordListIterator<T> Iterator; 84 typedef ORecordListIterator<T> Iterator;
85 85
86 /** 86 /**
87 * c'tor 87 * c'tor
88 */ 88 */
89 ORecordList () { 89 ORecordList () {
90 } 90 }
91 ORecordList( const QArray<int>& ids, 91 ORecordList( const QArray<int>& ids,
92 const Base* ); 92 const Base* );
93 ~ORecordList(); 93 ~ORecordList();
94 94
95 /** 95 /**
96 * the first iterator 96 * the first iterator
97 */ 97 */
98 Iterator begin(); 98 Iterator begin();
99 99
100 /** 100 /**
101 * the end 101 * the end
102 */ 102 */
103 Iterator end(); 103 Iterator end();
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 */
115private: 116private:
116 QArray<int> m_ids; 117 QArray<int> m_ids;
117 const Base* m_acc; 118 const Base* m_acc;
118}; 119};
119 120
120/* ok now implement it */ 121/* ok now implement it */
121template <class T> 122template <class T>
122ORecordListIterator<T>::ORecordListIterator() { 123ORecordListIterator<T>::ORecordListIterator() {
123 m_current = 0; 124 m_current = 0;
124 m_temp = 0l; 125 m_temp = 0l;
125 m_end = true; 126 m_end = true;
126 m_record = T(); 127 m_record = T();
127} 128}
128template <class T> 129template <class T>
129ORecordListIterator<T>::~ORecordListIterator() { 130ORecordListIterator<T>::~ORecordListIterator() {
130/* nothing to delete */ 131/* nothing to delete */
131} 132}
132 133
133template <class T> 134template <class T>
134ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 135ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
135// qWarning("ORecordListIterator copy c'tor"); 136// qWarning("ORecordListIterator copy c'tor");
136 m_uids = it.m_uids; 137 m_uids = it.m_uids;
137 m_current = it.m_current; 138 m_current = it.m_current;
138 m_temp = it.m_temp; 139 m_temp = it.m_temp;
139 m_end = it.m_end; 140 m_end = it.m_end;
140 m_record = it.m_record; 141 m_record = it.m_record;
141} 142}
142 143
143template <class T> 144template <class T>
144ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 145ORecordListIterator<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
154template <class T> 155template <class T>
155T ORecordListIterator<T>::operator*() { 156T ORecordListIterator<T>::operator*() {
156// qWarning("operator* %d %d", m_current, m_uids[m_current] ); 157// qWarning("operator* %d %d", m_current, m_uids[m_current] );
157 if (!m_end ) 158 if (!m_end )
158 /* FIXME 159 /* FIXME
159 * until the cache is in place 160 * until the cache is in place
160 * we do the uid match uid check 161 * we do the uid match uid check
161 */ 162 */
162 if(m_record.uid() != m_uids[m_current] ) 163 if(m_record.uid() != m_uids[m_current] )
163 m_record = m_temp->find( m_uids[m_current] ); 164 m_record = m_temp->find( m_uids[m_current] );
164 else 165 else
165 m_record = T(); 166 m_record = T();
166 167
167 return m_record; 168 return m_record;
168} 169}
169 170
170template <class T> 171template <class T>
171ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 172ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
172 if (m_current < m_uids.count() ) { 173 if (m_current < m_uids.count() ) {
173 m_end = false; 174 m_end = false;
174 ++m_current; 175 ++m_current;
175 }else 176 }else
176 m_end = true; 177 m_end = true;
177 178
178 return *this; 179 return *this;
179} 180}
180template <class T> 181template <class T>
181ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 182ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
182 if ( m_current > 0 ) { 183 if ( m_current > 0 ) {
183 --m_current; 184 --m_current;
184 m_end = false; 185 m_end = false;
185 } else 186 } else
186 m_end = true; 187 m_end = true;
187 188
188 return *this; 189 return *this;
189} 190}
190 191
191template <class T> 192template <class T>
192bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 193bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
193 194
194 /* if both are at we're the same.... */ 195 /* if both are at we're the same.... */
195 if ( m_end == it.m_end ) return true; 196 if ( m_end == it.m_end ) return true;
196 197
197 if ( m_uids != it.m_uids ) return false; 198 if ( m_uids != it.m_uids ) return false;
198 if ( m_current != it.m_current ) return false; 199 if ( m_current != it.m_current ) return false;
199 if ( m_temp != it.m_temp ) return false; 200 if ( m_temp != it.m_temp ) return false;
200 201
201 return true; 202 return true;
202} 203}
203template <class T> 204template <class T>
204bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 205bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
205 return !(*this == it ); 206 return !(*this == it );
206} 207}
207template <class T> 208template <class T>
208ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 209ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
209 const Base* t ) 210 const Base* t )
210 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) 211 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false )
211{ 212{
212} 213}
213template <class T> 214template <class T>
214uint ORecordListIterator<T>::current()const { 215uint ORecordListIterator<T>::current()const {
215 return m_current; 216 return m_current;
216} 217}
217template <class T> 218template <class T>
218void ORecordListIterator<T>::setCurrent( uint cur ) { 219void ORecordListIterator<T>::setCurrent( uint cur ) {
219 if( cur < m_uids.count() ) { 220 if( cur < m_uids.count() ) {
220 m_end = false; 221 m_end = false;
221 m_current= cur; 222 m_current= cur;
222 } 223 }
223} 224}
224template <class T> 225template <class T>
225uint ORecordListIterator<T>::count()const { 226uint ORecordListIterator<T>::count()const {
226 return m_uids.count(); 227 return m_uids.count();
227} 228}
228template <class T> 229template <class T>
229ORecordList<T>::ORecordList( const QArray<int>& ids, 230ORecordList<T>::ORecordList( const QArray<int>& ids,
230 const Base* acc ) 231 const Base* acc )
231 : m_ids( ids ), m_acc( acc ) 232 : m_ids( ids ), m_acc( acc )
232{ 233{
233} 234}
234template <class T> 235template <class T>
235ORecordList<T>::~ORecordList() { 236ORecordList<T>::~ORecordList() {
236/* nothing to do here */ 237/* nothing to do here */
237} 238}
238template <class T> 239template <class T>
239ORecordList<T>::Iterator ORecordList<T>::begin() { 240ORecordList<T>::Iterator ORecordList<T>::begin() {
240 Iterator it( m_ids, m_acc ); 241 Iterator it( m_ids, m_acc );
241 return it; 242 return it;
242} 243}
243template <class T> 244template <class T>
244ORecordList<T>::Iterator ORecordList<T>::end() { 245ORecordList<T>::Iterator ORecordList<T>::end() {
245 Iterator it( m_ids, m_acc ); 246 Iterator it( m_ids, m_acc );
246 it.m_end = true; 247 it.m_end = true;
247 it.m_current = m_ids.count(); 248 it.m_current = m_ids.count();
248 249
249 return it; 250 return it;
250} 251}
251template <class T> 252template <class T>
252uint ORecordList<T>::count()const { 253uint ORecordList<T>::count()const {
253return m_ids.count(); 254return m_ids.count();
254} 255}
256template <class T>
257T 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
@@ -1,386 +1,387 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15 15
16#include "otodo.h" 16#include "otodo.h"
17 17
18 18
19struct OTodo::OTodoData : public QShared { 19struct OTodo::OTodoData : public QShared {
20 OTodoData() : QShared() { 20 OTodoData() : QShared() {
21 }; 21 };
22 22
23 QDate date; 23 QDate date;
24 bool isCompleted:1; 24 bool isCompleted:1;
25 bool hasDate:1; 25 bool hasDate:1;
26 int priority; 26 int priority;
27 QString desc; 27 QString desc;
28 QString sum; 28 QString sum;
29 QMap<QString, QString> extra; 29 QMap<QString, QString> extra;
30 ushort prog; 30 ushort prog;
31 bool hasAlarmDateTime :1; 31 bool hasAlarmDateTime :1;
32 QDateTime alarmDateTime; 32 QDateTime alarmDateTime;
33}; 33};
34 34
35OTodo::OTodo(const OTodo &event ) 35OTodo::OTodo(const OTodo &event )
36 : OPimRecord( event ), data( event.data ) 36 : OPimRecord( event ), data( event.data )
37{ 37{
38 data->ref(); 38 data->ref();
39// qWarning("ref up"); 39// qWarning("ref up");
40} 40}
41OTodo::~OTodo() { 41OTodo::~OTodo() {
42 42
43// qWarning("~OTodo " ); 43// qWarning("~OTodo " );
44 if ( data->deref() ) { 44 if ( data->deref() ) {
45// qWarning("OTodo::dereffing"); 45// qWarning("OTodo::dereffing");
46 delete data; 46 delete data;
47 data = 0l; 47 data = 0l;
48 } 48 }
49} 49}
50OTodo::OTodo(bool completed, int priority, 50OTodo::OTodo(bool completed, int priority,
51 const QArray<int> &category, 51 const QArray<int> &category,
52 const QString& summary, 52 const QString& summary,
53 const QString &description, 53 const QString &description,
54 ushort progress, 54 ushort progress,
55 bool hasDate, QDate date, int uid ) 55 bool hasDate, QDate date, int uid )
56 : OPimRecord( uid ) 56 : OPimRecord( uid )
57{ 57{
58// qWarning("OTodoData " + summary); 58// qWarning("OTodoData " + summary);
59 setCategories( category ); 59 setCategories( category );
60 60
61 data = new OTodoData; 61 data = new OTodoData;
62 62
63 data->date = date; 63 data->date = date;
64 data->isCompleted = completed; 64 data->isCompleted = completed;
65 data->hasDate = hasDate; 65 data->hasDate = hasDate;
66 data->priority = priority; 66 data->priority = priority;
67 data->sum = summary; 67 data->sum = summary;
68 data->prog = progress; 68 data->prog = progress;
69 data->desc = Qtopia::simplifyMultiLineSpace(description ); 69 data->desc = Qtopia::simplifyMultiLineSpace(description );
70 data->hasAlarmDateTime = false; 70 data->hasAlarmDateTime = false;
71 71
72} 72}
73OTodo::OTodo(bool completed, int priority, 73OTodo::OTodo(bool completed, int priority,
74 const QStringList &category, 74 const QStringList &category,
75 const QString& summary, 75 const QString& summary,
76 const QString &description, 76 const QString &description,
77 ushort progress, 77 ushort progress,
78 bool hasDate, QDate date, int uid ) 78 bool hasDate, QDate date, int uid )
79 : OPimRecord( uid ) 79 : OPimRecord( uid )
80{ 80{
81// qWarning("OTodoData" + summary); 81// qWarning("OTodoData" + summary);
82 setCategories( idsFromString( category.join(";") ) ); 82 setCategories( idsFromString( category.join(";") ) );
83 83
84 data = new OTodoData; 84 data = new OTodoData;
85 85
86 data->date = date; 86 data->date = date;
87 data->isCompleted = completed; 87 data->isCompleted = completed;
88 data->hasDate = hasDate; 88 data->hasDate = hasDate;
89 data->priority = priority; 89 data->priority = priority;
90 data->sum = summary; 90 data->sum = summary;
91 data->prog = progress; 91 data->prog = progress;
92 data->desc = Qtopia::simplifyMultiLineSpace(description ); 92 data->desc = Qtopia::simplifyMultiLineSpace(description );
93 data->hasAlarmDateTime = false; 93 data->hasAlarmDateTime = false;
94 94
95} 95}
96bool OTodo::match( const QRegExp &regExp )const 96bool OTodo::match( const QRegExp &regExp )const
97{ 97{
98 if( QString::number( data->priority ).find( regExp ) != -1 ){ 98 if( QString::number( data->priority ).find( regExp ) != -1 ){
99 return true; 99 return true;
100 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 100 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
101 return true; 101 return true;
102 }else if(data->desc.find( regExp ) != -1 ){ 102 }else if(data->desc.find( regExp ) != -1 ){
103 return true; 103 return true;
104 }else if(data->sum.find( regExp ) != -1 ) { 104 }else if(data->sum.find( regExp ) != -1 ) {
105 return true; 105 return true;
106 } 106 }
107 return false; 107 return false;
108} 108}
109bool OTodo::isCompleted() const 109bool OTodo::isCompleted() const
110{ 110{
111 return data->isCompleted; 111 return data->isCompleted;
112} 112}
113bool OTodo::hasDueDate() const 113bool OTodo::hasDueDate() const
114{ 114{
115 return data->hasDate; 115 return data->hasDate;
116} 116}
117bool OTodo::hasAlarmDateTime() const 117bool OTodo::hasAlarmDateTime() const
118{ 118{
119 return data->hasAlarmDateTime; 119 return data->hasAlarmDateTime;
120} 120}
121int OTodo::priority()const 121int OTodo::priority()const
122{ 122{
123 return data->priority; 123 return data->priority;
124} 124}
125QString OTodo::summary() const 125QString OTodo::summary() const
126{ 126{
127 return data->sum; 127 return data->sum;
128} 128}
129ushort OTodo::progress() const 129ushort OTodo::progress() const
130{ 130{
131 return data->prog; 131 return data->prog;
132} 132}
133QDate OTodo::dueDate()const 133QDate OTodo::dueDate()const
134{ 134{
135 return data->date; 135 return data->date;
136} 136}
137 137
138QDateTime OTodo::alarmDateTime() const 138QDateTime OTodo::alarmDateTime() const
139{ 139{
140 return data->alarmDateTime; 140 return data->alarmDateTime;
141} 141}
142 142
143QString OTodo::description()const 143QString OTodo::description()const
144{ 144{
145 return data->desc; 145 return data->desc;
146} 146}
147void OTodo::setCompleted( bool completed ) 147void OTodo::setCompleted( bool completed )
148{ 148{
149 changeOrModify(); 149 changeOrModify();
150 data->isCompleted = completed; 150 data->isCompleted = completed;
151} 151}
152void OTodo::setHasDueDate( bool hasDate ) 152void OTodo::setHasDueDate( bool hasDate )
153{ 153{
154 changeOrModify(); 154 changeOrModify();
155 data->hasDate = hasDate; 155 data->hasDate = hasDate;
156} 156}
157void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) 157void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime )
158{ 158{
159 changeOrModify(); 159 changeOrModify();
160 data->hasAlarmDateTime = hasAlarmDateTime; 160 data->hasAlarmDateTime = hasAlarmDateTime;
161} 161}
162void OTodo::setDescription(const QString &desc ) 162void OTodo::setDescription(const QString &desc )
163{ 163{
164// qWarning( "desc " + desc ); 164// qWarning( "desc " + desc );
165 changeOrModify(); 165 changeOrModify();
166 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 166 data->desc = Qtopia::simplifyMultiLineSpace(desc );
167} 167}
168void OTodo::setSummary( const QString& sum ) 168void OTodo::setSummary( const QString& sum )
169{ 169{
170 changeOrModify(); 170 changeOrModify();
171 data->sum = sum; 171 data->sum = sum;
172} 172}
173void OTodo::setPriority(int prio ) 173void 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}
178void OTodo::setDueDate( QDate date ) 179void OTodo::setDueDate( QDate date )
179{ 180{
180 changeOrModify(); 181 changeOrModify();
181 data->date = date; 182 data->date = date;
182} 183}
183void OTodo::setAlarmDateTime( const QDateTime& alarm ) 184void OTodo::setAlarmDateTime( const QDateTime& alarm )
184{ 185{
185 changeOrModify(); 186 changeOrModify();
186 data->alarmDateTime = alarm; 187 data->alarmDateTime = alarm;
187} 188}
188bool OTodo::isOverdue( ) 189bool OTodo::isOverdue( )
189{ 190{
190 if( data->hasDate ) 191 if( data->hasDate )
191 return QDate::currentDate() > data->date; 192 return QDate::currentDate() > data->date;
192 return false; 193 return false;
193} 194}
194void OTodo::setProgress(ushort progress ) 195void OTodo::setProgress(ushort progress )
195{ 196{
196 changeOrModify(); 197 changeOrModify();
197 data->prog = progress; 198 data->prog = progress;
198} 199}
199QString OTodo::toShortText() const { 200QString OTodo::toShortText() const {
200 return summary(); 201 return summary();
201} 202}
202/*! 203/*!
203 Returns a richt text string 204 Returns a richt text string
204*/ 205*/
205QString OTodo::toRichText() const 206QString OTodo::toRichText() const
206{ 207{
207 QString text; 208 QString text;
208 QStringList catlist; 209 QStringList catlist;
209 210
210 // Description of the todo 211 // Description of the todo
211 if ( !summary().isEmpty() ) { 212 if ( !summary().isEmpty() ) {
212 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 213 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
213 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 214 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
214 } 215 }
215 if( !description().isEmpty() ){ 216 if( !description().isEmpty() ){
216 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 217 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
217 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 218 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
218 } 219 }
219 text += "<br><br><br>"; 220 text += "<br><br><br>";
220 221
221 text += "<b>" + QObject::tr( "Priority:") +" </b>" 222 text += "<b>" + QObject::tr( "Priority:") +" </b>"
222 + QString::number( priority() ) + " <br>"; 223 + QString::number( priority() ) + " <br>";
223 text += "<b>" + QObject::tr( "Progress:") + " </b>" 224 text += "<b>" + QObject::tr( "Progress:") + " </b>"
224 + QString::number( progress() ) + " %<br>"; 225 + QString::number( progress() ) + " %<br>";
225 if (hasDueDate() ){ 226 if (hasDueDate() ){
226 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 227 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
227 text += dueDate().toString(); 228 text += dueDate().toString();
228 text += "<br>"; 229 text += "<br>";
229 } 230 }
230 if (hasAlarmDateTime() ){ 231 if (hasAlarmDateTime() ){
231 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>"; 232 text += "<b>" + QObject::tr( "Alarmed Notification:") + " </b>";
232 text += alarmDateTime().toString(); 233 text += alarmDateTime().toString();
233 text += "<br>"; 234 text += "<br>";
234 } 235 }
235 236
236 text += "<b>" + QObject::tr( "Category:") + "</b> "; 237 text += "<b>" + QObject::tr( "Category:") + "</b> ";
237 text += categoryNames().join(", "); 238 text += categoryNames().join(", ");
238 text += "<br>"; 239 text += "<br>";
239 240
240 return text; 241 return text;
241} 242}
242 243
243bool OTodo::operator<( const OTodo &toDoEvent )const{ 244bool OTodo::operator<( const OTodo &toDoEvent )const{
244 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 245 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
245 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 246 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
246 if( hasDueDate() && toDoEvent.hasDueDate() ){ 247 if( hasDueDate() && toDoEvent.hasDueDate() ){
247 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 248 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
248 return priority() < toDoEvent.priority(); 249 return priority() < toDoEvent.priority();
249 }else{ 250 }else{
250 return dueDate() < toDoEvent.dueDate(); 251 return dueDate() < toDoEvent.dueDate();
251 } 252 }
252 } 253 }
253 return false; 254 return false;
254} 255}
255bool OTodo::operator<=(const OTodo &toDoEvent )const 256bool OTodo::operator<=(const OTodo &toDoEvent )const
256{ 257{
257 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 258 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
258 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 259 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
259 if( hasDueDate() && toDoEvent.hasDueDate() ){ 260 if( hasDueDate() && toDoEvent.hasDueDate() ){
260 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 261 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
261 return priority() <= toDoEvent.priority(); 262 return priority() <= toDoEvent.priority();
262 }else{ 263 }else{
263 return dueDate() <= toDoEvent.dueDate(); 264 return dueDate() <= toDoEvent.dueDate();
264 } 265 }
265 } 266 }
266 return true; 267 return true;
267} 268}
268bool OTodo::operator>(const OTodo &toDoEvent )const 269bool OTodo::operator>(const OTodo &toDoEvent )const
269{ 270{
270 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 271 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
271 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 272 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
272 if( hasDueDate() && toDoEvent.hasDueDate() ){ 273 if( hasDueDate() && toDoEvent.hasDueDate() ){
273 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 274 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
274 return priority() > toDoEvent.priority(); 275 return priority() > toDoEvent.priority();
275 }else{ 276 }else{
276 return dueDate() > toDoEvent.dueDate(); 277 return dueDate() > toDoEvent.dueDate();
277 } 278 }
278 } 279 }
279 return false; 280 return false;
280} 281}
281bool OTodo::operator>=(const OTodo &toDoEvent )const 282bool OTodo::operator>=(const OTodo &toDoEvent )const
282{ 283{
283 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 284 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
284 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 285 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
285 if( hasDueDate() && toDoEvent.hasDueDate() ){ 286 if( hasDueDate() && toDoEvent.hasDueDate() ){
286 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 287 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
287 return priority() > toDoEvent.priority(); 288 return priority() > toDoEvent.priority();
288 }else{ 289 }else{
289 return dueDate() > toDoEvent.dueDate(); 290 return dueDate() > toDoEvent.dueDate();
290 } 291 }
291 } 292 }
292 return true; 293 return true;
293} 294}
294bool OTodo::operator==(const OTodo &toDoEvent )const 295bool OTodo::operator==(const OTodo &toDoEvent )const
295{ 296{
296 if ( data->priority != toDoEvent.data->priority ) return false; 297 if ( data->priority != toDoEvent.data->priority ) return false;
297 if ( data->priority != toDoEvent.data->prog ) return false; 298 if ( data->priority != toDoEvent.data->prog ) return false;
298 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 299 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
299 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 300 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
300 if ( data->date != toDoEvent.data->date ) return false; 301 if ( data->date != toDoEvent.data->date ) return false;
301 if ( data->sum != toDoEvent.data->sum ) return false; 302 if ( data->sum != toDoEvent.data->sum ) return false;
302 if ( data->desc != toDoEvent.data->desc ) return false; 303 if ( data->desc != toDoEvent.data->desc ) return false;
303 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime ) 304 if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime )
304 return false; 305 return false;
305 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime ) 306 if ( data->alarmDateTime != toDoEvent.data->alarmDateTime )
306 return false; 307 return false;
307 308
308 return OPimRecord::operator==( toDoEvent ); 309 return OPimRecord::operator==( toDoEvent );
309} 310}
310void OTodo::deref() { 311void OTodo::deref() {
311 312
312// qWarning("deref in ToDoEvent"); 313// qWarning("deref in ToDoEvent");
313 if ( data->deref() ) { 314 if ( data->deref() ) {
314// qWarning("deleting"); 315// qWarning("deleting");
315 delete data; 316 delete data;
316 data= 0; 317 data= 0;
317 } 318 }
318} 319}
319OTodo &OTodo::operator=(const OTodo &item ) 320OTodo &OTodo::operator=(const OTodo &item )
320{ 321{
321 OPimRecord::operator=( item ); 322 OPimRecord::operator=( item );
322 //qWarning("operator= ref "); 323 //qWarning("operator= ref ");
323 item.data->ref(); 324 item.data->ref();
324 deref(); 325 deref();
325 data = item.data; 326 data = item.data;
326 327
327 return *this; 328 return *this;
328} 329}
329 330
330QMap<int, QString> OTodo::toMap() const { 331QMap<int, QString> OTodo::toMap() const {
331 QMap<int, QString> map; 332 QMap<int, QString> map;
332 333
333 map.insert( Uid, QString::number( uid() ) ); 334 map.insert( Uid, QString::number( uid() ) );
334 map.insert( Category, idsToString( categories() ) ); 335 map.insert( Category, idsToString( categories() ) );
335 map.insert( HasDate, QString::number( data->hasDate ) ); 336 map.insert( HasDate, QString::number( data->hasDate ) );
336 map.insert( Completed, QString::number( data->isCompleted ) ); 337 map.insert( Completed, QString::number( data->isCompleted ) );
337 map.insert( Description, data->desc ); 338 map.insert( Description, data->desc );
338 map.insert( Summary, data->sum ); 339 map.insert( Summary, data->sum );
339 map.insert( Priority, QString::number( data->priority ) ); 340 map.insert( Priority, QString::number( data->priority ) );
340 map.insert( DateDay, QString::number( data->date.day() ) ); 341 map.insert( DateDay, QString::number( data->date.day() ) );
341 map.insert( DateMonth, QString::number( data->date.month() ) ); 342 map.insert( DateMonth, QString::number( data->date.month() ) );
342 map.insert( DateYear, QString::number( data->date.year() ) ); 343 map.insert( DateYear, QString::number( data->date.year() ) );
343 map.insert( Progress, QString::number( data->prog ) ); 344 map.insert( Progress, QString::number( data->prog ) );
344 map.insert( CrossReference, crossToString() ); 345 map.insert( CrossReference, crossToString() );
345 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); 346 map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) );
346 map.insert( AlarmDateTime, data->alarmDateTime.toString() ); 347 map.insert( AlarmDateTime, data->alarmDateTime.toString() );
347 348
348 return map; 349 return map;
349} 350}
350 351
351QMap<QString, QString> OTodo::toExtraMap()const { 352QMap<QString, QString> OTodo::toExtraMap()const {
352 return data->extra; 353 return data->extra;
353} 354}
354/** 355/**
355 * change or modify looks at the ref count and either 356 * change or modify looks at the ref count and either
356 * creates a new QShared Object or it can modify it 357 * creates a new QShared Object or it can modify it
357 * right in place 358 * right in place
358 */ 359 */
359void OTodo::changeOrModify() { 360void OTodo::changeOrModify() {
360 if ( data->count != 1 ) { 361 if ( data->count != 1 ) {
361// qWarning("changeOrModify"); 362// qWarning("changeOrModify");
362 data->deref(); 363 data->deref();
363 OTodoData* d2 = new OTodoData(); 364 OTodoData* d2 = new OTodoData();
364 copy(data, d2 ); 365 copy(data, d2 );
365 data = d2; 366 data = d2;
366 } 367 }
367} 368}
368void OTodo::copy( OTodoData* src, OTodoData* dest ) { 369void OTodo::copy( OTodoData* src, OTodoData* dest ) {
369 dest->date = src->date; 370 dest->date = src->date;
370 dest->isCompleted = src->isCompleted; 371 dest->isCompleted = src->isCompleted;
371 dest->hasDate = src->hasDate; 372 dest->hasDate = src->hasDate;
372 dest->priority = src->priority; 373 dest->priority = src->priority;
373 dest->desc = src->desc; 374 dest->desc = src->desc;
374 dest->sum = src->sum; 375 dest->sum = src->sum;
375 dest->extra = src->extra; 376 dest->extra = src->extra;
376 dest->prog = src->prog; 377 dest->prog = src->prog;
377 dest->hasAlarmDateTime = src->hasAlarmDateTime; 378 dest->hasAlarmDateTime = src->hasAlarmDateTime;
378 dest->alarmDateTime = src->alarmDateTime; 379 dest->alarmDateTime = src->alarmDateTime;
379} 380}
380QString OTodo::type() const { 381QString OTodo::type() const {
381 return QString::fromLatin1("OTodo"); 382 return QString::fromLatin1("OTodo");
382} 383}
383QString OTodo::recordField(int id )const { 384QString OTodo::recordField(int id )const {
384 return QString::null; 385 return QString::null;
385} 386}
386 387
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
@@ -1,71 +1,77 @@
1#include <qdatetime.h> 1#include <qdatetime.h>
2 2
3#include <qpe/alarmserver.h> 3#include <qpe/alarmserver.h>
4 4
5#include "otodoaccessxml.h" 5#include "otodoaccessxml.h"
6#include "otodoaccess.h" 6#include "otodoaccess.h"
7 7
8 8
9OTodoAccess::OTodoAccess( OTodoAccessBackend* end ) 9OTodoAccess::OTodoAccess( OTodoAccessBackend* end )
10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end ) 10 : QObject(), OPimAccessTemplate<OTodo>( end ), m_todoBackEnd( end )
11{ 11{
12 if (end == 0l ) 12 if (end == 0l )
13 m_todoBackEnd = new OTodoAccessXML( "Todolist" ); 13 m_todoBackEnd = new OTodoAccessXML( "Todolist" );
14 14
15 setBackEnd( m_todoBackEnd ); 15 setBackEnd( m_todoBackEnd );
16} 16}
17OTodoAccess::~OTodoAccess() { 17OTodoAccess::~OTodoAccess() {
18// qWarning("~OTodoAccess"); 18// qWarning("~OTodoAccess");
19} 19}
20void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) { 20void OTodoAccess::mergeWith( const QValueList<OTodo>& list ) {
21 QValueList<OTodo>::ConstIterator it; 21 QValueList<OTodo>::ConstIterator it;
22 for ( it = list.begin(); it != list.end(); ++it ) { 22 for ( it = list.begin(); it != list.end(); ++it ) {
23 replace( (*it) ); 23 replace( (*it) );
24 } 24 }
25} 25}
26OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 26OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
27 const QDate& end, 27 const QDate& end,
28 bool includeNoDates ) { 28 bool includeNoDates ) {
29 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 29 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
30 30
31 List lis( ints, this ); 31 List lis( ints, this );
32 return lis; 32 return lis;
33} 33}
34OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start, 34OTodoAccess::List OTodoAccess::effectiveToDos( const QDate& start,
35 bool includeNoDates ) { 35 bool includeNoDates ) {
36 return effectiveToDos( start, QDate::currentDate(), 36 return effectiveToDos( start, QDate::currentDate(),
37 includeNoDates ); 37 includeNoDates );
38} 38}
39OTodoAccess::List OTodoAccess::overDue() { 39OTodoAccess::List OTodoAccess::overDue() {
40 List lis( m_todoBackEnd->overDue(), this ); 40 List lis( m_todoBackEnd->overDue(), this );
41 return lis; 41 return lis;
42} 42}
43void OTodoAccess::addAlarm( const OTodo& event) { 43void OTodoAccess::addAlarm( const OTodo& event) {
44 if (!event.hasAlarmDateTime() ) 44 if (!event.hasAlarmDateTime() )
45 return; 45 return;
46 46
47 QDateTime now = QDateTime::currentDateTime(); 47 QDateTime now = QDateTime::currentDateTime();
48 QDateTime schedule = event.alarmDateTime(); 48 QDateTime schedule = event.alarmDateTime();
49 49
50 if ( schedule > now ){ 50 if ( schedule > now ){
51 AlarmServer::addAlarm( schedule, 51 AlarmServer::addAlarm( schedule,
52 "QPE/Application/todolist", 52 "QPE/Application/todolist",
53 "alarm(QDateTime,int)", event.uid() ); 53 "alarm(QDateTime,int)", event.uid() );
54 54
55 } 55 }
56} 56}
57void OTodoAccess::delAlarm( int uid) { 57void OTodoAccess::delAlarm( int uid) {
58 58
59 QDateTime schedule; // Create null DateTime 59 QDateTime schedule; // Create null DateTime
60 60
61 // I hope this will remove all scheduled alarms 61 // I hope this will remove all scheduled alarms
62 // with the given uid !? 62 // with the given uid !?
63 // If not: I have to rethink how to remove already 63 // If not: I have to rethink how to remove already
64 // scheduled events... (se) 64 // scheduled events... (se)
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 */
72OTodoAccess::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
@@ -1,79 +1,93 @@
1#ifndef OPIE_TODO_ACCESS_H 1#ifndef OPIE_TODO_ACCESS_H
2#define OPIE_TODO_ACCESS_H 2#define OPIE_TODO_ACCESS_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qvaluelist.h> 5#include <qvaluelist.h>
6 6
7#include "otodo.h" 7#include "otodo.h"
8#include "otodoaccessbackend.h" 8#include "otodoaccessbackend.h"
9#include "opimaccesstemplate.h" 9#include "opimaccesstemplate.h"
10 10
11 11
12/** 12/**
13 * OTodoAccess 13 * OTodoAccess
14 * the class to get access to 14 * the class to get access to
15 * the todolist 15 * the todolist
16 */ 16 */
17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { 17class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> {
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
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 */
30 /** 37 /**
31 * include todos from start to end 38 * include todos from start to end
32 * includeNoDates whether or not to include 39 * includeNoDates whether or not to include
33 * events with no dates 40 * events with no dates
34 */ 41 */
35 List effectiveToDos( const QDate& start, 42 List effectiveToDos( const QDate& start,
36 const QDate& end, 43 const QDate& end,
37 bool includeNoDates = true ); 44 bool includeNoDates = true );
38 45
39 /** 46 /**
40 * start 47 * start
41 * end date taken from the currentDate() 48 * end date taken from the currentDate()
42 */ 49 */
43 List effectiveToDos( const QDate& start, 50 List effectiveToDos( const QDate& start,
44 bool includeNoDates = true ); 51 bool includeNoDates = true );
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
57 /** 70 /**
58 * add an Alarm to the AlarmServer 71 * add an Alarm to the AlarmServer
59 */ 72 */
60 void addAlarm( const OTodo& ); 73 void addAlarm( const OTodo& );
61 74
62 /** 75 /**
63 * delete an alarm with the uid from 76 * delete an alarm with the uid from
64 * the alarm server 77 * the alarm server
65 */ 78 */
66 void delAlarm( int uid ); 79 void delAlarm( int uid );
67 80
68signals: 81signals:
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* );
73private: 86private:
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
@@ -1,18 +1,20 @@
1#ifndef OPIE_TODO_ACCESS_BACKEND_H 1#ifndef OPIE_TODO_ACCESS_BACKEND_H
2#define OPIE_TODO_ACCESS_BACKEND_H 2#define OPIE_TODO_ACCESS_BACKEND_H
3 3
4#include "otodo.h" 4#include "otodo.h"
5#include "opimaccessbackend.h" 5#include "opimaccessbackend.h"
6 6
7class OTodoAccessBackend : public OPimAccessBackend<OTodo> { 7class OTodoAccessBackend : public OPimAccessBackend<OTodo> {
8public: 8public:
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,366 +1,511 @@
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>
8 9
9#include "otodoaccessxml.h" 10#include "otodoaccessxml.h"
10 11
11OTodoAccessXML::OTodoAccessXML( const QString& appName, 12OTodoAccessXML::OTodoAccessXML( const QString& appName,
12 const QString& fileName ) 13 const QString& fileName )
13 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
14{ 15{
15 if (!fileName.isEmpty() ) 16 if (!fileName.isEmpty() )
16 m_file = fileName; 17 m_file = fileName;
17 else 18 else
18 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 19 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
19} 20}
20OTodoAccessXML::~OTodoAccessXML() { 21OTodoAccessXML::~OTodoAccessXML() {
21 22
22} 23}
23bool OTodoAccessXML::load() { 24bool OTodoAccessXML::load() {
24 m_opened = true; 25 m_opened = true;
25 m_changed = false; 26 m_changed = false;
26 /* initialize dict */ 27 /* initialize dict */
27 /* 28 /*
28 * UPDATE dict if you change anything!!! 29 * UPDATE dict if you change anything!!!
29 */ 30 */
30 QAsciiDict<int> dict(15); 31 QAsciiDict<int> dict(15);
31 dict.setAutoDelete( TRUE ); 32 dict.setAutoDelete( TRUE );
32 dict.insert("Categories" , new int(OTodo::Category) ); 33 dict.insert("Categories" , new int(OTodo::Category) );
33 dict.insert("Uid" , new int(OTodo::Uid) ); 34 dict.insert("Uid" , new int(OTodo::Uid) );
34 dict.insert("HasDate" , new int(OTodo::HasDate) ); 35 dict.insert("HasDate" , new int(OTodo::HasDate) );
35 dict.insert("Completed" , new int(OTodo::Completed) ); 36 dict.insert("Completed" , new int(OTodo::Completed) );
36 dict.insert("Description" , new int(OTodo::Description) ); 37 dict.insert("Description" , new int(OTodo::Description) );
37 dict.insert("Summary" , new int(OTodo::Summary) ); 38 dict.insert("Summary" , new int(OTodo::Summary) );
38 dict.insert("Priority" , new int(OTodo::Priority) ); 39 dict.insert("Priority" , new int(OTodo::Priority) );
39 dict.insert("DateDay" , new int(OTodo::DateDay) ); 40 dict.insert("DateDay" , new int(OTodo::DateDay) );
40 dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 41 dict.insert("DateMonth" , new int(OTodo::DateMonth) );
41 dict.insert("DateYear" , new int(OTodo::DateYear) ); 42 dict.insert("DateYear" , new int(OTodo::DateYear) );
42 dict.insert("Progress" , new int(OTodo::Progress) ); 43 dict.insert("Progress" , new int(OTodo::Progress) );
43 dict.insert("Completed", new int(OTodo::Completed) ); 44 dict.insert("Completed", new int(OTodo::Completed) );
44 dict.insert("CrossReference", new int(OTodo::CrossReference) ); 45 dict.insert("CrossReference", new int(OTodo::CrossReference) );
45 dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); 46 dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
46 dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); 47 dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
47 48
48 Opie::XMLElement *root = Opie::XMLElement::load( m_file ); 49 Opie::XMLElement *root = Opie::XMLElement::load( m_file );
49 int day, year, month; 50 int day, year, month;
50 day = year = month = -1; 51 day = year = month = -1;
51 52
52 /* if opened */ 53 /* if opened */
53 if ( root != 0l ) { 54 if ( root != 0l ) {
54 Opie::XMLElement *element = root->firstChild(); 55 Opie::XMLElement *element = root->firstChild();
55 if ( element == 0l ) 56 if ( element == 0l )
56 return false; 57 return false;
57 58
58 element = element->firstChild(); 59 element = element->firstChild();
59 60
60 while ( element ) { 61 while ( element ) {
61 if ( element->tagName() != QString::fromLatin1("Task") ) { 62 if ( element->tagName() != QString::fromLatin1("Task") ) {
62 element = element->nextChild(); 63 element = element->nextChild();
63 continue; 64 continue;
64 } 65 }
65 /* here is the right element for a task */ 66 /* here is the right element for a task */
66 OTodo ev = todo( &dict, element ); 67 OTodo ev = todo( &dict, element );
67 m_events.insert( ev.uid(), ev ); 68 m_events.insert( ev.uid(), ev );
68 69
69 element = element->nextChild(); 70 element = element->nextChild();
70 } 71 }
71 }else { 72 }else {
72// qWarning("could not parse"); 73// qWarning("could not parse");
73 return false;; 74 return false;;
74 } 75 }
75 delete root; 76 delete root;
76 77
77// qWarning("Access %d" + m_events.count() ); 78// qWarning("Access %d" + m_events.count() );
78 return true; 79 return true;
79} 80}
80bool OTodoAccessXML::reload() { 81bool OTodoAccessXML::reload() {
81 return load(); 82 return load();
82} 83}
83bool OTodoAccessXML::save() { 84bool OTodoAccessXML::save() {
84// qWarning("saving"); 85// qWarning("saving");
85 if (!m_opened || !m_changed ) { 86 if (!m_opened || !m_changed ) {
86// qWarning("not saving"); 87// qWarning("not saving");
87 return true; 88 return true;
88 } 89 }
89 QString strNewFile = m_file + ".new"; 90 QString strNewFile = m_file + ".new";
90 QFile f( strNewFile ); 91 QFile f( strNewFile );
91 if (!f.open( IO_WriteOnly|IO_Raw ) ) 92 if (!f.open( IO_WriteOnly|IO_Raw ) )
92 return false; 93 return false;
93 94
94 int written; 95 int written;
95 QString out; 96 QString out;
96 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 97 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
97 98
98 // for all todos 99 // for all todos
99 QMap<int, OTodo>::Iterator it; 100 QMap<int, OTodo>::Iterator it;
100 for (it = m_events.begin(); it != m_events.end(); ++it ) { 101 for (it = m_events.begin(); it != m_events.end(); ++it ) {
101 out+= "<Task " + toString( (*it) ) + " />\n"; 102 out+= "<Task " + toString( (*it) ) + " />\n";
102 QCString cstr = out.utf8(); 103 QCString cstr = out.utf8();
103 written = f.writeBlock( cstr.data(), cstr.length() ); 104 written = f.writeBlock( cstr.data(), cstr.length() );
104 105
105 /* less written then we wanted */ 106 /* less written then we wanted */
106 if ( written != (int)cstr.length() ) { 107 if ( written != (int)cstr.length() ) {
107 f.close(); 108 f.close();
108 QFile::remove( strNewFile ); 109 QFile::remove( strNewFile );
109 return false; 110 return false;
110 } 111 }
111 out = QString::null; 112 out = QString::null;
112 } 113 }
113 114
114 out += "</Tasks>"; 115 out += "</Tasks>";
115 QCString cstr = out.utf8(); 116 QCString cstr = out.utf8();
116 written = f.writeBlock( cstr.data(), cstr.length() ); 117 written = f.writeBlock( cstr.data(), cstr.length() );
117 118
118 if ( written != (int)cstr.length() ) { 119 if ( written != (int)cstr.length() ) {
119 f.close(); 120 f.close();
120 QFile::remove( strNewFile ); 121 QFile::remove( strNewFile );
121 return false; 122 return false;
122 } 123 }
123 /* flush before renaming */ 124 /* flush before renaming */
124 f.close(); 125 f.close();
125 126
126 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 127 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
127// qWarning("error renaming"); 128// qWarning("error renaming");
128 QFile::remove( strNewFile ); 129 QFile::remove( strNewFile );
129 } 130 }
130 131
131 m_changed = false; 132 m_changed = false;
132 return true; 133 return true;
133} 134}
134QArray<int> OTodoAccessXML::allRecords()const { 135QArray<int> OTodoAccessXML::allRecords()const {
135 QArray<int> ids( m_events.count() ); 136 QArray<int> ids( m_events.count() );
136 QMap<int, OTodo>::ConstIterator it; 137 QMap<int, OTodo>::ConstIterator it;
137 int i = 0; 138 int i = 0;
138 139
139 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 140 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
140 ids[i] = it.key(); 141 ids[i] = it.key();
141 i++; 142 i++;
142 } 143 }
143 return ids; 144 return ids;
144} 145}
145QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) { 146QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) {
146 QArray<int> ids(0); 147 QArray<int> ids(0);
147 return ids; 148 return ids;
148} 149}
149OTodo OTodoAccessXML::find( int uid )const { 150OTodo OTodoAccessXML::find( int uid )const {
150 OTodo todo; 151 OTodo todo;
151 todo.setUid( 0 ); // isEmpty() 152 todo.setUid( 0 ); // isEmpty()
152 QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); 153 QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
153 if ( it != m_events.end() ) 154 if ( it != m_events.end() )
154 todo = it.data(); 155 todo = it.data();
155 156
156 return todo; 157 return todo;
157} 158}
158void OTodoAccessXML::clear() { 159void OTodoAccessXML::clear() {
159 if (m_opened ) 160 if (m_opened )
160 m_changed = true; 161 m_changed = true;
161 162
162 m_events.clear(); 163 m_events.clear();
163} 164}
164bool OTodoAccessXML::add( const OTodo& todo ) { 165bool OTodoAccessXML::add( const OTodo& todo ) {
165// qWarning("add"); 166// qWarning("add");
166 m_changed = true; 167 m_changed = true;
167 m_events.insert( todo.uid(), todo ); 168 m_events.insert( todo.uid(), todo );
168 169
169 return true; 170 return true;
170} 171}
171bool OTodoAccessXML::remove( int uid ) { 172bool OTodoAccessXML::remove( int uid ) {
172 m_changed = true; 173 m_changed = true;
173 m_events.remove( uid ); 174 m_events.remove( uid );
174 175
175 return true; 176 return true;
176} 177}
177bool OTodoAccessXML::replace( const OTodo& todo) { 178bool OTodoAccessXML::replace( const OTodo& todo) {
178 m_changed = true; 179 m_changed = true;
179 m_events.replace( todo.uid(), todo ); 180 m_events.replace( todo.uid(), todo );
180 181
181 return true; 182 return true;
182} 183}
183QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, 184QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
184 const QDate& end, 185 const QDate& end,
185 bool includeNoDates ) { 186 bool includeNoDates ) {
186 QArray<int> ids( m_events.count() ); 187 QArray<int> ids( m_events.count() );
187 QMap<int, OTodo>::Iterator it; 188 QMap<int, OTodo>::Iterator it;
188 189
189 int i = 0; 190 int i = 0;
190 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 191 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
191 if ( !it.data().hasDueDate() ) { 192 if ( !it.data().hasDueDate() ) {
192 if ( includeNoDates ) { 193 if ( includeNoDates ) {
193 ids[i] = it.key(); 194 ids[i] = it.key();
194 i++; 195 i++;
195 } 196 }
196 }else if ( it.data().dueDate() >= start && 197 }else if ( it.data().dueDate() >= start &&
197 it.data().dueDate() <= end ) { 198 it.data().dueDate() <= end ) {
198 ids[i] = it.key(); 199 ids[i] = it.key();
199 i++; 200 i++;
200 } 201 }
201 } 202 }
202 ids.resize( i ); 203 ids.resize( i );
203 return ids; 204 return ids;
204} 205}
205QArray<int> OTodoAccessXML::overDue() { 206QArray<int> OTodoAccessXML::overDue() {
206 QArray<int> ids( m_events.count() ); 207 QArray<int> ids( m_events.count() );
207 int i = 0; 208 int i = 0;
208 209
209 QMap<int, OTodo>::Iterator it; 210 QMap<int, OTodo>::Iterator it;
210 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 211 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
211 if ( it.data().isOverdue() ) { 212 if ( it.data().isOverdue() ) {
212 ids[i] = it.key(); 213 ids[i] = it.key();
213 i++; 214 i++;
214 } 215 }
215 } 216 }
216 ids.resize( i ); 217 ids.resize( i );
217 return ids; 218 return ids;
218} 219}
219 220
220 221
221/* private */ 222/* private */
222OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)const { 223OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)const {
223// qWarning("parse to do from XMLElement" ); 224// qWarning("parse to do from XMLElement" );
224 OTodo ev; 225 OTodo ev;
225 QMap<QString, QString> attributes = element->attributes(); 226 QMap<QString, QString> attributes = element->attributes();
226 QMap<QString, QString>::Iterator it; 227 QMap<QString, QString>::Iterator it;
227 228
228 int *find=0; 229 int *find=0;
229 int day, month, year; 230 int day, month, year;
230 day = month = year = -1; 231 day = month = year = -1;
231 for ( it = attributes.begin(); it != attributes.end(); ++it ) { 232 for ( it = attributes.begin(); it != attributes.end(); ++it ) {
232 find = (*dict)[ it.key() ]; 233 find = (*dict)[ it.key() ];
233 if (!find ) { 234 if (!find ) {
234// qWarning("Unknown option" + it.key() ); 235// qWarning("Unknown option" + it.key() );
235 ev.setCustomField( it.key(), it.data() ); 236 ev.setCustomField( it.key(), it.data() );
236 continue; 237 continue;
237 } 238 }
238 239
239 switch( *find ) { 240 switch( *find ) {
240 case OTodo::Uid: 241 case OTodo::Uid:
241 ev.setUid( it.data().toInt() ); 242 ev.setUid( it.data().toInt() );
242 break; 243 break;
243 case OTodo::Category: 244 case OTodo::Category:
244 ev.setCategories( ev.idsFromString( it.data() ) ); 245 ev.setCategories( ev.idsFromString( it.data() ) );
245 break; 246 break;
246 case OTodo::HasDate: 247 case OTodo::HasDate:
247 ev.setHasDueDate( it.data().toInt() ); 248 ev.setHasDueDate( it.data().toInt() );
248 break; 249 break;
249 case OTodo::Completed: 250 case OTodo::Completed:
250 ev.setCompleted( it.data().toInt() ); 251 ev.setCompleted( it.data().toInt() );
251 break; 252 break;
252 case OTodo::Description: 253 case OTodo::Description:
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:
265 month = it.data().toInt(); 267 month = it.data().toInt();
266 break; 268 break;
267 case OTodo::DateYear: 269 case OTodo::DateYear:
268 year = it.data().toInt(); 270 year = it.data().toInt();
269 break; 271 break;
270 case OTodo::Progress: 272 case OTodo::Progress:
271 ev.setProgress( it.data().toInt() ); 273 ev.setProgress( it.data().toInt() );
272 break; 274 break;
273 case OTodo::CrossReference: 275 case OTodo::CrossReference:
274 { 276 {
275 /* 277 /*
276 * A cross refernce looks like 278 * A cross refernce looks like
277 * appname,id;appname,id 279 * appname,id;appname,id
278 * we need to split it up 280 * we need to split it up
279 */ 281 */
280 QStringList refs = QStringList::split(';', it.data() ); 282 QStringList refs = QStringList::split(';', it.data() );
281 QStringList::Iterator strIt; 283 QStringList::Iterator strIt;
282 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { 284 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
283 int pos = (*strIt).find(','); 285 int pos = (*strIt).find(',');
284 if ( pos > -1 ) 286 if ( pos > -1 )
285 ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); 287 ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
286 288
287 } 289 }
288 break; 290 break;
289 } 291 }
290 case OTodo::HasAlarmDateTime: 292 case OTodo::HasAlarmDateTime:
291 ev.setHasAlarmDateTime( it.data().toInt() ); 293 ev.setHasAlarmDateTime( it.data().toInt() );
292 break; 294 break;
293 case OTodo::AlarmDateTime: { 295 case OTodo::AlarmDateTime: {
294 /* this sounds better ;) zecke */ 296 /* this sounds better ;) zecke */
295 ev.setAlarmDateTime( TimeConversion::fromISO8601( it.data().local8Bit() ) ); 297 ev.setAlarmDateTime( TimeConversion::fromISO8601( it.data().local8Bit() ) );
296 break; 298 break;
297 } 299 }
298 default: 300 default:
299 break; 301 break;
300 } 302 }
301 } 303 }
302 if ( ev.hasDueDate() ) { 304 if ( ev.hasDueDate() ) {
303 QDate date( year, month, day ); 305 QDate date( year, month, day );
304 ev.setDueDate( date ); 306 ev.setDueDate( date );
305 } 307 }
306 308
307 return ev; 309 return ev;
308} 310}
309QString OTodoAccessXML::toString( const OTodo& ev )const { 311QString OTodoAccessXML::toString( const OTodo& ev )const {
310 QString str; 312 QString str;
311 313
312 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; 314 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
313 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; 315 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
314 str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; 316 str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
315 str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; 317 str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
316 318
317 str += "Categories=\"" + toString( ev.categories() ) + "\" "; 319 str += "Categories=\"" + toString( ev.categories() ) + "\" ";
318 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; 320 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
319 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; 321 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
320 322
321 if ( ev.hasDueDate() ) { 323 if ( ev.hasDueDate() ) {
322 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 324 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
323 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; 325 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
324 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; 326 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
325 } 327 }
326// qWarning( "Uid %d", ev.uid() ); 328// qWarning( "Uid %d", ev.uid() );
327 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 329 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
328 330
329// append the extra options 331// append the extra options
330 /* FIXME Qtopia::Record this is currently not 332 /* FIXME Qtopia::Record this is currently not
331 * possible you can set custom fields 333 * possible you can set custom fields
332 * but don' iterate over the list 334 * but don' iterate over the list
333 * I may do #define private protected 335 * I may do #define private protected
334 * for this case - cough --zecke 336 * for this case - cough --zecke
335 */ 337 */
336 /* 338 /*
337 QMap<QString, QString> extras = ev.extras(); 339 QMap<QString, QString> extras = ev.extras();
338 QMap<QString, QString>::Iterator extIt; 340 QMap<QString, QString>::Iterator extIt;
339 for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) 341 for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
340 str += extIt.key() + "=\"" + extIt.data() + "\" "; 342 str += extIt.key() + "=\"" + extIt.data() + "\" ";
341 */ 343 */
342 // cross refernce 344 // cross refernce
343 QStringList list = ev.relatedApps(); 345 QStringList list = ev.relatedApps();
344 QStringList::Iterator listIt; 346 QStringList::Iterator listIt;
345 QString refs; 347 QString refs;
346 str += "CrossReference=\""; 348 str += "CrossReference=\"";
347 bool added = false; 349 bool added = false;
348 for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { 350 for ( listIt = list.begin(); listIt != list.end(); ++listIt ) {
349 added = true; 351 added = true;
350 QArray<int> ints = ev.relations( (*listIt) ); 352 QArray<int> ints = ev.relations( (*listIt) );
351 for ( uint i = 0; i< ints.count(); i++ ) { 353 for ( uint i = 0; i< ints.count(); i++ ) {
352 str += (*listIt) + "," + QString::number( i ) + ";"; 354 str += (*listIt) + "," + QString::number( i ) + ";";
353 } 355 }
354 } 356 }
355 if ( added ) 357 if ( added )
356 str = str.remove( str.length()-1, 1 ); 358 str = str.remove( str.length()-1, 1 );
357 359
358 str += "\" "; 360 str += "\" ";
359 361
360 str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; 362 str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" ";
361 363
362 return str; 364 return str;
363} 365}
364QString OTodoAccessXML::toString( const QArray<int>& ints ) const { 366QString 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
372struct 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 */
391class OTodoXMLVector : public QVector<OTodoXMLContainer> {
392public:
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
475QArray<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
@@ -1,53 +1,55 @@
1#ifndef OPIE_TODO_ACCESS_XML_H 1#ifndef OPIE_TODO_ACCESS_XML_H
2#define OPIE_TODO_ACCESS_XML_H 2#define OPIE_TODO_ACCESS_XML_H
3 3
4#include <qasciidict.h> 4#include <qasciidict.h>
5#include <qmap.h> 5#include <qmap.h>
6 6
7#include "otodoaccessbackend.h" 7#include "otodoaccessbackend.h"
8 8
9namespace Opie { 9namespace Opie {
10 class XMLElement; 10 class XMLElement;
11}; 11};
12 12
13class OTodoAccessXML : public OTodoAccessBackend { 13class OTodoAccessXML : public OTodoAccessBackend {
14public: 14public:
15 /** 15 /**
16 * fileName if Empty we will use the default path 16 * fileName if Empty we will use the default path
17 */ 17 */
18 OTodoAccessXML( const QString& appName, 18 OTodoAccessXML( const QString& appName,
19 const QString& fileName = QString::null ); 19 const QString& fileName = QString::null );
20 ~OTodoAccessXML(); 20 ~OTodoAccessXML();
21 21
22 bool load(); 22 bool load();
23 bool reload(); 23 bool reload();
24 bool save(); 24 bool save();
25 25
26 QArray<int> allRecords()const; 26 QArray<int> allRecords()const;
27 QArray<int> queryByExample( const OTodo&, int sort ); 27 QArray<int> queryByExample( const OTodo&, int sort );
28 OTodo find( int uid )const; 28 OTodo find( int uid )const;
29 void clear(); 29 void clear();
30 bool add( const OTodo& ); 30 bool add( const OTodo& );
31 bool remove( int uid ); 31 bool remove( int uid );
32 bool replace( const OTodo& ); 32 bool replace( const OTodo& );
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 );
39private: 41private:
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;
45 QString m_app; 47 QString m_app;
46 bool m_opened : 1; 48 bool m_opened : 1;
47 bool m_changed : 1; 49 bool m_changed : 1;
48 class OTodoAccessXMLPrivate; 50 class OTodoAccessXMLPrivate;
49 OTodoAccessXMLPrivate* d; 51 OTodoAccessXMLPrivate* d;
50 52
51}; 53};
52 54
53#endif 55#endif