summaryrefslogtreecommitdiff
path: root/libopie/pim
Unidiff
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/orecordlist.h5
-rw-r--r--libopie/pim/otodoaccess.cpp4
-rw-r--r--libopie/pim/otodoaccesssql.cpp397
-rw-r--r--libopie/pim/otodoaccesssql.h46
-rw-r--r--libopie/pim/otodoaccessxml.cpp1
5 files changed, 448 insertions, 5 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index 1fd0741..b6fa7fa 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -1,260 +1,259 @@
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 T operator[]( uint i );
111 // FIXME implemenent remove 111 // FIXME implemenent remove
112 /* 112 /*
113 ConstIterator begin()const; 113 ConstIterator begin()const;
114 ConstIterator end()const; 114 ConstIterator end()const;
115 */ 115 */
116private: 116private:
117 QArray<int> m_ids; 117 QArray<int> m_ids;
118 const Base* m_acc; 118 const Base* m_acc;
119}; 119};
120 120
121/* ok now implement it */ 121/* ok now implement it */
122template <class T> 122template <class T>
123ORecordListIterator<T>::ORecordListIterator() { 123ORecordListIterator<T>::ORecordListIterator() {
124 m_current = 0; 124 m_current = 0;
125 m_temp = 0l; 125 m_temp = 0l;
126 m_end = true; 126 m_end = true;
127 m_record = T(); 127 m_record = T();
128} 128}
129template <class T> 129template <class T>
130ORecordListIterator<T>::~ORecordListIterator() { 130ORecordListIterator<T>::~ORecordListIterator() {
131/* nothing to delete */ 131/* nothing to delete */
132} 132}
133 133
134template <class T> 134template <class T>
135ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 135ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
136// qWarning("ORecordListIterator copy c'tor"); 136// qWarning("ORecordListIterator copy c'tor");
137 m_uids = it.m_uids; 137 m_uids = it.m_uids;
138 m_current = it.m_current; 138 m_current = it.m_current;
139 m_temp = it.m_temp; 139 m_temp = it.m_temp;
140 m_end = it.m_end; 140 m_end = it.m_end;
141 m_record = it.m_record; 141 m_record = it.m_record;
142} 142}
143 143
144template <class T> 144template <class T>
145ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 145ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
146 m_uids = it.m_uids; 146 m_uids = it.m_uids;
147 m_current = it.m_current; 147 m_current = it.m_current;
148 m_temp = it.m_temp; 148 m_temp = it.m_temp;
149 m_end = it.m_end; 149 m_end = it.m_end;
150 m_record = it.m_record; 150 m_record = it.m_record;
151 151
152 return *this; 152 return *this;
153} 153}
154 154
155template <class T> 155template <class T>
156T ORecordListIterator<T>::operator*() { 156T ORecordListIterator<T>::operator*() {
157// qWarning("operator* %d %d", m_current, m_uids[m_current] ); 157 qWarning("operator* %d %d", m_current, m_uids[m_current] );
158 if (!m_end ) 158 if (!m_end )
159 /* FIXME 159 /* FIXME
160 * until the cache is in place 160 * until the cache is in place
161 * we do the uid match uid check 161 * we do the uid match uid check
162 */ 162 */
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] );
165 else 164 else
166 m_record = T(); 165 m_record = T();
167 166
168 return m_record; 167 return m_record;
169} 168}
170 169
171template <class T> 170template <class T>
172ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 171ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
173 if (m_current < m_uids.count() ) { 172 if (m_current < m_uids.count() ) {
174 m_end = false; 173 m_end = false;
175 ++m_current; 174 ++m_current;
176 }else 175 }else
177 m_end = true; 176 m_end = true;
178 177
179 return *this; 178 return *this;
180} 179}
181template <class T> 180template <class T>
182ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 181ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
183 if ( m_current > 0 ) { 182 if ( m_current > 0 ) {
184 --m_current; 183 --m_current;
185 m_end = false; 184 m_end = false;
186 } else 185 } else
187 m_end = true; 186 m_end = true;
188 187
189 return *this; 188 return *this;
190} 189}
191 190
192template <class T> 191template <class T>
193bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 192bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
194 193
195 /* if both are at we're the same.... */ 194 /* if both are at we're the same.... */
196 if ( m_end == it.m_end ) return true; 195 if ( m_end == it.m_end ) return true;
197 196
198 if ( m_uids != it.m_uids ) return false; 197 if ( m_uids != it.m_uids ) return false;
199 if ( m_current != it.m_current ) return false; 198 if ( m_current != it.m_current ) return false;
200 if ( m_temp != it.m_temp ) return false; 199 if ( m_temp != it.m_temp ) return false;
201 200
202 return true; 201 return true;
203} 202}
204template <class T> 203template <class T>
205bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 204bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
206 return !(*this == it ); 205 return !(*this == it );
207} 206}
208template <class T> 207template <class T>
209ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 208ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
210 const Base* t ) 209 const Base* t )
211 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) 210 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false )
212{ 211{
213} 212}
214template <class T> 213template <class T>
215uint ORecordListIterator<T>::current()const { 214uint ORecordListIterator<T>::current()const {
216 return m_current; 215 return m_current;
217} 216}
218template <class T> 217template <class T>
219void ORecordListIterator<T>::setCurrent( uint cur ) { 218void ORecordListIterator<T>::setCurrent( uint cur ) {
220 if( cur < m_uids.count() ) { 219 if( cur < m_uids.count() ) {
221 m_end = false; 220 m_end = false;
222 m_current= cur; 221 m_current= cur;
223 } 222 }
224} 223}
225template <class T> 224template <class T>
226uint ORecordListIterator<T>::count()const { 225uint ORecordListIterator<T>::count()const {
227 return m_uids.count(); 226 return m_uids.count();
228} 227}
229template <class T> 228template <class T>
230ORecordList<T>::ORecordList( const QArray<int>& ids, 229ORecordList<T>::ORecordList( const QArray<int>& ids,
231 const Base* acc ) 230 const Base* acc )
232 : m_ids( ids ), m_acc( acc ) 231 : m_ids( ids ), m_acc( acc )
233{ 232{
234} 233}
235template <class T> 234template <class T>
236ORecordList<T>::~ORecordList() { 235ORecordList<T>::~ORecordList() {
237/* nothing to do here */ 236/* nothing to do here */
238} 237}
239template <class T> 238template <class T>
240ORecordList<T>::Iterator ORecordList<T>::begin() { 239ORecordList<T>::Iterator ORecordList<T>::begin() {
241 Iterator it( m_ids, m_acc ); 240 Iterator it( m_ids, m_acc );
242 return it; 241 return it;
243} 242}
244template <class T> 243template <class T>
245ORecordList<T>::Iterator ORecordList<T>::end() { 244ORecordList<T>::Iterator ORecordList<T>::end() {
246 Iterator it( m_ids, m_acc ); 245 Iterator it( m_ids, m_acc );
247 it.m_end = true; 246 it.m_end = true;
248 it.m_current = m_ids.count(); 247 it.m_current = m_ids.count();
249 248
250 return it; 249 return it;
251} 250}
252template <class T> 251template <class T>
253uint ORecordList<T>::count()const { 252uint ORecordList<T>::count()const {
254return m_ids.count(); 253return m_ids.count();
255} 254}
256template <class T> 255template <class T>
257T ORecordList<T>::operator[]( uint i ) { 256T ORecordList<T>::operator[]( uint i ) {
258 return m_acc->find( m_ids[i] ); 257 return m_acc->find( m_ids[i] );
259} 258}
260#endif 259#endif
diff --git a/libopie/pim/otodoaccess.cpp b/libopie/pim/otodoaccess.cpp
index f51da29..5990841 100644
--- a/libopie/pim/otodoaccess.cpp
+++ b/libopie/pim/otodoaccess.cpp
@@ -1,77 +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 "otodoaccesssql.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 OTodoAccessBackendSQL( QString::null);
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/* sort order */ 71/* sort order */
72OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 72OTodoAccess::List OTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
73 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, 73 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
74 filter, cat ); 74 filter, cat );
75 OTodoAccess::List list( ints, this ); 75 OTodoAccess::List list( ints, this );
76 return list; 76 return list;
77} 77}
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
new file mode 100644
index 0000000..209e714
--- a/dev/null
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -0,0 +1,397 @@
1
2#include <qdatetime.h>
3
4#include <qpe/global.h>
5
6#include <opie/osqldriver.h>
7#include <opie/osqlresult.h>
8#include <opie/osqlmanager.h>
9#include <opie/osqlquery.h>
10
11#include "otodoaccesssql.h"
12
13/*
14 * first some query
15 * CREATE query
16 * LOAD query
17 * INSERT
18 * REMOVE
19 * CLEAR
20 */
21namespace {
22 /**
23 * CreateQuery for the Todolist Table
24 */
25 class CreateQuery : public OSQLQuery {
26 public:
27 CreateQuery();
28 ~CreateQuery();
29 QString query()const;
30 };
31
32 /**
33 * LoadQuery
34 * this one queries for all uids
35 */
36 class LoadQuery : public OSQLQuery {
37 public:
38 LoadQuery();
39 ~LoadQuery();
40 QString query()const;
41 };
42
43 /**
44 * inserts/adds a OTodo to the table
45 */
46 class InsertQuery : public OSQLQuery {
47 public:
48 InsertQuery(const OTodo& );
49 ~InsertQuery();
50 QString query()const;
51 private:
52 OTodo m_todo;
53 };
54
55 /**
56 * removes one from the table
57 */
58 class RemoveQuery : public OSQLQuery {
59 public:
60 RemoveQuery(int uid );
61 ~RemoveQuery();
62 QString query()const;
63 private:
64 int m_uid;
65 };
66
67 /**
68 * Clears (delete) a Table
69 */
70 class ClearQuery : public OSQLQuery {
71 public:
72 ClearQuery();
73 ~ClearQuery();
74 QString query()const;
75
76 };
77
78 /**
79 * a find query
80 */
81 class FindQuery : public OSQLQuery {
82 public:
83 FindQuery(int uid);
84 ~FindQuery();
85 QString query()const;
86 private:
87 int m_uid;
88 };
89
90 /**
91 * overdue query
92 */
93 class OverDueQuery : public OSQLQuery {
94 public:
95 OverDueQuery();
96 ~OverDueQuery();
97 QString query()const;
98 };
99 class EffQuery : public OSQLQuery {
100 public:
101 EffQuery( const QDate&, const QDate&, bool inc );
102 ~EffQuery();
103 QString query()const;
104 private:
105 QString with()const;
106 QString out()const;
107 QDate m_start;
108 QDate m_end;
109 bool m_inc :1;
110 };
111
112
113 CreateQuery::CreateQuery() : OSQLQuery() {}
114 CreateQuery::~CreateQuery() {}
115 QString CreateQuery::query()const {
116 QString qu;
117 qu += "create table todolist( uid, categories, completed, progress, ";
118 qu += "summary, DueDate, priority, description )";
119 return qu;
120 }
121
122 LoadQuery::LoadQuery() : OSQLQuery() {}
123 LoadQuery::~LoadQuery() {}
124 QString LoadQuery::query()const {
125 QString qu;
126 qu += "select distinct uid from todolist";
127
128 return qu;
129 }
130
131 InsertQuery::InsertQuery( const OTodo& todo )
132 : OSQLQuery(), m_todo( todo ) {
133 }
134 InsertQuery::~InsertQuery() {
135 }
136 /*
137 * converts from a OTodo to a query
138 * we leave out X-Ref + Alarms
139 */
140 QString InsertQuery::query()const{
141 int year, month, day;
142 year = month = day = 0;
143 if (m_todo.hasDueDate() ) {
144 QDate date = m_todo.dueDate();
145 year = date.year();
146 month = date.month();
147 day = date.day();
148 }
149 QString qu;
150 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',";
151 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ",";
152 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',";
153 qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')";
154
155 qWarning("add %s", qu.latin1() );
156 return qu;
157 }
158
159 RemoveQuery::RemoveQuery(int uid )
160 : OSQLQuery(), m_uid( uid ) {}
161 RemoveQuery::~RemoveQuery() {}
162 QString RemoveQuery::query()const {
163 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid);
164 return qu;
165 }
166
167
168 ClearQuery::ClearQuery()
169 : OSQLQuery() {}
170 ClearQuery::~ClearQuery() {}
171 QString ClearQuery::query()const {
172 QString qu = "drop table todolist";
173 return qu;
174 }
175 FindQuery::FindQuery(int uid)
176 : OSQLQuery(), m_uid(uid ) {
177 }
178 FindQuery::~FindQuery() {
179 }
180 QString FindQuery::query()const{
181 QString qu = "select uid, categories, completed, progress, summary, ";
182 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid);
183 return qu;
184 }
185
186 OverDueQuery::OverDueQuery(): OSQLQuery() {}
187 OverDueQuery::~OverDueQuery() {}
188 QString OverDueQuery::query()const {
189 QDate date = QDate::currentDate();
190 QString str;
191 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
192
193 return str;
194 }
195
196
197 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
198 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
199 EffQuery::~EffQuery() {}
200 QString EffQuery::query()const {
201 return m_inc ? with() : out();
202 }
203 QString EffQuery::with()const {
204 QString str;
205 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
206 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
207 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
208 return str;
209 }
210 QString EffQuery::out()const {
211 QString str;
212 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
213 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
214 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
215
216 return str;
217 }
218};
219
220OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
221 : OTodoAccessBackend(), m_dict(15)
222{
223 QString fi = file;
224 if ( fi.isEmpty() )
225 fi = Global::applicationFileName( "todolist", "todolist.db" );
226 OSQLManager man;
227 m_driver = man.standard();
228 m_driver->setUrl(fi);
229 fillDict();
230}
231
232OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
233}
234bool OTodoAccessBackendSQL::load(){
235 if (!m_driver->open() )
236 return false;
237
238 CreateQuery creat;
239 OSQLResult res = m_driver->query(&creat );
240
241 update();
242 qWarning("loaded %d", m_uids.count() );
243 return true;
244}
245bool OTodoAccessBackendSQL::reload(){
246 return load();
247}
248
249bool OTodoAccessBackendSQL::save(){
250 return m_driver->close();
251}
252QArray<int> OTodoAccessBackendSQL::allRecords()const {
253 return m_uids;
254}
255QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
256 QArray<int> ints(0);
257 return ints;
258}
259OTodo OTodoAccessBackendSQL::find(int uid ) const{
260 FindQuery query( uid );
261 return todo( m_driver->query(&query) );
262
263}
264void OTodoAccessBackendSQL::clear() {
265 ClearQuery cle;
266 OSQLResult res = m_driver->query( &cle );
267 CreateQuery qu;
268 res = m_driver->query(&qu);
269}
270bool OTodoAccessBackendSQL::add( const OTodo& t) {
271 InsertQuery ins( t );
272 OSQLResult res = m_driver->query( &ins );
273
274 if ( res.state() == OSQLResult::Failure )
275 return false;
276 int c = m_uids.count();
277 m_uids.resize( c+1 );
278 m_uids[c] = t.uid();
279
280 return true;
281}
282bool OTodoAccessBackendSQL::remove( int uid ) {
283 RemoveQuery rem( uid );
284 OSQLResult res = m_driver->query(&rem );
285
286 if ( res.state() == OSQLResult::Failure )
287 return false;
288
289 update();
290 return true;
291}
292/*
293 * FIXME better set query
294 * but we need the cache for that
295 * now we remove
296 */
297bool OTodoAccessBackendSQL::replace( const OTodo& t) {
298 remove( t.uid() );
299 return add(t);
300}
301QArray<int> OTodoAccessBackendSQL::overDue() {
302 OverDueQuery qu;
303 return uids( m_driver->query(&qu ) );
304}
305QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s,
306 const QDate& t,
307 bool u) {
308 EffQuery ef(s, t, u );
309 return uids (m_driver->query(&ef) );
310}
311QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
312 int sortFilter, int cat ) {
313 QArray<int> ints(0);
314 return ints;
315}
316bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
317 if ( str == "0-0-0" )
318 return false;
319 else{
320 int day, year, month;
321 QStringList list = QStringList::split("-", str );
322 year = list[0].toInt();
323 month = list[1].toInt();
324 day = list[2].toInt();
325 da.setYMD( year, month, day );
326 return true;
327 }
328}
329OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
330 if ( res.state() == OSQLResult::Failure ) {
331 OTodo to;
332 return to;
333 }
334
335 OSQLResultItem::ValueList list = res.results();
336 OSQLResultItem::ValueList::Iterator it = list.begin();
337
338 bool has = false; QDate da = QDate::currentDate();
339 has = date( da, (*it).data("DueDate") );
340 QStringList cats = QStringList::split(";", (*it).data("categories") );
341
342 OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(),
343 cats, (*it).data("summary"), (*it).data("description"),
344 (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() );
345 return to;
346}
347OTodo OTodoAccessBackendSQL::todo( int uid )const {
348 FindQuery find( uid );
349 return todo( m_driver->query(&find) );
350}
351/*
352 * update the dict
353 */
354void OTodoAccessBackendSQL::fillDict() {
355 /* initialize dict */
356 /*
357 * UPDATE dict if you change anything!!!
358 */
359 m_dict.setAutoDelete( TRUE );
360 m_dict.insert("Categories" , new int(OTodo::Category) );
361 m_dict.insert("Uid" , new int(OTodo::Uid) );
362 m_dict.insert("HasDate" , new int(OTodo::HasDate) );
363 m_dict.insert("Completed" , new int(OTodo::Completed) );
364 m_dict.insert("Description" , new int(OTodo::Description) );
365 m_dict.insert("Summary" , new int(OTodo::Summary) );
366 m_dict.insert("Priority" , new int(OTodo::Priority) );
367 m_dict.insert("DateDay" , new int(OTodo::DateDay) );
368 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
369 m_dict.insert("DateYear" , new int(OTodo::DateYear) );
370 m_dict.insert("Progress" , new int(OTodo::Progress) );
371 m_dict.insert("Completed", new int(OTodo::Completed) );
372 m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
373 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
374 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
375}
376void OTodoAccessBackendSQL::update() {
377 LoadQuery lo;
378 OSQLResult res = m_driver->query(&lo);
379 if ( res.state() != OSQLResult::Success )
380 return;
381
382 m_uids = uids( res );
383}
384QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
385
386 OSQLResultItem::ValueList list = res.results();
387 OSQLResultItem::ValueList::Iterator it;
388 QArray<int> ints(list.count() );
389
390 int i = 0;
391 for (it = list.begin(); it != list.end(); ++it ) {
392 ints[i] = (*it).data("uid").toInt();
393 i++;
394 }
395 return ints;
396}
397
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h
new file mode 100644
index 0000000..966628d
--- a/dev/null
+++ b/libopie/pim/otodoaccesssql.h
@@ -0,0 +1,46 @@
1#ifndef OPIE_PIM_ACCESS_SQL_H
2#define OPIE_PIM_ACCESS_SQL_H
3
4#include <qasciidict.h>
5
6#include "otodoaccessbackend.h"
7
8class OSQLDriver;
9class OSQLResult;
10class OTodoAccessBackendSQL : public OTodoAccessBackend {
11public:
12 OTodoAccessBackendSQL( const QString& file );
13 ~OTodoAccessBackendSQL();
14
15 bool load();
16 bool reload();
17 bool save();
18 QArray<int> allRecords()const;
19
20 QArray<int> queryByExample( const OTodo& t, int sort );
21 OTodo find(int uid)const;
22 void clear();
23 bool add( const OTodo& t );
24 bool remove( int uid );
25 bool replace( const OTodo& t );
26
27 QArray<int> overDue();
28 QArray<int> effectiveToDos( const QDate& start,
29 const QDate& end, bool includeNoDates );
30 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
31
32private:
33 void update();
34 void fillDict();
35 bool date( QDate& date, const QString& )const;
36 OTodo todo( const OSQLResult& )const;
37 QArray<int> uids( const OSQLResult& )const;
38 OTodo todo( int uid )const;
39
40 QAsciiDict<int> m_dict;
41 OSQLDriver* m_driver;
42 QArray<int> m_uids;
43};
44
45
46#endif
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index 31822d4..80b8599 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,547 +1,548 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qvector.h> 2#include <qvector.h>
3 3
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qpe/stringutil.h> 5#include <qpe/stringutil.h>
6#include <qpe/timeconversion.h> 6#include <qpe/timeconversion.h>
7 7
8#include <opie/xmltree.h> 8#include <opie/xmltree.h>
9 9
10#include "otodoaccessxml.h" 10#include "otodoaccessxml.h"
11 11
12OTodoAccessXML::OTodoAccessXML( const QString& appName, 12OTodoAccessXML::OTodoAccessXML( const QString& appName,
13 const QString& fileName ) 13 const QString& fileName )
14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 14 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
15{ 15{
16 if (!fileName.isEmpty() ) 16 if (!fileName.isEmpty() )
17 m_file = fileName; 17 m_file = fileName;
18 else 18 else
19 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 19 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
20} 20}
21OTodoAccessXML::~OTodoAccessXML() { 21OTodoAccessXML::~OTodoAccessXML() {
22 22
23} 23}
24bool OTodoAccessXML::load() { 24bool OTodoAccessXML::load() {
25 m_opened = true; 25 m_opened = true;
26 m_changed = false; 26 m_changed = false;
27 /* initialize dict */ 27 /* initialize dict */
28 /* 28 /*
29 * UPDATE dict if you change anything!!! 29 * UPDATE dict if you change anything!!!
30 */ 30 */
31 QAsciiDict<int> dict(15); 31 QAsciiDict<int> dict(15);
32 dict.setAutoDelete( TRUE ); 32 dict.setAutoDelete( TRUE );
33 dict.insert("Categories" , new int(OTodo::Category) ); 33 dict.insert("Categories" , new int(OTodo::Category) );
34 dict.insert("Uid" , new int(OTodo::Uid) ); 34 dict.insert("Uid" , new int(OTodo::Uid) );
35 dict.insert("HasDate" , new int(OTodo::HasDate) ); 35 dict.insert("HasDate" , new int(OTodo::HasDate) );
36 dict.insert("Completed" , new int(OTodo::Completed) ); 36 dict.insert("Completed" , new int(OTodo::Completed) );
37 dict.insert("Description" , new int(OTodo::Description) ); 37 dict.insert("Description" , new int(OTodo::Description) );
38 dict.insert("Summary" , new int(OTodo::Summary) ); 38 dict.insert("Summary" , new int(OTodo::Summary) );
39 dict.insert("Priority" , new int(OTodo::Priority) ); 39 dict.insert("Priority" , new int(OTodo::Priority) );
40 dict.insert("DateDay" , new int(OTodo::DateDay) ); 40 dict.insert("DateDay" , new int(OTodo::DateDay) );
41 dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 41 dict.insert("DateMonth" , new int(OTodo::DateMonth) );
42 dict.insert("DateYear" , new int(OTodo::DateYear) ); 42 dict.insert("DateYear" , new int(OTodo::DateYear) );
43 dict.insert("Progress" , new int(OTodo::Progress) ); 43 dict.insert("Progress" , new int(OTodo::Progress) );
44 dict.insert("Completed", new int(OTodo::Completed) ); 44 dict.insert("Completed", new int(OTodo::Completed) );
45 dict.insert("CrossReference", new int(OTodo::CrossReference) ); 45 dict.insert("CrossReference", new int(OTodo::CrossReference) );
46 dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); 46 dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
47 dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); 47 dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
48 48
49 // here the custom XML parser from TT it's GPL 49 // here the custom XML parser from TT it's GPL
50 // but we want to push that to TT..... 50 // but we want to push that to TT.....
51 QFile f(m_file ); 51 QFile f(m_file );
52 if (!f.open(IO_ReadOnly) ) 52 if (!f.open(IO_ReadOnly) )
53 return false; 53 return false;
54 54
55 QByteArray ba = f.readAll(); 55 QByteArray ba = f.readAll();
56 f.close(); 56 f.close();
57 char* dt = ba.data(); 57 char* dt = ba.data();
58 int len = ba.size(); 58 int len = ba.size();
59 int i = 0; 59 int i = 0;
60 char *point; 60 char *point;
61 const char* collectionString = "<Task "; 61 const char* collectionString = "<Task ";
62 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 62 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
63 i = point -dt; 63 i = point -dt;
64 i+= strlen(collectionString); 64 i+= strlen(collectionString);
65 OTodo ev; 65 OTodo ev;
66 m_year = m_month = m_day = 0; 66 m_year = m_month = m_day = 0;
67 67
68 while ( TRUE ) { 68 while ( TRUE ) {
69 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 69 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
70 ++i; 70 ++i;
71 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 71 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
72 break; 72 break;
73 73
74 // we have another attribute, read it. 74 // we have another attribute, read it.
75 int j = i; 75 int j = i;
76 while ( j < len && dt[j] != '=' ) 76 while ( j < len && dt[j] != '=' )
77 ++j; 77 ++j;
78 QCString attr( dt+i, j-i+1); 78 QCString attr( dt+i, j-i+1);
79 79
80 i = ++j; // skip = 80 i = ++j; // skip =
81 81
82 // find the start of quotes 82 // find the start of quotes
83 while ( i < len && dt[i] != '"' ) 83 while ( i < len && dt[i] != '"' )
84 ++i; 84 ++i;
85 j = ++i; 85 j = ++i;
86 86
87 bool haveUtf = FALSE; 87 bool haveUtf = FALSE;
88 bool haveEnt = FALSE; 88 bool haveEnt = FALSE;
89 while ( j < len && dt[j] != '"' ) { 89 while ( j < len && dt[j] != '"' ) {
90 if ( ((unsigned char)dt[j]) > 0x7f ) 90 if ( ((unsigned char)dt[j]) > 0x7f )
91 haveUtf = TRUE; 91 haveUtf = TRUE;
92 if ( dt[j] == '&' ) 92 if ( dt[j] == '&' )
93 haveEnt = TRUE; 93 haveEnt = TRUE;
94 ++j; 94 ++j;
95 } 95 }
96 if ( i == j ) { 96 if ( i == j ) {
97 // empty value 97 // empty value
98 i = j + 1; 98 i = j + 1;
99 continue; 99 continue;
100 } 100 }
101 101
102 QCString value( dt+i, j-i+1 ); 102 QCString value( dt+i, j-i+1 );
103 i = j + 1; 103 i = j + 1;
104 104
105 QString str = (haveUtf ? QString::fromUtf8( value ) 105 QString str = (haveUtf ? QString::fromUtf8( value )
106 : QString::fromLatin1( value ) ); 106 : QString::fromLatin1( value ) );
107 if ( haveEnt ) 107 if ( haveEnt )
108 str = Qtopia::plainString( str ); 108 str = Qtopia::plainString( str );
109 109
110 /* 110 /*
111 * add key + value 111 * add key + value
112 */ 112 */
113 todo( &dict, ev, attr, str ); 113 todo( &dict, ev, attr, str );
114 114
115 } 115 }
116 /* 116 /*
117 * now add it 117 * now add it
118 */ 118 */
119 m_events.insert(ev.uid(), ev ); 119 m_events.insert(ev.uid(), ev );
120 } 120 }
121 121
122 qWarning("counts %d", m_events.count() );
122 return true; 123 return true;
123} 124}
124bool OTodoAccessXML::reload() { 125bool OTodoAccessXML::reload() {
125 return load(); 126 return load();
126} 127}
127bool OTodoAccessXML::save() { 128bool OTodoAccessXML::save() {
128// qWarning("saving"); 129// qWarning("saving");
129 if (!m_opened || !m_changed ) { 130 if (!m_opened || !m_changed ) {
130// qWarning("not saving"); 131// qWarning("not saving");
131 return true; 132 return true;
132 } 133 }
133 QString strNewFile = m_file + ".new"; 134 QString strNewFile = m_file + ".new";
134 QFile f( strNewFile ); 135 QFile f( strNewFile );
135 if (!f.open( IO_WriteOnly|IO_Raw ) ) 136 if (!f.open( IO_WriteOnly|IO_Raw ) )
136 return false; 137 return false;
137 138
138 int written; 139 int written;
139 QString out; 140 QString out;
140 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 141 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
141 142
142 // for all todos 143 // for all todos
143 QMap<int, OTodo>::Iterator it; 144 QMap<int, OTodo>::Iterator it;
144 for (it = m_events.begin(); it != m_events.end(); ++it ) { 145 for (it = m_events.begin(); it != m_events.end(); ++it ) {
145 out+= "<Task " + toString( (*it) ) + " />\n"; 146 out+= "<Task " + toString( (*it) ) + " />\n";
146 QCString cstr = out.utf8(); 147 QCString cstr = out.utf8();
147 written = f.writeBlock( cstr.data(), cstr.length() ); 148 written = f.writeBlock( cstr.data(), cstr.length() );
148 149
149 /* less written then we wanted */ 150 /* less written then we wanted */
150 if ( written != (int)cstr.length() ) { 151 if ( written != (int)cstr.length() ) {
151 f.close(); 152 f.close();
152 QFile::remove( strNewFile ); 153 QFile::remove( strNewFile );
153 return false; 154 return false;
154 } 155 }
155 out = QString::null; 156 out = QString::null;
156 } 157 }
157 158
158 out += "</Tasks>"; 159 out += "</Tasks>";
159 QCString cstr = out.utf8(); 160 QCString cstr = out.utf8();
160 written = f.writeBlock( cstr.data(), cstr.length() ); 161 written = f.writeBlock( cstr.data(), cstr.length() );
161 162
162 if ( written != (int)cstr.length() ) { 163 if ( written != (int)cstr.length() ) {
163 f.close(); 164 f.close();
164 QFile::remove( strNewFile ); 165 QFile::remove( strNewFile );
165 return false; 166 return false;
166 } 167 }
167 /* flush before renaming */ 168 /* flush before renaming */
168 f.close(); 169 f.close();
169 170
170 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 171 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
171// qWarning("error renaming"); 172// qWarning("error renaming");
172 QFile::remove( strNewFile ); 173 QFile::remove( strNewFile );
173 } 174 }
174 175
175 m_changed = false; 176 m_changed = false;
176 return true; 177 return true;
177} 178}
178QArray<int> OTodoAccessXML::allRecords()const { 179QArray<int> OTodoAccessXML::allRecords()const {
179 QArray<int> ids( m_events.count() ); 180 QArray<int> ids( m_events.count() );
180 QMap<int, OTodo>::ConstIterator it; 181 QMap<int, OTodo>::ConstIterator it;
181 int i = 0; 182 int i = 0;
182 183
183 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 184 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
184 ids[i] = it.key(); 185 ids[i] = it.key();
185 i++; 186 i++;
186 } 187 }
187 return ids; 188 return ids;
188} 189}
189QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) { 190QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int sort ) {
190 QArray<int> ids(0); 191 QArray<int> ids(0);
191 return ids; 192 return ids;
192} 193}
193OTodo OTodoAccessXML::find( int uid )const { 194OTodo OTodoAccessXML::find( int uid )const {
194 OTodo todo; 195 OTodo todo;
195 todo.setUid( 0 ); // isEmpty() 196 todo.setUid( 0 ); // isEmpty()
196 QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); 197 QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
197 if ( it != m_events.end() ) 198 if ( it != m_events.end() )
198 todo = it.data(); 199 todo = it.data();
199 200
200 return todo; 201 return todo;
201} 202}
202void OTodoAccessXML::clear() { 203void OTodoAccessXML::clear() {
203 if (m_opened ) 204 if (m_opened )
204 m_changed = true; 205 m_changed = true;
205 206
206 m_events.clear(); 207 m_events.clear();
207} 208}
208bool OTodoAccessXML::add( const OTodo& todo ) { 209bool OTodoAccessXML::add( const OTodo& todo ) {
209// qWarning("add"); 210// qWarning("add");
210 m_changed = true; 211 m_changed = true;
211 m_events.insert( todo.uid(), todo ); 212 m_events.insert( todo.uid(), todo );
212 213
213 return true; 214 return true;
214} 215}
215bool OTodoAccessXML::remove( int uid ) { 216bool OTodoAccessXML::remove( int uid ) {
216 m_changed = true; 217 m_changed = true;
217 m_events.remove( uid ); 218 m_events.remove( uid );
218 219
219 return true; 220 return true;
220} 221}
221bool OTodoAccessXML::replace( const OTodo& todo) { 222bool OTodoAccessXML::replace( const OTodo& todo) {
222 m_changed = true; 223 m_changed = true;
223 m_events.replace( todo.uid(), todo ); 224 m_events.replace( todo.uid(), todo );
224 225
225 return true; 226 return true;
226} 227}
227QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, 228QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
228 const QDate& end, 229 const QDate& end,
229 bool includeNoDates ) { 230 bool includeNoDates ) {
230 QArray<int> ids( m_events.count() ); 231 QArray<int> ids( m_events.count() );
231 QMap<int, OTodo>::Iterator it; 232 QMap<int, OTodo>::Iterator it;
232 233
233 int i = 0; 234 int i = 0;
234 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 235 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
235 if ( !it.data().hasDueDate() ) { 236 if ( !it.data().hasDueDate() ) {
236 if ( includeNoDates ) { 237 if ( includeNoDates ) {
237 ids[i] = it.key(); 238 ids[i] = it.key();
238 i++; 239 i++;
239 } 240 }
240 }else if ( it.data().dueDate() >= start && 241 }else if ( it.data().dueDate() >= start &&
241 it.data().dueDate() <= end ) { 242 it.data().dueDate() <= end ) {
242 ids[i] = it.key(); 243 ids[i] = it.key();
243 i++; 244 i++;
244 } 245 }
245 } 246 }
246 ids.resize( i ); 247 ids.resize( i );
247 return ids; 248 return ids;
248} 249}
249QArray<int> OTodoAccessXML::overDue() { 250QArray<int> OTodoAccessXML::overDue() {
250 QArray<int> ids( m_events.count() ); 251 QArray<int> ids( m_events.count() );
251 int i = 0; 252 int i = 0;
252 253
253 QMap<int, OTodo>::Iterator it; 254 QMap<int, OTodo>::Iterator it;
254 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 255 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
255 if ( it.data().isOverdue() ) { 256 if ( it.data().isOverdue() ) {
256 ids[i] = it.key(); 257 ids[i] = it.key();
257 i++; 258 i++;
258 } 259 }
259 } 260 }
260 ids.resize( i ); 261 ids.resize( i );
261 return ids; 262 return ids;
262} 263}
263 264
264 265
265/* private */ 266/* private */
266void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, 267void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
267 const QCString& attr, const QString& val) { 268 const QCString& attr, const QString& val) {
268// qWarning("parse to do from XMLElement" ); 269// qWarning("parse to do from XMLElement" );
269 270
270 int *find=0; 271 int *find=0;
271 272
272 find = (*dict)[ attr.data() ]; 273 find = (*dict)[ attr.data() ];
273 if (!find ) { 274 if (!find ) {
274// qWarning("Unknown option" + it.key() ); 275// qWarning("Unknown option" + it.key() );
275 ev.setCustomField( attr, val ); 276 ev.setCustomField( attr, val );
276 return; 277 return;
277 } 278 }
278 279
279 switch( *find ) { 280 switch( *find ) {
280 case OTodo::Uid: 281 case OTodo::Uid:
281 ev.setUid( val.toInt() ); 282 ev.setUid( val.toInt() );
282 break; 283 break;
283 case OTodo::Category: 284 case OTodo::Category:
284 ev.setCategories( ev.idsFromString( val ) ); 285 ev.setCategories( ev.idsFromString( val ) );
285 break; 286 break;
286 case OTodo::HasDate: 287 case OTodo::HasDate:
287 ev.setHasDueDate( val.toInt() ); 288 ev.setHasDueDate( val.toInt() );
288 break; 289 break;
289 case OTodo::Completed: 290 case OTodo::Completed:
290 ev.setCompleted( val.toInt() ); 291 ev.setCompleted( val.toInt() );
291 break; 292 break;
292 case OTodo::Description: 293 case OTodo::Description:
293 ev.setDescription( val ); 294 ev.setDescription( val );
294 break; 295 break;
295 case OTodo::Summary: 296 case OTodo::Summary:
296 ev.setSummary( val ); 297 ev.setSummary( val );
297 break; 298 break;
298 case OTodo::Priority: 299 case OTodo::Priority:
299 ev.setPriority( val.toInt() ); 300 ev.setPriority( val.toInt() );
300 break; 301 break;
301 case OTodo::DateDay: 302 case OTodo::DateDay:
302 m_day = val.toInt(); 303 m_day = val.toInt();
303 break; 304 break;
304 case OTodo::DateMonth: 305 case OTodo::DateMonth:
305 m_month = val.toInt(); 306 m_month = val.toInt();
306 break; 307 break;
307 case OTodo::DateYear: 308 case OTodo::DateYear:
308 m_year = val.toInt(); 309 m_year = val.toInt();
309 break; 310 break;
310 case OTodo::Progress: 311 case OTodo::Progress:
311 ev.setProgress( val.toInt() ); 312 ev.setProgress( val.toInt() );
312 break; 313 break;
313 case OTodo::CrossReference: 314 case OTodo::CrossReference:
314 { 315 {
315 /* 316 /*
316 * A cross refernce looks like 317 * A cross refernce looks like
317 * appname,id;appname,id 318 * appname,id;appname,id
318 * we need to split it up 319 * we need to split it up
319 */ 320 */
320 QStringList refs = QStringList::split(';', val ); 321 QStringList refs = QStringList::split(';', val );
321 QStringList::Iterator strIt; 322 QStringList::Iterator strIt;
322 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { 323 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
323 int pos = (*strIt).find(','); 324 int pos = (*strIt).find(',');
324 if ( pos > -1 ) 325 if ( pos > -1 )
325 ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); 326 ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
326 327
327 } 328 }
328 break; 329 break;
329 } 330 }
330 case OTodo::HasAlarmDateTime: 331 case OTodo::HasAlarmDateTime:
331 ev.setHasAlarmDateTime( val.toInt() ); 332 ev.setHasAlarmDateTime( val.toInt() );
332 break; 333 break;
333 case OTodo::AlarmDateTime: { 334 case OTodo::AlarmDateTime: {
334 /* this sounds better ;) zecke */ 335 /* this sounds better ;) zecke */
335 ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) ); 336 ev.setAlarmDateTime( TimeConversion::fromISO8601( val.local8Bit() ) );
336 break; 337 break;
337 } 338 }
338 default: 339 default:
339 break; 340 break;
340 } 341 }
341 342
342 if ( ev.hasDueDate() ) { 343 if ( ev.hasDueDate() ) {
343 QDate date( m_year, m_month, m_day ); 344 QDate date( m_year, m_month, m_day );
344 ev.setDueDate( date ); 345 ev.setDueDate( date );
345 } 346 }
346} 347}
347QString OTodoAccessXML::toString( const OTodo& ev )const { 348QString OTodoAccessXML::toString( const OTodo& ev )const {
348 QString str; 349 QString str;
349 350
350 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; 351 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
351 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; 352 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
352 str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; 353 str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
353 str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; 354 str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
354 355
355 str += "Categories=\"" + toString( ev.categories() ) + "\" "; 356 str += "Categories=\"" + toString( ev.categories() ) + "\" ";
356 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; 357 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
357 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; 358 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
358 359
359 if ( ev.hasDueDate() ) { 360 if ( ev.hasDueDate() ) {
360 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 361 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
361 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; 362 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
362 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; 363 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
363 } 364 }
364// qWarning( "Uid %d", ev.uid() ); 365// qWarning( "Uid %d", ev.uid() );
365 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 366 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
366 367
367// append the extra options 368// append the extra options
368 /* FIXME Qtopia::Record this is currently not 369 /* FIXME Qtopia::Record this is currently not
369 * possible you can set custom fields 370 * possible you can set custom fields
370 * but don' iterate over the list 371 * but don' iterate over the list
371 * I may do #define private protected 372 * I may do #define private protected
372 * for this case - cough --zecke 373 * for this case - cough --zecke
373 */ 374 */
374 /* 375 /*
375 QMap<QString, QString> extras = ev.extras(); 376 QMap<QString, QString> extras = ev.extras();
376 QMap<QString, QString>::Iterator extIt; 377 QMap<QString, QString>::Iterator extIt;
377 for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) 378 for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
378 str += extIt.key() + "=\"" + extIt.data() + "\" "; 379 str += extIt.key() + "=\"" + extIt.data() + "\" ";
379 */ 380 */
380 // cross refernce 381 // cross refernce
381 QStringList list = ev.relatedApps(); 382 QStringList list = ev.relatedApps();
382 QStringList::Iterator listIt; 383 QStringList::Iterator listIt;
383 QString refs; 384 QString refs;
384 str += "CrossReference=\""; 385 str += "CrossReference=\"";
385 bool added = false; 386 bool added = false;
386 for ( listIt = list.begin(); listIt != list.end(); ++listIt ) { 387 for ( listIt = list.begin(); listIt != list.end(); ++listIt ) {
387 added = true; 388 added = true;
388 QArray<int> ints = ev.relations( (*listIt) ); 389 QArray<int> ints = ev.relations( (*listIt) );
389 for ( uint i = 0; i< ints.count(); i++ ) { 390 for ( uint i = 0; i< ints.count(); i++ ) {
390 str += (*listIt) + "," + QString::number( i ) + ";"; 391 str += (*listIt) + "," + QString::number( i ) + ";";
391 } 392 }
392 } 393 }
393 if ( added ) 394 if ( added )
394 str = str.remove( str.length()-1, 1 ); 395 str = str.remove( str.length()-1, 1 );
395 396
396 str += "\" "; 397 str += "\" ";
397 398
398 str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" "; 399 str += "AlarmDateTime=\"" + TimeConversion::toISO8601( ev.alarmDateTime() ) + "\" ";
399 400
400 return str; 401 return str;
401} 402}
402QString OTodoAccessXML::toString( const QArray<int>& ints ) const { 403QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
403 return Qtopia::Record::idsToString( ints ); 404 return Qtopia::Record::idsToString( ints );
404} 405}
405 406
406/* internal class for sorting */ 407/* internal class for sorting */
407 408
408struct OTodoXMLContainer { 409struct OTodoXMLContainer {
409 OTodo todo; 410 OTodo todo;
410}; 411};
411 /* 412 /*
412 * Returns: 413 * Returns:
413 * 0 if item1 == item2 414 * 0 if item1 == item2
414 * 415 *
415 * non-zero if item1 != item2 416 * non-zero if item1 != item2
416 * 417 *
417 * This function returns int rather than bool so that reimplementations 418 * This function returns int rather than bool so that reimplementations
418 * can return one of three values and use it to sort by: 419 * can return one of three values and use it to sort by:
419 * 420 *
420 * 0 if item1 == item2 421 * 0 if item1 == item2
421 * 422 *
422 * > 0 (positive integer) if item1 > item2 423 * > 0 (positive integer) if item1 > item2
423 * 424 *
424 * < 0 (negative integer) if item1 < item2 425 * < 0 (negative integer) if item1 < item2
425 * 426 *
426 */ 427 */
427class OTodoXMLVector : public QVector<OTodoXMLContainer> { 428class OTodoXMLVector : public QVector<OTodoXMLContainer> {
428public: 429public:
429 OTodoXMLVector(int size, bool asc, int sort) 430 OTodoXMLVector(int size, bool asc, int sort)
430 : QVector<OTodoXMLContainer>( size ) 431 : QVector<OTodoXMLContainer>( size )
431 { 432 {
432 setAutoDelete( true ); 433 setAutoDelete( true );
433 m_asc = asc; 434 m_asc = asc;
434 m_sort = sort; 435 m_sort = sort;
435 } 436 }
436 /* return the summary/description */ 437 /* return the summary/description */
437 QString string( const OTodo& todo) { 438 QString string( const OTodo& todo) {
438 return todo.summary().isEmpty() ? 439 return todo.summary().isEmpty() ?
439 todo.description().left(20 ) : 440 todo.description().left(20 ) :
440 todo.summary(); 441 todo.summary();
441 } 442 }
442 /** 443 /**
443 * we take the sortorder( switch on it ) 444 * we take the sortorder( switch on it )
444 * 445 *
445 */ 446 */
446 int compareItems( Item d1, Item d2 ) { 447 int compareItems( Item d1, Item d2 ) {
447 qWarning("compare items"); 448 qWarning("compare items");
448 int ret =0; 449 int ret =0;
449 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; 450 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
450 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; 451 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
451 452
452 /* same item */ 453 /* same item */
453 if ( con1->todo.uid() == con2->todo.uid() ) 454 if ( con1->todo.uid() == con2->todo.uid() )
454 return 0; 455 return 0;
455 qWarning("m_sort %d", m_sort ); 456 qWarning("m_sort %d", m_sort );
456 457
457 switch ( m_sort ) { 458 switch ( m_sort ) {
458 /* completed */ 459 /* completed */
459 case 0: { 460 case 0: {
460 ret = 0; 461 ret = 0;
461 if ( con1->todo.isCompleted() ) ret++; 462 if ( con1->todo.isCompleted() ) ret++;
462 if ( con2->todo.isCompleted() ) ret--; 463 if ( con2->todo.isCompleted() ) ret--;
463 break; 464 break;
464 } 465 }
465 /* priority */ 466 /* priority */
466 case 1: { 467 case 1: {
467 ret = con1->todo.priority() - con2->todo.priority(); 468 ret = con1->todo.priority() - con2->todo.priority();
468 qWarning(" priority %d %d %d", ret, 469 qWarning(" priority %d %d %d", ret,
469 con1->todo.priority(), 470 con1->todo.priority(),
470 con2->todo.priority() 471 con2->todo.priority()
471 ); 472 );
472 break; 473 break;
473 } 474 }
474 /* description */ 475 /* description */
475 case 2: { 476 case 2: {
476 QString str1 = string( con1->todo ); 477 QString str1 = string( con1->todo );
477 QString str2 = string( con2->todo ); 478 QString str2 = string( con2->todo );
478 ret = QString::compare( str1, str2 ); 479 ret = QString::compare( str1, str2 );
479 break; 480 break;
480 } 481 }
481 /* deadline */ 482 /* deadline */
482 case 3: { 483 case 3: {
483 /* either bot got a dueDate 484 /* either bot got a dueDate
484 * or one of them got one 485 * or one of them got one
485 */ 486 */
486 if ( con1->todo.hasDueDate() && 487 if ( con1->todo.hasDueDate() &&
487 con2->todo.hasDueDate() ) 488 con2->todo.hasDueDate() )
488 ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); 489 ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() );
489 else if ( con1->todo.hasDueDate() ) 490 else if ( con1->todo.hasDueDate() )
490 ret = -1; 491 ret = -1;
491 else if ( con2->todo.hasDueDate() ) 492 else if ( con2->todo.hasDueDate() )
492 ret = 0; 493 ret = 0;
493 break; 494 break;
494 } 495 }
495 default: 496 default:
496 ret = 0; 497 ret = 0;
497 break; 498 break;
498 }; 499 };
499 500
500 /* twist it we're not ascending*/ 501 /* twist it we're not ascending*/
501 if (!m_asc) 502 if (!m_asc)
502 ret = ret * -1; 503 ret = ret * -1;
503 return ret; 504 return ret;
504 } 505 }
505 private: 506 private:
506 bool m_asc; 507 bool m_asc;
507 int m_sort; 508 int m_sort;
508 509
509}; 510};
510 511
511QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, 512QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
512 int sortFilter, int cat ) { 513 int sortFilter, int cat ) {
513 OTodoXMLVector vector(m_events.count(), asc,sortOrder ); 514 OTodoXMLVector vector(m_events.count(), asc,sortOrder );
514 QMap<int, OTodo>::Iterator it; 515 QMap<int, OTodo>::Iterator it;
515 int item = 0; 516 int item = 0;
516 517
517 bool bCat = sortFilter & 1 ? true : false; 518 bool bCat = sortFilter & 1 ? true : false;
518 bool bOver = sortFilter & 0 ? true : false; 519 bool bOver = sortFilter & 0 ? true : false;
519 bool bOnly = sortFilter & 2 ? true : false; 520 bool bOnly = sortFilter & 2 ? true : false;
520 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 521 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
521 522
522 /* show category */ 523 /* show category */
523 if ( bCat ) 524 if ( bCat )
524 if (!(*it).categories().contains( cat ) ) 525 if (!(*it).categories().contains( cat ) )
525 continue; 526 continue;
526 /* isOverdue but we should not show overdue */ 527 /* isOverdue but we should not show overdue */
527 if ( (*it).isOverdue() && ( !bOver || !bOnly ) ) 528 if ( (*it).isOverdue() && ( !bOver || !bOnly ) )
528 continue; 529 continue;
529 if ( !(*it).isOverdue() && bOnly ) 530 if ( !(*it).isOverdue() && bOnly )
530 continue; 531 continue;
531 532
532 533
533 OTodoXMLContainer* con = new OTodoXMLContainer(); 534 OTodoXMLContainer* con = new OTodoXMLContainer();
534 con->todo = (*it); 535 con->todo = (*it);
535 vector.insert(item, con ); 536 vector.insert(item, con );
536 item++; 537 item++;
537 } 538 }
538 vector.resize( item ); 539 vector.resize( item );
539 /* sort it now */ 540 /* sort it now */
540 vector.sort(); 541 vector.sort();
541 /* now get the uids */ 542 /* now get the uids */
542 QArray<int> array( vector.count() ); 543 QArray<int> array( vector.count() );
543 for (uint i= 0; i < vector.count(); i++ ) { 544 for (uint i= 0; i < vector.count(); i++ ) {
544 array[i] = ( vector.at(i) )->todo.uid(); 545 array[i] = ( vector.at(i) )->todo.uid();
545 } 546 }
546 return array; 547 return array;
547}; 548};