summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 70eda1b..9332e21 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1,140 +1,141 @@
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 41
42#include <kglobal.h> 42#include <kglobal.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kdebug.h> 44#include <kdebug.h>
45#include <libkcal/syncdefines.h>
45#include "addressbook.h" 46#include "addressbook.h"
46#include "resource.h" 47#include "resource.h"
47 48
48//US #include "addressbook.moc" 49//US #include "addressbook.moc"
49 50
50using namespace KABC; 51using namespace KABC;
51 52
52struct AddressBook::AddressBookData 53struct AddressBook::AddressBookData
53{ 54{
54 Addressee::List mAddressees; 55 Addressee::List mAddressees;
55 Addressee::List mRemovedAddressees; 56 Addressee::List mRemovedAddressees;
56 Field::List mAllFields; 57 Field::List mAllFields;
57 KConfig *mConfig; 58 KConfig *mConfig;
58 KRES::Manager<Resource> *mManager; 59 KRES::Manager<Resource> *mManager;
59//US ErrorHandler *mErrorHandler; 60//US ErrorHandler *mErrorHandler;
60}; 61};
61 62
62struct AddressBook::Iterator::IteratorData 63struct AddressBook::Iterator::IteratorData
63{ 64{
64 Addressee::List::Iterator mIt; 65 Addressee::List::Iterator mIt;
65}; 66};
66 67
67struct AddressBook::ConstIterator::ConstIteratorData 68struct AddressBook::ConstIterator::ConstIteratorData
68{ 69{
69 Addressee::List::ConstIterator mIt; 70 Addressee::List::ConstIterator mIt;
70}; 71};
71 72
72AddressBook::Iterator::Iterator() 73AddressBook::Iterator::Iterator()
73{ 74{
74 d = new IteratorData; 75 d = new IteratorData;
75} 76}
76 77
77AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) 78AddressBook::Iterator::Iterator( const AddressBook::Iterator &i )
78{ 79{
79 d = new IteratorData; 80 d = new IteratorData;
80 d->mIt = i.d->mIt; 81 d->mIt = i.d->mIt;
81} 82}
82 83
83AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) 84AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i )
84{ 85{
85 if( this == &i ) return *this; // guard against self assignment 86 if( this == &i ) return *this; // guard against self assignment
86 delete d; // delete the old data the Iterator was completely constructed before 87 delete d; // delete the old data the Iterator was completely constructed before
87 d = new IteratorData; 88 d = new IteratorData;
88 d->mIt = i.d->mIt; 89 d->mIt = i.d->mIt;
89 return *this; 90 return *this;
90} 91}
91 92
92AddressBook::Iterator::~Iterator() 93AddressBook::Iterator::~Iterator()
93{ 94{
94 delete d; 95 delete d;
95} 96}
96 97
97const Addressee &AddressBook::Iterator::operator*() const 98const Addressee &AddressBook::Iterator::operator*() const
98{ 99{
99 return *(d->mIt); 100 return *(d->mIt);
100} 101}
101 102
102Addressee &AddressBook::Iterator::operator*() 103Addressee &AddressBook::Iterator::operator*()
103{ 104{
104 return *(d->mIt); 105 return *(d->mIt);
105} 106}
106 107
107Addressee *AddressBook::Iterator::operator->() 108Addressee *AddressBook::Iterator::operator->()
108{ 109{
109 return &(*(d->mIt)); 110 return &(*(d->mIt));
110} 111}
111 112
112AddressBook::Iterator &AddressBook::Iterator::operator++() 113AddressBook::Iterator &AddressBook::Iterator::operator++()
113{ 114{
114 (d->mIt)++; 115 (d->mIt)++;
115 return *this; 116 return *this;
116} 117}
117 118
118AddressBook::Iterator &AddressBook::Iterator::operator++(int) 119AddressBook::Iterator &AddressBook::Iterator::operator++(int)
119{ 120{
120 (d->mIt)++; 121 (d->mIt)++;
121 return *this; 122 return *this;
122} 123}
123 124
124AddressBook::Iterator &AddressBook::Iterator::operator--() 125AddressBook::Iterator &AddressBook::Iterator::operator--()
125{ 126{
126 (d->mIt)--; 127 (d->mIt)--;
127 return *this; 128 return *this;
128} 129}
129 130
130AddressBook::Iterator &AddressBook::Iterator::operator--(int) 131AddressBook::Iterator &AddressBook::Iterator::operator--(int)
131{ 132{
132 (d->mIt)--; 133 (d->mIt)--;
133 return *this; 134 return *this;
134} 135}
135 136
136bool AddressBook::Iterator::operator==( const Iterator &it ) 137bool AddressBook::Iterator::operator==( const Iterator &it )
137{ 138{
138 return ( d->mIt == it.d->mIt ); 139 return ( d->mIt == it.d->mIt );
139} 140}
140 141
@@ -419,192 +420,218 @@ AddressBook::ConstIterator AddressBook::end() const
419void AddressBook::clear() 420void AddressBook::clear()
420{ 421{
421 d->mAddressees.clear(); 422 d->mAddressees.clear();
422} 423}
423 424
424Ticket *AddressBook::requestSaveTicket( Resource *resource ) 425Ticket *AddressBook::requestSaveTicket( Resource *resource )
425{ 426{
426 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; 427 kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
427 428
428 if ( !resource ) 429 if ( !resource )
429 { 430 {
430 qDebug("AddressBook::requestSaveTicket no resource" ); 431 qDebug("AddressBook::requestSaveTicket no resource" );
431 resource = standardResource(); 432 resource = standardResource();
432 } 433 }
433 434
434 KRES::Manager<Resource>::ActiveIterator it; 435 KRES::Manager<Resource>::ActiveIterator it;
435 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 436 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
436 if ( (*it) == resource ) { 437 if ( (*it) == resource ) {
437 if ( (*it)->readOnly() || !(*it)->isOpen() ) 438 if ( (*it)->readOnly() || !(*it)->isOpen() )
438 return 0; 439 return 0;
439 else 440 else
440 return (*it)->requestSaveTicket(); 441 return (*it)->requestSaveTicket();
441 } 442 }
442 } 443 }
443 444
444 return 0; 445 return 0;
445} 446}
446 447
447void AddressBook::insertAddressee( const Addressee &a ) 448void AddressBook::insertAddressee( const Addressee &a )
448{ 449{
449 Addressee::List::Iterator it; 450 Addressee::List::Iterator it;
450 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { 451 for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
451 if ( a.uid() == (*it).uid() ) { 452 if ( a.uid() == (*it).uid() ) {
452 bool changed = false; 453 bool changed = false;
453 Addressee addr = a; 454 Addressee addr = a;
454 if ( addr != (*it) ) 455 if ( addr != (*it) )
455 changed = true; 456 changed = true;
456 457
457 (*it) = a; 458 (*it) = a;
458 if ( (*it).resource() == 0 ) 459 if ( (*it).resource() == 0 )
459 (*it).setResource( standardResource() ); 460 (*it).setResource( standardResource() );
460 461
461 if ( changed ) { 462 if ( changed ) {
462 (*it).setRevision( QDateTime::currentDateTime() ); 463 (*it).setRevision( QDateTime::currentDateTime() );
463 (*it).setChanged( true ); 464 (*it).setChanged( true );
464 } 465 }
465 466
466 return; 467 return;
467 } 468 }
468 } 469 }
469 d->mAddressees.append( a ); 470 d->mAddressees.append( a );
470 Addressee& addr = d->mAddressees.last(); 471 Addressee& addr = d->mAddressees.last();
471 if ( addr.resource() == 0 ) 472 if ( addr.resource() == 0 )
472 addr.setResource( standardResource() ); 473 addr.setResource( standardResource() );
473 474
474 addr.setChanged( true ); 475 addr.setChanged( true );
475} 476}
476 477
477void AddressBook::removeAddressee( const Addressee &a ) 478void AddressBook::removeAddressee( const Addressee &a )
478{ 479{
479 Iterator it; 480 Iterator it;
480 for ( it = begin(); it != end(); ++it ) { 481 for ( it = begin(); it != end(); ++it ) {
481 if ( a.uid() == (*it).uid() ) { 482 if ( a.uid() == (*it).uid() ) {
482 removeAddressee( it ); 483 removeAddressee( it );
483 return; 484 return;
484 } 485 }
485 } 486 }
486} 487}
487 488
488void AddressBook::removeAddressee( const Iterator &it ) 489void AddressBook::removeAddressee( const Iterator &it )
489{ 490{
490 d->mRemovedAddressees.append( (*it) ); 491 d->mRemovedAddressees.append( (*it) );
491 d->mAddressees.remove( it.d->mIt ); 492 d->mAddressees.remove( it.d->mIt );
492} 493}
493 494
494AddressBook::Iterator AddressBook::find( const Addressee &a ) 495AddressBook::Iterator AddressBook::find( const Addressee &a )
495{ 496{
496 Iterator it; 497 Iterator it;
497 for ( it = begin(); it != end(); ++it ) { 498 for ( it = begin(); it != end(); ++it ) {
498 if ( a.uid() == (*it).uid() ) { 499 if ( a.uid() == (*it).uid() ) {
499 return it; 500 return it;
500 } 501 }
501 } 502 }
502 return end(); 503 return end();
503} 504}
504 505
505Addressee AddressBook::findByUid( const QString &uid ) 506Addressee AddressBook::findByUid( const QString &uid )
506{ 507{
507 Iterator it; 508 Iterator it;
508 for ( it = begin(); it != end(); ++it ) { 509 for ( it = begin(); it != end(); ++it ) {
509 if ( uid == (*it).uid() ) { 510 if ( uid == (*it).uid() ) {
510 return *it; 511 return *it;
511 } 512 }
512 } 513 }
513 return Addressee(); 514 return Addressee();
514} 515}
516Addressee::List AddressBook::getExternLastSyncAddressees()
517{
518 Addressee::List results;
519
520 Iterator it;
521 for ( it = begin(); it != end(); ++it ) {
522 if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) {
523 if ( (*it).familyName().left(3) == "E: " )
524 results.append( *it );
525 }
526 }
527
528 return results;
529}
530void AddressBook::resetTempSyncStat()
531{
532
533
534 Iterator it;
535 for ( it = begin(); it != end(); ++it ) {
536 (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
537 }
538
539}
540
541
515 542
516Addressee::List AddressBook::allAddressees() 543Addressee::List AddressBook::allAddressees()
517{ 544{
518 return d->mAddressees; 545 return d->mAddressees;
519} 546}
520 547
521Addressee::List AddressBook::findByName( const QString &name ) 548Addressee::List AddressBook::findByName( const QString &name )
522{ 549{
523 Addressee::List results; 550 Addressee::List results;
524 551
525 Iterator it; 552 Iterator it;
526 for ( it = begin(); it != end(); ++it ) { 553 for ( it = begin(); it != end(); ++it ) {
527 if ( name == (*it).realName() ) { 554 if ( name == (*it).realName() ) {
528 results.append( *it ); 555 results.append( *it );
529 } 556 }
530 } 557 }
531 558
532 return results; 559 return results;
533} 560}
534 561
535Addressee::List AddressBook::findByEmail( const QString &email ) 562Addressee::List AddressBook::findByEmail( const QString &email )
536{ 563{
537 Addressee::List results; 564 Addressee::List results;
538 QStringList mailList; 565 QStringList mailList;
539 566
540 Iterator it; 567 Iterator it;
541 for ( it = begin(); it != end(); ++it ) { 568 for ( it = begin(); it != end(); ++it ) {
542 mailList = (*it).emails(); 569 mailList = (*it).emails();
543 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { 570 for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
544 if ( email == (*ite) ) { 571 if ( email == (*ite) ) {
545 results.append( *it ); 572 results.append( *it );
546 } 573 }
547 } 574 }
548 } 575 }
549 576
550 return results; 577 return results;
551} 578}
552 579
553Addressee::List AddressBook::findByCategory( const QString &category ) 580Addressee::List AddressBook::findByCategory( const QString &category )
554{ 581{
555 Addressee::List results; 582 Addressee::List results;
556 583
557 Iterator it; 584 Iterator it;
558 for ( it = begin(); it != end(); ++it ) { 585 for ( it = begin(); it != end(); ++it ) {
559 if ( (*it).hasCategory( category) ) { 586 if ( (*it).hasCategory( category) ) {
560 results.append( *it ); 587 results.append( *it );
561 } 588 }
562 } 589 }
563 590
564 return results; 591 return results;
565} 592}
566 593
567void AddressBook::dump() const 594void AddressBook::dump() const
568{ 595{
569 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; 596 kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
570 597
571 ConstIterator it; 598 ConstIterator it;
572 for( it = begin(); it != end(); ++it ) { 599 for( it = begin(); it != end(); ++it ) {
573 (*it).dump(); 600 (*it).dump();
574 } 601 }
575 602
576 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; 603 kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
577} 604}
578 605
579QString AddressBook::identifier() 606QString AddressBook::identifier()
580{ 607{
581 QStringList identifier; 608 QStringList identifier;
582 609
583 610
584 KRES::Manager<Resource>::ActiveIterator it; 611 KRES::Manager<Resource>::ActiveIterator it;
585 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { 612 for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
586 if ( !(*it)->identifier().isEmpty() ) 613 if ( !(*it)->identifier().isEmpty() )
587 identifier.append( (*it)->identifier() ); 614 identifier.append( (*it)->identifier() );
588 } 615 }
589 616
590 return identifier.join( ":" ); 617 return identifier.join( ":" );
591} 618}
592 619
593Field::List AddressBook::fields( int category ) 620Field::List AddressBook::fields( int category )
594{ 621{
595 if ( d->mAllFields.isEmpty() ) { 622 if ( d->mAllFields.isEmpty() ) {
596 d->mAllFields = Field::allFields(); 623 d->mAllFields = Field::allFields();
597 } 624 }
598 625
599 if ( category == Field::All ) return d->mAllFields; 626 if ( category == Field::All ) return d->mAllFields;
600 627
601 Field::List result; 628 Field::List result;
602 Field::List::ConstIterator it; 629 Field::List::ConstIterator it;
603 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { 630 for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
604 if ( (*it)->category() & category ) result.append( *it ); 631 if ( (*it)->category() & category ) result.append( *it );
605 } 632 }
606 633
607 return result; 634 return result;
608} 635}
609 636
610bool AddressBook::addCustomField( const QString &label, int category, 637bool AddressBook::addCustomField( const QString &label, int category,