summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp44
-rw-r--r--kabc/addressbook.h3
2 files changed, 47 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16927e2..d037d2f 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,145 +1,146 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28/*US 28/*US
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qtimer.h> 32#include <qtimer.h>
33 33
34#include <kapplication.h> 34#include <kapplication.h>
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
38#include "errorhandler.h" 38#include "errorhandler.h"
39*/ 39*/
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qfile.h> 42#include <qfile.h>
43#include <qregexp.h> 43#include <qregexp.h>
44 44
45#include <kglobal.h> 45#include <kglobal.h>
46#include <klocale.h> 46#include <klocale.h>
47#include <kmessagebox.h> 47#include <kmessagebox.h>
48#include <kdebug.h> 48#include <kdebug.h>
49#include <libkcal/syncdefines.h> 49#include <libkcal/syncdefines.h>
50#include <libkdepim/phoneaccess.h>
50#include "addressbook.h" 51#include "addressbook.h"
51#include "resource.h" 52#include "resource.h"
52#include "vcardconverter.h" 53#include "vcardconverter.h"
53#include "vcardparser/vcardtool.h" 54#include "vcardparser/vcardtool.h"
54 55
55//US #include "addressbook.moc" 56//US #include "addressbook.moc"
56 57
57using namespace KABC; 58using namespace KABC;
58 59
59struct AddressBook::AddressBookData 60struct AddressBook::AddressBookData
60{ 61{
61 Addressee::List mAddressees; 62 Addressee::List mAddressees;
62 Addressee::List mRemovedAddressees; 63 Addressee::List mRemovedAddressees;
63 Field::List mAllFields; 64 Field::List mAllFields;
64 KConfig *mConfig; 65 KConfig *mConfig;
65 KRES::Manager<Resource> *mManager; 66 KRES::Manager<Resource> *mManager;
66//US ErrorHandler *mErrorHandler; 67//US ErrorHandler *mErrorHandler;
67}; 68};
68 69
69struct AddressBook::Iterator::IteratorData 70struct AddressBook::Iterator::IteratorData
70{ 71{
71 Addressee::List::Iterator mIt; 72 Addressee::List::Iterator mIt;
72}; 73};
73 74
74struct AddressBook::ConstIterator::ConstIteratorData 75struct AddressBook::ConstIterator::ConstIteratorData
75{ 76{
76 Addressee::List::ConstIterator mIt; 77 Addressee::List::ConstIterator mIt;
77}; 78};
78 79
79AddressBook::Iterator::Iterator() 80AddressBook::Iterator::Iterator()
80{ 81{
81 d = new IteratorData; 82 d = new IteratorData;
82} 83}
83 84
84AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 85AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
85{ 86{
86 d = new IteratorData; 87 d = new IteratorData;
87 d->mIt = i.d->mIt; 88 d->mIt = i.d->mIt;
88} 89}
89 90
90AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 91AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
91{ 92{
92 if( this == &i ) return *this; // guard against self assignment 93 if( this == &i ) return *this; // guard against self assignment
93 delete d; // delete the old data the Iterator was completely constructed before 94 delete d; // delete the old data the Iterator was completely constructed before
94 d = new IteratorData; 95 d = new IteratorData;
95 d->mIt = i.d->mIt; 96 d->mIt = i.d->mIt;
96 return *this; 97 return *this;
97} 98}
98 99
99AddressBook::Iterator::~Iterator() 100AddressBook::Iterator::~Iterator()
100{ 101{
101 delete d; 102 delete d;
102} 103}
103 104
104const Addressee &AddressBook::Iterator::operator*() const 105const Addressee &AddressBook::Iterator::operator*() const
105{ 106{
106 return *(d->mIt); 107 return *(d->mIt);
107} 108}
108 109
109Addressee &AddressBook::Iterator::operator*() 110Addressee &AddressBook::Iterator::operator*()
110{ 111{
111 return *(d->mIt); 112 return *(d->mIt);
112} 113}
113 114
114Addressee *AddressBook::Iterator::operator->() 115Addressee *AddressBook::Iterator::operator->()
115{ 116{
116 return &(*(d->mIt)); 117 return &(*(d->mIt));
117} 118}
118 119
119AddressBook::Iterator &AddressBook::Iterator::operator++() 120AddressBook::Iterator &AddressBook::Iterator::operator++()
120{ 121{
121 (d->mIt)++; 122 (d->mIt)++;
122 return *this; 123 return *this;
123} 124}
124 125
125AddressBook::Iterator &AddressBook::Iterator::operator++(int) 126AddressBook::Iterator &AddressBook::Iterator::operator++(int)
126{ 127{
127 (d->mIt)++; 128 (d->mIt)++;
128 return *this; 129 return *this;
129} 130}
130 131
131AddressBook::Iterator &AddressBook::Iterator::operator--() 132AddressBook::Iterator &AddressBook::Iterator::operator--()
132{ 133{
133 (d->mIt)--; 134 (d->mIt)--;
134 return *this; 135 return *this;
135} 136}
136 137
137AddressBook::Iterator &AddressBook::Iterator::operator--(int) 138AddressBook::Iterator &AddressBook::Iterator::operator--(int)
138{ 139{
139 (d->mIt)--; 140 (d->mIt)--;
140 return *this; 141 return *this;
141} 142}
142 143
143bool AddressBook::Iterator::operator==( const Iterator &it ) 144bool AddressBook::Iterator::operator==( const Iterator &it )
144{ 145{
145 return ( d->mIt == it.d->mIt ); 146 return ( d->mIt == it.d->mIt );
@@ -366,192 +367,235 @@ bool AddressBook::load()
366} 367}
367 368
368bool AddressBook::save( Ticket *ticket ) 369bool AddressBook::save( Ticket *ticket )
369{ 370{
370 kdDebug(5700) << "AddressBook::save()"<< endl; 371 kdDebug(5700) << "AddressBook::save()"<< endl;
371 372
372 if ( ticket->resource() ) { 373 if ( ticket->resource() ) {
373 deleteRemovedAddressees(); 374 deleteRemovedAddressees();
374 return ticket->resource()->save( ticket ); 375 return ticket->resource()->save( ticket );
375 } 376 }
376 377
377 return false; 378 return false;
378} 379}
379void AddressBook::export2File( QString fileName ) 380void AddressBook::export2File( QString fileName )
380{ 381{
381 382
382 QFile outFile( fileName ); 383 QFile outFile( fileName );
383 if ( !outFile.open( IO_WriteOnly ) ) { 384 if ( !outFile.open( IO_WriteOnly ) ) {
384 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); 385 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
385 KMessageBox::error( 0, text.arg( fileName ) ); 386 KMessageBox::error( 0, text.arg( fileName ) );
386 return ; 387 return ;
387 } 388 }
388 QTextStream t( &outFile ); 389 QTextStream t( &outFile );
389 t.setEncoding( QTextStream::UnicodeUTF8 ); 390 t.setEncoding( QTextStream::UnicodeUTF8 );
390 Iterator it; 391 Iterator it;
391 KABC::VCardConverter::Version version; 392 KABC::VCardConverter::Version version;
392 version = KABC::VCardConverter::v3_0; 393 version = KABC::VCardConverter::v3_0;
393 for ( it = begin(); it != end(); ++it ) { 394 for ( it = begin(); it != end(); ++it ) {
394 if ( !(*it).IDStr().isEmpty() ) { 395 if ( !(*it).IDStr().isEmpty() ) {
395 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 396 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
396 } 397 }
397 KABC::VCardConverter converter; 398 KABC::VCardConverter converter;
398 QString vcard; 399 QString vcard;
399 //Resource *resource() const; 400 //Resource *resource() const;
400 converter.addresseeToVCard( *it, vcard, version ); 401 converter.addresseeToVCard( *it, vcard, version );
401 t << vcard << "\r\n"; 402 t << vcard << "\r\n";
402 } 403 }
403 t << "\r\n\r\n"; 404 t << "\r\n\r\n";
404 outFile.close(); 405 outFile.close();
405} 406}
406void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 407void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
407{ 408{
408 409
409 if ( removeOld ) 410 if ( removeOld )
410 setUntagged(); 411 setUntagged();
411 KABC::Addressee::List list; 412 KABC::Addressee::List list;
412 QFile file( fileName ); 413 QFile file( fileName );
413 file.open( IO_ReadOnly ); 414 file.open( IO_ReadOnly );
414 QByteArray rawData = file.readAll(); 415 QByteArray rawData = file.readAll();
415 file.close(); 416 file.close();
416 QString data; 417 QString data;
417 if ( replaceLabel ) { 418 if ( replaceLabel ) {
418 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 419 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
419 data.replace ( QRegExp("LABEL") , "ADR" ); 420 data.replace ( QRegExp("LABEL") , "ADR" );
420 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 421 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
421 } else 422 } else
422 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 423 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
423 KABC::VCardTool tool; 424 KABC::VCardTool tool;
424 list = tool.parseVCards( data ); 425 list = tool.parseVCards( data );
425 KABC::Addressee::List::Iterator it; 426 KABC::Addressee::List::Iterator it;
426 for ( it = list.begin(); it != list.end(); ++it ) { 427 for ( it = list.begin(); it != list.end(); ++it ) {
427 (*it).setResource( 0 ); 428 (*it).setResource( 0 );
428 if ( replaceLabel ) 429 if ( replaceLabel )
429 (*it).removeVoice(); 430 (*it).removeVoice();
430 if ( removeOld ) 431 if ( removeOld )
431 (*it).setTagged( true ); 432 (*it).setTagged( true );
432 insertAddressee( (*it), false, true ); 433 insertAddressee( (*it), false, true );
433 } 434 }
434 if ( removeOld ) 435 if ( removeOld )
435 removeUntagged(); 436 removeUntagged();
436} 437}
437void AddressBook::setUntagged() 438void AddressBook::setUntagged()
438{ 439{
439 Iterator ait; 440 Iterator ait;
440 for ( ait = begin(); ait != end(); ++ait ) { 441 for ( ait = begin(); ait != end(); ++ait ) {
441 (*ait).setTagged( false ); 442 (*ait).setTagged( false );
442 } 443 }
443} 444}
444void AddressBook::removeUntagged() 445void AddressBook::removeUntagged()
445{ 446{
446 Iterator ait; 447 Iterator ait;
447 bool todelete = false; 448 bool todelete = false;
448 Iterator todel; 449 Iterator todel;
449 for ( ait = begin(); ait != end(); ++ait ) { 450 for ( ait = begin(); ait != end(); ++ait ) {
450 if ( todelete ) 451 if ( todelete )
451 removeAddressee( todel ); 452 removeAddressee( todel );
452 if (!(*ait).tagged()) { 453 if (!(*ait).tagged()) {
453 todelete = true; 454 todelete = true;
454 todel = ait; 455 todel = ait;
455 } else 456 } else
456 todelete = false; 457 todelete = false;
457 } 458 }
458 if ( todelete ) 459 if ( todelete )
459 removeAddressee( todel ); 460 removeAddressee( todel );
460 deleteRemovedAddressees(); 461 deleteRemovedAddressees();
461} 462}
463void AddressBook::smplifyAddressees()
464{
465 Iterator ait;
466 for ( ait = begin(); ait != end(); ++ait ) {
467 (*ait).simplifyEmails();
468 (*ait).simplifyPhoneNumbers();
469 (*ait).simplifyPhoneNumberTypes();
470 (*ait).simplifyAddresses();
471 }
472}
473void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
474{
475 Iterator ait;
476 for ( ait = begin(); ait != end(); ++ait ) {
477 QString id = (*ait).IDStr();
478 (*ait).setIDStr( ":");
479 (*ait).setExternalUID( id );
480 (*ait).setOriginalExternalUID( id );
481 if ( isPreSync )
482 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
483 else
484 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
485 }
486}
487bool AddressBook::saveABphone( QString fileName )
488{
489 smplifyAddressees();
490 qDebug("saveABphone:: saving AB... ");
491 if ( ! saveAB() )
492 return false;
493 qDebug("saveABphone:: writing to phone... ");
494 if ( !PhoneAccess::writeToPhone( fileName) ) {
495 return false;
496 }
497 qDebug("saveABphone:: re-reading from phone... ");
498 if ( !PhoneAccess::readFromPhone( fileName) ) {
499 return false;
500 }
501 qDebug("reloading phone book... ");
502 if ( !load() )
503 return false;
504 return true;
505}
462bool AddressBook::saveAB() 506bool AddressBook::saveAB()
463{ 507{
464 bool ok = true; 508 bool ok = true;
465 509
466 deleteRemovedAddressees(); 510 deleteRemovedAddressees();
467 Iterator ait; 511 Iterator ait;
468 for ( ait = begin(); ait != end(); ++ait ) { 512 for ( ait = begin(); ait != end(); ++ait ) {
469 if ( !(*ait).IDStr().isEmpty() ) { 513 if ( !(*ait).IDStr().isEmpty() ) {
470 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 514 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
471 } 515 }
472 } 516 }
473 KRES::Manager<Resource>::ActiveIterator it; 517 KRES::Manager<Resource>::ActiveIterator it;
474 KRES::Manager<Resource> *manager = d->mManager; 518 KRES::Manager<Resource> *manager = d->mManager;
475 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 519 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
476 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 520 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
477 Ticket *ticket = requestSaveTicket( *it ); 521 Ticket *ticket = requestSaveTicket( *it );
478// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 522// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
479 if ( !ticket ) { 523 if ( !ticket ) {
480 error( i18n( "Unable to save to resource '%1'. It is locked." ) 524 error( i18n( "Unable to save to resource '%1'. It is locked." )
481 .arg( (*it)->resourceName() ) ); 525 .arg( (*it)->resourceName() ) );
482 return false; 526 return false;
483 } 527 }
484 528
485 //if ( !save( ticket ) ) 529 //if ( !save( ticket ) )
486 if ( ticket->resource() ) { 530 if ( ticket->resource() ) {
487 if ( ! ticket->resource()->save( ticket ) ) 531 if ( ! ticket->resource()->save( ticket ) )
488 ok = false; 532 ok = false;
489 } else 533 } else
490 ok = false; 534 ok = false;
491 535
492 } 536 }
493 } 537 }
494 return ok; 538 return ok;
495} 539}
496 540
497AddressBook::Iterator AddressBook::begin() 541AddressBook::Iterator AddressBook::begin()
498{ 542{
499 Iterator it = Iterator(); 543 Iterator it = Iterator();
500 it.d->mIt = d->mAddressees.begin(); 544 it.d->mIt = d->mAddressees.begin();
501 return it; 545 return it;
502} 546}
503 547
504AddressBook::ConstIterator AddressBook::begin() const 548AddressBook::ConstIterator AddressBook::begin() const
505{ 549{
506 ConstIterator it = ConstIterator(); 550 ConstIterator it = ConstIterator();
507 it.d->mIt = d->mAddressees.begin(); 551 it.d->mIt = d->mAddressees.begin();
508 return it; 552 return it;
509} 553}
510 554
511AddressBook::Iterator AddressBook::end() 555AddressBook::Iterator AddressBook::end()
512{ 556{
513 Iterator it = Iterator(); 557 Iterator it = Iterator();
514 it.d->mIt = d->mAddressees.end(); 558 it.d->mIt = d->mAddressees.end();
515 return it; 559 return it;
516} 560}
517 561
518AddressBook::ConstIterator AddressBook::end() const 562AddressBook::ConstIterator AddressBook::end() const
519{ 563{
520 ConstIterator it = ConstIterator(); 564 ConstIterator it = ConstIterator();
521 it.d->mIt = d->mAddressees.end(); 565 it.d->mIt = d->mAddressees.end();
522 return it; 566 return it;
523} 567}
524 568
525void AddressBook::clear() 569void AddressBook::clear()
526{ 570{
527 d->mAddressees.clear(); 571 d->mAddressees.clear();
528} 572}
529 573
530Ticket *AddressBook::requestSaveTicket( Resource *resource ) 574Ticket *AddressBook::requestSaveTicket( Resource *resource )
531{ 575{
532 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 576 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
533 577
534 if ( !resource ) 578 if ( !resource )
535 { 579 {
536 qDebug("AddressBook::requestSaveTicket no resource" ); 580 qDebug("AddressBook::requestSaveTicket no resource" );
537 resource = standardResource(); 581 resource = standardResource();
538 } 582 }
539 583
540 KRES::Manager<Resource>::ActiveIterator it; 584 KRES::Manager<Resource>::ActiveIterator it;
541 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 585 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
542 if ( (*it) == resource ) { 586 if ( (*it) == resource ) {
543 if ( (*it)->readOnly() || !(*it)->isOpen() ) 587 if ( (*it)->readOnly() || !(*it)->isOpen() )
544 return 0; 588 return 0;
545 else 589 else
546 return (*it)->requestSaveTicket(); 590 return (*it)->requestSaveTicket();
547 } 591 }
548 } 592 }
549 593
550 return 0; 594 return 0;
551} 595}
552 596
553void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 597void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
554{ 598{
555 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { 599 if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
556 //qDebug("block insert "); 600 //qDebug("block insert ");
557 return; 601 return;
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 532e05d..cc755d1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -49,192 +49,195 @@ class Ticket;
49*/ 49*/
50class AddressBook : public QObject 50class AddressBook : public QObject
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54 friend QDataStream &operator<<( QDataStream &, const AddressBook & ); 54 friend QDataStream &operator<<( QDataStream &, const AddressBook & );
55 friend QDataStream &operator>>( QDataStream &, AddressBook & ); 55 friend QDataStream &operator>>( QDataStream &, AddressBook & );
56 friend class StdAddressBook; 56 friend class StdAddressBook;
57 57
58 public: 58 public:
59 /** 59 /**
60 @short Address Book Iterator 60 @short Address Book Iterator
61 61
62 This class provides an iterator for address book entries. 62 This class provides an iterator for address book entries.
63 */ 63 */
64 class Iterator 64 class Iterator
65 { 65 {
66 public: 66 public:
67 Iterator(); 67 Iterator();
68 Iterator( const Iterator & ); 68 Iterator( const Iterator & );
69 ~Iterator(); 69 ~Iterator();
70 70
71 Iterator &operator=( const Iterator & ); 71 Iterator &operator=( const Iterator & );
72 const Addressee &operator*() const; 72 const Addressee &operator*() const;
73 Addressee &operator*(); 73 Addressee &operator*();
74 Addressee* operator->(); 74 Addressee* operator->();
75 Iterator &operator++(); 75 Iterator &operator++();
76 Iterator &operator++(int); 76 Iterator &operator++(int);
77 Iterator &operator--(); 77 Iterator &operator--();
78 Iterator &operator--(int); 78 Iterator &operator--(int);
79 bool operator==( const Iterator &it ); 79 bool operator==( const Iterator &it );
80 bool operator!=( const Iterator &it ); 80 bool operator!=( const Iterator &it );
81 81
82 struct IteratorData; 82 struct IteratorData;
83 IteratorData *d; 83 IteratorData *d;
84 }; 84 };
85 85
86 /** 86 /**
87 @short Address Book Const Iterator 87 @short Address Book Const Iterator
88 88
89 This class provides a const iterator for address book entries. 89 This class provides a const iterator for address book entries.
90 */ 90 */
91 class ConstIterator 91 class ConstIterator
92 { 92 {
93 public: 93 public:
94 ConstIterator(); 94 ConstIterator();
95 ConstIterator( const ConstIterator & ); 95 ConstIterator( const ConstIterator & );
96 ~ConstIterator(); 96 ~ConstIterator();
97 97
98 ConstIterator &operator=( const ConstIterator & ); 98 ConstIterator &operator=( const ConstIterator & );
99 const Addressee &operator*() const; 99 const Addressee &operator*() const;
100 const Addressee* operator->() const; 100 const Addressee* operator->() const;
101 ConstIterator &operator++(); 101 ConstIterator &operator++();
102 ConstIterator &operator++(int); 102 ConstIterator &operator++(int);
103 ConstIterator &operator--(); 103 ConstIterator &operator--();
104 ConstIterator &operator--(int); 104 ConstIterator &operator--(int);
105 bool operator==( const ConstIterator &it ); 105 bool operator==( const ConstIterator &it );
106 bool operator!=( const ConstIterator &it ); 106 bool operator!=( const ConstIterator &it );
107 107
108 struct ConstIteratorData; 108 struct ConstIteratorData;
109 ConstIteratorData *d; 109 ConstIteratorData *d;
110 }; 110 };
111 111
112 /** 112 /**
113 Constructs a address book object. 113 Constructs a address book object.
114 114
115 @param format File format class. 115 @param format File format class.
116 */ 116 */
117 AddressBook(); 117 AddressBook();
118 AddressBook( const QString &config ); 118 AddressBook( const QString &config );
119 AddressBook( const QString &config, const QString &family ); 119 AddressBook( const QString &config, const QString &family );
120 virtual ~AddressBook(); 120 virtual ~AddressBook();
121 121
122 /** 122 /**
123 Requests a ticket for saving the addressbook. Calling this function locks 123 Requests a ticket for saving the addressbook. Calling this function locks
124 the addressbook for all other processes. If the address book is already 124 the addressbook for all other processes. If the address book is already
125 locked the function returns 0. You need the returned @ref Ticket object 125 locked the function returns 0. You need the returned @ref Ticket object
126 for calling the @ref save() function. 126 for calling the @ref save() function.
127 127
128 @see save() 128 @see save()
129 */ 129 */
130 Ticket *requestSaveTicket( Resource *resource=0 ); 130 Ticket *requestSaveTicket( Resource *resource=0 );
131 131
132 /** 132 /**
133 Load address book from file. 133 Load address book from file.
134 */ 134 */
135 bool load(); 135 bool load();
136 136
137 /** 137 /**
138 Save address book. The address book is saved to the file, the Ticket 138 Save address book. The address book is saved to the file, the Ticket
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
142 */ 142 */
143 bool save( Ticket *ticket ); 143 bool save( Ticket *ticket );
144 bool saveAB( ); 144 bool saveAB( );
145 bool saveABphone( QString fileName );
146 void smplifyAddressees();
147 void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
145 void export2File( QString fileName ); 148 void export2File( QString fileName );
146 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); 149 void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
147 void setUntagged(); 150 void setUntagged();
148 void removeUntagged(); 151 void removeUntagged();
149 /** 152 /**
150 Returns a iterator for first entry of address book. 153 Returns a iterator for first entry of address book.
151 */ 154 */
152 Iterator begin(); 155 Iterator begin();
153 156
154 /** 157 /**
155 Returns a const iterator for first entry of address book. 158 Returns a const iterator for first entry of address book.
156 */ 159 */
157 ConstIterator begin() const; 160 ConstIterator begin() const;
158 161
159 /** 162 /**
160 Returns a iterator for first entry of address book. 163 Returns a iterator for first entry of address book.
161 */ 164 */
162 Iterator end(); 165 Iterator end();
163 166
164 /** 167 /**
165 Returns a const iterator for first entry of address book. 168 Returns a const iterator for first entry of address book.
166 */ 169 */
167 ConstIterator end() const; 170 ConstIterator end() const;
168 171
169 /** 172 /**
170 Removes all entries from address book. 173 Removes all entries from address book.
171 */ 174 */
172 void clear(); 175 void clear();
173 176
174 /** 177 /**
175 Insert an Addressee object into address book. If an object with the same 178 Insert an Addressee object into address book. If an object with the same
176 unique id already exists in the address book it it replaced by the new 179 unique id already exists in the address book it it replaced by the new
177 one. If not the new object is appended to the address book. 180 one. If not the new object is appended to the address book.
178 */ 181 */
179 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); 182 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
180 183
181 /** 184 /**
182 Removes entry from the address book. 185 Removes entry from the address book.
183 */ 186 */
184 void removeAddressee( const Addressee & ); 187 void removeAddressee( const Addressee & );
185 188
186 /** 189 /**
187 This is like @ref removeAddressee() just above, with the difference that 190 This is like @ref removeAddressee() just above, with the difference that
188 the first element is a iterator, returned by @ref begin(). 191 the first element is a iterator, returned by @ref begin().
189 */ 192 */
190 void removeAddressee( const Iterator & ); 193 void removeAddressee( const Iterator & );
191 194
192 /** 195 /**
193 Find the specified entry in address book. Returns end(), if the entry 196 Find the specified entry in address book. Returns end(), if the entry
194 couldn't be found. 197 couldn't be found.
195 */ 198 */
196 Iterator find( const Addressee & ); 199 Iterator find( const Addressee & );
197 200
198 /** 201 /**
199 Find the entry specified by an unique id. Returns an empty Addressee 202 Find the entry specified by an unique id. Returns an empty Addressee
200 object, if the address book does not contain an entry with this id. 203 object, if the address book does not contain an entry with this id.
201 */ 204 */
202 Addressee findByUid( const QString & ); 205 Addressee findByUid( const QString & );
203 206
204 207
205 /** 208 /**
206 Returns a list of all addressees in the address book. This list can 209 Returns a list of all addressees in the address book. This list can
207 be sorted with @ref KABC::AddresseeList for example. 210 be sorted with @ref KABC::AddresseeList for example.
208 */ 211 */
209 Addressee::List allAddressees(); 212 Addressee::List allAddressees();
210 213
211 /** 214 /**
212 Find all entries with the specified name in the address book. Returns 215 Find all entries with the specified name in the address book. Returns
213 an empty list, if no entries could be found. 216 an empty list, if no entries could be found.
214 */ 217 */
215 Addressee::List findByName( const QString & ); 218 Addressee::List findByName( const QString & );
216 219
217 /** 220 /**
218 Find all entries with the specified email address in the address book. 221 Find all entries with the specified email address in the address book.
219 Returns an empty list, if no entries could be found. 222 Returns an empty list, if no entries could be found.
220 */ 223 */
221 Addressee::List findByEmail( const QString & ); 224 Addressee::List findByEmail( const QString & );
222 225
223 /** 226 /**
224 Find all entries wich have the specified category in the address book. 227 Find all entries wich have the specified category in the address book.
225 Returns an empty list, if no entries could be found. 228 Returns an empty list, if no entries could be found.
226 */ 229 */
227 Addressee::List findByCategory( const QString & ); 230 Addressee::List findByCategory( const QString & );
228 231
229 /** 232 /**
230 Return a string identifying this addressbook. 233 Return a string identifying this addressbook.
231 */ 234 */
232 virtual QString identifier(); 235 virtual QString identifier();
233 236
234 /** 237 /**
235 Used for debug output. 238 Used for debug output.
236 */ 239 */
237 void dump() const; 240 void dump() const;
238 241
239 void emitAddressBookLocked() { emit addressBookLocked( this ); } 242 void emitAddressBookLocked() { emit addressBookLocked( this ); }
240 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } 243 void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }