kabc
addressbook.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KABC_ADDRESSBOOK_H
00022 #define KABC_ADDRESSBOOK_H
00023
00024 #include "addressee.h"
00025 #include "field.h"
00026
00027 #include "kresources/manager.h"
00028
00029 #include <QtCore/QObject>
00030 #include <QtCore/QList>
00031
00032 namespace KABC {
00033
00034 class DistributionList;
00035 class ErrorHandler;
00036 class Resource;
00037 class Ticket;
00038
00044 class KABC_EXPORT AddressBook : public QObject
00045 {
00046 Q_OBJECT
00047
00048 friend KABC_EXPORT QDataStream &operator<<( QDataStream &lhs,
00049 const AddressBook &rhs );
00050 friend KABC_EXPORT QDataStream &operator>>( QDataStream &lhs,
00051 AddressBook &rhs );
00052 friend class StdAddressBook;
00053
00054 public:
00055 class ConstIterator;
00056
00062 class KABC_EXPORT Iterator
00063 {
00064 friend class AddressBook;
00065 friend class ConstIterator;
00066 public:
00070 Iterator();
00071
00075 Iterator( const Iterator & );
00076 ~Iterator();
00077
00083 Iterator &operator=( const Iterator & );
00084
00091 const Addressee &operator*() const;
00092
00099 Addressee &operator*();
00100
00107 Addressee *operator->();
00108
00114 Iterator &operator++();
00115
00122 Iterator &operator++(int);
00123
00129 Iterator &operator--();
00130
00137 Iterator &operator--(int);
00138
00146 bool operator==( const Iterator &it ) const;
00147
00155 bool operator!=( const Iterator &it ) const;
00156
00157 private:
00158 struct IteratorData;
00159 IteratorData *const d;
00160 };
00161
00167 class KABC_EXPORT ConstIterator
00168 {
00169 friend class AddressBook;
00170 public:
00174 ConstIterator();
00175
00179 ConstIterator( const ConstIterator & );
00180
00185 ConstIterator( const Iterator & );
00186 ~ConstIterator();
00187
00193 ConstIterator &operator=( const ConstIterator & );
00194
00203 const Addressee &operator*() const;
00204
00211 const Addressee *operator->() const;
00212
00218 ConstIterator &operator++();
00219
00226 ConstIterator &operator++(int);
00227
00233 ConstIterator &operator--();
00234
00241 ConstIterator &operator--(int);
00242
00250 bool operator==( const ConstIterator &it ) const;
00251
00259 bool operator!=( const ConstIterator &it ) const;
00260
00261 private:
00262 struct ConstIteratorData;
00263 ConstIteratorData *const d;
00264 };
00265
00269 typedef Iterator iterator;
00270
00274 typedef ConstIterator const_iterator;
00275
00280 AddressBook();
00281
00288 AddressBook( const QString &config );
00289
00293 virtual ~AddressBook();
00294
00306 Ticket *requestSaveTicket( Resource *resource = 0 );
00307
00314 void releaseSaveTicket( Ticket *ticket );
00315
00321 bool load();
00322
00330 bool asyncLoad();
00331
00339 bool save( Ticket *ticket );
00340
00348 bool asyncSave( Ticket *ticket );
00349
00354 ConstIterator begin() const;
00355
00360 Iterator begin();
00361
00366 ConstIterator end() const;
00367
00372 Iterator end();
00373
00377 void clear();
00378
00386 void insertAddressee( const Addressee &addr );
00387
00393 void removeAddressee( const Addressee &addr );
00394
00401 void removeAddressee( const Iterator &it );
00402
00409 Iterator find( const Addressee &addr );
00410
00417 ConstIterator find( const Addressee &addr ) const;
00418
00426 Addressee findByUid( const QString &uid ) const;
00427
00431 Addressee::List allAddressees() const;
00432
00439 Addressee::List findByName( const QString &name ) const;
00440
00447 Addressee::List findByEmail( const QString &email ) const;
00448
00455 Addressee::List findByCategory( const QString &category ) const;
00456
00470 DistributionList* createDistributionList( const QString &name, Resource* resource = 0 );
00471
00477 void removeDistributionList( DistributionList *list );
00478
00484 DistributionList* findDistributionListByIdentifier( const QString &identifier );
00485
00493 DistributionList* findDistributionListByName( const QString &name, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive );
00494
00499 QList<DistributionList*> allDistributionLists();
00500
00508 QStringList allDistributionListNames() const;
00509
00514 virtual QString identifier() const;
00515
00520 Field::List fields( int category = Field::All ) const;
00521
00531 bool addCustomField( const QString &label, int category = Field::All,
00532 const QString &key = QString(),
00533 const QString &app = QString() ) const;
00534
00541 bool addResource( Resource *resource );
00542
00549 bool removeResource( Resource *resource );
00550
00554 QList<Resource*> resources() const;
00555
00562 void setErrorHandler( ErrorHandler *errorHandler );
00563
00569 void error( const QString &msg );
00570
00575 void dump() const;
00576
00580 void emitAddressBookLocked() { addressBookLocked( this ); }
00584 void emitAddressBookUnlocked() { addressBookUnlocked( this ); }
00588 void emitAddressBookChanged() { addressBookChanged( this ); }
00589
00594 bool loadingHasFinished() const;
00595
00596 Q_SIGNALS:
00605 void addressBookChanged( AddressBook *addressBook );
00606
00612 void addressBookLocked( AddressBook *addressBook );
00613
00622 void addressBookUnlocked( AddressBook *addressBook );
00623
00630 void loadingFinished( Resource *resource );
00631
00638 void savingFinished( Resource *resource );
00639
00640 protected Q_SLOTS:
00651 void resourceLoadingFinished( Resource *resource );
00652
00660 void resourceSavingFinished( Resource *resource );
00661
00672 void resourceLoadingError( Resource *resource, const QString &errMsg );
00673
00682 void resourceSavingError( Resource *resource, const QString &errMsg );
00683
00684 protected:
00694 void setStandardResource( Resource *resource );
00695
00703 Resource *standardResource();
00704
00708 KRES::Manager<Resource> *resourceManager();
00709
00710 private:
00711 class Private;
00712 Private *const d;
00713 };
00714
00715 KABC_EXPORT QDataStream &operator<<( QDataStream &lhs, const AddressBook &rhs );
00716 KABC_EXPORT QDataStream &operator>>( QDataStream &lhs, AddressBook &rhs );
00717
00718 }
00719
00720 #endif