-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 36 | ||||
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | 7 |
2 files changed, 36 insertions, 7 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index 43e530a..5bb21c7 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -43,17 +43,19 @@ | |||
43 | #define protected public | 43 | #define protected public |
44 | #include <qfile.h> | 44 | #include <qfile.h> |
45 | #undef protected | 45 | #undef protected |
46 | 46 | ||
47 | namespace Opie { | 47 | namespace Opie { |
48 | 48 | ||
49 | OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): | 49 | OPimContactAccessBackend_VCard::OPimContactAccessBackend_VCard ( const QString& , const QString& filename ): |
50 | m_dirty( false ), | 50 | m_dirty( false ), |
51 | m_file( filename ) | 51 | m_file( filename ), |
52 | version_major( 1 ), | ||
53 | version_minor( 0 ) | ||
52 | { | 54 | { |
53 | load(); | 55 | load(); |
54 | } | 56 | } |
55 | 57 | ||
56 | 58 | ||
57 | bool OPimContactAccessBackend_VCard::load () | 59 | bool OPimContactAccessBackend_VCard::load () |
58 | { | 60 | { |
59 | m_map.clear(); | 61 | m_map.clear(); |
@@ -181,32 +183,40 @@ bool OPimContactAccessBackend_VCard::wasChangedExternally() | |||
181 | { | 183 | { |
182 | return false; // Don't expect concurrent access | 184 | return false; // Don't expect concurrent access |
183 | } | 185 | } |
184 | 186 | ||
185 | // *** Private stuff *** | 187 | // *** Private stuff *** |
186 | OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) | 188 | OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) |
187 | { | 189 | { |
188 | OPimContact c; | 190 | OPimContact c; |
189 | |||
190 | VObjectIterator it; | 191 | VObjectIterator it; |
191 | initPropIterator( &it, obj ); | 192 | initPropIterator( &it, obj ); |
192 | while( moreIteration( &it ) ) { | 193 | while( moreIteration( &it ) ) { |
193 | VObject *o = nextVObject( &it ); | 194 | VObject *o = nextVObject( &it ); |
194 | QCString name = vObjectName( o ); | 195 | QCString name = vObjectName( o ); |
195 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | 196 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); |
196 | odebug << "(1)Read: %s" << QString( value ).latin1() << oendl; | 197 | odebug << "(1)Read: " << name << " " << QString( value ).latin1() << oendl; |
197 | if ( name == VCNameProp ) { | 198 | if ( name == VCVersionProp ) { |
199 | |||
200 | odebug << "Version: " << value << oendl; | ||
201 | QStringList version = QStringList::split( ".", value ); | ||
202 | version_major = version[0].toUInt(); | ||
203 | version_minor = version[1].toUInt(); | ||
204 | odebug << "Major: "<< version_major << " Minor: " << version_minor << oendl; | ||
205 | |||
206 | } | ||
207 | else if ( name == VCNameProp ) { | ||
198 | VObjectIterator nit; | 208 | VObjectIterator nit; |
199 | initPropIterator( &nit, o ); | 209 | initPropIterator( &nit, o ); |
200 | while( moreIteration( &nit ) ) { | 210 | while( moreIteration( &nit ) ) { |
201 | VObject *o = nextVObject( &nit ); | 211 | VObject *o = nextVObject( &nit ); |
202 | QCString name = vObjectTypeInfo( o ); | 212 | QCString name = vObjectTypeInfo( o ); |
203 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | 213 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); |
204 | odebug << "(2)Read: %s" << value.latin1() << oendl; | 214 | odebug << "Nametype is: "<< name << " Value: " << value.latin1() << oendl; |
205 | if ( name == VCNamePrefixesProp ) | 215 | if ( name == VCNamePrefixesProp ) |
206 | c.setTitle( value ); | 216 | c.setTitle( value ); |
207 | else if ( name == VCNameSuffixesProp ) | 217 | else if ( name == VCNameSuffixesProp ) |
208 | c.setSuffix( value ); | 218 | c.setSuffix( value ); |
209 | else if ( name == VCFamilyNameProp ) | 219 | else if ( name == VCFamilyNameProp ) |
210 | c.setLastName( value ); | 220 | c.setLastName( value ); |
211 | else if ( name == VCGivenNameProp ) | 221 | else if ( name == VCGivenNameProp ) |
212 | c.setFirstName( value ); | 222 | c.setFirstName( value ); |
@@ -221,18 +231,19 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
221 | QString region; | 231 | QString region; |
222 | QString postal; | 232 | QString postal; |
223 | QString country; | 233 | QString country; |
224 | 234 | ||
225 | VObjectIterator nit; | 235 | VObjectIterator nit; |
226 | initPropIterator( &nit, o ); | 236 | initPropIterator( &nit, o ); |
227 | while( moreIteration( &nit ) ) { | 237 | while( moreIteration( &nit ) ) { |
228 | VObject *o = nextVObject( &nit ); | 238 | VObject *o = nextVObject( &nit ); |
229 | QCString name = vObjectName( o ); | 239 | QCString name = vObjectTypeInfo( o ); |
230 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); | 240 | QString value = QString::fromUtf8( vObjectStringZValue( o ) ); |
241 | odebug << "AddressType is: "<< name << " Value: " << value.latin1() << oendl; | ||
231 | if ( name == VCHomeProp ) | 242 | if ( name == VCHomeProp ) |
232 | work = FALSE; | 243 | work = FALSE; |
233 | else if ( name == VCWorkProp ) | 244 | else if ( name == VCWorkProp ) |
234 | work = TRUE; | 245 | work = TRUE; |
235 | else if ( name == VCStreetAddressProp ) | 246 | else if ( name == VCStreetAddressProp ) |
236 | street = value; | 247 | street = value; |
237 | else if ( name == VCCityProp ) | 248 | else if ( name == VCCityProp ) |
238 | city = value; | 249 | city = value; |
@@ -269,39 +280,44 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
269 | }; | 280 | }; |
270 | int type = 0; | 281 | int type = 0; |
271 | 282 | ||
272 | VObjectIterator nit; | 283 | VObjectIterator nit; |
273 | initPropIterator( &nit, o ); | 284 | initPropIterator( &nit, o ); |
274 | while( moreIteration( &nit ) ) { | 285 | while( moreIteration( &nit ) ) { |
275 | VObject *o = nextVObject( &nit ); | 286 | VObject *o = nextVObject( &nit ); |
276 | QCString name = vObjectTypeInfo( o ); | 287 | QCString name = vObjectTypeInfo( o ); |
288 | odebug << "Telephonetype is: "<< name << " Value: " << value.latin1() << oendl; | ||
277 | if ( name == VCHomeProp ) | 289 | if ( name == VCHomeProp ) |
278 | type |= HOME; | 290 | type |= HOME; |
279 | else if ( name == VCWorkProp ) | 291 | else if ( name == VCWorkProp ) |
280 | type |= WORK; | 292 | type |= WORK; |
281 | else if ( name == VCVoiceProp ) | 293 | else if ( name == VCVoiceProp ) |
282 | type |= VOICE; | 294 | type |= VOICE; |
283 | else if ( name == VCCellularProp ) | 295 | else if ( name == VCCellularProp ) |
284 | type |= CELL; | 296 | type |= CELL; |
285 | else if ( name == VCFaxProp ) | 297 | else if ( name == VCFaxProp ) |
286 | type |= FAX; | 298 | type |= FAX; |
287 | else if ( name == VCPagerProp ) | 299 | else if ( name == VCPagerProp ) |
288 | type |= PAGER; | 300 | type |= PAGER; |
289 | else if ( name == VCPreferredProp ) | 301 | else if ( name == VCPreferredProp ) |
290 | ; | 302 | ; |
303 | else if ( name.left( 2 ) == "X-" || name.left( 2 ) == "x-" ) | ||
304 | ; // Ignore | ||
291 | else | 305 | else |
292 | type |= UNKNOWN; | 306 | type |= UNKNOWN; |
293 | } | 307 | } |
294 | if ( (type & UNKNOWN) != UNKNOWN ) { | 308 | if ( (type & UNKNOWN) != UNKNOWN ) { |
295 | if ( ( type & (HOME|WORK) ) == 0 ) // default | 309 | if ( ( type & (HOME|WORK) ) == 0 ) // default |
296 | type |= HOME; | 310 | type |= HOME; |
297 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default | 311 | if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default |
298 | type |= VOICE; | 312 | type |= VOICE; |
299 | 313 | ||
314 | odebug << "value %s %d" << value.data() << type << oendl; | ||
315 | |||
300 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) | 316 | if ( (type & (VOICE|HOME) ) == (VOICE|HOME) && (type & (CELL|HOME) ) != (CELL|HOME) ) |
301 | c.setHomePhone( value ); | 317 | c.setHomePhone( value ); |
302 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) | 318 | if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) |
303 | c.setHomeFax( value ); | 319 | c.setHomeFax( value ); |
304 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) | 320 | if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) |
305 | c.setHomeMobile( value ); | 321 | c.setHomeMobile( value ); |
306 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) | 322 | if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) && (type & (CELL|WORK) ) != (CELL|WORK) ) |
307 | c.setBusinessPhone( value ); | 323 | c.setBusinessPhone( value ); |
@@ -316,21 +332,25 @@ OPimContact OPimContactAccessBackend_VCard::parseVObject( VObject *obj ) | |||
316 | else if ( name == VCEmailAddressProp ) { | 332 | else if ( name == VCEmailAddressProp ) { |
317 | QString email = QString::fromUtf8( vObjectStringZValue( o ) ); | 333 | QString email = QString::fromUtf8( vObjectStringZValue( o ) ); |
318 | bool valid = TRUE; | 334 | bool valid = TRUE; |
319 | VObjectIterator nit; | 335 | VObjectIterator nit; |
320 | initPropIterator( &nit, o ); | 336 | initPropIterator( &nit, o ); |
321 | while( moreIteration( &nit ) ) { | 337 | while( moreIteration( &nit ) ) { |
322 | VObject *o = nextVObject( &nit ); | 338 | VObject *o = nextVObject( &nit ); |
323 | QCString name = vObjectTypeInfo( o ); | 339 | QCString name = vObjectTypeInfo( o ); |
340 | odebug << "Emailtype is: "<< name << " Value: " << value.latin1() << oendl; | ||
324 | if ( name != VCInternetProp && name != VCHomeProp && | 341 | if ( name != VCInternetProp && name != VCHomeProp && |
325 | name != VCWorkProp && | 342 | name != VCWorkProp && |
326 | name != VCPreferredProp ) | 343 | name != VCPreferredProp && |
344 | name.left( 2 ) != "X-" && name.left( 2 ) != "x-" ){ | ||
327 | // ### preffered should map to default email | 345 | // ### preffered should map to default email |
328 | valid = FALSE; | 346 | valid = FALSE; |
347 | odebug << "Email was detected as invalid!" << oendl; | ||
348 | } | ||
329 | } | 349 | } |
330 | if ( valid ) { | 350 | if ( valid ) { |
331 | c.insertEmail( email ); | 351 | c.insertEmail( email ); |
332 | } | 352 | } |
333 | } | 353 | } |
334 | else if ( name == VCURLProp ) { | 354 | else if ( name == VCURLProp ) { |
335 | VObjectIterator nit; | 355 | VObjectIterator nit; |
336 | initPropIterator( &nit, o ); | 356 | initPropIterator( &nit, o ); |
@@ -577,9 +597,11 @@ VObject* OPimContactAccessBackend_VCard::safeAddPropValue( VObject *o, const cha | |||
577 | VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) | 597 | VObject* OPimContactAccessBackend_VCard::safeAddProp( VObject *o, const char *prop) |
578 | { | 598 | { |
579 | VObject *ret = 0; | 599 | VObject *ret = 0; |
580 | if ( o ) | 600 | if ( o ) |
581 | ret = addProp( o, prop ); | 601 | ret = addProp( o, prop ); |
582 | return ret; | 602 | return ret; |
583 | } | 603 | } |
584 | 604 | ||
605 | |||
606 | |||
585 | } | 607 | } |
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h index 1faf747..b734530 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.h | |||
@@ -70,13 +70,20 @@ private: | |||
70 | QString convDateToVCardDate( const QDate& c ) const; | 70 | QString convDateToVCardDate( const QDate& c ) const; |
71 | QDate convVCardDateToDate( const QString& datestr ); | 71 | QDate convVCardDateToDate( const QString& datestr ); |
72 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); | 72 | VObject *safeAddPropValue( VObject *o, const char* prop, const QString& value ); |
73 | VObject *safeAddProp( VObject* o, const char* prop); | 73 | VObject *safeAddProp( VObject* o, const char* prop); |
74 | 74 | ||
75 | bool m_dirty : 1; | 75 | bool m_dirty : 1; |
76 | QString m_file; | 76 | QString m_file; |
77 | QMap<int, OPimContact> m_map; | 77 | QMap<int, OPimContact> m_map; |
78 | |||
79 | /** | ||
80 | * Version of parsed VCard | ||
81 | */ | ||
82 | uint version_major; | ||
83 | uint version_minor; | ||
84 | |||
78 | }; | 85 | }; |
79 | 86 | ||
80 | } | 87 | } |
81 | 88 | ||
82 | #endif | 89 | #endif |