Diffstat (limited to 'libopie/pim/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index ec9c14c..23e0c3e 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -1,21 +1,21 @@ | |||
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 <opie2/osqldriver.h> |
7 | #include <opie/osqlresult.h> | 7 | #include <opie2/osqlresult.h> |
8 | #include <opie/osqlmanager.h> | 8 | #include <opie2/osqlmanager.h> |
9 | #include <opie/osqlquery.h> | 9 | #include <opie2/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 { |
@@ -240,25 +240,25 @@ namespace { | |||
240 | } | 240 | } |
241 | }; | 241 | }; |
242 | 242 | ||
243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
244 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) | 244 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) |
245 | { | 245 | { |
246 | QString fi = file; | 246 | QString fi = file; |
247 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
249 | OSQLManager man; | 249 | OSQLManager man; |
250 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
251 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
252 | fillDict(); | 252 | // fillDict(); |
253 | } | 253 | } |
254 | 254 | ||
255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
256 | } | 256 | } |
257 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
258 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
259 | return false; | 259 | return false; |
260 | 260 | ||
261 | CreateQuery creat; | 261 | CreateQuery creat; |
262 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
263 | 263 | ||
264 | m_dirty = true; | 264 | m_dirty = true; |
@@ -288,33 +288,33 @@ OTodo OTodoAccessBackendSQL::find(int uid ) const{ | |||
288 | } | 288 | } |
289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
290 | uint cur, Frontend::CacheDirection dir ) const{ | 290 | uint cur, Frontend::CacheDirection dir ) const{ |
291 | int CACHE = readAhead(); | 291 | int CACHE = readAhead(); |
292 | qWarning("searching for %d", uid ); | 292 | qWarning("searching for %d", uid ); |
293 | QArray<int> search( CACHE ); | 293 | QArray<int> search( CACHE ); |
294 | uint size =0; | 294 | uint size =0; |
295 | OTodo to; | 295 | OTodo to; |
296 | 296 | ||
297 | // we try to cache CACHE items | 297 | // we try to cache CACHE items |
298 | switch( dir ) { | 298 | switch( dir ) { |
299 | /* forward */ | 299 | /* forward */ |
300 | case 0: | 300 | case 0: // FIXME: Not a good style to use magic numbers here (eilers) |
301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { | 301 | for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { |
302 | qWarning("size %d %d", size, ints[i] ); | 302 | qWarning("size %d %d", size, ints[i] ); |
303 | search[size] = ints[i]; | 303 | search[size] = ints[i]; |
304 | size++; | 304 | size++; |
305 | } | 305 | } |
306 | break; | 306 | break; |
307 | /* reverse */ | 307 | /* reverse */ |
308 | case 1: | 308 | case 1: // FIXME: Not a good style to use magic numbers here (eilers) |
309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { | 309 | for (uint i = cur; i != 0 && size < CACHE; i-- ) { |
310 | search[size] = ints[i]; | 310 | search[size] = ints[i]; |
311 | size++; | 311 | size++; |
312 | } | 312 | } |
313 | break; | 313 | break; |
314 | } | 314 | } |
315 | search.resize( size ); | 315 | search.resize( size ); |
316 | FindQuery query( search ); | 316 | FindQuery query( search ); |
317 | OSQLResult res = m_driver->query( &query ); | 317 | OSQLResult res = m_driver->query( &query ); |
318 | if ( res.state() != OSQLResult::Success ) | 318 | if ( res.state() != OSQLResult::Success ) |
319 | return to; | 319 | return to; |
320 | 320 | ||
@@ -372,24 +372,25 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | |||
372 | /* | 372 | /* |
373 | * | 373 | * |
374 | */ | 374 | */ |
375 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 375 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
376 | int sortFilter, int cat ) { | 376 | int sortFilter, int cat ) { |
377 | qWarning("sorted %d, %d", asc, sortOrder ); | 377 | qWarning("sorted %d, %d", asc, sortOrder ); |
378 | QString query; | 378 | QString query; |
379 | query = "select uid from todolist WHERE "; | 379 | query = "select uid from todolist WHERE "; |
380 | 380 | ||
381 | /* | 381 | /* |
382 | * Sort Filter stuff | 382 | * Sort Filter stuff |
383 | * not that straight forward | 383 | * not that straight forward |
384 | * FIXME: Replace magic numbers | ||
384 | * | 385 | * |
385 | */ | 386 | */ |
386 | /* Category */ | 387 | /* Category */ |
387 | if ( sortFilter & 1 ) { | 388 | if ( sortFilter & 1 ) { |
388 | QString str; | 389 | QString str; |
389 | if (cat != 0 ) str = QString::number( cat ); | 390 | if (cat != 0 ) str = QString::number( cat ); |
390 | query += " categories like '%" +str+"%' AND"; | 391 | query += " categories like '%" +str+"%' AND"; |
391 | } | 392 | } |
392 | /* Show only overdue */ | 393 | /* Show only overdue */ |
393 | if ( sortFilter & 2 ) { | 394 | if ( sortFilter & 2 ) { |
394 | QDate date = QDate::currentDate(); | 395 | QDate date = QDate::currentDate(); |
395 | QString due; | 396 | QString due; |
@@ -483,41 +484,42 @@ OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | |||
483 | } | 484 | } |
484 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 485 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
485 | FindQuery find( uid ); | 486 | FindQuery find( uid ); |
486 | return todo( m_driver->query(&find) ); | 487 | return todo( m_driver->query(&find) ); |
487 | } | 488 | } |
488 | /* | 489 | /* |
489 | * update the dict | 490 | * update the dict |
490 | */ | 491 | */ |
491 | void OTodoAccessBackendSQL::fillDict() { | 492 | void OTodoAccessBackendSQL::fillDict() { |
492 | /* initialize dict */ | 493 | /* initialize dict */ |
493 | /* | 494 | /* |
494 | * UPDATE dict if you change anything!!! | 495 | * UPDATE dict if you change anything!!! |
496 | * FIXME: Isn't this dict obsolete ? (eilers) | ||
495 | */ | 497 | */ |
496 | m_dict.setAutoDelete( TRUE ); | 498 | m_dict.setAutoDelete( TRUE ); |
497 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 499 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
498 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 500 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
499 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 501 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
500 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 502 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
501 | m_dict.insert("Description" , new int(OTodo::Description) ); | 503 | m_dict.insert("Description" , new int(OTodo::Description) ); |
502 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 504 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
503 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 505 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
504 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 506 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
505 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 507 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
506 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 508 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
507 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 509 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
508 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 510 | m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) |
509 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 511 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
510 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 512 | // m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) |
511 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 513 | // m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) |
512 | } | 514 | } |
513 | /* | 515 | /* |
514 | * need to be const so let's fool the | 516 | * need to be const so let's fool the |
515 | * compiler :( | 517 | * compiler :( |
516 | */ | 518 | */ |
517 | void OTodoAccessBackendSQL::update()const { | 519 | void OTodoAccessBackendSQL::update()const { |
518 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | 520 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; |
519 | LoadQuery lo; | 521 | LoadQuery lo; |
520 | OSQLResult res = m_driver->query(&lo); | 522 | OSQLResult res = m_driver->query(&lo); |
521 | if ( res.state() != OSQLResult::Success ) | 523 | if ( res.state() != OSQLResult::Success ) |
522 | return; | 524 | return; |
523 | 525 | ||
@@ -529,12 +531,63 @@ QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | |||
529 | OSQLResultItem::ValueList::Iterator it; | 531 | OSQLResultItem::ValueList::Iterator it; |
530 | QArray<int> ints(list.count() ); | 532 | QArray<int> ints(list.count() ); |
531 | qWarning(" count = %d", list.count() ); | 533 | qWarning(" count = %d", list.count() ); |
532 | 534 | ||
533 | int i = 0; | 535 | int i = 0; |
534 | for (it = list.begin(); it != list.end(); ++it ) { | 536 | for (it = list.begin(); it != list.end(); ++it ) { |
535 | ints[i] = (*it).data("uid").toInt(); | 537 | ints[i] = (*it).data("uid").toInt(); |
536 | i++; | 538 | i++; |
537 | } | 539 | } |
538 | return ints; | 540 | return ints; |
539 | } | 541 | } |
540 | 542 | ||
543 | QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const | ||
544 | { | ||
545 | |||
546 | #warning OTodoAccessBackendSQL::matchRegexp() not implemented !! | ||
547 | |||
548 | #if 0 | ||
549 | |||
550 | Copied from xml-backend by not adapted to sql (eilers) | ||
551 | |||
552 | QArray<int> m_currentQuery( m_events.count() ); | ||
553 | uint arraycounter = 0; | ||
554 | |||
555 | |||
556 | |||
557 | QMap<int, OTodo>::ConstIterator it; | ||
558 | for (it = m_events.begin(); it != m_events.end(); ++it ) { | ||
559 | if ( it.data().match( r ) ) | ||
560 | m_currentQuery[arraycounter++] = it.data().uid(); | ||
561 | |||
562 | } | ||
563 | // Shrink to fit.. | ||
564 | m_currentQuery.resize(arraycounter); | ||
565 | |||
566 | return m_currentQuery; | ||
567 | #endif | ||
568 | QArray<int> empty; | ||
569 | return empty; | ||
570 | } | ||
571 | QBitArray OTodoAccessBackendSQL::supports()const { | ||
572 | |||
573 | static QBitArray ar = sup(); | ||
574 | return ar; | ||
575 | } | ||
576 | |||
577 | QBitArray OTodoAccessBackendSQL::sup() { | ||
578 | |||
579 | QBitArray ar( OTodo::CompletedDate + 1 ); | ||
580 | ar.fill( true ); | ||
581 | ar[OTodo::CrossReference] = false; | ||
582 | ar[OTodo::State ] = false; | ||
583 | ar[OTodo::Reminders] = false; | ||
584 | ar[OTodo::Notifiers] = false; | ||
585 | ar[OTodo::Maintainer] = false; | ||
586 | |||
587 | return ar; | ||
588 | } | ||
589 | |||
590 | void OTodoAccessBackendSQL::removeAllCompleted(){ | ||
591 | #warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! | ||
592 | |||
593 | } | ||