author | eilers <eilers> | 2002-10-16 10:52:40 (UTC) |
---|---|---|
committer | eilers <eilers> | 2002-10-16 10:52:40 (UTC) |
commit | f9756ca203a06fa60413ef1a96416d87b9dc1a6b (patch) (unidiff) | |
tree | 0b67c3c485349a1c31ea82e7c12526b990654d58 /libopie/pim | |
parent | 9eba62fc184260f1a0455a6dd057e2ccebf4bdac (diff) | |
download | opie-f9756ca203a06fa60413ef1a96416d87b9dc1a6b.zip opie-f9756ca203a06fa60413ef1a96416d87b9dc1a6b.tar.gz opie-f9756ca203a06fa60413ef1a96416d87b9dc1a6b.tar.bz2 |
Added some docu to the interface and now using the cache infrastucture by zecke.. :)
-rw-r--r-- | libopie/pim/ocontactaccess.cpp | 57 | ||||
-rw-r--r-- | libopie/pim/ocontactaccess.h | 43 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.h | 21 | ||||
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 27 |
4 files changed, 55 insertions, 93 deletions
diff --git a/libopie/pim/ocontactaccess.cpp b/libopie/pim/ocontactaccess.cpp index e8c0a45..2ca0283 100644 --- a/libopie/pim/ocontactaccess.cpp +++ b/libopie/pim/ocontactaccess.cpp | |||
@@ -16,16 +16,19 @@ | |||
16 | * ToDo: XML-Backend: Automatic reload if something was changed... | 16 | * ToDo: XML-Backend: Automatic reload if something was changed... |
17 | * | 17 | * |
18 | * | 18 | * |
19 | * ===================================================================== | 19 | * ===================================================================== |
20 | * Version: $Id$ | 20 | * Version: $Id$ |
21 | * ===================================================================== | 21 | * ===================================================================== |
22 | * History: | 22 | * History: |
23 | * $Log$ | 23 | * $Log$ |
24 | * Revision 1.5 2002/10/16 10:52:40 eilers | ||
25 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
26 | * | ||
24 | * Revision 1.4 2002/10/14 16:21:54 eilers | 27 | * Revision 1.4 2002/10/14 16:21:54 eilers |
25 | * Some minor interface updates | 28 | * Some minor interface updates |
26 | * | 29 | * |
27 | * Revision 1.3 2002/10/07 17:34:24 eilers | 30 | * Revision 1.3 2002/10/07 17:34:24 eilers |
28 | * added OBackendFactory for advanced backend access | 31 | * added OBackendFactory for advanced backend access |
29 | * | 32 | * |
30 | * Revision 1.2 2002/10/02 16:18:11 eilers | 33 | * Revision 1.2 2002/10/02 16:18:11 eilers |
31 | * debugged and seems to work almost perfectly .. | 34 | * debugged and seems to work almost perfectly .. |
@@ -57,18 +60,17 @@ | |||
57 | #include <unistd.h> | 60 | #include <unistd.h> |
58 | #include <stdlib.h> | 61 | #include <stdlib.h> |
59 | 62 | ||
60 | #include "ocontactaccessbackend_xml.h" | 63 | #include "ocontactaccessbackend_xml.h" |
61 | 64 | ||
62 | 65 | ||
63 | OContactAccess::OContactAccess ( const QString appname, const QString , | 66 | OContactAccess::OContactAccess ( const QString appname, const QString , |
64 | OContactAccessBackend* end, bool autosync ): | 67 | OContactAccessBackend* end, bool autosync ): |
65 | OPimAccessTemplate<OContact>( end ), | 68 | OPimAccessTemplate<OContact>( end ) |
66 | m_changed ( false ) | ||
67 | { | 69 | { |
68 | /* take care of the backend. If there is no one defined, we | 70 | /* take care of the backend. If there is no one defined, we |
69 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 71 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
70 | */ | 72 | */ |
71 | if( end == 0 ) { | 73 | if( end == 0 ) { |
72 | qWarning ("Using BackendFactory !"); | 74 | qWarning ("Using BackendFactory !"); |
73 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); | 75 | end = OBackendFactory<OContactAccessBackend>::Default( "contact", appname ); |
74 | } | 76 | } |
@@ -89,94 +91,57 @@ OContactAccess::OContactAccess ( const QString appname, const QString , | |||
89 | 91 | ||
90 | 92 | ||
91 | } | 93 | } |
92 | OContactAccess::~OContactAccess () | 94 | OContactAccess::~OContactAccess () |
93 | { | 95 | { |
94 | /* The user may forget to save the changed database, therefore try to | 96 | /* The user may forget to save the changed database, therefore try to |
95 | * do it for him.. | 97 | * do it for him.. |
96 | */ | 98 | */ |
97 | if ( m_changed ) | 99 | save(); |
98 | save(); | ||
99 | // delete m_backEnd; is done by template.. | 100 | // delete m_backEnd; is done by template.. |
100 | } | 101 | } |
101 | 102 | ||
102 | bool OContactAccess::load() | ||
103 | { | ||
104 | return ( m_backEnd->load() ); | ||
105 | } | ||
106 | 103 | ||
107 | bool OContactAccess::save () | 104 | bool OContactAccess::save () |
108 | { | 105 | { |
109 | /* If the database was changed externally, we could not save the | 106 | /* If the database was changed externally, we could not save the |
110 | * Data. This will remove added items which is unacceptable ! | 107 | * Data. This will remove added items which is unacceptable ! |
111 | * Therefore: Reload database and merge the data... | 108 | * Therefore: Reload database and merge the data... |
112 | */ | 109 | */ |
113 | if ( m_backEnd->wasChangedExternally() ) | 110 | if ( OPimAccessTemplate<OContact>::wasChangedExternally() ) |
114 | reload(); | 111 | reload(); |
115 | 112 | ||
116 | if ( m_changed ){ | 113 | bool status = OPimAccessTemplate<OContact>::save(); |
117 | bool status = m_backEnd->save(); | 114 | if ( !status ) return false; |
118 | if ( !status ) return false; | ||
119 | 115 | ||
120 | m_changed = false; | 116 | /* Now tell everyone that new data is available. |
121 | /* Now tell everyone that new data is available. | 117 | */ |
122 | */ | 118 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
123 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | ||
124 | |||
125 | } | ||
126 | 119 | ||
127 | return true; | 120 | return true; |
128 | } | 121 | } |
129 | 122 | ||
130 | const uint OContactAccess::querySettings() | 123 | const uint OContactAccess::querySettings() |
131 | { | 124 | { |
132 | return ( m_backEnd->querySettings() ); | 125 | return ( m_backEnd->querySettings() ); |
133 | } | 126 | } |
134 | 127 | ||
135 | bool OContactAccess::hasQuerySettings ( int querySettings ) const | 128 | bool OContactAccess::hasQuerySettings ( int querySettings ) const |
136 | { | 129 | { |
137 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 130 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
138 | } | 131 | } |
139 | 132 | ||
140 | bool OContactAccess::add ( const OContact& newcontact ) | ||
141 | { | ||
142 | m_changed = true; | ||
143 | return ( m_backEnd->add ( newcontact ) ); | ||
144 | } | ||
145 | |||
146 | bool OContactAccess::replace ( const OContact& contact ) | ||
147 | { | ||
148 | m_changed = true; | ||
149 | return ( m_backEnd->replace ( contact ) ); | ||
150 | } | ||
151 | |||
152 | bool OContactAccess::remove ( const OContact& t ) | ||
153 | { | ||
154 | m_changed = true; | ||
155 | return ( m_backEnd->remove ( t.uid() ) ); | ||
156 | } | ||
157 | |||
158 | bool OContactAccess::remove ( int uid ) | ||
159 | { | ||
160 | m_changed = true; | ||
161 | return ( m_backEnd->remove ( uid ) ); | ||
162 | } | ||
163 | 133 | ||
164 | bool OContactAccess::wasChangedExternally()const | 134 | bool OContactAccess::wasChangedExternally()const |
165 | { | 135 | { |
166 | return ( m_backEnd->wasChangedExternally() ); | 136 | return ( m_backEnd->wasChangedExternally() ); |
167 | } | 137 | } |
168 | 138 | ||
169 | 139 | ||
170 | bool OContactAccess::reload() | ||
171 | { | ||
172 | return ( m_backEnd->reload() ); | ||
173 | } | ||
174 | |||
175 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 140 | void OContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
176 | { | 141 | { |
177 | if ( msg == "addressbookUpdated()" ){ | 142 | if ( msg == "addressbookUpdated()" ){ |
178 | qWarning ("OContactAccess: Received addressbokUpdated()"); | 143 | qWarning ("OContactAccess: Received addressbokUpdated()"); |
179 | emit signalChanged ( this ); | 144 | emit signalChanged ( this ); |
180 | } else if ( msg == "flush()" ) { | 145 | } else if ( msg == "flush()" ) { |
181 | qWarning ("OContactAccess: Received flush()"); | 146 | qWarning ("OContactAccess: Received flush()"); |
182 | save (); | 147 | save (); |
diff --git a/libopie/pim/ocontactaccess.h b/libopie/pim/ocontactaccess.h index adc66cf..da9c942 100644 --- a/libopie/pim/ocontactaccess.h +++ b/libopie/pim/ocontactaccess.h | |||
@@ -12,16 +12,19 @@ | |||
12 | * version. | 12 | * version. |
13 | * ===================================================================== | 13 | * ===================================================================== |
14 | * ToDo: Define enum for query settings | 14 | * ToDo: Define enum for query settings |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.3 2002/10/16 10:52:40 eilers | ||
21 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
22 | * | ||
20 | * Revision 1.2 2002/10/14 16:21:54 eilers | 23 | * Revision 1.2 2002/10/14 16:21:54 eilers |
21 | * Some minor interface updates | 24 | * Some minor interface updates |
22 | * | 25 | * |
23 | * Revision 1.1 2002/09/27 17:11:44 eilers | 26 | * Revision 1.1 2002/09/27 17:11:44 eilers |
24 | * Added API for accessing the Contact-Database ! It is compiling, but | 27 | * Added API for accessing the Contact-Database ! It is compiling, but |
25 | * please do not expect that anything is working ! | 28 | * please do not expect that anything is working ! |
26 | * I will debug that stuff in the next time .. | 29 | * I will debug that stuff in the next time .. |
27 | * Please read README_COMPILE for compiling ! | 30 | * Please read README_COMPILE for compiling ! |
@@ -86,61 +89,22 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | |||
86 | */ | 89 | */ |
87 | const uint querySettings(); | 90 | const uint querySettings(); |
88 | 91 | ||
89 | /** Check whether settings are correct. | 92 | /** Check whether settings are correct. |
90 | * @return <i>true</i> if the given settings are correct and possible. | 93 | * @return <i>true</i> if the given settings are correct and possible. |
91 | */ | 94 | */ |
92 | bool hasQuerySettings ( int querySettings ) const; | 95 | bool hasQuerySettings ( int querySettings ) const; |
93 | 96 | ||
94 | /** Add Contact to database. | ||
95 | * @param newcontact The contact to add. | ||
96 | * @return <i>true</i> if added successfully. | ||
97 | */ | ||
98 | bool add (const OContact& newcontact); | ||
99 | |||
100 | /** Replace contact. | ||
101 | * Replaces given contact with contact with the user id <i>uid</i>. | ||
102 | * @param uid The user ID | ||
103 | * @param contact The new contact | ||
104 | * @return <i>true</i> if successful. | ||
105 | */ | ||
106 | bool replace ( const OContact& contact ); | ||
107 | |||
108 | /** Remove contact. | ||
109 | * Removes contact with the user id <i>uid</i>. | ||
110 | * @param The contact to remove | ||
111 | * @return <i>true</i> if successful. | ||
112 | */ | ||
113 | bool remove ( const OContact& t ); | ||
114 | |||
115 | /** Remove contact. | ||
116 | * Removes contact with the user id <i>uid</i>. | ||
117 | * @param The user id of the contact to remove | ||
118 | * @return <i>true</i> if successful. | ||
119 | */ | ||
120 | bool remove ( int uid ); | ||
121 | |||
122 | /** Load Database * | ||
123 | */ | ||
124 | bool load(); | ||
125 | |||
126 | /** | 97 | /** |
127 | * if the resource was changed externally. | 98 | * if the resource was changed externally. |
128 | * You should use the signal instead of polling possible changes ! | 99 | * You should use the signal instead of polling possible changes ! |
129 | */ | 100 | */ |
130 | bool wasChangedExternally()const; | 101 | bool wasChangedExternally()const; |
131 | 102 | ||
132 | /** Reload database. | ||
133 | * You should execute this function if the external database | ||
134 | * was changed. | ||
135 | * This function will load the external database and afterwards | ||
136 | * rejoin the local changes. Therefore the local database will be set consistent. | ||
137 | */ | ||
138 | bool reload(); | ||
139 | 103 | ||
140 | /** Save contacts database. | 104 | /** Save contacts database. |
141 | * Save is more a "commit". After calling this function, all changes are public available. | 105 | * Save is more a "commit". After calling this function, all changes are public available. |
142 | * @return true if successful | 106 | * @return true if successful |
143 | */ | 107 | */ |
144 | bool save(); | 108 | bool save(); |
145 | 109 | ||
146 | signals: | 110 | signals: |
@@ -153,16 +117,15 @@ class OContactAccess: public QObject, public OPimAccessTemplate<OContact> | |||
153 | void signalChanged ( const OContactAccess *which ); | 117 | void signalChanged ( const OContactAccess *which ); |
154 | 118 | ||
155 | 119 | ||
156 | private: | 120 | private: |
157 | // class OContactAccessPrivate; | 121 | // class OContactAccessPrivate; |
158 | // OContactAccessPrivate* d; | 122 | // OContactAccessPrivate* d; |
159 | OContactAccessBackend *m_backEnd; | 123 | OContactAccessBackend *m_backEnd; |
160 | bool m_loading:1; | 124 | bool m_loading:1; |
161 | bool m_changed; | ||
162 | 125 | ||
163 | private slots: | 126 | private slots: |
164 | void copMessage( const QCString &msg, const QByteArray &data ); | 127 | void copMessage( const QCString &msg, const QByteArray &data ); |
165 | 128 | ||
166 | 129 | ||
167 | }; | 130 | }; |
168 | #endif | 131 | #endif |
diff --git a/libopie/pim/ocontactaccessbackend_xml.h b/libopie/pim/ocontactaccessbackend_xml.h index 50ea329..12a75ba 100644 --- a/libopie/pim/ocontactaccessbackend_xml.h +++ b/libopie/pim/ocontactaccessbackend_xml.h | |||
@@ -12,16 +12,19 @@ | |||
12 | * ToDo: XML-Backend: Automatic reload if something was changed... | 12 | * ToDo: XML-Backend: Automatic reload if something was changed... |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * ===================================================================== | 15 | * ===================================================================== |
16 | * Version: $Id$ | 16 | * Version: $Id$ |
17 | * ===================================================================== | 17 | * ===================================================================== |
18 | * History: | 18 | * History: |
19 | * $Log$ | 19 | * $Log$ |
20 | * Revision 1.4 2002/10/16 10:52:40 eilers | ||
21 | * Added some docu to the interface and now using the cache infrastucture by zecke.. :) | ||
22 | * | ||
20 | * Revision 1.3 2002/10/14 16:21:54 eilers | 23 | * Revision 1.3 2002/10/14 16:21:54 eilers |
21 | * Some minor interface updates | 24 | * Some minor interface updates |
22 | * | 25 | * |
23 | * Revision 1.2 2002/10/07 17:34:24 eilers | 26 | * Revision 1.2 2002/10/07 17:34:24 eilers |
24 | * added OBackendFactory for advanced backend access | 27 | * added OBackendFactory for advanced backend access |
25 | * | 28 | * |
26 | * Revision 1.1 2002/09/27 17:11:44 eilers | 29 | * Revision 1.1 2002/09/27 17:11:44 eilers |
27 | * Added API for accessing the Contact-Database ! It is compiling, but | 30 | * Added API for accessing the Contact-Database ! It is compiling, but |
@@ -51,17 +54,18 @@ | |||
51 | #include <stdlib.h> | 54 | #include <stdlib.h> |
52 | #include <errno.h> | 55 | #include <errno.h> |
53 | 56 | ||
54 | using namespace Opie; | 57 | using namespace Opie; |
55 | 58 | ||
56 | /* the default xml implementation */ | 59 | /* the default xml implementation */ |
57 | class OContactAccessBackend_XML : public OContactAccessBackend { | 60 | class OContactAccessBackend_XML : public OContactAccessBackend { |
58 | public: | 61 | public: |
59 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ) | 62 | OContactAccessBackend_XML ( QString appname, QString filename = 0l ): |
63 | m_changed( false ) | ||
60 | { | 64 | { |
61 | m_appName = appname; | 65 | m_appName = appname; |
62 | 66 | ||
63 | /* Set journalfile name ... */ | 67 | /* Set journalfile name ... */ |
64 | m_journalName = getenv("HOME"); | 68 | m_journalName = getenv("HOME"); |
65 | m_journalName +="/.abjournal" + appname; | 69 | m_journalName +="/.abjournal" + appname; |
66 | 70 | ||
67 | /* Expecting to access the default filename if nothing else is set */ | 71 | /* Expecting to access the default filename if nothing else is set */ |
@@ -70,16 +74,20 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
70 | } else | 74 | } else |
71 | m_fileName = filename; | 75 | m_fileName = filename; |
72 | 76 | ||
73 | /* Load Database now */ | 77 | /* Load Database now */ |
74 | load (); | 78 | load (); |
75 | } | 79 | } |
76 | 80 | ||
77 | bool save() { | 81 | bool save() { |
82 | |||
83 | if ( !m_changed ) | ||
84 | return true; | ||
85 | |||
78 | QString strNewFile = m_fileName + ".new"; | 86 | QString strNewFile = m_fileName + ".new"; |
79 | QFile f( strNewFile ); | 87 | QFile f( strNewFile ); |
80 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | 88 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) |
81 | return false; | 89 | return false; |
82 | 90 | ||
83 | int total_written; | 91 | int total_written; |
84 | QString out; | 92 | QString out; |
85 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | 93 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" |
@@ -118,16 +126,18 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
118 | qWarning( "problem renaming file %s to %s, errno: %d", | 126 | qWarning( "problem renaming file %s to %s, errno: %d", |
119 | strNewFile.latin1(), m_journalName.latin1(), errno ); | 127 | strNewFile.latin1(), m_journalName.latin1(), errno ); |
120 | // remove the tmp file... | 128 | // remove the tmp file... |
121 | QFile::remove( strNewFile ); | 129 | QFile::remove( strNewFile ); |
122 | } | 130 | } |
123 | 131 | ||
124 | /* The journalfile should be removed now... */ | 132 | /* The journalfile should be removed now... */ |
125 | removeJournal(); | 133 | removeJournal(); |
134 | |||
135 | m_changed = false; | ||
126 | return true; | 136 | return true; |
127 | } | 137 | } |
128 | 138 | ||
129 | bool load () { | 139 | bool load () { |
130 | m_contactList.clear(); | 140 | m_contactList.clear(); |
131 | 141 | ||
132 | /* Load XML-File and journal if it exists */ | 142 | /* Load XML-File and journal if it exists */ |
133 | if ( !load ( m_fileName, false ) ) | 143 | if ( !load ( m_fileName, false ) ) |
@@ -140,16 +150,17 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
140 | */ | 150 | */ |
141 | load (m_journalName, true); | 151 | load (m_journalName, true); |
142 | 152 | ||
143 | return true; | 153 | return true; |
144 | } | 154 | } |
145 | 155 | ||
146 | void clear () { | 156 | void clear () { |
147 | m_contactList.clear(); | 157 | m_contactList.clear(); |
158 | m_changed = false; | ||
148 | 159 | ||
149 | } | 160 | } |
150 | 161 | ||
151 | bool wasChangedExternally() | 162 | bool wasChangedExternally() |
152 | { | 163 | { |
153 | QFileInfo fi( m_fileName ); | 164 | QFileInfo fi( m_fileName ); |
154 | 165 | ||
155 | QDateTime lastmod = fi.lastModified (); | 166 | QDateTime lastmod = fi.lastModified (); |
@@ -270,21 +281,26 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
270 | } | 281 | } |
271 | } | 282 | } |
272 | 283 | ||
273 | bool add ( const OContact &newcontact ) | 284 | bool add ( const OContact &newcontact ) |
274 | { | 285 | { |
275 | //qWarning("odefaultbackend: ACTION::ADD"); | 286 | //qWarning("odefaultbackend: ACTION::ADD"); |
276 | updateJournal (newcontact, OContact::ACTION_ADD); | 287 | updateJournal (newcontact, OContact::ACTION_ADD); |
277 | addContact_p( newcontact ); | 288 | addContact_p( newcontact ); |
289 | |||
290 | m_changed = true; | ||
291 | |||
278 | return true; | 292 | return true; |
279 | } | 293 | } |
280 | 294 | ||
281 | bool replace ( const OContact &contact ) | 295 | bool replace ( const OContact &contact ) |
282 | { | 296 | { |
297 | m_changed = true; | ||
298 | |||
283 | bool found = false; | 299 | bool found = false; |
284 | 300 | ||
285 | QValueListIterator<OContact> it; | 301 | QValueListIterator<OContact> it; |
286 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 302 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
287 | if ( (*it).uid() == contact.uid() ){ | 303 | if ( (*it).uid() == contact.uid() ){ |
288 | found = true; | 304 | found = true; |
289 | break; | 305 | break; |
290 | } | 306 | } |
@@ -295,16 +311,18 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
295 | m_contactList.append (contact); | 311 | m_contactList.append (contact); |
296 | return true; | 312 | return true; |
297 | } else | 313 | } else |
298 | return false; | 314 | return false; |
299 | } | 315 | } |
300 | 316 | ||
301 | bool remove ( int uid ) | 317 | bool remove ( int uid ) |
302 | { | 318 | { |
319 | m_changed = true; | ||
320 | |||
303 | bool found = false; | 321 | bool found = false; |
304 | QValueListIterator<OContact> it; | 322 | QValueListIterator<OContact> it; |
305 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ | 323 | for( it = m_contactList.begin(); it != m_contactList.end(); ++it ){ |
306 | if ((*it).uid() == uid){ | 324 | if ((*it).uid() == uid){ |
307 | found = true; | 325 | found = true; |
308 | break; | 326 | break; |
309 | } | 327 | } |
310 | } | 328 | } |
@@ -548,16 +566,17 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
548 | void removeJournal() | 566 | void removeJournal() |
549 | { | 567 | { |
550 | QFile f ( m_journalName ); | 568 | QFile f ( m_journalName ); |
551 | if ( f.exists() ) | 569 | if ( f.exists() ) |
552 | f.remove(); | 570 | f.remove(); |
553 | } | 571 | } |
554 | 572 | ||
555 | protected: | 573 | protected: |
574 | bool m_changed; | ||
556 | QString m_journalName; | 575 | QString m_journalName; |
557 | QString m_fileName; | 576 | QString m_fileName; |
558 | QString m_appName; | 577 | QString m_appName; |
559 | QValueList<OContact> m_contactList; | 578 | QValueList<OContact> m_contactList; |
560 | QDateTime m_readtime; | 579 | QDateTime m_readtime; |
561 | }; | 580 | }; |
562 | 581 | ||
563 | #endif | 582 | #endif |
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 3e1f393..50cb1e4 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -32,39 +32,45 @@ public: | |||
32 | OPimAccessTemplate( BackEnd* end); | 32 | OPimAccessTemplate( BackEnd* end); |
33 | virtual ~OPimAccessTemplate(); | 33 | virtual ~OPimAccessTemplate(); |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * load from the backend | 36 | * load from the backend |
37 | */ | 37 | */ |
38 | virtual bool load(); | 38 | virtual bool load(); |
39 | 39 | ||
40 | /** | 40 | /** Reload database. |
41 | * reload from the backend | 41 | * You should execute this function if the external database |
42 | * was changed. | ||
43 | * This function will load the external database and afterwards | ||
44 | * rejoin the local changes. Therefore the local database will be set consistent. | ||
42 | */ | 45 | */ |
43 | virtual bool reload(); | 46 | virtual bool reload(); |
44 | 47 | ||
45 | /** | 48 | /** Save contacts database. |
46 | * save to the backend | 49 | * Save is more a "commit". After calling this function, all changes are public available. |
50 | * @return true if successful | ||
47 | */ | 51 | */ |
48 | virtual bool save(); | 52 | virtual bool save(); |
49 | 53 | ||
50 | /** | 54 | /** |
51 | * if the resource was changed externally | 55 | * if the resource was changed externally |
56 | * You should use the signal handling instead of polling possible changes ! | ||
57 | * zecke: Do you implement a signal for otodoaccess ? | ||
52 | */ | 58 | */ |
53 | bool wasChangedExternally()const; | 59 | bool wasChangedExternally()const; |
54 | 60 | ||
55 | /** | 61 | /** |
56 | * return a List of records | 62 | * return a List of records |
57 | * you can iterate over them | 63 | * you can iterate over them |
58 | */ | 64 | */ |
59 | virtual List allRecords()const; | 65 | virtual List allRecords()const; |
60 | 66 | ||
61 | /** | 67 | /** |
62 | * queryByExample) | 68 | * queryByExample. |
63 | * @see otodoaccess, ocontactaccess | 69 | * @see otodoaccess, ocontactaccess |
64 | */ | 70 | */ |
65 | virtual List queryByExample( const T& t, int querySettings ); | 71 | virtual List queryByExample( const T& t, int querySettings ); |
66 | 72 | ||
67 | /** | 73 | /** |
68 | * find the OPimRecord uid | 74 | * find the OPimRecord uid |
69 | */ | 75 | */ |
70 | virtual T find( int uid )const; | 76 | virtual T find( int uid )const; |
@@ -78,32 +84,40 @@ public: | |||
78 | /* invalidate cache here */ | 84 | /* invalidate cache here */ |
79 | /** | 85 | /** |
80 | * clears the backend and invalidates the backend | 86 | * clears the backend and invalidates the backend |
81 | */ | 87 | */ |
82 | virtual void clear() ; | 88 | virtual void clear() ; |
83 | 89 | ||
84 | /** | 90 | /** |
85 | * add T to the backend | 91 | * add T to the backend |
92 | * @param t The item to add. | ||
93 | * @return <i>true</i> if added successfully. | ||
86 | */ | 94 | */ |
87 | virtual bool add( const T& t ) ; | 95 | virtual bool add( const T& t ) ; |
88 | 96 | ||
89 | /* only the uid matters */ | 97 | /* only the uid matters */ |
90 | /** | 98 | /** |
91 | * remove T from the backend | 99 | * remove T from the backend |
100 | * @param t The item to remove | ||
101 | * @return <i>true</i> if successful. | ||
92 | */ | 102 | */ |
93 | virtual bool remove( const T& t ); | 103 | virtual bool remove( const T& t ); |
94 | 104 | ||
95 | /** | 105 | /** |
96 | * remove the OPimRecord with uid | 106 | * remove the OPimRecord with uid |
107 | * @param uid The ID of the item to remove | ||
108 | * @return <i>true</i> if successful. | ||
97 | */ | 109 | */ |
98 | virtual bool remove( int uid ); | 110 | virtual bool remove( int uid ); |
99 | 111 | ||
100 | /** | 112 | /** |
101 | * replace T from backend | 113 | * replace T from backend |
114 | * @param t The item to replace | ||
115 | * @return <i>true</i> if successful. | ||
102 | */ | 116 | */ |
103 | virtual bool replace( const T& t) ; | 117 | virtual bool replace( const T& t) ; |
104 | 118 | ||
105 | /** | 119 | /** |
106 | * @internal | 120 | * @internal |
107 | */ | 121 | */ |
108 | void cache( const T& )const; | 122 | void cache( const T& )const; |
109 | void setSaneCacheSize( int ); | 123 | void setSaneCacheSize( int ); |
@@ -137,17 +151,18 @@ OPimAccessTemplate<T>::~OPimAccessTemplate() { | |||
137 | } | 151 | } |
138 | template <class T> | 152 | template <class T> |
139 | bool OPimAccessTemplate<T>::load() { | 153 | bool OPimAccessTemplate<T>::load() { |
140 | invalidateCache(); | 154 | invalidateCache(); |
141 | return m_backEnd->load(); | 155 | return m_backEnd->load(); |
142 | } | 156 | } |
143 | template <class T> | 157 | template <class T> |
144 | bool OPimAccessTemplate<T>::reload() { | 158 | bool OPimAccessTemplate<T>::reload() { |
145 | return m_backEnd->reload(); | 159 | invalidateCache(); // zecke: I think this should be added (se) |
160 | return m_backEnd->reload(); | ||
146 | } | 161 | } |
147 | template <class T> | 162 | template <class T> |
148 | bool OPimAccessTemplate<T>::save() { | 163 | bool OPimAccessTemplate<T>::save() { |
149 | return m_backEnd->save(); | 164 | return m_backEnd->save(); |
150 | } | 165 | } |
151 | template <class T> | 166 | template <class T> |
152 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 167 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
153 | QArray<int> ints = m_backEnd->allRecords(); | 168 | QArray<int> ints = m_backEnd->allRecords(); |