summaryrefslogtreecommitdiff
path: root/libopie
authoreilers <eilers>2003-03-21 12:26:28 (UTC)
committer eilers <eilers>2003-03-21 12:26:28 (UTC)
commit6d066b0ed3fd7fbedce84616a8fa279eec480f13 (patch) (unidiff)
treee4da9ca6c25236a72bd88f58876c1814bfbd174d /libopie
parent8136284c38384b169cd2843ee61480d45b6c1cba (diff)
downloadopie-6d066b0ed3fd7fbedce84616a8fa279eec480f13.zip
opie-6d066b0ed3fd7fbedce84616a8fa279eec480f13.tar.gz
opie-6d066b0ed3fd7fbedce84616a8fa279eec480f13.tar.bz2
Fixing small bug: If we search a birthday from today to today, it returned
every contact ..
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactaccessbackend_xml.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/libopie/pim/ocontactaccessbackend_xml.cpp b/libopie/pim/ocontactaccessbackend_xml.cpp
index 4abf4d9..9fe3d1e 100644
--- a/libopie/pim/ocontactaccessbackend_xml.cpp
+++ b/libopie/pim/ocontactaccessbackend_xml.cpp
@@ -1,520 +1,524 @@
1/* 1/*
2 * XML Backend for the OPIE-Contact Database. 2 * XML Backend for the OPIE-Contact Database.
3 * 3 *
4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) 4 * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de)
5 * 5 *
6 * ===================================================================== 6 * =====================================================================
7 *This program is free software; you can redistribute it and/or 7 *This program is free software; you can redistribute it and/or
8 *modify it under the terms of the GNU Library General Public 8 *modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * ToDo: XML-Backend: Automatic reload if something was changed... 12 * ToDo: XML-Backend: Automatic reload if something was changed...
13 * 13 *
14 * 14 *
15 * ===================================================================== 15 * =====================================================================
16 * Version: $Id$ 16 * Version: $Id$
17 * ===================================================================== 17 * =====================================================================
18 * History: 18 * History:
19 * $Log$ 19 * $Log$
20 * Revision 1.3 2003/03/21 12:26:28 eilers
21 * Fixing small bug: If we search a birthday from today to today, it returned
22 * every contact ..
23 *
20 * Revision 1.2 2003/03/21 10:33:09 eilers 24 * Revision 1.2 2003/03/21 10:33:09 eilers
21 * Merged speed optimized xml backend for contacts to main. 25 * Merged speed optimized xml backend for contacts to main.
22 * Added QDateTime to querybyexample. For instance, it is now possible to get 26 * Added QDateTime to querybyexample. For instance, it is now possible to get
23 * all Birthdays/Anniversaries between two dates. This should be used 27 * all Birthdays/Anniversaries between two dates. This should be used
24 * to show all birthdays in the datebook.. 28 * to show all birthdays in the datebook..
25 * This change is sourcecode backward compatible but you have to upgrade 29 * This change is sourcecode backward compatible but you have to upgrade
26 * the binaries for today-addressbook. 30 * the binaries for today-addressbook.
27 * 31 *
28 * Revision 1.1.2.2 2003/02/11 12:17:28 eilers 32 * Revision 1.1.2.2 2003/02/11 12:17:28 eilers
29 * Speed optimization. Removed the sequential search loops. 33 * Speed optimization. Removed the sequential search loops.
30 * 34 *
31 * Revision 1.1.2.1 2003/02/10 15:31:38 eilers 35 * Revision 1.1.2.1 2003/02/10 15:31:38 eilers
32 * Writing offsets to debug output.. 36 * Writing offsets to debug output..
33 * 37 *
34 * Revision 1.1 2003/02/09 15:05:01 eilers 38 * Revision 1.1 2003/02/09 15:05:01 eilers
35 * Nothing happened.. Just some cleanup before I will start.. 39 * Nothing happened.. Just some cleanup before I will start..
36 * 40 *
37 * Revision 1.12 2003/01/03 16:58:03 eilers 41 * Revision 1.12 2003/01/03 16:58:03 eilers
38 * Reenable debug output 42 * Reenable debug output
39 * 43 *
40 * Revision 1.11 2003/01/03 12:31:28 eilers 44 * Revision 1.11 2003/01/03 12:31:28 eilers
41 * Bugfix for calculating data diffs.. 45 * Bugfix for calculating data diffs..
42 * 46 *
43 * Revision 1.10 2003/01/02 14:27:12 eilers 47 * Revision 1.10 2003/01/02 14:27:12 eilers
44 * Improved query by example: Search by date is possible.. First step 48 * Improved query by example: Search by date is possible.. First step
45 * for a today plugin for birthdays.. 49 * for a today plugin for birthdays..
46 * 50 *
47 * Revision 1.9 2002/12/08 12:48:57 eilers 51 * Revision 1.9 2002/12/08 12:48:57 eilers
48 * Moved journal-enum from ocontact into i the xml-backend.. 52 * Moved journal-enum from ocontact into i the xml-backend..
49 * 53 *
50 * Revision 1.8 2002/11/14 17:04:24 eilers 54 * Revision 1.8 2002/11/14 17:04:24 eilers
51 * Sorting will now work if fullname is identical on some entries 55 * Sorting will now work if fullname is identical on some entries
52 * 56 *
53 * Revision 1.7 2002/11/13 15:02:46 eilers 57 * Revision 1.7 2002/11/13 15:02:46 eilers
54 * Small Bug in sorted fixed 58 * Small Bug in sorted fixed
55 * 59 *
56 * Revision 1.6 2002/11/13 14:14:51 eilers 60 * Revision 1.6 2002/11/13 14:14:51 eilers
57 * Added sorted for Contacts.. 61 * Added sorted for Contacts..
58 * 62 *
59 * Revision 1.5 2002/11/01 15:10:42 eilers 63 * Revision 1.5 2002/11/01 15:10:42 eilers
60 * Added regExp-search in database for all fields in a contact. 64 * Added regExp-search in database for all fields in a contact.
61 * 65 *
62 * Revision 1.4 2002/10/16 10:52:40 eilers 66 * Revision 1.4 2002/10/16 10:52:40 eilers
63 * Added some docu to the interface and now using the cache infrastucture by zecke.. :) 67 * Added some docu to the interface and now using the cache infrastucture by zecke.. :)
64 * 68 *
65 * Revision 1.3 2002/10/14 16:21:54 eilers 69 * Revision 1.3 2002/10/14 16:21:54 eilers
66 * Some minor interface updates 70 * Some minor interface updates
67 * 71 *
68 * Revision 1.2 2002/10/07 17:34:24 eilers 72 * Revision 1.2 2002/10/07 17:34:24 eilers
69 * added OBackendFactory for advanced backend access 73 * added OBackendFactory for advanced backend access
70 * 74 *
71 * Revision 1.1 2002/09/27 17:11:44 eilers 75 * Revision 1.1 2002/09/27 17:11:44 eilers
72 * Added API for accessing the Contact-Database ! It is compiling, but 76 * Added API for accessing the Contact-Database ! It is compiling, but
73 * please do not expect that anything is working ! 77 * please do not expect that anything is working !
74 * I will debug that stuff in the next time .. 78 * I will debug that stuff in the next time ..
75 * Please read README_COMPILE for compiling ! 79 * Please read README_COMPILE for compiling !
76 * 80 *
77 * 81 *
78 */ 82 */
79 83
80#include "ocontactaccessbackend_xml.h" 84#include "ocontactaccessbackend_xml.h"
81 85
82#include <qasciidict.h> 86#include <qasciidict.h>
83#include <qdatetime.h> 87#include <qdatetime.h>
84#include <qfile.h> 88#include <qfile.h>
85#include <qfileinfo.h> 89#include <qfileinfo.h>
86#include <qregexp.h> 90#include <qregexp.h>
87#include <qarray.h> 91#include <qarray.h>
88#include <qmap.h> 92#include <qmap.h>
89#include <qdatetime.h> 93#include <qdatetime.h>
90 94
91#include <qpe/global.h> 95#include <qpe/global.h>
92 96
93#include <opie/xmltree.h> 97#include <opie/xmltree.h>
94#include "ocontactaccessbackend.h" 98#include "ocontactaccessbackend.h"
95#include "ocontactaccess.h" 99#include "ocontactaccess.h"
96 100
97#include <stdlib.h> 101#include <stdlib.h>
98#include <errno.h> 102#include <errno.h>
99 103
100using namespace Opie; 104using namespace Opie;
101 105
102 106
103OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename = 0l ): 107OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename = 0l ):
104 m_changed( false ) 108 m_changed( false )
105{ 109{
106 // Just m_contactlist should call delete if an entry 110 // Just m_contactlist should call delete if an entry
107 // is removed. 111 // is removed.
108 m_contactList.setAutoDelete( true ); 112 m_contactList.setAutoDelete( true );
109 m_uidToContact.setAutoDelete( false ); 113 m_uidToContact.setAutoDelete( false );
110 114
111 m_appName = appname; 115 m_appName = appname;
112 116
113 /* Set journalfile name ... */ 117 /* Set journalfile name ... */
114 m_journalName = getenv("HOME"); 118 m_journalName = getenv("HOME");
115 m_journalName +="/.abjournal" + appname; 119 m_journalName +="/.abjournal" + appname;
116 120
117 /* Expecting to access the default filename if nothing else is set */ 121 /* Expecting to access the default filename if nothing else is set */
118 if ( filename.isEmpty() ){ 122 if ( filename.isEmpty() ){
119 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 123 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
120 } else 124 } else
121 m_fileName = filename; 125 m_fileName = filename;
122 126
123 /* Load Database now */ 127 /* Load Database now */
124 load (); 128 load ();
125} 129}
126 130
127bool OContactAccessBackend_XML::save() 131bool OContactAccessBackend_XML::save()
128{ 132{
129 133
130 if ( !m_changed ) 134 if ( !m_changed )
131 return true; 135 return true;
132 136
133 QString strNewFile = m_fileName + ".new"; 137 QString strNewFile = m_fileName + ".new";
134 QFile f( strNewFile ); 138 QFile f( strNewFile );
135 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 139 if ( !f.open( IO_WriteOnly|IO_Raw ) )
136 return false; 140 return false;
137 141
138 int total_written; 142 int total_written;
139 int idx_offset = 0; 143 int idx_offset = 0;
140 QString out; 144 QString out;
141 145
142 // Write Header 146 // Write Header
143 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 147 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
144 " <Groups>\n" 148 " <Groups>\n"
145 " </Groups>\n" 149 " </Groups>\n"
146 " <Contacts>\n"; 150 " <Contacts>\n";
147 QCString cstr = out.utf8(); 151 QCString cstr = out.utf8();
148 f.writeBlock( cstr.data(), cstr.length() ); 152 f.writeBlock( cstr.data(), cstr.length() );
149 idx_offset += cstr.length(); 153 idx_offset += cstr.length();
150 out = ""; 154 out = "";
151 155
152 // Write all contacts 156 // Write all contacts
153 QListIterator<OContact> it( m_contactList ); 157 QListIterator<OContact> it( m_contactList );
154 for ( ; it.current(); ++it ) { 158 for ( ; it.current(); ++it ) {
155 qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); 159 qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset );
156 out += "<Contact "; 160 out += "<Contact ";
157 (*it)->save( out ); 161 (*it)->save( out );
158 out += "/>\n"; 162 out += "/>\n";
159 cstr = out.utf8(); 163 cstr = out.utf8();
160 total_written = f.writeBlock( cstr.data(), cstr.length() ); 164 total_written = f.writeBlock( cstr.data(), cstr.length() );
161 idx_offset += cstr.length(); 165 idx_offset += cstr.length();
162 if ( total_written != int(cstr.length()) ) { 166 if ( total_written != int(cstr.length()) ) {
163 f.close(); 167 f.close();
164 QFile::remove( strNewFile ); 168 QFile::remove( strNewFile );
165 return false; 169 return false;
166 } 170 }
167 out = ""; 171 out = "";
168 } 172 }
169 out += " </Contacts>\n</AddressBook>\n"; 173 out += " </Contacts>\n</AddressBook>\n";
170 174
171 // Write Footer 175 // Write Footer
172 cstr = out.utf8(); 176 cstr = out.utf8();
173 total_written = f.writeBlock( cstr.data(), cstr.length() ); 177 total_written = f.writeBlock( cstr.data(), cstr.length() );
174 if ( total_written != int( cstr.length() ) ) { 178 if ( total_written != int( cstr.length() ) ) {
175 f.close(); 179 f.close();
176 QFile::remove( strNewFile ); 180 QFile::remove( strNewFile );
177 return false; 181 return false;
178 } 182 }
179 f.close(); 183 f.close();
180 184
181 // move the file over, I'm just going to use the system call 185 // move the file over, I'm just going to use the system call
182 // because, I don't feel like using QDir. 186 // because, I don't feel like using QDir.
183 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 187 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
184 qWarning( "problem renaming file %s to %s, errno: %d", 188 qWarning( "problem renaming file %s to %s, errno: %d",
185 strNewFile.latin1(), m_journalName.latin1(), errno ); 189 strNewFile.latin1(), m_journalName.latin1(), errno );
186 // remove the tmp file... 190 // remove the tmp file...
187 QFile::remove( strNewFile ); 191 QFile::remove( strNewFile );
188 } 192 }
189 193
190 /* The journalfile should be removed now... */ 194 /* The journalfile should be removed now... */
191 removeJournal(); 195 removeJournal();
192 196
193 m_changed = false; 197 m_changed = false;
194 return true; 198 return true;
195} 199}
196 200
197bool OContactAccessBackend_XML::load () 201bool OContactAccessBackend_XML::load ()
198{ 202{
199 m_contactList.clear(); 203 m_contactList.clear();
200 m_uidToContact.clear(); 204 m_uidToContact.clear();
201 205
202 /* Load XML-File and journal if it exists */ 206 /* Load XML-File and journal if it exists */
203 if ( !load ( m_fileName, false ) ) 207 if ( !load ( m_fileName, false ) )
204 return false; 208 return false;
205 /* The returncode of the journalfile is ignored due to the 209 /* The returncode of the journalfile is ignored due to the
206 * fact that it does not exist when this class is instantiated ! 210 * fact that it does not exist when this class is instantiated !
207 * But there may such a file exist, if the application crashed. 211 * But there may such a file exist, if the application crashed.
208 * Therefore we try to load it to get the changes before the # 212 * Therefore we try to load it to get the changes before the #
209 * crash happened... 213 * crash happened...
210 */ 214 */
211 load (m_journalName, true); 215 load (m_journalName, true);
212 216
213 return true; 217 return true;
214} 218}
215 219
216void OContactAccessBackend_XML::clear () 220void OContactAccessBackend_XML::clear ()
217{ 221{
218 m_contactList.clear(); 222 m_contactList.clear();
219 m_uidToContact.clear(); 223 m_uidToContact.clear();
220 224
221 m_changed = false; 225 m_changed = false;
222} 226}
223 227
224bool OContactAccessBackend_XML::wasChangedExternally() 228bool OContactAccessBackend_XML::wasChangedExternally()
225{ 229{
226 QFileInfo fi( m_fileName ); 230 QFileInfo fi( m_fileName );
227 231
228 QDateTime lastmod = fi.lastModified (); 232 QDateTime lastmod = fi.lastModified ();
229 233
230 return (lastmod != m_readtime); 234 return (lastmod != m_readtime);
231} 235}
232 236
233QArray<int> OContactAccessBackend_XML::allRecords() const 237QArray<int> OContactAccessBackend_XML::allRecords() const
234{ 238{
235 QArray<int> uid_list( m_contactList.count() ); 239 QArray<int> uid_list( m_contactList.count() );
236 240
237 uint counter = 0; 241 uint counter = 0;
238 QListIterator<OContact> it( m_contactList ); 242 QListIterator<OContact> it( m_contactList );
239 for( ; it.current(); ++it ){ 243 for( ; it.current(); ++it ){
240 uid_list[counter++] = (*it)->uid(); 244 uid_list[counter++] = (*it)->uid();
241 } 245 }
242 246
243 return ( uid_list ); 247 return ( uid_list );
244} 248}
245 249
246OContact OContactAccessBackend_XML::find ( int uid ) const 250OContact OContactAccessBackend_XML::find ( int uid ) const
247{ 251{
248 OContact foundContact; //Create empty contact 252 OContact foundContact; //Create empty contact
249 253
250 OContact* found = m_uidToContact.find( QString().setNum( uid ) ); 254 OContact* found = m_uidToContact.find( QString().setNum( uid ) );
251 255
252 if ( found ){ 256 if ( found ){
253 foundContact = *found; 257 foundContact = *found;
254 } 258 }
255 259
256 return ( foundContact ); 260 return ( foundContact );
257} 261}
258 262
259QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, 263QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings,
260 const QDateTime& d ) 264 const QDateTime& d )
261{ 265{
262 266
263 QArray<int> m_currentQuery( m_contactList.count() ); 267 QArray<int> m_currentQuery( m_contactList.count() );
264 QListIterator<OContact> it( m_contactList ); 268 QListIterator<OContact> it( m_contactList );
265 uint arraycounter = 0; 269 uint arraycounter = 0;
266 270
267 for( ; it.current(); ++it ){ 271 for( ; it.current(); ++it ){
268 /* Search all fields and compare them with query object. Store them into list 272 /* Search all fields and compare them with query object. Store them into list
269 * if all fields matches. 273 * if all fields matches.
270 */ 274 */
271 QDate* queryDate = 0l; 275 QDate* queryDate = 0l;
272 QDate* checkDate = 0l; 276 QDate* checkDate = 0l;
273 bool allcorrect = true; 277 bool allcorrect = true;
274 for ( int i = 0; i < Qtopia::Groups; i++ ) { 278 for ( int i = 0; i < Qtopia::Groups; i++ ) {
275 // Birthday and anniversary are special nonstring fields and should 279 // Birthday and anniversary are special nonstring fields and should
276 // be handled specially 280 // be handled specially
277 switch ( i ){ 281 switch ( i ){
278 case Qtopia::Birthday: 282 case Qtopia::Birthday:
279 queryDate = new QDate( query.birthday() ); 283 queryDate = new QDate( query.birthday() );
280 checkDate = new QDate( (*it)->birthday() ); 284 checkDate = new QDate( (*it)->birthday() );
281 case Qtopia::Anniversary: 285 case Qtopia::Anniversary:
282 if ( queryDate == 0l ){ 286 if ( queryDate == 0l ){
283 queryDate = new QDate( query.anniversary() ); 287 queryDate = new QDate( query.anniversary() );
284 checkDate = new QDate( (*it)->anniversary() ); 288 checkDate = new QDate( (*it)->anniversary() );
285 } 289 }
286 290
287 if ( queryDate->isValid() ){ 291 if ( queryDate->isValid() ){
288 if( checkDate->isValid() ){ 292 if( checkDate->isValid() ){
289 if ( settings & OContactAccess::DateYear ){ 293 if ( settings & OContactAccess::DateYear ){
290 if ( queryDate->year() != checkDate->year() ) 294 if ( queryDate->year() != checkDate->year() )
291 allcorrect = false; 295 allcorrect = false;
292 } 296 }
293 if ( settings & OContactAccess::DateMonth ){ 297 if ( settings & OContactAccess::DateMonth ){
294 if ( queryDate->month() != checkDate->month() ) 298 if ( queryDate->month() != checkDate->month() )
295 allcorrect = false; 299 allcorrect = false;
296 } 300 }
297 if ( settings & OContactAccess::DateDay ){ 301 if ( settings & OContactAccess::DateDay ){
298 if ( queryDate->day() != checkDate->day() ) 302 if ( queryDate->day() != checkDate->day() )
299 allcorrect = false; 303 allcorrect = false;
300 } 304 }
301 if ( settings & OContactAccess::DateDiff ) { 305 if ( settings & OContactAccess::DateDiff ) {
302 QDate current; 306 QDate current;
303 // If we get an additional date, we 307 // If we get an additional date, we
304 // will take this date instead of 308 // will take this date instead of
305 // the current one.. 309 // the current one..
306 if ( !d.date().isValid() ) 310 if ( !d.date().isValid() )
307 current = QDate::currentDate(); 311 current = QDate::currentDate();
308 else 312 else
309 current = d.date(); 313 current = d.date();
310 314
311 // We have to equalize the year, otherwise 315 // We have to equalize the year, otherwise
312 // the search will fail.. 316 // the search will fail..
313 checkDate->setYMD( current.year(), 317 checkDate->setYMD( current.year(),
314 checkDate->month(), 318 checkDate->month(),
315 checkDate->day() ); 319 checkDate->day() );
316 if ( *checkDate < current ) 320 if ( *checkDate < current )
317 checkDate->setYMD( current.year()+1, 321 checkDate->setYMD( current.year()+1,
318 checkDate->month(), 322 checkDate->month(),
319 checkDate->day() ); 323 checkDate->day() );
320 324
321 // Check whether the birthday/anniversary date is between 325 // Check whether the birthday/anniversary date is between
322 // the current/given date and the maximum date 326 // the current/given date and the maximum date
323 // ( maximum time range ) ! 327 // ( maximum time range ) !
324 qWarning("Checking if %s is between %s and %s ! ", 328 qWarning("Checking if %s is between %s and %s ! ",
325 checkDate->toString().latin1(), 329 checkDate->toString().latin1(),
326 current.toString().latin1(), 330 current.toString().latin1(),
327 queryDate->toString().latin1() ); 331 queryDate->toString().latin1() );
328 if ( current.daysTo( *queryDate ) > 0 ){ 332 if ( current.daysTo( *queryDate ) >= 0 ){
329 if ( !( ( *checkDate >= current ) && 333 if ( !( ( *checkDate >= current ) &&
330 ( *checkDate <= *queryDate ) ) ){ 334 ( *checkDate <= *queryDate ) ) ){
331 allcorrect = false; 335 allcorrect = false;
332 qWarning (" Nope!.."); 336 qWarning (" Nope!..");
333 } 337 }
334 } 338 }
335 } 339 }
336 } else{ 340 } else{
337 // checkDate is invalid. Therefore this entry is always rejected 341 // checkDate is invalid. Therefore this entry is always rejected
338 allcorrect = false; 342 allcorrect = false;
339 } 343 }
340 } 344 }
341 345
342 delete queryDate; 346 delete queryDate;
343 queryDate = 0l; 347 queryDate = 0l;
344 delete checkDate; 348 delete checkDate;
345 checkDate = 0l; 349 checkDate = 0l;
346 break; 350 break;
347 default: 351 default:
348 /* Just compare fields which are not empty in the query object */ 352 /* Just compare fields which are not empty in the query object */
349 if ( !query.field(i).isEmpty() ){ 353 if ( !query.field(i).isEmpty() ){
350 switch ( settings & ~( OContactAccess::IgnoreCase 354 switch ( settings & ~( OContactAccess::IgnoreCase
351 | OContactAccess::DateDiff 355 | OContactAccess::DateDiff
352 | OContactAccess::DateYear 356 | OContactAccess::DateYear
353 | OContactAccess::DateMonth 357 | OContactAccess::DateMonth
354 | OContactAccess::DateDay 358 | OContactAccess::DateDay
355 | OContactAccess::MatchOne 359 | OContactAccess::MatchOne
356 ) ){ 360 ) ){
357 361
358 case OContactAccess::RegExp:{ 362 case OContactAccess::RegExp:{
359 QRegExp expr ( query.field(i), 363 QRegExp expr ( query.field(i),
360 !(settings & OContactAccess::IgnoreCase), 364 !(settings & OContactAccess::IgnoreCase),
361 false ); 365 false );
362 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 366 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
363 allcorrect = false; 367 allcorrect = false;
364 } 368 }
365 break; 369 break;
366 case OContactAccess::WildCards:{ 370 case OContactAccess::WildCards:{
367 QRegExp expr ( query.field(i), 371 QRegExp expr ( query.field(i),
368 !(settings & OContactAccess::IgnoreCase), 372 !(settings & OContactAccess::IgnoreCase),
369 true ); 373 true );
370 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 374 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
371 allcorrect = false; 375 allcorrect = false;
372 } 376 }
373 break; 377 break;
374 case OContactAccess::ExactMatch:{ 378 case OContactAccess::ExactMatch:{
375 if (settings & OContactAccess::IgnoreCase){ 379 if (settings & OContactAccess::IgnoreCase){
376 if ( query.field(i).upper() != 380 if ( query.field(i).upper() !=
377 (*it)->field(i).upper() ) 381 (*it)->field(i).upper() )
378 allcorrect = false; 382 allcorrect = false;
379 }else{ 383 }else{
380 if ( query.field(i) != (*it)->field(i) ) 384 if ( query.field(i) != (*it)->field(i) )
381 allcorrect = false; 385 allcorrect = false;
382 } 386 }
383 } 387 }
384 break; 388 break;
385 } 389 }
386 } 390 }
387 } 391 }
388 } 392 }
389 if ( allcorrect ){ 393 if ( allcorrect ){
390 m_currentQuery[arraycounter++] = (*it)->uid(); 394 m_currentQuery[arraycounter++] = (*it)->uid();
391 } 395 }
392 } 396 }
393 397
394 // Shrink to fit.. 398 // Shrink to fit..
395 m_currentQuery.resize(arraycounter); 399 m_currentQuery.resize(arraycounter);
396 400
397 return m_currentQuery; 401 return m_currentQuery;
398} 402}
399 403
400QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 404QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
401{ 405{
402 QArray<int> m_currentQuery( m_contactList.count() ); 406 QArray<int> m_currentQuery( m_contactList.count() );
403 QListIterator<OContact> it( m_contactList ); 407 QListIterator<OContact> it( m_contactList );
404 uint arraycounter = 0; 408 uint arraycounter = 0;
405 409
406 for( ; it.current(); ++it ){ 410 for( ; it.current(); ++it ){
407 if ( (*it)->match( r ) ){ 411 if ( (*it)->match( r ) ){
408 m_currentQuery[arraycounter++] = (*it)->uid(); 412 m_currentQuery[arraycounter++] = (*it)->uid();
409 } 413 }
410 414
411 } 415 }
412 // Shrink to fit.. 416 // Shrink to fit..
413 m_currentQuery.resize(arraycounter); 417 m_currentQuery.resize(arraycounter);
414 418
415 return m_currentQuery; 419 return m_currentQuery;
416} 420}
417 421
418const uint OContactAccessBackend_XML::querySettings() 422const uint OContactAccessBackend_XML::querySettings()
419{ 423{
420 return ( OContactAccess::WildCards 424 return ( OContactAccess::WildCards
421 | OContactAccess::IgnoreCase 425 | OContactAccess::IgnoreCase
422 | OContactAccess::RegExp 426 | OContactAccess::RegExp
423 | OContactAccess::ExactMatch 427 | OContactAccess::ExactMatch
424 | OContactAccess::DateDiff 428 | OContactAccess::DateDiff
425 | OContactAccess::DateYear 429 | OContactAccess::DateYear
426 | OContactAccess::DateMonth 430 | OContactAccess::DateMonth
427 | OContactAccess::DateDay 431 | OContactAccess::DateDay
428 ); 432 );
429} 433}
430 434
431bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const 435bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
432{ 436{
433 /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 437 /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
434 * may be added with any of the other settings. IgnoreCase should never used alone. 438 * may be added with any of the other settings. IgnoreCase should never used alone.
435 * Wildcards, RegExp, ExactMatch should never used at the same time... 439 * Wildcards, RegExp, ExactMatch should never used at the same time...
436 */ 440 */
437 441
438 if ( querySettings == OContactAccess::IgnoreCase ) 442 if ( querySettings == OContactAccess::IgnoreCase )
439 return false; 443 return false;
440 444
441 switch ( querySettings & ~( OContactAccess::IgnoreCase 445 switch ( querySettings & ~( OContactAccess::IgnoreCase
442 | OContactAccess::DateDiff 446 | OContactAccess::DateDiff
443 | OContactAccess::DateYear 447 | OContactAccess::DateYear
444 | OContactAccess::DateMonth 448 | OContactAccess::DateMonth
445 | OContactAccess::DateDay 449 | OContactAccess::DateDay
446 ) 450 )
447 ){ 451 ){
448 case OContactAccess::RegExp: 452 case OContactAccess::RegExp:
449 return ( true ); 453 return ( true );
450 case OContactAccess::WildCards: 454 case OContactAccess::WildCards:
451 return ( true ); 455 return ( true );
452 case OContactAccess::ExactMatch: 456 case OContactAccess::ExactMatch:
453 return ( true ); 457 return ( true );
454 default: 458 default:
455 return ( false ); 459 return ( false );
456 } 460 }
457} 461}
458 462
459// Currently only asc implemented.. 463// Currently only asc implemented..
460QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) 464QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int )
461{ 465{
462 QMap<QString, int> nameToUid; 466 QMap<QString, int> nameToUid;
463 QStringList names; 467 QStringList names;
464 QArray<int> m_currentQuery( m_contactList.count() ); 468 QArray<int> m_currentQuery( m_contactList.count() );
465 469
466 // First fill map and StringList with all Names 470 // First fill map and StringList with all Names
467 // Afterwards sort namelist and use map to fill array to return.. 471 // Afterwards sort namelist and use map to fill array to return..
468 QListIterator<OContact> it( m_contactList ); 472 QListIterator<OContact> it( m_contactList );
469 for( ; it.current(); ++it ){ 473 for( ; it.current(); ++it ){
470 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); 474 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
471 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); 475 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
472 } 476 }
473 names.sort(); 477 names.sort();
474 478
475 int i = 0; 479 int i = 0;
476 if ( asc ){ 480 if ( asc ){
477 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 481 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
478 m_currentQuery[i++] = nameToUid[ (*it) ]; 482 m_currentQuery[i++] = nameToUid[ (*it) ];
479 }else{ 483 }else{
480 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 484 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
481 m_currentQuery[i++] = nameToUid[ (*it) ]; 485 m_currentQuery[i++] = nameToUid[ (*it) ];
482 } 486 }
483 487
484 return m_currentQuery; 488 return m_currentQuery;
485 489
486} 490}
487 491
488bool OContactAccessBackend_XML::add ( const OContact &newcontact ) 492bool OContactAccessBackend_XML::add ( const OContact &newcontact )
489{ 493{
490 //qWarning("odefaultbackend: ACTION::ADD"); 494 //qWarning("odefaultbackend: ACTION::ADD");
491 updateJournal (newcontact, ACTION_ADD); 495 updateJournal (newcontact, ACTION_ADD);
492 addContact_p( newcontact ); 496 addContact_p( newcontact );
493 497
494 m_changed = true; 498 m_changed = true;
495 499
496 return true; 500 return true;
497} 501}
498 502
499bool OContactAccessBackend_XML::replace ( const OContact &contact ) 503bool OContactAccessBackend_XML::replace ( const OContact &contact )
500{ 504{
501 m_changed = true; 505 m_changed = true;
502 506
503 OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); 507 OContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
504 508
505 if ( found ) { 509 if ( found ) {
506 OContact* newCont = new OContact( contact ); 510 OContact* newCont = new OContact( contact );
507 511
508 updateJournal ( *newCont, ACTION_REPLACE); 512 updateJournal ( *newCont, ACTION_REPLACE);
509 m_contactList.removeRef ( found ); 513 m_contactList.removeRef ( found );
510 m_contactList.append ( newCont ); 514 m_contactList.append ( newCont );
511 m_uidToContact.remove( QString().setNum( contact.uid() ) ); 515 m_uidToContact.remove( QString().setNum( contact.uid() ) );
512 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); 516 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
513 517
514 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); 518 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid());
515 519
516 return true; 520 return true;
517 } else 521 } else
518 return false; 522 return false;
519} 523}
520 524