author | zautrix <zautrix> | 2004-10-30 00:27:02 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-30 00:27:02 (UTC) |
commit | af857a738da80e9eb68cf311832d44ecb9caf1dd (patch) (unidiff) | |
tree | 7e45bdfeb5d2f70f8125f5fed20c28366de91c9a /kabc/plugins | |
parent | 84afedde379f67982d96dc9efa7abf9d200734e4 (diff) | |
download | kdepimpi-af857a738da80e9eb68cf311832d44ecb9caf1dd.zip kdepimpi-af857a738da80e9eb68cf311832d44ecb9caf1dd.tar.gz kdepimpi-af857a738da80e9eb68cf311832d44ecb9caf1dd.tar.bz2 |
fixed DTM sync cat handling
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 110 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.h | 1 |
3 files changed, 77 insertions, 36 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 7069f5d..6413b42 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -201,6 +201,7 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
201 | if (res == true) | 201 | if (res == true) |
202 | { | 202 | { |
203 | res = mAccess->finishEditCard(&id);; | 203 | res = mAccess->finishEditCard(&id);; |
204 | mConverter->setCategories( (*it), mAccess, id ); | ||
204 | map.insert(id,(*it).uid()); | 205 | map.insert(id,(*it).uid()); |
205 | if (res == false) | 206 | if (res == false) |
206 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 207 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
@@ -228,6 +229,7 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
228 | if (res == true) | 229 | if (res == true) |
229 | { | 230 | { |
230 | res = mAccess->finishEditCard(&id); | 231 | res = mAccess->finishEditCard(&id); |
232 | mConverter->setCategories( (*it), mAccess, id ); | ||
231 | map.insert(id,(*it).uid()); | 233 | map.insert(id,(*it).uid()); |
232 | if (res == false) | 234 | if (res == false) |
233 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 235 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp index 396be0a..ae4cfbb 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp | |||
@@ -307,59 +307,43 @@ bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* da | |||
307 | database->writeField(ZdbAdrs::Emails, emails ); | 307 | database->writeField(ZdbAdrs::Emails, emails ); |
308 | 308 | ||
309 | database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); | 309 | database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); |
310 | |||
311 | |||
312 | // home | 310 | // home |
313 | const Address homeaddress = addr.address(Address::Home); | 311 | const Address homeaddress = addr.address(Address::Home); |
314 | if (!homeaddress.isEmpty()) { | ||
315 | //qDebug("write home address "); | ||
316 | database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); | 312 | database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); |
317 | database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); | 313 | database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); |
318 | database->writeField(ZdbAdrs::HomeState, homeaddress.region()); | 314 | database->writeField(ZdbAdrs::HomeState, homeaddress.region()); |
319 | database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); | 315 | database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); |
320 | database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); | 316 | database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); |
321 | } | ||
322 | 317 | ||
323 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 318 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
324 | if (!homephone.number().isEmpty()) | ||
325 | database->writeField(ZdbAdrs::HomePhone, homephone.number()); | 319 | database->writeField(ZdbAdrs::HomePhone, homephone.number()); |
326 | |||
327 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 320 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
328 | if (!homefax.number().isEmpty()) | ||
329 | database->writeField(ZdbAdrs::HomeFax, homefax.number()); | 321 | database->writeField(ZdbAdrs::HomeFax, homefax.number()); |
330 | |||
331 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 322 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
332 | if (!homemobile.number().isEmpty()) { | ||
333 | database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); | 323 | database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); |
324 | if (!homemobile.number().isEmpty()) { | ||
334 | cellHome = true; | 325 | cellHome = true; |
335 | } | 326 | } |
336 | |||
337 | database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); | 327 | database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); |
338 | |||
339 | |||
340 | // business | 328 | // business |
341 | const Address businessaddress = addr.address(Address::Work); | 329 | const Address businessaddress = addr.address(Address::Work); |
342 | if (!businessaddress.isEmpty()) { | ||
343 | //qDebug("write business address "); | 330 | //qDebug("write business address "); |
344 | database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); | 331 | database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); |
345 | database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); | 332 | database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); |
346 | database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); | 333 | database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); |
347 | database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); | 334 | database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); |
348 | database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); | 335 | database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); |
349 | } | ||
350 | 336 | ||
351 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 337 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
352 | if (!businessphone.number().isEmpty()) | ||
353 | database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); | 338 | database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); |
354 | 339 | ||
355 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 340 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
356 | if (!businessfax.number().isEmpty()) | ||
357 | database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); | 341 | database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); |
358 | 342 | ||
359 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 343 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
344 | database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); | ||
360 | if (!businessmobile.number().isEmpty()) { | 345 | if (!businessmobile.number().isEmpty()) { |
361 | cellWork = true; | 346 | cellWork = true; |
362 | database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); | ||
363 | } | 347 | } |
364 | PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); | 348 | PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); |
365 | if (! mobile.number().isEmpty()) { | 349 | if (! mobile.number().isEmpty()) { |
@@ -370,7 +354,6 @@ bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* da | |||
370 | } | 354 | } |
371 | 355 | ||
372 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 356 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
373 | if (!businesspager.number().isEmpty()) | ||
374 | database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); | 357 | database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); |
375 | 358 | ||
376 | database->writeField(ZdbAdrs::JobTitle, addr.role()); | 359 | database->writeField(ZdbAdrs::JobTitle, addr.role()); |
@@ -396,19 +379,19 @@ bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* da | |||
396 | else | 379 | else |
397 | database->writeField(ZdbAdrs::Gender, ""); | 380 | database->writeField(ZdbAdrs::Gender, ""); |
398 | 381 | ||
399 | 382 | QString dateS ; | |
400 | QDate dt = KGlobal::locale()->readDate( | 383 | QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
401 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | ||
402 | if ( dt.isValid() ) { | 384 | if ( dt.isValid() ) { |
403 | QString dateS = KGlobal::locale()->formatDate(dt, true ); | 385 | dateS = KGlobal::locale()->formatDate(dt, true ); |
404 | database->writeField(ZdbAdrs::Anniversary, dateS ); | ||
405 | } | 386 | } |
387 | database->writeField(ZdbAdrs::Anniversary, dateS ); | ||
406 | database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); | 388 | database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); |
407 | dt = addr.birthday().date(); | 389 | dt = addr.birthday().date(); |
390 | dateS = ""; | ||
408 | if ( dt.isValid() ) { | 391 | if ( dt.isValid() ) { |
409 | QString dateS = KGlobal::locale()->formatDate(dt, true ); | 392 | dateS = KGlobal::locale()->formatDate(dt, true ); |
410 | database->writeField(ZdbAdrs::Birthday, dateS); | ||
411 | } | 393 | } |
394 | database->writeField(ZdbAdrs::Birthday, dateS); | ||
412 | database->writeField(ZdbAdrs::Nickname, addr.nickName()); | 395 | database->writeField(ZdbAdrs::Nickname, addr.nickName()); |
413 | 396 | ||
414 | // other | 397 | // other |
@@ -420,21 +403,76 @@ bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* da | |||
420 | 403 | ||
421 | //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); | 404 | //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); |
422 | 405 | ||
423 | QStringList cats = addr.categories(); | 406 | return true; |
424 | int ii; | 407 | } |
425 | for ( ii = 0; ii < cats.count() ;++ii ) { | 408 | |
426 | if ( !catDB->exists( cats[ii] )) | 409 | |
427 | catDB->addCategory(cats[ii]); | 410 | bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) |
411 | { | ||
412 | QStringList list = addr.categories(); | ||
413 | |||
414 | QArray<int> ids(list.count()); | ||
415 | uint index = 0; | ||
416 | for(uint i=0; i<ids.size(); i++){ | ||
417 | if(catDB->exists(list[i])){ | ||
418 | ids[index] = catDB->id(list[i]); | ||
419 | qDebug("set ex cat %d %s ",ids[index] , list[i].latin1()); | ||
420 | index++; | ||
421 | } else { | ||
422 | ids[index] = catDB->addCategory(list[i]); | ||
423 | qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); | ||
424 | index++; | ||
428 | } | 425 | } |
429 | QArray<int> iar; | 426 | } |
430 | if ( !cats.isEmpty() ) { | 427 | bool res ; |
431 | QArray<int> iar = catDB->ids(cats); | 428 | if ( res = database->updateCategories(contact, ids) ) |
432 | //qDebug("***cat count is %d ", iar.count()); | 429 | qDebug("cat updated "); |
433 | database->updateCategories(contact, iar); | 430 | else |
431 | qDebug("error cat updating "); | ||
432 | |||
433 | return res; | ||
434 | } | 434 | } |
435 | 435 | ||
436 | #if 0 | ||
437 | m_pCategories = new SlCategories; | ||
438 | catDB | ||
439 | |||
440 | if(categories == QString::null) return true; | ||
441 | QStringList list = CSVParser::parse(categories); | ||
442 | QArray<int> ids(list.count()); | ||
443 | uint index = 0; | ||
444 | for(uint i=0; i<ids.size(); i++){ | ||
445 | #if 0 | ||
446 | bool ok; | ||
447 | ids[index] = list[i].toInt(&ok); | ||
448 | if(ok){ | ||
449 | index++; | ||
450 | } else { | ||
451 | if(m_pCategories->exists(list[i])){ | ||
452 | ids[index] = m_pCategories->id(list[i]); | ||
453 | index++; | ||
454 | } | ||
455 | } | ||
456 | #else | ||
457 | if(m_pCategories->exists(list[i])){ | ||
458 | ids[index] = m_pCategories->id(list[i]); | ||
459 | index++; | ||
460 | } else if(m_addCategory){ | ||
461 | ids[index] = m_pCategories->addCategory(list[i]); | ||
462 | index++; | ||
463 | } | ||
464 | #endif | ||
465 | } | ||
466 | if(ids.size() > 0 && index == 0){ | ||
436 | return true; | 467 | return true; |
468 | } else if(index != ids.size()){ | ||
469 | ids.resize(index); | ||
470 | } | ||
471 | if(!m_pZdb->updateCategories(id, ids)){ | ||
472 | return false; | ||
437 | } | 473 | } |
474 | return true; | ||
475 | #endif | ||
438 | 476 | ||
439 | QDate SharpDTMConverter::convertDate( QString s) | 477 | QDate SharpDTMConverter::convertDate( QString s) |
440 | { | 478 | { |
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.h b/kabc/plugins/sharpdtm/sharpdtmconverter.h index a04083e..db1bf2d 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.h +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.h | |||
@@ -75,6 +75,7 @@ public: | |||
75 | * @param contact The sharp card id, eventhough it might be 0, if the contact is a new one. | 75 | * @param contact The sharp card id, eventhough it might be 0, if the contact is a new one. |
76 | */ | 76 | */ |
77 | bool addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ); | 77 | bool addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ); |
78 | bool setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ); | ||
78 | 79 | ||
79 | private: | 80 | private: |
80 | SlCategory::SlCategories* catDB; | 81 | SlCategory::SlCategories* catDB; |