libkpimidentities

identity.h

00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002  * User identity information
00003  *
00004  * Author: Stefan Taferner <taferner@kde.org>
00005  * This code is under GPL
00006  */
00007 #ifndef kpim_identity_h
00008 #define kpim_identity_h
00009 
00010 #include <kleo/enum.h>
00011 
00012 #include <kdepimmacros.h>
00013 
00014 #include <qstring.h>
00015 #include <qcstring.h>
00016 #include <qstringlist.h>
00017 
00018 class KProcess;
00019 namespace KPIM {
00020   class Identity;
00021   class Signature;
00022 }
00023 class KConfigBase;
00024 class IdentityList;
00025 class QDataStream;
00026 
00027 namespace KPIM {
00028 
00033 class KDE_EXPORT Signature {
00034   friend class Identity;
00035 
00036   friend QDataStream & KPIM::operator<<( QDataStream & stream, const Signature & sig );
00037   friend QDataStream & KPIM::operator>>( QDataStream & stream, Signature & sig );
00038 
00039 public:
00041   enum Type { Disabled = 0, Inlined = 1, FromFile = 2, FromCommand = 3 };
00042 
00044   bool operator==( const Signature & other ) const;
00045 
00047   Signature();
00049   Signature( const QString & text );
00051   Signature( const QString & url, bool isExecutable );
00052 
00054   QString rawText( bool * ok=0 ) const;
00055 
00058   QString withSeparator( bool * ok=0 ) const;
00059 
00062   void setText( const QString & text ) { mText = text; mType = Inlined; }
00063   QString text() const { return mText; }
00064 
00067   void setUrl( const QString & url, bool isExecutable=false );
00068   QString url() const { return mUrl; }
00069 
00071   Type type() const { return mType; }
00072 
00073 protected:
00074   void writeConfig( KConfigBase * config ) const;
00075   void readConfig( const KConfigBase * config );
00076 
00077 private:
00078   QString textFromFile( bool * ok ) const;
00079   QString textFromCommand( bool * ok ) const;
00080 
00081 private:
00082   QString mUrl;
00083   QString mText;
00084   Type    mType;
00085 };
00086 
00088 class KDE_EXPORT Identity
00089 {
00090   // only the identity manager should be able to construct and
00091   // destruct us, but then we get into problems with using
00092   // QValueList<Identity> and especially qHeapSort().
00093   friend class IdentityManager;
00094 
00095   friend QDataStream & operator<<( QDataStream & stream, const KPIM::Identity & ident );
00096   friend QDataStream & operator>>( QDataStream & stream, KPIM::Identity & ident );
00097 
00098 public:
00099   typedef QValueList<Identity> List;
00100 
00102   bool operator==( const Identity & other ) const;
00103 
00104   bool operator!=( const Identity & other ) const {
00105     return !operator==( other );
00106   }
00107 
00109   bool operator<( const Identity & other ) const {
00110     if ( isDefault() ) return true;
00111     if ( other.isDefault() ) return false;
00112     return identityName() < other.identityName();
00113   }
00114   bool operator>( const Identity & other ) const {
00115     if ( isDefault() ) return false;
00116     if ( other.isDefault() ) return true;
00117     return identityName() > other.identityName();
00118   }
00119   bool operator<=( const Identity & other ) const {
00120     return !operator>( other );
00121   }
00122   bool operator>=( const Identity & other ) const {
00123     return !operator<( other );
00124   }
00125 
00127   explicit Identity( const QString & id=QString::null,
00128              const QString & realName=QString::null,
00129              const QString & emailAddr=QString::null,
00130              const QString & organization=QString::null,
00131              const QString & replyToAddress=QString::null );
00132 
00134   ~Identity();
00135 
00136 protected:
00139   void readConfig( const KConfigBase * );
00140 
00143   void writeConfig( KConfigBase * ) const;
00144 
00145 public:
00147   bool mailingAllowed() const;
00148 
00150   QString identityName() const { return mIdentity; }
00151   void setIdentityName( const QString & name );
00152 
00154   bool isDefault() const { return mIsDefault; }
00155 
00157   uint uoid() const { return mUoid; }
00158 
00159 protected:
00169   void setIsDefault( bool flag );
00170 
00171   void setUoid( uint aUoid ) { mUoid = aUoid; }
00172 
00173 public:
00175   QString fullName() const { return mFullName; }
00176   void setFullName(const QString&);
00177 
00179   QString organization() const { return mOrganization; }
00180   void setOrganization(const QString&);
00181 
00182   KDE_DEPRECATED QCString pgpIdentity() const { return pgpEncryptionKey(); }
00183   KDE_DEPRECATED void setPgpIdentity( const QCString & key ) {
00184     setPGPEncryptionKey( key );
00185     setPGPSigningKey( key );
00186   }
00187 
00189   QCString pgpEncryptionKey() const { return mPGPEncryptionKey; }
00190   void setPGPEncryptionKey( const QCString & key );
00191 
00193   QCString pgpSigningKey() const { return mPGPSigningKey; }
00194   void setPGPSigningKey( const QCString & key );
00195 
00197   QCString smimeEncryptionKey() const { return mSMIMEEncryptionKey; }
00198   void setSMIMEEncryptionKey( const QCString & key );
00199 
00201   QCString smimeSigningKey() const { return mSMIMESigningKey; }
00202   void setSMIMESigningKey( const QCString & key );
00203 
00204   Kleo::CryptoMessageFormat preferredCryptoMessageFormat() const { return mPreferredCryptoMessageFormat; }
00205   void setPreferredCryptoMessageFormat( Kleo::CryptoMessageFormat format ) { mPreferredCryptoMessageFormat = format; }
00206 
00208   QString emailAddr() const { return mEmailAddr; }
00209   void setEmailAddr(const QString&);
00210 
00212   QString vCardFile() const { return mVCardFile; }
00213   void setVCardFile(const QString&);
00214 
00217   QString fullEmailAddr() const;
00218 
00220   QString replyToAddr() const { return mReplyToAddr; }
00221   void setReplyToAddr(const QString&);
00222 
00224   QString bcc() const { return mBcc; }
00225   void setBcc(const QString& aBcc) { mBcc = aBcc; }
00226 
00227   void setSignature( const Signature & sig ) { mSignature = sig; }
00228   Signature & signature() /* _not_ const! */ { return mSignature; }
00229 
00230 protected:
00232   bool signatureIsCommand() const { return mSignature.type() == Signature::FromCommand; }
00234   bool signatureIsPlainFile() const { return mSignature.type() == Signature::FromFile; }
00236   bool signatureIsInline() const { return mSignature.type() == Signature::Inlined; }
00237 
00239   QString signatureFile() const { return mSignature.url(); }
00240   void setSignatureFile(const QString&);
00241 
00243   QString signatureInlineText() const { return mSignature.text();}
00244   void setSignatureInlineText(const QString&);
00245 
00247   bool useSignatureFile() const { return signatureIsPlainFile() || signatureIsCommand(); }
00248 
00249 public:
00255   QString signatureText( bool * ok=0) const;
00256 
00259   QString transport() const { return mTransport; }
00260   void setTransport(const QString&);
00261 
00264   QString fcc() const { return mFcc; }
00265   void setFcc(const QString&);
00266 
00269   QString drafts() const { return mDrafts; }
00270   void setDrafts(const QString&);
00271 
00274   QString templates() const { return mTemplates; }
00275   void setTemplates( const QString& );
00276 
00278   QString dictionary() const { return mDictionary; }
00279   void setDictionary( const QString& );
00280 
00282   QString xface() const { return mXFace; }
00283   void setXFace( const QString& );
00284   bool isXFaceEnabled() const { return mXFaceEnabled; }
00285   void setXFaceEnabled( const bool );
00286 
00287   static const Identity& null();
00288   bool isNull() const;
00289 protected:
00290   // if you add new members, make sure they have an operator= (or the
00291   // compiler can synthesize one) and amend Identity::operator==,
00292   // isNull(), readConfig() and writeConfig() as well as operator<<
00293   // and operator>> accordingly:
00294   uint mUoid;
00295   QString mIdentity, mFullName, mEmailAddr, mOrganization;
00296   QString mReplyToAddr;
00297   QString mBcc;
00298   QString mVCardFile;
00299   QCString mPGPEncryptionKey, mPGPSigningKey, mSMIMEEncryptionKey, mSMIMESigningKey;
00300   QString mFcc, mDrafts, mTemplates, mTransport;
00301   QString mDictionary;
00302   QString mXFace;
00303   bool mXFaceEnabled;
00304   Signature mSignature;
00305   bool      mIsDefault;
00306   Kleo::CryptoMessageFormat mPreferredCryptoMessageFormat;
00307 };
00308 
00309 KDE_EXPORT QDataStream & operator<<( QDataStream & stream, const KPIM::Signature & sig );
00310 KDE_EXPORT QDataStream & operator>>( QDataStream & stream, KPIM::Signature & sig );
00311 
00312 KDE_EXPORT QDataStream & operator<<( QDataStream & stream, const KPIM::Identity & ident );
00313 KDE_EXPORT QDataStream & operator>>( QDataStream & stream, KPIM::Identity & ident );
00314 
00315 } // namespace KPIM
00316 
00317 #endif /*kpim_identity_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys