libkpimidentities

identity.h
1 /*
2  * User identity information
3  *
4  * Author: Stefan Taferner <taferner@kde.org>
5  * This code is under GPL
6  */
7 #ifndef kpim_identity_h
8 #define kpim_identity_h
9 
10 #include <kleo/enum.h>
11 
12 #include <tdemacros.h>
13 
14 #include <tqstring.h>
15 #include <tqcstring.h>
16 #include <tqstringlist.h>
17 
18 class TDEProcess;
19 namespace KPIM {
20  class Identity;
21  class Signature;
22 }
23 class TDEConfigBase;
24 class IdentityList;
25 class TQDataStream;
26 
27 namespace KPIM {
28 
29 TDE_EXPORT TQDataStream & operator<<( TQDataStream & stream, const KPIM::Signature & sig );
30 TDE_EXPORT TQDataStream & operator>>( TQDataStream & stream, KPIM::Signature & sig );
31 
32 TDE_EXPORT TQDataStream & operator<<( TQDataStream & stream, const KPIM::Identity & ident );
33 TDE_EXPORT TQDataStream & operator>>( TQDataStream & stream, KPIM::Identity & ident );
34 
39 class TDE_EXPORT Signature {
40  friend class Identity;
41 
42  friend TQDataStream & KPIM::operator<<( TQDataStream & stream, const Signature & sig );
43  friend TQDataStream & KPIM::operator>>( TQDataStream & stream, Signature & sig );
44 
45 public:
47  enum Type { Disabled = 0, Inlined = 1, FromFile = 2, FromCommand = 3 };
48 
50  bool operator==( const Signature & other ) const;
51 
53  Signature();
55  Signature( const TQString & text );
57  Signature( const TQString & url, bool isExecutable );
58 
60  TQString rawText( bool * ok=0 ) const;
61 
64  TQString withSeparator( bool * ok=0 ) const;
65 
68  void setText( const TQString & text ) { mText = text; }
69  TQString text() const { return mText; }
70 
73  void setUrl( const TQString & url, bool isExecutable=false );
74  TQString url() const { return mUrl; }
75 
77  Type type() const { return mType; }
78  void setType( Type type ) { mType = type; }
79 
80 protected:
81  void writeConfig( TDEConfigBase * config ) const;
82  void readConfig( const TDEConfigBase * config );
83 
84 private:
85  TQString textFromFile( bool * ok ) const;
86  TQString textFromCommand( bool * ok ) const;
87 
88 private:
89  TQString mUrl;
90  TQString mText;
91  Type mType;
92 };
93 
95 class TDE_EXPORT Identity
96 {
97  // only the identity manager should be able to construct and
98  // destruct us, but then we get into problems with using
99  // TQValueList<Identity> and especially qHeapSort().
100  friend class IdentityManager;
101 
102  friend TQDataStream & operator<<( TQDataStream & stream, const KPIM::Identity & ident );
103  friend TQDataStream & operator>>( TQDataStream & stream, KPIM::Identity & ident );
104 
105 public:
106  typedef TQValueList<Identity> List;
107 
109  bool operator==( const Identity & other ) const;
110 
111  bool operator!=( const Identity & other ) const {
112  return !operator==( other );
113  }
114 
116  bool operator<( const Identity & other ) const {
117  if ( isDefault() ) return true;
118  if ( other.isDefault() ) return false;
119  return identityName() < other.identityName();
120  }
121  bool operator>( const Identity & other ) const {
122  if ( isDefault() ) return false;
123  if ( other.isDefault() ) return true;
124  return identityName() > other.identityName();
125  }
126  bool operator<=( const Identity & other ) const {
127  return !operator>( other );
128  }
129  bool operator>=( const Identity & other ) const {
130  return !operator<( other );
131  }
132 
134  explicit Identity( const TQString & id=TQString(),
135  const TQString & realName=TQString(),
136  const TQString & emailAddr=TQString(),
137  const TQString & organization=TQString(),
138  const TQString & replyToAddress=TQString() );
139 
141  ~Identity();
142 
143 protected:
146  void readConfig( const TDEConfigBase * );
147 
150  void writeConfig( TDEConfigBase * ) const;
151 
152 public:
154  bool mailingAllowed() const;
155 
157  TQString identityName() const { return mIdentity; }
158  void setIdentityName( const TQString & name );
159 
161  bool isDefault() const { return mIsDefault; }
162 
164  uint uoid() const { return mUoid; }
165 
166 protected:
176  void setIsDefault( bool flag );
177 
178  void setUoid( uint aUoid ) { mUoid = aUoid; }
179 
180 public:
182  TQString fullName() const { return mFullName; }
183  void setFullName(const TQString&);
184 
186  TQString organization() const { return mOrganization; }
187  void setOrganization(const TQString&);
188 
189  TDE_DEPRECATED TQCString pgpIdentity() const { return pgpEncryptionKey(); }
190  TDE_DEPRECATED void setPgpIdentity( const TQCString & key ) {
191  setPGPEncryptionKey( key );
192  setPGPSigningKey( key );
193  }
194 
196  TQCString pgpEncryptionKey() const { return mPGPEncryptionKey; }
197  void setPGPEncryptionKey( const TQCString & key );
198 
200  TQCString pgpSigningKey() const { return mPGPSigningKey; }
201  void setPGPSigningKey( const TQCString & key );
202 
204  TQCString smimeEncryptionKey() const { return mSMIMEEncryptionKey; }
205  void setSMIMEEncryptionKey( const TQCString & key );
206 
208  TQCString smimeSigningKey() const { return mSMIMESigningKey; }
209  void setSMIMESigningKey( const TQCString & key );
210 
211  Kleo::CryptoMessageFormat preferredCryptoMessageFormat() const { return mPreferredCryptoMessageFormat; }
212  void setPreferredCryptoMessageFormat( Kleo::CryptoMessageFormat format ) { mPreferredCryptoMessageFormat = format; }
213 
215  TDE_DEPRECATED TQString emailAddr() const { return primaryEmailAddress(); }
216  TDE_DEPRECATED void setEmailAddr( const TQString & email ) { setPrimaryEmailAddress( email ); }
217 
220  TQString primaryEmailAddress() const { return mEmailAddr; }
221  void setPrimaryEmailAddress( const TQString & email );
222 
224  const TQStringList & emailAliases() const { return mEmailAliases; }
225  void setEmailAliases( const TQStringList & );
226 
227  bool matchesEmailAddress( const TQString & addr ) const;
228 
230  TQString vCardFile() const { return mVCardFile; }
231  void setVCardFile(const TQString&);
232 
235  TQString fullEmailAddr() const;
236 
238  TQString replyToAddr() const { return mReplyToAddr; }
239  void setReplyToAddr(const TQString&);
240 
242  TQString bcc() const { return mBcc; }
243  void setBcc(const TQString& aBcc) { mBcc = aBcc; }
244 
245  void setSignature( const Signature & sig ) { mSignature = sig; }
246  Signature & signature() /* _not_ const! */ { return mSignature; }
247  const Signature & signature() const { return mSignature; }
248 
249 protected:
251  bool signatureIsCommand() const { return mSignature.type() == Signature::FromCommand; }
253  bool signatureIsPlainFile() const { return mSignature.type() == Signature::FromFile; }
255  bool signatureIsInline() const { return mSignature.type() == Signature::Inlined; }
256 
258  TQString signatureFile() const { return mSignature.url(); }
259  void setSignatureFile(const TQString&);
260 
262  TQString signatureInlineText() const { return mSignature.text();}
263  void setSignatureInlineText(const TQString&);
264 
266  bool useSignatureFile() const { return signatureIsPlainFile() || signatureIsCommand(); }
267 
268 public:
274  TQString signatureText( bool * ok=0) const;
275 
278  TQString transport() const { return mTransport; }
279  void setTransport(const TQString&);
280 
283  TQString fcc() const { return mFcc; }
284  void setFcc(const TQString&);
285 
288  TQString drafts() const { return mDrafts; }
289  void setDrafts(const TQString&);
290 
293  TQString templates() const { return mTemplates; }
294  void setTemplates( const TQString& );
295 
297  TQString dictionary() const { return mDictionary; }
298  void setDictionary( const TQString& );
299 
301  TQString xface() const { return mXFace; }
302  void setXFace( const TQString& );
303  bool isXFaceEnabled() const { return mXFaceEnabled; }
304  void setXFaceEnabled( const bool );
305 
306  static const Identity& null();
307  bool isNull() const;
308 protected:
309  // if you add new members, make sure they have an operator= (or the
310  // compiler can synthesize one) and amend Identity::operator==,
311  // isNull(), readConfig() and writeConfig() as well as operator<<
312  // and operator>> accordingly:
313  uint mUoid;
314  TQString mIdentity, mFullName, mEmailAddr, mOrganization;
315  TQStringList mEmailAliases;
316  TQString mReplyToAddr;
317  TQString mBcc;
318  TQString mVCardFile;
319  TQCString mPGPEncryptionKey, mPGPSigningKey, mSMIMEEncryptionKey, mSMIMESigningKey;
320  TQString mFcc, mDrafts, mTemplates, mTransport;
321  TQString mDictionary;
322  TQString mXFace;
323  bool mXFaceEnabled;
324  Signature mSignature;
325  bool mIsDefault;
326  Kleo::CryptoMessageFormat mPreferredCryptoMessageFormat;
327 };
328 
329 } // namespace KPIM
330 
331 #endif /*kpim_identity_h*/
User identity information.
Definition: identity.h:96
bool signatureIsCommand() const
Definition: identity.h:251
bool isDefault() const
Definition: identity.h:161
TQString xface() const
a X-Face header for this identity
Definition: identity.h:301
bool signatureIsInline() const
Definition: identity.h:255
uint uoid() const
Unique Object Identifier for this identity.
Definition: identity.h:164
TQString organization() const
The user's organization (optional)
Definition: identity.h:186
TQCString smimeEncryptionKey() const
The user's S/MIME encryption key.
Definition: identity.h:204
TQCString smimeSigningKey() const
The user's S/MIME signing key.
Definition: identity.h:208
TQString signatureFile() const
name of the signature file (with path)
Definition: identity.h:258
TQString identityName() const
Identity/nickname for this collection.
Definition: identity.h:157
TQString fcc() const
The folder where sent messages from this identity will be stored by default.
Definition: identity.h:283
bool operator<(const Identity &other) const
used for sorting
Definition: identity.h:116
bool useSignatureFile() const
Inline or signature from a file.
Definition: identity.h:266
TDE_DEPRECATED TQString emailAddr() const
email address (without the user name - only name@host)
Definition: identity.h:215
TQString bcc() const
email addresses for the BCC: field
Definition: identity.h:242
TQString signatureInlineText() const
inline signature
Definition: identity.h:262
TQString fullName() const
Full name of the user.
Definition: identity.h:182
TQString dictionary() const
dictionary which should be used for spell checking
Definition: identity.h:297
TQString primaryEmailAddress() const
primary email address (without the user name - only name@host).
Definition: identity.h:220
TQString transport() const
The transport that is set for this identity.
Definition: identity.h:278
TQString replyToAddr() const
email address for the ReplyTo: field
Definition: identity.h:238
TQCString pgpEncryptionKey() const
The user's OpenPGP encryption key.
Definition: identity.h:196
const TQStringList & emailAliases() const
email address aliases
Definition: identity.h:224
TQString drafts() const
The folder where draft messages from this identity will be stored by default.
Definition: identity.h:288
bool signatureIsPlainFile() const
Definition: identity.h:253
TQString templates() const
The folder where template messages from this identity will be stored by default.
Definition: identity.h:293
TQString vCardFile() const
vCard to attach to outgoing emails
Definition: identity.h:230
TQCString pgpSigningKey() const
The user's OpenPGP signing key.
Definition: identity.h:200
abstraction of a signature (aka "footer").
Definition: identity.h:39
Type
Type of signature (ie.
Definition: identity.h:47
Type type() const
Definition: identity.h:77
void setText(const TQString &text)
Set the signature text and mark this signature as being of "inline text" type.
Definition: identity.h:68