-rw-r--r-- | kabc/addressbook.cpp | 28 |
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 | |||
@@ -187,133 +187,136 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | |||
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 "); | 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 |
288 | qDebug(" No resource available!!!"); | 291 | qDebug(" No resource available!!!"); |
289 | } | 292 | } |
290 | setStandardResource( res ); | 293 | setStandardResource( res ); |
291 | manager->writeConfig(); | 294 | manager->writeConfig(); |
292 | } | 295 | } |
293 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 296 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
294 | "X-Department", "KADDRESSBOOK" ); | 297 | "X-Department", "KADDRESSBOOK" ); |
295 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 298 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
296 | "X-Profession", "KADDRESSBOOK" ); | 299 | "X-Profession", "KADDRESSBOOK" ); |
297 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 300 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
298 | "X-AssistantsName", "KADDRESSBOOK" ); | 301 | "X-AssistantsName", "KADDRESSBOOK" ); |
299 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 302 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
300 | "X-ManagersName", "KADDRESSBOOK" ); | 303 | "X-ManagersName", "KADDRESSBOOK" ); |
301 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 304 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
302 | "X-SpousesName", "KADDRESSBOOK" ); | 305 | "X-SpousesName", "KADDRESSBOOK" ); |
303 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 306 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
304 | "X-Office", "KADDRESSBOOK" ); | 307 | "X-Office", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 308 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
306 | "X-IMAddress", "KADDRESSBOOK" ); | 309 | "X-IMAddress", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 310 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
308 | "X-Anniversary", "KADDRESSBOOK" ); | 311 | "X-Anniversary", "KADDRESSBOOK" ); |
309 | 312 | ||
310 | //US added this field to become compatible with Opie/qtopia addressbook | 313 | //US added this field to become compatible with Opie/qtopia addressbook |
311 | // values can be "female" or "male" or "". An empty field represents undefined. | 314 | // values can be "female" or "male" or "". An empty field represents undefined. |
312 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 315 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
313 | "X-Gender", "KADDRESSBOOK" ); | 316 | "X-Gender", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 317 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
315 | "X-Children", "KADDRESSBOOK" ); | 318 | "X-Children", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 319 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
317 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 320 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
319 | "X-ExternalID", "KADDRESSBOOK" ); | 322 | "X-ExternalID", "KADDRESSBOOK" ); |
@@ -538,128 +541,149 @@ void AddressBook::removeAddressee( const Addressee &a ) | |||
538 | des += id + ","; | 541 | des += id + ","; |
539 | (*it).setNote( des ); | 542 | (*it).setNote( des ); |
540 | } | 543 | } |
541 | } | 544 | } |
542 | } | 545 | } |
543 | 546 | ||
544 | } | 547 | } |
545 | } | 548 | } |
546 | 549 | ||
547 | if ( found ) | 550 | if ( found ) |
548 | removeAddressee( it2 ); | 551 | removeAddressee( it2 ); |
549 | 552 | ||
550 | } | 553 | } |
551 | 554 | ||
552 | void AddressBook::removeDeletedAddressees() | 555 | void AddressBook::removeDeletedAddressees() |
553 | { | 556 | { |
554 | deleteRemovedAddressees(); | 557 | deleteRemovedAddressees(); |
555 | Iterator it = begin(); | 558 | Iterator it = begin(); |
556 | Iterator it2 ; | 559 | Iterator it2 ; |
557 | QDateTime dt ( QDate( 2004,1,1) ); | 560 | QDateTime dt ( QDate( 2004,1,1) ); |
558 | while ( it != end() ) { | 561 | while ( it != end() ) { |
559 | (*it).setRevision( dt ); | 562 | (*it).setRevision( dt ); |
560 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 563 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
561 | (*it).setIDStr(""); | 564 | (*it).setIDStr(""); |
562 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 565 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
563 | it2 = it; | 566 | it2 = it; |
564 | //qDebug("removing %s ",(*it).uid().latin1() ); | 567 | //qDebug("removing %s ",(*it).uid().latin1() ); |
565 | ++it; | 568 | ++it; |
566 | removeAddressee( it2 ); | 569 | removeAddressee( it2 ); |
567 | } else { | 570 | } else { |
568 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 571 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
569 | ++it; | 572 | ++it; |
570 | } | 573 | } |
571 | } | 574 | } |
572 | deleteRemovedAddressees(); | 575 | deleteRemovedAddressees(); |
573 | } | 576 | } |
574 | 577 | ||
575 | void AddressBook::removeAddressee( const Iterator &it ) | 578 | void 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 | ||
581 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 584 | AddressBook::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 | ||
592 | Addressee AddressBook::findByUid( const QString &uid ) | 595 | Addressee 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 | } |
605 | Addressee 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 | } | ||
614 | void 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 |
603 | Addressee::List AddressBook::getExternLastSyncAddressees() | 627 | Addressee::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 |
618 | void AddressBook::resetTempSyncStat() | 642 | void 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 | ||
627 | QStringList AddressBook:: uidList() | 651 | QStringList 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 | } |
634 | return results; | 658 | return results; |
635 | } | 659 | } |
636 | 660 | ||
637 | 661 | ||
638 | Addressee::List AddressBook::allAddressees() | 662 | Addressee::List AddressBook::allAddressees() |
639 | { | 663 | { |
640 | return d->mAddressees; | 664 | return d->mAddressees; |
641 | 665 | ||
642 | } | 666 | } |
643 | 667 | ||
644 | Addressee::List AddressBook::findByName( const QString &name ) | 668 | Addressee::List AddressBook::findByName( const QString &name ) |
645 | { | 669 | { |
646 | Addressee::List results; | 670 | Addressee::List results; |
647 | 671 | ||
648 | Iterator it; | 672 | Iterator it; |
649 | for ( it = begin(); it != end(); ++it ) { | 673 | for ( it = begin(); it != end(); ++it ) { |
650 | if ( name == (*it).realName() ) { | 674 | if ( name == (*it).realName() ) { |
651 | results.append( *it ); | 675 | results.append( *it ); |
652 | } | 676 | } |
653 | } | 677 | } |
654 | 678 | ||
655 | return results; | 679 | return results; |
656 | } | 680 | } |
657 | 681 | ||
658 | Addressee::List AddressBook::findByEmail( const QString &email ) | 682 | Addressee::List AddressBook::findByEmail( const QString &email ) |
659 | { | 683 | { |
660 | Addressee::List results; | 684 | Addressee::List results; |
661 | QStringList mailList; | 685 | QStringList mailList; |
662 | 686 | ||
663 | Iterator it; | 687 | Iterator it; |
664 | for ( it = begin(); it != end(); ++it ) { | 688 | for ( it = begin(); it != end(); ++it ) { |
665 | mailList = (*it).emails(); | 689 | mailList = (*it).emails(); |