-rw-r--r-- | kabc/addressbook.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index bf6d053..1a06956 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -318,193 +318,192 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
318 | 318 | ||
319 | //US added this field to become compatible with Opie/qtopia addressbook | 319 | //US added this field to become compatible with Opie/qtopia addressbook |
320 | // values can be "female" or "male" or "". An empty field represents undefined. | 320 | // values can be "female" or "male" or "". An empty field represents undefined. |
321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
322 | "X-Gender", "KADDRESSBOOK" ); | 322 | "X-Gender", "KADDRESSBOOK" ); |
323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
324 | "X-Children", "KADDRESSBOOK" ); | 324 | "X-Children", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
328 | "X-ExternalID", "KADDRESSBOOK" ); | 328 | "X-ExternalID", "KADDRESSBOOK" ); |
329 | } | 329 | } |
330 | 330 | ||
331 | AddressBook::~AddressBook() | 331 | AddressBook::~AddressBook() |
332 | { | 332 | { |
333 | delete d->mConfig; d->mConfig = 0; | 333 | delete d->mConfig; d->mConfig = 0; |
334 | delete d->mManager; d->mManager = 0; | 334 | delete d->mManager; d->mManager = 0; |
335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
336 | delete d; d = 0; | 336 | delete d; d = 0; |
337 | } | 337 | } |
338 | 338 | ||
339 | bool AddressBook::load() | 339 | bool AddressBook::load() |
340 | { | 340 | { |
341 | 341 | ||
342 | 342 | ||
343 | clear(); | 343 | clear(); |
344 | 344 | ||
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } | 351 | } |
352 | 352 | ||
353 | // mark all addressees as unchanged | 353 | // mark all addressees as unchanged |
354 | Addressee::List::Iterator addrIt; | 354 | Addressee::List::Iterator addrIt; |
355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
356 | (*addrIt).setChanged( false ); | 356 | (*addrIt).setChanged( false ); |
357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
358 | if ( !id.isEmpty() ) { | 358 | if ( !id.isEmpty() ) { |
359 | //qDebug("setId aa %s ", id.latin1()); | 359 | //qDebug("setId aa %s ", id.latin1()); |
360 | (*addrIt).setIDStr(id ); | 360 | (*addrIt).setIDStr(id ); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | blockLSEchange = true; | 363 | blockLSEchange = true; |
364 | return ok; | 364 | return ok; |
365 | } | 365 | } |
366 | 366 | ||
367 | bool AddressBook::save( Ticket *ticket ) | 367 | bool AddressBook::save( Ticket *ticket ) |
368 | { | 368 | { |
369 | kdDebug(5700) << "AddressBook::save()"<< endl; | 369 | kdDebug(5700) << "AddressBook::save()"<< endl; |
370 | 370 | ||
371 | if ( ticket->resource() ) { | 371 | if ( ticket->resource() ) { |
372 | deleteRemovedAddressees(); | 372 | deleteRemovedAddressees(); |
373 | return ticket->resource()->save( ticket ); | 373 | return ticket->resource()->save( ticket ); |
374 | } | 374 | } |
375 | 375 | ||
376 | return false; | 376 | return false; |
377 | } | 377 | } |
378 | void AddressBook::export2File( QString fileName ) | 378 | void AddressBook::export2File( QString fileName ) |
379 | { | 379 | { |
380 | 380 | ||
381 | QFile outFile( fileName ); | 381 | QFile outFile( fileName ); |
382 | if ( !outFile.open( IO_WriteOnly ) ) { | 382 | if ( !outFile.open( IO_WriteOnly ) ) { |
383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
384 | KMessageBox::error( 0, text.arg( fileName ) ); | 384 | KMessageBox::error( 0, text.arg( fileName ) ); |
385 | return ; | 385 | return ; |
386 | } | 386 | } |
387 | QTextStream t( &outFile ); | 387 | QTextStream t( &outFile ); |
388 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 388 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
389 | Iterator it; | 389 | Iterator it; |
390 | KABC::VCardConverter::Version version; | 390 | KABC::VCardConverter::Version version; |
391 | version = KABC::VCardConverter::v3_0; | 391 | version = KABC::VCardConverter::v3_0; |
392 | for ( it = begin(); it != end(); ++it ) { | 392 | for ( it = begin(); it != end(); ++it ) { |
393 | if ( !(*it).IDStr().isEmpty() ) { | 393 | if ( !(*it).IDStr().isEmpty() ) { |
394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
395 | } | 395 | } |
396 | KABC::VCardConverter converter; | 396 | KABC::VCardConverter converter; |
397 | QString vcard; | 397 | QString vcard; |
398 | //Resource *resource() const; | 398 | //Resource *resource() const; |
399 | converter.addresseeToVCard( *it, vcard, version ); | 399 | converter.addresseeToVCard( *it, vcard, version ); |
400 | t << vcard << "\r\n"; | 400 | t << vcard << "\r\n"; |
401 | } | 401 | } |
402 | t << "\r\n\r\n"; | 402 | t << "\r\n\r\n"; |
403 | outFile.close(); | 403 | outFile.close(); |
404 | } | 404 | } |
405 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) | 405 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) |
406 | { | 406 | { |
407 | 407 | ||
408 | KABC::Addressee::List list; | 408 | KABC::Addressee::List list; |
409 | QFile file( fileName ); | 409 | QFile file( fileName ); |
410 | 410 | ||
411 | file.open( IO_ReadOnly ); | 411 | file.open( IO_ReadOnly ); |
412 | QByteArray rawData = file.readAll(); | 412 | QByteArray rawData = file.readAll(); |
413 | file.close(); | 413 | file.close(); |
414 | qDebug("AddressBook::importFromFile "); | ||
415 | QString data; | 414 | QString data; |
416 | if ( replaceLabel ) { | 415 | if ( replaceLabel ) { |
417 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 416 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
418 | data.replace ( QRegExp("LABEL") , "ADR" ); | 417 | data.replace ( QRegExp("LABEL") , "ADR" ); |
419 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 418 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
420 | } else | 419 | } else |
421 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 420 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
422 | KABC::VCardTool tool; | 421 | KABC::VCardTool tool; |
423 | list = tool.parseVCards( data ); | 422 | list = tool.parseVCards( data ); |
424 | KABC::Addressee::List::Iterator it; | 423 | KABC::Addressee::List::Iterator it; |
425 | for ( it = list.begin(); it != list.end(); ++it ) { | 424 | for ( it = list.begin(); it != list.end(); ++it ) { |
426 | (*it).setResource( 0 ); | 425 | (*it).setResource( 0 ); |
427 | if ( replaceLabel ) | 426 | if ( replaceLabel ) |
428 | (*it).removeVoice(); | 427 | (*it).removeVoice(); |
429 | insertAddressee( (*it), false, true ); | 428 | insertAddressee( (*it), false, true ); |
430 | } | 429 | } |
431 | 430 | ||
432 | } | 431 | } |
433 | 432 | ||
434 | bool AddressBook::saveAB() | 433 | bool AddressBook::saveAB() |
435 | { | 434 | { |
436 | bool ok = true; | 435 | bool ok = true; |
437 | 436 | ||
438 | deleteRemovedAddressees(); | 437 | deleteRemovedAddressees(); |
439 | Iterator ait; | 438 | Iterator ait; |
440 | for ( ait = begin(); ait != end(); ++ait ) { | 439 | for ( ait = begin(); ait != end(); ++ait ) { |
441 | if ( !(*ait).IDStr().isEmpty() ) { | 440 | if ( !(*ait).IDStr().isEmpty() ) { |
442 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 441 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
443 | } | 442 | } |
444 | } | 443 | } |
445 | KRES::Manager<Resource>::ActiveIterator it; | 444 | KRES::Manager<Resource>::ActiveIterator it; |
446 | KRES::Manager<Resource> *manager = d->mManager; | 445 | KRES::Manager<Resource> *manager = d->mManager; |
447 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 446 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
448 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 447 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
449 | Ticket *ticket = requestSaveTicket( *it ); | 448 | Ticket *ticket = requestSaveTicket( *it ); |
450 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 449 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
451 | if ( !ticket ) { | 450 | if ( !ticket ) { |
452 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 451 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
453 | .arg( (*it)->resourceName() ) ); | 452 | .arg( (*it)->resourceName() ) ); |
454 | return false; | 453 | return false; |
455 | } | 454 | } |
456 | 455 | ||
457 | //if ( !save( ticket ) ) | 456 | //if ( !save( ticket ) ) |
458 | if ( ticket->resource() ) { | 457 | if ( ticket->resource() ) { |
459 | if ( ! ticket->resource()->save( ticket ) ) | 458 | if ( ! ticket->resource()->save( ticket ) ) |
460 | ok = false; | 459 | ok = false; |
461 | } else | 460 | } else |
462 | ok = false; | 461 | ok = false; |
463 | 462 | ||
464 | } | 463 | } |
465 | } | 464 | } |
466 | return ok; | 465 | return ok; |
467 | } | 466 | } |
468 | 467 | ||
469 | AddressBook::Iterator AddressBook::begin() | 468 | AddressBook::Iterator AddressBook::begin() |
470 | { | 469 | { |
471 | Iterator it = Iterator(); | 470 | Iterator it = Iterator(); |
472 | it.d->mIt = d->mAddressees.begin(); | 471 | it.d->mIt = d->mAddressees.begin(); |
473 | return it; | 472 | return it; |
474 | } | 473 | } |
475 | 474 | ||
476 | AddressBook::ConstIterator AddressBook::begin() const | 475 | AddressBook::ConstIterator AddressBook::begin() const |
477 | { | 476 | { |
478 | ConstIterator it = ConstIterator(); | 477 | ConstIterator it = ConstIterator(); |
479 | it.d->mIt = d->mAddressees.begin(); | 478 | it.d->mIt = d->mAddressees.begin(); |
480 | return it; | 479 | return it; |
481 | } | 480 | } |
482 | 481 | ||
483 | AddressBook::Iterator AddressBook::end() | 482 | AddressBook::Iterator AddressBook::end() |
484 | { | 483 | { |
485 | Iterator it = Iterator(); | 484 | Iterator it = Iterator(); |
486 | it.d->mIt = d->mAddressees.end(); | 485 | it.d->mIt = d->mAddressees.end(); |
487 | return it; | 486 | return it; |
488 | } | 487 | } |
489 | 488 | ||
490 | AddressBook::ConstIterator AddressBook::end() const | 489 | AddressBook::ConstIterator AddressBook::end() const |
491 | { | 490 | { |
492 | ConstIterator it = ConstIterator(); | 491 | ConstIterator it = ConstIterator(); |
493 | it.d->mIt = d->mAddressees.end(); | 492 | it.d->mIt = d->mAddressees.end(); |
494 | return it; | 493 | return it; |
495 | } | 494 | } |
496 | 495 | ||
497 | void AddressBook::clear() | 496 | void AddressBook::clear() |
498 | { | 497 | { |
499 | d->mAddressees.clear(); | 498 | d->mAddressees.clear(); |
500 | } | 499 | } |
501 | 500 | ||
502 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 501 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
503 | { | 502 | { |
504 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 503 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
505 | 504 | ||
506 | if ( !resource ) | 505 | if ( !resource ) |
507 | { | 506 | { |
508 | qDebug("AddressBook::requestSaveTicket no resource" ); | 507 | qDebug("AddressBook::requestSaveTicket no resource" ); |
509 | resource = standardResource(); | 508 | resource = standardResource(); |
510 | } | 509 | } |