author | eilers <eilers> | 2003-03-21 12:26:28 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-03-21 12:26:28 (UTC) |
commit | 6d066b0ed3fd7fbedce84616a8fa279eec480f13 (patch) (unidiff) | |
tree | e4da9ca6c25236a72bd88f58876c1814bfbd174d /libopie | |
parent | 8136284c38384b169cd2843ee61480d45b6c1cba (diff) | |
download | opie-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 ..
-rw-r--r-- | libopie/pim/ocontactaccessbackend_xml.cpp | 6 |
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,777 +1,781 @@ | |||
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 | ||
100 | using namespace Opie; | 104 | using namespace Opie; |
101 | 105 | ||
102 | 106 | ||
103 | OContactAccessBackend_XML::OContactAccessBackend_XML ( QString appname, QString filename = 0l ): | 107 | OContactAccessBackend_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 | ||
127 | bool OContactAccessBackend_XML::save() | 131 | bool 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 | ||
197 | bool OContactAccessBackend_XML::load () | 201 | bool 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 | ||
216 | void OContactAccessBackend_XML::clear () | 220 | void 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 | ||
224 | bool OContactAccessBackend_XML::wasChangedExternally() | 228 | bool 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 | ||
233 | QArray<int> OContactAccessBackend_XML::allRecords() const | 237 | QArray<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 | ||
246 | OContact OContactAccessBackend_XML::find ( int uid ) const | 250 | OContact 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 | ||
259 | QArray<int> OContactAccessBackend_XML::queryByExample ( const OContact &query, int settings, | 263 | QArray<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 | ||
400 | QArray<int> OContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const | 404 | QArray<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 | ||
418 | const uint OContactAccessBackend_XML::querySettings() | 422 | const 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 | ||
431 | bool OContactAccessBackend_XML::hasQuerySettings (uint querySettings) const | 435 | bool 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.. |
460 | QArray<int> OContactAccessBackend_XML::sorted( bool asc, int , int , int ) | 464 | QArray<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 | ||
488 | bool OContactAccessBackend_XML::add ( const OContact &newcontact ) | 492 | bool 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 | ||
499 | bool OContactAccessBackend_XML::replace ( const OContact &contact ) | 503 | bool 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 | ||
521 | bool OContactAccessBackend_XML::remove ( int uid ) | 525 | bool OContactAccessBackend_XML::remove ( int uid ) |
522 | { | 526 | { |
523 | m_changed = true; | 527 | m_changed = true; |
524 | 528 | ||
525 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); | 529 | OContact* found = m_uidToContact.find ( QString().setNum( uid ) ); |
526 | 530 | ||
527 | if ( found ) { | 531 | if ( found ) { |
528 | updateJournal ( *found, ACTION_REMOVE); | 532 | updateJournal ( *found, ACTION_REMOVE); |
529 | m_contactList.removeRef ( found ); | 533 | m_contactList.removeRef ( found ); |
530 | m_uidToContact.remove( QString().setNum( uid ) ); | 534 | m_uidToContact.remove( QString().setNum( uid ) ); |
531 | 535 | ||
532 | return true; | 536 | return true; |
533 | } else | 537 | } else |
534 | return false; | 538 | return false; |
535 | } | 539 | } |
536 | 540 | ||
537 | bool OContactAccessBackend_XML::reload(){ | 541 | bool OContactAccessBackend_XML::reload(){ |
538 | /* Reload is the same as load in this implementation */ | 542 | /* Reload is the same as load in this implementation */ |
539 | return ( load() ); | 543 | return ( load() ); |
540 | } | 544 | } |
541 | 545 | ||
542 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) | 546 | void OContactAccessBackend_XML::addContact_p( const OContact &newcontact ) |
543 | { | 547 | { |
544 | OContact* contRef = new OContact( newcontact ); | 548 | OContact* contRef = new OContact( newcontact ); |
545 | 549 | ||
546 | m_contactList.append ( contRef ); | 550 | m_contactList.append ( contRef ); |
547 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); | 551 | m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); |
548 | } | 552 | } |
549 | 553 | ||
550 | /* This function loads the xml-database and the journalfile */ | 554 | /* This function loads the xml-database and the journalfile */ |
551 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) | 555 | bool OContactAccessBackend_XML::load( const QString filename, bool isJournal ) |
552 | { | 556 | { |
553 | 557 | ||
554 | /* We use the time of the last read to check if the file was | 558 | /* We use the time of the last read to check if the file was |
555 | * changed externally. | 559 | * changed externally. |
556 | */ | 560 | */ |
557 | if ( !isJournal ){ | 561 | if ( !isJournal ){ |
558 | QFileInfo fi( filename ); | 562 | QFileInfo fi( filename ); |
559 | m_readtime = fi.lastModified (); | 563 | m_readtime = fi.lastModified (); |
560 | } | 564 | } |
561 | 565 | ||
562 | const int JOURNALACTION = Qtopia::Notes + 1; | 566 | const int JOURNALACTION = Qtopia::Notes + 1; |
563 | const int JOURNALROW = JOURNALACTION + 1; | 567 | const int JOURNALROW = JOURNALACTION + 1; |
564 | 568 | ||
565 | bool foundAction = false; | 569 | bool foundAction = false; |
566 | journal_action action = ACTION_ADD; | 570 | journal_action action = ACTION_ADD; |
567 | int journalKey = 0; | 571 | int journalKey = 0; |
568 | QMap<int, QString> contactMap; | 572 | QMap<int, QString> contactMap; |
569 | QMap<QString, QString> customMap; | 573 | QMap<QString, QString> customMap; |
570 | QMap<QString, QString>::Iterator customIt; | 574 | QMap<QString, QString>::Iterator customIt; |
571 | QAsciiDict<int> dict( 47 ); | 575 | QAsciiDict<int> dict( 47 ); |
572 | 576 | ||
573 | dict.setAutoDelete( TRUE ); | 577 | dict.setAutoDelete( TRUE ); |
574 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | 578 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); |
575 | dict.insert( "Title", new int(Qtopia::Title) ); | 579 | dict.insert( "Title", new int(Qtopia::Title) ); |
576 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | 580 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); |
577 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | 581 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); |
578 | dict.insert( "LastName", new int(Qtopia::LastName) ); | 582 | dict.insert( "LastName", new int(Qtopia::LastName) ); |
579 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | 583 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); |
580 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | 584 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); |
581 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | 585 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); |
582 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | 586 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); |
583 | dict.insert( "Emails", new int(Qtopia::Emails) ); | 587 | dict.insert( "Emails", new int(Qtopia::Emails) ); |
584 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | 588 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); |
585 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | 589 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); |
586 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | 590 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); |
587 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | 591 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); |
588 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | 592 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); |
589 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | 593 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); |
590 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | 594 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); |
591 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | 595 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); |
592 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | 596 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); |
593 | dict.insert( "Company", new int(Qtopia::Company) ); | 597 | dict.insert( "Company", new int(Qtopia::Company) ); |
594 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | 598 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); |
595 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | 599 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); |
596 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | 600 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); |
597 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | 601 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); |
598 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | 602 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); |
599 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | 603 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); |
600 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | 604 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); |
601 | dict.insert( "Department", new int(Qtopia::Department) ); | 605 | dict.insert( "Department", new int(Qtopia::Department) ); |
602 | dict.insert( "Office", new int(Qtopia::Office) ); | 606 | dict.insert( "Office", new int(Qtopia::Office) ); |
603 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | 607 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); |
604 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | 608 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); |
605 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | 609 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); |
606 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | 610 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); |
607 | dict.insert( "Profession", new int(Qtopia::Profession) ); | 611 | dict.insert( "Profession", new int(Qtopia::Profession) ); |
608 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | 612 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); |
609 | dict.insert( "Manager", new int(Qtopia::Manager) ); | 613 | dict.insert( "Manager", new int(Qtopia::Manager) ); |
610 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | 614 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); |
611 | dict.insert( "Children", new int(Qtopia::Children) ); | 615 | dict.insert( "Children", new int(Qtopia::Children) ); |
612 | dict.insert( "Gender", new int(Qtopia::Gender) ); | 616 | dict.insert( "Gender", new int(Qtopia::Gender) ); |
613 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | 617 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); |
614 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | 618 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); |
615 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | 619 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); |
616 | dict.insert( "Notes", new int(Qtopia::Notes) ); | 620 | dict.insert( "Notes", new int(Qtopia::Notes) ); |
617 | dict.insert( "action", new int(JOURNALACTION) ); | 621 | dict.insert( "action", new int(JOURNALACTION) ); |
618 | dict.insert( "actionrow", new int(JOURNALROW) ); | 622 | dict.insert( "actionrow", new int(JOURNALROW) ); |
619 | 623 | ||
620 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); | 624 | //qWarning( "OContactDefaultBackEnd::loading %s", filename.latin1() ); |
621 | 625 | ||
622 | XMLElement *root = XMLElement::load( filename ); | 626 | XMLElement *root = XMLElement::load( filename ); |
623 | if(root != 0l ){ // start parsing | 627 | if(root != 0l ){ // start parsing |
624 | /* Parse all XML-Elements and put the data into the | 628 | /* Parse all XML-Elements and put the data into the |
625 | * Contact-Class | 629 | * Contact-Class |
626 | */ | 630 | */ |
627 | XMLElement *element = root->firstChild(); | 631 | XMLElement *element = root->firstChild(); |
628 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); | 632 | //qWarning("OContactAccess::load tagName(): %s", root->tagName().latin1() ); |
629 | element = element->firstChild(); | 633 | element = element->firstChild(); |
630 | 634 | ||
631 | /* Search Tag "Contacts" which is the parent of all Contacts */ | 635 | /* Search Tag "Contacts" which is the parent of all Contacts */ |
632 | while( element && !isJournal ){ | 636 | while( element && !isJournal ){ |
633 | if( element->tagName() != QString::fromLatin1("Contacts") ){ | 637 | if( element->tagName() != QString::fromLatin1("Contacts") ){ |
634 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", | 638 | //qWarning ("OContactDefBack::Searching for Tag \"Contacts\"! Found: %s", |
635 | // element->tagName().latin1()); | 639 | // element->tagName().latin1()); |
636 | element = element->nextChild(); | 640 | element = element->nextChild(); |
637 | } else { | 641 | } else { |
638 | element = element->firstChild(); | 642 | element = element->firstChild(); |
639 | break; | 643 | break; |
640 | } | 644 | } |
641 | } | 645 | } |
642 | /* Parse all Contacts and ignore unknown tags */ | 646 | /* Parse all Contacts and ignore unknown tags */ |
643 | while( element ){ | 647 | while( element ){ |
644 | if( element->tagName() != QString::fromLatin1("Contact") ){ | 648 | if( element->tagName() != QString::fromLatin1("Contact") ){ |
645 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", | 649 | //qWarning ("OContactDefBack::Searching for Tag \"Contact\"! Found: %s", |
646 | // element->tagName().latin1()); | 650 | // element->tagName().latin1()); |
647 | element = element->nextChild(); | 651 | element = element->nextChild(); |
648 | continue; | 652 | continue; |
649 | } | 653 | } |
650 | /* Found alement with tagname "contact", now parse and store all | 654 | /* Found alement with tagname "contact", now parse and store all |
651 | * attributes contained | 655 | * attributes contained |
652 | */ | 656 | */ |
653 | //qWarning("OContactDefBack::load element tagName() : %s", | 657 | //qWarning("OContactDefBack::load element tagName() : %s", |
654 | // element->tagName().latin1() ); | 658 | // element->tagName().latin1() ); |
655 | QString dummy; | 659 | QString dummy; |
656 | foundAction = false; | 660 | foundAction = false; |
657 | 661 | ||
658 | XMLElement::AttributeMap aMap = element->attributes(); | 662 | XMLElement::AttributeMap aMap = element->attributes(); |
659 | XMLElement::AttributeMap::Iterator it; | 663 | XMLElement::AttributeMap::Iterator it; |
660 | contactMap.clear(); | 664 | contactMap.clear(); |
661 | customMap.clear(); | 665 | customMap.clear(); |
662 | for( it = aMap.begin(); it != aMap.end(); ++it ){ | 666 | for( it = aMap.begin(); it != aMap.end(); ++it ){ |
663 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); | 667 | // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); |
664 | 668 | ||
665 | int *find = dict[ it.key() ]; | 669 | int *find = dict[ it.key() ]; |
666 | /* Unknown attributes will be stored as "Custom" elements */ | 670 | /* Unknown attributes will be stored as "Custom" elements */ |
667 | if ( !find ) { | 671 | if ( !find ) { |
668 | qWarning("Attribute %s not known.", it.key().latin1()); | 672 | qWarning("Attribute %s not known.", it.key().latin1()); |
669 | //contact.setCustomField(it.key(), it.data()); | 673 | //contact.setCustomField(it.key(), it.data()); |
670 | customMap.insert( it.key(), it.data() ); | 674 | customMap.insert( it.key(), it.data() ); |
671 | continue; | 675 | continue; |
672 | } | 676 | } |
673 | 677 | ||
674 | /* Check if special conversion is needed and add attribute | 678 | /* Check if special conversion is needed and add attribute |
675 | * into Contact class | 679 | * into Contact class |
676 | */ | 680 | */ |
677 | switch( *find ) { | 681 | switch( *find ) { |
678 | /* | 682 | /* |
679 | case Qtopia::AddressUid: | 683 | case Qtopia::AddressUid: |
680 | contact.setUid( it.data().toInt() ); | 684 | contact.setUid( it.data().toInt() ); |
681 | break; | 685 | break; |
682 | case Qtopia::AddressCategory: | 686 | case Qtopia::AddressCategory: |
683 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); | 687 | contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); |
684 | break; | 688 | break; |
685 | */ | 689 | */ |
686 | case JOURNALACTION: | 690 | case JOURNALACTION: |
687 | action = journal_action(it.data().toInt()); | 691 | action = journal_action(it.data().toInt()); |
688 | foundAction = true; | 692 | foundAction = true; |
689 | qWarning ("ODefBack(journal)::ACTION found: %d", action); | 693 | qWarning ("ODefBack(journal)::ACTION found: %d", action); |
690 | break; | 694 | break; |
691 | case JOURNALROW: | 695 | case JOURNALROW: |
692 | journalKey = it.data().toInt(); | 696 | journalKey = it.data().toInt(); |
693 | break; | 697 | break; |
694 | default: // no conversion needed add them to the map | 698 | default: // no conversion needed add them to the map |
695 | contactMap.insert( *find, it.data() ); | 699 | contactMap.insert( *find, it.data() ); |
696 | break; | 700 | break; |
697 | } | 701 | } |
698 | } | 702 | } |
699 | /* now generate the Contact contact */ | 703 | /* now generate the Contact contact */ |
700 | OContact contact( contactMap ); | 704 | OContact contact( contactMap ); |
701 | 705 | ||
702 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { | 706 | for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { |
703 | contact.setCustomField( customIt.key(), customIt.data() ); | 707 | contact.setCustomField( customIt.key(), customIt.data() ); |
704 | } | 708 | } |
705 | 709 | ||
706 | if (foundAction){ | 710 | if (foundAction){ |
707 | foundAction = false; | 711 | foundAction = false; |
708 | switch ( action ) { | 712 | switch ( action ) { |
709 | case ACTION_ADD: | 713 | case ACTION_ADD: |
710 | addContact_p (contact); | 714 | addContact_p (contact); |
711 | break; | 715 | break; |
712 | case ACTION_REMOVE: | 716 | case ACTION_REMOVE: |
713 | if ( !remove (contact.uid()) ) | 717 | if ( !remove (contact.uid()) ) |
714 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", | 718 | qWarning ("ODefBack(journal)::Unable to remove uid: %d", |
715 | contact.uid() ); | 719 | contact.uid() ); |
716 | break; | 720 | break; |
717 | case ACTION_REPLACE: | 721 | case ACTION_REPLACE: |
718 | if ( !replace ( contact ) ) | 722 | if ( !replace ( contact ) ) |
719 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", | 723 | qWarning ("ODefBack(journal)::Unable to replace uid: %d", |
720 | contact.uid() ); | 724 | contact.uid() ); |
721 | break; | 725 | break; |
722 | default: | 726 | default: |
723 | qWarning ("Unknown action: ignored !"); | 727 | qWarning ("Unknown action: ignored !"); |
724 | break; | 728 | break; |
725 | } | 729 | } |
726 | }else{ | 730 | }else{ |
727 | /* Add contact to list */ | 731 | /* Add contact to list */ |
728 | addContact_p (contact); | 732 | addContact_p (contact); |
729 | } | 733 | } |
730 | 734 | ||
731 | /* Move to next element */ | 735 | /* Move to next element */ |
732 | element = element->nextChild(); | 736 | element = element->nextChild(); |
733 | } | 737 | } |
734 | }else { | 738 | }else { |
735 | qWarning("ODefBack::could not load"); | 739 | qWarning("ODefBack::could not load"); |
736 | } | 740 | } |
737 | delete root; | 741 | delete root; |
738 | qWarning("returning from loading" ); | 742 | qWarning("returning from loading" ); |
739 | return true; | 743 | return true; |
740 | } | 744 | } |
741 | 745 | ||
742 | 746 | ||
743 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, | 747 | void OContactAccessBackend_XML::updateJournal( const OContact& cnt, |
744 | journal_action action ) | 748 | journal_action action ) |
745 | { | 749 | { |
746 | QFile f( m_journalName ); | 750 | QFile f( m_journalName ); |
747 | bool created = !f.exists(); | 751 | bool created = !f.exists(); |
748 | if ( !f.open(IO_WriteOnly|IO_Append) ) | 752 | if ( !f.open(IO_WriteOnly|IO_Append) ) |
749 | return; | 753 | return; |
750 | 754 | ||
751 | QString buf; | 755 | QString buf; |
752 | QCString str; | 756 | QCString str; |
753 | 757 | ||
754 | // if the file was created, we have to set the Tag "<CONTACTS>" to | 758 | // if the file was created, we have to set the Tag "<CONTACTS>" to |
755 | // get a XML-File which is readable by our parser. | 759 | // get a XML-File which is readable by our parser. |
756 | // This is just a cheat, but better than rewrite the parser. | 760 | // This is just a cheat, but better than rewrite the parser. |
757 | if ( created ){ | 761 | if ( created ){ |
758 | buf = "<Contacts>"; | 762 | buf = "<Contacts>"; |
759 | QCString cstr = buf.utf8(); | 763 | QCString cstr = buf.utf8(); |
760 | f.writeBlock( cstr.data(), cstr.length() ); | 764 | f.writeBlock( cstr.data(), cstr.length() ); |
761 | } | 765 | } |
762 | 766 | ||
763 | buf = "<Contact "; | 767 | buf = "<Contact "; |
764 | cnt.save( buf ); | 768 | cnt.save( buf ); |
765 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | 769 | buf += " action=\"" + QString::number( (int)action ) + "\" "; |
766 | buf += "/>\n"; | 770 | buf += "/>\n"; |
767 | QCString cstr = buf.utf8(); | 771 | QCString cstr = buf.utf8(); |
768 | f.writeBlock( cstr.data(), cstr.length() ); | 772 | f.writeBlock( cstr.data(), cstr.length() ); |
769 | } | 773 | } |
770 | 774 | ||
771 | void OContactAccessBackend_XML::removeJournal() | 775 | void OContactAccessBackend_XML::removeJournal() |
772 | { | 776 | { |
773 | QFile f ( m_journalName ); | 777 | QFile f ( m_journalName ); |
774 | if ( f.exists() ) | 778 | if ( f.exists() ) |
775 | f.remove(); | 779 | f.remove(); |
776 | } | 780 | } |
777 | 781 | ||