Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index 944f82a..72232e5 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -30,25 +30,25 @@ | |||
30 | #include <qdatetime.h> | 30 | #include <qdatetime.h> |
31 | 31 | ||
32 | #include <qpe/global.h> | 32 | #include <qpe/global.h> |
33 | 33 | ||
34 | #include <opie2/osqldriver.h> | 34 | #include <opie2/osqldriver.h> |
35 | #include <opie2/osqlresult.h> | 35 | #include <opie2/osqlresult.h> |
36 | #include <opie2/osqlmanager.h> | 36 | #include <opie2/osqlmanager.h> |
37 | #include <opie2/osqlquery.h> | 37 | #include <opie2/osqlquery.h> |
38 | 38 | ||
39 | #include <opie2/otodoaccesssql.h> | 39 | #include <opie2/otodoaccesssql.h> |
40 | #include <opie2/opimstate.h> | 40 | #include <opie2/opimstate.h> |
41 | #include <opie2/opimnotifymanager.h> | 41 | #include <opie2/opimnotifymanager.h> |
42 | #include <opie2/orecur.h> | 42 | #include <opie2/opimrecurrence.h> |
43 | 43 | ||
44 | using namespace Opie; | 44 | using namespace Opie; |
45 | /* | 45 | /* |
46 | * first some query | 46 | * first some query |
47 | * CREATE query | 47 | * CREATE query |
48 | * LOAD query | 48 | * LOAD query |
49 | * INSERT | 49 | * INSERT |
50 | * REMOVE | 50 | * REMOVE |
51 | * CLEAR | 51 | * CLEAR |
52 | */ | 52 | */ |
53 | namespace { | 53 | namespace { |
54 | /** | 54 | /** |
@@ -64,33 +64,33 @@ namespace { | |||
64 | /** | 64 | /** |
65 | * LoadQuery | 65 | * LoadQuery |
66 | * this one queries for all uids | 66 | * this one queries for all uids |
67 | */ | 67 | */ |
68 | class LoadQuery : public OSQLQuery { | 68 | class LoadQuery : public OSQLQuery { |
69 | public: | 69 | public: |
70 | LoadQuery(); | 70 | LoadQuery(); |
71 | ~LoadQuery(); | 71 | ~LoadQuery(); |
72 | QString query()const; | 72 | QString query()const; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * inserts/adds a OTodo to the table | 76 | * inserts/adds a OPimTodo to the table |
77 | */ | 77 | */ |
78 | class InsertQuery : public OSQLQuery { | 78 | class InsertQuery : public OSQLQuery { |
79 | public: | 79 | public: |
80 | InsertQuery(const OTodo& ); | 80 | InsertQuery(const OPimTodo& ); |
81 | ~InsertQuery(); | 81 | ~InsertQuery(); |
82 | QString query()const; | 82 | QString query()const; |
83 | private: | 83 | private: |
84 | OTodo m_todo; | 84 | OPimTodo m_todo; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * removes one from the table | 88 | * removes one from the table |
89 | */ | 89 | */ |
90 | class RemoveQuery : public OSQLQuery { | 90 | class RemoveQuery : public OSQLQuery { |
91 | public: | 91 | public: |
92 | RemoveQuery(int uid ); | 92 | RemoveQuery(int uid ); |
93 | ~RemoveQuery(); | 93 | ~RemoveQuery(); |
94 | QString query()const; | 94 | QString query()const; |
95 | private: | 95 | private: |
96 | int m_uid; | 96 | int m_uid; |
@@ -143,49 +143,49 @@ namespace { | |||
143 | QDate m_start; | 143 | QDate m_start; |
144 | QDate m_end; | 144 | QDate m_end; |
145 | bool m_inc :1; | 145 | bool m_inc :1; |
146 | }; | 146 | }; |
147 | 147 | ||
148 | 148 | ||
149 | CreateQuery::CreateQuery() : OSQLQuery() {} | 149 | CreateQuery::CreateQuery() : OSQLQuery() {} |
150 | CreateQuery::~CreateQuery() {} | 150 | CreateQuery::~CreateQuery() {} |
151 | QString CreateQuery::query()const { | 151 | QString CreateQuery::query()const { |
152 | QString qu; | 152 | QString qu; |
153 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; | 153 | qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; |
154 | qu += "description, summary, priority, DueDate, progress , state, "; | 154 | qu += "description, summary, priority, DueDate, progress , state, "; |
155 | // This is the recurrance-stuff .. Exceptions are currently not supported (see ORecur.cpp) ! (eilers) | 155 | // This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers) |
156 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; | 156 | qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, "; |
157 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; | 157 | qu += "reminders, alarms, maintainer, startdate, completeddate);"; |
158 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 158 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
159 | return qu; | 159 | return qu; |
160 | } | 160 | } |
161 | 161 | ||
162 | LoadQuery::LoadQuery() : OSQLQuery() {} | 162 | LoadQuery::LoadQuery() : OSQLQuery() {} |
163 | LoadQuery::~LoadQuery() {} | 163 | LoadQuery::~LoadQuery() {} |
164 | QString LoadQuery::query()const { | 164 | QString LoadQuery::query()const { |
165 | QString qu; | 165 | QString qu; |
166 | // We do not need "distinct" here. The primary key is always unique.. | 166 | // We do not need "distinct" here. The primary key is always unique.. |
167 | //qu += "select distinct uid from todolist"; | 167 | //qu += "select distinct uid from todolist"; |
168 | qu += "select uid from todolist"; | 168 | qu += "select uid from todolist"; |
169 | 169 | ||
170 | return qu; | 170 | return qu; |
171 | } | 171 | } |
172 | 172 | ||
173 | InsertQuery::InsertQuery( const OTodo& todo ) | 173 | InsertQuery::InsertQuery( const OPimTodo& todo ) |
174 | : OSQLQuery(), m_todo( todo ) { | 174 | : OSQLQuery(), m_todo( todo ) { |
175 | } | 175 | } |
176 | InsertQuery::~InsertQuery() { | 176 | InsertQuery::~InsertQuery() { |
177 | } | 177 | } |
178 | /* | 178 | /* |
179 | * converts from a OTodo to a query | 179 | * converts from a OPimTodo to a query |
180 | * we leave out X-Ref + Alarms | 180 | * we leave out X-Ref + Alarms |
181 | */ | 181 | */ |
182 | QString InsertQuery::query()const{ | 182 | QString InsertQuery::query()const{ |
183 | 183 | ||
184 | int year, month, day; | 184 | int year, month, day; |
185 | year = month = day = 0; | 185 | year = month = day = 0; |
186 | if (m_todo.hasDueDate() ) { | 186 | if (m_todo.hasDueDate() ) { |
187 | QDate date = m_todo.dueDate(); | 187 | QDate date = m_todo.dueDate(); |
188 | year = date.year(); | 188 | year = date.year(); |
189 | month = date.month(); | 189 | month = date.month(); |
190 | day = date.day(); | 190 | day = date.day(); |
191 | } | 191 | } |
@@ -209,32 +209,32 @@ namespace { | |||
209 | qu = "insert into todolist VALUES(" | 209 | qu = "insert into todolist VALUES(" |
210 | + QString::number( m_todo.uid() ) + "," | 210 | + QString::number( m_todo.uid() ) + "," |
211 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," | 211 | + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," |
212 | + QString::number( m_todo.isCompleted() ) + "," | 212 | + QString::number( m_todo.isCompleted() ) + "," |
213 | + "'" + m_todo.description() + "'" + "," | 213 | + "'" + m_todo.description() + "'" + "," |
214 | + "'" + m_todo.summary() + "'" + "," | 214 | + "'" + m_todo.summary() + "'" + "," |
215 | + QString::number(m_todo.priority() ) + "," | 215 | + QString::number(m_todo.priority() ) + "," |
216 | + "'" + QString::number(year) + "-" | 216 | + "'" + QString::number(year) + "-" |
217 | + QString::number(month) | 217 | + QString::number(month) |
218 | + "-" + QString::number( day ) + "'" + "," | 218 | + "-" + QString::number( day ) + "'" + "," |
219 | + QString::number( m_todo.progress() ) + "," | 219 | + QString::number( m_todo.progress() ) + "," |
220 | + QString::number( m_todo.state().state() ) + "," | 220 | + QString::number( m_todo.state().state() ) + "," |
221 | + "'" + recMap[ ORecur::RType ] + "'" + "," | 221 | + "'" + recMap[ OPimRecurrence::RType ] + "'" + "," |
222 | + "'" + recMap[ ORecur::RWeekdays ] + "'" + "," | 222 | + "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + "," |
223 | + "'" + recMap[ ORecur::RPosition ] + "'" + "," | 223 | + "'" + recMap[ OPimRecurrence::RPosition ] + "'" + "," |
224 | + "'" + recMap[ ORecur::RFreq ] + "'" + "," | 224 | + "'" + recMap[ OPimRecurrence::RFreq ] + "'" + "," |
225 | + "'" + recMap[ ORecur::RHasEndDate ] + "'" + "," | 225 | + "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + "," |
226 | + "'" + recMap[ ORecur::EndDate ] + "'" + "," | 226 | + "'" + recMap[ OPimRecurrence::EndDate ] + "'" + "," |
227 | + "'" + recMap[ ORecur::Created ] + "'" + "," | 227 | + "'" + recMap[ OPimRecurrence::Created ] + "'" + "," |
228 | + "'" + recMap[ ORecur::Exceptions ] + "'" + ","; | 228 | + "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ","; |
229 | 229 | ||
230 | if ( m_todo.hasNotifiers() ) { | 230 | if ( m_todo.hasNotifiers() ) { |
231 | OPimNotifyManager manager = m_todo.notifiers(); | 231 | OPimNotifyManager manager = m_todo.notifiers(); |
232 | qu += "'" + manager.remindersToString() + "'" + "," | 232 | qu += "'" + manager.remindersToString() + "'" + "," |
233 | + "'" + manager.alarmsToString() + "'" + ","; | 233 | + "'" + manager.alarmsToString() + "'" + ","; |
234 | } | 234 | } |
235 | else{ | 235 | else{ |
236 | qu += QString( "''" ) + "," | 236 | qu += QString( "''" ) + "," |
237 | + "''" + ","; | 237 | + "''" + ","; |
238 | } | 238 | } |
239 | 239 | ||
240 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) | 240 | qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !) |
@@ -320,80 +320,80 @@ namespace { | |||
320 | QString EffQuery::out()const { | 320 | QString EffQuery::out()const { |
321 | QString str; | 321 | QString str; |
322 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 322 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
323 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 323 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
324 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 324 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
325 | 325 | ||
326 | return str; | 326 | return str; |
327 | } | 327 | } |
328 | }; | 328 | }; |
329 | 329 | ||
330 | 330 | ||
331 | namespace Opie { | 331 | namespace Opie { |
332 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 332 | OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file ) |
333 | : OTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) | 333 | : OPimTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true) |
334 | { | 334 | { |
335 | QString fi = file; | 335 | QString fi = file; |
336 | if ( fi.isEmpty() ) | 336 | if ( fi.isEmpty() ) |
337 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 337 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
338 | OSQLManager man; | 338 | OSQLManager man; |
339 | m_driver = man.standard(); | 339 | m_driver = man.standard(); |
340 | m_driver->setUrl(fi); | 340 | m_driver->setUrl(fi); |
341 | // fillDict(); | 341 | // fillDict(); |
342 | } | 342 | } |
343 | 343 | ||
344 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 344 | OPimTodoAccessBackendSQL::~OPimTodoAccessBackendSQL(){ |
345 | if( m_driver ) | 345 | if( m_driver ) |
346 | delete m_driver; | 346 | delete m_driver; |
347 | } | 347 | } |
348 | 348 | ||
349 | bool OTodoAccessBackendSQL::load(){ | 349 | bool OPimTodoAccessBackendSQL::load(){ |
350 | if (!m_driver->open() ) | 350 | if (!m_driver->open() ) |
351 | return false; | 351 | return false; |
352 | 352 | ||
353 | CreateQuery creat; | 353 | CreateQuery creat; |
354 | OSQLResult res = m_driver->query(&creat ); | 354 | OSQLResult res = m_driver->query(&creat ); |
355 | 355 | ||
356 | m_dirty = true; | 356 | m_dirty = true; |
357 | return true; | 357 | return true; |
358 | } | 358 | } |
359 | bool OTodoAccessBackendSQL::reload(){ | 359 | bool OPimTodoAccessBackendSQL::reload(){ |
360 | return load(); | 360 | return load(); |
361 | } | 361 | } |
362 | 362 | ||
363 | bool OTodoAccessBackendSQL::save(){ | 363 | bool OPimTodoAccessBackendSQL::save(){ |
364 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 364 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
365 | } | 365 | } |
366 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 366 | QArray<int> OPimTodoAccessBackendSQL::allRecords()const { |
367 | if (m_dirty ) | 367 | if (m_dirty ) |
368 | update(); | 368 | update(); |
369 | 369 | ||
370 | return m_uids; | 370 | return m_uids; |
371 | } | 371 | } |
372 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ | 372 | QArray<int> OPimTodoAccessBackendSQL::queryByExample( const OPimTodo& , int, const QDateTime& ){ |
373 | QArray<int> ints(0); | 373 | QArray<int> ints(0); |
374 | return ints; | 374 | return ints; |
375 | } | 375 | } |
376 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 376 | OPimTodo OPimTodoAccessBackendSQL::find(int uid ) const{ |
377 | FindQuery query( uid ); | 377 | FindQuery query( uid ); |
378 | return todo( m_driver->query(&query) ); | 378 | return todo( m_driver->query(&query) ); |
379 | 379 | ||
380 | } | 380 | } |
381 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 381 | OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
382 | uint cur, Frontend::CacheDirection dir ) const{ | 382 | uint cur, Frontend::CacheDirection dir ) const{ |
383 | uint CACHE = readAhead(); | 383 | uint CACHE = readAhead(); |
384 | qWarning("searching for %d", uid ); | 384 | qWarning("searching for %d", uid ); |
385 | QArray<int> search( CACHE ); | 385 | QArray<int> search( CACHE ); |
386 | uint size =0; | 386 | uint size =0; |
387 | OTodo to; | 387 | OPimTodo to; |
388 | 388 | ||
389 | // we try to cache CACHE items | 389 | // we try to cache CACHE items |
390 | switch( dir ) { | 390 | switch( dir ) { |
391 | /* forward */ | 391 | /* forward */ |
392 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) | 392 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) |
393 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 393 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
394 | qWarning("size %d %d", size, ints[i] ); | 394 | qWarning("size %d %d", size, ints[i] ); |
395 | search[size] = ints[i]; | 395 | search[size] = ints[i]; |
396 | size++; | 396 | size++; |
397 | } | 397 | } |
398 | break; | 398 | break; |
399 | /* reverse */ | 399 | /* reverse */ |
@@ -403,77 +403,77 @@ OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | |||
403 | size++; | 403 | size++; |
404 | } | 404 | } |
405 | break; | 405 | break; |
406 | } | 406 | } |
407 | search.resize( size ); | 407 | search.resize( size ); |
408 | FindQuery query( search ); | 408 | FindQuery query( search ); |
409 | OSQLResult res = m_driver->query( &query ); | 409 | OSQLResult res = m_driver->query( &query ); |
410 | if ( res.state() != OSQLResult::Success ) | 410 | if ( res.state() != OSQLResult::Success ) |
411 | return to; | 411 | return to; |
412 | 412 | ||
413 | return todo( res ); | 413 | return todo( res ); |
414 | } | 414 | } |
415 | void OTodoAccessBackendSQL::clear() { | 415 | void OPimTodoAccessBackendSQL::clear() { |
416 | ClearQuery cle; | 416 | ClearQuery cle; |
417 | OSQLResult res = m_driver->query( &cle ); | 417 | OSQLResult res = m_driver->query( &cle ); |
418 | CreateQuery qu; | 418 | CreateQuery qu; |
419 | res = m_driver->query(&qu); | 419 | res = m_driver->query(&qu); |
420 | } | 420 | } |
421 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 421 | bool OPimTodoAccessBackendSQL::add( const OPimTodo& t) { |
422 | InsertQuery ins( t ); | 422 | InsertQuery ins( t ); |
423 | OSQLResult res = m_driver->query( &ins ); | 423 | OSQLResult res = m_driver->query( &ins ); |
424 | 424 | ||
425 | if ( res.state() == OSQLResult::Failure ) | 425 | if ( res.state() == OSQLResult::Failure ) |
426 | return false; | 426 | return false; |
427 | int c = m_uids.count(); | 427 | int c = m_uids.count(); |
428 | m_uids.resize( c+1 ); | 428 | m_uids.resize( c+1 ); |
429 | m_uids[c] = t.uid(); | 429 | m_uids[c] = t.uid(); |
430 | 430 | ||
431 | return true; | 431 | return true; |
432 | } | 432 | } |
433 | bool OTodoAccessBackendSQL::remove( int uid ) { | 433 | bool OPimTodoAccessBackendSQL::remove( int uid ) { |
434 | RemoveQuery rem( uid ); | 434 | RemoveQuery rem( uid ); |
435 | OSQLResult res = m_driver->query(&rem ); | 435 | OSQLResult res = m_driver->query(&rem ); |
436 | 436 | ||
437 | if ( res.state() == OSQLResult::Failure ) | 437 | if ( res.state() == OSQLResult::Failure ) |
438 | return false; | 438 | return false; |
439 | 439 | ||
440 | m_dirty = true; | 440 | m_dirty = true; |
441 | return true; | 441 | return true; |
442 | } | 442 | } |
443 | /* | 443 | /* |
444 | * FIXME better set query | 444 | * FIXME better set query |
445 | * but we need the cache for that | 445 | * but we need the cache for that |
446 | * now we remove | 446 | * now we remove |
447 | */ | 447 | */ |
448 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 448 | bool OPimTodoAccessBackendSQL::replace( const OPimTodo& t) { |
449 | remove( t.uid() ); | 449 | remove( t.uid() ); |
450 | bool b= add(t); | 450 | bool b= add(t); |
451 | m_dirty = false; // we changed some stuff but the UID stayed the same | 451 | m_dirty = false; // we changed some stuff but the UID stayed the same |
452 | return b; | 452 | return b; |
453 | } | 453 | } |
454 | QArray<int> OTodoAccessBackendSQL::overDue() { | 454 | QArray<int> OPimTodoAccessBackendSQL::overDue() { |
455 | OverDueQuery qu; | 455 | OverDueQuery qu; |
456 | return uids( m_driver->query(&qu ) ); | 456 | return uids( m_driver->query(&qu ) ); |
457 | } | 457 | } |
458 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 458 | QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
459 | const QDate& t, | 459 | const QDate& t, |
460 | bool u) { | 460 | bool u) { |
461 | EffQuery ef(s, t, u ); | 461 | EffQuery ef(s, t, u ); |
462 | return uids (m_driver->query(&ef) ); | 462 | return uids (m_driver->query(&ef) ); |
463 | } | 463 | } |
464 | /* | 464 | /* |
465 | * | 465 | * |
466 | */ | 466 | */ |
467 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 467 | QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
468 | int sortFilter, int cat ) { | 468 | int sortFilter, int cat ) { |
469 | qWarning("sorted %d, %d", asc, sortOrder ); | 469 | qWarning("sorted %d, %d", asc, sortOrder ); |
470 | QString query; | 470 | QString query; |
471 | query = "select uid from todolist WHERE "; | 471 | query = "select uid from todolist WHERE "; |
472 | 472 | ||
473 | /* | 473 | /* |
474 | * Sort Filter stuff | 474 | * Sort Filter stuff |
475 | * not that straight forward | 475 | * not that straight forward |
476 | * FIXME: Replace magic numbers | 476 | * FIXME: Replace magic numbers |
477 | * | 477 | * |
478 | */ | 478 | */ |
479 | /* Category */ | 479 | /* Category */ |
@@ -521,65 +521,65 @@ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | |||
521 | break; | 521 | break; |
522 | } | 522 | } |
523 | 523 | ||
524 | if ( !asc ) { | 524 | if ( !asc ) { |
525 | qWarning("not ascending!"); | 525 | qWarning("not ascending!"); |
526 | query += " DESC"; | 526 | query += " DESC"; |
527 | } | 527 | } |
528 | 528 | ||
529 | qWarning( query ); | 529 | qWarning( query ); |
530 | OSQLRawQuery raw(query ); | 530 | OSQLRawQuery raw(query ); |
531 | return uids( m_driver->query(&raw) ); | 531 | return uids( m_driver->query(&raw) ); |
532 | } | 532 | } |
533 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 533 | bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
534 | if ( str == "0-0-0" ) | 534 | if ( str == "0-0-0" ) |
535 | return false; | 535 | return false; |
536 | else{ | 536 | else{ |
537 | int day, year, month; | 537 | int day, year, month; |
538 | QStringList list = QStringList::split("-", str ); | 538 | QStringList list = QStringList::split("-", str ); |
539 | year = list[0].toInt(); | 539 | year = list[0].toInt(); |
540 | month = list[1].toInt(); | 540 | month = list[1].toInt(); |
541 | day = list[2].toInt(); | 541 | day = list[2].toInt(); |
542 | da.setYMD( year, month, day ); | 542 | da.setYMD( year, month, day ); |
543 | return true; | 543 | return true; |
544 | } | 544 | } |
545 | } | 545 | } |
546 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 546 | OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
547 | if ( res.state() == OSQLResult::Failure ) { | 547 | if ( res.state() == OSQLResult::Failure ) { |
548 | OTodo to; | 548 | OPimTodo to; |
549 | return to; | 549 | return to; |
550 | } | 550 | } |
551 | 551 | ||
552 | OSQLResultItem::ValueList list = res.results(); | 552 | OSQLResultItem::ValueList list = res.results(); |
553 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 553 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
554 | qWarning("todo1"); | 554 | qWarning("todo1"); |
555 | OTodo to = todo( (*it) ); | 555 | OPimTodo to = todo( (*it) ); |
556 | cache( to ); | 556 | cache( to ); |
557 | ++it; | 557 | ++it; |
558 | 558 | ||
559 | for ( ; it != list.end(); ++it ) { | 559 | for ( ; it != list.end(); ++it ) { |
560 | qWarning("caching"); | 560 | qWarning("caching"); |
561 | cache( todo( (*it) ) ); | 561 | cache( todo( (*it) ) ); |
562 | } | 562 | } |
563 | return to; | 563 | return to; |
564 | } | 564 | } |
565 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 565 | OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
566 | qWarning("todo"); | 566 | qWarning("todo"); |
567 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); | 567 | bool hasDueDate = false; QDate dueDate = QDate::currentDate(); |
568 | hasDueDate = date( dueDate, item.data("DueDate") ); | 568 | hasDueDate = date( dueDate, item.data("DueDate") ); |
569 | QStringList cats = QStringList::split(";", item.data("categories") ); | 569 | QStringList cats = QStringList::split(";", item.data("categories") ); |
570 | 570 | ||
571 | qWarning("Item is completed: %d", item.data("completed").toInt() ); | 571 | qWarning("Item is completed: %d", item.data("completed").toInt() ); |
572 | 572 | ||
573 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 573 | OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
574 | cats, item.data("summary"), item.data("description"), | 574 | cats, item.data("summary"), item.data("description"), |
575 | item.data("progress").toUShort(), hasDueDate, dueDate, | 575 | item.data("progress").toUShort(), hasDueDate, dueDate, |
576 | item.data("uid").toInt() ); | 576 | item.data("uid").toInt() ); |
577 | 577 | ||
578 | bool isOk; | 578 | bool isOk; |
579 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); | 579 | int prioInt = QString( item.data("priority") ).toInt( &isOk ); |
580 | if ( isOk ) | 580 | if ( isOk ) |
581 | to.setPriority( prioInt ); | 581 | to.setPriority( prioInt ); |
582 | 582 | ||
583 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); | 583 | bool hasStartDate = false; QDate startDate = QDate::currentDate(); |
584 | hasStartDate = date( startDate, item.data("startdate") ); | 584 | hasStartDate = date( startDate, item.data("startdate") ); |
585 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); | 585 | bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); |
@@ -590,137 +590,137 @@ OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
590 | if ( hasCompletedDate ) | 590 | if ( hasCompletedDate ) |
591 | to.setCompletedDate( completedDate ); | 591 | to.setCompletedDate( completedDate ); |
592 | 592 | ||
593 | OPimNotifyManager& manager = to.notifiers(); | 593 | OPimNotifyManager& manager = to.notifiers(); |
594 | manager.alarmsFromString( item.data("alarms") ); | 594 | manager.alarmsFromString( item.data("alarms") ); |
595 | manager.remindersFromString( item.data("reminders") ); | 595 | manager.remindersFromString( item.data("reminders") ); |
596 | 596 | ||
597 | OPimState pimState; | 597 | OPimState pimState; |
598 | pimState.setState( QString( item.data("state") ).toInt() ); | 598 | pimState.setState( QString( item.data("state") ).toInt() ); |
599 | to.setState( pimState ); | 599 | to.setState( pimState ); |
600 | 600 | ||
601 | QMap<int, QString> recMap; | 601 | QMap<int, QString> recMap; |
602 | recMap.insert( ORecur::RType , item.data("RType") ); | 602 | recMap.insert( OPimRecurrence::RType , item.data("RType") ); |
603 | recMap.insert( ORecur::RWeekdays , item.data("RWeekdays") ); | 603 | recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") ); |
604 | recMap.insert( ORecur::RPosition , item.data("RPosition") ); | 604 | recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") ); |
605 | recMap.insert( ORecur::RFreq , item.data("RFreq") ); | 605 | recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") ); |
606 | recMap.insert( ORecur::RHasEndDate, item.data("RHasEndDate") ); | 606 | recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") ); |
607 | recMap.insert( ORecur::EndDate , item.data("EndDate") ); | 607 | recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") ); |
608 | recMap.insert( ORecur::Created , item.data("Created") ); | 608 | recMap.insert( OPimRecurrence::Created , item.data("Created") ); |
609 | recMap.insert( ORecur::Exceptions , item.data("Exceptions") ); | 609 | recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") ); |
610 | 610 | ||
611 | ORecur recur; | 611 | OPimRecurrence recur; |
612 | recur.fromMap( recMap ); | 612 | recur.fromMap( recMap ); |
613 | to.setRecurrence( recur ); | 613 | to.setRecurrence( recur ); |
614 | 614 | ||
615 | return to; | 615 | return to; |
616 | } | 616 | } |
617 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 617 | OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { |
618 | FindQuery find( uid ); | 618 | FindQuery find( uid ); |
619 | return todo( m_driver->query(&find) ); | 619 | return todo( m_driver->query(&find) ); |
620 | } | 620 | } |
621 | /* | 621 | /* |
622 | * update the dict | 622 | * update the dict |
623 | */ | 623 | */ |
624 | void OTodoAccessBackendSQL::fillDict() { | 624 | void OPimTodoAccessBackendSQL::fillDict() { |
625 | /* initialize dict */ | 625 | /* initialize dict */ |
626 | /* | 626 | /* |
627 | * UPDATE dict if you change anything!!! | 627 | * UPDATE dict if you change anything!!! |
628 | * FIXME: Isn't this dict obsolete ? (eilers) | 628 | * FIXME: Isn't this dict obsolete ? (eilers) |
629 | */ | 629 | */ |
630 | m_dict.setAutoDelete( TRUE ); | 630 | m_dict.setAutoDelete( TRUE ); |
631 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 631 | m_dict.insert("Categories" , new int(OPimTodo::Category) ); |
632 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 632 | m_dict.insert("Uid" , new int(OPimTodo::Uid) ); |
633 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 633 | m_dict.insert("HasDate" , new int(OPimTodo::HasDate) ); |
634 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 634 | m_dict.insert("Completed" , new int(OPimTodo::Completed) ); |
635 | m_dict.insert("Description" , new int(OTodo::Description) ); | 635 | m_dict.insert("Description" , new int(OPimTodo::Description) ); |
636 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 636 | m_dict.insert("Summary" , new int(OPimTodo::Summary) ); |
637 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 637 | m_dict.insert("Priority" , new int(OPimTodo::Priority) ); |
638 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 638 | m_dict.insert("DateDay" , new int(OPimTodo::DateDay) ); |
639 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 639 | m_dict.insert("DateMonth" , new int(OPimTodo::DateMonth) ); |
640 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 640 | m_dict.insert("DateYear" , new int(OPimTodo::DateYear) ); |
641 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 641 | m_dict.insert("Progress" , new int(OPimTodo::Progress) ); |
642 | m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) | 642 | m_dict.insert("Completed", new int(OPimTodo::Completed) ); // Why twice ? (eilers) |
643 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 643 | m_dict.insert("CrossReference", new int(OPimTodo::CrossReference) ); |
644 | // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) | 644 | // m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers) |
645 | // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) | 645 | // m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) |
646 | } | 646 | } |
647 | /* | 647 | /* |
648 | * need to be const so let's fool the | 648 | * need to be const so let's fool the |
649 | * compiler :( | 649 | * compiler :( |
650 | */ | 650 | */ |
651 | void OTodoAccessBackendSQL::update()const { | 651 | void OPimTodoAccessBackendSQL::update()const { |
652 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | 652 | ((OPimTodoAccessBackendSQL*)this)->m_dirty = false; |
653 | LoadQuery lo; | 653 | LoadQuery lo; |
654 | OSQLResult res = m_driver->query(&lo); | 654 | OSQLResult res = m_driver->query(&lo); |
655 | if ( res.state() != OSQLResult::Success ) | 655 | if ( res.state() != OSQLResult::Success ) |
656 | return; | 656 | return; |
657 | 657 | ||
658 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); | 658 | ((OPimTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
659 | } | 659 | } |
660 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 660 | QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
661 | 661 | ||
662 | OSQLResultItem::ValueList list = res.results(); | 662 | OSQLResultItem::ValueList list = res.results(); |
663 | OSQLResultItem::ValueList::Iterator it; | 663 | OSQLResultItem::ValueList::Iterator it; |
664 | QArray<int> ints(list.count() ); | 664 | QArray<int> ints(list.count() ); |
665 | qWarning(" count = %d", list.count() ); | 665 | qWarning(" count = %d", list.count() ); |
666 | 666 | ||
667 | int i = 0; | 667 | int i = 0; |
668 | for (it = list.begin(); it != list.end(); ++it ) { | 668 | for (it = list.begin(); it != list.end(); ++it ) { |
669 | ints[i] = (*it).data("uid").toInt(); | 669 | ints[i] = (*it).data("uid").toInt(); |
670 | i++; | 670 | i++; |
671 | } | 671 | } |
672 | return ints; | 672 | return ints; |
673 | } | 673 | } |
674 | 674 | ||
675 | QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | 675 | QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const |
676 | { | 676 | { |
677 | 677 | ||
678 | #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! | 678 | #warning OPimTodoAccessBackendSQL::matchRegexp() not implemented !! |
679 | 679 | ||
680 | #if 0 | 680 | #if 0 |
681 | 681 | ||
682 | Copied from xml-backend by not adapted to sql (eilers) | 682 | Copied from xml-backend by not adapted to sql (eilers) |
683 | 683 | ||
684 | QArray<int> m_currentQuery( m_events.count() ); | 684 | QArray<int> m_currentQuery( m_events.count() ); |
685 | uint arraycounter = 0; | 685 | uint arraycounter = 0; |
686 | 686 | ||
687 | 687 | ||
688 | 688 | ||
689 | QMap<int, OTodo>::ConstIterator it; | 689 | QMap<int, OPimTodo>::ConstIterator it; |
690 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | 690 | for (it = m_events.begin(); it != m_events.end(); ++it ) { |
691 | if ( it.data().match( r ) ) | 691 | if ( it.data().match( r ) ) |
692 | m_currentQuery[arraycounter++] = it.data().uid(); | 692 | m_currentQuery[arraycounter++] = it.data().uid(); |
693 | 693 | ||
694 | } | 694 | } |
695 | // Shrink to fit.. | 695 | // Shrink to fit.. |
696 | m_currentQuery.resize(arraycounter); | 696 | m_currentQuery.resize(arraycounter); |
697 | 697 | ||
698 | return m_currentQuery; | 698 | return m_currentQuery; |
699 | #endif | 699 | #endif |
700 | QArray<int> empty; | 700 | QArray<int> empty; |
701 | return empty; | 701 | return empty; |
702 | } | 702 | } |
703 | QBitArray OTodoAccessBackendSQL::supports()const { | 703 | QBitArray OPimTodoAccessBackendSQL::supports()const { |
704 | 704 | ||
705 | return sup(); | 705 | return sup(); |
706 | } | 706 | } |
707 | 707 | ||
708 | QBitArray OTodoAccessBackendSQL::sup() const{ | 708 | QBitArray OPimTodoAccessBackendSQL::sup() const{ |
709 | 709 | ||
710 | QBitArray ar( OTodo::CompletedDate + 1 ); | 710 | QBitArray ar( OPimTodo::CompletedDate + 1 ); |
711 | ar.fill( true ); | 711 | ar.fill( true ); |
712 | ar[OTodo::CrossReference] = false; | 712 | ar[OPimTodo::CrossReference] = false; |
713 | ar[OTodo::State ] = false; | 713 | ar[OPimTodo::State ] = false; |
714 | ar[OTodo::Reminders] = false; | 714 | ar[OPimTodo::Reminders] = false; |
715 | ar[OTodo::Notifiers] = false; | 715 | ar[OPimTodo::Notifiers] = false; |
716 | ar[OTodo::Maintainer] = false; | 716 | ar[OPimTodo::Maintainer] = false; |
717 | 717 | ||
718 | return ar; | 718 | return ar; |
719 | } | 719 | } |
720 | 720 | ||
721 | void OTodoAccessBackendSQL::removeAllCompleted(){ | 721 | void OPimTodoAccessBackendSQL::removeAllCompleted(){ |
722 | #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! | 722 | #warning OPimTodoAccessBackendSQL::removeAllCompleted() not implemented !! |
723 | 723 | ||
724 | } | 724 | } |
725 | 725 | ||
726 | } | 726 | } |