summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp1182
1 files changed, 593 insertions, 589 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 7b4d81f..5ffcb11 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -27,724 +27,728 @@
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29/* 29/*
30 * XML Backend for the OPIE-Contact Database. 30 * XML Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33
34/* OPIE */
33#include <opie2/ocontactaccessbackend_xml.h> 35#include <opie2/ocontactaccessbackend_xml.h>
36#include <opie2/xmltree.h>
37#include <opie2/ocontactaccessbackend.h>
38#include <opie2/ocontactaccess.h>
39#include <opie2/odebug.h>
40
41#include <qpe/global.h>
34 42
43/* QT */
35#include <qasciidict.h> 44#include <qasciidict.h>
36#include <qfile.h> 45#include <qfile.h>
37#include <qfileinfo.h> 46#include <qfileinfo.h>
38#include <qregexp.h> 47#include <qregexp.h>
39#include <qarray.h> 48#include <qarray.h>
40#include <qmap.h> 49#include <qmap.h>
41 50
42#include <qpe/global.h> 51/* STD */
43
44#include <opie2/xmltree.h>
45#include <opie2/ocontactaccessbackend.h>
46#include <opie2/ocontactaccess.h>
47
48#include <stdlib.h> 52#include <stdlib.h>
49#include <errno.h> 53#include <errno.h>
50 54
51using namespace Opie::Core; 55using namespace Opie::Core;
52 56
53 57
54namespace Opie { 58namespace Opie {
55OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ): 59OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ):
56 m_changed( false ) 60 m_changed( false )
57{ 61{
58 // Just m_contactlist should call delete if an entry 62 // Just m_contactlist should call delete if an entry
59 // is removed. 63 // is removed.
60 m_contactList.setAutoDelete( true ); 64 m_contactList.setAutoDelete( true );
61 m_uidToContact.setAutoDelete( false ); 65 m_uidToContact.setAutoDelete( false );
62 66
63 m_appName = appname; 67 m_appName = appname;
64 68
65 /* Set journalfile name ... */ 69 /* Set journalfile name ... */
66 m_journalName = getenv("HOME"); 70 m_journalName = getenv("HOME");
67 m_journalName +="/.abjournal" + appname; 71 m_journalName +="/.abjournal" + appname;
68 72
69 /* Expecting to access the default filename if nothing else is set */ 73 /* Expecting to access the default filename if nothing else is set */
70 if ( filename.isEmpty() ){ 74 if ( filename.isEmpty() ){
71 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 75 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
72 } else 76 } else
73 m_fileName = filename; 77 m_fileName = filename;
74 78
75 /* Load Database now */ 79 /* Load Database now */
76 load (); 80 load ();
77} 81}
78 82
79bool OPimContactAccessBackend_XML::save() 83bool OPimContactAccessBackend_XML::save()
80{ 84{
81 85
82 if ( !m_changed ) 86 if ( !m_changed )
83 return true; 87 return true;
84 88
85 QString strNewFile = m_fileName + ".new"; 89 QString strNewFile = m_fileName + ".new";
86 QFile f( strNewFile ); 90 QFile f( strNewFile );
87 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 91 if ( !f.open( IO_WriteOnly|IO_Raw ) )
88 return false; 92 return false;
89 93
90 int total_written; 94 int total_written;
91 int idx_offset = 0; 95 int idx_offset = 0;
92 QString out; 96 QString out;
93 97
94 // Write Header 98 // Write Header
95 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 99 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
96 " <Groups>\n" 100 " <Groups>\n"
97 " </Groups>\n" 101 " </Groups>\n"
98 " <Contacts>\n"; 102 " <Contacts>\n";
99 QCString cstr = out.utf8(); 103 QCString cstr = out.utf8();
100 f.writeBlock( cstr.data(), cstr.length() ); 104 f.writeBlock( cstr.data(), cstr.length() );
101 idx_offset += cstr.length(); 105 idx_offset += cstr.length();
102 out = ""; 106 out = "";
103 107
104 // Write all contacts 108 // Write all contacts
105 QListIterator<OPimContact> it( m_contactList ); 109 QListIterator<OPimContact> it( m_contactList );
106 for ( ; it.current(); ++it ) { 110 for ( ; it.current(); ++it ) {
107 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); 111 // owarn << " Uid " << (*it)->uid() << " at Offset: " << idx_offset << "" << oendl;
108 out += "<Contact "; 112 out += "<Contact ";
109 (*it)->save( out ); 113 (*it)->save( out );
110 out += "/>\n"; 114 out += "/>\n";
111 cstr = out.utf8(); 115 cstr = out.utf8();
112 total_written = f.writeBlock( cstr.data(), cstr.length() ); 116 total_written = f.writeBlock( cstr.data(), cstr.length() );
113 idx_offset += cstr.length(); 117 idx_offset += cstr.length();
114 if ( total_written != int(cstr.length()) ) { 118 if ( total_written != int(cstr.length()) ) {
115 f.close(); 119 f.close();
116 QFile::remove( strNewFile ); 120 QFile::remove( strNewFile );
117 return false; 121 return false;
118 } 122 }
119 out = ""; 123 out = "";
120 } 124 }
121 out += " </Contacts>\n</AddressBook>\n"; 125 out += " </Contacts>\n</AddressBook>\n";
122 126
123 // Write Footer 127 // Write Footer
124 cstr = out.utf8(); 128 cstr = out.utf8();
125 total_written = f.writeBlock( cstr.data(), cstr.length() ); 129 total_written = f.writeBlock( cstr.data(), cstr.length() );
126 if ( total_written != int( cstr.length() ) ) { 130 if ( total_written != int( cstr.length() ) ) {
127 f.close(); 131 f.close();
128 QFile::remove( strNewFile ); 132 QFile::remove( strNewFile );
129 return false; 133 return false;
130 } 134 }
131 f.close(); 135 f.close();
132 136
133 // move the file over, I'm just going to use the system call 137 // move the file over, I'm just going to use the system call
134 // because, I don't feel like using QDir. 138 // because, I don't feel like using QDir.
135 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 139 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
136 qWarning( "problem renaming file %s to %s, errno: %d", 140 qWarning( "problem renaming file %s to %s, errno: %d",
137 strNewFile.latin1(), m_journalName.latin1(), errno ); 141 strNewFile.latin1(), m_journalName.latin1(), errno );
138 // remove the tmp file... 142 // remove the tmp file...
139 QFile::remove( strNewFile ); 143 QFile::remove( strNewFile );
140 } 144 }
141 145
142 /* The journalfile should be removed now... */ 146 /* The journalfile should be removed now... */
143 removeJournal(); 147 removeJournal();
144 148
145 m_changed = false; 149 m_changed = false;
146 return true; 150 return true;
147} 151}
148 152
149bool OPimContactAccessBackend_XML::load () 153bool OPimContactAccessBackend_XML::load ()
150{ 154{
151 m_contactList.clear(); 155 m_contactList.clear();
152 m_uidToContact.clear(); 156 m_uidToContact.clear();
153 157
154 /* Load XML-File and journal if it exists */ 158 /* Load XML-File and journal if it exists */
155 if ( !load ( m_fileName, false ) ) 159 if ( !load ( m_fileName, false ) )
156 return false; 160 return false;
157 /* The returncode of the journalfile is ignored due to the 161 /* The returncode of the journalfile is ignored due to the
158 * fact that it does not exist when this class is instantiated ! 162 * fact that it does not exist when this class is instantiated !
159 * But there may such a file exist, if the application crashed. 163 * But there may such a file exist, if the application crashed.
160 * Therefore we try to load it to get the changes before the # 164 * Therefore we try to load it to get the changes before the #
161 * crash happened... 165 * crash happened...
162 */ 166 */
163 load (m_journalName, true); 167 load (m_journalName, true);
164 168
165 return true; 169 return true;
166} 170}
167 171
168void OPimContactAccessBackend_XML::clear () 172void OPimContactAccessBackend_XML::clear ()
169{ 173{
170 m_contactList.clear(); 174 m_contactList.clear();
171 m_uidToContact.clear(); 175 m_uidToContact.clear();
172 176
173 m_changed = false; 177 m_changed = false;
174} 178}
175 179
176bool OPimContactAccessBackend_XML::wasChangedExternally() 180bool OPimContactAccessBackend_XML::wasChangedExternally()
177{ 181{
178 QFileInfo fi( m_fileName ); 182 QFileInfo fi( m_fileName );
179 183
180 QDateTime lastmod = fi.lastModified (); 184 QDateTime lastmod = fi.lastModified ();
181 185
182 return (lastmod != m_readtime); 186 return (lastmod != m_readtime);
183} 187}
184 188
185QArray<int> OPimContactAccessBackend_XML::allRecords() const 189QArray<int> OPimContactAccessBackend_XML::allRecords() const
186{ 190{
187 QArray<int> uid_list( m_contactList.count() ); 191 QArray<int> uid_list( m_contactList.count() );
188 192
189 uint counter = 0; 193 uint counter = 0;
190 QListIterator<OPimContact> it( m_contactList ); 194 QListIterator<OPimContact> it( m_contactList );
191 for( ; it.current(); ++it ){ 195 for( ; it.current(); ++it ){
192 uid_list[counter++] = (*it)->uid(); 196 uid_list[counter++] = (*it)->uid();
193 } 197 }
194 198
195 return ( uid_list ); 199 return ( uid_list );
196} 200}
197 201
198OPimContact OPimContactAccessBackend_XML::find ( int uid ) const 202OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
199{ 203{
200 OPimContact foundContact; //Create empty contact 204 OPimContact foundContact; //Create empty contact
201 205
202 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) ); 206 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) );
203 207
204 if ( found ){ 208 if ( found ){
205 foundContact = *found; 209 foundContact = *found;
206 } 210 }
207 211
208 return ( foundContact ); 212 return ( foundContact );
209} 213}
210 214
211QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, 215QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
212 const QDateTime& d ) 216 const QDateTime& d )
213{ 217{
214 218
215 QArray<int> m_currentQuery( m_contactList.count() ); 219 QArray<int> m_currentQuery( m_contactList.count() );
216 QListIterator<OPimContact> it( m_contactList ); 220 QListIterator<OPimContact> it( m_contactList );
217 uint arraycounter = 0; 221 uint arraycounter = 0;
218 222
219 for( ; it.current(); ++it ){ 223 for( ; it.current(); ++it ){
220 /* Search all fields and compare them with query object. Store them into list 224 /* Search all fields and compare them with query object. Store them into list
221 * if all fields matches. 225 * if all fields matches.
222 */ 226 */
223 QDate* queryDate = 0l; 227 QDate* queryDate = 0l;
224 QDate* checkDate = 0l; 228 QDate* checkDate = 0l;
225 bool allcorrect = true; 229 bool allcorrect = true;
226 for ( int i = 0; i < Qtopia::Groups; i++ ) { 230 for ( int i = 0; i < Qtopia::Groups; i++ ) {
227 // Birthday and anniversary are special nonstring fields and should 231 // Birthday and anniversary are special nonstring fields and should
228 // be handled specially 232 // be handled specially
229 switch ( i ){ 233 switch ( i ){
230 case Qtopia::Birthday: 234 case Qtopia::Birthday:
231 queryDate = new QDate( query.birthday() ); 235 queryDate = new QDate( query.birthday() );
232 checkDate = new QDate( (*it)->birthday() ); 236 checkDate = new QDate( (*it)->birthday() );
233 // fall through 237 // fall through
234 case Qtopia::Anniversary: 238 case Qtopia::Anniversary:
235 if ( queryDate == 0l ){ 239 if ( queryDate == 0l ){
236 queryDate = new QDate( query.anniversary() ); 240 queryDate = new QDate( query.anniversary() );
237 checkDate = new QDate( (*it)->anniversary() ); 241 checkDate = new QDate( (*it)->anniversary() );
238 } 242 }
239 243
240 if ( queryDate->isValid() ){ 244 if ( queryDate->isValid() ){
241 if( checkDate->isValid() ){ 245 if( checkDate->isValid() ){
242 if ( settings & OPimContactAccess::DateYear ){ 246 if ( settings & OPimContactAccess::DateYear ){
243 if ( queryDate->year() != checkDate->year() ) 247 if ( queryDate->year() != checkDate->year() )
244 allcorrect = false; 248 allcorrect = false;
245 } 249 }
246 if ( settings & OPimContactAccess::DateMonth ){ 250 if ( settings & OPimContactAccess::DateMonth ){
247 if ( queryDate->month() != checkDate->month() ) 251 if ( queryDate->month() != checkDate->month() )
248 allcorrect = false; 252 allcorrect = false;
249 } 253 }
250 if ( settings & OPimContactAccess::DateDay ){ 254 if ( settings & OPimContactAccess::DateDay ){
251 if ( queryDate->day() != checkDate->day() ) 255 if ( queryDate->day() != checkDate->day() )
252 allcorrect = false; 256 allcorrect = false;
253 } 257 }
254 if ( settings & OPimContactAccess::DateDiff ) { 258 if ( settings & OPimContactAccess::DateDiff ) {
255 QDate current; 259 QDate current;
256 // If we get an additional date, we 260 // If we get an additional date, we
257 // will take this date instead of 261 // will take this date instead of
258 // the current one.. 262 // the current one..
259 if ( !d.date().isValid() ) 263 if ( !d.date().isValid() )
260 current = QDate::currentDate(); 264 current = QDate::currentDate();
261 else 265 else
262 current = d.date(); 266 current = d.date();
263 267
264 // We have to equalize the year, otherwise 268 // We have to equalize the year, otherwise
265 // the search will fail.. 269 // the search will fail..
266 checkDate->setYMD( current.year(), 270 checkDate->setYMD( current.year(),
267 checkDate->month(), 271 checkDate->month(),
268 checkDate->day() ); 272 checkDate->day() );
269 if ( *checkDate < current ) 273 if ( *checkDate < current )
270 checkDate->setYMD( current.year()+1, 274 checkDate->setYMD( current.year()+1,
271 checkDate->month(), 275 checkDate->month(),
272 checkDate->day() ); 276 checkDate->day() );
273 277
274 // Check whether the birthday/anniversary date is between 278 // Check whether the birthday/anniversary date is between
275 // the current/given date and the maximum date 279 // the current/given date and the maximum date
276 // ( maximum time range ) ! 280 // ( maximum time range ) !
277 qWarning("Checking if %s is between %s and %s ! ", 281 qWarning("Checking if %s is between %s and %s ! ",
278 checkDate->toString().latin1(), 282 checkDate->toString().latin1(),
279 current.toString().latin1(), 283 current.toString().latin1(),
280 queryDate->toString().latin1() ); 284 queryDate->toString().latin1() );
281 if ( current.daysTo( *queryDate ) >= 0 ){ 285 if ( current.daysTo( *queryDate ) >= 0 ){
282 if ( !( ( *checkDate >= current ) && 286 if ( !( ( *checkDate >= current ) &&
283 ( *checkDate <= *queryDate ) ) ){ 287 ( *checkDate <= *queryDate ) ) ){
284 allcorrect = false; 288 allcorrect = false;
285 qWarning (" Nope!.."); 289 qWarning (" Nope!..");
286 } 290 }
287 } 291 }
288 } 292 }
289 } else{ 293 } else{
290 // checkDate is invalid. Therefore this entry is always rejected 294 // checkDate is invalid. Therefore this entry is always rejected
291 allcorrect = false; 295 allcorrect = false;
292 } 296 }
293 } 297 }
294 298
295 delete queryDate; 299 delete queryDate;
296 queryDate = 0l; 300 queryDate = 0l;
297 delete checkDate; 301 delete checkDate;
298 checkDate = 0l; 302 checkDate = 0l;
299 break; 303 break;
300 default: 304 default:
301 /* Just compare fields which are not empty in the query object */ 305 /* Just compare fields which are not empty in the query object */
302 if ( !query.field(i).isEmpty() ){ 306 if ( !query.field(i).isEmpty() ){
303 switch ( settings & ~( OPimContactAccess::IgnoreCase 307 switch ( settings & ~( OPimContactAccess::IgnoreCase
304 | OPimContactAccess::DateDiff 308 | OPimContactAccess::DateDiff
305 | OPimContactAccess::DateYear 309 | OPimContactAccess::DateYear
306 | OPimContactAccess::DateMonth 310 | OPimContactAccess::DateMonth
307 | OPimContactAccess::DateDay 311 | OPimContactAccess::DateDay
308 | OPimContactAccess::MatchOne 312 | OPimContactAccess::MatchOne
309 ) ){ 313 ) ){
310 314
311 case OPimContactAccess::RegExp:{ 315 case OPimContactAccess::RegExp:{
312 QRegExp expr ( query.field(i), 316 QRegExp expr ( query.field(i),
313 !(settings & OPimContactAccess::IgnoreCase), 317 !(settings & OPimContactAccess::IgnoreCase),
314 false ); 318 false );
315 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 319 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
316 allcorrect = false; 320 allcorrect = false;
317 } 321 }
318 break; 322 break;
319 case OPimContactAccess::WildCards:{ 323 case OPimContactAccess::WildCards:{
320 QRegExp expr ( query.field(i), 324 QRegExp expr ( query.field(i),
321 !(settings & OPimContactAccess::IgnoreCase), 325 !(settings & OPimContactAccess::IgnoreCase),
322 true ); 326 true );
323 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 327 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
324 allcorrect = false; 328 allcorrect = false;
325 } 329 }
326 break; 330 break;
327 case OPimContactAccess::ExactMatch:{ 331 case OPimContactAccess::ExactMatch:{
328 if (settings & OPimContactAccess::IgnoreCase){ 332 if (settings & OPimContactAccess::IgnoreCase){
329 if ( query.field(i).upper() != 333 if ( query.field(i).upper() !=
330 (*it)->field(i).upper() ) 334 (*it)->field(i).upper() )
331 allcorrect = false; 335 allcorrect = false;
332 }else{ 336 }else{
333 if ( query.field(i) != (*it)->field(i) ) 337 if ( query.field(i) != (*it)->field(i) )
334 allcorrect = false; 338 allcorrect = false;
335 } 339 }
336 } 340 }
337 break; 341 break;
338 } 342 }
339 } 343 }
340 } 344 }
341 } 345 }
342 if ( allcorrect ){ 346 if ( allcorrect ){
343 m_currentQuery[arraycounter++] = (*it)->uid(); 347 m_currentQuery[arraycounter++] = (*it)->uid();
344 } 348 }
345 } 349 }
346 350
347 // Shrink to fit.. 351 // Shrink to fit..
348 m_currentQuery.resize(arraycounter); 352 m_currentQuery.resize(arraycounter);
349 353
350 return m_currentQuery; 354 return m_currentQuery;
351} 355}
352 356
353QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 357QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
354{ 358{
355 QArray<int> m_currentQuery( m_contactList.count() ); 359 QArray<int> m_currentQuery( m_contactList.count() );
356 QListIterator<OPimContact> it( m_contactList ); 360 QListIterator<OPimContact> it( m_contactList );
357 uint arraycounter = 0; 361 uint arraycounter = 0;
358 362
359 for( ; it.current(); ++it ){ 363 for( ; it.current(); ++it ){
360 if ( (*it)->match( r ) ){ 364 if ( (*it)->match( r ) ){
361 m_currentQuery[arraycounter++] = (*it)->uid(); 365 m_currentQuery[arraycounter++] = (*it)->uid();
362 } 366 }
363 367
364 } 368 }
365 // Shrink to fit.. 369 // Shrink to fit..
366 m_currentQuery.resize(arraycounter); 370 m_currentQuery.resize(arraycounter);
367 371
368 return m_currentQuery; 372 return m_currentQuery;
369} 373}
370 374
371const uint OPimContactAccessBackend_XML::querySettings() 375const uint OPimContactAccessBackend_XML::querySettings()
372{ 376{
373 return ( OPimContactAccess::WildCards 377 return ( OPimContactAccess::WildCards
374 | OPimContactAccess::IgnoreCase 378 | OPimContactAccess::IgnoreCase
375 | OPimContactAccess::RegExp 379 | OPimContactAccess::RegExp
376 | OPimContactAccess::ExactMatch 380 | OPimContactAccess::ExactMatch
377 | OPimContactAccess::DateDiff 381 | OPimContactAccess::DateDiff
378 | OPimContactAccess::DateYear 382 | OPimContactAccess::DateYear
379 | OPimContactAccess::DateMonth 383 | OPimContactAccess::DateMonth
380 | OPimContactAccess::DateDay 384 | OPimContactAccess::DateDay
381 ); 385 );
382} 386}
383 387
384bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const 388bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
385{ 389{
386 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 390 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
387 * may be added with any of the other settings. IgnoreCase should never used alone. 391 * may be added with any of the other settings. IgnoreCase should never used alone.
388 * Wildcards, RegExp, ExactMatch should never used at the same time... 392 * Wildcards, RegExp, ExactMatch should never used at the same time...
389 */ 393 */
390 394
391 // Step 1: Check whether the given settings are supported by this backend 395 // Step 1: Check whether the given settings are supported by this backend
392 if ( ( querySettings & ( 396 if ( ( querySettings & (
393 OPimContactAccess::IgnoreCase 397 OPimContactAccess::IgnoreCase
394 | OPimContactAccess::WildCards 398 | OPimContactAccess::WildCards
395 | OPimContactAccess::DateDiff 399 | OPimContactAccess::DateDiff
396 | OPimContactAccess::DateYear 400 | OPimContactAccess::DateYear
397 | OPimContactAccess::DateMonth 401 | OPimContactAccess::DateMonth
398 | OPimContactAccess::DateDay 402 | OPimContactAccess::DateDay
399 | OPimContactAccess::RegExp 403 | OPimContactAccess::RegExp
400 | OPimContactAccess::ExactMatch 404 | OPimContactAccess::ExactMatch
401 ) ) != querySettings ) 405 ) ) != querySettings )
402 return false; 406 return false;
403 407
404 // Step 2: Check whether the given combinations are ok.. 408 // Step 2: Check whether the given combinations are ok..
405 409
406 // IngoreCase alone is invalid 410 // IngoreCase alone is invalid
407 if ( querySettings == OPimContactAccess::IgnoreCase ) 411 if ( querySettings == OPimContactAccess::IgnoreCase )
408 return false; 412 return false;
409 413
410 // WildCards, RegExp and ExactMatch should never used at the same time 414 // WildCards, RegExp and ExactMatch should never used at the same time
411 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 415 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
412 | OPimContactAccess::DateDiff 416 | OPimContactAccess::DateDiff
413 | OPimContactAccess::DateYear 417 | OPimContactAccess::DateYear
414 | OPimContactAccess::DateMonth 418 | OPimContactAccess::DateMonth
415 | OPimContactAccess::DateDay 419 | OPimContactAccess::DateDay
416 ) 420 )
417 ){ 421 ){
418 case OPimContactAccess::RegExp: 422 case OPimContactAccess::RegExp:
419 return ( true ); 423 return ( true );
420 case OPimContactAccess::WildCards: 424 case OPimContactAccess::WildCards:
421 return ( true ); 425 return ( true );
422 case OPimContactAccess::ExactMatch: 426 case OPimContactAccess::ExactMatch:
423 return ( true ); 427 return ( true );
424 case 0: // one of the upper removed bits were set.. 428 case 0: // one of the upper removed bits were set..
425 return ( true ); 429 return ( true );
426 default: 430 default:
427 return ( false ); 431 return ( false );
428 } 432 }
429} 433}
430 434
431// Currently only asc implemented.. 435// Currently only asc implemented..
432QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) 436QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
433{ 437{
434 QMap<QString, int> nameToUid; 438 QMap<QString, int> nameToUid;
435 QStringList names; 439 QStringList names;
436 QArray<int> m_currentQuery( m_contactList.count() ); 440 QArray<int> m_currentQuery( m_contactList.count() );
437 441
438 // First fill map and StringList with all Names 442 // First fill map and StringList with all Names
439 // Afterwards sort namelist and use map to fill array to return.. 443 // Afterwards sort namelist and use map to fill array to return..
440 QListIterator<OPimContact> it( m_contactList ); 444 QListIterator<OPimContact> it( m_contactList );
441 for( ; it.current(); ++it ){ 445 for( ; it.current(); ++it ){
442 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); 446 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
443 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); 447 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
444 } 448 }
445 names.sort(); 449 names.sort();
446 450
447 int i = 0; 451 int i = 0;
448 if ( asc ){ 452 if ( asc ){
449 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 453 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
450 m_currentQuery[i++] = nameToUid[ (*it) ]; 454 m_currentQuery[i++] = nameToUid[ (*it) ];
451 }else{ 455 }else{
452 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 456 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
453 m_currentQuery[i++] = nameToUid[ (*it) ]; 457 m_currentQuery[i++] = nameToUid[ (*it) ];
454 } 458 }
455 459
456 return m_currentQuery; 460 return m_currentQuery;
457 461
458} 462}
459 463
460bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact ) 464bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
461{ 465{
462 //qWarning("odefaultbackend: ACTION::ADD"); 466 //owarn << "odefaultbackend: ACTION::ADD" << oendl;
463 updateJournal (newcontact, ACTION_ADD); 467 updateJournal (newcontact, ACTION_ADD);
464 addContact_p( newcontact ); 468 addContact_p( newcontact );
465 469
466 m_changed = true; 470 m_changed = true;
467 471
468 return true; 472 return true;
469} 473}
470 474
471bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact ) 475bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
472{ 476{
473 m_changed = true; 477 m_changed = true;
474 478
475 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); 479 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
476 480
477 if ( found ) { 481 if ( found ) {
478 OPimContact* newCont = new OPimContact( contact ); 482 OPimContact* newCont = new OPimContact( contact );
479 483
480 updateJournal ( *newCont, ACTION_REPLACE); 484 updateJournal ( *newCont, ACTION_REPLACE);
481 m_contactList.removeRef ( found ); 485 m_contactList.removeRef ( found );
482 m_contactList.append ( newCont ); 486 m_contactList.append ( newCont );
483 m_uidToContact.remove( QString().setNum( contact.uid() ) ); 487 m_uidToContact.remove( QString().setNum( contact.uid() ) );
484 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); 488 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
485 489
486 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); 490 owarn << "Nur zur Sicherheit: " << contact.uid() << " == " << newCont->uid() << " ?" << oendl;
487 491
488 return true; 492 return true;
489 } else 493 } else
490 return false; 494 return false;
491} 495}
492 496
493bool OPimContactAccessBackend_XML::remove ( int uid ) 497bool OPimContactAccessBackend_XML::remove ( int uid )
494{ 498{
495 m_changed = true; 499 m_changed = true;
496 500
497 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) ); 501 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) );
498 502
499 if ( found ) { 503 if ( found ) {
500 updateJournal ( *found, ACTION_REMOVE); 504 updateJournal ( *found, ACTION_REMOVE);
501 m_contactList.removeRef ( found ); 505 m_contactList.removeRef ( found );
502 m_uidToContact.remove( QString().setNum( uid ) ); 506 m_uidToContact.remove( QString().setNum( uid ) );
503 507
504 return true; 508 return true;
505 } else 509 } else
506 return false; 510 return false;
507} 511}
508 512
509bool OPimContactAccessBackend_XML::reload(){ 513bool OPimContactAccessBackend_XML::reload(){
510 /* Reload is the same as load in this implementation */ 514 /* Reload is the same as load in this implementation */
511 return ( load() ); 515 return ( load() );
512} 516}
513 517
514void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) 518void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact )
515{ 519{
516 OPimContact* contRef = new OPimContact( newcontact ); 520 OPimContact* contRef = new OPimContact( newcontact );
517 521
518 m_contactList.append ( contRef ); 522 m_contactList.append ( contRef );
519 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); 523 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
520} 524}
521 525
522/* This function loads the xml-database and the journalfile */ 526/* This function loads the xml-database and the journalfile */
523bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) 527bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal )
524{ 528{
525 529
526 /* We use the time of the last read to check if the file was 530 /* We use the time of the last read to check if the file was
527 * changed externally. 531 * changed externally.
528 */ 532 */
529 if ( !isJournal ){ 533 if ( !isJournal ){
530 QFileInfo fi( filename ); 534 QFileInfo fi( filename );
531 m_readtime = fi.lastModified (); 535 m_readtime = fi.lastModified ();
532 } 536 }
533 537
534 const int JOURNALACTION = Qtopia::Notes + 1; 538 const int JOURNALACTION = Qtopia::Notes + 1;
535 const int JOURNALROW = JOURNALACTION + 1; 539 const int JOURNALROW = JOURNALACTION + 1;
536 540
537 bool foundAction = false; 541 bool foundAction = false;
538 journal_action action = ACTION_ADD; 542 journal_action action = ACTION_ADD;
539 int journalKey = 0; 543 int journalKey = 0;
540 QMap<int, QString> contactMap; 544 QMap<int, QString> contactMap;
541 QMap<QString, QString> customMap; 545 QMap<QString, QString> customMap;
542 QMap<QString, QString>::Iterator customIt; 546 QMap<QString, QString>::Iterator customIt;
543 QAsciiDict<int> dict( 47 ); 547 QAsciiDict<int> dict( 47 );
544 548
545 dict.setAutoDelete( TRUE ); 549 dict.setAutoDelete( TRUE );
546 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 550 dict.insert( "Uid", new int(Qtopia::AddressUid) );
547 dict.insert( "Title", new int(Qtopia::Title) ); 551 dict.insert( "Title", new int(Qtopia::Title) );
548 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 552 dict.insert( "FirstName", new int(Qtopia::FirstName) );
549 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 553 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
550 dict.insert( "LastName", new int(Qtopia::LastName) ); 554 dict.insert( "LastName", new int(Qtopia::LastName) );
551 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 555 dict.insert( "Suffix", new int(Qtopia::Suffix) );
552 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 556 dict.insert( "FileAs", new int(Qtopia::FileAs) );
553 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 557 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
554 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 558 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
555 dict.insert( "Emails", new int(Qtopia::Emails) ); 559 dict.insert( "Emails", new int(Qtopia::Emails) );
556 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 560 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
557 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 561 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
558 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 562 dict.insert( "HomeState", new int(Qtopia::HomeState) );
559 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 563 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
560 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 564 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
561 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 565 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
562 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 566 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
563 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 567 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
564 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 568 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
565 dict.insert( "Company", new int(Qtopia::Company) ); 569 dict.insert( "Company", new int(Qtopia::Company) );
566 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); 570 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
567 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); 571 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
568 dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); 572 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
569 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); 573 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
570 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); 574 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
571 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); 575 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
572 dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); 576 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
573 dict.insert( "Department", new int(Qtopia::Department) ); 577 dict.insert( "Department", new int(Qtopia::Department) );
574 dict.insert( "Office", new int(Qtopia::Office) ); 578 dict.insert( "Office", new int(Qtopia::Office) );
575 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); 579 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
576 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); 580 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
577 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); 581 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
578 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); 582 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
579 dict.insert( "Profession", new int(Qtopia::Profession) ); 583 dict.insert( "Profession", new int(Qtopia::Profession) );
580 dict.insert( "Assistant", new int(Qtopia::Assistant) ); 584 dict.insert( "Assistant", new int(Qtopia::Assistant) );
581 dict.insert( "Manager", new int(Qtopia::Manager) ); 585 dict.insert( "Manager", new int(Qtopia::Manager) );
582 dict.insert( "Spouse", new int(Qtopia::Spouse) ); 586 dict.insert( "Spouse", new int(Qtopia::Spouse) );
583 dict.insert( "Children", new int(Qtopia::Children) ); 587 dict.insert( "Children", new int(Qtopia::Children) );
584 dict.insert( "Gender", new int(Qtopia::Gender) ); 588 dict.insert( "Gender", new int(Qtopia::Gender) );
585 dict.insert( "Birthday", new int(Qtopia::Birthday) ); 589 dict.insert( "Birthday", new int(Qtopia::Birthday) );
586 dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); 590 dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
587 dict.insert( "Nickname", new int(Qtopia::Nickname) ); 591 dict.insert( "Nickname", new int(Qtopia::Nickname) );
588 dict.insert( "Notes", new int(Qtopia::Notes) ); 592 dict.insert( "Notes", new int(Qtopia::Notes) );
589 dict.insert( "action", new int(JOURNALACTION) ); 593 dict.insert( "action", new int(JOURNALACTION) );
590 dict.insert( "actionrow", new int(JOURNALROW) ); 594 dict.insert( "actionrow", new int(JOURNALROW) );
591 595
592 //qWarning( "OPimContactDefaultBackEnd::loading %s", filename.latin1() ); 596 //owarn << "OPimContactDefaultBackEnd::loading " << filename << "" << oendl;
593 597
594 XMLElement *root = XMLElement::load( filename ); 598 XMLElement *root = XMLElement::load( filename );
595 if(root != 0l ){ // start parsing 599 if(root != 0l ){ // start parsing
596 /* Parse all XML-Elements and put the data into the 600 /* Parse all XML-Elements and put the data into the
597 * Contact-Class 601 * Contact-Class
598 */ 602 */
599 XMLElement *element = root->firstChild(); 603 XMLElement *element = root->firstChild();
600 //qWarning("OPimContactAccess::load tagName(): %s", root->tagName().latin1() ); 604 //owarn << "OPimContactAccess::load tagName(): " << root->tagName() << "" << oendl;
601 element = element->firstChild(); 605 element = element->firstChild();
602 606
603 /* Search Tag "Contacts" which is the parent of all Contacts */ 607 /* Search Tag "Contacts" which is the parent of all Contacts */
604 while( element && !isJournal ){ 608 while( element && !isJournal ){
605 if( element->tagName() != QString::fromLatin1("Contacts") ){ 609 if( element->tagName() != QString::fromLatin1("Contacts") ){
606 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s", 610 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
607 // element->tagName().latin1()); 611 // element->tagName().latin1());
608 element = element->nextChild(); 612 element = element->nextChild();
609 } else { 613 } else {
610 element = element->firstChild(); 614 element = element->firstChild();
611 break; 615 break;
612 } 616 }
613 } 617 }
614 /* Parse all Contacts and ignore unknown tags */ 618 /* Parse all Contacts and ignore unknown tags */
615 while( element ){ 619 while( element ){
616 if( element->tagName() != QString::fromLatin1("Contact") ){ 620 if( element->tagName() != QString::fromLatin1("Contact") ){
617 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s", 621 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s",
618 // element->tagName().latin1()); 622 // element->tagName().latin1());
619 element = element->nextChild(); 623 element = element->nextChild();
620 continue; 624 continue;
621 } 625 }
622 /* Found alement with tagname "contact", now parse and store all 626 /* Found alement with tagname "contact", now parse and store all
623 * attributes contained 627 * attributes contained
624 */ 628 */
625 //qWarning("OPimContactDefBack::load element tagName() : %s", 629 //qWarning("OPimContactDefBack::load element tagName() : %s",
626 // element->tagName().latin1() ); 630 // element->tagName().latin1() );
627 QString dummy; 631 QString dummy;
628 foundAction = false; 632 foundAction = false;
629 633
630 XMLElement::AttributeMap aMap = element->attributes(); 634 XMLElement::AttributeMap aMap = element->attributes();
631 XMLElement::AttributeMap::Iterator it; 635 XMLElement::AttributeMap::Iterator it;
632 contactMap.clear(); 636 contactMap.clear();
633 customMap.clear(); 637 customMap.clear();
634 for( it = aMap.begin(); it != aMap.end(); ++it ){ 638 for( it = aMap.begin(); it != aMap.end(); ++it ){
635 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); 639 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
636 640
637 int *find = dict[ it.key() ]; 641 int *find = dict[ it.key() ];
638 /* Unknown attributes will be stored as "Custom" elements */ 642 /* Unknown attributes will be stored as "Custom" elements */
639 if ( !find ) { 643 if ( !find ) {
640 // qWarning("Attribute %s not known.", it.key().latin1()); 644 // owarn << "Attribute " << it.key() << " not known." << oendl;
641 //contact.setCustomField(it.key(), it.data()); 645 //contact.setCustomField(it.key(), it.data());
642 customMap.insert( it.key(), it.data() ); 646 customMap.insert( it.key(), it.data() );
643 continue; 647 continue;
644 } 648 }
645 649
646 /* Check if special conversion is needed and add attribute 650 /* Check if special conversion is needed and add attribute
647 * into Contact class 651 * into Contact class
648 */ 652 */
649 switch( *find ) { 653 switch( *find ) {
650 /* 654 /*
651 case Qtopia::AddressUid: 655 case Qtopia::AddressUid:
652 contact.setUid( it.data().toInt() ); 656 contact.setUid( it.data().toInt() );
653 break; 657 break;
654 case Qtopia::AddressCategory: 658 case Qtopia::AddressCategory:
655 contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); 659 contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
656 break; 660 break;
657 */ 661 */
658 case JOURNALACTION: 662 case JOURNALACTION:
659 action = journal_action(it.data().toInt()); 663 action = journal_action(it.data().toInt());
660 foundAction = true; 664 foundAction = true;
661 qWarning ("ODefBack(journal)::ACTION found: %d", action); 665 qWarning ("ODefBack(journal)::ACTION found: %d", action);
662 break; 666 break;
663 case JOURNALROW: 667 case JOURNALROW:
664 journalKey = it.data().toInt(); 668 journalKey = it.data().toInt();
665 break; 669 break;
666 default: // no conversion needed add them to the map 670 default: // no conversion needed add them to the map
667 contactMap.insert( *find, it.data() ); 671 contactMap.insert( *find, it.data() );
668 break; 672 break;
669 } 673 }
670 } 674 }
671 /* now generate the Contact contact */ 675 /* now generate the Contact contact */
672 OPimContact contact( contactMap ); 676 OPimContact contact( contactMap );
673 677
674 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { 678 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
675 contact.setCustomField( customIt.key(), customIt.data() ); 679 contact.setCustomField( customIt.key(), customIt.data() );
676 } 680 }
677 681
678 if (foundAction){ 682 if (foundAction){
679 foundAction = false; 683 foundAction = false;
680 switch ( action ) { 684 switch ( action ) {
681 case ACTION_ADD: 685 case ACTION_ADD:
682 addContact_p (contact); 686 addContact_p (contact);
683 break; 687 break;
684 case ACTION_REMOVE: 688 case ACTION_REMOVE:
685 if ( !remove (contact.uid()) ) 689 if ( !remove (contact.uid()) )
686 qWarning ("ODefBack(journal)::Unable to remove uid: %d", 690 qWarning ("ODefBack(journal)::Unable to remove uid: %d",
687 contact.uid() ); 691 contact.uid() );
688 break; 692 break;
689 case ACTION_REPLACE: 693 case ACTION_REPLACE:
690 if ( !replace ( contact ) ) 694 if ( !replace ( contact ) )
691 qWarning ("ODefBack(journal)::Unable to replace uid: %d", 695 qWarning ("ODefBack(journal)::Unable to replace uid: %d",
692 contact.uid() ); 696 contact.uid() );
693 break; 697 break;
694 default: 698 default:
695 qWarning ("Unknown action: ignored !"); 699 qWarning ("Unknown action: ignored !");
696 break; 700 break;
697 } 701 }
698 }else{ 702 }else{
699 /* Add contact to list */ 703 /* Add contact to list */
700 addContact_p (contact); 704 addContact_p (contact);
701 } 705 }
702 706
703 /* Move to next element */ 707 /* Move to next element */
704 element = element->nextChild(); 708 element = element->nextChild();
705 } 709 }
706 }else { 710 }else {
707 qWarning("ODefBack::could not load"); 711 owarn << "ODefBack::could not load" << oendl;
708 } 712 }
709 delete root; 713 delete root;
710 qWarning("returning from loading" ); 714 owarn << "returning from loading" << oendl;
711 return true; 715 return true;
712} 716}
713 717
714 718
715void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt, 719void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt,
716 journal_action action ) 720 journal_action action )
717{ 721{
718 QFile f( m_journalName ); 722 QFile f( m_journalName );
719 bool created = !f.exists(); 723 bool created = !f.exists();
720 if ( !f.open(IO_WriteOnly|IO_Append) ) 724 if ( !f.open(IO_WriteOnly|IO_Append) )
721 return; 725 return;
722 726
723 QString buf; 727 QString buf;
724 QCString str; 728 QCString str;
725 729
726 // if the file was created, we have to set the Tag "<CONTACTS>" to 730 // if the file was created, we have to set the Tag "<CONTACTS>" to
727 // get a XML-File which is readable by our parser. 731 // get a XML-File which is readable by our parser.
728 // This is just a cheat, but better than rewrite the parser. 732 // This is just a cheat, but better than rewrite the parser.
729 if ( created ){ 733 if ( created ){
730 buf = "<Contacts>"; 734 buf = "<Contacts>";
731 QCString cstr = buf.utf8(); 735 QCString cstr = buf.utf8();
732 f.writeBlock( cstr.data(), cstr.length() ); 736 f.writeBlock( cstr.data(), cstr.length() );
733 } 737 }
734 738
735 buf = "<Contact "; 739 buf = "<Contact ";
736 cnt.save( buf ); 740 cnt.save( buf );
737 buf += " action=\"" + QString::number( (int)action ) + "\" "; 741 buf += " action=\"" + QString::number( (int)action ) + "\" ";
738 buf += "/>\n"; 742 buf += "/>\n";
739 QCString cstr = buf.utf8(); 743 QCString cstr = buf.utf8();
740 f.writeBlock( cstr.data(), cstr.length() ); 744 f.writeBlock( cstr.data(), cstr.length() );
741} 745}
742 746
743void OPimContactAccessBackend_XML::removeJournal() 747void OPimContactAccessBackend_XML::removeJournal()
744{ 748{
745 QFile f ( m_journalName ); 749 QFile f ( m_journalName );
746 if ( f.exists() ) 750 if ( f.exists() )
747 f.remove(); 751 f.remove();
748} 752}
749 753
750} 754}