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 Qt library by Trolltech AS, Norway (or with modified versions
00023     of Qt that use the same license as Qt), 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     Qt.  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 <qvaluelist.h>
00037 #include <dcopobject.h>
00038 #include <kdepimmacros.h>
00039 
00040 class KConfigBase;
00041 class KConfig;
00042 class KMKernel;
00043 class QStringList;
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   K_DCOP
00059 
00060 public:
00068   IdentityManager( bool readonly = false, QObject * parent=0, const char * name=0 );
00069   virtual ~IdentityManager();
00070 
00071 public:
00072   typedef QValueList<Identity>::Iterator Iterator;
00073   typedef QValueList<Identity>::ConstIterator ConstIterator;
00074 
00076   void commit();
00078   void rollback();
00079 
00081   bool hasPendingChanges() const;
00082 
00084   QStringList identities() const;
00085 
00091   QStringList shadowIdentities() const;
00092 
00097   void sort();
00098 
00102   const Identity & identityForAddress( const QString & addresses ) const;
00103 
00108   bool thatIsMe( const QString & addressList ) const;
00109 
00114   const Identity & identityForName( const QString & identityName ) const;
00115 
00119   const Identity & identityForUoid( uint uoid ) const;
00120 
00127   const Identity & identityForNameOrDefault( const QString & identityName ) const;
00128 
00134   const Identity & identityForUoidOrDefault( uint uoid ) const;
00135 
00137   const Identity & defaultIdentity() const;
00138 
00145   bool setAsDefault( const QString & identityName );
00146 
00153   bool setAsDefault( uint uoid );
00154 
00159   Identity & modifyIdentityForName( const QString & identityName );
00160 
00165   Identity & modifyIdentityForUoid( uint uoid );
00166 
00168   bool removeIdentity( const QString & identityName );
00169 
00170   ConstIterator begin() const;
00171   ConstIterator end() const;
00174   Iterator modifyBegin();
00175   Iterator modifyEnd();
00176 
00177   Identity & newFromScratch( const QString & name );
00178   Identity & newFromControlCenter( const QString & name );
00179   Identity & newFromExisting( const Identity & other,
00180                 const QString & name=QString::null );
00181 
00183   QStringList allEmails() const;
00184 
00185 signals:
00190   void changed( uint uoid );
00194   void changed( const KPIM::Identity & ident );
00198   void deleted( uint uoid );
00200   void added( const KPIM::Identity & ident );
00201 
00202 protected:
00208   virtual void createDefaultIdentity( QString& /*fullName*/, QString& /*emailAddress*/ ) {}
00209 
00210 protected slots:
00211   void slotRollback() { rollback(); };
00212 
00213 protected:
00215   QValueList<Identity> mIdentities;
00217   QValueList<Identity> mShadowIdentities;
00218 
00219 //k_dcop_signals:
00220 //  void identitiesChanged( QCString appId, QCString objId );
00221 
00222 k_dcop:
00223   // Connected to the DCOP signal
00224   void slotIdentitiesChanged( QCString appId, QCString objId );
00225 
00226 private:
00227   void writeConfig() const;
00228   void readConfig(KConfigBase* config);
00229   QStringList groupList(KConfigBase* config) const;
00230   void createDefaultIdentity();
00231 
00232   // returns a new Unique Object Identifier
00233   int newUoid();
00234 
00235 private:
00236   KConfig* mConfig;
00237   bool mReadOnly;
00238 };
00239 
00240 } // namespace
00241 
00242 #endif // _KMAIL_IDENTITYMANAGER_H_
KDE Home | KDE Accessibility Home | Description of Access Keys