mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Prefs API changed to use filespecs instead of string paths. Added Get/SetFilePref. Cleaned up the API so that StartUp() does not need to be called.
This commit is contained in:
parent
7fb6d19406
commit
e4661eacd6
@ -883,6 +883,9 @@ sub BuildMailNewsProjects()
|
||||
|
||||
sub BuildProjects()
|
||||
{
|
||||
# activate Toolserver
|
||||
ActivateApplication('MPSX');
|
||||
|
||||
# activate CodeWarrior
|
||||
ActivateApplication('CWIE');
|
||||
|
||||
|
@ -441,10 +441,10 @@ int main()
|
||||
// has the ability to take nsnull as a parameter. Once that happens,
|
||||
// prefs will do the work of figuring out which prefs file to load...
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &result);
|
||||
if (NS_SUCCEEDED(result) && prefs)
|
||||
{
|
||||
prefs->Startup("prefs50.js");
|
||||
}
|
||||
// if (NS_SUCCEEDED(result) && prefs)
|
||||
// {
|
||||
// prefs->Startup("prefs50.js");
|
||||
// }
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
nsIEventQueueService* pEventQService;
|
||||
|
@ -468,11 +468,13 @@ int main()
|
||||
// mscott - this is just a bad bad bad hack right now until prefs
|
||||
// has the ability to take nsnull as a parameter. Once that happens,
|
||||
// prefs will do the work of figuring out which prefs file to load...
|
||||
// jrm - You don't even need to call this now. Just using the service
|
||||
// should do the trick.
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &result);
|
||||
if (NS_SUCCEEDED(result) && prefs)
|
||||
{
|
||||
prefs->Startup("prefs50.js");
|
||||
}
|
||||
// if (NS_SUCCEEDED(result) && prefs)
|
||||
// {
|
||||
// prefs->StartUp();
|
||||
// }
|
||||
|
||||
// Create the Event Queue for this thread...
|
||||
nsIEventQueueService* pEventQService;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "jsapi.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsFileSpec;
|
||||
|
||||
/* Temporarily conditionally compile PrefChangedFunc typedef.
|
||||
** During migration from old libpref to nsIPref we need it in
|
||||
** both header files. Eventually prefapi.h will become a private
|
||||
@ -59,24 +61,48 @@ public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPREF_IID)
|
||||
|
||||
// Initialize/shutdown
|
||||
NS_IMETHOD Startup(const char *filename) = 0;
|
||||
NS_IMETHOD Shutdown() = 0;
|
||||
#ifdef PREF_SUPPORT_OLD_PATH_STRINGS
|
||||
nsresult Shutdown() { return ShutDown(); }
|
||||
nsresult Startup(void*) { return StartUp(); }
|
||||
NS_IMETHOD ReadUserJSFile(const char *filename) = 0; // deprecated
|
||||
NS_IMETHOD ReadLIJSFile(const char *filename) = 0; // deprecated
|
||||
NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length,
|
||||
const char* filename,
|
||||
PRBool bGlobalContext,
|
||||
PRBool bCallbacks) = 0; // deprecated
|
||||
NS_IMETHOD SavePrefFileAs(const char *filename) = 0;
|
||||
NS_IMETHOD SaveLIPrefFile(const char *filename) = 0;
|
||||
|
||||
// Path prefs
|
||||
NS_IMETHOD CopyPathPref(const char *pref, char ** return_buf) = 0;
|
||||
NS_IMETHOD SetPathPref(const char *pref_name,
|
||||
const char *path, PRBool set_default) = 0;
|
||||
#endif
|
||||
// Initialize/shut down
|
||||
NS_IMETHOD StartUp() = 0;
|
||||
NS_IMETHOD StartUpWith(const nsFileSpec& inSpec) = 0;
|
||||
NS_IMETHOD ShutDown() = 0;
|
||||
|
||||
// Config file input
|
||||
NS_IMETHOD ReadUserJSFile(const char *filename) = 0;
|
||||
NS_IMETHOD ReadLIJSFile(const char *filename) = 0;
|
||||
NS_IMETHOD ReadUserJSFile(const nsFileSpec& inSpec) = 0;
|
||||
NS_IMETHOD ReadLIJSFile(const nsFileSpec& inSpec) = 0;
|
||||
|
||||
NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length,
|
||||
PRBool bGlobalContext,
|
||||
PRBool bCallbacks) = 0;
|
||||
NS_IMETHOD EvaluateConfigScriptFile(const char * js_buffer, size_t length,
|
||||
const nsFileSpec& inSpec,
|
||||
PRBool bGlobalContext,
|
||||
PRBool bCallbacks) = 0;
|
||||
|
||||
NS_IMETHOD SavePrefFileAs(const nsFileSpec& inSpec) = 0;
|
||||
NS_IMETHOD SaveLIPrefFile(const nsFileSpec& inSpec) = 0;
|
||||
|
||||
// JS stuff
|
||||
NS_IMETHOD GetConfigContext(JSContext **js_context) = 0;
|
||||
NS_IMETHOD GetGlobalConfigObject(JSObject **js_object) = 0;
|
||||
NS_IMETHOD GetPrefConfigObject(JSObject **js_object) = 0;
|
||||
|
||||
NS_IMETHOD EvaluateConfigScript(const char * js_buffer, size_t length,
|
||||
const char* filename,
|
||||
PRBool bGlobalContext,
|
||||
PRBool bCallbacks) = 0;
|
||||
|
||||
// Getters
|
||||
NS_IMETHOD GetCharPref(const char *pref,
|
||||
char * return_buf, int * buf_length) = 0;
|
||||
@ -140,18 +166,15 @@ public:
|
||||
NS_IMETHOD CopyDefaultBinaryPref(const char *pref,
|
||||
void ** return_val, int * size) = 0;
|
||||
|
||||
// Path prefs
|
||||
NS_IMETHOD CopyPathPref(const char *pref, char ** return_buf) = 0;
|
||||
NS_IMETHOD SetPathPref(const char *pref_name,
|
||||
const char *path, PRBool set_default) = 0;
|
||||
NS_IMETHOD GetFilePref(const char* pref, nsFileSpec* value) = 0;
|
||||
NS_IMETHOD SetFilePref(
|
||||
const char* pref, const nsFileSpec* value, PRBool setDefault) = 0;
|
||||
|
||||
// Pref info
|
||||
NS_IMETHOD PrefIsLocked(const char *pref_name, PRBool *res) = 0;
|
||||
|
||||
// Save pref files
|
||||
NS_IMETHOD SavePrefFile(void) = 0;
|
||||
NS_IMETHOD SavePrefFileAs(const char *filename) = 0;
|
||||
NS_IMETHOD SaveLIPrefFile(const char *filename) = 0;
|
||||
NS_IMETHOD SavePrefFile() = 0;
|
||||
|
||||
// Callbacks
|
||||
NS_IMETHOD RegisterCallback( const char* domain,
|
||||
|
@ -25,7 +25,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = pref
|
||||
LIBRARY_NAME = pref
|
||||
|
||||
REQUIRES = js pref dbm security ldap img layer xpcom util
|
||||
REQUIRES = js raptorbase pref dbm security ldap img layer xpcom util
|
||||
|
||||
ifneq ($(subst /,_,$(shell uname -s)),OS2)
|
||||
CSRCS = unix/unixpref.c
|
||||
|
@ -80,6 +80,7 @@ LLIBS = \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\js$(MOZ_BITS)$(VERSION_NUMBER).lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(HASHLIBS)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@
|
||||
|
||||
/* Data shared between prefapi.c and nsPref.cpp */
|
||||
|
||||
NSPR_BEGIN_EXTERN_C
|
||||
extern JSTaskState * gMochaTaskState;
|
||||
extern JSContext * gMochaContext;
|
||||
extern JSObject * gMochaPrefObject;
|
||||
@ -40,13 +41,16 @@ extern PLHashTable* gHashTable;
|
||||
extern char * gSavedLine;
|
||||
extern PLHashAllocOps pref_HashAllocOps;
|
||||
|
||||
NSPR_BEGIN_EXTERN_C
|
||||
PR_EXTERN(JSBool) PR_CALLBACK pref_BranchCallback(JSContext *cx, JSScript *script);
|
||||
PR_EXTERN(PrefResult) pref_savePref(PLHashEntry *he, int i, void *arg);
|
||||
PR_EXTERN(PrefResult) pref_saveLIPref(PLHashEntry *he, int i, void *arg);
|
||||
PR_EXTERN(PRBool) pref_VerifyLockFile(char* buf, long buflen);
|
||||
PR_EXTERN(PrefResult) PREF_SetSpecialPrefsLocal(void);
|
||||
PR_EXTERN(int) pref_CompareStrings(const void *v1, const void *v2);
|
||||
/* -- Platform specific function extern */
|
||||
#if !defined(XP_WIN) && !defined(XP_OS2)
|
||||
extern JSBool pref_InitInitialObjects(void);
|
||||
#endif
|
||||
NSPR_END_EXTERN_C
|
||||
|
||||
/* Possibly exportable */
|
||||
|
@ -127,7 +127,7 @@ nsViewerApp::~nsViewerApp()
|
||||
{
|
||||
Destroy();
|
||||
if (nsnull != mPrefs) {
|
||||
mPrefs->Shutdown();
|
||||
mPrefs->ShutDown();
|
||||
NS_RELEASE(mPrefs);
|
||||
}
|
||||
}
|
||||
@ -234,7 +234,7 @@ nsViewerApp::Initialize(int argc, char** argv)
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
mPrefs->Startup(nsnull);
|
||||
mPrefs->StartUp();
|
||||
|
||||
|
||||
// Load Fullcircle Talkback crash-reporting mechanism.
|
||||
|
@ -140,6 +140,7 @@ nsresult nsPrefsCore::InitializePrefsManager()
|
||||
if (!prefs)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
#if 0
|
||||
nsIFileLocator* locator;
|
||||
rv = nsServiceManager::GetService(kFileLocatorCID, kIFileLocatorIID, (nsISupports**)&locator);
|
||||
if (NS_FAILED(rv))
|
||||
@ -150,6 +151,7 @@ nsresult nsPrefsCore::InitializePrefsManager()
|
||||
nsFileSpec newPrefs;
|
||||
rv = locator->GetFileLocation(nsSpecialFileSpec::App_PreferencesFile50, &newPrefs);
|
||||
#if 0
|
||||
// Migration?
|
||||
if (NS_FAILED(rv) || !newPrefs.Exists())
|
||||
{
|
||||
nsFileSpec oldPrefs;
|
||||
@ -196,7 +198,7 @@ nsresult nsPrefsCore::InitializePrefsManager()
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
#endif // 0
|
||||
mPrefs = prefs;
|
||||
return NS_OK;
|
||||
} // nsPrefsCore::InitializePrefsManager
|
||||
@ -366,19 +368,18 @@ nsresult nsPrefsCore::InitializeOneWidget(
|
||||
// Check the subtree first, then the real tree.
|
||||
// If the preference value is not set at all, let the HTML
|
||||
// determine the setting.
|
||||
char* charVal;
|
||||
if (NS_SUCCEEDED(mPrefs->CopyPathPref(tempPrefName, &charVal))
|
||||
|| NS_SUCCEEDED(mPrefs->CopyPathPref(inPrefName, &charVal)))
|
||||
nsFileSpec specVal;
|
||||
if (NS_SUCCEEDED(mPrefs->GetFilePref(tempPrefName, &specVal))
|
||||
|| NS_SUCCEEDED(mPrefs->GetFilePref(inPrefName, &specVal)))
|
||||
{
|
||||
nsString newValue = charVal;
|
||||
PR_Free(charVal);
|
||||
nsString newValue = specVal.GetCString();
|
||||
inElement->SetValue(newValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
} // nsPrefsCore::InitializeOneWidget
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsPrefsCore::InitializeWidgetsRecursive(nsIDOMNode* inParentNode)
|
||||
@ -520,10 +521,8 @@ nsresult nsPrefsCore::FinalizeOneWidget(
|
||||
nsresult rv = inElement->GetValue(fieldValue);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
char* s = fieldValue.ToNewCString();
|
||||
mPrefs->SetPathPref(tempPrefName, s, PR_TRUE);
|
||||
delete [] s;
|
||||
break;
|
||||
nsFileSpec specValue(fieldValue);
|
||||
mPrefs->SetFilePref(tempPrefName, &specValue, PR_TRUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -532,7 +531,7 @@ nsresult nsPrefsCore::FinalizeOneWidget(
|
||||
// inElement->SetAttribute(attributeToSet, newValue);
|
||||
// }
|
||||
return NS_OK;
|
||||
}
|
||||
} // nsPrefsCore::FinalizeOneWidget
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsresult nsPrefsCore::FinalizeWidgetsRecursive(nsIDOMNode* inParentNode)
|
||||
|
@ -148,7 +148,6 @@ int main(int argc, char* argv[])
|
||||
// XXX: This call will be replaced by a registry initialization...
|
||||
NS_SetupRegistry_1();
|
||||
|
||||
//Is there a call to get current working directory ?
|
||||
nsIFileLocator* locator = nsnull;
|
||||
rv = nsServiceManager::GetService(kFileLocatorCID, kIFileLocatorIID, (nsISupports**)&locator);
|
||||
if (NS_FAILED(rv))
|
||||
@ -312,7 +311,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
/*
|
||||
* Load preferences
|
||||
* Load preferences, causing them to be initialized, and hold a reference to them.
|
||||
*/
|
||||
rv = nsServiceManager::GetService(kPrefCID,
|
||||
nsIPref::GetIID(),
|
||||
@ -320,29 +319,6 @@ int main(int argc, char* argv[])
|
||||
if (NS_FAILED(rv))
|
||||
goto done;
|
||||
|
||||
{ // <-Scoping for nsFileSpec
|
||||
nsFileSpec newPrefs;
|
||||
rv = locator->GetFileLocation(nsSpecialFileSpec::App_PreferencesFile50, &newPrefs);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (!newPrefs.Exists())
|
||||
{
|
||||
nsOutputFileStream stream(newPrefs);
|
||||
if (stream.is_open())
|
||||
{
|
||||
stream << "// This is an empty prefs file" << nsEndl;
|
||||
}
|
||||
}
|
||||
if (newPrefs.Exists())
|
||||
rv = prefs->Startup(newPrefs.GetCString());
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
} // <- end of scoping for nsFileSpec
|
||||
|
||||
/*
|
||||
* Create the Application Shell instance...
|
||||
*/
|
||||
@ -488,7 +464,7 @@ done:
|
||||
|
||||
/* Release the global preferences... */
|
||||
if (prefs) {
|
||||
prefs->Shutdown();
|
||||
prefs->ShutDown();
|
||||
nsServiceManager::ReleaseService(kPrefCID, prefs);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user