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 "kabc_export.h"
00025
00026 #include "addressee.h"
00027 #include "field.h"
00028
00029 #include "kresources/manager.h"
00030
00031 #include <QtCore/QObject>
00032 #include <QtCore/QList>
00033
00034 namespace KABC {
00035
00036 class DistributionList;
00037 class ErrorHandler;
00038 class Resource;
00039 class Ticket;
00040
00046 class KABC_EXPORT_DEPRECATED AddressBook : public QObject
00047 {
00048 Q_OBJECT
00049
00050 friend KABC_EXPORT QDataStream &operator<<( QDataStream &lhs,
00051 const AddressBook &rhs );
00052 friend KABC_EXPORT QDataStream &operator>>( QDataStream &lhs,
00053 AddressBook &rhs );
00054 friend class StdAddressBook;
00055
00056 public:
00057 class ConstIterator;
00058
00064 class KABC_EXPORT_DEPRECATED Iterator
00065 {
00066 friend class AddressBook;
00067 friend class ConstIterator;
00068 public:
00072 Iterator();
00073
00077 Iterator( const Iterator & );
00078 ~Iterator();
00079
00085 Iterator &operator=( const Iterator & );
00086
00093 const Addressee &operator*() const;
00094
00101 Addressee &operator*();
00102
00109 Addressee *operator->();
00110
00116 Iterator &operator++();
00117
00124 Iterator &operator++(int);
00125
00131 Iterator &operator--();
00132
00139 Iterator &operator--(int);
00140
00148 bool operator==( const Iterator &it ) const;
00149
00157 bool operator!=( const Iterator &it ) const;
00158
00159 private:
00160 struct IteratorData;
00161 IteratorData *const d;
00162 };
00163
00169 class KABC_EXPORT_DEPRECATED ConstIterator
00170 {
00171 friend class AddressBook;
00172 public:
00176 ConstIterator();
00177
00181 ConstIterator( const ConstIterator & );
00182
00183 #ifndef QT_STRICT_ITERATORS
00184
00188 ConstIterator( const Iterator & );
00189 #endif
00190
00191 ~ConstIterator();
00192
00198 ConstIterator &operator=( const ConstIterator & );
00199
00208 const Addressee &operator*() const;
00209
00216 const Addressee *operator->() const;
00217
00223 ConstIterator &operator++();
00224
00231 ConstIterator &operator++(int);
00232
00238 ConstIterator &operator--();
00239
00246 ConstIterator &operator--(int);
00247
00255 bool operator==( const ConstIterator &it ) const;
00256
00264 bool operator!=( const ConstIterator &it ) const;
00265
00266 private:
00267 struct ConstIteratorData;
00268 ConstIteratorData *const d;
00269 };
00270
00274 typedef Iterator iterator;
00275
00279 typedef ConstIterator const_iterator;
00280
00285 AddressBook();
00286
00293 AddressBook( const QString &config );
00294
00298 virtual ~AddressBook();
00299
00311 Ticket *requestSaveTicket( Resource *resource = 0 );
00312
00319 void releaseSaveTicket( Ticket *ticket );
00320
00326 bool load();
00327
00335 bool asyncLoad();
00336
00344 bool save( Ticket *ticket );
00345
00353 bool asyncSave( Ticket *ticket );
00354
00359 ConstIterator begin() const;
00360 ConstIterator constBegin() const { return begin(); }
00361
00366 Iterator begin();
00367
00372 ConstIterator end() const;
00373 ConstIterator constEnd() const { return end(); }
00374
00379 Iterator end();
00380
00384 void clear();
00385
00393 void insertAddressee( const Addressee &addr );
00394
00400 void removeAddressee( const Addressee &addr );
00401
00408 void removeAddressee( const Iterator &it );
00409
00416 Iterator find( const Addressee &addr );
00417
00424 ConstIterator find( const Addressee &addr ) const;
00425
00433 Addressee findByUid( const QString &uid ) const;
00434
00438 Addressee::List allAddressees() const;
00439
00446 Addressee::List findByName( const QString &name ) const;
00447
00454 Addressee::List findByEmail( const QString &email ) const;
00455
00462 Addressee::List findByCategory( const QString &category ) const;
00463
00477 DistributionList *createDistributionList( const QString &name, Resource *resource = 0 );
00478
00484 void removeDistributionList( DistributionList *list );
00485
00491 DistributionList *findDistributionListByIdentifier( const QString &identifier );
00492
00500 DistributionList *findDistributionListByName(
00501 const QString &name,
00502 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive );
00503
00508 QList<DistributionList*> allDistributionLists();
00509
00517 QStringList allDistributionListNames() const;
00518
00523 virtual QString identifier() const;
00524
00529 Field::List fields( int category = Field::All ) const;
00530
00540 bool addCustomField( const QString &label, int category = Field::All,
00541 const QString &key = QString(),
00542 const QString &app = QString() ) const;
00543
00550 bool addResource( Resource *resource );
00551
00558 bool removeResource( Resource *resource );
00559
00563 QList<Resource*> resources() const;
00564
00571 void setErrorHandler( ErrorHandler *errorHandler );
00572
00578 void error( const QString &msg );
00579
00584 void dump() const;
00585
00589 void emitAddressBookLocked() { addressBookLocked( this ); }
00593 void emitAddressBookUnlocked() { addressBookUnlocked( this ); }
00597 void emitAddressBookChanged() { addressBookChanged( this ); }
00598
00603 bool loadingHasFinished() const;
00604
00605 Q_SIGNALS:
00614 void addressBookChanged( AddressBook *addressBook );
00615
00621 void addressBookLocked( AddressBook *addressBook );
00622
00631 void addressBookUnlocked( AddressBook *addressBook );
00632
00639 void loadingFinished( Resource *resource );
00640
00647 void savingFinished( Resource *resource );
00648
00649 protected Q_SLOTS:
00660 void resourceLoadingFinished( Resource *resource );
00661
00669 void resourceSavingFinished( Resource *resource );
00670
00681 void resourceLoadingError( Resource *resource, const QString &errMsg );
00682
00691 void resourceSavingError( Resource *resource, const QString &errMsg );
00692
00693 protected:
00703 void setStandardResource( Resource *resource );
00704
00712 Resource *standardResource();
00713
00717 KRES::Manager<Resource> *resourceManager();
00718
00719 private:
00720 class Private;
00721 Private *const d;
00722 };
00723
00724 KABC_EXPORT QDataStream &operator<<( QDataStream &lhs, const AddressBook &rhs );
00725 KABC_EXPORT QDataStream &operator>>( QDataStream &lhs, AddressBook &rhs );
00726
00727 }
00728
00729 #endif