00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KPIMIDENTITIES_IDENTITYMANAGER_H
00021 #define KPIMIDENTITIES_IDENTITYMANAGER_H
00022
00023 #include <kpimidentities/kpimidentities_export.h>
00024 #include <kconfiggroup.h>
00025 #include <QtCore/QObject>
00026
00027 class KConfigBase;
00028 class KConfig;
00029 class QStringList;
00030
00031 namespace KPIMIdentities
00032 {
00033
00034 class Identity;
00039 class KPIMIDENTITIES_EXPORT IdentityManager : public QObject
00040 {
00041 Q_OBJECT
00042 public:
00051 explicit IdentityManager( bool readonly = false, QObject *parent=0,
00052 const char *name=0 );
00053 virtual ~IdentityManager();
00054
00055 public:
00056 typedef QList<Identity>::Iterator Iterator;
00057 typedef QList<Identity>::ConstIterator ConstIterator;
00058
00062 typedef Iterator iterator;
00063
00067 typedef ConstIterator const_iterator;
00068
00070 QString makeUnique( const QString &name ) const;
00071
00073 bool isUnique( const QString &name ) const;
00074
00076 void commit();
00077
00079 void rollback();
00080
00082 bool hasPendingChanges() const;
00083
00085 QStringList identities() const;
00086
00092 QStringList shadowIdentities() const;
00093
00098 void sort();
00099
00103 const Identity &identityForAddress( const QString &addresses ) const;
00104
00109 bool thatIsMe( const QString &addressList ) const;
00110
00114 const Identity &identityForUoid( uint uoid ) const;
00115
00121 const Identity &identityForUoidOrDefault( uint uoid ) const;
00122
00124 const Identity &defaultIdentity() const;
00125
00132 bool setAsDefault( uint uoid );
00133
00138 Identity &modifyIdentityForName( const QString &identityName );
00139
00144 Identity &modifyIdentityForUoid( uint uoid );
00145
00150 bool removeIdentity( const QString &identityName );
00151
00161 bool removeIdentityForced( const QString &identityName );
00162
00163 ConstIterator begin() const;
00164 ConstIterator end() const;
00167 Iterator modifyBegin();
00168 Iterator modifyEnd();
00169
00170 Identity &newFromScratch( const QString &name );
00171 Identity &newFromControlCenter( const QString &name );
00172 Identity &newFromExisting( const Identity &other,
00173 const QString &name=QString() );
00174
00177 QStringList allEmails() const;
00178
00179 Q_SIGNALS:
00181 void changed();
00186 void changed( uint uoid );
00190 void changed( const KPIMIdentities::Identity &ident );
00194 void deleted( uint uoid );
00196 void added( const KPIMIdentities::Identity &ident );
00197
00198 protected:
00205 virtual void createDefaultIdentity( QString&,
00206 QString& ) {}
00207
00208 protected Q_SLOTS:
00209 void slotRollback();
00210
00211 protected:
00213 QList<Identity> mIdentities;
00215 QList<Identity> mShadowIdentities;
00216
00217 Q_SIGNALS:
00218 void identitiesChanged( const QString &id );
00219
00220 private Q_SLOTS:
00221
00222 void slotIdentitiesChanged( const QString &id );
00223
00224 private:
00225 void writeConfig() const;
00226 void readConfig( KConfig *config );
00227 QStringList groupList( KConfig *config ) const;
00228 void createDefaultIdentity();
00229
00230
00231 int newUoid();
00232
00233 private:
00234 KConfig *mConfig;
00235 bool mReadOnly;
00236 };
00237
00238 }
00239
00240 #endif // _KMAIL_IDENTITYMANAGER_H_