Back to index

lightning-sunbird  0.9+nobinonly
nsPrefBranch.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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 Communicator client 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  *   Brian Nesse <bnesse@netscape.com>
00025  *   Benjamin Smedberg <benjamin@smedbergs.us>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsIObserver.h"
00043 #include "nsIPrefBranch.h"
00044 #include "nsIPrefBranchInternal.h"
00045 #include "nsIPrefLocalizedString.h"
00046 #include "nsISecurityPref.h"
00047 #include "nsISupportsArray.h"
00048 #include "nsXPCOM.h"
00049 #include "nsISupportsPrimitives.h"
00050 #include "nsIRelativeFilePref.h"
00051 #include "nsILocalFile.h"
00052 #include "nsString.h"
00053 #include "nsVoidArray.h"
00054 #include "nsWeakReference.h"
00055 
00056 class nsPrefBranch : public nsIPrefBranchInternal,
00057                      public nsISecurityPref,
00058                      public nsIObserver,
00059                      public nsSupportsWeakReference
00060 {
00061 public:
00062   NS_DECL_ISUPPORTS
00063   NS_DECL_NSIPREFBRANCH
00064   NS_DECL_NSIPREFBRANCH2
00065   NS_DECL_NSISECURITYPREF
00066   NS_DECL_NSIOBSERVER
00067 
00068   nsPrefBranch(const char *aPrefRoot, PRBool aDefaultBranch);
00069   virtual ~nsPrefBranch();
00070 
00071   PRInt32 GetRootLength() { return mPrefRootLength; }
00072 
00073 protected:
00074   nsPrefBranch()     /* disallow use of this constructer */
00075     { };
00076 
00077   nsresult   GetDefaultFromPropertiesFile(const char *aPrefName, PRUnichar **return_buf);
00078   const char *getPrefName(const char *aPrefName);
00079   nsresult   getValidatedPrefName(const char *aPrefName, const char **_retval);
00080   void       freeObserverList(void);
00081 
00082 private:
00083   PRInt32         mPrefRootLength;
00084   nsAutoVoidArray *mObservers;
00085   nsCString       mPrefRoot;
00086   nsCStringArray  mObserverDomains;
00087   PRBool          mIsDefault;
00088 
00089 };
00090 
00091 
00092 class nsPrefLocalizedString : public nsIPrefLocalizedString,
00093                               public nsISupportsString
00094 {
00095 public:
00096   nsPrefLocalizedString();
00097   virtual ~nsPrefLocalizedString();
00098 
00099   NS_DECL_ISUPPORTS
00100   NS_FORWARD_NSISUPPORTSSTRING(mUnicodeString->)
00101   NS_FORWARD_NSISUPPORTSPRIMITIVE(mUnicodeString->)
00102 
00103   nsresult Init();
00104 
00105 private:
00106   NS_IMETHOD GetData(PRUnichar**);
00107   NS_IMETHOD SetData(const PRUnichar* aData);
00108   NS_IMETHOD SetDataWithLength(PRUint32 aLength, const PRUnichar *aData);
00109                                
00110   nsCOMPtr<nsISupportsString> mUnicodeString;
00111 };
00112 
00113 
00114 class nsRelativeFilePref : public nsIRelativeFilePref
00115 {
00116 public:
00117   NS_DECL_ISUPPORTS
00118   NS_DECL_NSIRELATIVEFILEPREF
00119   
00120                 nsRelativeFilePref();
00121   virtual       ~nsRelativeFilePref();
00122   
00123 private:
00124   nsCOMPtr<nsILocalFile> mFile;
00125   nsCAutoString mRelativeToKey; // An nsCAutoString because length is always very short.
00126                                 // While this makes the object larger, avoids allocation.
00127 };