Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsSystemPref Class Reference

#include <nsSystemPref.h>

Inheritance diagram for nsSystemPref:
Inheritance graph
[legend]
Collaboration diagram for nsSystemPref:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER 
nsSystemPref ()
virtual ~nsSystemPref ()
nsresult Init (void)
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Private Member Functions

nsresult UseSystemPrefs ()
nsresult ReadSystemPref (const char *aPrefName)
nsresult SaveMozDefaultPref (const char *aPrefName, MozPrefValue *aPrefVal, PRBool *aLocked)
nsresult UseMozillaPrefs ()
nsresult RestoreMozDefaultPref (const char *aPrefName, MozPrefValue *aPrefVal, PRBool aLocked)

Private Attributes

nsCOMPtr< nsIPrefBranch2mSysPrefService
PRBool mEnabled
SysPrefItemmSysPrefs

Detailed Description

Definition at line 75 of file nsSystemPref.h.


Constructor & Destructor Documentation

Definition at line 92 of file nsSystemPref.cpp.

Definition at line 99 of file nsSystemPref.cpp.


Member Function Documentation

Definition at line 111 of file nsSystemPref.cpp.

{
    nsresult rv;

    if (!gSysPrefLog) {
        gSysPrefLog = PR_NewLogModule("Syspref");
        if (!gSysPrefLog)
            return NS_ERROR_OUT_OF_MEMORY;
    }

    nsCOMPtr<nsIObserverService> observerService = 
        do_GetService("@mozilla.org/observer-service;1", &rv);

    if (observerService) {
        rv = observerService->AddObserver(this, NS_PREFSERVICE_READ_TOPIC_ID,
                                          PR_FALSE);
        rv = observerService->AddObserver(this, "profile-before-change",
                                          PR_FALSE);
        SYSPREF_LOG(("Add Observer for %s\n", NS_PREFSERVICE_READ_TOPIC_ID));
    }
    return(rv);
}

Here is the call graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
nsresult nsSystemPref::ReadSystemPref ( const char *  aPrefName) [private]

Definition at line 277 of file nsSystemPref.cpp.

{
    if (!mSysPrefService)
        return NS_ERROR_FAILURE;
    nsresult rv;

    nsCOMPtr<nsIPrefBranch> prefBranch
        (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
    if (NS_FAILED(rv))
        return rv;

    SYSPREF_LOG(("about to read aPrefName %s\n", aPrefName));

    prefBranch->UnlockPref(aPrefName);

    PRInt32 prefType = nsIPrefBranch::PREF_INVALID;
    nsXPIDLCString strValue;
    PRInt32 intValue = 0;
    PRBool boolValue = PR_FALSE;

    rv = prefBranch->GetPrefType(aPrefName, &prefType);
    if (NS_FAILED(rv))
        return rv;
    switch (prefType) {
    case nsIPrefBranch::PREF_STRING:
        mSysPrefService->GetCharPref(aPrefName, getter_Copies(strValue));
        SYSPREF_LOG(("system value is %s\n", strValue.get()));

        prefBranch->SetCharPref(aPrefName, strValue.get());
        break;
    case nsIPrefBranch::PREF_INT:
        mSysPrefService->GetIntPref(aPrefName, &intValue);
        SYSPREF_LOG(("system value is %d\n", intValue));

        prefBranch->SetIntPref(aPrefName, intValue);
        break;
    case nsIPrefBranch::PREF_BOOL:
        mSysPrefService->GetBoolPref(aPrefName, &boolValue);
        SYSPREF_LOG(("system value is %s\n", boolValue ? "TRUE" : "FALSE"));

        prefBranch->SetBoolPref(aPrefName, boolValue);
        break;
    default:
        SYSPREF_LOG(("Fail to system value for it\n"));
        return NS_ERROR_FAILURE;
    }
    prefBranch->LockPref(aPrefName);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSystemPref::RestoreMozDefaultPref ( const char *  aPrefName,
MozPrefValue aPrefVal,
PRBool  aLocked 
) [private]

Definition at line 421 of file nsSystemPref.cpp.

{
    NS_ENSURE_ARG_POINTER(aPrefName);

    nsresult rv;

    nsCOMPtr<nsIPrefBranch> prefBranch =
        do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return rv;

    SYSPREF_LOG(("Restore Mozilla value for %s\n", aPrefName));

    PRInt32 prefType = nsIPrefBranch::PREF_INVALID;
    rv = prefBranch->GetPrefType(aPrefName, &prefType);
    if (NS_FAILED(rv))
        return rv;

    // unlock, if it is locked
    prefBranch->UnlockPref(aPrefName);

    switch (prefType) {
    case nsIPrefBranch::PREF_STRING:
        prefBranch->SetCharPref(aPrefName,
                                aPrefValue->stringVal);
        SYSPREF_LOG(("Mozilla value is %s\n", aPrefValue->stringVal));

        PL_strfree(aPrefValue->stringVal);
        aPrefValue->stringVal = nsnull;

        break;
    case nsIPrefBranch::PREF_INT:
        prefBranch->SetIntPref(aPrefName, aPrefValue->intVal);
        SYSPREF_LOG(("Mozilla value is %d\n", aPrefValue->intVal));

        break;
    case nsIPrefBranch::PREF_BOOL:
        prefBranch->SetBoolPref(aPrefName, aPrefValue->boolVal);
        SYSPREF_LOG(("Mozilla value is %s\n",
                     aPrefValue->boolVal ? "TRUE" : "FALSE"));

        break;
    default:
        SYSPREF_LOG(("Fail to Restore Mozilla value for it\n"));
        return NS_ERROR_FAILURE;
    }

    // restore its old lock status
    if (aLocked)
        prefBranch->LockPref(aPrefName);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSystemPref::SaveMozDefaultPref ( const char *  aPrefName,
MozPrefValue aPrefVal,
PRBool aLocked 
) [private]

Definition at line 361 of file nsSystemPref.cpp.

{
    NS_ENSURE_ARG_POINTER(aPrefName);
    NS_ENSURE_ARG_POINTER(aPrefValue);
    NS_ENSURE_ARG_POINTER(aLocked);

    nsresult rv;

    nsCOMPtr<nsIPrefBranch> prefBranch =
        do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return rv;

    SYSPREF_LOG(("Save Mozilla value for %s\n", aPrefName));

    PRInt32 prefType = nsIPrefBranch::PREF_INVALID;
    nsXPIDLCString strValue;

    rv = prefBranch->GetPrefType(aPrefName, &prefType);
    if (NS_FAILED(rv))
        return rv;
    switch (prefType) {
    case nsIPrefBranch::PREF_STRING:
        prefBranch->GetCharPref(aPrefName,
                                getter_Copies(strValue));
        SYSPREF_LOG(("Mozilla value is %s", strValue.get()));

        if (aPrefValue->stringVal)
            PL_strfree(aPrefValue->stringVal);
        aPrefValue->stringVal = PL_strdup(strValue.get());
        break;
    case nsIPrefBranch::PREF_INT:
        prefBranch->GetIntPref(aPrefName, &aPrefValue->intVal);
        SYSPREF_LOG(("Mozilla value is %d\n", aPrefValue->intVal));

        break;
    case nsIPrefBranch::PREF_BOOL:
        prefBranch->GetBoolPref(aPrefName, &aPrefValue->boolVal);
        SYSPREF_LOG(("Mozilla value is %s\n",
                     aPrefValue->boolVal ? "TRUE" : "FALSE"));

        break;
    default:
        SYSPREF_LOG(("Fail to Read Mozilla value for it\n"));
        return NS_ERROR_FAILURE;
    }
    rv = prefBranch->PrefIsLocked(aPrefName, aLocked);
    SYSPREF_LOG((" (%s).\n", aLocked ? "Locked" : "NOT Locked"));
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 332 of file nsSystemPref.cpp.

{
    nsresult rv = NS_OK;
    SYSPREF_LOG(("\n====Now rollback to Mozilla prefs==\n"));

    // if we did not use system prefs, do nothing
    if (!mSysPrefService)
        return NS_OK;

    PRIntn sysPrefCount= sizeof(sSysPrefList) / sizeof(sSysPrefList[0]);
    for (PRIntn index = 0; index < sysPrefCount; ++index) {
        // restore mozilla default value and free string memory if needed
        RestoreMozDefaultPref(mSysPrefs[index].prefName,
                              &mSysPrefs[index].defaultValue,
                              mSysPrefs[index].isLocked);
        SYSPREF_LOG(("stop listening on %s\n", mSysPrefs[index].prefName));
        mSysPrefService->RemoveObserver(mSysPrefs[index].prefName,
                                        this);
    }
    return rv;
}

Here is the call graph for this function:

Definition at line 239 of file nsSystemPref.cpp.

{
    SYSPREF_LOG(("\n====Now Use system prefs==\n"));
    nsresult rv = NS_OK;
    if (!mSysPrefService) {
        return NS_ERROR_FAILURE;
    }

    PRIntn sysPrefCount= sizeof(sSysPrefList) / sizeof(sSysPrefList[0]);

    if (!mSysPrefs) {
        mSysPrefs = new SysPrefItem[sysPrefCount];
        if (!mSysPrefs)
            return NS_ERROR_OUT_OF_MEMORY;
        for (PRIntn index = 0; index < sysPrefCount; ++index)
            mSysPrefs[index].SetPrefName(sSysPrefList[index]);
    }

    for (PRIntn index = 0; index < sysPrefCount; ++index) {
        // save mozilla prefs
        SaveMozDefaultPref(mSysPrefs[index].prefName,
                           &mSysPrefs[index].defaultValue,
                           &mSysPrefs[index].isLocked);

        // get the system prefs
        ReadSystemPref(mSysPrefs[index].prefName);
        SYSPREF_LOG(("Add Listener on %s\n", mSysPrefs[index].prefName));
        mSysPrefService->AddObserver(mSysPrefs[index].prefName,
                                     this, PR_TRUE);
    }
    return rv;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 101 of file nsSystemPref.h.

Definition at line 102 of file nsSystemPref.h.

Definition at line 100 of file nsSystemPref.h.


The documentation for this class was generated from the following files: