Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions
prefapi.h File Reference
#include "nscore.h"
#include "pldhash.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  PrefValue
struct  PrefHashEntry

Defines

#define have_PrefChangedFunc_typedef

Typedefs

typedef nsresult(* PrefChangedFunc )(const char *, void *)

Enumerations

enum  PrefType {
  PREF_INVALID = 0, PREF_LOCKED = 1, PREF_USERSET = 2, PREF_CONFIG = 4,
  PREF_REMOTE = 8, PREF_LILOCAL = 16, PREF_STRING = 32, PREF_INT = 64,
  PREF_BOOL = 128, PREF_VALUETYPE_MASK = (PREF_STRING | PREF_INT | PREF_BOOL)
}

Functions

nsresult PREF_Init ()
void PREF_Cleanup ()
void PREF_CleanupPrefs ()
nsresult PREF_SetCharPref (const char *pref, const char *value, PRBool set_default=PR_FALSE)
nsresult PREF_SetIntPref (const char *pref, PRInt32 value, PRBool set_default=PR_FALSE)
nsresult PREF_SetBoolPref (const char *pref, PRBool value, PRBool set_default=PR_FALSE)
PRBool PREF_HasUserPref (const char *pref_name)
nsresult PREF_GetIntPref (const char *pref, PRInt32 *return_int, PRBool get_default)
nsresult PREF_GetBoolPref (const char *pref, PRBool *return_val, PRBool get_default)
nsresult PREF_CopyCharPref (const char *pref, char **return_buf, PRBool get_default)
PRBool PREF_PrefIsLocked (const char *pref_name)
nsresult PREF_LockPref (const char *key, PRBool lockIt)
PrefType PREF_GetPrefType (const char *pref_name)
nsresult PREF_DeleteBranch (const char *branch_name)
nsresult PREF_ClearUserPref (const char *pref_name)
nsresult PREF_ClearAllUserPrefs ()
void PREF_RegisterCallback (const char *domain, PrefChangedFunc callback, void *instance_data)
nsresult PREF_UnregisterCallback (const char *domain, PrefChangedFunc callback, void *instance_data)
void PREF_ReaderCallback (void *closure, const char *pref, PrefValue value, PrefType type, PRBool isDefault)

Class Documentation

union PrefValue

Definition at line 49 of file prefapi.h.

Class Members
PRBool boolVal
PRInt32 intVal
char * stringVal

Define Documentation

Definition at line 187 of file prefapi.h.


Typedef Documentation

typedef nsresult(* PrefChangedFunc)(const char *, void *)

Definition at line 186 of file prefapi.h.


Enumeration Type Documentation

enum PrefType
Enumerator:
PREF_INVALID 
PREF_LOCKED 
PREF_USERSET 
PREF_CONFIG 
PREF_REMOTE 
PREF_LILOCAL 
PREF_STRING 
PREF_INT 
PREF_BOOL 
PREF_VALUETYPE_MASK 

Definition at line 85 of file prefapi.h.


Function Documentation

Definition at line 213 of file prefapi.cpp.

{
    NS_ASSERTION(!gCallbacksInProgress,
        "PREF_Cleanup was called while gCallbacksInProgress is PR_TRUE!");
    struct CallbackNode* node = gCallbacks;
    struct CallbackNode* next_node;

    while (node)
    {
        next_node = node->next;
        PR_Free(node->domain);
        PR_Free(node);
        node = next_node;
    }
    gCallbacks = NULL;

    PREF_CleanupPrefs();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 233 of file prefapi.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 603 of file prefapi.cpp.

Here is the call graph for this function:

nsresult PREF_ClearUserPref ( const char *  pref_name)

Definition at line 562 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
    if (pref && PREF_HAS_USER_VALUE(pref))
    {
        pref->flags &= ~PREF_USERSET;
        if (gCallbacksEnabled)
            pref_DoCallback(pref_name);
        gDirty = PR_TRUE;
        rv = NS_OK;
    }
    return rv;
}

Here is the call graph for this function:

nsresult PREF_CopyCharPref ( const char *  pref,
char **  return_buf,
PRBool  get_default 
)

Definition at line 444 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    char* stringVal;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);

    if (pref && (pref->flags & PREF_STRING))
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
            stringVal = pref->defaultPref.stringVal;
        else
            stringVal = pref->userPref.stringVal;

        if (stringVal) {
            *return_buffer = PL_strdup(stringVal);
            rv = NS_OK;
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_DeleteBranch ( const char *  branch_name)

Definition at line 537 of file prefapi.cpp.

{
    int len = (int)PL_strlen(branch_name);

    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    /* The following check insures that if the branch name already has a "."
     * at the end, we don't end up with a "..". This fixes an incompatibility
     * between nsIPref, which needs the period added, and nsIPrefBranch which
     * does not. When nsIPref goes away this function should be fixed to
     * never add the period at all.
     */
    nsCAutoString branch_dot(branch_name);
    if ((len > 1) && branch_name[len - 1] != '.')
        branch_dot += '.';

    PL_DHashTableEnumerate(&gHashTable, pref_DeleteItem,
                           (void*) branch_dot.get());
    gDirty = PR_TRUE;
    return NS_OK;
}

Here is the call graph for this function:

nsresult PREF_GetBoolPref ( const char *  pref,
PRBool return_val,
PRBool  get_default 
)

Definition at line 492 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
    //NS_ASSERTION(pref, pref_name);
    if (pref && (pref->flags & PREF_BOOL))
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
        {
            PRBool tempBool = pref->defaultPref.boolVal;
            /* check to see if we even had a default */
            if (tempBool != ((PRBool) BOGUS_DEFAULT_BOOL_PREF_VALUE)) {
                *return_value = tempBool;
                rv = NS_OK;
            }
        }
        else {
            *return_value = pref->userPref.boolVal;
            rv = NS_OK;
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_GetIntPref ( const char *  pref,
PRInt32 return_int,
PRBool  get_default 
)

Definition at line 468 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
    if (pref && (pref->flags & PREF_INT))
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
        {
            PRInt32 tempInt = pref->defaultPref.intVal;
            /* check to see if we even had a default */
            if (tempInt == ((PRInt32) BOGUS_DEFAULT_INT_PREF_VALUE))
                return NS_ERROR_UNEXPECTED;
            *return_int = tempInt;
        }
        else
            *return_int = pref->userPref.intVal;
        rv = NS_OK;
    }
    return rv;
}

Here is the call graph for this function:

PrefType PREF_GetPrefType ( const char *  pref_name)

Definition at line 778 of file prefapi.cpp.

{
    if (gHashTable.ops)
    {
        PrefHashEntry* pref = pref_HashTableLookup(pref_name);
        if (pref)
        {
            if (pref->flags & PREF_STRING)
                return PREF_STRING;
            else if (pref->flags & PREF_INT)
                return PREF_INT;
            else if (pref->flags & PREF_BOOL)
                return PREF_BOOL;
        }
    }
    return PREF_INVALID;
}

Here is the call graph for this function:

PRBool PREF_HasUserPref ( const char *  pref_name)

Definition at line 398 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return PR_FALSE;

    PrefHashEntry *pref = pref_HashTableLookup(pref_name);
    if (!pref) return PR_FALSE;

    /* convert PREF_HAS_USER_VALUE to bool */
    return (PREF_HAS_USER_VALUE(pref) != 0);

}

Here is the call graph for this function:

Definition at line 197 of file prefapi.cpp.

{
    if (!gHashTable.ops) {
        if (!PL_DHashTableInit(&gHashTable, &pref_HashTableOps, nsnull,
                               sizeof(PrefHashEntry), 1024)) {
            gHashTable.ops = nsnull;
            return NS_ERROR_OUT_OF_MEMORY;
        }

        PL_INIT_ARENA_POOL(&gPrefNameArena, "PrefNameArena",
                           PREFNAME_ARENA_SIZE);
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_LockPref ( const char *  key,
PRBool  lockIt 
)

Definition at line 614 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    PrefHashEntry* pref = pref_HashTableLookup(key);
    if (!pref)
        return NS_ERROR_UNEXPECTED;

    if (lockit) {
        if (!PREF_IS_LOCKED(pref))
        {
            pref->flags |= PREF_LOCKED;
            gIsAnyPrefLocked = PR_TRUE;
            if (gCallbacksEnabled)
                pref_DoCallback(key);
        }
    }
    else
    {
        if (PREF_IS_LOCKED(pref))
        {
            pref->flags &= ~PREF_LOCKED;
            if (gCallbacksEnabled)
                pref_DoCallback(key);
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

PRBool PREF_PrefIsLocked ( const char *  pref_name)

Definition at line 799 of file prefapi.cpp.

{
    PRBool result = PR_FALSE;
    if (gIsAnyPrefLocked) {
        PrefHashEntry* pref = pref_HashTableLookup(pref_name);
        if (pref && PREF_IS_LOCKED(pref))
            result = PR_TRUE;
    }

    return result;
}

Here is the call graph for this function:

void PREF_ReaderCallback ( void closure,
const char *  pref,
PrefValue  value,
PrefType  type,
PRBool  isDefault 
)

Definition at line 944 of file prefapi.cpp.

{
    pref_HashPref(pref, value, type, isDefault);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PREF_RegisterCallback ( const char *  domain,
PrefChangedFunc  callback,
void instance_data 
)

Definition at line 813 of file prefapi.cpp.

{
    NS_PRECONDITION(pref_node, "pref_node must not be nsnull");
    NS_PRECONDITION(callback, "callback must not be nsnull");

    struct CallbackNode* node = (struct CallbackNode*) malloc(sizeof(struct CallbackNode));
    if (node)
    {
        node->domain = PL_strdup(pref_node);
        node->func = callback;
        node->data = instance_data;
        node->next = gCallbacks;
        gCallbacks = node;
    }
    return;
}

Here is the caller graph for this function:

nsresult PREF_SetBoolPref ( const char *  pref,
PRBool  value,
PRBool  set_default = PR_FALSE 
)

Definition at line 311 of file prefapi.cpp.

{
    PrefValue pref;
    pref.boolVal = value ? PR_TRUE : PR_FALSE;

    return pref_HashPref(pref_name, pref, PREF_BOOL, set_default);
}

Here is the call graph for this function:

nsresult PREF_SetCharPref ( const char *  pref,
const char *  value,
PRBool  set_default = PR_FALSE 
)

Definition at line 293 of file prefapi.cpp.

{
    PrefValue pref;
    pref.stringVal = (char*) value;

    return pref_HashPref(pref_name, pref, PREF_STRING, set_default);
}

Here is the call graph for this function:

nsresult PREF_SetIntPref ( const char *  pref,
PRInt32  value,
PRBool  set_default = PR_FALSE 
)

Definition at line 302 of file prefapi.cpp.

{
    PrefValue pref;
    pref.intVal = value;

    return pref_HashPref(pref_name, pref, PREF_INT, set_default);
}

Here is the call graph for this function:

nsresult PREF_UnregisterCallback ( const char *  domain,
PrefChangedFunc  callback,
void instance_data 
)

Definition at line 856 of file prefapi.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    struct CallbackNode* node = gCallbacks;
    struct CallbackNode* prev_node = NULL;

    while (node != NULL)
    {
        if ( strcmp(node->domain, pref_node) == 0 &&
             node->func == callback &&
             node->data == instance_data)
        {
            if (gCallbacksInProgress)
            {
                // postpone the node removal until after
                // gCallbacks enumeration is finished.
                node->func = nsnull;
                gShouldCleanupDeadNodes = PR_TRUE;
                prev_node = node;
                node = node->next;
            }
            else
            {
                node = pref_RemoveCallbackNode(node, prev_node);
            }
            rv = NS_OK;
        }
        else
        {
            prev_node = node;
            node = node->next;
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function: