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