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; }
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   void setType( Type type ) { mType = type; }
00073 
00074 protected:
00075   void writeConfig( KConfigBase * config ) const;
00076   void readConfig( const KConfigBase * config );
00077 
00078 private:
00079   QString textFromFile( bool * ok ) const;
00080   QString textFromCommand( bool * ok ) const;
00081 
00082 private:
00083   QString mUrl;
00084   QString mText;
00085   Type    mType;
00086 };
00087 
00089 class KDE_EXPORT Identity
00090 {
00091   // only the identity manager should be able to construct and
00092   // destruct us, but then we get into problems with using
00093   // QValueList<Identity> and especially qHeapSort().
00094   friend class IdentityManager;
00095 
00096   friend QDataStream & operator<<( QDataStream & stream, const KPIM::Identity & ident );
00097   friend QDataStream & operator>>( QDataStream & stream, KPIM::Identity & ident );
00098 
00099 public:
00100   typedef QValueList<Identity> List;
00101 
00103   bool operator==( const Identity & other ) const;
00104 
00105   bool operator!=( const Identity & other ) const {
00106     return !operator==( other );
00107   }
00108 
00110   bool operator<( const Identity & other ) const {
00111     if ( isDefault() ) return true;
00112     if ( other.isDefault() ) return false;
00113     return identityName() < other.identityName();
00114   }
00115   bool operator>( const Identity & other ) const {
00116     if ( isDefault() ) return false;
00117     if ( other.isDefault() ) return true;
00118     return identityName() > other.identityName();
00119   }
00120   bool operator<=( const Identity & other ) const {
00121     return !operator>( other );
00122   }
00123   bool operator>=( const Identity & other ) const {
00124     return !operator<( other );
00125   }
00126 
00128   explicit Identity( const QString & id=QString::null,
00129              const QString & realName=QString::null,
00130              const QString & emailAddr=QString::null,
00131              const QString & organization=QString::null,
00132              const QString & replyToAddress=QString::null );
00133 
00135   ~Identity();
00136 
00137 protected:
00140   void readConfig( const KConfigBase * );
00141 
00144   void writeConfig( KConfigBase * ) const;
00145 
00146 public:
00148   bool mailingAllowed() const;
00149 
00151   QString identityName() const { return mIdentity; }
00152   void setIdentityName( const QString & name );
00153 
00155   bool isDefault() const { return mIsDefault; }
00156 
00158   uint uoid() const { return mUoid; }
00159 
00160 protected:
00170   void setIsDefault( bool flag );
00171 
00172   void setUoid( uint aUoid ) { mUoid = aUoid; }
00173 
00174 public:
00176   QString fullName() const { return mFullName; }
00177   void setFullName(const QString&);
00178 
00180   QString organization() const { return mOrganization; }
00181   void setOrganization(const QString&);
00182 
00183   KDE_DEPRECATED QCString pgpIdentity() const { return pgpEncryptionKey(); }
00184   KDE_DEPRECATED void setPgpIdentity( const QCString & key ) {
00185     setPGPEncryptionKey( key );
00186     setPGPSigningKey( key );
00187   }
00188 
00190   QCString pgpEncryptionKey() const { return mPGPEncryptionKey; }
00191   void setPGPEncryptionKey( const QCString & key );
00192 
00194   QCString pgpSigningKey() const { return mPGPSigningKey; }
00195   void setPGPSigningKey( const QCString & key );
00196 
00198   QCString smimeEncryptionKey() const { return mSMIMEEncryptionKey; }
00199   void setSMIMEEncryptionKey( const QCString & key );
00200 
00202   QCString smimeSigningKey() const { return mSMIMESigningKey; }
00203   void setSMIMESigningKey( const QCString & key );
00204 
00205   Kleo::CryptoMessageFormat preferredCryptoMessageFormat() const { return mPreferredCryptoMessageFormat; }
00206   void setPreferredCryptoMessageFormat( Kleo::CryptoMessageFormat format ) { mPreferredCryptoMessageFormat = format; }
00207 
00209   QString emailAddr() const { return mEmailAddr; }
00210   void setEmailAddr(const QString&);
00211 
00213   QString vCardFile() const { return mVCardFile; }
00214   void setVCardFile(const QString&);
00215 
00218   QString fullEmailAddr() const;
00219 
00221   QString replyToAddr() const { return mReplyToAddr; }
00222   void setReplyToAddr(const QString&);
00223 
00225   QString bcc() const { return mBcc; }
00226   void setBcc(const QString& aBcc) { mBcc = aBcc; }
00227 
00228   void setSignature( const Signature & sig ) { mSignature = sig; }
00229   Signature & signature() /* _not_ const! */ { return mSignature; }
00230 
00231 protected:
00233   bool signatureIsCommand() const { return mSignature.type() == Signature::FromCommand; }
00235   bool signatureIsPlainFile() const { return mSignature.type() == Signature::FromFile; }
00237   bool signatureIsInline() const { return mSignature.type() == Signature::Inlined; }
00238 
00240   QString signatureFile() const { return mSignature.url(); }
00241   void setSignatureFile(const QString&);
00242 
00244   QString signatureInlineText() const { return mSignature.text();}
00245   void setSignatureInlineText(const QString&);
00246 
00248   bool useSignatureFile() const { return signatureIsPlainFile() || signatureIsCommand(); }
00249 
00250 public:
00256   QString signatureText( bool * ok=0) const;
00257 
00260   QString transport() const { return mTransport; }
00261   void setTransport(const QString&);
00262 
00265   QString fcc() const { return mFcc; }
00266   void setFcc(const QString&);
00267 
00270   QString drafts() const { return mDrafts; }
00271   void setDrafts(const QString&);
00272 
00275   QString templates() const { return mTemplates; }
00276   void setTemplates( const QString& );
00277 
00279   QString dictionary() const { return mDictionary; }
00280   void setDictionary( const QString& );
00281 
00283   QString xface() const { return mXFace; }
00284   void setXFace( const QString& );
00285   bool isXFaceEnabled() const { return mXFaceEnabled; }
00286   void setXFaceEnabled( const bool );
00287 
00288   static const Identity& null();
00289   bool isNull() const;
00290 protected:
00291   // if you add new members, make sure they have an operator= (or the
00292   // compiler can synthesize one) and amend Identity::operator==,
00293   // isNull(), readConfig() and writeConfig() as well as operator<<
00294   // and operator>> accordingly:
00295   uint mUoid;
00296   QString mIdentity, mFullName, mEmailAddr, mOrganization;
00297   QString mReplyToAddr;
00298   QString mBcc;
00299   QString mVCardFile;
00300   QCString mPGPEncryptionKey, mPGPSigningKey, mSMIMEEncryptionKey, mSMIMESigningKey;
00301   QString mFcc, mDrafts, mTemplates, mTransport;
00302   QString mDictionary;
00303   QString mXFace;
00304   bool mXFaceEnabled;
00305   Signature mSignature;
00306   bool      mIsDefault;
00307   Kleo::CryptoMessageFormat mPreferredCryptoMessageFormat;
00308 };
00309 
00310 KDE_EXPORT QDataStream & operator<<( QDataStream & stream, const KPIM::Signature & sig );
00311 KDE_EXPORT QDataStream & operator>>( QDataStream & stream, KPIM::Signature & sig );
00312 
00313 KDE_EXPORT QDataStream & operator<<( QDataStream & stream, const KPIM::Identity & ident );
00314 KDE_EXPORT QDataStream & operator>>( QDataStream & stream, KPIM::Identity & ident );
00315 
00316 } // namespace KPIM
00317 
00318 #endif /*kpim_identity_h*/
KDE Home | KDE Accessibility Home | Description of Access Keys