-rw-r--r-- | kabc/addressbook.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index adb451f..5fb49eb 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -176,131 +176,129 @@ const Addressee &AddressBook::ConstIterator::operator*() const | |||
176 | } | 176 | } |
177 | 177 | ||
178 | const Addressee* AddressBook::ConstIterator::operator->() const | 178 | const Addressee* AddressBook::ConstIterator::operator->() const |
179 | { | 179 | { |
180 | return &(*(d->mIt)); | 180 | return &(*(d->mIt)); |
181 | } | 181 | } |
182 | 182 | ||
183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
184 | { | 184 | { |
185 | (d->mIt)++; | 185 | (d->mIt)++; |
186 | return *this; | 186 | return *this; |
187 | } | 187 | } |
188 | 188 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
190 | { | 190 | { |
191 | (d->mIt)++; | 191 | (d->mIt)++; |
192 | return *this; | 192 | return *this; |
193 | } | 193 | } |
194 | 194 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
196 | { | 196 | { |
197 | (d->mIt)--; | 197 | (d->mIt)--; |
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
202 | { | 202 | { |
203 | (d->mIt)--; | 203 | (d->mIt)--; |
204 | return *this; | 204 | return *this; |
205 | } | 205 | } |
206 | 206 | ||
207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
208 | { | 208 | { |
209 | return ( d->mIt == it.d->mIt ); | 209 | return ( d->mIt == it.d->mIt ); |
210 | } | 210 | } |
211 | 211 | ||
212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
213 | { | 213 | { |
214 | return ( d->mIt != it.d->mIt ); | 214 | return ( d->mIt != it.d->mIt ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | AddressBook::AddressBook() | 218 | AddressBook::AddressBook() |
219 | { | 219 | { |
220 | init(0, "contact"); | 220 | init(0, "contact"); |
221 | } | 221 | } |
222 | 222 | ||
223 | AddressBook::AddressBook( const QString &config ) | 223 | AddressBook::AddressBook( const QString &config ) |
224 | { | 224 | { |
225 | init(config, "contact"); | 225 | init(config, "contact"); |
226 | } | 226 | } |
227 | 227 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 228 | AddressBook::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" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 235 | void 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 "); | ||
241 | if (config != 0) { | 240 | if (config != 0) { |
242 | qDebug("config != 0 "); | ||
243 | if ( family == "syncContact" ) { | 241 | if ( family == "syncContact" ) { |
244 | qDebug("creating sync config "); | 242 | qDebug("creating sync config "); |
245 | fami = "contact"; | 243 | fami = "contact"; |
246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 244 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
247 | con->setGroup( "General" ); | 245 | con->setGroup( "General" ); |
248 | con->writeEntry( "ResourceKeys", QString("sync") ); | 246 | con->writeEntry( "ResourceKeys", QString("sync") ); |
249 | con->writeEntry( "Standard", QString("sync") ); | 247 | con->writeEntry( "Standard", QString("sync") ); |
250 | con->setGroup( "Resource_sync" ); | 248 | con->setGroup( "Resource_sync" ); |
251 | con->writeEntry( "FileName", config ); | 249 | con->writeEntry( "FileName", config ); |
252 | con->writeEntry( "FileFormat", QString("vcard") ); | 250 | con->writeEntry( "FileFormat", QString("vcard") ); |
253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 251 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
254 | con->writeEntry( "ResourceName", QString("sync_res") ); | 252 | con->writeEntry( "ResourceName", QString("sync_res") ); |
255 | if ( config.right(4) == ".xml" ) | 253 | if ( config.right(4) == ".xml" ) |
256 | con->writeEntry( "ResourceType", QString("qtopia") ); | 254 | con->writeEntry( "ResourceType", QString("qtopia") ); |
257 | else if ( config == "sharp" ) { | 255 | else if ( config == "sharp" ) { |
258 | con->writeEntry( "ResourceType", QString("sharp") ); | 256 | con->writeEntry( "ResourceType", QString("sharp") ); |
259 | } else { | 257 | } else { |
260 | con->writeEntry( "ResourceType", QString("file") ); | 258 | con->writeEntry( "ResourceType", QString("file") ); |
261 | } | 259 | } |
262 | //con->sync(); | 260 | //con->sync(); |
263 | d->mConfig = con; | 261 | d->mConfig = con; |
264 | } | 262 | } |
265 | else | 263 | else |
266 | d->mConfig = new KConfig( locateLocal("config", config) ); | 264 | d->mConfig = new KConfig( locateLocal("config", config) ); |
267 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 265 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
268 | } | 266 | } |
269 | else { | 267 | else { |
270 | d->mConfig = 0; | 268 | d->mConfig = 0; |
271 | // qDebug("AddressBook::init 1 config=0"); | 269 | // qDebug("AddressBook::init 1 config=0"); |
272 | } | 270 | } |
273 | 271 | ||
274 | //US d->mErrorHandler = 0; | 272 | //US d->mErrorHandler = 0; |
275 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 273 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
276 | d->mManager->readConfig( d->mConfig ); | 274 | d->mManager->readConfig( d->mConfig ); |
277 | if ( family == "syncContact" ) { | 275 | if ( family == "syncContact" ) { |
278 | KRES::Manager<Resource> *manager = d->mManager; | 276 | KRES::Manager<Resource> *manager = d->mManager; |
279 | KRES::Manager<Resource>::ActiveIterator it; | 277 | KRES::Manager<Resource>::ActiveIterator it; |
280 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 278 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
281 | (*it)->setAddressBook( this ); | 279 | (*it)->setAddressBook( this ); |
282 | if ( !(*it)->open() ) | 280 | if ( !(*it)->open() ) |
283 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 281 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
284 | } | 282 | } |
285 | Resource *res = standardResource(); | 283 | Resource *res = standardResource(); |
286 | if ( !res ) { | 284 | if ( !res ) { |
287 | qDebug("ERROR: no standard resource"); | 285 | qDebug("ERROR: no standard resource"); |
288 | res = manager->createResource( "file" ); | 286 | res = manager->createResource( "file" ); |
289 | if ( res ) | 287 | if ( res ) |
290 | { | 288 | { |
291 | addResource( res ); | 289 | addResource( res ); |
292 | } | 290 | } |
293 | else | 291 | else |
294 | qDebug(" No resource available!!!"); | 292 | qDebug(" No resource available!!!"); |
295 | } | 293 | } |
296 | setStandardResource( res ); | 294 | setStandardResource( res ); |
297 | manager->writeConfig(); | 295 | manager->writeConfig(); |
298 | } | 296 | } |
299 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 297 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
300 | "X-Department", "KADDRESSBOOK" ); | 298 | "X-Department", "KADDRESSBOOK" ); |
301 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 299 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
302 | "X-Profession", "KADDRESSBOOK" ); | 300 | "X-Profession", "KADDRESSBOOK" ); |
303 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 301 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
304 | "X-AssistantsName", "KADDRESSBOOK" ); | 302 | "X-AssistantsName", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 303 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
306 | "X-ManagersName", "KADDRESSBOOK" ); | 304 | "X-ManagersName", "KADDRESSBOOK" ); |
@@ -545,142 +543,142 @@ void AddressBook::removeAddressee( const Addressee &a ) | |||
545 | (*it).setNote( des ); | 543 | (*it).setNote( des ); |
546 | } | 544 | } |
547 | } | 545 | } |
548 | } | 546 | } |
549 | 547 | ||
550 | } | 548 | } |
551 | } | 549 | } |
552 | 550 | ||
553 | if ( found ) | 551 | if ( found ) |
554 | removeAddressee( it2 ); | 552 | removeAddressee( it2 ); |
555 | 553 | ||
556 | } | 554 | } |
557 | 555 | ||
558 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 556 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
559 | { | 557 | { |
560 | Iterator it = begin(); | 558 | Iterator it = begin(); |
561 | Iterator it2 ; | 559 | Iterator it2 ; |
562 | QDateTime dt ( QDate( 2004,1,1) ); | 560 | QDateTime dt ( QDate( 2004,1,1) ); |
563 | while ( it != end() ) { | 561 | while ( it != end() ) { |
564 | (*it).setRevision( dt ); | 562 | (*it).setRevision( dt ); |
565 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 563 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
566 | (*it).setIDStr(""); | 564 | (*it).setIDStr(""); |
567 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 565 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
568 | it2 = it; | 566 | it2 = it; |
569 | //qDebug("removing %s ",(*it).uid().latin1() ); | 567 | //qDebug("removing %s ",(*it).uid().latin1() ); |
570 | ++it; | 568 | ++it; |
571 | removeAddressee( it2 ); | 569 | removeAddressee( it2 ); |
572 | } else { | 570 | } else { |
573 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 571 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
574 | ++it; | 572 | ++it; |
575 | } | 573 | } |
576 | } | 574 | } |
577 | deleteRemovedAddressees(); | 575 | deleteRemovedAddressees(); |
578 | } | 576 | } |
579 | 577 | ||
580 | void AddressBook::removeAddressee( const Iterator &it ) | 578 | void AddressBook::removeAddressee( const Iterator &it ) |
581 | { | 579 | { |
582 | d->mRemovedAddressees.append( (*it) ); | 580 | d->mRemovedAddressees.append( (*it) ); |
583 | d->mAddressees.remove( it.d->mIt ); | 581 | d->mAddressees.remove( it.d->mIt ); |
584 | } | 582 | } |
585 | 583 | ||
586 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 584 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
587 | { | 585 | { |
588 | Iterator it; | 586 | Iterator it; |
589 | for ( it = begin(); it != end(); ++it ) { | 587 | for ( it = begin(); it != end(); ++it ) { |
590 | if ( a.uid() == (*it).uid() ) { | 588 | if ( a.uid() == (*it).uid() ) { |
591 | return it; | 589 | return it; |
592 | } | 590 | } |
593 | } | 591 | } |
594 | return end(); | 592 | return end(); |
595 | } | 593 | } |
596 | 594 | ||
597 | Addressee AddressBook::findByUid( const QString &uid ) | 595 | Addressee AddressBook::findByUid( const QString &uid ) |
598 | { | 596 | { |
599 | Iterator it; | 597 | Iterator it; |
600 | for ( it = begin(); it != end(); ++it ) { | 598 | for ( it = begin(); it != end(); ++it ) { |
601 | if ( uid == (*it).uid() ) { | 599 | if ( uid == (*it).uid() ) { |
602 | return *it; | 600 | return *it; |
603 | } | 601 | } |
604 | } | 602 | } |
605 | return Addressee(); | 603 | return Addressee(); |
606 | } | 604 | } |
607 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 605 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
608 | { | 606 | { |
609 | qDebug("AddressBook::preExternSync "); | 607 | //qDebug("AddressBook::preExternSync "); |
610 | AddressBook::Iterator it; | 608 | AddressBook::Iterator it; |
611 | for ( it = begin(); it != end(); ++it ) { | 609 | for ( it = begin(); it != end(); ++it ) { |
612 | (*it).setID( csd, (*it).externalUID() ); | 610 | (*it).setID( csd, (*it).externalUID() ); |
613 | (*it).computeCsum( csd ); | 611 | (*it).computeCsum( csd ); |
614 | } | 612 | } |
615 | mergeAB( aBook ,csd ); | 613 | mergeAB( aBook ,csd ); |
616 | } | 614 | } |
617 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 615 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
618 | { | 616 | { |
619 | qDebug("AddressBook::postExternSync "); | 617 | //qDebug("AddressBook::postExternSync "); |
620 | AddressBook::Iterator it; | 618 | AddressBook::Iterator it; |
621 | for ( it = begin(); it != end(); ++it ) { | 619 | for ( it = begin(); it != end(); ++it ) { |
622 | qDebug("check uid %s ", (*it).uid().latin1() ); | 620 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
623 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 621 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
624 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 622 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
625 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 623 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
626 | if ( ad.isEmpty() ) { | 624 | if ( ad.isEmpty() ) { |
627 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 625 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
628 | } else { | 626 | } else { |
629 | (*it).computeCsum( csd ); | 627 | (*it).computeCsum( csd ); |
630 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 628 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
631 | ad.setID( csd, (*it).externalUID() ); | 629 | ad.setID( csd, (*it).externalUID() ); |
632 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 630 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
633 | aBook->insertAddressee( ad ); | 631 | aBook->insertAddressee( ad ); |
634 | } | 632 | } |
635 | } | 633 | } |
636 | } | 634 | } |
637 | } | 635 | } |
638 | 636 | ||
639 | bool AddressBook::containsExternalUid( const QString& uid ) | 637 | bool AddressBook::containsExternalUid( const QString& uid ) |
640 | { | 638 | { |
641 | Iterator it; | 639 | Iterator it; |
642 | for ( it = begin(); it != end(); ++it ) { | 640 | for ( it = begin(); it != end(); ++it ) { |
643 | if ( uid == (*it).externalUID( ) ) | 641 | if ( uid == (*it).externalUID( ) ) |
644 | return true; | 642 | return true; |
645 | } | 643 | } |
646 | return false; | 644 | return false; |
647 | } | 645 | } |
648 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 646 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
649 | { | 647 | { |
650 | Iterator it; | 648 | Iterator it; |
651 | for ( it = begin(); it != end(); ++it ) { | 649 | for ( it = begin(); it != end(); ++it ) { |
652 | if ( uid == (*it).getID( profile ) ) | 650 | if ( uid == (*it).getID( profile ) ) |
653 | return (*it); | 651 | return (*it); |
654 | } | 652 | } |
655 | return Addressee(); | 653 | return Addressee(); |
656 | } | 654 | } |
657 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 655 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
658 | { | 656 | { |
659 | Iterator it; | 657 | Iterator it; |
660 | Addressee ad; | 658 | Addressee ad; |
661 | for ( it = begin(); it != end(); ++it ) { | 659 | for ( it = begin(); it != end(); ++it ) { |
662 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 660 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
663 | if ( !ad.isEmpty() ) { | 661 | if ( !ad.isEmpty() ) { |
664 | (*it).mergeContact( ad ); | 662 | (*it).mergeContact( ad ); |
665 | } | 663 | } |
666 | } | 664 | } |
667 | #if 0 | 665 | #if 0 |
668 | // test only | 666 | // test only |
669 | for ( it = begin(); it != end(); ++it ) { | 667 | for ( it = begin(); it != end(); ++it ) { |
670 | 668 | ||
671 | qDebug("uid %s ", (*it).uid().latin1()); | 669 | qDebug("uid %s ", (*it).uid().latin1()); |
672 | } | 670 | } |
673 | #endif | 671 | #endif |
674 | } | 672 | } |
675 | 673 | ||
676 | #if 0 | 674 | #if 0 |
677 | Addressee::List AddressBook::getExternLastSyncAddressees() | 675 | Addressee::List AddressBook::getExternLastSyncAddressees() |
678 | { | 676 | { |
679 | Addressee::List results; | 677 | Addressee::List results; |
680 | 678 | ||
681 | Iterator it; | 679 | Iterator it; |
682 | for ( it = begin(); it != end(); ++it ) { | 680 | for ( it = begin(); it != end(); ++it ) { |
683 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 681 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
684 | if ( (*it).familyName().left(4) == "!E: " ) | 682 | if ( (*it).familyName().left(4) == "!E: " ) |
685 | results.append( *it ); | 683 | results.append( *it ); |
686 | } | 684 | } |