author | eilers <eilers> | 2004-04-28 09:22:02 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-04-28 09:22:02 (UTC) |
commit | 134b7accd6bdc8fbc160a42f7c52c585e73f4add (patch) (unidiff) | |
tree | 5e221e990d0c94e38d816e147762f205733b0e72 | |
parent | 8ce67859c54234dabd88e17a0bc72369ea8301a3 (diff) | |
download | opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.zip opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.tar.gz opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.tar.bz2 |
Some modifications to alow use of generic OPimRecords without need to
cast them manually to the right type
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 28 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.h | 6 |
9 files changed, 65 insertions, 15 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 401a3c1..14207be 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -337,192 +337,193 @@ namespace { | |||
337 | QString qu = "select uid, type, value from custom_data where uid = "; | 337 | QString qu = "select uid, type, value from custom_data where uid = "; |
338 | qu += QString::number(m_uid); | 338 | qu += QString::number(m_uid); |
339 | return qu; | 339 | return qu; |
340 | } | 340 | } |
341 | 341 | ||
342 | }; | 342 | }; |
343 | 343 | ||
344 | 344 | ||
345 | /* --------------------------------------------------------------------------- */ | 345 | /* --------------------------------------------------------------------------- */ |
346 | 346 | ||
347 | namespace Opie { | 347 | namespace Opie { |
348 | 348 | ||
349 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, | 349 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, |
350 | const QString& filename ): | 350 | const QString& filename ): |
351 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) | 351 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) |
352 | { | 352 | { |
353 | qDebug("C'tor OPimContactAccessBackend_SQL starts"); | 353 | qDebug("C'tor OPimContactAccessBackend_SQL starts"); |
354 | QTime t; | 354 | QTime t; |
355 | t.start(); | 355 | t.start(); |
356 | 356 | ||
357 | /* Expecting to access the default filename if nothing else is set */ | 357 | /* Expecting to access the default filename if nothing else is set */ |
358 | if ( filename.isEmpty() ){ | 358 | if ( filename.isEmpty() ){ |
359 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); | 359 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); |
360 | } else | 360 | } else |
361 | m_fileName = filename; | 361 | m_fileName = filename; |
362 | 362 | ||
363 | // Get the standart sql-driver from the OSQLManager.. | 363 | // Get the standart sql-driver from the OSQLManager.. |
364 | OSQLManager man; | 364 | OSQLManager man; |
365 | m_driver = man.standard(); | 365 | m_driver = man.standard(); |
366 | m_driver->setUrl( m_fileName ); | 366 | m_driver->setUrl( m_fileName ); |
367 | 367 | ||
368 | load(); | 368 | load(); |
369 | 369 | ||
370 | qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); | 370 | qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); |
371 | } | 371 | } |
372 | 372 | ||
373 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () | 373 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () |
374 | { | 374 | { |
375 | if( m_driver ) | 375 | if( m_driver ) |
376 | delete m_driver; | 376 | delete m_driver; |
377 | } | 377 | } |
378 | 378 | ||
379 | bool OPimContactAccessBackend_SQL::load () | 379 | bool OPimContactAccessBackend_SQL::load () |
380 | { | 380 | { |
381 | if (!m_driver->open() ) | 381 | if (!m_driver->open() ) |
382 | return false; | 382 | return false; |
383 | 383 | ||
384 | // Don't expect that the database exists. | 384 | // Don't expect that the database exists. |
385 | // It is save here to create the table, even if it | 385 | // It is save here to create the table, even if it |
386 | // do exist. ( Is that correct for all databases ?? ) | 386 | // do exist. ( Is that correct for all databases ?? ) |
387 | CreateQuery creat; | 387 | CreateQuery creat; |
388 | OSQLResult res = m_driver->query( &creat ); | 388 | OSQLResult res = m_driver->query( &creat ); |
389 | 389 | ||
390 | update(); | 390 | update(); |
391 | 391 | ||
392 | return true; | 392 | return true; |
393 | 393 | ||
394 | } | 394 | } |
395 | 395 | ||
396 | bool OPimContactAccessBackend_SQL::reload() | 396 | bool OPimContactAccessBackend_SQL::reload() |
397 | { | 397 | { |
398 | return load(); | 398 | return load(); |
399 | } | 399 | } |
400 | 400 | ||
401 | bool OPimContactAccessBackend_SQL::save() | 401 | bool OPimContactAccessBackend_SQL::save() |
402 | { | 402 | { |
403 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 403 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void OPimContactAccessBackend_SQL::clear () | 407 | void OPimContactAccessBackend_SQL::clear () |
408 | { | 408 | { |
409 | ClearQuery cle; | 409 | ClearQuery cle; |
410 | OSQLResult res = m_driver->query( &cle ); | 410 | OSQLResult res = m_driver->query( &cle ); |
411 | 411 | ||
412 | reload(); | 412 | reload(); |
413 | } | 413 | } |
414 | 414 | ||
415 | bool OPimContactAccessBackend_SQL::wasChangedExternally() | 415 | bool OPimContactAccessBackend_SQL::wasChangedExternally() |
416 | { | 416 | { |
417 | return false; | 417 | return false; |
418 | } | 418 | } |
419 | 419 | ||
420 | QArray<int> OPimContactAccessBackend_SQL::allRecords() const | 420 | QArray<int> OPimContactAccessBackend_SQL::allRecords() const |
421 | { | 421 | { |
422 | 422 | ||
423 | // FIXME: Think about cute handling of changed tables.. | 423 | // FIXME: Think about cute handling of changed tables.. |
424 | // Thus, we don't have to call update here... | 424 | // Thus, we don't have to call update here... |
425 | if ( m_changed ) | 425 | if ( m_changed ) |
426 | ((OPimContactAccessBackend_SQL*)this)->update(); | 426 | ((OPimContactAccessBackend_SQL*)this)->update(); |
427 | 427 | ||
428 | return m_uids; | 428 | return m_uids; |
429 | } | 429 | } |
430 | 430 | ||
431 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) | 431 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) |
432 | { | 432 | { |
433 | qDebug("add in contact SQL-Backend"); | ||
433 | InsertQuery ins( newcontact ); | 434 | InsertQuery ins( newcontact ); |
434 | OSQLResult res = m_driver->query( &ins ); | 435 | OSQLResult res = m_driver->query( &ins ); |
435 | 436 | ||
436 | if ( res.state() == OSQLResult::Failure ) | 437 | if ( res.state() == OSQLResult::Failure ) |
437 | return false; | 438 | return false; |
438 | 439 | ||
439 | int c = m_uids.count(); | 440 | int c = m_uids.count(); |
440 | m_uids.resize( c+1 ); | 441 | m_uids.resize( c+1 ); |
441 | m_uids[c] = newcontact.uid(); | 442 | m_uids[c] = newcontact.uid(); |
442 | 443 | ||
443 | return true; | 444 | return true; |
444 | } | 445 | } |
445 | 446 | ||
446 | 447 | ||
447 | bool OPimContactAccessBackend_SQL::remove ( int uid ) | 448 | bool OPimContactAccessBackend_SQL::remove ( int uid ) |
448 | { | 449 | { |
449 | RemoveQuery rem( uid ); | 450 | RemoveQuery rem( uid ); |
450 | OSQLResult res = m_driver->query(&rem ); | 451 | OSQLResult res = m_driver->query(&rem ); |
451 | 452 | ||
452 | if ( res.state() == OSQLResult::Failure ) | 453 | if ( res.state() == OSQLResult::Failure ) |
453 | return false; | 454 | return false; |
454 | 455 | ||
455 | m_changed = true; | 456 | m_changed = true; |
456 | 457 | ||
457 | return true; | 458 | return true; |
458 | } | 459 | } |
459 | 460 | ||
460 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) | 461 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) |
461 | { | 462 | { |
462 | if ( !remove( contact.uid() ) ) | 463 | if ( !remove( contact.uid() ) ) |
463 | return false; | 464 | return false; |
464 | 465 | ||
465 | return add( contact ); | 466 | return add( contact ); |
466 | } | 467 | } |
467 | 468 | ||
468 | 469 | ||
469 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | 470 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const |
470 | { | 471 | { |
471 | qDebug("OPimContactAccessBackend_SQL::find()"); | 472 | qDebug("OPimContactAccessBackend_SQL::find()"); |
472 | QTime t; | 473 | QTime t; |
473 | t.start(); | 474 | t.start(); |
474 | 475 | ||
475 | OPimContact retContact( requestNonCustom( uid ) ); | 476 | OPimContact retContact( requestNonCustom( uid ) ); |
476 | retContact.setExtraMap( requestCustom( uid ) ); | 477 | retContact.setExtraMap( requestCustom( uid ) ); |
477 | 478 | ||
478 | qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); | 479 | qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); |
479 | return retContact; | 480 | return retContact; |
480 | } | 481 | } |
481 | 482 | ||
482 | 483 | ||
483 | 484 | ||
484 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) | 485 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) |
485 | { | 486 | { |
486 | QString qu = "SELECT uid FROM addressbook WHERE"; | 487 | QString qu = "SELECT uid FROM addressbook WHERE"; |
487 | QString searchQuery =""; | 488 | QString searchQuery =""; |
488 | 489 | ||
489 | QDate startDate; | 490 | QDate startDate; |
490 | 491 | ||
491 | if ( qd.isValid() ) | 492 | if ( qd.isValid() ) |
492 | startDate = qd.date(); | 493 | startDate = qd.date(); |
493 | else | 494 | else |
494 | startDate = QDate::currentDate(); | 495 | startDate = QDate::currentDate(); |
495 | 496 | ||
496 | 497 | ||
497 | QMap<int, QString> queryFields = query.toMap(); | 498 | QMap<int, QString> queryFields = query.toMap(); |
498 | QStringList fieldList = OPimContactFields::untrfields( false ); | 499 | QStringList fieldList = OPimContactFields::untrfields( false ); |
499 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 500 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
500 | 501 | ||
501 | // Convert every filled field to a SQL-Query | 502 | // Convert every filled field to a SQL-Query |
502 | // bool isAnyFieldSelected = false; | 503 | // bool isAnyFieldSelected = false; |
503 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 504 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
504 | 505 | ||
505 | int id = translate[*it]; | 506 | int id = translate[*it]; |
506 | QString queryStr = queryFields[id]; | 507 | QString queryStr = queryFields[id]; |
507 | QDate* endDate = 0l; | 508 | QDate* endDate = 0l; |
508 | 509 | ||
509 | if ( !queryStr.isEmpty() ){ | 510 | if ( !queryStr.isEmpty() ){ |
510 | // If something is alredy stored in the query, add an "AND" | 511 | // If something is alredy stored in the query, add an "AND" |
511 | // to the end of the string to prepare for the next .. | 512 | // to the end of the string to prepare for the next .. |
512 | if ( !searchQuery.isEmpty() ) | 513 | if ( !searchQuery.isEmpty() ) |
513 | searchQuery += " AND"; | 514 | searchQuery += " AND"; |
514 | 515 | ||
515 | // isAnyFieldSelected = true; | 516 | // isAnyFieldSelected = true; |
516 | switch( id ){ | 517 | switch( id ){ |
517 | case Qtopia::Birthday: | 518 | case Qtopia::Birthday: |
518 | endDate = new QDate( query.birthday() ); | 519 | endDate = new QDate( query.birthday() ); |
519 | // Fall through ! | 520 | // Fall through ! |
520 | case Qtopia::Anniversary: | 521 | case Qtopia::Anniversary: |
521 | if ( endDate == 0l ) | 522 | if ( endDate == 0l ) |
522 | endDate = new QDate( query.anniversary() ); | 523 | endDate = new QDate( query.anniversary() ); |
523 | 524 | ||
524 | if ( settings & OPimContactAccess::DateDiff ) { | 525 | if ( settings & OPimContactAccess::DateDiff ) { |
525 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) | 526 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) |
526 | .arg( *it ) | 527 | .arg( *it ) |
527 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) | 528 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) |
528 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) | 529 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) |
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 4f9b504..67f267f 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp | |||
@@ -1,152 +1,158 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * ===================================================================== | 30 | * ===================================================================== |
31 | * ToDo: XML-Backend: Automatic reload if something was changed... | 31 | * ToDo: XML-Backend: Automatic reload if something was changed... |
32 | * | 32 | * |
33 | * | 33 | * |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "ocontactaccess.h" | 36 | #include "ocontactaccess.h" |
37 | #include "obackendfactory.h" | 37 | #include "obackendfactory.h" |
38 | 38 | ||
39 | #include <qasciidict.h> | 39 | #include <qasciidict.h> |
40 | #include <qdatetime.h> | 40 | #include <qdatetime.h> |
41 | #include <qfile.h> | 41 | #include <qfile.h> |
42 | #include <qregexp.h> | 42 | #include <qregexp.h> |
43 | #include <qlist.h> | 43 | #include <qlist.h> |
44 | #include <qcopchannel_qws.h> | 44 | #include <qcopchannel_qws.h> |
45 | 45 | ||
46 | //#include <qpe/qcopenvelope_qws.h> | 46 | //#include <qpe/qcopenvelope_qws.h> |
47 | #include <qpe/global.h> | 47 | #include <qpe/global.h> |
48 | 48 | ||
49 | #include <errno.h> | 49 | #include <errno.h> |
50 | #include <fcntl.h> | 50 | #include <fcntl.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | 53 | ||
54 | #include <opie2/ocontactaccessbackend_xml.h> | 54 | #include <opie2/ocontactaccessbackend_xml.h> |
55 | #include <opie2/opimresolver.h> | ||
55 | 56 | ||
56 | namespace Opie { | 57 | namespace Opie { |
57 | 58 | ||
58 | OPimContactAccess::OPimContactAccess ( const QString appname, const QString , | 59 | OPimContactAccess::OPimContactAccess ( const QString appname, const QString , |
59 | OPimContactAccessBackend* end, bool autosync ): | 60 | OPimContactAccessBackend* end, bool autosync ): |
60 | OPimAccessTemplate<OPimContact>( end ) | 61 | OPimAccessTemplate<OPimContact>( end ) |
61 | { | 62 | { |
62 | /* take care of the backend. If there is no one defined, we | 63 | /* take care of the backend. If there is no one defined, we |
63 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 64 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
64 | */ | 65 | */ |
65 | if( end == 0 ) { | 66 | if( end == 0 ) { |
66 | qWarning ("Using BackendFactory !"); | 67 | qWarning ("Using BackendFactory !"); |
67 | end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname ); | 68 | end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname ); |
68 | } | 69 | } |
69 | // Set backend locally and in template | 70 | // Set backend locally and in template |
70 | m_backEnd = end; | 71 | m_backEnd = end; |
71 | OPimAccessTemplate<OPimContact>::setBackEnd (end); | 72 | OPimAccessTemplate<OPimContact>::setBackEnd (end); |
72 | 73 | ||
73 | 74 | ||
74 | /* Connect signal of external db change to function */ | 75 | /* Connect signal of external db change to function */ |
75 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); | 76 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); |
76 | connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), | 77 | connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), |
77 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); | 78 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); |
78 | if ( autosync ){ | 79 | if ( autosync ){ |
79 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); | 80 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); |
80 | connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), | 81 | connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), |
81 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); | 82 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); |
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
85 | } | 86 | } |
86 | OPimContactAccess::~OPimContactAccess () | 87 | OPimContactAccess::~OPimContactAccess () |
87 | { | 88 | { |
88 | /* The user may forget to save the changed database, therefore try to | 89 | /* The user may forget to save the changed database, therefore try to |
89 | * do it for him.. | 90 | * do it for him.. |
90 | */ | 91 | */ |
91 | save(); | 92 | save(); |
92 | // delete m_backEnd; is done by template.. | 93 | // delete m_backEnd; is done by template.. |
93 | } | 94 | } |
94 | 95 | ||
95 | 96 | ||
96 | bool OPimContactAccess::save () | 97 | bool OPimContactAccess::save () |
97 | { | 98 | { |
98 | /* If the database was changed externally, we could not save the | 99 | /* If the database was changed externally, we could not save the |
99 | * Data. This will remove added items which is unacceptable ! | 100 | * Data. This will remove added items which is unacceptable ! |
100 | * Therefore: Reload database and merge the data... | 101 | * Therefore: Reload database and merge the data... |
101 | */ | 102 | */ |
102 | if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) | 103 | if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) |
103 | reload(); | 104 | reload(); |
104 | 105 | ||
105 | bool status = OPimAccessTemplate<OPimContact>::save(); | 106 | bool status = OPimAccessTemplate<OPimContact>::save(); |
106 | if ( !status ) return false; | 107 | if ( !status ) return false; |
107 | 108 | ||
108 | /* Now tell everyone that new data is available. | 109 | /* Now tell everyone that new data is available. |
109 | */ | 110 | */ |
110 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 111 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
111 | 112 | ||
112 | return true; | 113 | return true; |
113 | } | 114 | } |
114 | 115 | ||
115 | const uint OPimContactAccess::querySettings() | 116 | const uint OPimContactAccess::querySettings() |
116 | { | 117 | { |
117 | return ( m_backEnd->querySettings() ); | 118 | return ( m_backEnd->querySettings() ); |
118 | } | 119 | } |
119 | 120 | ||
120 | bool OPimContactAccess::hasQuerySettings ( int querySettings ) const | 121 | bool OPimContactAccess::hasQuerySettings ( int querySettings ) const |
121 | { | 122 | { |
122 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 123 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
123 | } | 124 | } |
124 | OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | 125 | OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const |
125 | { | 126 | { |
126 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | 127 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); |
127 | return ( OPimRecordList<OPimContact>(matchingContacts, this) ); | 128 | return ( OPimRecordList<OPimContact>(matchingContacts, this) ); |
128 | } | 129 | } |
129 | 130 | ||
130 | 131 | ||
131 | bool OPimContactAccess::wasChangedExternally()const | 132 | bool OPimContactAccess::wasChangedExternally()const |
132 | { | 133 | { |
133 | return ( m_backEnd->wasChangedExternally() ); | 134 | return ( m_backEnd->wasChangedExternally() ); |
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 138 | void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
138 | { | 139 | { |
139 | if ( msg == "addressbookUpdated()" ){ | 140 | if ( msg == "addressbookUpdated()" ){ |
140 | qWarning ("OPimContactAccess: Received addressbokUpdated()"); | 141 | qWarning ("OPimContactAccess: Received addressbokUpdated()"); |
141 | emit signalChanged ( this ); | 142 | emit signalChanged ( this ); |
142 | } else if ( msg == "flush()" ) { | 143 | } else if ( msg == "flush()" ) { |
143 | qWarning ("OPimContactAccess: Received flush()"); | 144 | qWarning ("OPimContactAccess: Received flush()"); |
144 | save (); | 145 | save (); |
145 | } else if ( msg == "reload()" ) { | 146 | } else if ( msg == "reload()" ) { |
146 | qWarning ("OPimContactAccess: Received reload()"); | 147 | qWarning ("OPimContactAccess: Received reload()"); |
147 | reload (); | 148 | reload (); |
148 | emit signalChanged ( this ); | 149 | emit signalChanged ( this ); |
149 | } | 150 | } |
150 | } | 151 | } |
151 | 152 | ||
153 | int OPimContactAccess::rtti() const | ||
154 | { | ||
155 | return OPimResolver::AddressBook; | ||
156 | } | ||
157 | |||
152 | } | 158 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index cf5333a..4429b6f 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -34,125 +34,130 @@ | |||
34 | #ifndef _OCONTACTACCESS_H | 34 | #ifndef _OCONTACTACCESS_H |
35 | #define _OCONTACTACCESS_H | 35 | #define _OCONTACTACCESS_H |
36 | 36 | ||
37 | #include <qobject.h> | 37 | #include <qobject.h> |
38 | 38 | ||
39 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
40 | 40 | ||
41 | #include <qvaluelist.h> | 41 | #include <qvaluelist.h> |
42 | #include <qfileinfo.h> | 42 | #include <qfileinfo.h> |
43 | 43 | ||
44 | #include <opie2/opimcontact.h> | 44 | #include <opie2/opimcontact.h> |
45 | #include <opie2/ocontactaccessbackend.h> | 45 | #include <opie2/ocontactaccessbackend.h> |
46 | #include <opie2/opimaccesstemplate.h> | 46 | #include <opie2/opimaccesstemplate.h> |
47 | 47 | ||
48 | namespace Opie { | 48 | namespace Opie { |
49 | /** | 49 | /** |
50 | * Class to access the contacts database. | 50 | * Class to access the contacts database. |
51 | * This is just a frontend for the real database handling which is | 51 | * This is just a frontend for the real database handling which is |
52 | * done by the backend. | 52 | * done by the backend. |
53 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | 53 | * This class is used to access the Contacts on a system. This class as any OPIE PIM |
54 | * class is backend independent. | 54 | * class is backend independent. |
55 | * @author Stefan Eilers, Holger Freyther | 55 | * @author Stefan Eilers, Holger Freyther |
56 | * @see OPimAccessTemplate | 56 | * @see OPimAccessTemplate |
57 | */ | 57 | */ |
58 | class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> | 58 | class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> |
59 | { | 59 | { |
60 | Q_OBJECT | 60 | Q_OBJECT |
61 | 61 | ||
62 | public: | 62 | public: |
63 | /** | 63 | /** |
64 | * Create Database with contacts (addressbook). | 64 | * Create Database with contacts (addressbook). |
65 | * @param appname Name of application which wants access to the database | 65 | * @param appname Name of application which wants access to the database |
66 | * (i.e. "todolist") | 66 | * (i.e. "todolist") |
67 | * @param filename The name of the database file. If not set, the default one | 67 | * @param filename The name of the database file. If not set, the default one |
68 | * is used. | 68 | * is used. |
69 | * @param backend Pointer to an alternative Backend. If not set, we will use | 69 | * @param backend Pointer to an alternative Backend. If not set, we will use |
70 | * the default backend. | 70 | * the default backend. |
71 | * @param handlesync If <b>true</b> the database stores the current state | 71 | * @param handlesync If <b>true</b> the database stores the current state |
72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
73 | * which are used before and after synchronisation. If the application wants | 73 | * which are used before and after synchronisation. If the application wants |
74 | * to react itself, it should be disabled by setting it to <b>false</b> | 74 | * to react itself, it should be disabled by setting it to <b>false</b> |
75 | * @see OPimContactAccessBackend | 75 | * @see OPimContactAccessBackend |
76 | */ | 76 | */ |
77 | OPimContactAccess (const QString appname, const QString filename = 0l, | 77 | OPimContactAccess (const QString appname, const QString filename = 0l, |
78 | OPimContactAccessBackend* backend = 0l, bool handlesync = true); | 78 | OPimContactAccessBackend* backend = 0l, bool handlesync = true); |
79 | ~OPimContactAccess (); | 79 | ~OPimContactAccess (); |
80 | 80 | ||
81 | /** Constants for query. | 81 | /** Constants for query. |
82 | * Use this constants to set the query parameters. | 82 | * Use this constants to set the query parameters. |
83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
84 | * @see queryByExample() | 84 | * @see queryByExample() |
85 | */ | 85 | */ |
86 | enum QuerySettings { | 86 | enum QuerySettings { |
87 | WildCards = 0x0001, | 87 | WildCards = 0x0001, |
88 | IgnoreCase = 0x0002, | 88 | IgnoreCase = 0x0002, |
89 | RegExp = 0x0004, | 89 | RegExp = 0x0004, |
90 | ExactMatch = 0x0008, | 90 | ExactMatch = 0x0008, |
91 | MatchOne = 0x0010, // Only one Entry must match | 91 | MatchOne = 0x0010, // Only one Entry must match |
92 | DateDiff = 0x0020, // Find all entries from today until given date | 92 | DateDiff = 0x0020, // Find all entries from today until given date |
93 | DateYear = 0x0040, // The year matches | 93 | DateYear = 0x0040, // The year matches |
94 | DateMonth = 0x0080, // The month matches | 94 | DateMonth = 0x0080, // The month matches |
95 | DateDay = 0x0100, // The day matches | 95 | DateDay = 0x0100, // The day matches |
96 | }; | 96 | }; |
97 | 97 | ||
98 | 98 | ||
99 | /** Return all Contacts in a sorted manner. | 99 | /** Return all Contacts in a sorted manner. |
100 | * @param ascending true: Sorted in acending order. | 100 | * @param ascending true: Sorted in acending order. |
101 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 101 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
102 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 102 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
103 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 103 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
104 | */ | 104 | */ |
105 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 105 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
106 | 106 | ||
107 | /** Return all possible settings. | 107 | /** Return all possible settings. |
108 | * @return All settings provided by the current backend | 108 | * @return All settings provided by the current backend |
109 | * (i.e.: query_WildCards & query_IgnoreCase) | 109 | * (i.e.: query_WildCards & query_IgnoreCase) |
110 | */ | 110 | */ |
111 | const uint querySettings(); | 111 | const uint querySettings(); |
112 | 112 | ||
113 | /** Check whether settings are correct. | 113 | /** Check whether settings are correct. |
114 | * @return <i>true</i> if the given settings are correct and possible. | 114 | * @return <i>true</i> if the given settings are correct and possible. |
115 | */ | 115 | */ |
116 | bool hasQuerySettings ( int querySettings ) const; | 116 | bool hasQuerySettings ( int querySettings ) const; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * if the resource was changed externally. | 119 | * if the resource was changed externally. |
120 | * You should use the signal instead of polling possible changes ! | 120 | * You should use the signal instead of polling possible changes ! |
121 | */ | 121 | */ |
122 | bool wasChangedExternally()const; | 122 | bool wasChangedExternally()const; |
123 | 123 | ||
124 | 124 | ||
125 | /** Save contacts database. | 125 | /** Save contacts database. |
126 | * Save is more a "commit". After calling this function, all changes are public available. | 126 | * Save is more a "commit". After calling this function, all changes are public available. |
127 | * @return true if successful | 127 | * @return true if successful |
128 | */ | 128 | */ |
129 | bool save(); | 129 | bool save(); |
130 | |||
131 | /** | ||
132 | * Return identification of used records | ||
133 | */ | ||
134 | int rtti() const; | ||
130 | 135 | ||
131 | signals: | 136 | signals: |
132 | /* Signal is emitted if the database was changed. Therefore | 137 | /* Signal is emitted if the database was changed. Therefore |
133 | * we may need to reload to stay consistent. | 138 | * we may need to reload to stay consistent. |
134 | * @param which Pointer to the database who created this event. This pointer | 139 | * @param which Pointer to the database who created this event. This pointer |
135 | * is useful if an application has to handle multiple databases at the same time. | 140 | * is useful if an application has to handle multiple databases at the same time. |
136 | * @see reload() | 141 | * @see reload() |
137 | */ | 142 | */ |
138 | void signalChanged ( const OPimContactAccess *which ); | 143 | void signalChanged ( const OPimContactAccess *which ); |
139 | 144 | ||
140 | 145 | ||
141 | private: | 146 | private: |
142 | // class OPimContactAccessPrivate; | 147 | // class OPimContactAccessPrivate; |
143 | // OPimContactAccessPrivate* d; | 148 | // OPimContactAccessPrivate* d; |
144 | OPimContactAccessBackend *m_backEnd; | 149 | OPimContactAccessBackend *m_backEnd; |
145 | bool m_loading:1; | 150 | bool m_loading:1; |
146 | 151 | ||
147 | private slots: | 152 | private slots: |
148 | void copMessage( const QCString &msg, const QByteArray &data ); | 153 | void copMessage( const QCString &msg, const QByteArray &data ); |
149 | 154 | ||
150 | private: | 155 | private: |
151 | class Private; | 156 | class Private; |
152 | Private *d; | 157 | Private *d; |
153 | 158 | ||
154 | }; | 159 | }; |
155 | 160 | ||
156 | } | 161 | } |
157 | 162 | ||
158 | #endif | 163 | #endif |
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index ac310c1..29298ea 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp | |||
@@ -1,112 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | 3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #include <opie2/obackendfactory.h> | 29 | #include <opie2/obackendfactory.h> |
30 | #include <opie2/odatebookaccess.h> | 30 | #include <opie2/odatebookaccess.h> |
31 | #include <opie2/opimresolver.h> | ||
31 | 32 | ||
32 | namespace Opie { | 33 | namespace Opie { |
33 | /** | 34 | /** |
34 | * Simple constructor | 35 | * Simple constructor |
35 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation | 36 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation |
36 | * will be used! | 37 | * will be used! |
37 | * @param back The backend to be used or 0 for the default backend | 38 | * @param back The backend to be used or 0 for the default backend |
38 | * @param ac What kind of access is intended | 39 | * @param ac What kind of access is intended |
39 | */ | 40 | */ |
40 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) | 41 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) |
41 | : OPimAccessTemplate<OPimEvent>( back ) | 42 | : OPimAccessTemplate<OPimEvent>( back ) |
42 | { | 43 | { |
43 | if (!back ) | 44 | if (!back ) |
44 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); | 45 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); |
45 | 46 | ||
46 | m_backEnd = back; | 47 | m_backEnd = back; |
47 | setBackEnd( m_backEnd ); | 48 | setBackEnd( m_backEnd ); |
48 | } | 49 | } |
49 | ODateBookAccess::~ODateBookAccess() { | 50 | ODateBookAccess::~ODateBookAccess() { |
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * @return all events available | 54 | * @return all events available |
54 | */ | 55 | */ |
55 | ODateBookAccess::List ODateBookAccess::rawEvents()const { | 56 | ODateBookAccess::List ODateBookAccess::rawEvents()const { |
56 | QArray<int> ints = m_backEnd->rawEvents(); | 57 | QArray<int> ints = m_backEnd->rawEvents(); |
57 | 58 | ||
58 | List lis( ints, this ); | 59 | List lis( ints, this ); |
59 | return lis; | 60 | return lis; |
60 | } | 61 | } |
61 | 62 | ||
62 | /** | 63 | /** |
63 | * @return all repeating events | 64 | * @return all repeating events |
64 | */ | 65 | */ |
65 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { | 66 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { |
66 | QArray<int> ints = m_backEnd->rawRepeats(); | 67 | QArray<int> ints = m_backEnd->rawRepeats(); |
67 | 68 | ||
68 | List lis( ints, this ); | 69 | List lis( ints, this ); |
69 | return lis; | 70 | return lis; |
70 | } | 71 | } |
71 | 72 | ||
72 | /** | 73 | /** |
73 | * @return all non repeating events | 74 | * @return all non repeating events |
74 | */ | 75 | */ |
75 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { | 76 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { |
76 | QArray<int> ints = m_backEnd->nonRepeats(); | 77 | QArray<int> ints = m_backEnd->nonRepeats(); |
77 | 78 | ||
78 | List lis( ints, this ); | 79 | List lis( ints, this ); |
79 | return lis; | 80 | return lis; |
80 | } | 81 | } |
81 | 82 | ||
82 | /** | 83 | /** |
83 | * @return dates in the time span between from and to | 84 | * @return dates in the time span between from and to |
84 | * @param from Include all events from... | 85 | * @param from Include all events from... |
85 | * @param to Include all events to... | 86 | * @param to Include all events to... |
86 | */ | 87 | */ |
87 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { | 88 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { |
88 | return m_backEnd->effectiveEvents( from, to ); | 89 | return m_backEnd->effectiveEvents( from, to ); |
89 | } | 90 | } |
90 | /** | 91 | /** |
91 | * @return all events at a given datetime | 92 | * @return all events at a given datetime |
92 | */ | 93 | */ |
93 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { | 94 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { |
94 | return m_backEnd->effectiveEvents( start ); | 95 | return m_backEnd->effectiveEvents( start ); |
95 | } | 96 | } |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * @return non repeating dates in the time span between from and to | 99 | * @return non repeating dates in the time span between from and to |
99 | * @param from Include all events from... | 100 | * @param from Include all events from... |
100 | * @param to Include all events to... | 101 | * @param to Include all events to... |
101 | */ | 102 | */ |
102 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { | 103 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { |
103 | return m_backEnd->effectiveNonRepeatingEvents( from, to ); | 104 | return m_backEnd->effectiveNonRepeatingEvents( from, to ); |
104 | } | 105 | } |
105 | /** | 106 | /** |
106 | * @return all non repeating events at a given datetime | 107 | * @return all non repeating events at a given datetime |
107 | */ | 108 | */ |
108 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { | 109 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { |
109 | return m_backEnd->effectiveNonRepeatingEvents( start ); | 110 | return m_backEnd->effectiveNonRepeatingEvents( start ); |
110 | } | 111 | } |
112 | int ODateBookAccess::rtti() const | ||
113 | { | ||
114 | return OPimResolver::DateBook; | ||
115 | } | ||
111 | 116 | ||
112 | } | 117 | } |
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 6c9290f..c6c3598 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h | |||
@@ -1,75 +1,81 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | 3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #ifndef OPIE_DATE_BOOK_ACCESS_H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_H |
30 | #define OPIE_DATE_BOOK_ACCESS_H | 30 | #define OPIE_DATE_BOOK_ACCESS_H |
31 | 31 | ||
32 | #include "odatebookaccessbackend.h" | 32 | #include "odatebookaccessbackend.h" |
33 | #include "opimaccesstemplate.h" | 33 | #include "opimaccesstemplate.h" |
34 | 34 | ||
35 | #include <opie2/opimevent.h> | 35 | #include <opie2/opimevent.h> |
36 | 36 | ||
37 | namespace Opie { | 37 | namespace Opie { |
38 | /** | 38 | /** |
39 | * This is the object orientated datebook database. It'll use OBackendFactory | 39 | * This is the object orientated datebook database. It'll use OBackendFactory |
40 | * to query for a backend. | 40 | * to query for a backend. |
41 | * All access to the datebook should be done via this class. | 41 | * All access to the datebook should be done via this class. |
42 | * Make sure to load and save the datebook this is not part of | 42 | * Make sure to load and save the datebook this is not part of |
43 | * destructing and creating the object | 43 | * destructing and creating the object |
44 | * | 44 | * |
45 | * @author Holger Freyther, Stefan Eilers | 45 | * @author Holger Freyther, Stefan Eilers |
46 | */ | 46 | */ |
47 | class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { | 47 | class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { |
48 | public: | 48 | public: |
49 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); | 49 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); |
50 | ~ODateBookAccess(); | 50 | ~ODateBookAccess(); |
51 | 51 | ||
52 | /* return all events */ | 52 | /* return all events */ |
53 | List rawEvents()const; | 53 | List rawEvents()const; |
54 | 54 | ||
55 | /* return repeating events */ | 55 | /* return repeating events */ |
56 | List rawRepeats()const; | 56 | List rawRepeats()const; |
57 | 57 | ||
58 | /* return non repeating events */ | 58 | /* return non repeating events */ |
59 | List nonRepeats()const; | 59 | List nonRepeats()const; |
60 | 60 | ||
61 | /* return non repeating events (from,to) */ | 61 | /* return non repeating events (from,to) */ |
62 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; | 62 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; |
63 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; | 63 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; |
64 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; | 64 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; |
65 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; | 65 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; |
66 | 66 | ||
67 | /** | ||
68 | * Return identification of used records | ||
69 | */ | ||
70 | int rtti() const; | ||
71 | |||
72 | |||
67 | private: | 73 | private: |
68 | ODateBookAccessBackend* m_backEnd; | 74 | ODateBookAccessBackend* m_backEnd; |
69 | class Private; | 75 | class Private; |
70 | Private* d; | 76 | Private* d; |
71 | }; | 77 | }; |
72 | 78 | ||
73 | } | 79 | } |
74 | 80 | ||
75 | #endif | 81 | #endif |
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index f1bcc44..d4c5fbb 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,335 +1,357 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) Holger Freyther <zecke@handhelds.org> |
4 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 6 | .=l. |
6 | .>+-= | 7 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 14 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 22 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
28 | */ | 29 | */ |
29 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 30 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
30 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 31 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
31 | 32 | ||
32 | #include <qarray.h> | 33 | #include <qarray.h> |
33 | 34 | ||
34 | #include <opie2/opimrecord.h> | 35 | #include <opie2/opimrecord.h> |
35 | #include <opie2/opimaccessbackend.h> | 36 | #include <opie2/opimaccessbackend.h> |
36 | #include <opie2/opimrecordlist.h> | 37 | #include <opie2/opimrecordlist.h> |
37 | 38 | ||
38 | #include <opie2/opimcache.h> | 39 | #include <opie2/opimcache.h> |
39 | #include <opie2/opimtemplatebase.h> | 40 | #include <opie2/opimtemplatebase.h> |
40 | 41 | ||
41 | namespace Opie { | 42 | namespace Opie { |
42 | 43 | ||
43 | class OPimAccessTemplatePrivate; | 44 | class OPimAccessTemplatePrivate; |
44 | /** | 45 | /** |
45 | * Thats the frontend to our OPIE PIM | 46 | * Thats the frontend to our OPIE PIM |
46 | * Library. Either you want to use it's | 47 | * Library. Either you want to use it's |
47 | * interface or you want to implement | 48 | * interface or you want to implement |
48 | * your own Access lib | 49 | * your own Access lib |
49 | * Just create a OPimRecord and inherit from | 50 | * Just create a OPimRecord and inherit from |
50 | * the plugins | 51 | * the plugins |
51 | */ | 52 | */ |
52 | 53 | ||
53 | template <class T = OPimRecord > | 54 | template <class T = OPimRecord > |
54 | class OPimAccessTemplate : public OTemplateBase<T> { | 55 | class OPimAccessTemplate : public OTemplateBase<T> { |
55 | public: | 56 | public: |
56 | enum Access { | 57 | enum Access { |
57 | Random = 0, | 58 | Random = 0, |
58 | SortedAccess | 59 | SortedAccess |
59 | }; | 60 | }; |
60 | typedef OPimRecordList<T> List; | 61 | typedef OPimRecordList<T> List; |
61 | typedef OPimAccessBackend<T> BackEnd; | 62 | typedef OPimAccessBackend<T> BackEnd; |
62 | typedef OPimCache<T> Cache; | 63 | typedef OPimCache<T> Cache; |
63 | 64 | ||
64 | /** | 65 | /** |
65 | * c'tor BackEnd | 66 | * c'tor BackEnd |
66 | * enum Access a small hint on how to handle the backend | 67 | * enum Access a small hint on how to handle the backend |
67 | */ | 68 | */ |
68 | OPimAccessTemplate( BackEnd* end); | 69 | OPimAccessTemplate( BackEnd* end); |
69 | 70 | ||
70 | virtual ~OPimAccessTemplate(); | 71 | virtual ~OPimAccessTemplate(); |
71 | 72 | ||
72 | /** | 73 | /** |
73 | * load from the backend | 74 | * load from the backend |
74 | */ | 75 | */ |
75 | bool load(); | 76 | bool load(); |
76 | 77 | ||
77 | /** Reload database. | 78 | /** Reload database. |
78 | * You should execute this function if the external database | 79 | * You should execute this function if the external database |
79 | * was changed. | 80 | * was changed. |
80 | * This function will load the external database and afterwards | 81 | * This function will load the external database and afterwards |
81 | * rejoin the local changes. Therefore the local database will be set consistent. | 82 | * rejoin the local changes. Therefore the local database will be set consistent. |
82 | */ | 83 | */ |
83 | virtual bool reload(); | 84 | virtual bool reload(); |
84 | 85 | ||
85 | /** Save contacts database. | 86 | /** Save contacts database. |
86 | * Save is more a "commit". After calling this function, all changes are public available. | 87 | * Save is more a "commit". After calling this function, all changes are public available. |
87 | * @return true if successful | 88 | * @return true if successful |
88 | */ | 89 | */ |
89 | bool save(); | 90 | bool save(); |
90 | 91 | ||
91 | /** | 92 | /** |
92 | * if the resource was changed externally | 93 | * if the resource was changed externally |
93 | * You should use the signal handling instead of polling possible changes ! | 94 | * You should use the signal handling instead of polling possible changes ! |
94 | * zecke: Do you implement a signal for otodoaccess ? | 95 | * zecke: Do you implement a signal for otodoaccess ? |
95 | */ | 96 | */ |
96 | bool wasChangedExternally()const; | 97 | bool wasChangedExternally()const; |
97 | 98 | ||
98 | /** | 99 | /** |
99 | * return a List of records | 100 | * return a List of records |
100 | * you can iterate over them | 101 | * you can iterate over them |
101 | */ | 102 | */ |
102 | virtual List allRecords()const; | 103 | virtual List allRecords()const; |
103 | 104 | ||
104 | /** | 105 | /** |
105 | * return a List of records | 106 | * return a List of records |
106 | * that match the regex | 107 | * that match the regex |
107 | */ | 108 | */ |
108 | virtual List matchRegexp( const QRegExp &r ) const; | 109 | virtual List matchRegexp( const QRegExp &r ) const; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * queryByExample. | 112 | * queryByExample. |
112 | * @see otodoaccess, ocontactaccess | 113 | * @see otodoaccess, ocontactaccess |
113 | */ | 114 | */ |
114 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); | 115 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); |
115 | 116 | ||
116 | /** | 117 | /** |
117 | * find the OPimRecord uid | 118 | * find the OPimRecord uid |
118 | */ | 119 | */ |
119 | virtual T find( int uid )const; | 120 | virtual T find( int uid )const; |
120 | 121 | ||
121 | /** | 122 | /** |
122 | * read ahead cache find method ;) | 123 | * read ahead cache find method ;) |
123 | */ | 124 | */ |
124 | virtual T find( int uid, const QArray<int>&, | 125 | virtual T find( int uid, const QArray<int>&, |
125 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | 126 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; |
126 | 127 | ||
127 | /* invalidate cache here */ | 128 | /* invalidate cache here */ |
128 | /** | 129 | /** |
129 | * clears the backend and invalidates the backend | 130 | * clears the backend and invalidates the backend |
130 | */ | 131 | */ |
131 | void clear() ; | 132 | void clear() ; |
132 | 133 | ||
133 | /** | 134 | /** |
134 | * add T to the backend | 135 | * add T to the backend |
135 | * @param t The item to add. | 136 | * @param t The item to add. |
136 | * @return <i>true</i> if added successfully. | 137 | * @return <i>true</i> if added successfully. |
137 | */ | 138 | */ |
138 | virtual bool add( const T& t ) ; | 139 | virtual bool add( const T& t ) ; |
139 | bool add( const OPimRecord& ); | 140 | bool add( const OPimRecord& ); |
141 | // Needed for real generic access (eilers) | ||
142 | // Info: Take this if you are working with OPimRecord, which is a generic base class, and | ||
143 | // you need to add it into any database, you cannot generate a reference to | ||
144 | // it and casting may be not approriate, too. | ||
145 | // But take care that the accessing database is compatible to the real type of OPimRecord !! | ||
146 | bool add( const OPimRecord* ); | ||
147 | |||
140 | 148 | ||
141 | /* only the uid matters */ | 149 | /* only the uid matters */ |
142 | /** | 150 | /** |
143 | * remove T from the backend | 151 | * remove T from the backend |
144 | * @param t The item to remove | 152 | * @param t The item to remove |
145 | * @return <i>true</i> if successful. | 153 | * @return <i>true</i> if successful. |
146 | */ | 154 | */ |
147 | virtual bool remove( const T& t ); | 155 | virtual bool remove( const T& t ); |
148 | 156 | ||
149 | /** | 157 | /** |
150 | * remove the OPimRecord with uid | 158 | * remove the OPimRecord with uid |
151 | * @param uid The ID of the item to remove | 159 | * @param uid The ID of the item to remove |
152 | * @return <i>true</i> if successful. | 160 | * @return <i>true</i> if successful. |
153 | */ | 161 | */ |
154 | bool remove( int uid ); | 162 | bool remove( int uid ); |
155 | bool remove( const OPimRecord& ); | 163 | bool remove( const OPimRecord& ); |
156 | 164 | ||
157 | /** | 165 | /** |
158 | * replace T from backend | 166 | * replace T from backend |
159 | * @param t The item to replace | 167 | * @param t The item to replace |
160 | * @return <i>true</i> if successful. | 168 | * @return <i>true</i> if successful. |
161 | */ | 169 | */ |
162 | virtual bool replace( const T& t) ; | 170 | virtual bool replace( const T& t) ; |
163 | 171 | ||
164 | void setReadAhead( uint count ); | 172 | void setReadAhead( uint count ); |
165 | /** | 173 | /** |
166 | * @internal | 174 | * @internal |
167 | */ | 175 | */ |
168 | void cache( const T& )const; | 176 | void cache( const T& )const; |
169 | void setSaneCacheSize( int ); | 177 | void setSaneCacheSize( int ); |
170 | 178 | ||
171 | QArray<int> records()const; | 179 | QArray<int> records()const; |
172 | protected: | 180 | protected: |
173 | /** | 181 | /** |
174 | * invalidate the cache | 182 | * invalidate the cache |
175 | */ | 183 | */ |
176 | void invalidateCache(); | 184 | void invalidateCache(); |
177 | 185 | ||
178 | void setBackEnd( BackEnd* end ); | 186 | void setBackEnd( BackEnd* end ); |
179 | /** | 187 | /** |
180 | * returns the backend | 188 | * returns the backend |
181 | */ | 189 | */ |
182 | BackEnd* backEnd(); | 190 | BackEnd* backEnd(); |
183 | BackEnd* m_backEnd; | 191 | BackEnd* m_backEnd; |
184 | Cache m_cache; | 192 | Cache m_cache; |
185 | 193 | ||
186 | private: | 194 | private: |
187 | OPimAccessTemplatePrivate *d; | 195 | OPimAccessTemplatePrivate *d; |
188 | 196 | ||
189 | }; | 197 | }; |
190 | 198 | ||
191 | template <class T> | 199 | template <class T> |
192 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 200 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
193 | : OTemplateBase<T>(), m_backEnd( end ) | 201 | : OTemplateBase<T>(), m_backEnd( end ) |
194 | { | 202 | { |
195 | if (end ) | 203 | if (end ) |
196 | end->setFrontend( this ); | 204 | end->setFrontend( this ); |
197 | } | 205 | } |
198 | template <class T> | 206 | template <class T> |
199 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 207 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
200 | qWarning("~OPimAccessTemplate<T>"); | 208 | qWarning("~OPimAccessTemplate<T>"); |
201 | delete m_backEnd; | 209 | delete m_backEnd; |
202 | } | 210 | } |
203 | template <class T> | 211 | template <class T> |
204 | bool OPimAccessTemplate<T>::load() { | 212 | bool OPimAccessTemplate<T>::load() { |
205 | invalidateCache(); | 213 | invalidateCache(); |
206 | return m_backEnd->load(); | 214 | return m_backEnd->load(); |
207 | } | 215 | } |
208 | template <class T> | 216 | template <class T> |
209 | bool OPimAccessTemplate<T>::reload() { | 217 | bool OPimAccessTemplate<T>::reload() { |
210 | invalidateCache(); // zecke: I think this should be added (se) | 218 | invalidateCache(); // zecke: I think this should be added (se) |
211 | return m_backEnd->reload(); | 219 | return m_backEnd->reload(); |
212 | } | 220 | } |
213 | template <class T> | 221 | template <class T> |
214 | bool OPimAccessTemplate<T>::save() { | 222 | bool OPimAccessTemplate<T>::save() { |
215 | return m_backEnd->save(); | 223 | return m_backEnd->save(); |
216 | } | 224 | } |
217 | template <class T> | 225 | template <class T> |
218 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 226 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
219 | QArray<int> ints = m_backEnd->allRecords(); | 227 | QArray<int> ints = m_backEnd->allRecords(); |
220 | List lis(ints, this ); | 228 | List lis(ints, this ); |
221 | return lis; | 229 | return lis; |
222 | } | 230 | } |
223 | template <class T> | 231 | template <class T> |
224 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | 232 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { |
225 | QArray<int> ints = m_backEnd->matchRegexp( r ); | 233 | QArray<int> ints = m_backEnd->matchRegexp( r ); |
226 | List lis(ints, this ); | 234 | List lis(ints, this ); |
227 | return lis; | 235 | return lis; |
228 | } | 236 | } |
229 | template <class T> | 237 | template <class T> |
230 | QArray<int> OPimAccessTemplate<T>::records()const { | 238 | QArray<int> OPimAccessTemplate<T>::records()const { |
231 | return m_backEnd->allRecords(); | 239 | return m_backEnd->allRecords(); |
232 | } | 240 | } |
233 | template <class T> | 241 | template <class T> |
234 | typename OPimAccessTemplate<T>::List | 242 | typename OPimAccessTemplate<T>::List |
235 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | 243 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { |
236 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); | 244 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); |
237 | 245 | ||
238 | List lis(ints, this ); | 246 | List lis(ints, this ); |
239 | return lis; | 247 | return lis; |
240 | } | 248 | } |
241 | template <class T> | 249 | template <class T> |
242 | T OPimAccessTemplate<T>::find( int uid ) const{ | 250 | T OPimAccessTemplate<T>::find( int uid ) const{ |
243 | T t = m_backEnd->find( uid ); | 251 | T t = m_backEnd->find( uid ); |
244 | cache( t ); | 252 | cache( t ); |
245 | return t; | 253 | return t; |
246 | } | 254 | } |
247 | template <class T> | 255 | template <class T> |
248 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 256 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
249 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | 257 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { |
250 | /* | 258 | /* |
251 | * better do T.isEmpty() | 259 | * better do T.isEmpty() |
252 | * after a find this way we would | 260 | * after a find this way we would |
253 | * avoid two finds in QCache... | 261 | * avoid two finds in QCache... |
254 | */ | 262 | */ |
255 | // qWarning("find it now %d", uid ); | 263 | // qWarning("find it now %d", uid ); |
256 | if (m_cache.contains( uid ) ) { | 264 | if (m_cache.contains( uid ) ) { |
257 | return m_cache.find( uid ); | 265 | return m_cache.find( uid ); |
258 | } | 266 | } |
259 | 267 | ||
260 | T t = m_backEnd->find( uid, ar, current, dir ); | 268 | T t = m_backEnd->find( uid, ar, current, dir ); |
261 | cache( t ); | 269 | cache( t ); |
262 | return t; | 270 | return t; |
263 | } | 271 | } |
264 | template <class T> | 272 | template <class T> |
265 | void OPimAccessTemplate<T>::clear() { | 273 | void OPimAccessTemplate<T>::clear() { |
266 | invalidateCache(); | 274 | invalidateCache(); |
267 | m_backEnd->clear(); | 275 | m_backEnd->clear(); |
268 | } | 276 | } |
269 | template <class T> | 277 | template <class T> |
270 | bool OPimAccessTemplate<T>::add( const T& t ) { | 278 | bool OPimAccessTemplate<T>::add( const T& t ) { |
271 | cache( t ); | 279 | cache( t ); |
272 | return m_backEnd->add( t ); | 280 | return m_backEnd->add( t ); |
273 | } | 281 | } |
282 | |||
274 | template <class T> | 283 | template <class T> |
275 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 284 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { |
276 | /* same type */ | 285 | /* same type */ |
277 | if ( rec.rtti() == T::rtti() ) { | 286 | T tempInstance; |
278 | const T &t = static_cast<const T&>(rec); | 287 | if ( rec.rtti() == tempInstance.rtti() ) { |
288 | const T& t = static_cast<const T&>(rec); | ||
279 | return add(t); | 289 | return add(t); |
280 | } | 290 | } |
281 | return false; | 291 | return false; |
282 | } | 292 | } |
293 | |||
294 | template <class T> | ||
295 | bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { | ||
296 | /* same type, but pointer */ | ||
297 | T tempInstance; | ||
298 | if ( rec -> rtti() == tempInstance.rtti() ) { | ||
299 | const T* t = static_cast<const T*>(rec); | ||
300 | return add( *t ); | ||
301 | } | ||
302 | return false; | ||
303 | } | ||
304 | |||
283 | template <class T> | 305 | template <class T> |
284 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 306 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
285 | return remove( t.uid() ); | 307 | return remove( t.uid() ); |
286 | } | 308 | } |
287 | template <class T> | 309 | template <class T> |
288 | bool OPimAccessTemplate<T>::remove( int uid ) { | 310 | bool OPimAccessTemplate<T>::remove( int uid ) { |
289 | m_cache.remove( uid ); | 311 | m_cache.remove( uid ); |
290 | return m_backEnd->remove( uid ); | 312 | return m_backEnd->remove( uid ); |
291 | } | 313 | } |
292 | template <class T> | 314 | template <class T> |
293 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | 315 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { |
294 | return remove( rec.uid() ); | 316 | return remove( rec.uid() ); |
295 | } | 317 | } |
296 | template <class T> | 318 | template <class T> |
297 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 319 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
298 | m_cache.replace( t ); | 320 | m_cache.replace( t ); |
299 | return m_backEnd->replace( t ); | 321 | return m_backEnd->replace( t ); |
300 | } | 322 | } |
301 | template <class T> | 323 | template <class T> |
302 | void OPimAccessTemplate<T>::invalidateCache() { | 324 | void OPimAccessTemplate<T>::invalidateCache() { |
303 | m_cache.invalidate(); | 325 | m_cache.invalidate(); |
304 | } | 326 | } |
305 | template <class T> | 327 | template <class T> |
306 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 328 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
307 | return m_backEnd; | 329 | return m_backEnd; |
308 | } | 330 | } |
309 | template <class T> | 331 | template <class T> |
310 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 332 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
311 | return false; | 333 | return false; |
312 | } | 334 | } |
313 | template <class T> | 335 | template <class T> |
314 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 336 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
315 | m_backEnd = end; | 337 | m_backEnd = end; |
316 | if (m_backEnd ) | 338 | if (m_backEnd ) |
317 | m_backEnd->setFrontend( this ); | 339 | m_backEnd->setFrontend( this ); |
318 | } | 340 | } |
319 | template <class T> | 341 | template <class T> |
320 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 342 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
321 | /* hacky we need to work around the const*/ | 343 | /* hacky we need to work around the const*/ |
322 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 344 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
323 | } | 345 | } |
324 | template <class T> | 346 | template <class T> |
325 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 347 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
326 | m_cache.setSize( size ); | 348 | m_cache.setSize( size ); |
327 | } | 349 | } |
328 | template <class T> | 350 | template <class T> |
329 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | 351 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { |
330 | m_backEnd->setReadAhead( count ); | 352 | m_backEnd->setReadAhead( count ); |
331 | } | 353 | } |
332 | 354 | ||
333 | } | 355 | } |
334 | 356 | ||
335 | #endif | 357 | #endif |
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index 58cbfeb..b48dfed 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h | |||
@@ -1,130 +1,122 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) Holger Freyther <zecke@handhelds.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #ifndef OTEMPLATEBASE_H | 29 | #ifndef OTEMPLATEBASE_H |
30 | #define OTEMPLATEBASE_H | 30 | #define OTEMPLATEBASE_H |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/opimrecord.h> | 33 | #include <opie2/opimrecord.h> |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qarray.h> | 36 | #include <qarray.h> |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | /** | 39 | /** |
40 | * Templates do not have a base class, This is why | 40 | * Templates do not have a base class, This is why |
41 | * we've this class | 41 | * we've this class |
42 | * this is here to give us the possibility | 42 | * this is here to give us the possibility |
43 | * to have a common base class | 43 | * to have a common base class |
44 | * You may not want to use that interface internaly | 44 | * You may not want to use that interface internaly |
45 | * POOR mans interface | 45 | * POOR mans interface |
46 | */ | 46 | */ |
47 | class OPimBasePrivate; | 47 | class OPimBasePrivate; |
48 | struct OPimBase { | 48 | struct OPimBase { |
49 | /** | 49 | /** |
50 | * return the rtti | 50 | * return the rtti |
51 | */ | 51 | */ |
52 | virtual int rtti()= 0; | 52 | virtual int rtti() const = 0; |
53 | virtual OPimRecord* record()const = 0; | 53 | virtual OPimRecord* record()const = 0; |
54 | virtual OPimRecord* record(int uid)const = 0; | 54 | virtual OPimRecord* record(int uid)const = 0; |
55 | virtual bool add( const OPimRecord& ) = 0; | 55 | virtual bool add( const OPimRecord& ) = 0; |
56 | virtual bool add( const OPimRecord* ) = 0; | ||
56 | virtual bool remove( int uid ) = 0; | 57 | virtual bool remove( int uid ) = 0; |
57 | virtual bool remove( const OPimRecord& ) = 0; | 58 | virtual bool remove( const OPimRecord& ) = 0; |
58 | virtual void clear() = 0; | 59 | virtual void clear() = 0; |
59 | virtual bool load() = 0; | 60 | virtual bool load() = 0; |
60 | virtual bool save() = 0; | 61 | virtual bool save() = 0; |
61 | virtual QArray<int> records()const = 0; | 62 | virtual QArray<int> records()const = 0; |
62 | /* | 63 | /* |
63 | * ADD editing here? | 64 | * ADD editing here? |
64 | * -zecke | 65 | * -zecke |
65 | */ | 66 | */ |
66 | private: | 67 | private: |
67 | OPimBasePrivate* d; | 68 | OPimBasePrivate* d; |
68 | 69 | ||
69 | }; | 70 | }; |
70 | /** | 71 | /** |
71 | * internal template base | 72 | * internal template base |
72 | * T needs to implement the copy c'tor!!! | 73 | * T needs to implement the copy c'tor!!! |
73 | */ | 74 | */ |
74 | class OTemplateBasePrivate; | 75 | class OTemplateBasePrivate; |
75 | template <class T = OPimRecord> | 76 | template <class T = OPimRecord> |
76 | class OTemplateBase : public OPimBase { | 77 | class OTemplateBase : public OPimBase { |
77 | public: | 78 | public: |
78 | enum CacheDirection { Forward=0, Reverse }; | 79 | enum CacheDirection { Forward=0, Reverse }; |
79 | OTemplateBase() { | 80 | OTemplateBase() { |
80 | }; | 81 | }; |
81 | virtual ~OTemplateBase() { | 82 | virtual ~OTemplateBase() { |
82 | } | 83 | } |
83 | virtual T find( int uid )const = 0; | 84 | virtual T find( int uid )const = 0; |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * read ahead find | 87 | * read ahead find |
87 | */ | 88 | */ |
88 | virtual T find( int uid, const QArray<int>& items, | 89 | virtual T find( int uid, const QArray<int>& items, |
89 | uint current, CacheDirection dir = Forward )const = 0; | 90 | uint current, CacheDirection dir = Forward )const = 0; |
90 | virtual void cache( const T& )const = 0; | 91 | virtual void cache( const T& )const = 0; |
91 | virtual void setSaneCacheSize( int ) = 0; | 92 | virtual void setSaneCacheSize( int ) = 0; |
92 | 93 | ||
93 | /* reimplement of OPimBase */ | ||
94 | int rtti(); | ||
95 | OPimRecord* record()const; | 94 | OPimRecord* record()const; |
96 | OPimRecord* record(int uid )const; | 95 | OPimRecord* record(int uid )const; |
97 | static T* rec(); | 96 | static T* rec(); |
98 | 97 | ||
99 | private: | 98 | private: |
100 | OTemplateBasePrivate *d; | 99 | OTemplateBasePrivate *d; |
101 | }; | 100 | }; |
102 | 101 | ||
103 | /* | 102 | |
104 | * implementation | ||
105 | */ | ||
106 | template <class T> | ||
107 | int | ||
108 | OTemplateBase<T>::rtti() { | ||
109 | return T::rtti(); | ||
110 | } | ||
111 | template <class T> | 103 | template <class T> |
112 | OPimRecord* OTemplateBase<T>::record()const { | 104 | OPimRecord* OTemplateBase<T>::record()const { |
113 | T* t = new T; | 105 | T* t = new T; |
114 | return t; | 106 | return t; |
115 | } | 107 | } |
116 | template <class T> | 108 | template <class T> |
117 | OPimRecord* OTemplateBase<T>::record(int uid )const { | 109 | OPimRecord* OTemplateBase<T>::record(int uid )const { |
118 | T t2 = find(uid ); | 110 | T t2 = find(uid ); |
119 | T* t1 = new T(t2); | 111 | T* t1 = new T(t2); |
120 | 112 | ||
121 | return t1; | 113 | return t1; |
122 | }; | 114 | }; |
123 | template <class T> | 115 | template <class T> |
124 | T* OTemplateBase<T>::rec() { | 116 | T* OTemplateBase<T>::rec() { |
125 | return new T; | 117 | return new T; |
126 | } | 118 | } |
127 | 119 | ||
128 | } | 120 | } |
129 | 121 | ||
130 | #endif | 122 | #endif |
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 83750d5..6fa0089 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp | |||
@@ -1,93 +1,100 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
30 | 30 | ||
31 | #include <qpe/alarmserver.h> | 31 | #include <qpe/alarmserver.h> |
32 | 32 | ||
33 | // #include "otodoaccesssql.h" | 33 | // #include "otodoaccesssql.h" |
34 | #include <opie2/otodoaccess.h> | 34 | #include <opie2/otodoaccess.h> |
35 | #include <opie2/obackendfactory.h> | 35 | #include <opie2/obackendfactory.h> |
36 | #include <opie2/opimresolver.h> | ||
36 | 37 | ||
37 | namespace Opie { | 38 | namespace Opie { |
38 | OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) | 39 | OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) |
39 | : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) | 40 | : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) |
40 | { | 41 | { |
41 | // if (end == 0l ) | 42 | // if (end == 0l ) |
42 | // m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); | 43 | // m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); |
43 | 44 | ||
44 | // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! | 45 | // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! |
45 | if (end == 0l ) | 46 | if (end == 0l ) |
46 | m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::Default ("todo", QString::null); | 47 | m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::Default ("todo", QString::null); |
47 | 48 | ||
48 | setBackEnd( m_todoBackEnd ); | 49 | setBackEnd( m_todoBackEnd ); |
49 | } | 50 | } |
50 | OPimTodoAccess::~OPimTodoAccess() { | 51 | OPimTodoAccess::~OPimTodoAccess() { |
51 | // qWarning("~OPimTodoAccess"); | 52 | // qWarning("~OPimTodoAccess"); |
52 | } | 53 | } |
53 | void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { | 54 | void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { |
54 | QValueList<OPimTodo>::ConstIterator it; | 55 | QValueList<OPimTodo>::ConstIterator it; |
55 | for ( it = list.begin(); it != list.end(); ++it ) { | 56 | for ( it = list.begin(); it != list.end(); ++it ) { |
56 | replace( (*it) ); | 57 | replace( (*it) ); |
57 | } | 58 | } |
58 | } | 59 | } |
59 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, | 60 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, |
60 | const QDate& end, | 61 | const QDate& end, |
61 | bool includeNoDates ) { | 62 | bool includeNoDates ) { |
62 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); | 63 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); |
63 | 64 | ||
64 | List lis( ints, this ); | 65 | List lis( ints, this ); |
65 | return lis; | 66 | return lis; |
66 | } | 67 | } |
67 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, | 68 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, |
68 | bool includeNoDates ) { | 69 | bool includeNoDates ) { |
69 | return effectiveToDos( start, QDate::currentDate(), | 70 | return effectiveToDos( start, QDate::currentDate(), |
70 | includeNoDates ); | 71 | includeNoDates ); |
71 | } | 72 | } |
72 | OPimTodoAccess::List OPimTodoAccess::overDue() { | 73 | OPimTodoAccess::List OPimTodoAccess::overDue() { |
73 | List lis( m_todoBackEnd->overDue(), this ); | 74 | List lis( m_todoBackEnd->overDue(), this ); |
74 | return lis; | 75 | return lis; |
75 | } | 76 | } |
76 | /* sort order */ | 77 | /* sort order */ |
77 | OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { | 78 | OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { |
78 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, | 79 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, |
79 | filter, cat ); | 80 | filter, cat ); |
80 | OPimTodoAccess::List list( ints, this ); | 81 | OPimTodoAccess::List list( ints, this ); |
81 | return list; | 82 | return list; |
82 | } | 83 | } |
83 | void OPimTodoAccess::removeAllCompleted() { | 84 | void OPimTodoAccess::removeAllCompleted() { |
84 | m_todoBackEnd->removeAllCompleted(); | 85 | m_todoBackEnd->removeAllCompleted(); |
85 | } | 86 | } |
86 | QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ | 87 | QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ |
87 | return m_todoBackEnd->supports(); | 88 | return m_todoBackEnd->supports(); |
88 | } | 89 | } |
89 | bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ | 90 | bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ |
90 | return backendSupport(ar).testBit( attr ); | 91 | return backendSupport(ar).testBit( attr ); |
91 | } | 92 | } |
92 | 93 | ||
94 | |||
95 | int OPimTodoAccess::rtti() const | ||
96 | { | ||
97 | return OPimResolver::TodoList; | ||
98 | } | ||
99 | |||
93 | } | 100 | } |
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index 51f3793..3f5af30 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h | |||
@@ -23,114 +23,120 @@ | |||
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #ifndef OPIE_TODO_ACCESS_H | 29 | #ifndef OPIE_TODO_ACCESS_H |
30 | #define OPIE_TODO_ACCESS_H | 30 | #define OPIE_TODO_ACCESS_H |
31 | 31 | ||
32 | #include <qobject.h> | 32 | #include <qobject.h> |
33 | #include <qvaluelist.h> | 33 | #include <qvaluelist.h> |
34 | 34 | ||
35 | #include <opie2/opimtodo.h> | 35 | #include <opie2/opimtodo.h> |
36 | #include <opie2/otodoaccessbackend.h> | 36 | #include <opie2/otodoaccessbackend.h> |
37 | #include <opie2/opimaccesstemplate.h> | 37 | #include <opie2/opimaccesstemplate.h> |
38 | 38 | ||
39 | namespace Opie { | 39 | namespace Opie { |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * OPimTodoAccess | 42 | * OPimTodoAccess |
43 | * the class to get access to | 43 | * the class to get access to |
44 | * the todolist | 44 | * the todolist |
45 | */ | 45 | */ |
46 | class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> { | 46 | class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> { |
47 | Q_OBJECT | 47 | Q_OBJECT |
48 | public: | 48 | public: |
49 | enum SortOrder { Completed = 0, | 49 | enum SortOrder { Completed = 0, |
50 | Priority, | 50 | Priority, |
51 | Description, | 51 | Description, |
52 | Deadline }; | 52 | Deadline }; |
53 | enum SortFilter{ Category =1, | 53 | enum SortFilter{ Category =1, |
54 | OnlyOverDue= 2, | 54 | OnlyOverDue= 2, |
55 | DoNotShowCompleted =4 }; | 55 | DoNotShowCompleted =4 }; |
56 | /** | 56 | /** |
57 | * if you use 0l | 57 | * if you use 0l |
58 | * the default resource will be | 58 | * the default resource will be |
59 | * picked up | 59 | * picked up |
60 | */ | 60 | */ |
61 | OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random ); | 61 | OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random ); |
62 | ~OPimTodoAccess(); | 62 | ~OPimTodoAccess(); |
63 | 63 | ||
64 | 64 | ||
65 | /* our functions here */ | 65 | /* our functions here */ |
66 | /** | 66 | /** |
67 | * include todos from start to end | 67 | * include todos from start to end |
68 | * includeNoDates whether or not to include | 68 | * includeNoDates whether or not to include |
69 | * events with no dates | 69 | * events with no dates |
70 | */ | 70 | */ |
71 | List effectiveToDos( const QDate& start, | 71 | List effectiveToDos( const QDate& start, |
72 | const QDate& end, | 72 | const QDate& end, |
73 | bool includeNoDates = true ); | 73 | bool includeNoDates = true ); |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * start | 76 | * start |
77 | * end date taken from the currentDate() | 77 | * end date taken from the currentDate() |
78 | */ | 78 | */ |
79 | List effectiveToDos( const QDate& start, | 79 | List effectiveToDos( const QDate& start, |
80 | bool includeNoDates = true ); | 80 | bool includeNoDates = true ); |
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
84 | * return overdue OPimTodos | 84 | * return overdue OPimTodos |
85 | */ | 85 | */ |
86 | List overDue(); | 86 | List overDue(); |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * | 89 | * |
90 | */ | 90 | */ |
91 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 91 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * merge a list of OPimTodos into | 94 | * merge a list of OPimTodos into |
95 | * the resource | 95 | * the resource |
96 | */ | 96 | */ |
97 | void mergeWith( const QValueList<OPimTodo>& ); | 97 | void mergeWith( const QValueList<OPimTodo>& ); |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * delete all already completed items | 100 | * delete all already completed items |
101 | */ | 101 | */ |
102 | void removeAllCompleted(); | 102 | void removeAllCompleted(); |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * request information about what a backend supports. | 105 | * request information about what a backend supports. |
106 | * Supports in the sense of beeing able to store. | 106 | * Supports in the sense of beeing able to store. |
107 | * This is related to the enum in OPimTodo | 107 | * This is related to the enum in OPimTodo |
108 | * | 108 | * |
109 | * @param backend Will be used in the future when we support multiple backend | 109 | * @param backend Will be used in the future when we support multiple backend |
110 | */ | 110 | */ |
111 | QBitArray backendSupport( const QString& backend = QString::null )const; | 111 | QBitArray backendSupport( const QString& backend = QString::null )const; |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * see above but for a specefic attribute. This method was added for convience | 114 | * see above but for a specefic attribute. This method was added for convience |
115 | * @param attr The attribute to be queried for | 115 | * @param attr The attribute to be queried for |
116 | * @param backend Will be used in the future when we support multiple backends | 116 | * @param backend Will be used in the future when we support multiple backends |
117 | */ | 117 | */ |
118 | bool backendSupports( int attr, const QString& backend = QString::null )const; | 118 | bool backendSupports( int attr, const QString& backend = QString::null )const; |
119 | |||
120 | |||
121 | /** | ||
122 | * Return identification of used records | ||
123 | */ | ||
124 | int rtti() const; | ||
119 | signals: | 125 | signals: |
120 | /** | 126 | /** |
121 | * if the OPimTodoAccess was changed | 127 | * if the OPimTodoAccess was changed |
122 | */ | 128 | */ |
123 | void changed( const OPimTodoAccess* ); | 129 | void changed( const OPimTodoAccess* ); |
124 | void changed( const OPimTodoAccess*, int uid ); | 130 | void changed( const OPimTodoAccess*, int uid ); |
125 | void added( const OPimTodoAccess*, int uid ); | 131 | void added( const OPimTodoAccess*, int uid ); |
126 | void removed( const OPimTodoAccess*, int uid ); | 132 | void removed( const OPimTodoAccess*, int uid ); |
127 | private: | 133 | private: |
128 | int m_cat; | 134 | int m_cat; |
129 | OPimTodoAccessBackend* m_todoBackEnd; | 135 | OPimTodoAccessBackend* m_todoBackEnd; |
130 | class OPimTodoAccessPrivate; | 136 | class OPimTodoAccessPrivate; |
131 | OPimTodoAccessPrivate* d; | 137 | OPimTodoAccessPrivate* d; |
132 | }; | 138 | }; |
133 | 139 | ||
134 | } | 140 | } |
135 | 141 | ||
136 | #endif | 142 | #endif |