libkpimidentities

identitymanager.h
00001 /*  -*- c++ -*-
00002     identitymanager.h
00003 
00004     This file is part of KMail, the KDE mail client.
00005     Copyright (c) 2002 Marc Mutz <mutz@kde.org>
00006 
00007     KMail is free software; you can redistribute it and/or modify it
00008     under the terms of the GNU General Public License, version 2, as
00009     published by the Free Software Foundation.
00010 
00011     KMail is distributed in the hope that it will be useful, but
00012     WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020     In addition, as a special exception, the copyright holders give
00021     permission to link the code of this program with any edition of
00022     the TQt library by Trolltech AS, Norway (or with modified versions
00023     of TQt that use the same license as TQt), and distribute linked
00024     combinations including the two.  You must obey the GNU General
00025     Public License in all respects for all of the code used other than
00026     TQt.  If you modify this file, you may extend this exception to
00027     your version of the file, but you are not obligated to do so.  If
00028     you do not wish to do so, delete this exception statement from
00029     your version.
00030 */
00031 #ifndef _KPIM_IDENTITYMANAGER_H_
00032 #define _KPIM_IDENTITYMANAGER_H_
00033 
00034 #include <libkdepim/configmanager.h>
00035 
00036 #include <tqvaluelist.h>
00037 #include <dcopobject.h>
00038 #include <kdepimmacros.h>
00039 
00040 class KConfigBase;
00041 class KConfig;
00042 class KMKernel;
00043 class TQStringList;
00044 class KMIdentity;
00045 
00046 namespace KPIM {
00047 
00048 class Identity;
00053 #define IdentityManager KDE_EXPORT IdentityManager
00054 class IdentityManager : public ConfigManager, public DCOPObject
00055 #undef IdentityManager
00056 {
00057   Q_OBJECT
00058 //  TQ_OBJECT
00059   K_DCOP
00060 
00061 public:
00069   IdentityManager( bool readonly = false, TQObject * parent=0, const char * name=0 );
00070   virtual ~IdentityManager();
00071 
00072 public:
00073   typedef TQValueList<Identity>::Iterator Iterator;
00074   typedef TQValueList<Identity>::ConstIterator ConstIterator;
00075 
00077   void commit();
00079   void rollback();
00080 
00082   bool hasPendingChanges() const;
00083 
00085   TQStringList identities() const;
00086 
00092   TQStringList shadowIdentities() const;
00093 
00098   void sort();
00099 
00103   const Identity & identityForAddress( const TQString & addresses ) const;
00104 
00109   bool thatIsMe( const TQString & addressList ) const;
00110 
00115   const Identity & identityForName( const TQString & identityName ) const;
00116 
00120   const Identity & identityForUoid( uint uoid ) const;
00121 
00128   const Identity & identityForNameOrDefault( const TQString & identityName ) const;
00129 
00135   const Identity & identityForUoidOrDefault( uint uoid ) const;
00136 
00138   const Identity & defaultIdentity() const;
00139 
00146   bool setAsDefault( const TQString & identityName );
00147 
00154   bool setAsDefault( uint uoid );
00155 
00160   Identity & modifyIdentityForName( const TQString & identityName );
00161 
00166   Identity & modifyIdentityForUoid( uint uoid );
00167 
00169   bool removeIdentity( const TQString & identityName );
00170 
00171   ConstIterator begin() const;
00172   ConstIterator end() const;
00175   Iterator modifyBegin();
00176   Iterator modifyEnd();
00177 
00178   Identity & newFromScratch( const TQString & name );
00179   Identity & newFromControlCenter( const TQString & name );
00180   Identity & newFromExisting( const Identity & other,
00181                 const TQString & name=TQString() );
00182 
00184   TQStringList allEmails() const;
00185 
00186 signals:
00191   void changed( uint uoid );
00195   void changed( const KPIM::Identity & ident );
00199   void deleted( uint uoid );
00201   void added( const KPIM::Identity & ident );
00202 
00203 protected:
00209   virtual void createDefaultIdentity( TQString& /*fullName*/, TQString& /*emailAddress*/ ) {}
00210 
00211 protected slots:
00212   void slotRollback() { rollback(); };
00213 
00214 protected:
00216   TQValueList<Identity> mIdentities;
00218   TQValueList<Identity> mShadowIdentities;
00219 
00220 //k_dcop_signals:
00221 //  void identitiesChanged( TQCString appId, TQCString objId );
00222 
00223 k_dcop:
00224   // Connected to the DCOP signal
00225   void slotIdentitiesChanged( TQCString appId, TQCString objId );
00226 
00227 private:
00228   void writeConfig() const;
00229   void readConfig(KConfigBase* config);
00230   TQStringList groupList(KConfigBase* config) const;
00231   void createDefaultIdentity();
00232 
00233   // returns a new Unique Object Identifier
00234   int newUoid();
00235 
00236 private:
00237   KConfig* mConfig;
00238   bool mReadOnly;
00239 };
00240 
00241 } // namespace
00242 
00243 #endif // _KMAIL_IDENTITYMANAGER_H_