Back to index

lightning-sunbird  0.9+nobinonly
nsMsgIdentity.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alec Flett <alecf@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsMsgIdentity_h___
00040 #define nsMsgIdentity_h___
00041 
00042 #include "nsIMsgIdentity.h"
00043 #include "nsIPrefBranch.h"
00044 #include "msgCore.h"
00045 #include "nsISmtpServer.h"
00046 #include "nsWeakPtr.h"
00047 
00048 
00049 class NS_MSG_BASE nsMsgIdentity : public nsIMsgIdentity
00050 {
00051 public:
00052   nsMsgIdentity();
00053   virtual ~nsMsgIdentity();
00054   
00055   NS_DECL_ISUPPORTS
00056   NS_DECL_NSIMSGIDENTITY
00057   
00058 private:
00059   nsIMsgSignature* m_signature;
00060   char *m_identityKey;
00061   nsIPrefBranch *m_prefBranch;
00062   nsWeakPtr m_smtpServer;
00063 
00064 protected:
00065   nsresult getPrefService();
00066   char *getPrefName(const char *identityKey, const char *pref);
00067   char *getDefaultPrefName(const char *pref);
00068   
00069   nsresult getCharPref(const char *pref, char **);
00070   nsresult getDefaultCharPref(const char *pref, char **);
00071   nsresult setCharPref(const char *pref, const char *);
00072 
00073   nsresult getUnicharPref(const char *pref, PRUnichar **);
00074   nsresult getDefaultUnicharPref(const char *pref, PRUnichar **);
00075   nsresult setUnicharPref(const char *pref, const PRUnichar *);
00076 
00077   nsresult getBoolPref(const char *pref, PRBool *);
00078   nsresult getDefaultBoolPref(const char *pref, PRBool *);
00079   nsresult setBoolPref(const char *pref, PRBool);
00080 
00081   nsresult getIntPref(const char *pref, PRInt32 *);
00082   nsresult getDefaultIntPref(const char *pref, PRInt32 *);
00083   nsresult setIntPref(const char *pref, PRInt32);
00084 
00085   nsresult getFolderPref(const char *pref, char **, PRBool);
00086   nsresult setFolderPref(const char *pref, const char *);
00087 
00088 private:
00089   nsresult loadSmtpServer(nsISmtpServer**);
00090   
00091 };
00092 
00093 
00094 #define NS_IMPL_IDPREF_STR(_postfix, _prefname)  \
00095 NS_IMETHODIMP                                                         \
00096 nsMsgIdentity::Get##_postfix(char **retval)      \
00097 {                                                                                   \
00098   return getCharPref(_prefname, retval);         \
00099 }                                                                                   \
00100 NS_IMETHODIMP                                                         \
00101 nsMsgIdentity::Set##_postfix(const char *value)         \
00102 {                                                                                   \
00103   return setCharPref(_prefname, value);\
00104 }
00105 
00106 #define NS_IMPL_IDPREF_WSTR(_postfix, _prefname)\
00107 NS_IMETHODIMP                                                         \
00108 nsMsgIdentity::Get##_postfix(PRUnichar **retval)\
00109 {                                                                                   \
00110   return getUnicharPref(_prefname, retval);             \
00111 }                                                                                   \
00112 NS_IMETHODIMP                                                         \
00113 nsMsgIdentity::Set##_postfix(const PRUnichar *value)\
00114 {                                                                                   \
00115   return setUnicharPref(_prefname, value);\
00116 }
00117 
00118 #define NS_IMPL_IDPREF_BOOL(_postfix, _prefname)\
00119 NS_IMETHODIMP                                                         \
00120 nsMsgIdentity::Get##_postfix(PRBool *retval)     \
00121 {                                                                                   \
00122   return getBoolPref(_prefname, retval);         \
00123 }                                                                                   \
00124 NS_IMETHODIMP                                                         \
00125 nsMsgIdentity::Set##_postfix(PRBool value)              \
00126 {                                                                                   \
00127   return setBoolPref(_prefname, value);                 \
00128 }
00129 
00130 #define NS_IMPL_IDPREF_INT(_postfix, _prefname) \
00131 NS_IMETHODIMP                                                         \
00132 nsMsgIdentity::Get##_postfix(PRInt32 *retval)   \
00133 {                                                                                   \
00134   return getIntPref(_prefname, retval);          \
00135 }                                                                                   \
00136 NS_IMETHODIMP                                                         \
00137 nsMsgIdentity::Set##_postfix(PRInt32 value)             \
00138 {                                                                                   \
00139   return setIntPref(_prefname, value);                  \
00140 }
00141 
00142 
00143 #define NS_IMPL_FOLDERPREF_STR(_postfix, _prefname)     \
00144 NS_IMETHODIMP                                                         \
00145 nsMsgIdentity::Get##_postfix(char **retval)      \
00146 {                                                                                   \
00147   return getFolderPref(_prefname, retval, PR_TRUE);            \
00148 }                                                                                   \
00149 NS_IMETHODIMP                                                         \
00150 nsMsgIdentity::Set##_postfix(const char *value)         \
00151 {                                                                                   \
00152   return setFolderPref(_prefname, value);\
00153 }
00154 
00155 #endif /* nsMsgIdentity_h___ */