summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
authorzautrix <zautrix>2004-09-19 11:32:40 (UTC)
committer zautrix <zautrix>2004-09-19 11:32:40 (UTC)
commiteea0ff04703dffdbe8b67a0dc9f592597d7450c1 (patch) (unidiff)
tree874549d9c1c6239304fe1540d1b56269652954c0 /kabc/addressbook.cpp
parent953277a85e6ec5630ab0d64b4d68815e4e4f9906 (diff)
downloadkdepimpi-eea0ff04703dffdbe8b67a0dc9f592597d7450c1.zip
kdepimpi-eea0ff04703dffdbe8b67a0dc9f592597d7450c1.tar.gz
kdepimpi-eea0ff04703dffdbe8b67a0dc9f592597d7450c1.tar.bz2
more AB sync
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 46a9cf4..64832f1 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -219,69 +219,72 @@ AddressBook::AddressBook()
219{ 219{
220 init(0, "contact"); 220 init(0, "contact");
221} 221}
222 222
223AddressBook::AddressBook( const QString &config ) 223AddressBook::AddressBook( const QString &config )
224{ 224{
225 init(config, "contact"); 225 init(config, "contact");
226} 226}
227 227
228AddressBook::AddressBook( const QString &config, const QString &family ) 228AddressBook::AddressBook( const QString &config, const QString &family )
229{ 229{
230 init(config, family); 230 init(config, family);
231 231
232} 232}
233 233
234// the default family is "contact" 234// the default family is "contact"
235void AddressBook::init(const QString &config, const QString &family ) 235void AddressBook::init(const QString &config, const QString &family )
236{ 236{
237 blockLSEchange = false; 237 blockLSEchange = false;
238 d = new AddressBookData; 238 d = new AddressBookData;
239 QString fami = family; 239 QString fami = family;
240 qDebug("new ab "); 240 qDebug("new ab ");
241 if (config != 0) { 241 if (config != 0) {
242 qDebug("config != 0 "); 242 qDebug("config != 0 ");
243 if ( family == "syncContact" ) { 243 if ( family == "syncContact" ) {
244 qDebug("creating sync config "); 244 qDebug("creating sync config ");
245 fami = "contact"; 245 fami = "contact";
246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); 246 KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
247 con->setGroup( "General" ); 247 con->setGroup( "General" );
248 con->writeEntry( "ResourceKeys", QString("sync") ); 248 con->writeEntry( "ResourceKeys", QString("sync") );
249 con->writeEntry( "Standard", QString("sync") ); 249 con->writeEntry( "Standard", QString("sync") );
250 con->setGroup( "Resource_sync" ); 250 con->setGroup( "Resource_sync" );
251 con->writeEntry( "FileFormat", QString("vcard") );
252 con->writeEntry( "FileName", config ); 251 con->writeEntry( "FileName", config );
252 con->writeEntry( "FileFormat", QString("vcard") );
253 con->writeEntry( "ResourceIdentifier", QString("sync") ); 253 con->writeEntry( "ResourceIdentifier", QString("sync") );
254 con->writeEntry( "ResourceName", QString("sync_res") ); 254 con->writeEntry( "ResourceName", QString("sync_res") );
255 con->writeEntry( "ResourceType", QString("file") ); 255 if ( config.right(4) == ".xml" )
256 con->writeEntry( "ResourceType", QString("qtopia") );
257 else
258 con->writeEntry( "ResourceType", QString("file") );
256 //con->sync(); 259 //con->sync();
257 d->mConfig = con; 260 d->mConfig = con;
258 } 261 }
259 else 262 else
260 d->mConfig = new KConfig( locateLocal("config", config) ); 263 d->mConfig = new KConfig( locateLocal("config", config) );
261// qDebug("AddressBook::init 1 config=%s",config.latin1() ); 264// qDebug("AddressBook::init 1 config=%s",config.latin1() );
262 } 265 }
263 else { 266 else {
264 d->mConfig = 0; 267 d->mConfig = 0;
265// qDebug("AddressBook::init 1 config=0"); 268// qDebug("AddressBook::init 1 config=0");
266 } 269 }
267 270
268//US d->mErrorHandler = 0; 271//US d->mErrorHandler = 0;
269 d->mManager = new KRES::Manager<Resource>( fami, false ); 272 d->mManager = new KRES::Manager<Resource>( fami, false );
270 d->mManager->readConfig( d->mConfig ); 273 d->mManager->readConfig( d->mConfig );
271 if ( family == "syncContact" ) { 274 if ( family == "syncContact" ) {
272 KRES::Manager<Resource> *manager = d->mManager; 275 KRES::Manager<Resource> *manager = d->mManager;
273 KRES::Manager<Resource>::ActiveIterator it; 276 KRES::Manager<Resource>::ActiveIterator it;
274 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 277 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
275 (*it)->setAddressBook( this ); 278 (*it)->setAddressBook( this );
276 if ( !(*it)->open() ) 279 if ( !(*it)->open() )
277 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 280 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
278 } 281 }
279 Resource *res = standardResource(); 282 Resource *res = standardResource();
280 if ( !res ) { 283 if ( !res ) {
281 qDebug("ERROR: no standard resource"); 284 qDebug("ERROR: no standard resource");
282 res = manager->createResource( "file" ); 285 res = manager->createResource( "file" );
283 if ( res ) 286 if ( res )
284 { 287 {
285 addResource( res ); 288 addResource( res );
286 } 289 }
287 else 290 else
@@ -570,64 +573,85 @@ void AddressBook::removeDeletedAddressees()
570 } 573 }
571 } 574 }
572 deleteRemovedAddressees(); 575 deleteRemovedAddressees();
573} 576}
574 577
575void AddressBook::removeAddressee( const Iterator &it ) 578void AddressBook::removeAddressee( const Iterator &it )
576{ 579{
577 d->mRemovedAddressees.append( (*it) ); 580 d->mRemovedAddressees.append( (*it) );
578 d->mAddressees.remove( it.d->mIt ); 581 d->mAddressees.remove( it.d->mIt );
579} 582}
580 583
581AddressBook::Iterator AddressBook::find( const Addressee &a ) 584AddressBook::Iterator AddressBook::find( const Addressee &a )
582{ 585{
583 Iterator it; 586 Iterator it;
584 for ( it = begin(); it != end(); ++it ) { 587 for ( it = begin(); it != end(); ++it ) {
585 if ( a.uid() == (*it).uid() ) { 588 if ( a.uid() == (*it).uid() ) {
586 return it; 589 return it;
587 } 590 }
588 } 591 }
589 return end(); 592 return end();
590} 593}
591 594
592Addressee AddressBook::findByUid( const QString &uid ) 595Addressee AddressBook::findByUid( const QString &uid )
593{ 596{
594 Iterator it; 597 Iterator it;
595 for ( it = begin(); it != end(); ++it ) { 598 for ( it = begin(); it != end(); ++it ) {
596 if ( uid == (*it).uid() ) { 599 if ( uid == (*it).uid() ) {
597 return *it; 600 return *it;
598 } 601 }
599 } 602 }
600 return Addressee(); 603 return Addressee();
601} 604}
605Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile )
606{
607 Iterator it;
608 for ( it = begin(); it != end(); ++it ) {
609 if ( uid == (*it).getID( profile ) )
610 return (*it);
611 }
612 return Addressee();
613}
614void AddressBook::mergeAB( AddressBook *aBook, const QString& profile )
615{
616 Iterator it;
617 Addressee ad;
618 for ( it = begin(); it != end(); ++it ) {
619 ad = aBook->findByExternUid( (*it).externalUID(), profile );
620 if ( !ad.isEmpty() ) {
621 (*it).mergeContact( ad );
622 }
623 }
624}
625
602#if 0 626#if 0
603Addressee::List AddressBook::getExternLastSyncAddressees() 627Addressee::List AddressBook::getExternLastSyncAddressees()
604{ 628{
605 Addressee::List results; 629 Addressee::List results;
606 630
607 Iterator it; 631 Iterator it;
608 for ( it = begin(); it != end(); ++it ) { 632 for ( it = begin(); it != end(); ++it ) {
609 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { 633 if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
610 if ( (*it).familyName().left(4) == "!E: " ) 634 if ( (*it).familyName().left(4) == "!E: " )
611 results.append( *it ); 635 results.append( *it );
612 } 636 }
613 } 637 }
614 638
615 return results; 639 return results;
616} 640}
617#endif 641#endif
618void AddressBook::resetTempSyncStat() 642void AddressBook::resetTempSyncStat()
619{ 643{
620 Iterator it; 644 Iterator it;
621 for ( it = begin(); it != end(); ++it ) { 645 for ( it = begin(); it != end(); ++it ) {
622 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); 646 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
623 } 647 }
624 648
625} 649}
626 650
627QStringList AddressBook:: uidList() 651QStringList AddressBook:: uidList()
628{ 652{
629 QStringList results; 653 QStringList results;
630 Iterator it; 654 Iterator it;
631 for ( it = begin(); it != end(); ++it ) { 655 for ( it = begin(); it != end(); ++it ) {
632 results.append( (*it).uid() ); 656 results.append( (*it).uid() );
633 } 657 }