whack prefs with a medium sized-stick.

also fix #33668, allow localized prefs to come from stringbundles
This commit is contained in:
alecf%netscape.com 2000-05-05 00:22:20 +00:00
Родитель 21fe0d47f9
Коммит 67e1074068
5 изменённых файлов: 156 добавлений и 430 удалений

Просмотреть файл

@ -93,6 +93,7 @@ interface nsIPref : nsISupports {
void SetBoolPref(in string pref, in boolean value);
[noscript] void SetBinaryPref(in string pref, in voidStar value, in unsigned long size);
void ClearUserPref(in string pref_name);
/* get defaults */
@ -108,10 +109,13 @@ interface nsIPref : nsISupports {
void SetDefaultBoolPref(in string pref, in boolean value);
[noscript] void SetDefaultBinaryPref(in string pref, in voidStar value, in unsigned long size);
/* copy versions of getters */
// these are eventually changing from Copy->get
string CopyCharPref(in string pref);
wstring CopyUnicharPref(in string pref);
[noscript] voidStar CopyBinaryPref(in string pref, out long size);
// "localized" prefs - stored in the properties files
wstring getLocalizedUnicharPref(in string pref);
string CopyDefaultCharPref(in string pref);
wstring CopyDefaultUnicharPref(in string pref);

Просмотреть файл

@ -71,6 +71,8 @@
#include "nsXPIDLString.h"
#include "nsScriptSecurityManager.h"
#include "nsIStringBundle.h"
#ifdef _WIN32
#include "windows.h"
#endif /* _WIN32 */
@ -87,6 +89,7 @@
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kSecurityManagerCID, NS_SCRIPTSECURITYMANAGER_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
//========================================================================================
class nsPref: public nsIPref
@ -473,47 +476,30 @@ NS_IMETHODIMP nsPref::GetPrefType(const char *pref, PRInt32 * return_type)
NS_IMETHODIMP nsPref::GetIntPref(const char *pref, PRInt32 * return_int)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetIntPref(pref, return_int));
return _convertRes(PREF_GetIntPref(pref, return_int, PR_FALSE));
}
NS_IMETHODIMP nsPref::GetBoolPref(const char *pref, PRBool * return_val)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetBoolPref(pref, return_val));
return _convertRes(PREF_GetBoolPref(pref, return_val, PR_FALSE));
}
NS_IMETHODIMP nsPref::GetBinaryPref(const char *pref,
void * return_val, int * buf_length)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length));
return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length, PR_FALSE));
}
#if 0
NS_IMETHODIMP nsPref::GetColorPref(const char *pref,
PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetColorPref(pref, red, green, blue));
}
#endif
NS_IMETHODIMP nsPref::GetColorPrefDWord(const char *pref,
PRUint32 *colorref)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetColorPrefDWord(pref, colorref));
return _convertRes(PREF_GetColorPrefDWord(pref, colorref, PR_FALSE));
}
#if 0
NS_IMETHODIMP nsPref::GetRectPref(const char *pref,
PRInt16 *left, PRInt16 *top,
PRInt16 *right, PRInt16 *bottom)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetRectPref(pref, left, top, right, bottom));
}
#endif
/*
* Setters
@ -559,33 +545,6 @@ NS_IMETHODIMP nsPref::SetBinaryPref(const char *pref,void * value, PRUint32 size
return _convertRes(PREF_SetBinaryPref(pref, value, size));
}
#if 0
NS_IMETHODIMP nsPref::SetColorPref(const char *pref,
PRUint8 red, PRUint8 green, PRUint8 blue)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_SetColorPref(pref, red, green, blue));
}
#endif
#if 0
NS_IMETHODIMP nsPref::SetColorPrefDWord(const char *pref,
PRUint32 value)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_SetColorPrefDWord(pref, value));
}
#endif
#if 0
NS_IMETHODIMP nsPref::SetRectPref(const char *pref,
PRInt16 left, PRInt16 top,
PRInt16 right, PRInt16 bottom)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_SetRectPref(pref, left, top, right, bottom));
}
#endif
/*
* Get Defaults
@ -595,14 +554,14 @@ NS_IMETHODIMP nsPref::GetDefaultIntPref(const char *pref,
PRInt32 * return_int)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetDefaultIntPref(pref, return_int));
return _convertRes(PREF_GetIntPref(pref, return_int, PR_TRUE));
}
NS_IMETHODIMP nsPref::GetDefaultBoolPref(const char *pref,
PRBool * return_val)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetDefaultBoolPref(pref, return_val));
return _convertRes(PREF_GetBoolPref(pref, return_val, PR_TRUE));
}
NS_IMETHODIMP nsPref::GetDefaultBinaryPref(const char *pref,
@ -610,38 +569,9 @@ NS_IMETHODIMP nsPref::GetDefaultBinaryPref(const char *pref,
int * buf_length)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetDefaultBinaryPref(pref, return_val, buf_length));
return _convertRes(PREF_GetBinaryPref(pref, return_val, buf_length, PR_TRUE));
}
#if 0
NS_IMETHODIMP nsPref::GetDefaultColorPref(const char *pref,
PRUint8 *red, PRUint8 *green,
PRUint8 *blue)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetDefaultColorPref(pref, red, green, blue));
}
#endif
#if 0
NS_IMETHODIMP nsPref::GetDefaultColorPrefDWord(const char *pref,
PRUint32 *colorref)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetDefaultColorPrefDWord(pref, colorref));
}
#endif
#if 0
NS_IMETHODIMP nsPref::GetDefaultRectPref(const char *pref,
PRInt16 *left, PRInt16 *top,
PRInt16 *right, PRInt16 *bottom)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_GetDefaultRectPref(pref,
left, top, right, bottom));
}
#endif
/*
* Set defaults
@ -689,24 +619,6 @@ NS_IMETHODIMP nsPref::SetDefaultBinaryPref(const char *pref,
return _convertRes(PREF_SetDefaultBinaryPref(pref, value, size));
}
#if 0
NS_IMETHODIMP nsPref::SetDefaultColorPref(const char *pref,
PRUint8 red, PRUint8 green, PRUint8 blue)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_SetDefaultColorPref(pref, red, green, blue));
}
#endif
#if 0
NS_IMETHODIMP nsPref::SetDefaultRectPref(const char *pref,
PRInt16 left, PRInt16 top,
PRInt16 right, PRInt16 bottom)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_SetDefaultRectPref(pref, left, top, right, bottom));
}
#endif
NS_IMETHODIMP nsPref::ClearUserPref(const char *pref_name)
{
@ -721,7 +633,7 @@ NS_IMETHODIMP nsPref::ClearUserPref(const char *pref_name)
NS_IMETHODIMP nsPref::CopyCharPref(const char *pref, char ** return_buf)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_CopyCharPref(pref, return_buf));
return _convertRes(PREF_CopyCharPref(pref, return_buf, PR_FALSE));
}
// unicode "%s" format string
@ -744,6 +656,38 @@ NS_IMETHODIMP nsPref::CopyUnicharPref(const char *pref, PRUnichar ** return_buf)
return convertUTF8ToUnicode(utf8String, return_buf);
}
NS_IMETHODIMP
nsPref::GetLocalizedUnicharPref(const char *pref, PRUnichar **return_buf)
{
nsresult rv;
// if the user has set this pref, then just return the user value
if (PREF_HasUserPref(pref))
return CopyUnicharPref(pref, return_buf);
// user has not set the pref, so the default value
// contains a URL to a .properties file
nsXPIDLCString propertyFileURL;
rv = CopyCharPref(pref, getter_Copies(propertyFileURL));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(propertyFileURL, nsnull,
getter_AddRefs(bundle));
if (NS_FAILED(rv)) return rv;
// string names are in unicdoe
nsAutoString stringId;
stringId.AssignWithConversion(pref);
return bundle->GetStringFromName(stringId.GetUnicode(), return_buf);
}
nsresult
nsPref::convertUTF8ToUnicode(const char *utf8String, PRUnichar ** aResult)
{
@ -766,14 +710,14 @@ NS_IMETHODIMP nsPref::CopyBinaryPref(const char *pref,
int *size, void ** return_value)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_CopyBinaryPref(pref, return_value, size));
return _convertRes(PREF_CopyBinaryPref(pref, return_value, size, PR_FALSE));
}
NS_IMETHODIMP nsPref::CopyDefaultCharPref( const char *pref,
char ** return_buffer )
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_CopyDefaultCharPref(pref, return_buffer));
return _convertRes(PREF_CopyCharPref(pref, return_buffer, PR_TRUE));
}
NS_IMETHODIMP nsPref::CopyDefaultUnicharPref( const char *pref,
@ -793,31 +737,9 @@ NS_IMETHODIMP nsPref::CopyDefaultBinaryPref(const char *pref,
int * size, void ** return_val)
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_CopyDefaultBinaryPref(pref, return_val, size));
return _convertRes(PREF_CopyBinaryPref(pref, return_val, size, PR_TRUE));
}
#if 0
/*
* Path prefs
*/
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPref::CopyPathPref(const char *pref, char ** return_buf)
//----------------------------------------------------------------------------------------
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_CopyPathPref(pref, return_buf));
}
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPref::SetPathPref(const char *pref,
const char *path, PRBool set_default)
//----------------------------------------------------------------------------------------
{
if (NS_FAILED(SecurePrefCheck(pref))) return NS_ERROR_FAILURE;
return _convertRes(PREF_SetPathPref(pref, path, set_default));
}
#endif
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPref::GetFilePref(const char *pref_name, nsIFileSpec** value)
@ -837,9 +759,8 @@ NS_IMETHODIMP nsPref::GetFilePref(const char *pref_name, nsIFileSpec** value)
return NS_ERROR_FAILURE;
char *encodedString = nsnull;
PrefResult result = PREF_CopyCharPref(pref_name, &encodedString);
if (result != PREF_NOERROR)
return _convertRes(result);
rv = CopyCharPref(pref_name, &encodedString);
if (NS_FAILED(rv)) return rv;
PRBool valid;
(*value)->SetPersistentDescriptorString(encodedString);
@ -848,7 +769,7 @@ NS_IMETHODIMP nsPref::GetFilePref(const char *pref_name, nsIFileSpec** value)
/* if the ecodedString wasn't a valid persitent descriptor, it might be a valid native path*/
(*value)->SetNativePath(encodedString);
PR_Free(encodedString); // Allocated by PREF_CopyCharPref
PR_Free(encodedString); // Allocated by CopyCharPref
return NS_OK;
}
@ -934,14 +855,6 @@ NS_IMETHODIMP nsPref::UnregisterCallback( const char* domain,
* Tree editing
*/
#if 0
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPref::CopyPrefsTree(const char *srcRoot, const char *destRoot)
//----------------------------------------------------------------------------------------
{
return _convertRes(PREF_CopyPrefsTree(srcRoot, destRoot));
}
#endif
//----------------------------------------------------------------------------------------
NS_IMETHODIMP nsPref::DeleteBranch(const char *branchName)
//----------------------------------------------------------------------------------------

Просмотреть файл

@ -233,10 +233,6 @@ PR_EXTERN(PrefResult) PREF_SavePrefFileWith(const char *filename, PLHashEnumerat
PRBool pref_VerifyLockFile(char* buf, long buflen);
PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default);
PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default);
PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default);
PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default);
JSBool PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script);
void pref_ErrorReporter(JSContext *cx, const char *message,JSErrorReport *report);
@ -1216,7 +1212,22 @@ PR_IMPLEMENT(PrefResult) PREF_SavePrefFileAs(const char *filename)
}
#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */
PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default)
PRBool PREF_HasUserPref(const char *pref_name)
{
PrefNode *pref;
if (!gHashTable && !pref_useDefaultPrefFile())
return PR_FALSE;
pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name);
if (!pref) return PR_FALSE;
// convert PREF_HAS_USER_VALUE to bool
return (PREF_HAS_USER_VALUE(pref) != 0);
}
PrefResult PREF_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default)
{
PrefResult result = PREF_ERROR;
char* stringVal;
@ -1250,7 +1261,8 @@ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * l
return result;
}
PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default)
PrefResult
PREF_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default)
{
PrefResult result = PREF_ERROR;
char* stringVal;
@ -1276,7 +1288,7 @@ PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBoo
return result;
}
PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default)
PrefResult PREF_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default)
{
PrefResult result = PREF_ERROR;
PrefNode* pref;
@ -1301,7 +1313,7 @@ PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool ge
return result;
}
PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default)
PrefResult PREF_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default)
{
PrefResult result = PREF_ERROR;
PrefNode* pref;
@ -1327,37 +1339,14 @@ PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool
}
PR_IMPLEMENT(PrefResult)
PREF_GetCharPref(const char *pref_name, char * return_buffer, int * length)
{
return pref_GetCharPref(pref_name, return_buffer, length, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_CopyCharPref(const char *pref_name, char ** return_buffer)
{
return pref_CopyCharPref(pref_name, return_buffer, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetIntPref(const char *pref_name,PRInt32 * return_int)
{
return pref_GetIntPref(pref_name, return_int, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetBoolPref(const char *pref_name, PRBool * return_value)
{
return pref_GetBoolPref(pref_name, return_value, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
PrefResult
PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue, PRBool isDefault)
{
char colstr[8];
int iSize = 8;
PrefResult result = PREF_GetCharPref(pref_name, colstr, &iSize);
PrefResult result = PREF_GetCharPref(pref_name, colstr, &iSize, isDefault);
if (result == PREF_NOERROR)
{
@ -1372,44 +1361,28 @@ PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *
#define MYRGB(r, g ,b) ((PRUint32) (((PRUint8) (r) | ((PRUint16) (g) << 8)) | (((PRUint32) (PRUint8) (b)) << 16)))
PR_IMPLEMENT(PrefResult)
PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref)
PrefResult
PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref, PRBool isDefault)
{
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetColorPref(pref_name, &red, &green, &blue);
result = PREF_GetColorPref(pref_name, &red, &green, &blue, isDefault);
if (result == PREF_NOERROR)
*colorref = MYRGB(red,green,blue);
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[64];
int iSize=64;
PrefResult result = PREF_GetCharPref(pref_name, rectstr, &iSize);
if (result == PREF_NOERROR)
{
int l, t, r, b;
sscanf(rectstr, "%i,%i,%i,%i", &l, &t, &r, &b);
*left = l; *top = t;
*right = r; *bottom = b;
}
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size)
PrefResult
PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size, PRBool isDefault)
{
char* buf;
PrefResult result;
if (!gMochaPrefObject || !return_value) return PREF_ERROR;
result = PREF_CopyCharPref(pref_name, &buf);
result = PREF_CopyCharPref(pref_name, &buf, isDefault);
if (result == PREF_NOERROR)
{
@ -1426,10 +1399,10 @@ PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size)
return result;
}
typedef PrefResult (*CharPrefReadFunc)(const char*, char**);
typedef PrefResult (*CharPrefReadFunc)(const char*, char**, PRBool);
static PrefResult
ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPrefReadFunc inFunc)
ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPrefReadFunc inFunc, PRBool isDefault)
{
char* buf;
PrefResult result;
@ -1438,7 +1411,7 @@ ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPre
return PREF_ERROR;
*return_value = NULL;
result = inFunc(pref_name, &buf);
result = inFunc(pref_name, &buf, isDefault);
if (result == PREF_NOERROR)
{
@ -1456,23 +1429,17 @@ ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPre
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size)
PrefResult
PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size, PRBool isDefault)
{
return ReadCharPrefUsing(pref_name, return_value, size, PREF_CopyCharPref);
}
PR_IMPLEMENT(PrefResult)
PREF_CopyDefaultBinaryPref(const char *pref_name, void ** return_value, int *size)
{
return ReadCharPrefUsing(pref_name, return_value, size, PREF_CopyDefaultCharPref);
return ReadCharPrefUsing(pref_name, return_value, size, PREF_CopyCharPref, isDefault);
}
#ifndef XP_MAC
PR_IMPLEMENT(PrefResult)
PREF_CopyPathPref(const char *pref_name, char ** return_buffer)
PREF_CopyPathPref(const char *pref_name, char ** return_buffer, PRBool isDefault)
{
return PREF_CopyCharPref(pref_name, return_buffer);
return PREF_CopyCharPref(pref_name, return_buffer, isDefault);
}
PR_IMPLEMENT(PrefResult)
@ -1487,37 +1454,7 @@ PREF_SetPathPref(const char *pref_name, const char *path, PRBool set_default)
#endif /* XP_MAC */
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultCharPref(const char *pref_name, char * return_buffer, int * length)
{
return pref_GetCharPref(pref_name, return_buffer, length, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_CopyDefaultCharPref(const char *pref_name, char ** return_buffer)
{
return pref_CopyCharPref(pref_name, return_buffer, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultIntPref(const char *pref_name, PRInt32 * return_int)
{
return pref_GetIntPref(pref_name, return_int, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultBoolPref(const char *pref_name, PRBool * return_value)
{
return pref_GetBoolPref(pref_name, return_value, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultBinaryPref(const char *pref_name, void * return_value, int * length)
{
PR_ASSERT( PR_FALSE );
return PREF_ERROR;
}
#if 0
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
@ -1537,30 +1474,7 @@ PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PR
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 * colorref)
{
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetDefaultColorPref(pref_name, &red, &green, &blue);
if (result == PREF_NOERROR)
*colorref = MYRGB(red,green,blue);
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[256];
int iLen = 256;
PrefResult result = PREF_GetDefaultCharPref(pref_name, (char *)&rectstr, &iLen);
if (result == PREF_NOERROR)
sscanf(rectstr, "%hd,%hd,%hd,%hd", left, top, right, bottom);
return result;
}
#endif
/* Delete a branch. Used for deleting mime types */
PR_IMPLEMENT(int)
@ -2187,7 +2101,7 @@ PrefResult pref_copyTree(const char *srcPrefix, const char *destPrefix, const ch
{
char *prefVal = NULL;
result = PREF_CopyCharPref(child, &prefVal);
result = PREF_CopyCharPref(child, &prefVal, PR_FALSE);
if (result == PREF_NOERROR)
result = PREF_SetCharPref(destPrefName, prefVal);
@ -2199,7 +2113,7 @@ PrefResult pref_copyTree(const char *srcPrefix, const char *destPrefix, const ch
{
PRInt32 prefValInt;
result = PREF_GetIntPref(child, &prefValInt);
result = PREF_GetIntPref(child, &prefValInt, PR_FALSE);
if (result == PREF_NOERROR)
result = PREF_SetIntPref(destPrefName, prefValInt);
}
@ -2209,7 +2123,7 @@ PrefResult pref_copyTree(const char *srcPrefix, const char *destPrefix, const ch
{
PRBool prefBool;
result = PREF_GetBoolPref(child, &prefBool);
result = PREF_GetBoolPref(child, &prefBool, PR_FALSE);
if (result == PREF_NOERROR)
result = PREF_SetBoolPref(destPrefName, prefBool);
}
@ -2719,7 +2633,7 @@ static int pref_CountListMembers(char* list)
/*--------------------------------------------------------------------------------------*/
PR_IMPLEMENT(PrefResult) PREF_GetListPref(const char* pref, char*** list)
PR_IMPLEMENT(PrefResult) PREF_GetListPref(const char* pref, char*** list, PRBool isDefault)
/* Splits a comma separated string into an array of strings.
* The array of strings is actually just an array of pointers into a copy
* of the value returned by PREF_CopyCharPref(). So, we don't have to
@ -2732,7 +2646,7 @@ PR_IMPLEMENT(PrefResult) PREF_GetListPref(const char* pref, char*** list)
*list = NULL;
if ( PREF_CopyCharPref(pref, &value) != PREF_OK || value == NULL )
if ( PREF_CopyCharPref(pref, &value, isDefault) != PREF_OK || value == NULL )
return PREF_ERROR;
nugmembers = pref_CountListMembers(value);
@ -2796,7 +2710,7 @@ PREF_AppendListPref(const char* pref, const char* value)
char *pListPref = NULL, *pNewList = NULL;
int nPrefLen = 0;
PREF_CopyCharPref(pref, &pListPref);
PREF_CopyCharPref(pref, &pListPref, PR_FALSE);
if (pListPref)
{

Просмотреть файл

@ -233,10 +233,6 @@ PR_EXTERN(PrefResult) PREF_SavePrefFileWith(const char *filename, PLHashEnumerat
PRBool pref_VerifyLockFile(char* buf, long buflen);
PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default);
PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default);
PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default);
PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default);
JSBool PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script);
void pref_ErrorReporter(JSContext *cx, const char *message,JSErrorReport *report);
@ -1216,7 +1212,22 @@ PR_IMPLEMENT(PrefResult) PREF_SavePrefFileAs(const char *filename)
}
#endif /* PREF_SUPPORT_OLD_PATH_STRINGS */
PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default)
PRBool PREF_HasUserPref(const char *pref_name)
{
PrefNode *pref;
if (!gHashTable && !pref_useDefaultPrefFile())
return PR_FALSE;
pref = (PrefNode*) PR_HashTableLookup(gHashTable, pref_name);
if (!pref) return PR_FALSE;
// convert PREF_HAS_USER_VALUE to bool
return (PREF_HAS_USER_VALUE(pref) != 0);
}
PrefResult PREF_GetCharPref(const char *pref_name, char * return_buffer, int * length, PRBool get_default)
{
PrefResult result = PREF_ERROR;
char* stringVal;
@ -1250,7 +1261,8 @@ PrefResult pref_GetCharPref(const char *pref_name, char * return_buffer, int * l
return result;
}
PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default)
PrefResult
PREF_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool get_default)
{
PrefResult result = PREF_ERROR;
char* stringVal;
@ -1276,7 +1288,7 @@ PrefResult pref_CopyCharPref(const char *pref_name, char ** return_buffer, PRBoo
return result;
}
PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default)
PrefResult PREF_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_default)
{
PrefResult result = PREF_ERROR;
PrefNode* pref;
@ -1301,7 +1313,7 @@ PrefResult pref_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool ge
return result;
}
PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default)
PrefResult PREF_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool get_default)
{
PrefResult result = PREF_ERROR;
PrefNode* pref;
@ -1327,37 +1339,14 @@ PrefResult pref_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool
}
PR_IMPLEMENT(PrefResult)
PREF_GetCharPref(const char *pref_name, char * return_buffer, int * length)
{
return pref_GetCharPref(pref_name, return_buffer, length, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_CopyCharPref(const char *pref_name, char ** return_buffer)
{
return pref_CopyCharPref(pref_name, return_buffer, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetIntPref(const char *pref_name,PRInt32 * return_int)
{
return pref_GetIntPref(pref_name, return_int, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetBoolPref(const char *pref_name, PRBool * return_value)
{
return pref_GetBoolPref(pref_name, return_value, PR_FALSE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
PrefResult
PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue, PRBool isDefault)
{
char colstr[8];
int iSize = 8;
PrefResult result = PREF_GetCharPref(pref_name, colstr, &iSize);
PrefResult result = PREF_GetCharPref(pref_name, colstr, &iSize, isDefault);
if (result == PREF_NOERROR)
{
@ -1372,44 +1361,28 @@ PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *
#define MYRGB(r, g ,b) ((PRUint32) (((PRUint8) (r) | ((PRUint16) (g) << 8)) | (((PRUint32) (PRUint8) (b)) << 16)))
PR_IMPLEMENT(PrefResult)
PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref)
PrefResult
PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref, PRBool isDefault)
{
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetColorPref(pref_name, &red, &green, &blue);
result = PREF_GetColorPref(pref_name, &red, &green, &blue, isDefault);
if (result == PREF_NOERROR)
*colorref = MYRGB(red,green,blue);
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[64];
int iSize=64;
PrefResult result = PREF_GetCharPref(pref_name, rectstr, &iSize);
if (result == PREF_NOERROR)
{
int l, t, r, b;
sscanf(rectstr, "%i,%i,%i,%i", &l, &t, &r, &b);
*left = l; *top = t;
*right = r; *bottom = b;
}
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size)
PrefResult
PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size, PRBool isDefault)
{
char* buf;
PrefResult result;
if (!gMochaPrefObject || !return_value) return PREF_ERROR;
result = PREF_CopyCharPref(pref_name, &buf);
result = PREF_CopyCharPref(pref_name, &buf, isDefault);
if (result == PREF_NOERROR)
{
@ -1426,10 +1399,10 @@ PREF_GetBinaryPref(const char *pref_name, void * return_value, int *size)
return result;
}
typedef PrefResult (*CharPrefReadFunc)(const char*, char**);
typedef PrefResult (*CharPrefReadFunc)(const char*, char**, PRBool);
static PrefResult
ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPrefReadFunc inFunc)
ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPrefReadFunc inFunc, PRBool isDefault)
{
char* buf;
PrefResult result;
@ -1438,7 +1411,7 @@ ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPre
return PREF_ERROR;
*return_value = NULL;
result = inFunc(pref_name, &buf);
result = inFunc(pref_name, &buf, isDefault);
if (result == PREF_NOERROR)
{
@ -1456,23 +1429,17 @@ ReadCharPrefUsing(const char *pref_name, void** return_value, int *size, CharPre
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size)
PrefResult
PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size, PRBool isDefault)
{
return ReadCharPrefUsing(pref_name, return_value, size, PREF_CopyCharPref);
}
PR_IMPLEMENT(PrefResult)
PREF_CopyDefaultBinaryPref(const char *pref_name, void ** return_value, int *size)
{
return ReadCharPrefUsing(pref_name, return_value, size, PREF_CopyDefaultCharPref);
return ReadCharPrefUsing(pref_name, return_value, size, PREF_CopyCharPref, isDefault);
}
#ifndef XP_MAC
PR_IMPLEMENT(PrefResult)
PREF_CopyPathPref(const char *pref_name, char ** return_buffer)
PREF_CopyPathPref(const char *pref_name, char ** return_buffer, PRBool isDefault)
{
return PREF_CopyCharPref(pref_name, return_buffer);
return PREF_CopyCharPref(pref_name, return_buffer, isDefault);
}
PR_IMPLEMENT(PrefResult)
@ -1487,37 +1454,7 @@ PREF_SetPathPref(const char *pref_name, const char *path, PRBool set_default)
#endif /* XP_MAC */
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultCharPref(const char *pref_name, char * return_buffer, int * length)
{
return pref_GetCharPref(pref_name, return_buffer, length, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_CopyDefaultCharPref(const char *pref_name, char ** return_buffer)
{
return pref_CopyCharPref(pref_name, return_buffer, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultIntPref(const char *pref_name, PRInt32 * return_int)
{
return pref_GetIntPref(pref_name, return_int, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultBoolPref(const char *pref_name, PRBool * return_value)
{
return pref_GetBoolPref(pref_name, return_value, PR_TRUE);
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultBinaryPref(const char *pref_name, void * return_value, int * length)
{
PR_ASSERT( PR_FALSE );
return PREF_ERROR;
}
#if 0
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue)
{
@ -1537,30 +1474,7 @@ PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PR
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 * colorref)
{
PRUint8 red, green, blue;
PrefResult result;
PR_ASSERT(colorref);
result = PREF_GetDefaultColorPref(pref_name, &red, &green, &blue);
if (result == PREF_NOERROR)
*colorref = MYRGB(red,green,blue);
return result;
}
PR_IMPLEMENT(PrefResult)
PREF_GetDefaultRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom)
{
char rectstr[256];
int iLen = 256;
PrefResult result = PREF_GetDefaultCharPref(pref_name, (char *)&rectstr, &iLen);
if (result == PREF_NOERROR)
sscanf(rectstr, "%hd,%hd,%hd,%hd", left, top, right, bottom);
return result;
}
#endif
/* Delete a branch. Used for deleting mime types */
PR_IMPLEMENT(int)
@ -2187,7 +2101,7 @@ PrefResult pref_copyTree(const char *srcPrefix, const char *destPrefix, const ch
{
char *prefVal = NULL;
result = PREF_CopyCharPref(child, &prefVal);
result = PREF_CopyCharPref(child, &prefVal, PR_FALSE);
if (result == PREF_NOERROR)
result = PREF_SetCharPref(destPrefName, prefVal);
@ -2199,7 +2113,7 @@ PrefResult pref_copyTree(const char *srcPrefix, const char *destPrefix, const ch
{
PRInt32 prefValInt;
result = PREF_GetIntPref(child, &prefValInt);
result = PREF_GetIntPref(child, &prefValInt, PR_FALSE);
if (result == PREF_NOERROR)
result = PREF_SetIntPref(destPrefName, prefValInt);
}
@ -2209,7 +2123,7 @@ PrefResult pref_copyTree(const char *srcPrefix, const char *destPrefix, const ch
{
PRBool prefBool;
result = PREF_GetBoolPref(child, &prefBool);
result = PREF_GetBoolPref(child, &prefBool, PR_FALSE);
if (result == PREF_NOERROR)
result = PREF_SetBoolPref(destPrefName, prefBool);
}
@ -2719,7 +2633,7 @@ static int pref_CountListMembers(char* list)
/*--------------------------------------------------------------------------------------*/
PR_IMPLEMENT(PrefResult) PREF_GetListPref(const char* pref, char*** list)
PR_IMPLEMENT(PrefResult) PREF_GetListPref(const char* pref, char*** list, PRBool isDefault)
/* Splits a comma separated string into an array of strings.
* The array of strings is actually just an array of pointers into a copy
* of the value returned by PREF_CopyCharPref(). So, we don't have to
@ -2732,7 +2646,7 @@ PR_IMPLEMENT(PrefResult) PREF_GetListPref(const char* pref, char*** list)
*list = NULL;
if ( PREF_CopyCharPref(pref, &value) != PREF_OK || value == NULL )
if ( PREF_CopyCharPref(pref, &value, isDefault) != PREF_OK || value == NULL )
return PREF_ERROR;
nugmembers = pref_CountListMembers(value);
@ -2796,7 +2710,7 @@ PREF_AppendListPref(const char* pref, const char* value)
char *pListPref = NULL, *pNewList = NULL;
int nPrefLen = 0;
PREF_CopyCharPref(pref, &pListPref);
PREF_CopyCharPref(pref, &pListPref, PR_FALSE);
if (pListPref)
{

Просмотреть файл

@ -249,6 +249,8 @@ PR_EXTERN(PrefResult) PREF_SetDefaultBinaryPref(const char *pref,void * value, l
PR_EXTERN(PrefResult) PREF_SetDefaultColorPref(const char *pref_name, PRUint8 red, PRUint8 green, PRUint8 blue);
PR_EXTERN(PrefResult) PREF_SetDefaultRectPref(const char *pref_name, PRInt16 left, PRInt16 top, PRInt16 right, PRInt16 bottom);
PRBool PREF_HasUserPref(const char* pref_name);
/*
// <font color=blue>
// Get the various types of preferences. These functions take a dotted
@ -267,14 +269,12 @@ PR_EXTERN(PrefResult) PREF_SetDefaultRectPref(const char *pref_name, PRInt16 lef
// (if it is reasonably possible)
// </font>
*/
PR_EXTERN(PrefResult) PREF_GetCharPref(const char *pref, char * return_buf, int * buf_length);
PR_EXTERN(PrefResult) PREF_GetIntPref(const char *pref, PRInt32 * return_int);
PR_EXTERN(PrefResult) PREF_GetBoolPref(const char *pref, PRBool * return_val);
PR_EXTERN(PrefResult) PREF_GetBinaryPref(const char *pref, void * return_val, int * buf_length);
PR_EXTERN(PrefResult) PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue);
PR_EXTERN(PrefResult) PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref);
PR_EXTERN(PrefResult) PREF_GetRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom);
PrefResult PREF_GetIntPref(const char *pref,
PRInt32 * return_int, PRBool isDefault);
PrefResult PREF_GetBoolPref(const char *pref, PRBool * return_val, PRBool isDefault);
PrefResult PREF_GetBinaryPref(const char *pref, void * return_val, int * buf_length, PRBool isDefault);
PrefResult PREF_GetColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue, PRBool isDefault);
PrefResult PREF_GetColorPrefDWord(const char *pref_name, PRUint32 *colorref, PRBool isDefault);
/*
// <font color=blue>
// These functions are similar to the above "Get" version with the significant
@ -282,11 +282,8 @@ PR_EXTERN(PrefResult) PREF_GetRectPref(const char *pref_name, PRInt16 *left, PRI
// the caller will need to be responsible for freeing it...
// </font>
*/
PR_EXTERN(PrefResult) PREF_CopyCharPref(const char *pref, char ** return_buf);
PR_EXTERN(PrefResult) PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size);
PR_EXTERN(PrefResult) PREF_CopyDefaultCharPref( const char *pref_name, char ** return_buffer );
PR_EXTERN(PrefResult) PREF_CopyDefaultBinaryPref(const char *pref, void ** return_val, int * size);
PrefResult PREF_CopyCharPref(const char *pref, char ** return_buf, PRBool isDefault);
PrefResult PREF_CopyBinaryPref(const char *pref_name, void ** return_value, int *size, PRBool isDefault);
/*
// <font color=blue>
@ -297,25 +294,9 @@ PR_EXTERN(PrefResult) PREF_CopyDefaultBinaryPref(const char *pref, void ** retur
// between paths and aliases flattened into binary strings.
// </font>
*/
PR_EXTERN(PrefResult) PREF_CopyPathPref(const char *pref, char ** return_buf);
PR_EXTERN(PrefResult) PREF_CopyPathPref(const char *pref, char ** return_buf, PRBool isDefault);
PR_EXTERN(PrefResult) PREF_SetPathPref(const char *pref_name, const char *path, PRBool set_default);
/*
// <font color=blue>
// Same as the previous "Get" functions but will always return the
// default value regardless of what the user has set. These are designed
// to be used by functions which "reset" the preferences
//
// </font>
*/
PR_EXTERN(PrefResult) PREF_GetDefaultCharPref(const char *pref, char * return_buf, int * buf_length);
PR_EXTERN(PrefResult) PREF_GetDefaultIntPref(const char *pref, PRInt32 * return_int);
PR_EXTERN(PrefResult) PREF_GetDefaultBoolPref(const char *pref, PRBool * return_val);
PR_EXTERN(PrefResult) PREF_GetDefaultBinaryPref(const char *pref, void * return_val, int * buf_length);
PR_EXTERN(PrefResult) PREF_GetDefaultColorPref(const char *pref_name, PRUint8 *red, PRUint8 *green, PRUint8 *blue);
PR_EXTERN(PrefResult) PREF_GetDefaultColorPrefDWord(const char *pref_name, PRUint32 *colorref);
PR_EXTERN(PrefResult) PREF_GetDefaultRectPref(const char *pref_name, PRInt16 *left, PRInt16 *top, PRInt16 *right, PRInt16 *bottom);
/*
// <font color=blue>
// Administration Kit support
@ -342,7 +323,7 @@ PR_EXTERN(PrefResult) PREF_GetConfigBool(const char *obj_name, PRBool *return_bo
/*
* Listpref API
*/
PR_EXTERN(PrefResult) PREF_GetListPref(const char *pref_name, char*** list);
PR_EXTERN(PrefResult) PREF_GetListPref(const char *pref_name, char*** list, PRBool isDefault);
PR_EXTERN(PrefResult) PREF_SetListPref(const char *pref_name, char** list);
PR_EXTERN(PrefResult) PREF_AppendListPref(const char *pref_name, const char *value);
PR_EXTERN(PrefResult) PREF_FreeListPref(char*** list);