Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
GConfProxy Class Reference
Collaboration diagram for GConfProxy:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GConfProxy (nsSystemPrefService *aSysPrefService)
 ~GConfProxy ()
PRBool Init ()
nsresult GetBoolPref (const char *aMozKey, PRBool *retval)
nsresult GetCharPref (const char *aMozKey, char **retval)
nsresult GetIntPref (const char *aMozKey, PRInt32 *retval)
nsresult NotifyAdd (PRUint32 aAtom, void *aUserData)
nsresult NotifyRemove (PRUint32 aAtom, const void *aUserData)
nsresult GetAtomForMozKey (const char *aMozKey, PRUint32 *aAtom)
const char * GetMozKey (PRUint32 aAtom)
void OnNotify (void *aClient, void *aEntry, PRUint32 aNotifyId, GConfCallbackData *aData)

Private Member Functions

void InitFuncPtrs ()
nsresult GetAtom (const char *aKey, PRUint8 aNameType, PRUint32 *aAtom)
nsresult GetAtomForGConfKey (const char *aGConfKey, PRUint32 *aAtom)
const char * GetKey (PRUint32 aAtom, PRUint8 aNameType)
const char * GetGConfKey (PRUint32 aAtom)
const char * MozKey2GConfKey (const char *aMozKey)

Private Attributes

voidmGConfClient
PRLibrarymGConfLib
PRBool mInitialized
nsSystemPrefServicemSysPrefService
nsAutoVoidArray * mObservers
GConfClientGetDefaultType GConfClientGetDefault
GConfClientGetBoolType GConfClientGetBool
GConfClientGetStringType GConfClientGetString
GConfClientGetIntType GConfClientGetInt
GConfClientNotifyAddType GConfClientNotifyAdd
GConfClientNotifyRemoveType GConfClientNotifyRemove
GConfClientAddDirType GConfClientAddDir
GConfClientRemoveDirType GConfClientRemoveDir
GConfEntryGetValueType GConfEntryGetValue
GConfEntryGetKeyType GConfEntryGetKey
GConfValueGetBoolType GConfValueGetBool
GConfValueGetStringType GConfValueGetString
GConfValueGetIntType GConfValueGetInt

Static Private Attributes

static const char sPrefGConfKey [] = "accessibility.unix.gconf2.shared-library"
static const char sDefaultLibName1 [] = "libgconf-2.so.4"
static const char sDefaultLibName2 [] = "libgconf-2.so"

Detailed Description

Definition at line 132 of file nsSystemPrefService.cpp.


Constructor & Destructor Documentation

Definition at line 599 of file nsSystemPrefService.cpp.

{
    if (mGConfClient)
        g_object_unref(G_OBJECT(mGConfClient));

    if (mObservers) {
        (void)mObservers->EnumerateForwards(gconfDeleteObserver, nsnull);
        delete mObservers;
    }
}

Here is the call graph for this function:


Member Function Documentation

nsresult GConfProxy::GetAtom ( const char *  aKey,
PRUint8  aNameType,
PRUint32 aAtom 
) [private]

Definition at line 839 of file nsSystemPrefService.cpp.

{
    if (!aKey)
        return NS_ERROR_FAILURE;
    PRUint32 prefSize = sizeof(sPrefNameMapping) / sizeof(sPrefNameMapping[0]);
    for (PRUint32 index = 0; index < prefSize; ++index) {
        if (!strcmp((aNameType == 0) ? sPrefNameMapping[index].mozPrefName :
                    sPrefNameMapping[index].gconfPrefName, aKey)) {
            *aAtom = index;
            return NS_OK;
        }
    }
    return NS_ERROR_FAILURE;
}

Here is the caller graph for this function:

nsresult GConfProxy::GetAtomForGConfKey ( const char *  aGConfKey,
PRUint32 aAtom 
) [inline, private]

Definition at line 189 of file nsSystemPrefService.cpp.

    {return GetAtom(aGConfKey, 1, aAtom);}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult GConfProxy::GetAtomForMozKey ( const char *  aMozKey,
PRUint32 aAtom 
) [inline]

Definition at line 146 of file nsSystemPrefService.cpp.

                                                                    {
        return GetAtom(aMozKey, 0, aAtom); 
    }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult GConfProxy::GetBoolPref ( const char *  aMozKey,
PRBool retval 
)

Definition at line 680 of file nsSystemPrefService.cpp.

Here is the call graph for this function:

nsresult GConfProxy::GetCharPref ( const char *  aMozKey,
char **  retval 
)

Definition at line 688 of file nsSystemPrefService.cpp.

{
    NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE);

    gchar *str = GConfClientGetString(mGConfClient,
                                      MozKey2GConfKey(aMozKey), NULL);
    if (str) {
        *retval = PL_strdup(str);
        g_free(str);
    }
    return NS_OK;
}

Here is the call graph for this function:

const char* GConfProxy::GetGConfKey ( PRUint32  aAtom) [inline, private]

Definition at line 192 of file nsSystemPrefService.cpp.

    {return GetKey(aAtom, 1); }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult GConfProxy::GetIntPref ( const char *  aMozKey,
PRInt32 retval 
)

Definition at line 702 of file nsSystemPrefService.cpp.

{
    NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE);
    if (strcmp (aMozKey, "network.proxy.type") == 0) {
       gchar *str;

       str = GConfClientGetString(mGConfClient,
                                  MozKey2GConfKey (aMozKey), NULL);

       if (str) {
              if (strcmp (str, "manual") == 0)
                     *retval = 1;
              else if (strcmp (str, "auto") == 0)
                     *retval = 2;
              else
                     *retval = 0;

              g_free (str);
       } else
              *retval = 0;
    } else {
       *retval = GConfClientGetInt(mGConfClient, 
                                   MozKey2GConfKey(aMozKey), NULL);
    }

    return NS_OK;
}

Here is the call graph for this function:

const char * GConfProxy::GetKey ( PRUint32  aAtom,
PRUint8  aNameType 
) [private]

Definition at line 855 of file nsSystemPrefService.cpp.

{
    PRUint32 mapSize = sizeof(sPrefNameMapping) / sizeof(sPrefNameMapping[0]);
    if (aAtom >= 0 && aAtom < mapSize)
        return (aNameType == 0) ? sPrefNameMapping[aAtom].mozPrefName :
            sPrefNameMapping[aAtom].gconfPrefName;
    return NULL;
}

Here is the caller graph for this function:

const char* GConfProxy::GetMozKey ( PRUint32  aAtom) [inline]

Definition at line 149 of file nsSystemPrefService.cpp.

                                          {
        return GetKey(aAtom, 0); 
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 611 of file nsSystemPrefService.cpp.

{
    SYSPREF_LOG(("GConfProxy:: Init GConfProxy\n"));
    if (!mSysPrefService)
        return PR_FALSE;
    if (mInitialized)
        return PR_TRUE;

    nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
    if (!pref)
        return PR_FALSE;

    nsXPIDLCString gconfLibName;
    nsresult rv;

    //check if gconf-2 library is given in prefs
    rv = pref->GetCharPref(sPrefGConfKey, getter_Copies(gconfLibName));
    if (NS_SUCCEEDED(rv)) {
        //use the library name in the preference
        SYSPREF_LOG(("GConf library in prefs is %s\n", gconfLibName.get()));
        mGConfLib = PR_LoadLibrary(gconfLibName.get());
    }
    else {
        SYSPREF_LOG(("GConf library not specified in prefs, try the default: "
                     "%s and %s\n", sDefaultLibName1, sDefaultLibName2));
        mGConfLib = PR_LoadLibrary(sDefaultLibName1);
        if (!mGConfLib)
            mGConfLib = PR_LoadLibrary(sDefaultLibName2);
    }

    if (!mGConfLib) {
        SYSPREF_LOG(("Fail to load GConf library\n"));
        return PR_FALSE;
    }

    //check every func we need in the gconf library
    GConfFuncListType *funcList;
    PRFuncPtr func;
    for (funcList = sGConfFuncList; funcList->FuncName; ++funcList) {
        func = PR_FindFunctionSymbol(mGConfLib, funcList->FuncName);
        if (!func) {
            SYSPREF_LOG(("Check GConf Func Error: %s", funcList->FuncName));
            goto init_failed_unload;
        }
        funcList->FuncPtr = func;
    }

    InitFuncPtrs();

    mGConfClient = GConfClientGetDefault();

    // Don't unload past this point, since GConf's initialization of ORBit
    // causes atexit handlers to be registered.

    if (!mGConfClient) {
        SYSPREF_LOG(("Fail to Get default gconf client\n"));
        goto init_failed;
    }
    mInitialized = PR_TRUE;
    return PR_TRUE;

 init_failed_unload:
    PR_UnloadLibrary(mGConfLib);
 init_failed:
    mGConfLib = nsnull;
    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 790 of file nsSystemPrefService.cpp.

{
    //gconf client funcs
    GConfClientGetDefault =
        (GConfClientGetDefaultType) sGConfFuncList[0].FuncPtr;
    GConfClientGetBool =
        (GConfClientGetBoolType) sGConfFuncList[1].FuncPtr;
    GConfClientGetString =
        (GConfClientGetStringType) sGConfFuncList[2].FuncPtr;
    GConfClientGetInt =
        (GConfClientGetIntType) sGConfFuncList[3].FuncPtr;
    GConfClientNotifyAdd =
        (GConfClientNotifyAddType) sGConfFuncList[4].FuncPtr;
    GConfClientNotifyRemove =
        (GConfClientNotifyRemoveType) sGConfFuncList[5].FuncPtr;
    GConfClientAddDir =
        (GConfClientAddDirType) sGConfFuncList[6].FuncPtr;
    GConfClientRemoveDir =
        (GConfClientRemoveDirType) sGConfFuncList[7].FuncPtr;

    //gconf entry funcs
    GConfEntryGetValue = (GConfEntryGetValueType) sGConfFuncList[8].FuncPtr;
    GConfEntryGetKey = (GConfEntryGetKeyType) sGConfFuncList[9].FuncPtr;

    //gconf value funcs
    GConfValueGetBool = (GConfValueGetBoolType) sGConfFuncList[10].FuncPtr;
    GConfValueGetString = (GConfValueGetStringType) sGConfFuncList[11].FuncPtr;
    GConfValueGetInt = (GConfValueGetIntType) sGConfFuncList[12].FuncPtr;
}

Here is the caller graph for this function:

const char * GConfProxy::MozKey2GConfKey ( const char *  aMozKey) [inline, private]

Definition at line 865 of file nsSystemPrefService.cpp.

{
    PRUint32 atom;
    nsresult rv = GetAtomForMozKey(aMozKey, &atom);
    if (NS_SUCCEEDED(rv))
        return GetGConfKey(atom);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult GConfProxy::NotifyAdd ( PRUint32  aAtom,
void aUserData 
)

Definition at line 731 of file nsSystemPrefService.cpp.

{
    NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE);

    const char *gconfKey = GetGConfKey(aAtom);
    if (!gconfKey)
        return NS_ERROR_FAILURE;

    if (!mObservers) {
        mObservers = new nsAutoVoidArray();
        if (mObservers == nsnull)
            return NS_ERROR_OUT_OF_MEMORY;
    }
 
    GConfCallbackData *pData = (GConfCallbackData *)
        nsMemory::Alloc(sizeof(GConfCallbackData));
    NS_ENSURE_TRUE(pData, NS_ERROR_OUT_OF_MEMORY);

    pData->proxy = this;
    pData->userData = aUserData;
    pData->atom = aAtom;
    mObservers->AppendElement(pData);

    GConfClientAddDir(mGConfClient, gconfKey,
                      0, // GCONF_CLIENT_PRELOAD_NONE,  don't preload anything 
                      NULL);

    pData->notifyId = GConfClientNotifyAdd(mGConfClient, gconfKey,
                                           gconf_key_listener, pData,
                                           NULL, NULL);
    return NS_OK;
}

Here is the call graph for this function:

nsresult GConfProxy::NotifyRemove ( PRUint32  aAtom,
const void aUserData 
)

Definition at line 765 of file nsSystemPrefService.cpp.

{
    NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE);

    PRIntn count = mObservers->Count();
    if (count <= 0)
        return NS_OK;

    PRIntn i;
    GConfCallbackData *pData;
    for (i = 0; i < count; ++i) {
        pData = (GConfCallbackData *)mObservers->ElementAt(i);
        if (pData && pData->atom == aAtom && pData->userData == aUserData) {
            GConfClientNotifyRemove(mGConfClient, pData->notifyId);
            GConfClientRemoveDir(mGConfClient,
                                 GetGConfKey(pData->atom), NULL);
            mObservers->RemoveElementAt(i);
            nsMemory::Free(pData);
            break;
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GConfProxy::OnNotify ( void aClient,
void aEntry,
PRUint32  aNotifyId,
GConfCallbackData aData 
)

Definition at line 821 of file nsSystemPrefService.cpp.

{
    if (!mInitialized || !aEntry || (mGConfClient != aClient) || !aData)
        return;

    if (GConfEntryGetValue(aEntry) == NULL)
        return;

    PRUint32 prefAtom;
    nsresult rv = GetAtomForGConfKey(GConfEntryGetKey(aEntry), &prefAtom);
    if (NS_FAILED(rv))
        return;

    mSysPrefService->OnPrefChange(prefAtom, aData->userData);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 175 of file nsSystemPrefService.cpp.

Definition at line 170 of file nsSystemPrefService.cpp.

Definition at line 169 of file nsSystemPrefService.cpp.

Definition at line 172 of file nsSystemPrefService.cpp.

Definition at line 171 of file nsSystemPrefService.cpp.

Definition at line 173 of file nsSystemPrefService.cpp.

Definition at line 174 of file nsSystemPrefService.cpp.

Definition at line 176 of file nsSystemPrefService.cpp.

Definition at line 180 of file nsSystemPrefService.cpp.

Definition at line 179 of file nsSystemPrefService.cpp.

Definition at line 183 of file nsSystemPrefService.cpp.

Definition at line 185 of file nsSystemPrefService.cpp.

Definition at line 184 of file nsSystemPrefService.cpp.

Definition at line 157 of file nsSystemPrefService.cpp.

Definition at line 158 of file nsSystemPrefService.cpp.

Definition at line 159 of file nsSystemPrefService.cpp.

nsAutoVoidArray* GConfProxy::mObservers [private]

Definition at line 163 of file nsSystemPrefService.cpp.

Definition at line 160 of file nsSystemPrefService.cpp.

const char GConfProxy::sDefaultLibName1 = "libgconf-2.so.4" [static, private]

Definition at line 198 of file nsSystemPrefService.cpp.

const char GConfProxy::sDefaultLibName2 = "libgconf-2.so" [static, private]

Definition at line 199 of file nsSystemPrefService.cpp.

const char GConfProxy::sPrefGConfKey = "accessibility.unix.gconf2.shared-library" [static, private]

Definition at line 197 of file nsSystemPrefService.cpp.


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