-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.cpp | 13 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 13 |
2 files changed, 22 insertions, 4 deletions
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp index ca9e410..1dc6b48 100644 --- a/libopie/pim/ocontactaccessbackend_vcard.cpp +++ b/libopie/pim/ocontactaccessbackend_vcard.cpp | |||
@@ -1,444 +1,453 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
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/01/13 15:49:31 eilers | ||
21 | * Fixing crash when businesscard.vcf is missing.. | ||
22 | * | ||
20 | * Revision 1.5 2002/12/07 13:26:22 eilers | 23 | * Revision 1.5 2002/12/07 13:26:22 eilers |
21 | * Fixing bug in storing anniversary.. | 24 | * Fixing bug in storing anniversary.. |
22 | * | 25 | * |
23 | * Revision 1.4 2002/11/13 14:14:51 eilers | 26 | * Revision 1.4 2002/11/13 14:14:51 eilers |
24 | * Added sorted for Contacts.. | 27 | * Added sorted for Contacts.. |
25 | * | 28 | * |
26 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 29 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
27 | * no default arguments in implementation | 30 | * no default arguments in implementation |
28 | * | 31 | * |
29 | * Revision 1.2 2002/11/10 15:41:53 eilers | 32 | * Revision 1.2 2002/11/10 15:41:53 eilers |
30 | * Bugfixes.. | 33 | * Bugfixes.. |
31 | * | 34 | * |
32 | * Revision 1.1 2002/11/09 14:34:52 eilers | 35 | * Revision 1.1 2002/11/09 14:34:52 eilers |
33 | * Added VCard Backend. | 36 | * Added VCard Backend. |
34 | * | 37 | * |
35 | */ | 38 | */ |
36 | #include "ocontactaccessbackend_vcard.h" | 39 | #include "ocontactaccessbackend_vcard.h" |
37 | #include "../../library/backend/vobject_p.h" | 40 | #include "../../library/backend/vobject_p.h" |
38 | #include "../../library/backend/qfiledirect_p.h" | 41 | #include "../../library/backend/qfiledirect_p.h" |
39 | 42 | ||
40 | #include <qpe/timeconversion.h> | 43 | #include <qpe/timeconversion.h> |
41 | 44 | ||
42 | #include <qfile.h> | 45 | #include <qfile.h> |
43 | 46 | ||
44 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 47 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
45 | m_dirty( false ), | 48 | m_dirty( false ), |
46 | m_file( filename ) | 49 | m_file( filename ) |
47 | { | 50 | { |
48 | load(); | 51 | load(); |
49 | } | 52 | } |
50 | 53 | ||
51 | 54 | ||
52 | bool OContactAccessBackend_VCard::load () | 55 | bool OContactAccessBackend_VCard::load () |
53 | { | 56 | { |
54 | m_map.clear(); | 57 | m_map.clear(); |
55 | m_dirty = false; | 58 | m_dirty = false; |
56 | 59 | ||
57 | VObject* obj = 0l; | 60 | VObject* obj = 0l; |
58 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 61 | |
59 | if ( !obj ) | 62 | if ( QFile( m_file ).exists() ){ |
63 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | ||
64 | if ( !obj ) | ||
65 | return false; | ||
66 | }else{ | ||
67 | qWarning("File \"%s\" not found !", m_file.latin1() ); | ||
60 | return false; | 68 | return false; |
69 | } | ||
61 | 70 | ||
62 | while ( obj ) { | 71 | while ( obj ) { |
63 | OContact con = parseVObject( obj ); | 72 | OContact con = parseVObject( obj ); |
64 | /* | 73 | /* |
65 | * if uid is 0 assign a new one | 74 | * if uid is 0 assign a new one |
66 | * this at least happens on | 75 | * this at least happens on |
67 | * Nokia6210 | 76 | * Nokia6210 |
68 | */ | 77 | */ |
69 | if ( con.uid() == 0 ){ | 78 | if ( con.uid() == 0 ){ |
70 | con.setUid( 1 ); | 79 | con.setUid( 1 ); |
71 | qWarning("assigned new uid %d",con.uid() ); | 80 | qWarning("assigned new uid %d",con.uid() ); |
72 | } | 81 | } |
73 | 82 | ||
74 | m_map.insert( con.uid(), con ); | 83 | m_map.insert( con.uid(), con ); |
75 | 84 | ||
76 | VObject *t = obj; | 85 | VObject *t = obj; |
77 | obj = nextVObjectInList(obj); | 86 | obj = nextVObjectInList(obj); |
78 | cleanVObject( t ); | 87 | cleanVObject( t ); |
79 | } | 88 | } |
80 | 89 | ||
81 | return true; | 90 | return true; |
82 | 91 | ||
83 | } | 92 | } |
84 | bool OContactAccessBackend_VCard::reload() | 93 | bool OContactAccessBackend_VCard::reload() |
85 | { | 94 | { |
86 | return load(); | 95 | return load(); |
87 | } | 96 | } |
88 | bool OContactAccessBackend_VCard::save() | 97 | bool OContactAccessBackend_VCard::save() |
89 | { | 98 | { |
90 | if (!m_dirty ) | 99 | if (!m_dirty ) |
91 | return true; | 100 | return true; |
92 | 101 | ||
93 | QFileDirect file( m_file ); | 102 | QFileDirect file( m_file ); |
94 | if (!file.open(IO_WriteOnly ) ) | 103 | if (!file.open(IO_WriteOnly ) ) |
95 | return false; | 104 | return false; |
96 | 105 | ||
97 | VObject *obj; | 106 | VObject *obj; |
98 | obj = newVObject( VCCalProp ); | 107 | obj = newVObject( VCCalProp ); |
99 | addPropValue( obj, VCVersionProp, "1.0" ); | 108 | addPropValue( obj, VCVersionProp, "1.0" ); |
100 | 109 | ||
101 | VObject *vo; | 110 | VObject *vo; |
102 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 111 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
103 | vo = createVObject( *it ); | 112 | vo = createVObject( *it ); |
104 | writeVObject( file.directHandle() , vo ); | 113 | writeVObject( file.directHandle() , vo ); |
105 | cleanVObject( vo ); | 114 | cleanVObject( vo ); |
106 | } | 115 | } |
107 | cleanStrTbl(); | 116 | cleanStrTbl(); |
108 | 117 | ||
109 | m_dirty = false; | 118 | m_dirty = false; |
110 | return true; | 119 | return true; |
111 | 120 | ||
112 | 121 | ||
113 | } | 122 | } |
114 | void OContactAccessBackend_VCard::clear () | 123 | void OContactAccessBackend_VCard::clear () |
115 | { | 124 | { |
116 | m_map.clear(); | 125 | m_map.clear(); |
117 | m_dirty = true; // ??? sure ? (se) | 126 | m_dirty = true; // ??? sure ? (se) |
118 | } | 127 | } |
119 | 128 | ||
120 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 129 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
121 | { | 130 | { |
122 | m_map.insert( newcontact.uid(), newcontact ); | 131 | m_map.insert( newcontact.uid(), newcontact ); |
123 | m_dirty = true; | 132 | m_dirty = true; |
124 | return true; | 133 | return true; |
125 | } | 134 | } |
126 | 135 | ||
127 | bool OContactAccessBackend_VCard::remove ( int uid ) | 136 | bool OContactAccessBackend_VCard::remove ( int uid ) |
128 | { | 137 | { |
129 | m_map.remove( uid ); | 138 | m_map.remove( uid ); |
130 | m_dirty = true; | 139 | m_dirty = true; |
131 | return true; | 140 | return true; |
132 | } | 141 | } |
133 | 142 | ||
134 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 143 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |
135 | { | 144 | { |
136 | m_map.replace( contact.uid(), contact ); | 145 | m_map.replace( contact.uid(), contact ); |
137 | m_dirty = true; | 146 | m_dirty = true; |
138 | return true; | 147 | return true; |
139 | } | 148 | } |
140 | 149 | ||
141 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 150 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
142 | { | 151 | { |
143 | return m_map[uid]; | 152 | return m_map[uid]; |
144 | } | 153 | } |
145 | 154 | ||
146 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 155 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
147 | { | 156 | { |
148 | QArray<int> ar( m_map.count() ); | 157 | QArray<int> ar( m_map.count() ); |
149 | QMap<int, OContact>::ConstIterator it; | 158 | QMap<int, OContact>::ConstIterator it; |
150 | int i = 0; | 159 | int i = 0; |
151 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 160 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
152 | ar[i] = it.key(); | 161 | ar[i] = it.key(); |
153 | i++; | 162 | i++; |
154 | } | 163 | } |
155 | return ar; | 164 | return ar; |
156 | } | 165 | } |
157 | 166 | ||
158 | // Not implemented | 167 | // Not implemented |
159 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) | 168 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) |
160 | { | 169 | { |
161 | QArray<int> ar(0); | 170 | QArray<int> ar(0); |
162 | return ar; | 171 | return ar; |
163 | } | 172 | } |
164 | 173 | ||
165 | // Not implemented | 174 | // Not implemented |
166 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 175 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
167 | { | 176 | { |
168 | QArray<int> ar(0); | 177 | QArray<int> ar(0); |
169 | return ar; | 178 | return ar; |
170 | } | 179 | } |
171 | 180 | ||
172 | const uint OContactAccessBackend_VCard::querySettings() | 181 | const uint OContactAccessBackend_VCard::querySettings() |
173 | { | 182 | { |
174 | return 0; // No search possible | 183 | return 0; // No search possible |
175 | } | 184 | } |
176 | 185 | ||
177 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 186 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
178 | { | 187 | { |
179 | return false; // No search possible, therefore all settings invalid ;) | 188 | return false; // No search possible, therefore all settings invalid ;) |
180 | } | 189 | } |
181 | 190 | ||
182 | bool OContactAccessBackend_VCard::wasChangedExternally() | 191 | bool OContactAccessBackend_VCard::wasChangedExternally() |
183 | { | 192 | { |
184 | return false; // Don't expect concurrent access | 193 | return false; // Don't expect concurrent access |
185 | } | 194 | } |
186 | 195 | ||
187 | // Not implemented | 196 | // Not implemented |
188 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | 197 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) |
189 | { | 198 | { |
190 | QArray<int> ar(0); | 199 | QArray<int> ar(0); |
191 | return ar; | 200 | return ar; |
192 | } | 201 | } |
193 | 202 | ||
194 | // *** Private stuff *** | 203 | // *** Private stuff *** |
195 | 204 | ||
196 | 205 | ||
197 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 206 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
198 | { | 207 | { |
199 | OContact c; | 208 | OContact c; |
200 | 209 | ||
201 | VObjectIterator it; | 210 | VObjectIterator it; |
202 | initPropIterator( &it, obj ); | 211 | initPropIterator( &it, obj ); |
203 | while( moreIteration( &it ) ) { | 212 | while( moreIteration( &it ) ) { |
204 | VObject *o = nextVObject( &it ); | 213 | VObject *o = nextVObject( &it ); |
205 | QCString name = vObjectName( o ); | 214 | QCString name = vObjectName( o ); |
206 | QCString value = vObjectStringZValue( o ); | 215 | QCString value = vObjectStringZValue( o ); |
207 | if ( name == VCNameProp ) { | 216 | if ( name == VCNameProp ) { |
208 | VObjectIterator nit; | 217 | VObjectIterator nit; |
209 | initPropIterator( &nit, o ); | 218 | initPropIterator( &nit, o ); |
210 | while( moreIteration( &nit ) ) { | 219 | while( moreIteration( &nit ) ) { |
211 | VObject *o = nextVObject( &nit ); | 220 | VObject *o = nextVObject( &nit ); |
212 | QCString name = vObjectTypeInfo( o ); | 221 | QCString name = vObjectTypeInfo( o ); |
213 | QString value = vObjectStringZValue( o ); | 222 | QString value = vObjectStringZValue( o ); |
214 | if ( name == VCNamePrefixesProp ) | 223 | if ( name == VCNamePrefixesProp ) |
215 | c.setTitle( value ); | 224 | c.setTitle( value ); |
216 | else if ( name == VCNameSuffixesProp ) | 225 | else if ( name == VCNameSuffixesProp ) |
217 | c.setSuffix( value ); | 226 | c.setSuffix( value ); |
218 | else if ( name == VCFamilyNameProp ) | 227 | else if ( name == VCFamilyNameProp ) |
219 | c.setLastName( value ); | 228 | c.setLastName( value ); |
220 | else if ( name == VCGivenNameProp ) | 229 | else if ( name == VCGivenNameProp ) |
221 | c.setFirstName( value ); | 230 | c.setFirstName( value ); |
222 | else if ( name == VCAdditionalNamesProp ) | 231 | else if ( name == VCAdditionalNamesProp ) |
223 | c.setMiddleName( value ); | 232 | c.setMiddleName( value ); |
224 | } | 233 | } |
225 | } | 234 | } |
226 | else if ( name == VCAdrProp ) { | 235 | else if ( name == VCAdrProp ) { |
227 | bool work = TRUE; // default address is work address | 236 | bool work = TRUE; // default address is work address |
228 | QString street; | 237 | QString street; |
229 | QString city; | 238 | QString city; |
230 | QString region; | 239 | QString region; |
231 | QString postal; | 240 | QString postal; |
232 | QString country; | 241 | QString country; |
233 | 242 | ||
234 | VObjectIterator nit; | 243 | VObjectIterator nit; |
235 | initPropIterator( &nit, o ); | 244 | initPropIterator( &nit, o ); |
236 | while( moreIteration( &nit ) ) { | 245 | while( moreIteration( &nit ) ) { |
237 | VObject *o = nextVObject( &nit ); | 246 | VObject *o = nextVObject( &nit ); |
238 | QCString name = vObjectName( o ); | 247 | QCString name = vObjectName( o ); |
239 | QString value = vObjectStringZValue( o ); | 248 | QString value = vObjectStringZValue( o ); |
240 | if ( name == VCHomeProp ) | 249 | if ( name == VCHomeProp ) |
241 | work = FALSE; | 250 | work = FALSE; |
242 | else if ( name == VCWorkProp ) | 251 | else if ( name == VCWorkProp ) |
243 | work = TRUE; | 252 | work = TRUE; |
244 | else if ( name == VCStreetAddressProp ) | 253 | else if ( name == VCStreetAddressProp ) |
245 | street = value; | 254 | street = value; |
246 | else if ( name == VCCityProp ) | 255 | else if ( name == VCCityProp ) |
247 | city = value; | 256 | city = value; |
248 | else if ( name == VCRegionProp ) | 257 | else if ( name == VCRegionProp ) |
249 | region = value; | 258 | region = value; |
250 | else if ( name == VCPostalCodeProp ) | 259 | else if ( name == VCPostalCodeProp ) |
251 | postal = value; | 260 | postal = value; |
252 | else if ( name == VCCountryNameProp ) | 261 | else if ( name == VCCountryNameProp ) |
253 | country = value; | 262 | country = value; |
254 | } | 263 | } |
255 | if ( work ) { | 264 | if ( work ) { |
256 | c.setBusinessStreet( street ); | 265 | c.setBusinessStreet( street ); |
257 | c.setBusinessCity( city ); | 266 | c.setBusinessCity( city ); |
258 | c.setBusinessCountry( country ); | 267 | c.setBusinessCountry( country ); |
259 | c.setBusinessZip( postal ); | 268 | c.setBusinessZip( postal ); |
260 | c.setBusinessState( region ); | 269 | c.setBusinessState( region ); |
261 | } else { | 270 | } else { |
262 | c.setHomeStreet( street ); | 271 | c.setHomeStreet( street ); |
263 | c.setHomeCity( city ); | 272 | c.setHomeCity( city ); |
264 | c.setHomeCountry( country ); | 273 | c.setHomeCountry( country ); |
265 | c.setHomeZip( postal ); | 274 | c.setHomeZip( postal ); |
266 | c.setHomeState( region ); | 275 | c.setHomeState( region ); |
267 | } | 276 | } |
268 | } | 277 | } |
269 | else if ( name == VCTelephoneProp ) { | 278 | else if ( name == VCTelephoneProp ) { |
270 | enum { | 279 | enum { |
271 | HOME = 0x01, | 280 | HOME = 0x01, |
272 | WORK = 0x02, | 281 | WORK = 0x02, |
273 | VOICE = 0x04, | 282 | VOICE = 0x04, |
274 | CELL = 0x08, | 283 | CELL = 0x08, |
275 | FAX = 0x10, | 284 | FAX = 0x10, |
276 | PAGER = 0x20, | 285 | PAGER = 0x20, |
277 | UNKNOWN = 0x80 | 286 | UNKNOWN = 0x80 |
278 | }; | 287 | }; |
279 | int type = 0; | 288 | int type = 0; |
280 | 289 | ||
281 | VObjectIterator nit; | 290 | VObjectIterator nit; |
282 | initPropIterator( &nit, o ); | 291 | initPropIterator( &nit, o ); |
283 | while( moreIteration( &nit ) ) { | 292 | while( moreIteration( &nit ) ) { |
284 | VObject *o = nextVObject( &nit ); | 293 | VObject *o = nextVObject( &nit ); |
285 | QCString name = vObjectTypeInfo( o ); | 294 | QCString name = vObjectTypeInfo( o ); |
286 | if ( name == VCHomeProp ) | 295 | if ( name == VCHomeProp ) |
287 | type |= HOME; | 296 | type |= HOME; |
288 | else if ( name == VCWorkProp ) | 297 | else if ( name == VCWorkProp ) |
289 | type |= WORK; | 298 | type |= WORK; |
290 | else if ( name == VCVoiceProp ) | 299 | else if ( name == VCVoiceProp ) |
291 | type |= VOICE; | 300 | type |= VOICE; |
292 | else if ( name == VCCellularProp ) | 301 | else if ( name == VCCellularProp ) |
293 | type |= CELL; | 302 | type |= CELL; |
294 | else if ( name == VCFaxProp ) | 303 | else if ( name == VCFaxProp ) |
295 | type |= FAX; | 304 | type |= FAX; |
296 | else if ( name == VCPagerProp ) | 305 | else if ( name == VCPagerProp ) |
297 | type |= PAGER; | 306 | type |= PAGER; |
298 | else if ( name == VCPreferredProp ) | 307 | else if ( name == VCPreferredProp ) |
299 | ; | 308 | ; |
300 | else | 309 | else |
301 | type |= UNKNOWN; | 310 | type |= UNKNOWN; |
302 | } | 311 | } |
303 | if ( (type & UNKNOWN) != UNKNOWN ) { | 312 | if ( (type & UNKNOWN) != UNKNOWN ) { |
304 | if ( ( type & (HOME|WORK) ) == 0 ) // default | 313 | if ( ( type & (HOME|WORK) ) == 0 ) // default |
305 | type |= HOME; | 314 | type |= HOME; |
306 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | 315 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default |
307 | type |= VOICE; | 316 | type |= VOICE; |
308 | 317 | ||
309 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) | 318 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) |
310 | c.setHomePhone( value ); | 319 | c.setHomePhone( value ); |
311 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | 320 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) |
312 | c.setHomeFax( value ); | 321 | c.setHomeFax( value ); |
313 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | 322 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) |
314 | c.setHomeMobile( value ); | 323 | c.setHomeMobile( value ); |
315 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) | 324 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) |
316 | c.setBusinessPhone( value ); | 325 | c.setBusinessPhone( value ); |
317 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | 326 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) |
318 | c.setBusinessFax( value ); | 327 | c.setBusinessFax( value ); |
319 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | 328 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) |
320 | c.setBusinessMobile( value ); | 329 | c.setBusinessMobile( value ); |
321 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | 330 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) |
322 | c.setBusinessPager( value ); | 331 | c.setBusinessPager( value ); |
323 | } | 332 | } |
324 | } | 333 | } |
325 | else if ( name == VCEmailAddressProp ) { | 334 | else if ( name == VCEmailAddressProp ) { |
326 | QString email = vObjectStringZValue( o ); | 335 | QString email = vObjectStringZValue( o ); |
327 | bool valid = TRUE; | 336 | bool valid = TRUE; |
328 | VObjectIterator nit; | 337 | VObjectIterator nit; |
329 | initPropIterator( &nit, o ); | 338 | initPropIterator( &nit, o ); |
330 | while( moreIteration( &nit ) ) { | 339 | while( moreIteration( &nit ) ) { |
331 | VObject *o = nextVObject( &nit ); | 340 | VObject *o = nextVObject( &nit ); |
332 | QCString name = vObjectTypeInfo( o ); | 341 | QCString name = vObjectTypeInfo( o ); |
333 | if ( name != VCInternetProp && name != VCHomeProp && | 342 | if ( name != VCInternetProp && name != VCHomeProp && |
334 | name != VCWorkProp && | 343 | name != VCWorkProp && |
335 | name != VCPreferredProp ) | 344 | name != VCPreferredProp ) |
336 | // ### preffered should map to default email | 345 | // ### preffered should map to default email |
337 | valid = FALSE; | 346 | valid = FALSE; |
338 | } | 347 | } |
339 | if ( valid ) { | 348 | if ( valid ) { |
340 | c.insertEmail( email ); | 349 | c.insertEmail( email ); |
341 | } | 350 | } |
342 | } | 351 | } |
343 | else if ( name == VCURLProp ) { | 352 | else if ( name == VCURLProp ) { |
344 | VObjectIterator nit; | 353 | VObjectIterator nit; |
345 | initPropIterator( &nit, o ); | 354 | initPropIterator( &nit, o ); |
346 | while( moreIteration( &nit ) ) { | 355 | while( moreIteration( &nit ) ) { |
347 | VObject *o = nextVObject( &nit ); | 356 | VObject *o = nextVObject( &nit ); |
348 | QCString name = vObjectTypeInfo( o ); | 357 | QCString name = vObjectTypeInfo( o ); |
349 | if ( name == VCHomeProp ) | 358 | if ( name == VCHomeProp ) |
350 | c.setHomeWebpage( value ); | 359 | c.setHomeWebpage( value ); |
351 | else if ( name == VCWorkProp ) | 360 | else if ( name == VCWorkProp ) |
352 | c.setBusinessWebpage( value ); | 361 | c.setBusinessWebpage( value ); |
353 | } | 362 | } |
354 | } | 363 | } |
355 | else if ( name == VCOrgProp ) { | 364 | else if ( name == VCOrgProp ) { |
356 | VObjectIterator nit; | 365 | VObjectIterator nit; |
357 | initPropIterator( &nit, o ); | 366 | initPropIterator( &nit, o ); |
358 | while( moreIteration( &nit ) ) { | 367 | while( moreIteration( &nit ) ) { |
359 | VObject *o = nextVObject( &nit ); | 368 | VObject *o = nextVObject( &nit ); |
360 | QCString name = vObjectName( o ); | 369 | QCString name = vObjectName( o ); |
361 | QString value = vObjectStringZValue( o ); | 370 | QString value = vObjectStringZValue( o ); |
362 | if ( name == VCOrgNameProp ) | 371 | if ( name == VCOrgNameProp ) |
363 | c.setCompany( value ); | 372 | c.setCompany( value ); |
364 | else if ( name == VCOrgUnitProp ) | 373 | else if ( name == VCOrgUnitProp ) |
365 | c.setDepartment( value ); | 374 | c.setDepartment( value ); |
366 | else if ( name == VCOrgUnit2Prop ) | 375 | else if ( name == VCOrgUnit2Prop ) |
367 | c.setOffice( value ); | 376 | c.setOffice( value ); |
368 | } | 377 | } |
369 | } | 378 | } |
370 | else if ( name == VCTitleProp ) { | 379 | else if ( name == VCTitleProp ) { |
371 | c.setJobTitle( value ); | 380 | c.setJobTitle( value ); |
372 | } | 381 | } |
373 | else if ( name == "X-Qtopia-Profession" ) { | 382 | else if ( name == "X-Qtopia-Profession" ) { |
374 | c.setProfession( value ); | 383 | c.setProfession( value ); |
375 | } | 384 | } |
376 | else if ( name == "X-Qtopia-Manager" ) { | 385 | else if ( name == "X-Qtopia-Manager" ) { |
377 | c.setManager( value ); | 386 | c.setManager( value ); |
378 | } | 387 | } |
379 | else if ( name == "X-Qtopia-Assistant" ) { | 388 | else if ( name == "X-Qtopia-Assistant" ) { |
380 | c.setAssistant( value ); | 389 | c.setAssistant( value ); |
381 | } | 390 | } |
382 | else if ( name == "X-Qtopia-Spouse" ) { | 391 | else if ( name == "X-Qtopia-Spouse" ) { |
383 | c.setSpouse( value ); | 392 | c.setSpouse( value ); |
384 | } | 393 | } |
385 | else if ( name == "X-Qtopia-Gender" ) { | 394 | else if ( name == "X-Qtopia-Gender" ) { |
386 | c.setGender( value ); | 395 | c.setGender( value ); |
387 | } | 396 | } |
388 | else if ( name == "X-Qtopia-Anniversary" ) { | 397 | else if ( name == "X-Qtopia-Anniversary" ) { |
389 | c.setAnniversary( convVCardDateToDate( value ) ); | 398 | c.setAnniversary( convVCardDateToDate( value ) ); |
390 | } | 399 | } |
391 | else if ( name == "X-Qtopia-Nickname" ) { | 400 | else if ( name == "X-Qtopia-Nickname" ) { |
392 | c.setNickname( value ); | 401 | c.setNickname( value ); |
393 | } | 402 | } |
394 | else if ( name == "X-Qtopia-Children" ) { | 403 | else if ( name == "X-Qtopia-Children" ) { |
395 | c.setChildren( value ); | 404 | c.setChildren( value ); |
396 | } | 405 | } |
397 | else if ( name == VCBirthDateProp ) { | 406 | else if ( name == VCBirthDateProp ) { |
398 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 407 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
399 | c.setBirthday( convVCardDateToDate( value ) ); | 408 | c.setBirthday( convVCardDateToDate( value ) ); |
400 | 409 | ||
401 | } | 410 | } |
402 | 411 | ||
403 | #if 0 | 412 | #if 0 |
404 | else { | 413 | else { |
405 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 414 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
406 | VObjectIterator nit; | 415 | VObjectIterator nit; |
407 | initPropIterator( &nit, o ); | 416 | initPropIterator( &nit, o ); |
408 | while( moreIteration( &nit ) ) { | 417 | while( moreIteration( &nit ) ) { |
409 | VObject *o = nextVObject( &nit ); | 418 | VObject *o = nextVObject( &nit ); |
410 | QCString name = vObjectName( o ); | 419 | QCString name = vObjectName( o ); |
411 | QString value = vObjectStringZValue( o ); | 420 | QString value = vObjectStringZValue( o ); |
412 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 421 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
413 | } | 422 | } |
414 | } | 423 | } |
415 | #endif | 424 | #endif |
416 | } | 425 | } |
417 | c.setFileAs(); | 426 | c.setFileAs(); |
418 | return c; | 427 | return c; |
419 | } | 428 | } |
420 | 429 | ||
421 | 430 | ||
422 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 431 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) |
423 | { | 432 | { |
424 | VObject *vcard = newVObject( VCCardProp ); | 433 | VObject *vcard = newVObject( VCCardProp ); |
425 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 434 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
426 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 435 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
427 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 436 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
428 | 437 | ||
429 | // full name | 438 | // full name |
430 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 439 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
431 | 440 | ||
432 | // name properties | 441 | // name properties |
433 | VObject *name = safeAddProp( vcard, VCNameProp ); | 442 | VObject *name = safeAddProp( vcard, VCNameProp ); |
434 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 443 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
435 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | 444 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); |
436 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | 445 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); |
437 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | 446 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); |
438 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | 447 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); |
439 | 448 | ||
440 | // home properties | 449 | // home properties |
441 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | 450 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); |
442 | safeAddProp( home_adr, VCHomeProp ); | 451 | safeAddProp( home_adr, VCHomeProp ); |
443 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | 452 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); |
444 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | 453 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index ca9e410..1dc6b48 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -1,444 +1,453 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
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/01/13 15:49:31 eilers | ||
21 | * Fixing crash when businesscard.vcf is missing.. | ||
22 | * | ||
20 | * Revision 1.5 2002/12/07 13:26:22 eilers | 23 | * Revision 1.5 2002/12/07 13:26:22 eilers |
21 | * Fixing bug in storing anniversary.. | 24 | * Fixing bug in storing anniversary.. |
22 | * | 25 | * |
23 | * Revision 1.4 2002/11/13 14:14:51 eilers | 26 | * Revision 1.4 2002/11/13 14:14:51 eilers |
24 | * Added sorted for Contacts.. | 27 | * Added sorted for Contacts.. |
25 | * | 28 | * |
26 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 29 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
27 | * no default arguments in implementation | 30 | * no default arguments in implementation |
28 | * | 31 | * |
29 | * Revision 1.2 2002/11/10 15:41:53 eilers | 32 | * Revision 1.2 2002/11/10 15:41:53 eilers |
30 | * Bugfixes.. | 33 | * Bugfixes.. |
31 | * | 34 | * |
32 | * Revision 1.1 2002/11/09 14:34:52 eilers | 35 | * Revision 1.1 2002/11/09 14:34:52 eilers |
33 | * Added VCard Backend. | 36 | * Added VCard Backend. |
34 | * | 37 | * |
35 | */ | 38 | */ |
36 | #include "ocontactaccessbackend_vcard.h" | 39 | #include "ocontactaccessbackend_vcard.h" |
37 | #include "../../library/backend/vobject_p.h" | 40 | #include "../../library/backend/vobject_p.h" |
38 | #include "../../library/backend/qfiledirect_p.h" | 41 | #include "../../library/backend/qfiledirect_p.h" |
39 | 42 | ||
40 | #include <qpe/timeconversion.h> | 43 | #include <qpe/timeconversion.h> |
41 | 44 | ||
42 | #include <qfile.h> | 45 | #include <qfile.h> |
43 | 46 | ||
44 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 47 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
45 | m_dirty( false ), | 48 | m_dirty( false ), |
46 | m_file( filename ) | 49 | m_file( filename ) |
47 | { | 50 | { |
48 | load(); | 51 | load(); |
49 | } | 52 | } |
50 | 53 | ||
51 | 54 | ||
52 | bool OContactAccessBackend_VCard::load () | 55 | bool OContactAccessBackend_VCard::load () |
53 | { | 56 | { |
54 | m_map.clear(); | 57 | m_map.clear(); |
55 | m_dirty = false; | 58 | m_dirty = false; |
56 | 59 | ||
57 | VObject* obj = 0l; | 60 | VObject* obj = 0l; |
58 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | 61 | |
59 | if ( !obj ) | 62 | if ( QFile( m_file ).exists() ){ |
63 | obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); | ||
64 | if ( !obj ) | ||
65 | return false; | ||
66 | }else{ | ||
67 | qWarning("File \"%s\" not found !", m_file.latin1() ); | ||
60 | return false; | 68 | return false; |
69 | } | ||
61 | 70 | ||
62 | while ( obj ) { | 71 | while ( obj ) { |
63 | OContact con = parseVObject( obj ); | 72 | OContact con = parseVObject( obj ); |
64 | /* | 73 | /* |
65 | * if uid is 0 assign a new one | 74 | * if uid is 0 assign a new one |
66 | * this at least happens on | 75 | * this at least happens on |
67 | * Nokia6210 | 76 | * Nokia6210 |
68 | */ | 77 | */ |
69 | if ( con.uid() == 0 ){ | 78 | if ( con.uid() == 0 ){ |
70 | con.setUid( 1 ); | 79 | con.setUid( 1 ); |
71 | qWarning("assigned new uid %d",con.uid() ); | 80 | qWarning("assigned new uid %d",con.uid() ); |
72 | } | 81 | } |
73 | 82 | ||
74 | m_map.insert( con.uid(), con ); | 83 | m_map.insert( con.uid(), con ); |
75 | 84 | ||
76 | VObject *t = obj; | 85 | VObject *t = obj; |
77 | obj = nextVObjectInList(obj); | 86 | obj = nextVObjectInList(obj); |
78 | cleanVObject( t ); | 87 | cleanVObject( t ); |
79 | } | 88 | } |
80 | 89 | ||
81 | return true; | 90 | return true; |
82 | 91 | ||
83 | } | 92 | } |
84 | bool OContactAccessBackend_VCard::reload() | 93 | bool OContactAccessBackend_VCard::reload() |
85 | { | 94 | { |
86 | return load(); | 95 | return load(); |
87 | } | 96 | } |
88 | bool OContactAccessBackend_VCard::save() | 97 | bool OContactAccessBackend_VCard::save() |
89 | { | 98 | { |
90 | if (!m_dirty ) | 99 | if (!m_dirty ) |
91 | return true; | 100 | return true; |
92 | 101 | ||
93 | QFileDirect file( m_file ); | 102 | QFileDirect file( m_file ); |
94 | if (!file.open(IO_WriteOnly ) ) | 103 | if (!file.open(IO_WriteOnly ) ) |
95 | return false; | 104 | return false; |
96 | 105 | ||
97 | VObject *obj; | 106 | VObject *obj; |
98 | obj = newVObject( VCCalProp ); | 107 | obj = newVObject( VCCalProp ); |
99 | addPropValue( obj, VCVersionProp, "1.0" ); | 108 | addPropValue( obj, VCVersionProp, "1.0" ); |
100 | 109 | ||
101 | VObject *vo; | 110 | VObject *vo; |
102 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 111 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
103 | vo = createVObject( *it ); | 112 | vo = createVObject( *it ); |
104 | writeVObject( file.directHandle() , vo ); | 113 | writeVObject( file.directHandle() , vo ); |
105 | cleanVObject( vo ); | 114 | cleanVObject( vo ); |
106 | } | 115 | } |
107 | cleanStrTbl(); | 116 | cleanStrTbl(); |
108 | 117 | ||
109 | m_dirty = false; | 118 | m_dirty = false; |
110 | return true; | 119 | return true; |
111 | 120 | ||
112 | 121 | ||
113 | } | 122 | } |
114 | void OContactAccessBackend_VCard::clear () | 123 | void OContactAccessBackend_VCard::clear () |
115 | { | 124 | { |
116 | m_map.clear(); | 125 | m_map.clear(); |
117 | m_dirty = true; // ??? sure ? (se) | 126 | m_dirty = true; // ??? sure ? (se) |
118 | } | 127 | } |
119 | 128 | ||
120 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 129 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
121 | { | 130 | { |
122 | m_map.insert( newcontact.uid(), newcontact ); | 131 | m_map.insert( newcontact.uid(), newcontact ); |
123 | m_dirty = true; | 132 | m_dirty = true; |
124 | return true; | 133 | return true; |
125 | } | 134 | } |
126 | 135 | ||
127 | bool OContactAccessBackend_VCard::remove ( int uid ) | 136 | bool OContactAccessBackend_VCard::remove ( int uid ) |
128 | { | 137 | { |
129 | m_map.remove( uid ); | 138 | m_map.remove( uid ); |
130 | m_dirty = true; | 139 | m_dirty = true; |
131 | return true; | 140 | return true; |
132 | } | 141 | } |
133 | 142 | ||
134 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 143 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |
135 | { | 144 | { |
136 | m_map.replace( contact.uid(), contact ); | 145 | m_map.replace( contact.uid(), contact ); |
137 | m_dirty = true; | 146 | m_dirty = true; |
138 | return true; | 147 | return true; |
139 | } | 148 | } |
140 | 149 | ||
141 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 150 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
142 | { | 151 | { |
143 | return m_map[uid]; | 152 | return m_map[uid]; |
144 | } | 153 | } |
145 | 154 | ||
146 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 155 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
147 | { | 156 | { |
148 | QArray<int> ar( m_map.count() ); | 157 | QArray<int> ar( m_map.count() ); |
149 | QMap<int, OContact>::ConstIterator it; | 158 | QMap<int, OContact>::ConstIterator it; |
150 | int i = 0; | 159 | int i = 0; |
151 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { | 160 | for ( it = m_map.begin(); it != m_map.end(); ++it ) { |
152 | ar[i] = it.key(); | 161 | ar[i] = it.key(); |
153 | i++; | 162 | i++; |
154 | } | 163 | } |
155 | return ar; | 164 | return ar; |
156 | } | 165 | } |
157 | 166 | ||
158 | // Not implemented | 167 | // Not implemented |
159 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) | 168 | QArray<int> OContactAccessBackend_VCard::queryByExample ( const OContact&, int ) |
160 | { | 169 | { |
161 | QArray<int> ar(0); | 170 | QArray<int> ar(0); |
162 | return ar; | 171 | return ar; |
163 | } | 172 | } |
164 | 173 | ||
165 | // Not implemented | 174 | // Not implemented |
166 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const | 175 | QArray<int> OContactAccessBackend_VCard::matchRegexp( const QRegExp& ) const |
167 | { | 176 | { |
168 | QArray<int> ar(0); | 177 | QArray<int> ar(0); |
169 | return ar; | 178 | return ar; |
170 | } | 179 | } |
171 | 180 | ||
172 | const uint OContactAccessBackend_VCard::querySettings() | 181 | const uint OContactAccessBackend_VCard::querySettings() |
173 | { | 182 | { |
174 | return 0; // No search possible | 183 | return 0; // No search possible |
175 | } | 184 | } |
176 | 185 | ||
177 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const | 186 | bool OContactAccessBackend_VCard::hasQuerySettings (uint ) const |
178 | { | 187 | { |
179 | return false; // No search possible, therefore all settings invalid ;) | 188 | return false; // No search possible, therefore all settings invalid ;) |
180 | } | 189 | } |
181 | 190 | ||
182 | bool OContactAccessBackend_VCard::wasChangedExternally() | 191 | bool OContactAccessBackend_VCard::wasChangedExternally() |
183 | { | 192 | { |
184 | return false; // Don't expect concurrent access | 193 | return false; // Don't expect concurrent access |
185 | } | 194 | } |
186 | 195 | ||
187 | // Not implemented | 196 | // Not implemented |
188 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) | 197 | QArray<int> OContactAccessBackend_VCard::sorted( bool , int, int, int ) |
189 | { | 198 | { |
190 | QArray<int> ar(0); | 199 | QArray<int> ar(0); |
191 | return ar; | 200 | return ar; |
192 | } | 201 | } |
193 | 202 | ||
194 | // *** Private stuff *** | 203 | // *** Private stuff *** |
195 | 204 | ||
196 | 205 | ||
197 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) | 206 | OContact OContactAccessBackend_VCard::parseVObject( VObject *obj ) |
198 | { | 207 | { |
199 | OContact c; | 208 | OContact c; |
200 | 209 | ||
201 | VObjectIterator it; | 210 | VObjectIterator it; |
202 | initPropIterator( &it, obj ); | 211 | initPropIterator( &it, obj ); |
203 | while( moreIteration( &it ) ) { | 212 | while( moreIteration( &it ) ) { |
204 | VObject *o = nextVObject( &it ); | 213 | VObject *o = nextVObject( &it ); |
205 | QCString name = vObjectName( o ); | 214 | QCString name = vObjectName( o ); |
206 | QCString value = vObjectStringZValue( o ); | 215 | QCString value = vObjectStringZValue( o ); |
207 | if ( name == VCNameProp ) { | 216 | if ( name == VCNameProp ) { |
208 | VObjectIterator nit; | 217 | VObjectIterator nit; |
209 | initPropIterator( &nit, o ); | 218 | initPropIterator( &nit, o ); |
210 | while( moreIteration( &nit ) ) { | 219 | while( moreIteration( &nit ) ) { |
211 | VObject *o = nextVObject( &nit ); | 220 | VObject *o = nextVObject( &nit ); |
212 | QCString name = vObjectTypeInfo( o ); | 221 | QCString name = vObjectTypeInfo( o ); |
213 | QString value = vObjectStringZValue( o ); | 222 | QString value = vObjectStringZValue( o ); |
214 | if ( name == VCNamePrefixesProp ) | 223 | if ( name == VCNamePrefixesProp ) |
215 | c.setTitle( value ); | 224 | c.setTitle( value ); |
216 | else if ( name == VCNameSuffixesProp ) | 225 | else if ( name == VCNameSuffixesProp ) |
217 | c.setSuffix( value ); | 226 | c.setSuffix( value ); |
218 | else if ( name == VCFamilyNameProp ) | 227 | else if ( name == VCFamilyNameProp ) |
219 | c.setLastName( value ); | 228 | c.setLastName( value ); |
220 | else if ( name == VCGivenNameProp ) | 229 | else if ( name == VCGivenNameProp ) |
221 | c.setFirstName( value ); | 230 | c.setFirstName( value ); |
222 | else if ( name == VCAdditionalNamesProp ) | 231 | else if ( name == VCAdditionalNamesProp ) |
223 | c.setMiddleName( value ); | 232 | c.setMiddleName( value ); |
224 | } | 233 | } |
225 | } | 234 | } |
226 | else if ( name == VCAdrProp ) { | 235 | else if ( name == VCAdrProp ) { |
227 | bool work = TRUE; // default address is work address | 236 | bool work = TRUE; // default address is work address |
228 | QString street; | 237 | QString street; |
229 | QString city; | 238 | QString city; |
230 | QString region; | 239 | QString region; |
231 | QString postal; | 240 | QString postal; |
232 | QString country; | 241 | QString country; |
233 | 242 | ||
234 | VObjectIterator nit; | 243 | VObjectIterator nit; |
235 | initPropIterator( &nit, o ); | 244 | initPropIterator( &nit, o ); |
236 | while( moreIteration( &nit ) ) { | 245 | while( moreIteration( &nit ) ) { |
237 | VObject *o = nextVObject( &nit ); | 246 | VObject *o = nextVObject( &nit ); |
238 | QCString name = vObjectName( o ); | 247 | QCString name = vObjectName( o ); |
239 | QString value = vObjectStringZValue( o ); | 248 | QString value = vObjectStringZValue( o ); |
240 | if ( name == VCHomeProp ) | 249 | if ( name == VCHomeProp ) |
241 | work = FALSE; | 250 | work = FALSE; |
242 | else if ( name == VCWorkProp ) | 251 | else if ( name == VCWorkProp ) |
243 | work = TRUE; | 252 | work = TRUE; |
244 | else if ( name == VCStreetAddressProp ) | 253 | else if ( name == VCStreetAddressProp ) |
245 | street = value; | 254 | street = value; |
246 | else if ( name == VCCityProp ) | 255 | else if ( name == VCCityProp ) |
247 | city = value; | 256 | city = value; |
248 | else if ( name == VCRegionProp ) | 257 | else if ( name == VCRegionProp ) |
249 | region = value; | 258 | region = value; |
250 | else if ( name == VCPostalCodeProp ) | 259 | else if ( name == VCPostalCodeProp ) |
251 | postal = value; | 260 | postal = value; |
252 | else if ( name == VCCountryNameProp ) | 261 | else if ( name == VCCountryNameProp ) |
253 | country = value; | 262 | country = value; |
254 | } | 263 | } |
255 | if ( work ) { | 264 | if ( work ) { |
256 | c.setBusinessStreet( street ); | 265 | c.setBusinessStreet( street ); |
257 | c.setBusinessCity( city ); | 266 | c.setBusinessCity( city ); |
258 | c.setBusinessCountry( country ); | 267 | c.setBusinessCountry( country ); |
259 | c.setBusinessZip( postal ); | 268 | c.setBusinessZip( postal ); |
260 | c.setBusinessState( region ); | 269 | c.setBusinessState( region ); |
261 | } else { | 270 | } else { |
262 | c.setHomeStreet( street ); | 271 | c.setHomeStreet( street ); |
263 | c.setHomeCity( city ); | 272 | c.setHomeCity( city ); |
264 | c.setHomeCountry( country ); | 273 | c.setHomeCountry( country ); |
265 | c.setHomeZip( postal ); | 274 | c.setHomeZip( postal ); |
266 | c.setHomeState( region ); | 275 | c.setHomeState( region ); |
267 | } | 276 | } |
268 | } | 277 | } |
269 | else if ( name == VCTelephoneProp ) { | 278 | else if ( name == VCTelephoneProp ) { |
270 | enum { | 279 | enum { |
271 | HOME = 0x01, | 280 | HOME = 0x01, |
272 | WORK = 0x02, | 281 | WORK = 0x02, |
273 | VOICE = 0x04, | 282 | VOICE = 0x04, |
274 | CELL = 0x08, | 283 | CELL = 0x08, |
275 | FAX = 0x10, | 284 | FAX = 0x10, |
276 | PAGER = 0x20, | 285 | PAGER = 0x20, |
277 | UNKNOWN = 0x80 | 286 | UNKNOWN = 0x80 |
278 | }; | 287 | }; |
279 | int type = 0; | 288 | int type = 0; |
280 | 289 | ||
281 | VObjectIterator nit; | 290 | VObjectIterator nit; |
282 | initPropIterator( &nit, o ); | 291 | initPropIterator( &nit, o ); |
283 | while( moreIteration( &nit ) ) { | 292 | while( moreIteration( &nit ) ) { |
284 | VObject *o = nextVObject( &nit ); | 293 | VObject *o = nextVObject( &nit ); |
285 | QCString name = vObjectTypeInfo( o ); | 294 | QCString name = vObjectTypeInfo( o ); |
286 | if ( name == VCHomeProp ) | 295 | if ( name == VCHomeProp ) |
287 | type |= HOME; | 296 | type |= HOME; |
288 | else if ( name == VCWorkProp ) | 297 | else if ( name == VCWorkProp ) |
289 | type |= WORK; | 298 | type |= WORK; |
290 | else if ( name == VCVoiceProp ) | 299 | else if ( name == VCVoiceProp ) |
291 | type |= VOICE; | 300 | type |= VOICE; |
292 | else if ( name == VCCellularProp ) | 301 | else if ( name == VCCellularProp ) |
293 | type |= CELL; | 302 | type |= CELL; |
294 | else if ( name == VCFaxProp ) | 303 | else if ( name == VCFaxProp ) |
295 | type |= FAX; | 304 | type |= FAX; |
296 | else if ( name == VCPagerProp ) | 305 | else if ( name == VCPagerProp ) |
297 | type |= PAGER; | 306 | type |= PAGER; |
298 | else if ( name == VCPreferredProp ) | 307 | else if ( name == VCPreferredProp ) |
299 | ; | 308 | ; |
300 | else | 309 | else |
301 | type |= UNKNOWN; | 310 | type |= UNKNOWN; |
302 | } | 311 | } |
303 | if ( (type & UNKNOWN) != UNKNOWN ) { | 312 | if ( (type & UNKNOWN) != UNKNOWN ) { |
304 | if ( ( type & (HOME|WORK) ) == 0 ) // default | 313 | if ( ( type & (HOME|WORK) ) == 0 ) // default |
305 | type |= HOME; | 314 | type |= HOME; |
306 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | 315 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default |
307 | type |= VOICE; | 316 | type |= VOICE; |
308 | 317 | ||
309 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) | 318 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) |
310 | c.setHomePhone( value ); | 319 | c.setHomePhone( value ); |
311 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | 320 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) |
312 | c.setHomeFax( value ); | 321 | c.setHomeFax( value ); |
313 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | 322 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) |
314 | c.setHomeMobile( value ); | 323 | c.setHomeMobile( value ); |
315 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) | 324 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) |
316 | c.setBusinessPhone( value ); | 325 | c.setBusinessPhone( value ); |
317 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) | 326 | if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) |
318 | c.setBusinessFax( value ); | 327 | c.setBusinessFax( value ); |
319 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) | 328 | if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) |
320 | c.setBusinessMobile( value ); | 329 | c.setBusinessMobile( value ); |
321 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) | 330 | if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) |
322 | c.setBusinessPager( value ); | 331 | c.setBusinessPager( value ); |
323 | } | 332 | } |
324 | } | 333 | } |
325 | else if ( name == VCEmailAddressProp ) { | 334 | else if ( name == VCEmailAddressProp ) { |
326 | QString email = vObjectStringZValue( o ); | 335 | QString email = vObjectStringZValue( o ); |
327 | bool valid = TRUE; | 336 | bool valid = TRUE; |
328 | VObjectIterator nit; | 337 | VObjectIterator nit; |
329 | initPropIterator( &nit, o ); | 338 | initPropIterator( &nit, o ); |
330 | while( moreIteration( &nit ) ) { | 339 | while( moreIteration( &nit ) ) { |
331 | VObject *o = nextVObject( &nit ); | 340 | VObject *o = nextVObject( &nit ); |
332 | QCString name = vObjectTypeInfo( o ); | 341 | QCString name = vObjectTypeInfo( o ); |
333 | if ( name != VCInternetProp && name != VCHomeProp && | 342 | if ( name != VCInternetProp && name != VCHomeProp && |
334 | name != VCWorkProp && | 343 | name != VCWorkProp && |
335 | name != VCPreferredProp ) | 344 | name != VCPreferredProp ) |
336 | // ### preffered should map to default email | 345 | // ### preffered should map to default email |
337 | valid = FALSE; | 346 | valid = FALSE; |
338 | } | 347 | } |
339 | if ( valid ) { | 348 | if ( valid ) { |
340 | c.insertEmail( email ); | 349 | c.insertEmail( email ); |
341 | } | 350 | } |
342 | } | 351 | } |
343 | else if ( name == VCURLProp ) { | 352 | else if ( name == VCURLProp ) { |
344 | VObjectIterator nit; | 353 | VObjectIterator nit; |
345 | initPropIterator( &nit, o ); | 354 | initPropIterator( &nit, o ); |
346 | while( moreIteration( &nit ) ) { | 355 | while( moreIteration( &nit ) ) { |
347 | VObject *o = nextVObject( &nit ); | 356 | VObject *o = nextVObject( &nit ); |
348 | QCString name = vObjectTypeInfo( o ); | 357 | QCString name = vObjectTypeInfo( o ); |
349 | if ( name == VCHomeProp ) | 358 | if ( name == VCHomeProp ) |
350 | c.setHomeWebpage( value ); | 359 | c.setHomeWebpage( value ); |
351 | else if ( name == VCWorkProp ) | 360 | else if ( name == VCWorkProp ) |
352 | c.setBusinessWebpage( value ); | 361 | c.setBusinessWebpage( value ); |
353 | } | 362 | } |
354 | } | 363 | } |
355 | else if ( name == VCOrgProp ) { | 364 | else if ( name == VCOrgProp ) { |
356 | VObjectIterator nit; | 365 | VObjectIterator nit; |
357 | initPropIterator( &nit, o ); | 366 | initPropIterator( &nit, o ); |
358 | while( moreIteration( &nit ) ) { | 367 | while( moreIteration( &nit ) ) { |
359 | VObject *o = nextVObject( &nit ); | 368 | VObject *o = nextVObject( &nit ); |
360 | QCString name = vObjectName( o ); | 369 | QCString name = vObjectName( o ); |
361 | QString value = vObjectStringZValue( o ); | 370 | QString value = vObjectStringZValue( o ); |
362 | if ( name == VCOrgNameProp ) | 371 | if ( name == VCOrgNameProp ) |
363 | c.setCompany( value ); | 372 | c.setCompany( value ); |
364 | else if ( name == VCOrgUnitProp ) | 373 | else if ( name == VCOrgUnitProp ) |
365 | c.setDepartment( value ); | 374 | c.setDepartment( value ); |
366 | else if ( name == VCOrgUnit2Prop ) | 375 | else if ( name == VCOrgUnit2Prop ) |
367 | c.setOffice( value ); | 376 | c.setOffice( value ); |
368 | } | 377 | } |
369 | } | 378 | } |
370 | else if ( name == VCTitleProp ) { | 379 | else if ( name == VCTitleProp ) { |
371 | c.setJobTitle( value ); | 380 | c.setJobTitle( value ); |
372 | } | 381 | } |
373 | else if ( name == "X-Qtopia-Profession" ) { | 382 | else if ( name == "X-Qtopia-Profession" ) { |
374 | c.setProfession( value ); | 383 | c.setProfession( value ); |
375 | } | 384 | } |
376 | else if ( name == "X-Qtopia-Manager" ) { | 385 | else if ( name == "X-Qtopia-Manager" ) { |
377 | c.setManager( value ); | 386 | c.setManager( value ); |
378 | } | 387 | } |
379 | else if ( name == "X-Qtopia-Assistant" ) { | 388 | else if ( name == "X-Qtopia-Assistant" ) { |
380 | c.setAssistant( value ); | 389 | c.setAssistant( value ); |
381 | } | 390 | } |
382 | else if ( name == "X-Qtopia-Spouse" ) { | 391 | else if ( name == "X-Qtopia-Spouse" ) { |
383 | c.setSpouse( value ); | 392 | c.setSpouse( value ); |
384 | } | 393 | } |
385 | else if ( name == "X-Qtopia-Gender" ) { | 394 | else if ( name == "X-Qtopia-Gender" ) { |
386 | c.setGender( value ); | 395 | c.setGender( value ); |
387 | } | 396 | } |
388 | else if ( name == "X-Qtopia-Anniversary" ) { | 397 | else if ( name == "X-Qtopia-Anniversary" ) { |
389 | c.setAnniversary( convVCardDateToDate( value ) ); | 398 | c.setAnniversary( convVCardDateToDate( value ) ); |
390 | } | 399 | } |
391 | else if ( name == "X-Qtopia-Nickname" ) { | 400 | else if ( name == "X-Qtopia-Nickname" ) { |
392 | c.setNickname( value ); | 401 | c.setNickname( value ); |
393 | } | 402 | } |
394 | else if ( name == "X-Qtopia-Children" ) { | 403 | else if ( name == "X-Qtopia-Children" ) { |
395 | c.setChildren( value ); | 404 | c.setChildren( value ); |
396 | } | 405 | } |
397 | else if ( name == VCBirthDateProp ) { | 406 | else if ( name == VCBirthDateProp ) { |
398 | // Reading Birthdate regarding RFC 2425 (5.8.4) | 407 | // Reading Birthdate regarding RFC 2425 (5.8.4) |
399 | c.setBirthday( convVCardDateToDate( value ) ); | 408 | c.setBirthday( convVCardDateToDate( value ) ); |
400 | 409 | ||
401 | } | 410 | } |
402 | 411 | ||
403 | #if 0 | 412 | #if 0 |
404 | else { | 413 | else { |
405 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); | 414 | printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); |
406 | VObjectIterator nit; | 415 | VObjectIterator nit; |
407 | initPropIterator( &nit, o ); | 416 | initPropIterator( &nit, o ); |
408 | while( moreIteration( &nit ) ) { | 417 | while( moreIteration( &nit ) ) { |
409 | VObject *o = nextVObject( &nit ); | 418 | VObject *o = nextVObject( &nit ); |
410 | QCString name = vObjectName( o ); | 419 | QCString name = vObjectName( o ); |
411 | QString value = vObjectStringZValue( o ); | 420 | QString value = vObjectStringZValue( o ); |
412 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); | 421 | printf(" subprop: %s = %s\n", name.data(), value.latin1() ); |
413 | } | 422 | } |
414 | } | 423 | } |
415 | #endif | 424 | #endif |
416 | } | 425 | } |
417 | c.setFileAs(); | 426 | c.setFileAs(); |
418 | return c; | 427 | return c; |
419 | } | 428 | } |
420 | 429 | ||
421 | 430 | ||
422 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) | 431 | VObject* OContactAccessBackend_VCard::createVObject( const OContact &c ) |
423 | { | 432 | { |
424 | VObject *vcard = newVObject( VCCardProp ); | 433 | VObject *vcard = newVObject( VCCardProp ); |
425 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); | 434 | safeAddPropValue( vcard, VCVersionProp, "2.1" ); |
426 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); | 435 | safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); |
427 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); | 436 | safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); |
428 | 437 | ||
429 | // full name | 438 | // full name |
430 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); | 439 | safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); |
431 | 440 | ||
432 | // name properties | 441 | // name properties |
433 | VObject *name = safeAddProp( vcard, VCNameProp ); | 442 | VObject *name = safeAddProp( vcard, VCNameProp ); |
434 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); | 443 | safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); |
435 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); | 444 | safeAddPropValue( name, VCGivenNameProp, c.firstName() ); |
436 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); | 445 | safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); |
437 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); | 446 | safeAddPropValue( name, VCNamePrefixesProp, c.title() ); |
438 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); | 447 | safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); |
439 | 448 | ||
440 | // home properties | 449 | // home properties |
441 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); | 450 | VObject *home_adr= safeAddProp( vcard, VCAdrProp ); |
442 | safeAddProp( home_adr, VCHomeProp ); | 451 | safeAddProp( home_adr, VCHomeProp ); |
443 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); | 452 | safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); |
444 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); | 453 | safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); |