summaryrefslogtreecommitdiff
path: root/libopie/pim
Unidiff
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/libopie.pro6
-rw-r--r--libopie/pim/orecordlist.h2
-rw-r--r--libopie/pim/orecur.cpp127
-rw-r--r--libopie/pim/orecur.h54
-rw-r--r--libopie/pim/otodoaccesssql.cpp2
5 files changed, 188 insertions, 3 deletions
diff --git a/libopie/pim/libopie.pro b/libopie/pim/libopie.pro
index 1dacbe7..b871374 100644
--- a/libopie/pim/libopie.pro
+++ b/libopie/pim/libopie.pro
@@ -1,75 +1,77 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qte warn_on release 2CONFIG += qte warn_on release
3HEADERS = ofontmenu.h \ 3HEADERS = ofontmenu.h \
4 tododb.h \ 4 tododb.h \
5 todoevent.h todoresource.h \ 5 todoevent.h todoresource.h \
6 todovcalresource.h xmltree.h \ 6 todovcalresource.h xmltree.h \
7 colordialog.h colorpopupmenu.h \ 7 colordialog.h colorpopupmenu.h \
8 oclickablelabel.h oprocctrl.h \ 8 oclickablelabel.h oprocctrl.h \
9 oprocess.h odevice.h \ 9 oprocess.h odevice.h \
10 otimepicker.h otabwidget.h \ 10 otimepicker.h otabwidget.h \
11 otabbar.h otabinfo.h \ 11 otabbar.h otabinfo.h \
12 ofileselector/ofiledialog.h \ 12 ofileselector/ofiledialog.h \
13 ofileselector/ofilelistview.h \ 13 ofileselector/ofilelistview.h \
14 ofileselector/ofileselector.h \ 14 ofileselector/ofileselector.h \
15 ofileselector/ofileselectoritem.h \ 15 ofileselector/ofileselectoritem.h \
16 ofileselector/ofileview.h \ 16 ofileselector/ofileview.h \
17 ofileselector/olister.h \ 17 ofileselector/olister.h \
18 ofileselector/olocallister.h \ 18 ofileselector/olocallister.h \
19 ofileselector/ofileselectormain.h \ 19 ofileselector/ofileselectormain.h \
20 pim/opimrecord.h \ 20 pim/opimrecord.h \
21 pim/otodo.h \ 21 pim/otodo.h \
22 pim/orecordlist.h \ 22 pim/orecordlist.h \
23 pim/opimaccesstemplate.h \ 23 pim/opimaccesstemplate.h \
24 pim/opimaccessbackend.h \ 24 pim/opimaccessbackend.h \
25 pim/otodoaccess.h \ 25 pim/otodoaccess.h \
26 pim/otodacessbackend.h \ 26 pim/otodacessbackend.h \
27 pim/ocontact.h \ 27 pim/ocontact.h \
28 pim/ocontactaccess.h \ 28 pim/ocontactaccess.h \
29 pim/ocontactaccessbackend.h \ 29 pim/ocontactaccessbackend.h \
30 pim/ocontactaccessbackend_xml.h 30 pim/ocontactaccessbackend_xml.h \
31 pim/orecord.h
31 32
32SOURCES = ofontmenu.cc \ 33SOURCES = ofontmenu.cc \
33 xmltree.cc \ 34 xmltree.cc \
34 tododb.cpp todoevent.cpp \ 35 tododb.cpp todoevent.cpp \
35 todovcalresource.cpp colordialog.cpp \ 36 todovcalresource.cpp colordialog.cpp \
36 colorpopupmenu.cpp oclickablelabel.cpp \ 37 colorpopupmenu.cpp oclickablelabel.cpp \
37 oprocctrl.cpp oprocess.cpp \ 38 oprocctrl.cpp oprocess.cpp \
38 odevice.cpp otimepicker.cpp \ 39 odevice.cpp otimepicker.cpp \
39 otabwidget.cpp otabbar.cpp \ 40 otabwidget.cpp otabbar.cpp \
40 ofileselector/ofiledialog.cpp \ 41 ofileselector/ofiledialog.cpp \
41 ofileselector/ofilelistview.cpp \ 42 ofileselector/ofilelistview.cpp \
42 ofileselector/ofileselector.cpp \ 43 ofileselector/ofileselector.cpp \
43 ofileselector/ofileselectoritem.cpp \ 44 ofileselector/ofileselectoritem.cpp \
44 ofileselector/ofileview.cpp \ 45 ofileselector/ofileview.cpp \
45 ofileselector/olister.cpp \ 46 ofileselector/olister.cpp \
46 ofileselector/olocallister.cpp \ 47 ofileselector/olocallister.cpp \
47 ofileselector/ofileselectormain.cpp \ 48 ofileselector/ofileselectormain.cpp \
48 pim/otodo.cpp \ 49 pim/otodo.cpp \
49 pim/opimrecord.cpp \ 50 pim/opimrecord.cpp \
50 pim/otodoaccess.cpp \ 51 pim/otodoaccess.cpp \
51 pim/otodoaccessbackend.cpp \ 52 pim/otodoaccessbackend.cpp \
52 pim/ocontact.cpp \ 53 pim/ocontact.cpp \
53 pim/ocontactaccess.cpp 54 pim/ocontactaccess.cpp \
55 pim/orecord.cpp
54 56
55TARGET = opie 57TARGET = opie
56INCLUDEPATH += $(OPIEDIR)/include 58INCLUDEPATH += $(OPIEDIR)/include
57DESTDIR = $(QTDIR)/lib$(PROJMAK) 59DESTDIR = $(QTDIR)/lib$(PROJMAK)
58#VERSION = 1.0.0 60#VERSION = 1.0.0
59 61
60INTERFACES = otimepickerbase.ui 62INTERFACES = otimepickerbase.ui
61 63
62TRANSLATIONS = ../i18n/de/libopie.ts \ 64TRANSLATIONS = ../i18n/de/libopie.ts \
63 ../i18n/en/libopie.ts \ 65 ../i18n/en/libopie.ts \
64 ../i18n/es/libopie.ts \ 66 ../i18n/es/libopie.ts \
65 ../i18n/fr/libopie.ts \ 67 ../i18n/fr/libopie.ts \
66 ../i18n/hu/libopie.ts \ 68 ../i18n/hu/libopie.ts \
67 ../i18n/ja/libopie.ts \ 69 ../i18n/ja/libopie.ts \
68 ../i18n/ko/libopie.ts \ 70 ../i18n/ko/libopie.ts \
69 ../i18n/no/libopie.ts \ 71 ../i18n/no/libopie.ts \
70 ../i18n/pl/libopie.ts \ 72 ../i18n/pl/libopie.ts \
71 ../i18n/pt/libopie.ts \ 73 ../i18n/pt/libopie.ts \
72 ../i18n/pt_BR/libopie.ts \ 74 ../i18n/pt_BR/libopie.ts \
73 ../i18n/sl/libopie.ts \ 75 ../i18n/sl/libopie.ts \
74 ../i18n/zh_CN/libopie.ts \ 76 ../i18n/zh_CN/libopie.ts \
75 ../i18n/zh_TW/libopie.ts 77 ../i18n/zh_TW/libopie.ts
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index 5404910..e377447 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -1,270 +1,272 @@
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 bool m_direction :1; 71 bool m_direction :1;
72 72
73 /* d pointer for future versions */ 73 /* d pointer for future versions */
74 class IteratorPrivate; 74 class IteratorPrivate;
75 IteratorPrivate *d; 75 IteratorPrivate *d;
76}; 76};
77/** 77/**
78 * The recordlist used as a return type 78 * The recordlist used as a return type
79 * from OPimAccessTemplate 79 * from OPimAccessTemplate
80 */ 80 */
81template <class T = OPimRecord > 81template <class T = OPimRecord >
82class ORecordList { 82class ORecordList {
83public: 83public:
84 typedef OTemplateBase<T> Base; 84 typedef OTemplateBase<T> Base;
85 typedef ORecordListIterator<T> Iterator; 85 typedef ORecordListIterator<T> Iterator;
86 86
87 /** 87 /**
88 * c'tor 88 * c'tor
89 */ 89 */
90 ORecordList () { 90 ORecordList () {
91 } 91 }
92 ORecordList( const QArray<int>& ids, 92 ORecordList( const QArray<int>& ids,
93 const Base* ); 93 const Base* );
94 ~ORecordList(); 94 ~ORecordList();
95 95
96 /** 96 /**
97 * the first iterator 97 * the first iterator
98 */ 98 */
99 Iterator begin(); 99 Iterator begin();
100 100
101 /** 101 /**
102 * the end 102 * the end
103 */ 103 */
104 Iterator end(); 104 Iterator end();
105 105
106 /** 106 /**
107 * the number of items in the list 107 * the number of items in the list
108 */ 108 */
109 uint count()const; 109 uint count()const;
110 110
111 T operator[]( uint i ); 111 T operator[]( uint i );
112 int uidAt(uint i ); 112 int uidAt(uint i );
113 // FIXME implemenent remove 113 // FIXME implemenent remove
114 /* 114 /*
115 ConstIterator begin()const; 115 ConstIterator begin()const;
116 ConstIterator end()const; 116 ConstIterator end()const;
117 */ 117 */
118private: 118private:
119 QArray<int> m_ids; 119 QArray<int> m_ids;
120 const Base* m_acc; 120 const Base* m_acc;
121}; 121};
122 122
123/* ok now implement it */ 123/* ok now implement it */
124template <class T> 124template <class T>
125ORecordListIterator<T>::ORecordListIterator() { 125ORecordListIterator<T>::ORecordListIterator() {
126 m_current = 0; 126 m_current = 0;
127 m_temp = 0l; 127 m_temp = 0l;
128 m_end = true; 128 m_end = true;
129 m_record = T(); 129 m_record = T();
130 /* forward */ 130 /* forward */
131 m_direction = TRUE; 131 m_direction = TRUE;
132} 132}
133template <class T> 133template <class T>
134ORecordListIterator<T>::~ORecordListIterator() { 134ORecordListIterator<T>::~ORecordListIterator() {
135/* nothing to delete */ 135/* nothing to delete */
136} 136}
137 137
138template <class T> 138template <class T>
139ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 139ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
140// qWarning("ORecordListIterator copy c'tor"); 140// qWarning("ORecordListIterator copy c'tor");
141 m_uids = it.m_uids; 141 m_uids = it.m_uids;
142 m_current = it.m_current; 142 m_current = it.m_current;
143 m_temp = it.m_temp; 143 m_temp = it.m_temp;
144 m_end = it.m_end; 144 m_end = it.m_end;
145 m_record = it.m_record; 145 m_record = it.m_record;
146 m_direction = it.m_direction; 146 m_direction = it.m_direction;
147} 147}
148 148
149template <class T> 149template <class T>
150ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 150ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
151 m_uids = it.m_uids; 151 m_uids = it.m_uids;
152 m_current = it.m_current; 152 m_current = it.m_current;
153 m_temp = it.m_temp; 153 m_temp = it.m_temp;
154 m_end = it.m_end; 154 m_end = it.m_end;
155 m_record = it.m_record; 155 m_record = it.m_record;
156 156
157 return *this; 157 return *this;
158} 158}
159 159
160template <class T> 160template <class T>
161T ORecordListIterator<T>::operator*() { 161T ORecordListIterator<T>::operator*() {
162 qWarning("operator* %d %d", m_current, m_uids[m_current] ); 162 qWarning("operator* %d %d", m_current, m_uids[m_current] );
163 if (!m_end ) 163 if (!m_end )
164 m_record = m_temp->find( m_uids[m_current], m_uids, m_current, 164 m_record = m_temp->find( m_uids[m_current], m_uids, m_current,
165 m_direction ? Base::Forward : 165 m_direction ? Base::Forward :
166 Base::Reverse ); 166 Base::Reverse );
167 else 167 else
168 m_record = T(); 168 m_record = T();
169 169
170 return m_record; 170 return m_record;
171} 171}
172 172
173template <class T> 173template <class T>
174ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 174ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
175 m_direction = true; 175 m_direction = true;
176 if (m_current < m_uids.count() ) { 176 if (m_current < m_uids.count() ) {
177 m_end = false; 177 m_end = false;
178 ++m_current; 178 ++m_current;
179 }else 179 }else
180 m_end = true; 180 m_end = true;
181 181
182 return *this; 182 return *this;
183} 183}
184template <class T> 184template <class T>
185ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 185ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
186 m_direction = false; 186 m_direction = false;
187 if ( m_current > 0 ) { 187 if ( m_current > 0 ) {
188 --m_current; 188 --m_current;
189 m_end = false; 189 m_end = false;
190 } else 190 } else
191 m_end = true; 191 m_end = true;
192 192
193 return *this; 193 return *this;
194} 194}
195 195
196template <class T> 196template <class T>
197bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 197bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
198 198
199 /* if both are at we're the same.... */ 199 /* if both are at we're the same.... */
200 if ( m_end == it.m_end ) return true; 200 if ( m_end == it.m_end ) return true;
201 201
202 if ( m_uids != it.m_uids ) return false; 202 if ( m_uids != it.m_uids ) return false;
203 if ( m_current != it.m_current ) return false; 203 if ( m_current != it.m_current ) return false;
204 if ( m_temp != it.m_temp ) return false; 204 if ( m_temp != it.m_temp ) return false;
205 205
206 return true; 206 return true;
207} 207}
208template <class T> 208template <class T>
209bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 209bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
210 return !(*this == it ); 210 return !(*this == it );
211} 211}
212template <class T> 212template <class T>
213ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 213ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids,
214 const Base* t ) 214 const Base* t )
215 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), 215 : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ),
216 m_direction( false ) 216 m_direction( false )
217{ 217{
218} 218}
219template <class T> 219template <class T>
220uint ORecordListIterator<T>::current()const { 220uint ORecordListIterator<T>::current()const {
221 return m_current; 221 return m_current;
222} 222}
223template <class T> 223template <class T>
224void ORecordListIterator<T>::setCurrent( uint cur ) { 224void ORecordListIterator<T>::setCurrent( uint cur ) {
225 if( cur < m_uids.count() ) { 225 if( cur < m_uids.count() ) {
226 m_end = false; 226 m_end = false;
227 m_current= cur; 227 m_current= cur;
228 } 228 }
229} 229}
230template <class T> 230template <class T>
231uint ORecordListIterator<T>::count()const { 231uint ORecordListIterator<T>::count()const {
232 return m_uids.count(); 232 return m_uids.count();
233} 233}
234template <class T> 234template <class T>
235ORecordList<T>::ORecordList( const QArray<int>& ids, 235ORecordList<T>::ORecordList( const QArray<int>& ids,
236 const Base* acc ) 236 const Base* acc )
237 : m_ids( ids ), m_acc( acc ) 237 : m_ids( ids ), m_acc( acc )
238{ 238{
239} 239}
240template <class T> 240template <class T>
241ORecordList<T>::~ORecordList() { 241ORecordList<T>::~ORecordList() {
242/* nothing to do here */ 242/* nothing to do here */
243} 243}
244template <class T> 244template <class T>
245ORecordList<T>::Iterator ORecordList<T>::begin() { 245ORecordList<T>::Iterator ORecordList<T>::begin() {
246 Iterator it( m_ids, m_acc ); 246 Iterator it( m_ids, m_acc );
247 return it; 247 return it;
248} 248}
249template <class T> 249template <class T>
250ORecordList<T>::Iterator ORecordList<T>::end() { 250ORecordList<T>::Iterator ORecordList<T>::end() {
251 Iterator it( m_ids, m_acc ); 251 Iterator it( m_ids, m_acc );
252 it.m_end = true; 252 it.m_end = true;
253 it.m_current = m_ids.count(); 253 it.m_current = m_ids.count();
254 254
255 return it; 255 return it;
256} 256}
257template <class T> 257template <class T>
258uint ORecordList<T>::count()const { 258uint ORecordList<T>::count()const {
259return m_ids.count(); 259return m_ids.count();
260} 260}
261template <class T> 261template <class T>
262T ORecordList<T>::operator[]( uint i ) { 262T ORecordList<T>::operator[]( uint i ) {
263 if ( i < 0 || (i+1) > m_ids.count() )
264 return T();
263 /* forward */ 265 /* forward */
264 return m_acc->find( m_ids[i], m_ids, i ); 266 return m_acc->find( m_ids[i], m_ids, i );
265} 267}
266template <class T> 268template <class T>
267int ORecordList<T>::uidAt( uint i ) { 269int ORecordList<T>::uidAt( uint i ) {
268 return m_ids[i]; 270 return m_ids[i];
269} 271}
270#endif 272#endif
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp
new file mode 100644
index 0000000..6c81f8f
--- a/dev/null
+++ b/libopie/pim/orecur.cpp
@@ -0,0 +1,127 @@
1#include <qshared.h>
2
3#include <qtopia/timeconversion.h>
4
5#include "orecur.h"
6
7struct ORecur::Data : public QShared {
8 Data() : QShared() {
9 type = ORecur::NoRepeat;
10 freq = -1;
11 days = 0;
12 pos = 0;
13 create = -1;
14 hasEnd = FALSE;
15 end = 0;
16 }
17 char days; // Q_UINT8 for 8 seven days;)
18 ORecur::RepeatType type;
19 int freq;
20 int pos;
21 bool hasEnd : 1;
22 time_t end;
23 time_t create;
24};
25
26
27ORecur::ORecur() {
28 data = new Data;
29}
30ORecur::ORecur( const ORecur& rec)
31 : data( rec.data )
32{
33 data->ref();
34}
35ORecur::~ORecur() {
36 if ( data->deref() ) {
37 delete data;
38 data = 0l;
39 }
40}
41void ORecur::deref() {
42 if ( data->deref() ) {
43 delete data;
44 data = 0l;
45 }
46}
47bool ORecur::operator==( const ORecur& )const {
48 return false;
49}
50ORecur &ORecur::operator=( const ORecur& re) {
51 re.data->ref();
52 deref();
53 data = re.data;
54
55 return *this;
56}
57ORecur::RepeatType ORecur::type()const{
58 return data->type;
59}
60int ORecur::frequency()const {
61 return data->freq;
62}
63int ORecur::position()const {
64 return data->pos;
65}
66char ORecur::days() const{
67 return data->days;
68}
69bool ORecur::hasEndDate()const {
70 return data->hasEnd;
71}
72QDate ORecur::endDate()const {
73 return TimeConversion::fromUTC( data->end ).date();
74}
75time_t ORecur::endDateUTC()const {
76 return data->end;
77}
78time_t ORecur::createTime()const {
79 return data->create;
80}
81void ORecur::setType( const RepeatType& z) {
82 checkOrModify();
83 data->type = z;
84}
85void ORecur::setFrequency( int freq ) {
86 checkOrModify();
87 data->freq = freq;
88}
89void ORecur::setPosition( int pos ) {
90 checkOrModify();
91 data->pos = pos;
92}
93void ORecur::setDays( char c ) {
94 checkOrModify();
95 data->days = c;
96}
97void ORecur::setEndDate( const QDate& dt) {
98 checkOrModify();
99 data->end = TimeConversion::toUTC( dt );
100}
101void ORecur::setEndDateUTC( time_t t) {
102 checkOrModify();
103 data->end = t;
104}
105void ORecur::setCreateTime( time_t t) {
106 checkOrModify();
107 data->create = t;
108}
109void ORecur::setHasEndDate( bool b) {
110 checkOrModify();
111 data->hasEnd = b;
112}
113void ORecur::checkOrModify() {
114 if ( data->count != 1 ) {
115 data->deref();
116 Data* d2 = new Data;
117 d2->days = data->days;
118 d2->type = data->type;
119 d2->freq = data->freq;
120 d2->pos = data->pos;
121 d2->hasEnd = data->hasEnd;
122 d2->end = data->end;
123 d2->create = data->create;
124 data = d2;
125 }
126}
127
diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h
new file mode 100644
index 0000000..89258f8
--- a/dev/null
+++ b/libopie/pim/orecur.h
@@ -0,0 +1,54 @@
1/*
2 * GPL from TT
3 */
4
5#ifndef OPIE_RECUR_H
6#define OPIE_RECUR_H
7
8#include <sys/types.h>
9
10#include <qdatetime.h>
11
12
13
14class ORecur {
15public:
16 enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
17 MonthlyDate, Yearly };
18 enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
19 FRI = 0x10, SAT = 0x20, SUN = 0x40 };
20 ORecur();
21 ORecur( const ORecur& );
22 ~ORecur();
23
24 ORecur &operator=( const ORecur& );
25 bool operator==(const ORecur& )const;
26 RepeatType type()const;
27 int frequency()const;
28 int position()const;
29 char days()const;
30 bool hasEndDate()const;
31 QDate endDate()const;
32 time_t endDateUTC()const;
33 time_t createTime()const;
34
35 void setType( const RepeatType& );
36 void setFrequency( int freq );
37 void setPosition( int pos );
38 void setDays( char c);
39 void setEndDate( const QDate& dt );
40 void setEndDateUTC( time_t );
41 void setCreateTime( time_t );
42 void setHasEndDate( bool b );
43private:
44 void deref();
45 inline void checkOrModify();
46
47
48 class Data;
49 Data* data;
50 class ORecurPrivate;
51 ORecurPrivate *d;
52};
53
54#endif
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
index 8c2ea3a..761d7d8 100644
--- a/libopie/pim/otodoaccesssql.cpp
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -1,540 +1,540 @@
1 1
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include <qpe/global.h> 4#include <qpe/global.h>
5 5
6#include <opie/osqldriver.h> 6#include <opie/osqldriver.h>
7#include <opie/osqlresult.h> 7#include <opie/osqlresult.h>
8#include <opie/osqlmanager.h> 8#include <opie/osqlmanager.h>
9#include <opie/osqlquery.h> 9#include <opie/osqlquery.h>
10 10
11#include "otodoaccesssql.h" 11#include "otodoaccesssql.h"
12 12
13/* 13/*
14 * first some query 14 * first some query
15 * CREATE query 15 * CREATE query
16 * LOAD query 16 * LOAD query
17 * INSERT 17 * INSERT
18 * REMOVE 18 * REMOVE
19 * CLEAR 19 * CLEAR
20 */ 20 */
21namespace { 21namespace {
22 /** 22 /**
23 * CreateQuery for the Todolist Table 23 * CreateQuery for the Todolist Table
24 */ 24 */
25 class CreateQuery : public OSQLQuery { 25 class CreateQuery : public OSQLQuery {
26 public: 26 public:
27 CreateQuery(); 27 CreateQuery();
28 ~CreateQuery(); 28 ~CreateQuery();
29 QString query()const; 29 QString query()const;
30 }; 30 };
31 31
32 /** 32 /**
33 * LoadQuery 33 * LoadQuery
34 * this one queries for all uids 34 * this one queries for all uids
35 */ 35 */
36 class LoadQuery : public OSQLQuery { 36 class LoadQuery : public OSQLQuery {
37 public: 37 public:
38 LoadQuery(); 38 LoadQuery();
39 ~LoadQuery(); 39 ~LoadQuery();
40 QString query()const; 40 QString query()const;
41 }; 41 };
42 42
43 /** 43 /**
44 * inserts/adds a OTodo to the table 44 * inserts/adds a OTodo to the table
45 */ 45 */
46 class InsertQuery : public OSQLQuery { 46 class InsertQuery : public OSQLQuery {
47 public: 47 public:
48 InsertQuery(const OTodo& ); 48 InsertQuery(const OTodo& );
49 ~InsertQuery(); 49 ~InsertQuery();
50 QString query()const; 50 QString query()const;
51 private: 51 private:
52 OTodo m_todo; 52 OTodo m_todo;
53 }; 53 };
54 54
55 /** 55 /**
56 * removes one from the table 56 * removes one from the table
57 */ 57 */
58 class RemoveQuery : public OSQLQuery { 58 class RemoveQuery : public OSQLQuery {
59 public: 59 public:
60 RemoveQuery(int uid ); 60 RemoveQuery(int uid );
61 ~RemoveQuery(); 61 ~RemoveQuery();
62 QString query()const; 62 QString query()const;
63 private: 63 private:
64 int m_uid; 64 int m_uid;
65 }; 65 };
66 66
67 /** 67 /**
68 * Clears (delete) a Table 68 * Clears (delete) a Table
69 */ 69 */
70 class ClearQuery : public OSQLQuery { 70 class ClearQuery : public OSQLQuery {
71 public: 71 public:
72 ClearQuery(); 72 ClearQuery();
73 ~ClearQuery(); 73 ~ClearQuery();
74 QString query()const; 74 QString query()const;
75 75
76 }; 76 };
77 77
78 /** 78 /**
79 * a find query 79 * a find query
80 */ 80 */
81 class FindQuery : public OSQLQuery { 81 class FindQuery : public OSQLQuery {
82 public: 82 public:
83 FindQuery(int uid); 83 FindQuery(int uid);
84 FindQuery(const QArray<int>& ); 84 FindQuery(const QArray<int>& );
85 ~FindQuery(); 85 ~FindQuery();
86 QString query()const; 86 QString query()const;
87 private: 87 private:
88 QString single()const; 88 QString single()const;
89 QString multi()const; 89 QString multi()const;
90 QArray<int> m_uids; 90 QArray<int> m_uids;
91 int m_uid; 91 int m_uid;
92 }; 92 };
93 93
94 /** 94 /**
95 * overdue query 95 * overdue query
96 */ 96 */
97 class OverDueQuery : public OSQLQuery { 97 class OverDueQuery : public OSQLQuery {
98 public: 98 public:
99 OverDueQuery(); 99 OverDueQuery();
100 ~OverDueQuery(); 100 ~OverDueQuery();
101 QString query()const; 101 QString query()const;
102 }; 102 };
103 class EffQuery : public OSQLQuery { 103 class EffQuery : public OSQLQuery {
104 public: 104 public:
105 EffQuery( const QDate&, const QDate&, bool inc ); 105 EffQuery( const QDate&, const QDate&, bool inc );
106 ~EffQuery(); 106 ~EffQuery();
107 QString query()const; 107 QString query()const;
108 private: 108 private:
109 QString with()const; 109 QString with()const;
110 QString out()const; 110 QString out()const;
111 QDate m_start; 111 QDate m_start;
112 QDate m_end; 112 QDate m_end;
113 bool m_inc :1; 113 bool m_inc :1;
114 }; 114 };
115 115
116 116
117 CreateQuery::CreateQuery() : OSQLQuery() {} 117 CreateQuery::CreateQuery() : OSQLQuery() {}
118 CreateQuery::~CreateQuery() {} 118 CreateQuery::~CreateQuery() {}
119 QString CreateQuery::query()const { 119 QString CreateQuery::query()const {
120 QString qu; 120 QString qu;
121 qu += "create table todolist( uid, categories, completed, progress, "; 121 qu += "create table todolist( uid, categories, completed, progress, ";
122 qu += "summary, DueDate, priority, description )"; 122 qu += "summary, DueDate, priority, description )";
123 return qu; 123 return qu;
124 } 124 }
125 125
126 LoadQuery::LoadQuery() : OSQLQuery() {} 126 LoadQuery::LoadQuery() : OSQLQuery() {}
127 LoadQuery::~LoadQuery() {} 127 LoadQuery::~LoadQuery() {}
128 QString LoadQuery::query()const { 128 QString LoadQuery::query()const {
129 QString qu; 129 QString qu;
130 qu += "select distinct uid from todolist"; 130 qu += "select distinct uid from todolist";
131 131
132 return qu; 132 return qu;
133 } 133 }
134 134
135 InsertQuery::InsertQuery( const OTodo& todo ) 135 InsertQuery::InsertQuery( const OTodo& todo )
136 : OSQLQuery(), m_todo( todo ) { 136 : OSQLQuery(), m_todo( todo ) {
137 } 137 }
138 InsertQuery::~InsertQuery() { 138 InsertQuery::~InsertQuery() {
139 } 139 }
140 /* 140 /*
141 * converts from a OTodo to a query 141 * converts from a OTodo to a query
142 * we leave out X-Ref + Alarms 142 * we leave out X-Ref + Alarms
143 */ 143 */
144 QString InsertQuery::query()const{ 144 QString InsertQuery::query()const{
145 145
146 int year, month, day; 146 int year, month, day;
147 year = month = day = 0; 147 year = month = day = 0;
148 if (m_todo.hasDueDate() ) { 148 if (m_todo.hasDueDate() ) {
149 QDate date = m_todo.dueDate(); 149 QDate date = m_todo.dueDate();
150 year = date.year(); 150 year = date.year();
151 month = date.month(); 151 month = date.month();
152 day = date.day(); 152 day = date.day();
153 } 153 }
154 QString qu; 154 QString qu;
155 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; 155 qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',";
156 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; 156 qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ",";
157 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; 157 qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',";
158 qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; 158 qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')";
159 159
160 qWarning("add %s", qu.latin1() ); 160 qWarning("add %s", qu.latin1() );
161 return qu; 161 return qu;
162 } 162 }
163 163
164 RemoveQuery::RemoveQuery(int uid ) 164 RemoveQuery::RemoveQuery(int uid )
165 : OSQLQuery(), m_uid( uid ) {} 165 : OSQLQuery(), m_uid( uid ) {}
166 RemoveQuery::~RemoveQuery() {} 166 RemoveQuery::~RemoveQuery() {}
167 QString RemoveQuery::query()const { 167 QString RemoveQuery::query()const {
168 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); 168 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid);
169 return qu; 169 return qu;
170 } 170 }
171 171
172 172
173 ClearQuery::ClearQuery() 173 ClearQuery::ClearQuery()
174 : OSQLQuery() {} 174 : OSQLQuery() {}
175 ClearQuery::~ClearQuery() {} 175 ClearQuery::~ClearQuery() {}
176 QString ClearQuery::query()const { 176 QString ClearQuery::query()const {
177 QString qu = "drop table todolist"; 177 QString qu = "drop table todolist";
178 return qu; 178 return qu;
179 } 179 }
180 FindQuery::FindQuery(int uid) 180 FindQuery::FindQuery(int uid)
181 : OSQLQuery(), m_uid(uid ) { 181 : OSQLQuery(), m_uid(uid ) {
182 } 182 }
183 FindQuery::FindQuery(const QArray<int>& ints) 183 FindQuery::FindQuery(const QArray<int>& ints)
184 : OSQLQuery(), m_uids(ints){ 184 : OSQLQuery(), m_uids(ints){
185 } 185 }
186 FindQuery::~FindQuery() { 186 FindQuery::~FindQuery() {
187 } 187 }
188 QString FindQuery::query()const{ 188 QString FindQuery::query()const{
189 if (m_uids.count() == 0 ) 189 if (m_uids.count() == 0 )
190 return single(); 190 return single();
191 else 191 else
192 return multi(); 192 return multi();
193 } 193 }
194 QString FindQuery::single()const{ 194 QString FindQuery::single()const{
195 QString qu = "select uid, categories, completed, progress, summary, "; 195 QString qu = "select uid, categories, completed, progress, summary, ";
196 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); 196 qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid);
197 return qu; 197 return qu;
198 } 198 }
199 QString FindQuery::multi()const { 199 QString FindQuery::multi()const {
200 QString qu = "select uid, categories, completed, progress, summary, "; 200 QString qu = "select uid, categories, completed, progress, summary, ";
201 qu += "DueDate, priority, description from todolist where "; 201 qu += "DueDate, priority, description from todolist where ";
202 for (uint i = 0; i < m_uids.count(); i++ ) { 202 for (uint i = 0; i < m_uids.count(); i++ ) {
203 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 203 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
204 } 204 }
205 qu.remove( qu.length()-2, 2 ); 205 qu.remove( qu.length()-2, 2 );
206 return qu; 206 return qu;
207 } 207 }
208 208
209 OverDueQuery::OverDueQuery(): OSQLQuery() {} 209 OverDueQuery::OverDueQuery(): OSQLQuery() {}
210 OverDueQuery::~OverDueQuery() {} 210 OverDueQuery::~OverDueQuery() {}
211 QString OverDueQuery::query()const { 211 QString OverDueQuery::query()const {
212 QDate date = QDate::currentDate(); 212 QDate date = QDate::currentDate();
213 QString str; 213 QString str;
214 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 214 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
215 215
216 return str; 216 return str;
217 } 217 }
218 218
219 219
220 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 220 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
221 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 221 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
222 EffQuery::~EffQuery() {} 222 EffQuery::~EffQuery() {}
223 QString EffQuery::query()const { 223 QString EffQuery::query()const {
224 return m_inc ? with() : out(); 224 return m_inc ? with() : out();
225 } 225 }
226 QString EffQuery::with()const { 226 QString EffQuery::with()const {
227 QString str; 227 QString str;
228 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 228 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
229 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) 229 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
230 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); 230 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
231 return str; 231 return str;
232 } 232 }
233 QString EffQuery::out()const { 233 QString EffQuery::out()const {
234 QString str; 234 QString str;
235 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 235 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
236 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) 236 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
237 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); 237 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
238 238
239 return str; 239 return str;
240 } 240 }
241}; 241};
242 242
243OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) 243OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
244 : OTodoAccessBackend(), m_dict(15), m_dirty(true) 244 : OTodoAccessBackend(), m_dict(15), m_dirty(true)
245{ 245{
246 QString fi = file; 246 QString fi = file;
247 if ( fi.isEmpty() ) 247 if ( fi.isEmpty() )
248 fi = Global::applicationFileName( "todolist", "todolist.db" ); 248 fi = Global::applicationFileName( "todolist", "todolist.db" );
249 OSQLManager man; 249 OSQLManager man;
250 m_driver = man.standard(); 250 m_driver = man.standard();
251 m_driver->setUrl(fi); 251 m_driver->setUrl(fi);
252 fillDict(); 252 fillDict();
253} 253}
254 254
255OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ 255OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
256} 256}
257bool OTodoAccessBackendSQL::load(){ 257bool OTodoAccessBackendSQL::load(){
258 if (!m_driver->open() ) 258 if (!m_driver->open() )
259 return false; 259 return false;
260 260
261 CreateQuery creat; 261 CreateQuery creat;
262 OSQLResult res = m_driver->query(&creat ); 262 OSQLResult res = m_driver->query(&creat );
263 263
264 m_dirty = true; 264 m_dirty = true;
265 return true; 265 return true;
266} 266}
267bool OTodoAccessBackendSQL::reload(){ 267bool OTodoAccessBackendSQL::reload(){
268 return load(); 268 return load();
269} 269}
270 270
271bool OTodoAccessBackendSQL::save(){ 271bool OTodoAccessBackendSQL::save(){
272 return m_driver->close(); 272 return m_driver->close();
273} 273}
274QArray<int> OTodoAccessBackendSQL::allRecords()const { 274QArray<int> OTodoAccessBackendSQL::allRecords()const {
275 if (m_dirty ) 275 if (m_dirty )
276 update(); 276 update();
277 277
278 return m_uids; 278 return m_uids;
279} 279}
280QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ 280QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){
281 QArray<int> ints(0); 281 QArray<int> ints(0);
282 return ints; 282 return ints;
283} 283}
284OTodo OTodoAccessBackendSQL::find(int uid ) const{ 284OTodo OTodoAccessBackendSQL::find(int uid ) const{
285 FindQuery query( uid ); 285 FindQuery query( uid );
286 return todo( m_driver->query(&query) ); 286 return todo( m_driver->query(&query) );
287 287
288} 288}
289OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 289OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
290 uint cur, Frontend::CacheDirection dir ) const{ 290 uint cur, Frontend::CacheDirection dir ) const{
291 int CACHE = readAhead(); 291 int CACHE = readAhead();
292 qWarning("searching for %d", uid ); 292 qWarning("searching for %d", uid );
293 QArray<int> search( CACHE ); 293 QArray<int> search( CACHE );
294 uint size =0; 294 uint size =0;
295 OTodo to; 295 OTodo to;
296 296
297 // we try to cache CACHE items 297 // we try to cache CACHE items
298 switch( dir ) { 298 switch( dir ) {
299 /* forward */ 299 /* forward */
300 case 0: 300 case 0:
301 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 301 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
302 qWarning("size %d %d", size, ints[i] ); 302 qWarning("size %d %d", size, ints[i] );
303 search[size] = ints[i]; 303 search[size] = ints[i];
304 size++; 304 size++;
305 } 305 }
306 break; 306 break;
307 /* reverse */ 307 /* reverse */
308 case 1: 308 case 1:
309 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 309 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
310 search[size] = ints[i]; 310 search[size] = ints[i];
311 size++; 311 size++;
312 } 312 }
313 break; 313 break;
314 } 314 }
315 search.resize( size ); 315 search.resize( size );
316 FindQuery query( search ); 316 FindQuery query( search );
317 OSQLResult res = m_driver->query( &query ); 317 OSQLResult res = m_driver->query( &query );
318 if ( res.state() != OSQLResult::Success ) 318 if ( res.state() != OSQLResult::Success )
319 return to; 319 return to;
320 320
321 return todo( res ); 321 return todo( res );
322} 322}
323void OTodoAccessBackendSQL::clear() { 323void OTodoAccessBackendSQL::clear() {
324 ClearQuery cle; 324 ClearQuery cle;
325 OSQLResult res = m_driver->query( &cle ); 325 OSQLResult res = m_driver->query( &cle );
326 CreateQuery qu; 326 CreateQuery qu;
327 res = m_driver->query(&qu); 327 res = m_driver->query(&qu);
328} 328}
329bool OTodoAccessBackendSQL::add( const OTodo& t) { 329bool OTodoAccessBackendSQL::add( const OTodo& t) {
330 InsertQuery ins( t ); 330 InsertQuery ins( t );
331 OSQLResult res = m_driver->query( &ins ); 331 OSQLResult res = m_driver->query( &ins );
332 332
333 if ( res.state() == OSQLResult::Failure ) 333 if ( res.state() == OSQLResult::Failure )
334 return false; 334 return false;
335 int c = m_uids.count(); 335 int c = m_uids.count();
336 m_uids.resize( c+1 ); 336 m_uids.resize( c+1 );
337 m_uids[c] = t.uid(); 337 m_uids[c] = t.uid();
338 338
339 return true; 339 return true;
340} 340}
341bool OTodoAccessBackendSQL::remove( int uid ) { 341bool OTodoAccessBackendSQL::remove( int uid ) {
342 RemoveQuery rem( uid ); 342 RemoveQuery rem( uid );
343 OSQLResult res = m_driver->query(&rem ); 343 OSQLResult res = m_driver->query(&rem );
344 344
345 if ( res.state() == OSQLResult::Failure ) 345 if ( res.state() == OSQLResult::Failure )
346 return false; 346 return false;
347 347
348 m_dirty = true; 348 m_dirty = true;
349 return true; 349 return true;
350} 350}
351/* 351/*
352 * FIXME better set query 352 * FIXME better set query
353 * but we need the cache for that 353 * but we need the cache for that
354 * now we remove 354 * now we remove
355 */ 355 */
356bool OTodoAccessBackendSQL::replace( const OTodo& t) { 356bool OTodoAccessBackendSQL::replace( const OTodo& t) {
357 remove( t.uid() ); 357 remove( t.uid() );
358 bool b= add(t); 358 bool b= add(t);
359 m_dirty = false; // we changed some stuff but the UID stayed the same 359 m_dirty = false; // we changed some stuff but the UID stayed the same
360 return b; 360 return b;
361} 361}
362QArray<int> OTodoAccessBackendSQL::overDue() { 362QArray<int> OTodoAccessBackendSQL::overDue() {
363 OverDueQuery qu; 363 OverDueQuery qu;
364 return uids( m_driver->query(&qu ) ); 364 return uids( m_driver->query(&qu ) );
365} 365}
366QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, 366QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s,
367 const QDate& t, 367 const QDate& t,
368 bool u) { 368 bool u) {
369 EffQuery ef(s, t, u ); 369 EffQuery ef(s, t, u );
370 return uids (m_driver->query(&ef) ); 370 return uids (m_driver->query(&ef) );
371} 371}
372/* 372/*
373 * 373 *
374 */ 374 */
375QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 375QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
376 int sortFilter, int cat ) { 376 int sortFilter, int cat ) {
377 qWarning("sorted %d, %d", asc, sortOrder ); 377 qWarning("sorted %d, %d", asc, sortOrder );
378 QString query; 378 QString query;
379 query = "select uid from todolist WHERE "; 379 query = "select uid from todolist WHERE ";
380 380
381 /* 381 /*
382 * Sort Filter stuff 382 * Sort Filter stuff
383 * not that straight forward 383 * not that straight forward
384 * 384 *
385 */ 385 */
386 /* Category */ 386 /* Category */
387 if ( sortFilter & 1 ) { 387 if ( sortFilter & 1 ) {
388 QString str; 388 QString str;
389 if (cat != 0 ) str = QString::number( cat ); 389 if (cat != 0 ) str = QString::number( cat );
390 query += " categories like '%" +str+"%' AND"; 390 query += " categories like '%" +str+"%' AND";
391 } 391 }
392 /* Show only overdue */ 392 /* Show only overdue */
393 if ( sortFilter & 2 ) { 393 if ( sortFilter & 2 ) {
394 QDate date = QDate::currentDate(); 394 QDate date = QDate::currentDate();
395 QString due; 395 QString due;
396 QString base; 396 QString base;
397 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); 397 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() );
398 query += " " + base + " AND"; 398 query += " " + base + " AND";
399 } 399 }
400 /* not show completed */ 400 /* not show completed */
401 if ( sortFilter & 4 ) { 401 if ( sortFilter & 4 ) {
402 query += " completed = 0 AND"; 402 query += " completed = 0 AND";
403 }else{ 403 }else{
404 query += " ( completed = 1 OR completed = 0) AND"; 404 query += " ( completed = 1 OR completed = 0) AND";
405 } 405 }
406 /* srtip the end */ 406 /* srtip the end */
407 query = query.remove( query.length()-3, 3 ); 407 query = query.remove( query.length()-3, 3 );
408 408
409 409
410 /* 410 /*
411 * sort order stuff 411 * sort order stuff
412 * quite straight forward 412 * quite straight forward
413 */ 413 */
414 query += "ORDER BY "; 414 query += "ORDER BY ";
415 switch( sortOrder ) { 415 switch( sortOrder ) {
416 /* completed */ 416 /* completed */
417 case 0: 417 case 0:
418 query += "completed"; 418 query += "completed";
419 break; 419 break;
420 case 1: 420 case 1:
421 query += "priority"; 421 query += "priority";
422 break; 422 break;
423 case 2: 423 case 2:
424 query += "description"; 424 query += "summary";
425 break; 425 break;
426 case 3: 426 case 3:
427 query += "DueDate"; 427 query += "DueDate";
428 break; 428 break;
429 } 429 }
430 430
431 if ( !asc ) { 431 if ( !asc ) {
432 qWarning("not ascending!"); 432 qWarning("not ascending!");
433 query += " DESC"; 433 query += " DESC";
434 } 434 }
435 435
436 qWarning( query ); 436 qWarning( query );
437 OSQLRawQuery raw(query ); 437 OSQLRawQuery raw(query );
438 return uids( m_driver->query(&raw) ); 438 return uids( m_driver->query(&raw) );
439} 439}
440bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 440bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
441 if ( str == "0-0-0" ) 441 if ( str == "0-0-0" )
442 return false; 442 return false;
443 else{ 443 else{
444 int day, year, month; 444 int day, year, month;
445 QStringList list = QStringList::split("-", str ); 445 QStringList list = QStringList::split("-", str );
446 year = list[0].toInt(); 446 year = list[0].toInt();
447 month = list[1].toInt(); 447 month = list[1].toInt();
448 day = list[2].toInt(); 448 day = list[2].toInt();
449 da.setYMD( year, month, day ); 449 da.setYMD( year, month, day );
450 return true; 450 return true;
451 } 451 }
452} 452}
453OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 453OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
454 if ( res.state() == OSQLResult::Failure ) { 454 if ( res.state() == OSQLResult::Failure ) {
455 OTodo to; 455 OTodo to;
456 return to; 456 return to;
457 } 457 }
458 458
459 OSQLResultItem::ValueList list = res.results(); 459 OSQLResultItem::ValueList list = res.results();
460 OSQLResultItem::ValueList::Iterator it = list.begin(); 460 OSQLResultItem::ValueList::Iterator it = list.begin();
461 qWarning("todo1"); 461 qWarning("todo1");
462 OTodo to = todo( (*it) ); 462 OTodo to = todo( (*it) );
463 cache( to ); 463 cache( to );
464 ++it; 464 ++it;
465 465
466 for ( ; it != list.end(); ++it ) { 466 for ( ; it != list.end(); ++it ) {
467 qWarning("caching"); 467 qWarning("caching");
468 cache( todo( (*it) ) ); 468 cache( todo( (*it) ) );
469 } 469 }
470 return to; 470 return to;
471} 471}
472OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 472OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
473 qWarning("todo"); 473 qWarning("todo");
474 bool has = false; QDate da = QDate::currentDate(); 474 bool has = false; QDate da = QDate::currentDate();
475 has = date( da, item.data("DueDate") ); 475 has = date( da, item.data("DueDate") );
476 QStringList cats = QStringList::split(";", item.data("categories") ); 476 QStringList cats = QStringList::split(";", item.data("categories") );
477 477
478 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 478 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
479 cats, item.data("summary"), item.data("description"), 479 cats, item.data("summary"), item.data("description"),
480 item.data("progress").toUShort(), has, da, 480 item.data("progress").toUShort(), has, da,
481 item.data("uid").toInt() ); 481 item.data("uid").toInt() );
482 return to; 482 return to;
483} 483}
484OTodo OTodoAccessBackendSQL::todo( int uid )const { 484OTodo OTodoAccessBackendSQL::todo( int uid )const {
485 FindQuery find( uid ); 485 FindQuery find( uid );
486 return todo( m_driver->query(&find) ); 486 return todo( m_driver->query(&find) );
487} 487}
488/* 488/*
489 * update the dict 489 * update the dict
490 */ 490 */
491void OTodoAccessBackendSQL::fillDict() { 491void OTodoAccessBackendSQL::fillDict() {
492 /* initialize dict */ 492 /* initialize dict */
493 /* 493 /*
494 * UPDATE dict if you change anything!!! 494 * UPDATE dict if you change anything!!!
495 */ 495 */
496 m_dict.setAutoDelete( TRUE ); 496 m_dict.setAutoDelete( TRUE );
497 m_dict.insert("Categories" , new int(OTodo::Category) ); 497 m_dict.insert("Categories" , new int(OTodo::Category) );
498 m_dict.insert("Uid" , new int(OTodo::Uid) ); 498 m_dict.insert("Uid" , new int(OTodo::Uid) );
499 m_dict.insert("HasDate" , new int(OTodo::HasDate) ); 499 m_dict.insert("HasDate" , new int(OTodo::HasDate) );
500 m_dict.insert("Completed" , new int(OTodo::Completed) ); 500 m_dict.insert("Completed" , new int(OTodo::Completed) );
501 m_dict.insert("Description" , new int(OTodo::Description) ); 501 m_dict.insert("Description" , new int(OTodo::Description) );
502 m_dict.insert("Summary" , new int(OTodo::Summary) ); 502 m_dict.insert("Summary" , new int(OTodo::Summary) );
503 m_dict.insert("Priority" , new int(OTodo::Priority) ); 503 m_dict.insert("Priority" , new int(OTodo::Priority) );
504 m_dict.insert("DateDay" , new int(OTodo::DateDay) ); 504 m_dict.insert("DateDay" , new int(OTodo::DateDay) );
505 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 505 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
506 m_dict.insert("DateYear" , new int(OTodo::DateYear) ); 506 m_dict.insert("DateYear" , new int(OTodo::DateYear) );
507 m_dict.insert("Progress" , new int(OTodo::Progress) ); 507 m_dict.insert("Progress" , new int(OTodo::Progress) );
508 m_dict.insert("Completed", new int(OTodo::Completed) ); 508 m_dict.insert("Completed", new int(OTodo::Completed) );
509 m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); 509 m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
510 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); 510 m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) );
511 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); 511 m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) );
512} 512}
513/* 513/*
514 * need to be const so let's fool the 514 * need to be const so let's fool the
515 * compiler :( 515 * compiler :(
516 */ 516 */
517void OTodoAccessBackendSQL::update()const { 517void OTodoAccessBackendSQL::update()const {
518 ((OTodoAccessBackendSQL*)this)->m_dirty = false; 518 ((OTodoAccessBackendSQL*)this)->m_dirty = false;
519 LoadQuery lo; 519 LoadQuery lo;
520 OSQLResult res = m_driver->query(&lo); 520 OSQLResult res = m_driver->query(&lo);
521 if ( res.state() != OSQLResult::Success ) 521 if ( res.state() != OSQLResult::Success )
522 return; 522 return;
523 523
524 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); 524 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res );
525} 525}
526QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 526QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
527 527
528 OSQLResultItem::ValueList list = res.results(); 528 OSQLResultItem::ValueList list = res.results();
529 OSQLResultItem::ValueList::Iterator it; 529 OSQLResultItem::ValueList::Iterator it;
530 QArray<int> ints(list.count() ); 530 QArray<int> ints(list.count() );
531 qWarning(" count = %d", list.count() ); 531 qWarning(" count = %d", list.count() );
532 532
533 int i = 0; 533 int i = 0;
534 for (it = list.begin(); it != list.end(); ++it ) { 534 for (it = list.begin(); it != list.end(); ++it ) {
535 ints[i] = (*it).data("uid").toInt(); 535 ints[i] = (*it).data("uid").toInt();
536 i++; 536 i++;
537 } 537 }
538 return ints; 538 return ints;
539} 539}
540 540