TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

244 lines
8.1 KiB

  1. /*
  2. identitymanager.h
  3. This file is part of KMail, the KDE mail client.
  4. Copyright (c) 2002 Marc Mutz <mutz@kde.org>
  5. KMail is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License, version 2, as
  7. published by the Free Software Foundation.
  8. KMail is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  15. In addition, as a special exception, the copyright holders give
  16. permission to link the code of this program with any edition of
  17. the TQt library by Trolltech AS, Norway (or with modified versions
  18. of TQt that use the same license as TQt), and distribute linked
  19. combinations including the two. You must obey the GNU General
  20. Public License in all respects for all of the code used other than
  21. TQt. If you modify this file, you may extend this exception to
  22. your version of the file, but you are not obligated to do so. If
  23. you do not wish to do so, delete this exception statement from
  24. your version.
  25. */
  26. #ifndef _KPIM_IDENTITYMANAGER_H_
  27. #define _KPIM_IDENTITYMANAGER_H_
  28. #include <libtdepim/configmanager.h>
  29. #include <tqvaluelist.h>
  30. #include <dcopobject.h>
  31. #include <tdepimmacros.h>
  32. class TDEConfigBase;
  33. class TDEConfig;
  34. class KMKernel;
  35. class TQStringList;
  36. class KMIdentity;
  37. namespace KPIM {
  38. class Identity;
  39. /**
  40. * @short Manages the list of identities.
  41. * @author Marc Mutz <mutz@kde.org>
  42. **/
  43. #define IdentityManager KDE_EXPORT IdentityManager
  44. class IdentityManager : public ConfigManager, public DCOPObject
  45. #undef IdentityManager
  46. {
  47. Q_OBJECT
  48. //
  49. K_DCOP
  50. public:
  51. /**
  52. * Create an identity manager, which loads the emailidentities file
  53. * to create identities.
  54. * @param readonly if true, no changes can be made to the identity manager
  55. * This means in particular that if there is no identity configured,
  56. * the default identity created here will not be saved.
  57. */
  58. IdentityManager( bool readonly = false, TQObject * parent=0, const char * name=0 );
  59. virtual ~IdentityManager();
  60. public:
  61. typedef TQValueList<Identity>::Iterator Iterator;
  62. typedef TQValueList<Identity>::ConstIterator ConstIterator;
  63. /** Commit changes to disk and emit changed() if necessary. */
  64. void commit();
  65. /** Re-read the config from disk and forget changes. */
  66. void rollback();
  67. /** Check whether there are any unsaved changes. */
  68. bool hasPendingChanges() const;
  69. /** @return the list of identities */
  70. TQStringList identities() const;
  71. /** Convenience method.
  72. @return the list of (shadow) identities, ie. the ones currently
  73. under configuration.
  74. */
  75. TQStringList shadowIdentities() const;
  76. /** Sort the identities by name (the default is always first). This
  77. operates on the @em shadow list, so you need to @ref commit for
  78. the changes to take effect.
  79. **/
  80. void sort();
  81. /** @return an identity whose address matches any in @p addresses
  82. or @ref Identity::null if no such identity exists.
  83. **/
  84. const Identity & identityForAddress( const TQString & addresses ) const;
  85. /** @return true if @p addressList contains any of our addresses,
  86. false otherwise.
  87. @see #identityForAddress
  88. **/
  89. bool thatIsMe( const TQString & addressList ) const;
  90. /** @deprecated
  91. @return the identity named @p identityName or @ref
  92. Identity::null if not found.
  93. **/
  94. const Identity & identityForName( const TQString & identityName ) const;
  95. /** @return the identity with Unique Object Identifier (UOID) @p
  96. uoid or @ref Identity::null if not found.
  97. **/
  98. const Identity & identityForUoid( uint uoid ) const;
  99. /** @deprecated
  100. Convenience method.
  101. @return the identity named @p identityName or the default
  102. identity if not found.
  103. **/
  104. const Identity & identityForNameOrDefault( const TQString & identityName ) const;
  105. /** Convenience menthod.
  106. @return the identity with Unique Object Identifier (UOID) @p
  107. uoid or the default identity if not found.
  108. **/
  109. const Identity & identityForUoidOrDefault( uint uoid ) const;
  110. /** @return the default identity */
  111. const Identity & defaultIdentity() const;
  112. /** @deprecated
  113. Sets the identity named @p identityName to be the new default
  114. identity. As usual, use @ref commit to make this permanent.
  115. @return false if an identity named @p identityName was not found
  116. **/
  117. bool setAsDefault( const TQString & identityName );
  118. /** Sets the identity with Unique Object Identifier (UOID) @p uoid
  119. to be new the default identity. As usual, use @ref commit to
  120. make this permanent.
  121. @return false if an identity with UOID @p uoid was not found
  122. **/
  123. bool setAsDefault( uint uoid );
  124. /** @return the identity named @p identityName. This method returns a
  125. reference to the identity that can be modified. To let others
  126. see this change, use @ref commit.
  127. **/
  128. Identity & modifyIdentityForName( const TQString & identityName );
  129. /** @return the identity with Unique Object Identifier (UOID) @p uoid.
  130. This method returns a reference to the identity that can
  131. be modified. To let others see this change, use @ref commit.
  132. **/
  133. Identity & modifyIdentityForUoid( uint uoid );
  134. /** Removes the identity with name @p identityName */
  135. bool removeIdentity( const TQString & identityName );
  136. ConstIterator begin() const;
  137. ConstIterator end() const;
  138. /// Iterator used by the configuration dialog, which works on a separate list
  139. /// of identities, for modification. Changes are made effective by commit().
  140. Iterator modifyBegin();
  141. Iterator modifyEnd();
  142. Identity & newFromScratch( const TQString & name );
  143. Identity & newFromControlCenter( const TQString & name );
  144. Identity & newFromExisting( const Identity & other,
  145. const TQString & name=TQString() );
  146. /** Returns the list of all email addresses (only name@host) from all identities */
  147. TQStringList allEmails() const;
  148. signals:
  149. /** Emitted whenever the identity with Unique Object Identifier
  150. (UOID) @p uoid changed. Useful for more fine-grained change
  151. notifications than what is possible with the standard @ref
  152. changed() signal. */
  153. void changed( uint uoid );
  154. /** Emitted whenever the identity @p ident changed. Useful for more
  155. fine-grained change notifications than what is possible with the
  156. standard @ref changed() signal. */
  157. void changed( const KPIM::Identity & ident );
  158. /** Emitted on @ref commit() for each deleted identity. At the time
  159. this signal is emitted, the identity does still exist and can be
  160. retrieved by @ref identityForUoid() if needed */
  161. void deleted( uint uoid );
  162. /** Emitted on @ref commit() for each new identity */
  163. void added( const KPIM::Identity & ident );
  164. protected:
  165. /**
  166. * This is called when no identity has been defined, so we need to create a default one
  167. * The parameters are filled with some default values from KUser,
  168. * but reimplementations of this method can give them another value.
  169. */
  170. virtual void createDefaultIdentity( TQString& /*fullName*/, TQString& /*emailAddress*/ ) {}
  171. protected slots:
  172. void slotRollback() { rollback(); };
  173. protected:
  174. /** The list that will be seen by everyone */
  175. TQValueList<Identity> mIdentities;
  176. /** The list that will be seen by the config dialog */
  177. TQValueList<Identity> mShadowIdentities;
  178. //k_dcop_signals:
  179. // void identitiesChanged( TQCString appId, TQCString objId );
  180. k_dcop:
  181. // Connected to the DCOP signal
  182. void slotIdentitiesChanged( TQCString appId, TQCString objId );
  183. private:
  184. void writeConfig() const;
  185. void readConfig(TDEConfigBase* config);
  186. TQStringList groupList(TDEConfigBase* config) const;
  187. void createDefaultIdentity();
  188. // returns a new Unique Object Identifier
  189. int newUoid();
  190. private:
  191. TDEConfig* mConfig;
  192. bool mReadOnly;
  193. };
  194. } // namespace
  195. #endif // _KMAIL_IDENTITYMANAGER_H_