summaryrefslogtreecommitdiff
path: root/libopie/pim/otodoaccesssql.cpp
Unidiff
Diffstat (limited to 'libopie/pim/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/otodoaccesssql.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
index ebd03bb..3913661 100644
--- a/libopie/pim/otodoaccesssql.cpp
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -30,256 +30,266 @@ namespace {
30 CreateQuery(); 30 CreateQuery();
31 ~CreateQuery(); 31 ~CreateQuery();
32 QString query()const; 32 QString query()const;
33 }; 33 };
34 34
35 /** 35 /**
36 * LoadQuery 36 * LoadQuery
37 * this one queries for all uids 37 * this one queries for all uids
38 */ 38 */
39 class LoadQuery : public OSQLQuery { 39 class LoadQuery : public OSQLQuery {
40 public: 40 public:
41 LoadQuery(); 41 LoadQuery();
42 ~LoadQuery(); 42 ~LoadQuery();
43 QString query()const; 43 QString query()const;
44 }; 44 };
45 45
46 /** 46 /**
47 * inserts/adds a OTodo to the table 47 * inserts/adds a OTodo to the table
48 */ 48 */
49 class InsertQuery : public OSQLQuery { 49 class InsertQuery : public OSQLQuery {
50 public: 50 public:
51 InsertQuery(const OTodo& ); 51 InsertQuery(const OTodo& );
52 ~InsertQuery(); 52 ~InsertQuery();
53 QString query()const; 53 QString query()const;
54 private: 54 private:
55 OTodo m_todo; 55 OTodo m_todo;
56 }; 56 };
57 57
58 /** 58 /**
59 * removes one from the table 59 * removes one from the table
60 */ 60 */
61 class RemoveQuery : public OSQLQuery { 61 class RemoveQuery : public OSQLQuery {
62 public: 62 public:
63 RemoveQuery(int uid ); 63 RemoveQuery(int uid );
64 ~RemoveQuery(); 64 ~RemoveQuery();
65 QString query()const; 65 QString query()const;
66 private: 66 private:
67 int m_uid; 67 int m_uid;
68 }; 68 };
69 69
70 /** 70 /**
71 * Clears (delete) a Table 71 * Clears (delete) a Table
72 */ 72 */
73 class ClearQuery : public OSQLQuery { 73 class ClearQuery : public OSQLQuery {
74 public: 74 public:
75 ClearQuery(); 75 ClearQuery();
76 ~ClearQuery(); 76 ~ClearQuery();
77 QString query()const; 77 QString query()const;
78 78
79 }; 79 };
80 80
81 /** 81 /**
82 * a find query 82 * a find query
83 */ 83 */
84 class FindQuery : public OSQLQuery { 84 class FindQuery : public OSQLQuery {
85 public: 85 public:
86 FindQuery(int uid); 86 FindQuery(int uid);
87 FindQuery(const QArray<int>& ); 87 FindQuery(const QArray<int>& );
88 ~FindQuery(); 88 ~FindQuery();
89 QString query()const; 89 QString query()const;
90 private: 90 private:
91 QString single()const; 91 QString single()const;
92 QString multi()const; 92 QString multi()const;
93 QArray<int> m_uids; 93 QArray<int> m_uids;
94 int m_uid; 94 int m_uid;
95 }; 95 };
96 96
97 /** 97 /**
98 * overdue query 98 * overdue query
99 */ 99 */
100 class OverDueQuery : public OSQLQuery { 100 class OverDueQuery : public OSQLQuery {
101 public: 101 public:
102 OverDueQuery(); 102 OverDueQuery();
103 ~OverDueQuery(); 103 ~OverDueQuery();
104 QString query()const; 104 QString query()const;
105 }; 105 };
106 class EffQuery : public OSQLQuery { 106 class EffQuery : public OSQLQuery {
107 public: 107 public:
108 EffQuery( const QDate&, const QDate&, bool inc ); 108 EffQuery( const QDate&, const QDate&, bool inc );
109 ~EffQuery(); 109 ~EffQuery();
110 QString query()const; 110 QString query()const;
111 private: 111 private:
112 QString with()const; 112 QString with()const;
113 QString out()const; 113 QString out()const;
114 QDate m_start; 114 QDate m_start;
115 QDate m_end; 115 QDate m_end;
116 bool m_inc :1; 116 bool m_inc :1;
117 }; 117 };
118 118
119 119
120 CreateQuery::CreateQuery() : OSQLQuery() {} 120 CreateQuery::CreateQuery() : OSQLQuery() {}
121 CreateQuery::~CreateQuery() {} 121 CreateQuery::~CreateQuery() {}
122 QString CreateQuery::query()const { 122 QString CreateQuery::query()const {
123 QString qu; 123 QString qu;
124 qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; 124 qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
125 qu += "description, summary, priority, DueDate, progress , state, "; 125 qu += "description, summary, priority, DueDate, progress , state, ";
126 qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);"; 126 // This is the recurrance-stuff .. Exceptions are currently not supported (see ORecur.cpp) ! (eilers)
127 qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
128 qu += "reminders, alarms, maintainer, startdate, completeddate);";
127 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; 129 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
128 return qu; 130 return qu;
129 } 131 }
130 132
131 LoadQuery::LoadQuery() : OSQLQuery() {} 133 LoadQuery::LoadQuery() : OSQLQuery() {}
132 LoadQuery::~LoadQuery() {} 134 LoadQuery::~LoadQuery() {}
133 QString LoadQuery::query()const { 135 QString LoadQuery::query()const {
134 QString qu; 136 QString qu;
135 // We do not need "distinct" here. The primary key is always unique.. 137 // We do not need "distinct" here. The primary key is always unique..
136 //qu += "select distinct uid from todolist"; 138 //qu += "select distinct uid from todolist";
137 qu += "select uid from todolist"; 139 qu += "select uid from todolist";
138 140
139 return qu; 141 return qu;
140 } 142 }
141 143
142 InsertQuery::InsertQuery( const OTodo& todo ) 144 InsertQuery::InsertQuery( const OTodo& todo )
143 : OSQLQuery(), m_todo( todo ) { 145 : OSQLQuery(), m_todo( todo ) {
144 } 146 }
145 InsertQuery::~InsertQuery() { 147 InsertQuery::~InsertQuery() {
146 } 148 }
147 /* 149 /*
148 * converts from a OTodo to a query 150 * converts from a OTodo to a query
149 * we leave out X-Ref + Alarms 151 * we leave out X-Ref + Alarms
150 */ 152 */
151 QString InsertQuery::query()const{ 153 QString InsertQuery::query()const{
152 154
153 int year, month, day; 155 int year, month, day;
154 year = month = day = 0; 156 year = month = day = 0;
155 if (m_todo.hasDueDate() ) { 157 if (m_todo.hasDueDate() ) {
156 QDate date = m_todo.dueDate(); 158 QDate date = m_todo.dueDate();
157 year = date.year(); 159 year = date.year();
158 month = date.month(); 160 month = date.month();
159 day = date.day(); 161 day = date.day();
160 } 162 }
161 int sYear = 0, sMonth = 0, sDay = 0; 163 int sYear = 0, sMonth = 0, sDay = 0;
162 if( m_todo.hasStartDate() ){ 164 if( m_todo.hasStartDate() ){
163 QDate sDate = m_todo.startDate(); 165 QDate sDate = m_todo.startDate();
164 sYear = sDate.year(); 166 sYear = sDate.year();
165 sMonth= sDate.month(); 167 sMonth= sDate.month();
166 sDay = sDate.day(); 168 sDay = sDate.day();
167 } 169 }
168 170
169 int eYear = 0, eMonth = 0, eDay = 0; 171 int eYear = 0, eMonth = 0, eDay = 0;
170 if( m_todo.hasCompletedDate() ){ 172 if( m_todo.hasCompletedDate() ){
171 QDate eDate = m_todo.completedDate(); 173 QDate eDate = m_todo.completedDate();
172 eYear = eDate.year(); 174 eYear = eDate.year();
173 eMonth= eDate.month(); 175 eMonth= eDate.month();
174 eDay = eDate.day(); 176 eDay = eDate.day();
175 } 177 }
176 QString qu; 178 QString qu;
179 QMap<int, QString> recMap = m_todo.recurrence().toMap();
177 qu = "insert into todolist VALUES(" 180 qu = "insert into todolist VALUES("
178 + QString::number( m_todo.uid() ) + "," 181 + QString::number( m_todo.uid() ) + ","
179 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 182 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
180 + QString::number( m_todo.isCompleted() ) + "," 183 + QString::number( m_todo.isCompleted() ) + ","
181 + "'" + m_todo.description() + "'" + "," 184 + "'" + m_todo.description() + "'" + ","
182 + "'" + m_todo.summary() + "'" + "," 185 + "'" + m_todo.summary() + "'" + ","
183 + QString::number(m_todo.priority() ) + "," 186 + QString::number(m_todo.priority() ) + ","
184 + "'" + QString::number(year) + "-" 187 + "'" + QString::number(year) + "-"
185 + QString::number(month) 188 + QString::number(month)
186 + "-" + QString::number( day ) + "'" + "," 189 + "-" + QString::number( day ) + "'" + ","
187 + QString::number( m_todo.progress() ) + "," 190 + QString::number( m_todo.progress() ) + ","
188 + QString::number( m_todo.state().state() ) + "," 191 + QString::number( m_todo.state().state() ) + ","
189 + "'" + m_todo.recurrence().toString() + "'"+ ","; 192 + "'" + recMap[ ORecur::RType ] + "'" + ","
193 + "'" + recMap[ ORecur::RWeekdays ] + "'" + ","
194 + "'" + recMap[ ORecur::RPosition ] + "'" + ","
195 + "'" + recMap[ ORecur::RFreq ] + "'" + ","
196 + "'" + recMap[ ORecur::RHasEndDate ] + "'" + ","
197 + "'" + recMap[ ORecur::EndDate ] + "'" + ","
198 + "'" + recMap[ ORecur::Created ] + "'" + ","
199 + "'" + recMap[ ORecur::Exceptions ] + "'" + ",";
190 200
191 if ( m_todo.hasNotifiers() ) { 201 if ( m_todo.hasNotifiers() ) {
192 OPimNotifyManager manager = m_todo.notifiers(); 202 OPimNotifyManager manager = m_todo.notifiers();
193 qu += "'" + manager.remindersToString() + "'" + "," 203 qu += "'" + manager.remindersToString() + "'" + ","
194 + "'" + manager.alarmsToString() + "'" + ","; 204 + "'" + manager.alarmsToString() + "'" + ",";
195 } 205 }
196 else{ 206 else{
197 qu += QString( "''" ) + "," 207 qu += QString( "''" ) + ","
198 + "''" + ","; 208 + "''" + ",";
199 } 209 }
200 210
201 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) 211 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
202 + "'" + QString::number(sYear) + "-" 212 + "'" + QString::number(sYear) + "-"
203 + QString::number(sMonth) 213 + QString::number(sMonth)
204 + "-" + QString::number(sDay) + "'" + "," 214 + "-" + QString::number(sDay) + "'" + ","
205 + "'" + QString::number(eYear) + "-" 215 + "'" + QString::number(eYear) + "-"
206 + QString::number(eMonth) 216 + QString::number(eMonth)
207 + "-"+QString::number(eDay) + "'" 217 + "-"+QString::number(eDay) + "'"
208 + ")"; 218 + ")";
209 219
210 qWarning("add %s", qu.latin1() ); 220 qWarning("add %s", qu.latin1() );
211 return qu; 221 return qu;
212 } 222 }
213 223
214 RemoveQuery::RemoveQuery(int uid ) 224 RemoveQuery::RemoveQuery(int uid )
215 : OSQLQuery(), m_uid( uid ) {} 225 : OSQLQuery(), m_uid( uid ) {}
216 RemoveQuery::~RemoveQuery() {} 226 RemoveQuery::~RemoveQuery() {}
217 QString RemoveQuery::query()const { 227 QString RemoveQuery::query()const {
218 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); 228 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid);
219 return qu; 229 return qu;
220 } 230 }
221 231
222 232
223 ClearQuery::ClearQuery() 233 ClearQuery::ClearQuery()
224 : OSQLQuery() {} 234 : OSQLQuery() {}
225 ClearQuery::~ClearQuery() {} 235 ClearQuery::~ClearQuery() {}
226 QString ClearQuery::query()const { 236 QString ClearQuery::query()const {
227 QString qu = "drop table todolist"; 237 QString qu = "drop table todolist";
228 return qu; 238 return qu;
229 } 239 }
230 FindQuery::FindQuery(int uid) 240 FindQuery::FindQuery(int uid)
231 : OSQLQuery(), m_uid(uid ) { 241 : OSQLQuery(), m_uid(uid ) {
232 } 242 }
233 FindQuery::FindQuery(const QArray<int>& ints) 243 FindQuery::FindQuery(const QArray<int>& ints)
234 : OSQLQuery(), m_uids(ints){ 244 : OSQLQuery(), m_uids(ints){
235 } 245 }
236 FindQuery::~FindQuery() { 246 FindQuery::~FindQuery() {
237 } 247 }
238 QString FindQuery::query()const{ 248 QString FindQuery::query()const{
239 if (m_uids.count() == 0 ) 249 if (m_uids.count() == 0 )
240 return single(); 250 return single();
241 else 251 else
242 return multi(); 252 return multi();
243 } 253 }
244 QString FindQuery::single()const{ 254 QString FindQuery::single()const{
245 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 255 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
246 return qu; 256 return qu;
247 } 257 }
248 QString FindQuery::multi()const { 258 QString FindQuery::multi()const {
249 QString qu = "select * from todolist where "; 259 QString qu = "select * from todolist where ";
250 for (uint i = 0; i < m_uids.count(); i++ ) { 260 for (uint i = 0; i < m_uids.count(); i++ ) {
251 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 261 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
252 } 262 }
253 qu.remove( qu.length()-2, 2 ); 263 qu.remove( qu.length()-2, 2 );
254 return qu; 264 return qu;
255 } 265 }
256 266
257 OverDueQuery::OverDueQuery(): OSQLQuery() {} 267 OverDueQuery::OverDueQuery(): OSQLQuery() {}
258 OverDueQuery::~OverDueQuery() {} 268 OverDueQuery::~OverDueQuery() {}
259 QString OverDueQuery::query()const { 269 QString OverDueQuery::query()const {
260 QDate date = QDate::currentDate(); 270 QDate date = QDate::currentDate();
261 QString str; 271 QString str;
262 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 272 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
263 273
264 return str; 274 return str;
265 } 275 }
266 276
267 277
268 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 278 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
269 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 279 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
270 EffQuery::~EffQuery() {} 280 EffQuery::~EffQuery() {}
271 QString EffQuery::query()const { 281 QString EffQuery::query()const {
272 return m_inc ? with() : out(); 282 return m_inc ? with() : out();
273 } 283 }
274 QString EffQuery::with()const { 284 QString EffQuery::with()const {
275 QString str; 285 QString str;
276 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 286 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
277 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) 287 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
278 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); 288 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
279 return str; 289 return str;
280 } 290 }
281 QString EffQuery::out()const { 291 QString EffQuery::out()const {
282 QString str; 292 QString str;
283 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 293 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
284 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) 294 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
285 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); 295 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
@@ -431,222 +441,235 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
431 * not that straight forward 441 * not that straight forward
432 * FIXME: Replace magic numbers 442 * FIXME: Replace magic numbers
433 * 443 *
434 */ 444 */
435 /* Category */ 445 /* Category */
436 if ( sortFilter & 1 ) { 446 if ( sortFilter & 1 ) {
437 QString str; 447 QString str;
438 if (cat != 0 ) str = QString::number( cat ); 448 if (cat != 0 ) str = QString::number( cat );
439 query += " categories like '%" +str+"%' AND"; 449 query += " categories like '%" +str+"%' AND";
440 } 450 }
441 /* Show only overdue */ 451 /* Show only overdue */
442 if ( sortFilter & 2 ) { 452 if ( sortFilter & 2 ) {
443 QDate date = QDate::currentDate(); 453 QDate date = QDate::currentDate();
444 QString due; 454 QString due;
445 QString base; 455 QString base;
446 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); 456 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() );
447 query += " " + base + " AND"; 457 query += " " + base + " AND";
448 } 458 }
449 /* not show completed */ 459 /* not show completed */
450 if ( sortFilter & 4 ) { 460 if ( sortFilter & 4 ) {
451 query += " completed = 0 AND"; 461 query += " completed = 0 AND";
452 }else{ 462 }else{
453 query += " ( completed = 1 OR completed = 0) AND"; 463 query += " ( completed = 1 OR completed = 0) AND";
454 } 464 }
455 /* srtip the end */ 465 /* srtip the end */
456 query = query.remove( query.length()-3, 3 ); 466 query = query.remove( query.length()-3, 3 );
457 467
458 468
459 /* 469 /*
460 * sort order stuff 470 * sort order stuff
461 * quite straight forward 471 * quite straight forward
462 */ 472 */
463 query += "ORDER BY "; 473 query += "ORDER BY ";
464 switch( sortOrder ) { 474 switch( sortOrder ) {
465 /* completed */ 475 /* completed */
466 case 0: 476 case 0:
467 query += "completed"; 477 query += "completed";
468 break; 478 break;
469 case 1: 479 case 1:
470 query += "priority"; 480 query += "priority";
471 break; 481 break;
472 case 2: 482 case 2:
473 query += "summary"; 483 query += "summary";
474 break; 484 break;
475 case 3: 485 case 3:
476 query += "DueDate"; 486 query += "DueDate";
477 break; 487 break;
478 } 488 }
479 489
480 if ( !asc ) { 490 if ( !asc ) {
481 qWarning("not ascending!"); 491 qWarning("not ascending!");
482 query += " DESC"; 492 query += " DESC";
483 } 493 }
484 494
485 qWarning( query ); 495 qWarning( query );
486 OSQLRawQuery raw(query ); 496 OSQLRawQuery raw(query );
487 return uids( m_driver->query(&raw) ); 497 return uids( m_driver->query(&raw) );
488} 498}
489bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 499bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
490 if ( str == "0-0-0" ) 500 if ( str == "0-0-0" )
491 return false; 501 return false;
492 else{ 502 else{
493 int day, year, month; 503 int day, year, month;
494 QStringList list = QStringList::split("-", str ); 504 QStringList list = QStringList::split("-", str );
495 year = list[0].toInt(); 505 year = list[0].toInt();
496 month = list[1].toInt(); 506 month = list[1].toInt();
497 day = list[2].toInt(); 507 day = list[2].toInt();
498 da.setYMD( year, month, day ); 508 da.setYMD( year, month, day );
499 return true; 509 return true;
500 } 510 }
501} 511}
502OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 512OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
503 if ( res.state() == OSQLResult::Failure ) { 513 if ( res.state() == OSQLResult::Failure ) {
504 OTodo to; 514 OTodo to;
505 return to; 515 return to;
506 } 516 }
507 517
508 OSQLResultItem::ValueList list = res.results(); 518 OSQLResultItem::ValueList list = res.results();
509 OSQLResultItem::ValueList::Iterator it = list.begin(); 519 OSQLResultItem::ValueList::Iterator it = list.begin();
510 qWarning("todo1"); 520 qWarning("todo1");
511 OTodo to = todo( (*it) ); 521 OTodo to = todo( (*it) );
512 cache( to ); 522 cache( to );
513 ++it; 523 ++it;
514 524
515 for ( ; it != list.end(); ++it ) { 525 for ( ; it != list.end(); ++it ) {
516 qWarning("caching"); 526 qWarning("caching");
517 cache( todo( (*it) ) ); 527 cache( todo( (*it) ) );
518 } 528 }
519 return to; 529 return to;
520} 530}
521OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 531OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
522 qWarning("todo"); 532 qWarning("todo");
523 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 533 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
524 hasDueDate = date( dueDate, item.data("DueDate") ); 534 hasDueDate = date( dueDate, item.data("DueDate") );
525 QStringList cats = QStringList::split(";", item.data("categories") ); 535 QStringList cats = QStringList::split(";", item.data("categories") );
526 536
537 qWarning("Item is completed: %d", item.data("completed").toInt() );
538
527 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 539 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
528 cats, item.data("summary"), item.data("description"), 540 cats, item.data("summary"), item.data("description"),
529 item.data("progress").toUShort(), hasDueDate, dueDate, 541 item.data("progress").toUShort(), hasDueDate, dueDate,
530 item.data("uid").toInt() ); 542 item.data("uid").toInt() );
531 543
532 bool isOk; 544 bool isOk;
533 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 545 int prioInt = QString( item.data("priority") ).toInt( &isOk );
534 if ( isOk ) 546 if ( isOk )
535 to.setPriority( prioInt ); 547 to.setPriority( prioInt );
536 548
537 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 549 bool hasStartDate = false; QDate startDate = QDate::currentDate();
538 hasStartDate = date( startDate, item.data("startdate") ); 550 hasStartDate = date( startDate, item.data("startdate") );
539 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 551 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
540 hasCompletedDate = date( completedDate, item.data("completeddate") ); 552 hasCompletedDate = date( completedDate, item.data("completeddate") );
541 553
542 if ( hasStartDate ) 554 if ( hasStartDate )
543 to.setStartDate( startDate ); 555 to.setStartDate( startDate );
544 if ( hasCompletedDate ) 556 if ( hasCompletedDate )
545 to.setCompletedDate( completedDate ); 557 to.setCompletedDate( completedDate );
546 558
547 OPimNotifyManager& manager = to.notifiers(); 559 OPimNotifyManager& manager = to.notifiers();
548 manager.alarmsFromString( item.data("alarms") ); 560 manager.alarmsFromString( item.data("alarms") );
549 manager.remindersFromString( item.data("reminders") ); 561 manager.remindersFromString( item.data("reminders") );
550 562
551 OPimState pimState; 563 OPimState pimState;
552 pimState.setState( QString( item.data("state") ).toInt() ); 564 pimState.setState( QString( item.data("state") ).toInt() );
553 to.setState( pimState ); 565 to.setState( pimState );
554 566
555 // Recurrence not supported yet 567 QMap<int, QString> recMap;
556 // to.setRecurrence( 568 recMap.insert( ORecur::RType , item.data("RType") );
569 recMap.insert( ORecur::RWeekdays , item.data("RWeekdays") );
570 recMap.insert( ORecur::RPosition , item.data("RPosition") );
571 recMap.insert( ORecur::RFreq , item.data("RFreq") );
572 recMap.insert( ORecur::RHasEndDate, item.data("RHasEndDate") );
573 recMap.insert( ORecur::EndDate , item.data("EndDate") );
574 recMap.insert( ORecur::Created , item.data("Created") );
575 recMap.insert( ORecur::Exceptions , item.data("Exceptions") );
576
577 ORecur recur;
578 recur.fromMap( recMap );
579 to.setRecurrence( recur );
557 580
558 return to; 581 return to;
559} 582}
560OTodo OTodoAccessBackendSQL::todo( int uid )const { 583OTodo OTodoAccessBackendSQL::todo( int uid )const {
561 FindQuery find( uid ); 584 FindQuery find( uid );
562 return todo( m_driver->query(&find) ); 585 return todo( m_driver->query(&find) );
563} 586}
564/* 587/*
565 * update the dict 588 * update the dict
566 */ 589 */
567void OTodoAccessBackendSQL::fillDict() { 590void OTodoAccessBackendSQL::fillDict() {
568 /* initialize dict */ 591 /* initialize dict */
569 /* 592 /*
570 * UPDATE dict if you change anything!!! 593 * UPDATE dict if you change anything!!!
571 * FIXME: Isn't this dict obsolete ? (eilers) 594 * FIXME: Isn't this dict obsolete ? (eilers)
572 */ 595 */
573 m_dict.setAutoDelete( TRUE ); 596 m_dict.setAutoDelete( TRUE );
574 m_dict.insert("Categories" , new int(OTodo::Category) ); 597 m_dict.insert("Categories" , new int(OTodo::Category) );
575 m_dict.insert("Uid" , new int(OTodo::Uid) ); 598 m_dict.insert("Uid" , new int(OTodo::Uid) );
576 m_dict.insert("HasDate" , new int(OTodo::HasDate) ); 599 m_dict.insert("HasDate" , new int(OTodo::HasDate) );
577 m_dict.insert("Completed" , new int(OTodo::Completed) ); 600 m_dict.insert("Completed" , new int(OTodo::Completed) );
578 m_dict.insert("Description" , new int(OTodo::Description) ); 601 m_dict.insert("Description" , new int(OTodo::Description) );
579 m_dict.insert("Summary" , new int(OTodo::Summary) ); 602 m_dict.insert("Summary" , new int(OTodo::Summary) );
580 m_dict.insert("Priority" , new int(OTodo::Priority) ); 603 m_dict.insert("Priority" , new int(OTodo::Priority) );
581 m_dict.insert("DateDay" , new int(OTodo::DateDay) ); 604 m_dict.insert("DateDay" , new int(OTodo::DateDay) );
582 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 605 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
583 m_dict.insert("DateYear" , new int(OTodo::DateYear) ); 606 m_dict.insert("DateYear" , new int(OTodo::DateYear) );
584 m_dict.insert("Progress" , new int(OTodo::Progress) ); 607 m_dict.insert("Progress" , new int(OTodo::Progress) );
585 m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) 608 m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers)
586 m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); 609 m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
587// m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) 610// m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers)
588// m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) 611// m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers)
589} 612}
590/* 613/*
591 * need to be const so let's fool the 614 * need to be const so let's fool the
592 * compiler :( 615 * compiler :(
593 */ 616 */
594void OTodoAccessBackendSQL::update()const { 617void OTodoAccessBackendSQL::update()const {
595 ((OTodoAccessBackendSQL*)this)->m_dirty = false; 618 ((OTodoAccessBackendSQL*)this)->m_dirty = false;
596 LoadQuery lo; 619 LoadQuery lo;
597 OSQLResult res = m_driver->query(&lo); 620 OSQLResult res = m_driver->query(&lo);
598 if ( res.state() != OSQLResult::Success ) 621 if ( res.state() != OSQLResult::Success )
599 return; 622 return;
600 623
601 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); 624 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res );
602} 625}
603QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 626QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
604 627
605 OSQLResultItem::ValueList list = res.results(); 628 OSQLResultItem::ValueList list = res.results();
606 OSQLResultItem::ValueList::Iterator it; 629 OSQLResultItem::ValueList::Iterator it;
607 QArray<int> ints(list.count() ); 630 QArray<int> ints(list.count() );
608 qWarning(" count = %d", list.count() ); 631 qWarning(" count = %d", list.count() );
609 632
610 int i = 0; 633 int i = 0;
611 for (it = list.begin(); it != list.end(); ++it ) { 634 for (it = list.begin(); it != list.end(); ++it ) {
612 ints[i] = (*it).data("uid").toInt(); 635 ints[i] = (*it).data("uid").toInt();
613 i++; 636 i++;
614 } 637 }
615 return ints; 638 return ints;
616} 639}
617 640
618QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 641QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
619{ 642{
620 643
621#warning OTodoAccessBackendSQL::matchRegexp() not implemented !! 644#warning OTodoAccessBackendSQL::matchRegexp() not implemented !!
622 645
623#if 0 646#if 0
624 647
625 Copied from xml-backend by not adapted to sql (eilers) 648 Copied from xml-backend by not adapted to sql (eilers)
626 649
627 QArray<int> m_currentQuery( m_events.count() ); 650 QArray<int> m_currentQuery( m_events.count() );
628 uint arraycounter = 0; 651 uint arraycounter = 0;
629 652
630 653
631 654
632 QMap<int, OTodo>::ConstIterator it; 655 QMap<int, OTodo>::ConstIterator it;
633 for (it = m_events.begin(); it != m_events.end(); ++it ) { 656 for (it = m_events.begin(); it != m_events.end(); ++it ) {
634 if ( it.data().match( r ) ) 657 if ( it.data().match( r ) )
635 m_currentQuery[arraycounter++] = it.data().uid(); 658 m_currentQuery[arraycounter++] = it.data().uid();
636 659
637 } 660 }
638 // Shrink to fit.. 661 // Shrink to fit..
639 m_currentQuery.resize(arraycounter); 662 m_currentQuery.resize(arraycounter);
640 663
641 return m_currentQuery; 664 return m_currentQuery;
642#endif 665#endif
643 QArray<int> empty; 666 QArray<int> empty;
644 return empty; 667 return empty;
645} 668}
646QBitArray OTodoAccessBackendSQL::supports()const { 669QBitArray OTodoAccessBackendSQL::supports()const {
647 670
648 return sup(); 671 return sup();
649} 672}
650 673
651QBitArray OTodoAccessBackendSQL::sup() const{ 674QBitArray OTodoAccessBackendSQL::sup() const{
652 675