-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_xml.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h index 50ea329..12a75ba 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.h | |||
@@ -14,12 +14,15 @@ | |||
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 | * |
@@ -53,13 +56,14 @@ | |||
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; |
@@ -72,12 +76,16 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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; |
@@ -120,12 +128,14 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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 | ||
@@ -142,12 +152,13 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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 ); |
@@ -272,17 +283,22 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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; |
@@ -297,12 +313,14 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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; |
@@ -550,12 +568,13 @@ class OContactAccessBackend_XML : public OContactAccessBackend { | |||
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 | }; |