summaryrefslogtreecommitdiff
path: root/libopie2
authoreilers <eilers>2004-04-28 09:22:02 (UTC)
committer eilers <eilers>2004-04-28 09:22:02 (UTC)
commit134b7accd6bdc8fbc160a42f7c52c585e73f4add (patch) (unidiff)
tree5e221e990d0c94e38d816e147762f205733b0e72 /libopie2
parent8ce67859c54234dabd88e17a0bc72369ea8301a3 (diff)
downloadopie-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
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp1
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp6
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h5
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp5
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h6
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h28
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h16
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp7
-rw-r--r--libopie2/opiepim/core/otodoaccess.h6
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
@@ -385,96 +385,97 @@ bool OPimContactAccessBackend_SQL::load ()
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
396bool OPimContactAccessBackend_SQL::reload() 396bool OPimContactAccessBackend_SQL::reload()
397{ 397{
398 return load(); 398 return load();
399} 399}
400 400
401bool OPimContactAccessBackend_SQL::save() 401bool 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
407void OPimContactAccessBackend_SQL::clear () 407void 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
415bool OPimContactAccessBackend_SQL::wasChangedExternally() 415bool OPimContactAccessBackend_SQL::wasChangedExternally()
416{ 416{
417 return false; 417 return false;
418} 418}
419 419
420QArray<int> OPimContactAccessBackend_SQL::allRecords() const 420QArray<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
431bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) 431bool 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
447bool OPimContactAccessBackend_SQL::remove ( int uid ) 448bool 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
460bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) 461bool 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
469OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const 470OPimContact 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}
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
@@ -7,96 +7,97 @@
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
56namespace Opie { 57namespace Opie {
57 58
58OPimContactAccess::OPimContactAccess ( const QString appname, const QString , 59OPimContactAccess::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}
86OPimContactAccess::~OPimContactAccess () 87OPimContactAccess::~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
96bool OPimContactAccess::save () 97bool 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() )
@@ -104,49 +105,54 @@ bool OPimContactAccess::save ()
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
115const uint OPimContactAccess::querySettings() 116const uint OPimContactAccess::querySettings()
116{ 117{
117 return ( m_backEnd->querySettings() ); 118 return ( m_backEnd->querySettings() );
118} 119}
119 120
120bool OPimContactAccess::hasQuerySettings ( int querySettings ) const 121bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
121{ 122{
122 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 123 return ( m_backEnd->hasQuerySettings ( querySettings ) );
123} 124}
124OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 125OPimRecordList<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
131bool OPimContactAccess::wasChangedExternally()const 132bool OPimContactAccess::wasChangedExternally()const
132{ 133{
133 return ( m_backEnd->wasChangedExternally() ); 134 return ( m_backEnd->wasChangedExternally() );
134} 135}
135 136
136 137
137void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) 138void 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
153int 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
@@ -82,77 +82,82 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
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
32namespace Opie { 33namespace 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 */
40ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) 41ODateBookAccess::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}
49ODateBookAccess::~ODateBookAccess() { 50ODateBookAccess::~ODateBookAccess() {
50} 51}
51 52
52/** 53/**
53 * @return all events available 54 * @return all events available
54 */ 55 */
55ODateBookAccess::List ODateBookAccess::rawEvents()const { 56ODateBookAccess::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 */
65ODateBookAccess::List ODateBookAccess::rawRepeats()const { 66ODateBookAccess::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 */
75ODateBookAccess::List ODateBookAccess::nonRepeats()const { 76ODateBookAccess::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 */
87OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { 88OEffectiveEvent::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 */
93OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { 94OEffectiveEvent::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 */
102OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { 103OEffectiveEvent::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 */
108OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { 109OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const {
109 return m_backEnd->effectiveNonRepeatingEvents( start ); 110 return m_backEnd->effectiveNonRepeatingEvents( start );
110} 111}
112int 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
@@ -19,57 +19,63 @@
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
37namespace Opie { 37namespace 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 */
47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { 47class ODateBookAccess : public OPimAccessTemplate<OPimEvent> {
48public: 48public:
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
67private: 73private:
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,51 +1,52 @@
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
41namespace Opie { 42namespace Opie {
42 43
43class OPimAccessTemplatePrivate; 44class 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 */
@@ -92,96 +93,103 @@ public:
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;
172protected: 180protected:
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
186private: 194private:
187 OPimAccessTemplatePrivate *d; 195 OPimAccessTemplatePrivate *d;
@@ -226,105 +234,119 @@ typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const Q
226 List lis(ints, this ); 234 List lis(ints, this );
227 return lis; 235 return lis;
228} 236}
229template <class T> 237template <class T>
230QArray<int> OPimAccessTemplate<T>::records()const { 238QArray<int> OPimAccessTemplate<T>::records()const {
231 return m_backEnd->allRecords(); 239 return m_backEnd->allRecords();
232} 240}
233template <class T> 241template <class T>
234typename OPimAccessTemplate<T>::List 242typename OPimAccessTemplate<T>::List
235OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 243OPimAccessTemplate<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}
241template <class T> 249template <class T>
242T OPimAccessTemplate<T>::find( int uid ) const{ 250T 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}
247template <class T> 255template <class T>
248T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 256T 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}
264template <class T> 272template <class T>
265void OPimAccessTemplate<T>::clear() { 273void OPimAccessTemplate<T>::clear() {
266 invalidateCache(); 274 invalidateCache();
267 m_backEnd->clear(); 275 m_backEnd->clear();
268} 276}
269template <class T> 277template <class T>
270bool OPimAccessTemplate<T>::add( const T& t ) { 278bool 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
274template <class T> 283template <class T>
275bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 284bool 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
294template <class T>
295bool 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
283template <class T> 305template <class T>
284bool OPimAccessTemplate<T>::remove( const T& t ) { 306bool OPimAccessTemplate<T>::remove( const T& t ) {
285 return remove( t.uid() ); 307 return remove( t.uid() );
286} 308}
287template <class T> 309template <class T>
288bool OPimAccessTemplate<T>::remove( int uid ) { 310bool 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}
292template <class T> 314template <class T>
293bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 315bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
294 return remove( rec.uid() ); 316 return remove( rec.uid() );
295} 317}
296template <class T> 318template <class T>
297bool OPimAccessTemplate<T>::replace( const T& t ) { 319bool 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}
301template <class T> 323template <class T>
302void OPimAccessTemplate<T>::invalidateCache() { 324void OPimAccessTemplate<T>::invalidateCache() {
303 m_cache.invalidate(); 325 m_cache.invalidate();
304} 326}
305template <class T> 327template <class T>
306typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 328typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
307 return m_backEnd; 329 return m_backEnd;
308} 330}
309template <class T> 331template <class T>
310bool OPimAccessTemplate<T>::wasChangedExternally()const { 332bool OPimAccessTemplate<T>::wasChangedExternally()const {
311 return false; 333 return false;
312} 334}
313template <class T> 335template <class T>
314void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 336void 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}
319template <class T> 341template <class T>
320void OPimAccessTemplate<T>::cache( const T& t ) const{ 342void 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}
324template <class T> 346template <class T>
325void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 347void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
326 m_cache.setSize( size ); 348 m_cache.setSize( size );
327} 349}
328template <class T> 350template <class T>
329void OPimAccessTemplate<T>::setReadAhead( uint count ) { 351void OPimAccessTemplate<T>::setReadAhead( uint count ) {
330 m_backEnd->setReadAhead( count ); 352 m_backEnd->setReadAhead( count );
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
38namespace Opie { 38namespace 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 */
47class OPimBasePrivate; 47class OPimBasePrivate;
48struct OPimBase { 48struct 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 */
66private: 67private:
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 */
74class OTemplateBasePrivate; 75class OTemplateBasePrivate;
75template <class T = OPimRecord> 76template <class T = OPimRecord>
76class OTemplateBase : public OPimBase { 77class OTemplateBase : public OPimBase {
77public: 78public:
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
99private: 98private:
100 OTemplateBasePrivate *d; 99 OTemplateBasePrivate *d;
101}; 100};
102 101
103/* 102
104 * implementation
105 */
106template <class T>
107int
108OTemplateBase<T>::rtti() {
109 return T::rtti();
110}
111template <class T> 103template <class T>
112OPimRecord* OTemplateBase<T>::record()const { 104OPimRecord* OTemplateBase<T>::record()const {
113 T* t = new T; 105 T* t = new T;
114 return t; 106 return t;
115} 107}
116template <class T> 108template <class T>
117OPimRecord* OTemplateBase<T>::record(int uid )const { 109OPimRecord* 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};
123template <class T> 115template <class T>
124T* OTemplateBase<T>::rec() { 116T* 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
37namespace Opie { 38namespace Opie {
38OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) 39OPimTodoAccess::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}
50OPimTodoAccess::~OPimTodoAccess() { 51OPimTodoAccess::~OPimTodoAccess() {
51// qWarning("~OPimTodoAccess"); 52// qWarning("~OPimTodoAccess");
52} 53}
53void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { 54void 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}
59OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 60OPimTodoAccess::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}
67OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 68OPimTodoAccess::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}
72OPimTodoAccess::List OPimTodoAccess::overDue() { 73OPimTodoAccess::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 */
77OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { 78OPimTodoAccess::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}
83void OPimTodoAccess::removeAllCompleted() { 84void OPimTodoAccess::removeAllCompleted() {
84 m_todoBackEnd->removeAllCompleted(); 85 m_todoBackEnd->removeAllCompleted();
85} 86}
86QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ 87QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
87 return m_todoBackEnd->supports(); 88 return m_todoBackEnd->supports();
88} 89}
89bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ 90bool 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
95int 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
@@ -71,66 +71,72 @@ public:
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;
119signals: 125signals:
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 );
127private: 133private:
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