-rw-r--r-- | libopie/pim/otodoaccess.h | 6 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 61 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 6 |
3 files changed, 65 insertions, 8 deletions
diff --git a/libopie/pim/otodoaccess.h b/libopie/pim/otodoaccess.h index 12997aa..390ab0e 100644 --- a/libopie/pim/otodoaccess.h +++ b/libopie/pim/otodoaccess.h | |||
@@ -1,93 +1,93 @@ | |||
1 | #ifndef OPIE_TODO_ACCESS_H | 1 | #ifndef OPIE_TODO_ACCESS_H |
2 | #define OPIE_TODO_ACCESS_H | 2 | #define OPIE_TODO_ACCESS_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qvaluelist.h> | 5 | #include <qvaluelist.h> |
6 | 6 | ||
7 | #include "otodo.h" | 7 | #include "otodo.h" |
8 | #include "otodoaccessbackend.h" | 8 | #include "otodoaccessbackend.h" |
9 | #include "opimaccesstemplate.h" | 9 | #include "opimaccesstemplate.h" |
10 | 10 | ||
11 | 11 | ||
12 | /** | 12 | /** |
13 | * OTodoAccess | 13 | * OTodoAccess |
14 | * the class to get access to | 14 | * the class to get access to |
15 | * the todolist | 15 | * the todolist |
16 | */ | 16 | */ |
17 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { | 17 | class OTodoAccess : public QObject, public OPimAccessTemplate<OTodo> { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | public: | 19 | public: |
20 | enum SortOrder { Completed = 0, | 20 | enum SortOrder { Completed = 0, |
21 | Priority, | 21 | Priority, |
22 | Description, | 22 | Description, |
23 | Deadline }; | 23 | Deadline }; |
24 | enum SortFilter{ ShowOverdue = 0, | 24 | enum SortFilter{ Category =1, |
25 | Category =1, | 25 | OnlyOverDue= 2, |
26 | OnlyOverDue= 2 }; | 26 | DoNotShowCompleted =4 }; |
27 | /** | 27 | /** |
28 | * if you use 0l | 28 | * if you use 0l |
29 | * the default resource will be | 29 | * the default resource will be |
30 | * picked up | 30 | * picked up |
31 | */ | 31 | */ |
32 | OTodoAccess( OTodoAccessBackend* = 0l); | 32 | OTodoAccess( OTodoAccessBackend* = 0l); |
33 | ~OTodoAccess(); | 33 | ~OTodoAccess(); |
34 | 34 | ||
35 | 35 | ||
36 | /* our functions here */ | 36 | /* our functions here */ |
37 | /** | 37 | /** |
38 | * include todos from start to end | 38 | * include todos from start to end |
39 | * includeNoDates whether or not to include | 39 | * includeNoDates whether or not to include |
40 | * events with no dates | 40 | * events with no dates |
41 | */ | 41 | */ |
42 | List effectiveToDos( const QDate& start, | 42 | List effectiveToDos( const QDate& start, |
43 | const QDate& end, | 43 | const QDate& end, |
44 | bool includeNoDates = true ); | 44 | bool includeNoDates = true ); |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * start | 47 | * start |
48 | * end date taken from the currentDate() | 48 | * end date taken from the currentDate() |
49 | */ | 49 | */ |
50 | List effectiveToDos( const QDate& start, | 50 | List effectiveToDos( const QDate& start, |
51 | bool includeNoDates = true ); | 51 | bool includeNoDates = true ); |
52 | 52 | ||
53 | 53 | ||
54 | /** | 54 | /** |
55 | * return overdue OTodos | 55 | * return overdue OTodos |
56 | */ | 56 | */ |
57 | List overDue(); | 57 | List overDue(); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * | 60 | * |
61 | */ | 61 | */ |
62 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 62 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * merge a list of OTodos into | 65 | * merge a list of OTodos into |
66 | * the resource | 66 | * the resource |
67 | */ | 67 | */ |
68 | void mergeWith( const QValueList<OTodo>& ); | 68 | void mergeWith( const QValueList<OTodo>& ); |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * add an Alarm to the AlarmServer | 71 | * add an Alarm to the AlarmServer |
72 | */ | 72 | */ |
73 | void addAlarm( const OTodo& ); | 73 | void addAlarm( const OTodo& ); |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * delete an alarm with the uid from | 76 | * delete an alarm with the uid from |
77 | * the alarm server | 77 | * the alarm server |
78 | */ | 78 | */ |
79 | void delAlarm( int uid ); | 79 | void delAlarm( int uid ); |
80 | 80 | ||
81 | signals: | 81 | signals: |
82 | /** | 82 | /** |
83 | * if the OTodoAccess was changed | 83 | * if the OTodoAccess was changed |
84 | */ | 84 | */ |
85 | void signalChanged( const OTodoAccess* ); | 85 | void signalChanged( const OTodoAccess* ); |
86 | private: | 86 | private: |
87 | int m_cat; | 87 | int m_cat; |
88 | OTodoAccessBackend* m_todoBackEnd; | 88 | OTodoAccessBackend* m_todoBackEnd; |
89 | class OTodoAccessPrivate; | 89 | class OTodoAccessPrivate; |
90 | OTodoAccessPrivate* d; | 90 | OTodoAccessPrivate* d; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | #endif | 93 | #endif |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index 209e714..25536e0 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -1,397 +1,454 @@ | |||
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 | */ |
21 | namespace { | 21 | namespace { |
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(); | 84 | ~FindQuery(); |
85 | QString query()const; | 85 | QString query()const; |
86 | private: | 86 | private: |
87 | int m_uid; | 87 | int m_uid; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * overdue query | 91 | * overdue query |
92 | */ | 92 | */ |
93 | class OverDueQuery : public OSQLQuery { | 93 | class OverDueQuery : public OSQLQuery { |
94 | public: | 94 | public: |
95 | OverDueQuery(); | 95 | OverDueQuery(); |
96 | ~OverDueQuery(); | 96 | ~OverDueQuery(); |
97 | QString query()const; | 97 | QString query()const; |
98 | }; | 98 | }; |
99 | class EffQuery : public OSQLQuery { | 99 | class EffQuery : public OSQLQuery { |
100 | public: | 100 | public: |
101 | EffQuery( const QDate&, const QDate&, bool inc ); | 101 | EffQuery( const QDate&, const QDate&, bool inc ); |
102 | ~EffQuery(); | 102 | ~EffQuery(); |
103 | QString query()const; | 103 | QString query()const; |
104 | private: | 104 | private: |
105 | QString with()const; | 105 | QString with()const; |
106 | QString out()const; | 106 | QString out()const; |
107 | QDate m_start; | 107 | QDate m_start; |
108 | QDate m_end; | 108 | QDate m_end; |
109 | bool m_inc :1; | 109 | bool m_inc :1; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | 112 | ||
113 | CreateQuery::CreateQuery() : OSQLQuery() {} | 113 | CreateQuery::CreateQuery() : OSQLQuery() {} |
114 | CreateQuery::~CreateQuery() {} | 114 | CreateQuery::~CreateQuery() {} |
115 | QString CreateQuery::query()const { | 115 | QString CreateQuery::query()const { |
116 | QString qu; | 116 | QString qu; |
117 | qu += "create table todolist( uid, categories, completed, progress, "; | 117 | qu += "create table todolist( uid, categories, completed, progress, "; |
118 | qu += "summary, DueDate, priority, description )"; | 118 | qu += "summary, DueDate, priority, description )"; |
119 | return qu; | 119 | return qu; |
120 | } | 120 | } |
121 | 121 | ||
122 | LoadQuery::LoadQuery() : OSQLQuery() {} | 122 | LoadQuery::LoadQuery() : OSQLQuery() {} |
123 | LoadQuery::~LoadQuery() {} | 123 | LoadQuery::~LoadQuery() {} |
124 | QString LoadQuery::query()const { | 124 | QString LoadQuery::query()const { |
125 | QString qu; | 125 | QString qu; |
126 | qu += "select distinct uid from todolist"; | 126 | qu += "select distinct uid from todolist"; |
127 | 127 | ||
128 | return qu; | 128 | return qu; |
129 | } | 129 | } |
130 | 130 | ||
131 | InsertQuery::InsertQuery( const OTodo& todo ) | 131 | InsertQuery::InsertQuery( const OTodo& todo ) |
132 | : OSQLQuery(), m_todo( todo ) { | 132 | : OSQLQuery(), m_todo( todo ) { |
133 | } | 133 | } |
134 | InsertQuery::~InsertQuery() { | 134 | InsertQuery::~InsertQuery() { |
135 | } | 135 | } |
136 | /* | 136 | /* |
137 | * converts from a OTodo to a query | 137 | * converts from a OTodo to a query |
138 | * we leave out X-Ref + Alarms | 138 | * we leave out X-Ref + Alarms |
139 | */ | 139 | */ |
140 | QString InsertQuery::query()const{ | 140 | QString InsertQuery::query()const{ |
141 | int year, month, day; | 141 | int year, month, day; |
142 | year = month = day = 0; | 142 | year = month = day = 0; |
143 | if (m_todo.hasDueDate() ) { | 143 | if (m_todo.hasDueDate() ) { |
144 | QDate date = m_todo.dueDate(); | 144 | QDate date = m_todo.dueDate(); |
145 | year = date.year(); | 145 | year = date.year(); |
146 | month = date.month(); | 146 | month = date.month(); |
147 | day = date.day(); | 147 | day = date.day(); |
148 | } | 148 | } |
149 | QString qu; | 149 | QString qu; |
150 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; | 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() ) + ","; | 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)+"',"; | 152 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; |
153 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; | 153 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; |
154 | 154 | ||
155 | qWarning("add %s", qu.latin1() ); | 155 | qWarning("add %s", qu.latin1() ); |
156 | return qu; | 156 | return qu; |
157 | } | 157 | } |
158 | 158 | ||
159 | RemoveQuery::RemoveQuery(int uid ) | 159 | RemoveQuery::RemoveQuery(int uid ) |
160 | : OSQLQuery(), m_uid( uid ) {} | 160 | : OSQLQuery(), m_uid( uid ) {} |
161 | RemoveQuery::~RemoveQuery() {} | 161 | RemoveQuery::~RemoveQuery() {} |
162 | QString RemoveQuery::query()const { | 162 | QString RemoveQuery::query()const { |
163 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 163 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); |
164 | return qu; | 164 | return qu; |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | ClearQuery::ClearQuery() | 168 | ClearQuery::ClearQuery() |
169 | : OSQLQuery() {} | 169 | : OSQLQuery() {} |
170 | ClearQuery::~ClearQuery() {} | 170 | ClearQuery::~ClearQuery() {} |
171 | QString ClearQuery::query()const { | 171 | QString ClearQuery::query()const { |
172 | QString qu = "drop table todolist"; | 172 | QString qu = "drop table todolist"; |
173 | return qu; | 173 | return qu; |
174 | } | 174 | } |
175 | FindQuery::FindQuery(int uid) | 175 | FindQuery::FindQuery(int uid) |
176 | : OSQLQuery(), m_uid(uid ) { | 176 | : OSQLQuery(), m_uid(uid ) { |
177 | } | 177 | } |
178 | FindQuery::~FindQuery() { | 178 | FindQuery::~FindQuery() { |
179 | } | 179 | } |
180 | QString FindQuery::query()const{ | 180 | QString FindQuery::query()const{ |
181 | QString qu = "select uid, categories, completed, progress, summary, "; | 181 | QString qu = "select uid, categories, completed, progress, summary, "; |
182 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); | 182 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); |
183 | return qu; | 183 | return qu; |
184 | } | 184 | } |
185 | 185 | ||
186 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 186 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
187 | OverDueQuery::~OverDueQuery() {} | 187 | OverDueQuery::~OverDueQuery() {} |
188 | QString OverDueQuery::query()const { | 188 | QString OverDueQuery::query()const { |
189 | QDate date = QDate::currentDate(); | 189 | QDate date = QDate::currentDate(); |
190 | QString str; | 190 | QString str; |
191 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 191 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); |
192 | 192 | ||
193 | return str; | 193 | return str; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 197 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
198 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 198 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
199 | EffQuery::~EffQuery() {} | 199 | EffQuery::~EffQuery() {} |
200 | QString EffQuery::query()const { | 200 | QString EffQuery::query()const { |
201 | return m_inc ? with() : out(); | 201 | return m_inc ? with() : out(); |
202 | } | 202 | } |
203 | QString EffQuery::with()const { | 203 | QString EffQuery::with()const { |
204 | QString str; | 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' ") | 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() ) | 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() ); | 207 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); |
208 | return str; | 208 | return str; |
209 | } | 209 | } |
210 | QString EffQuery::out()const { | 210 | QString EffQuery::out()const { |
211 | QString str; | 211 | QString str; |
212 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 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() ) | 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() ); | 214 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
215 | 215 | ||
216 | return str; | 216 | return str; |
217 | } | 217 | } |
218 | }; | 218 | }; |
219 | 219 | ||
220 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 220 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
221 | : OTodoAccessBackend(), m_dict(15) | 221 | : OTodoAccessBackend(), m_dict(15) |
222 | { | 222 | { |
223 | QString fi = file; | 223 | QString fi = file; |
224 | if ( fi.isEmpty() ) | 224 | if ( fi.isEmpty() ) |
225 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 225 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
226 | OSQLManager man; | 226 | OSQLManager man; |
227 | m_driver = man.standard(); | 227 | m_driver = man.standard(); |
228 | m_driver->setUrl(fi); | 228 | m_driver->setUrl(fi); |
229 | fillDict(); | 229 | fillDict(); |
230 | } | 230 | } |
231 | 231 | ||
232 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 232 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
233 | } | 233 | } |
234 | bool OTodoAccessBackendSQL::load(){ | 234 | bool OTodoAccessBackendSQL::load(){ |
235 | if (!m_driver->open() ) | 235 | if (!m_driver->open() ) |
236 | return false; | 236 | return false; |
237 | 237 | ||
238 | CreateQuery creat; | 238 | CreateQuery creat; |
239 | OSQLResult res = m_driver->query(&creat ); | 239 | OSQLResult res = m_driver->query(&creat ); |
240 | 240 | ||
241 | update(); | 241 | update(); |
242 | qWarning("loaded %d", m_uids.count() ); | 242 | qWarning("loaded %d", m_uids.count() ); |
243 | return true; | 243 | return true; |
244 | } | 244 | } |
245 | bool OTodoAccessBackendSQL::reload(){ | 245 | bool OTodoAccessBackendSQL::reload(){ |
246 | return load(); | 246 | return load(); |
247 | } | 247 | } |
248 | 248 | ||
249 | bool OTodoAccessBackendSQL::save(){ | 249 | bool OTodoAccessBackendSQL::save(){ |
250 | return m_driver->close(); | 250 | return m_driver->close(); |
251 | } | 251 | } |
252 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 252 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
253 | return m_uids; | 253 | return m_uids; |
254 | } | 254 | } |
255 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 255 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
256 | QArray<int> ints(0); | 256 | QArray<int> ints(0); |
257 | return ints; | 257 | return ints; |
258 | } | 258 | } |
259 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 259 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
260 | FindQuery query( uid ); | 260 | FindQuery query( uid ); |
261 | return todo( m_driver->query(&query) ); | 261 | return todo( m_driver->query(&query) ); |
262 | 262 | ||
263 | } | 263 | } |
264 | void OTodoAccessBackendSQL::clear() { | 264 | void OTodoAccessBackendSQL::clear() { |
265 | ClearQuery cle; | 265 | ClearQuery cle; |
266 | OSQLResult res = m_driver->query( &cle ); | 266 | OSQLResult res = m_driver->query( &cle ); |
267 | CreateQuery qu; | 267 | CreateQuery qu; |
268 | res = m_driver->query(&qu); | 268 | res = m_driver->query(&qu); |
269 | } | 269 | } |
270 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 270 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
271 | InsertQuery ins( t ); | 271 | InsertQuery ins( t ); |
272 | OSQLResult res = m_driver->query( &ins ); | 272 | OSQLResult res = m_driver->query( &ins ); |
273 | 273 | ||
274 | if ( res.state() == OSQLResult::Failure ) | 274 | if ( res.state() == OSQLResult::Failure ) |
275 | return false; | 275 | return false; |
276 | int c = m_uids.count(); | 276 | int c = m_uids.count(); |
277 | m_uids.resize( c+1 ); | 277 | m_uids.resize( c+1 ); |
278 | m_uids[c] = t.uid(); | 278 | m_uids[c] = t.uid(); |
279 | 279 | ||
280 | return true; | 280 | return true; |
281 | } | 281 | } |
282 | bool OTodoAccessBackendSQL::remove( int uid ) { | 282 | bool OTodoAccessBackendSQL::remove( int uid ) { |
283 | RemoveQuery rem( uid ); | 283 | RemoveQuery rem( uid ); |
284 | OSQLResult res = m_driver->query(&rem ); | 284 | OSQLResult res = m_driver->query(&rem ); |
285 | 285 | ||
286 | if ( res.state() == OSQLResult::Failure ) | 286 | if ( res.state() == OSQLResult::Failure ) |
287 | return false; | 287 | return false; |
288 | 288 | ||
289 | update(); | 289 | update(); |
290 | return true; | 290 | return true; |
291 | } | 291 | } |
292 | /* | 292 | /* |
293 | * FIXME better set query | 293 | * FIXME better set query |
294 | * but we need the cache for that | 294 | * but we need the cache for that |
295 | * now we remove | 295 | * now we remove |
296 | */ | 296 | */ |
297 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 297 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
298 | remove( t.uid() ); | 298 | remove( t.uid() ); |
299 | return add(t); | 299 | return add(t); |
300 | } | 300 | } |
301 | QArray<int> OTodoAccessBackendSQL::overDue() { | 301 | QArray<int> OTodoAccessBackendSQL::overDue() { |
302 | OverDueQuery qu; | 302 | OverDueQuery qu; |
303 | return uids( m_driver->query(&qu ) ); | 303 | return uids( m_driver->query(&qu ) ); |
304 | } | 304 | } |
305 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 305 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
306 | const QDate& t, | 306 | const QDate& t, |
307 | bool u) { | 307 | bool u) { |
308 | EffQuery ef(s, t, u ); | 308 | EffQuery ef(s, t, u ); |
309 | return uids (m_driver->query(&ef) ); | 309 | return uids (m_driver->query(&ef) ); |
310 | } | 310 | } |
311 | /* | ||
312 | * | ||
313 | */ | ||
311 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 314 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
312 | int sortFilter, int cat ) { | 315 | int sortFilter, int cat ) { |
313 | QArray<int> ints(0); | 316 | QString query; |
314 | return ints; | 317 | query = "select uid from todolist WHERE "; |
318 | |||
319 | /* | ||
320 | * Sort Filter stuff | ||
321 | * not that straight forward | ||
322 | * | ||
323 | */ | ||
324 | /* Category */ | ||
325 | if ( sortFilter & 1 ) { | ||
326 | query += " categories like '%" +QString::number(cat)+"%' AND"; | ||
327 | } | ||
328 | /* Show only overdue */ | ||
329 | if ( sortFilter & 2 ) { | ||
330 | QDate date = QDate::currentDate(); | ||
331 | QString due; | ||
332 | QString base; | ||
333 | base = QString("DueDate <= '%1-%2-%3' AND WHERE completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | ||
334 | query += " " + base + " AND"; | ||
335 | } | ||
336 | /* not show completed */ | ||
337 | if ( sortFilter & 4 ) { | ||
338 | query += " completed = 0 AND"; | ||
339 | }else{ | ||
340 | query += " ( completed = 1 OR completed = 0) AND"; | ||
341 | } | ||
342 | /* srtip the end */ | ||
343 | query = query.remove( query.length()-3, 3 ); | ||
344 | |||
345 | |||
346 | /* | ||
347 | * sort order stuff | ||
348 | * quite straight forward | ||
349 | */ | ||
350 | query += "ORDER BY "; | ||
351 | switch( sortOrder ) { | ||
352 | /* completed */ | ||
353 | case 0: | ||
354 | query += "completed"; | ||
355 | break; | ||
356 | case 1: | ||
357 | query += "priority"; | ||
358 | break; | ||
359 | case 2: | ||
360 | query += "description"; | ||
361 | break; | ||
362 | case 3: | ||
363 | query += "DueDate"; | ||
364 | break; | ||
365 | } | ||
366 | if ( !asc ) | ||
367 | query += " DESC"; | ||
368 | |||
369 | qWarning( query ); | ||
370 | OSQLRawQuery raw(query ); | ||
371 | return uids( m_driver->query(&raw) ); | ||
315 | } | 372 | } |
316 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 373 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
317 | if ( str == "0-0-0" ) | 374 | if ( str == "0-0-0" ) |
318 | return false; | 375 | return false; |
319 | else{ | 376 | else{ |
320 | int day, year, month; | 377 | int day, year, month; |
321 | QStringList list = QStringList::split("-", str ); | 378 | QStringList list = QStringList::split("-", str ); |
322 | year = list[0].toInt(); | 379 | year = list[0].toInt(); |
323 | month = list[1].toInt(); | 380 | month = list[1].toInt(); |
324 | day = list[2].toInt(); | 381 | day = list[2].toInt(); |
325 | da.setYMD( year, month, day ); | 382 | da.setYMD( year, month, day ); |
326 | return true; | 383 | return true; |
327 | } | 384 | } |
328 | } | 385 | } |
329 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 386 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
330 | if ( res.state() == OSQLResult::Failure ) { | 387 | if ( res.state() == OSQLResult::Failure ) { |
331 | OTodo to; | 388 | OTodo to; |
332 | return to; | 389 | return to; |
333 | } | 390 | } |
334 | 391 | ||
335 | OSQLResultItem::ValueList list = res.results(); | 392 | OSQLResultItem::ValueList list = res.results(); |
336 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 393 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
337 | 394 | ||
338 | bool has = false; QDate da = QDate::currentDate(); | 395 | bool has = false; QDate da = QDate::currentDate(); |
339 | has = date( da, (*it).data("DueDate") ); | 396 | has = date( da, (*it).data("DueDate") ); |
340 | QStringList cats = QStringList::split(";", (*it).data("categories") ); | 397 | QStringList cats = QStringList::split(";", (*it).data("categories") ); |
341 | 398 | ||
342 | OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), | 399 | OTodo to( (bool)(*it).data("completed").toInt(), (*it).data("priority").toInt(), |
343 | cats, (*it).data("summary"), (*it).data("description"), | 400 | cats, (*it).data("summary"), (*it).data("description"), |
344 | (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); | 401 | (*it).data("progress").toUShort(), has, da, (*it).data("uid").toInt() ); |
345 | return to; | 402 | return to; |
346 | } | 403 | } |
347 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 404 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
348 | FindQuery find( uid ); | 405 | FindQuery find( uid ); |
349 | return todo( m_driver->query(&find) ); | 406 | return todo( m_driver->query(&find) ); |
350 | } | 407 | } |
351 | /* | 408 | /* |
352 | * update the dict | 409 | * update the dict |
353 | */ | 410 | */ |
354 | void OTodoAccessBackendSQL::fillDict() { | 411 | void OTodoAccessBackendSQL::fillDict() { |
355 | /* initialize dict */ | 412 | /* initialize dict */ |
356 | /* | 413 | /* |
357 | * UPDATE dict if you change anything!!! | 414 | * UPDATE dict if you change anything!!! |
358 | */ | 415 | */ |
359 | m_dict.setAutoDelete( TRUE ); | 416 | m_dict.setAutoDelete( TRUE ); |
360 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 417 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
361 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 418 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
362 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 419 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
363 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 420 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
364 | m_dict.insert("Description" , new int(OTodo::Description) ); | 421 | m_dict.insert("Description" , new int(OTodo::Description) ); |
365 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 422 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
366 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 423 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
367 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 424 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
368 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 425 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
369 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 426 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
370 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 427 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
371 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 428 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
372 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 429 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
373 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 430 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
374 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 431 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
375 | } | 432 | } |
376 | void OTodoAccessBackendSQL::update() { | 433 | void OTodoAccessBackendSQL::update() { |
377 | LoadQuery lo; | 434 | LoadQuery lo; |
378 | OSQLResult res = m_driver->query(&lo); | 435 | OSQLResult res = m_driver->query(&lo); |
379 | if ( res.state() != OSQLResult::Success ) | 436 | if ( res.state() != OSQLResult::Success ) |
380 | return; | 437 | return; |
381 | 438 | ||
382 | m_uids = uids( res ); | 439 | m_uids = uids( res ); |
383 | } | 440 | } |
384 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 441 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
385 | 442 | ||
386 | OSQLResultItem::ValueList list = res.results(); | 443 | OSQLResultItem::ValueList list = res.results(); |
387 | OSQLResultItem::ValueList::Iterator it; | 444 | OSQLResultItem::ValueList::Iterator it; |
388 | QArray<int> ints(list.count() ); | 445 | QArray<int> ints(list.count() ); |
389 | 446 | ||
390 | int i = 0; | 447 | int i = 0; |
391 | for (it = list.begin(); it != list.end(); ++it ) { | 448 | for (it = list.begin(); it != list.end(); ++it ) { |
392 | ints[i] = (*it).data("uid").toInt(); | 449 | ints[i] = (*it).data("uid").toInt(); |
393 | i++; | 450 | i++; |
394 | } | 451 | } |
395 | return ints; | 452 | return ints; |
396 | } | 453 | } |
397 | 454 | ||
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index 966628d..6c5f50a 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h | |||
@@ -1,46 +1,46 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_SQL_H | 1 | #ifndef OPIE_PIM_ACCESS_SQL_H |
2 | #define OPIE_PIM_ACCESS_SQL_H | 2 | #define OPIE_PIM_ACCESS_SQL_H |
3 | 3 | ||
4 | #include <qasciidict.h> | 4 | #include <qasciidict.h> |
5 | 5 | ||
6 | #include "otodoaccessbackend.h" | 6 | #include "otodoaccessbackend.h" |
7 | 7 | ||
8 | class OSQLDriver; | 8 | class OSQLDriver; |
9 | class OSQLResult; | 9 | class OSQLResult; |
10 | class OTodoAccessBackendSQL : public OTodoAccessBackend { | 10 | class OTodoAccessBackendSQL : public OTodoAccessBackend { |
11 | public: | 11 | public: |
12 | OTodoAccessBackendSQL( const QString& file ); | 12 | OTodoAccessBackendSQL( const QString& file ); |
13 | ~OTodoAccessBackendSQL(); | 13 | ~OTodoAccessBackendSQL(); |
14 | 14 | ||
15 | bool load(); | 15 | bool load(); |
16 | bool reload(); | 16 | bool reload(); |
17 | bool save(); | 17 | bool save(); |
18 | QArray<int> allRecords()const; | 18 | QArray<int> allRecords()const; |
19 | 19 | ||
20 | QArray<int> queryByExample( const OTodo& t, int sort ); | 20 | QArray<int> queryByExample( const OTodo& t, int sort ); |
21 | OTodo find(int uid)const; | 21 | OTodo find(int uid)const; |
22 | void clear(); | 22 | void clear(); |
23 | bool add( const OTodo& t ); | 23 | bool add( const OTodo& t ); |
24 | bool remove( int uid ); | 24 | bool remove( int uid ); |
25 | bool replace( const OTodo& t ); | 25 | bool replace( const OTodo& t ); |
26 | 26 | ||
27 | QArray<int> overDue(); | 27 | QArray<int> overDue(); |
28 | QArray<int> effectiveToDos( const QDate& start, | 28 | QArray<int> effectiveToDos( const QDate& start, |
29 | const QDate& end, bool includeNoDates ); | 29 | const QDate& end, bool includeNoDates ); |
30 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 30 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
31 | 31 | ||
32 | private: | 32 | private: |
33 | void update(); | 33 | void update(); |
34 | void fillDict(); | 34 | void fillDict(); |
35 | bool date( QDate& date, const QString& )const; | 35 | inline bool date( QDate& date, const QString& )const; |
36 | OTodo todo( const OSQLResult& )const; | 36 | inline OTodo todo( const OSQLResult& )const; |
37 | QArray<int> uids( const OSQLResult& )const; | 37 | inline QArray<int> uids( const OSQLResult& )const; |
38 | OTodo todo( int uid )const; | 38 | OTodo todo( int uid )const; |
39 | 39 | ||
40 | QAsciiDict<int> m_dict; | 40 | QAsciiDict<int> m_dict; |
41 | OSQLDriver* m_driver; | 41 | OSQLDriver* m_driver; |
42 | QArray<int> m_uids; | 42 | QArray<int> m_uids; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | 45 | ||
46 | #endif | 46 | #endif |