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