Difference between revisions of "How preferences work"

From Second Life Wiki
Jump to navigation Jump to search
(Major expansion of article coverage)
m (client → advanced)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This document contains information about how user preferences are stored and manipulated in the Second Life Viewer Client.
{{OSWikiLearnBox|parent=Viewer architecture}}
[[Category:Viewer Architecture]]


== The gSavedSettings Control Group ==
This articles describes how the Second Life Viewer stores and manipulates preferences.
For a description of all the preferences settings, see [[Debug Settings]].
 
== The gSavedSettings control group ==


The values for user preferences are stored in gSavedSettings, a global variable of the class LLControlGroup (see "indra/llxml/llcontrol.cpp" for the definition of that class). At the end of the session (i.e. when the viewer client is quit), persistent settings are saved to "settings.xml". They will be loaded from that file at the beginning of the next session.
The values for user preferences are stored in gSavedSettings, a global variable of the class LLControlGroup (see "indra/llxml/llcontrol.cpp" for the definition of that class). At the end of the session (i.e. when the viewer client is quit), persistent settings are saved to "settings.xml". They will be loaded from that file at the beginning of the next session.


== Declaring a New Preference ==
== Declaring a New Preference ==
 
As of Viewer relese 1.20 the settings system uses an XML file, <code>app_settings/settings.xml</code>, to control settings values.
All preferences must be declared in "indra/newview/llcontroldef.cpp" to be used. The declaration informs the client of details about the preference:
This file provides the following information for each preference setting:
* its data type (e.g. color, string, float);
* Data type
* its name (e.g. "EffectColor");
* Name
* its initial (default) value;
* Default value
* its documentation string, which is displayed in the "Debug Settings" floater (in the Client menu);
* Documentation string, displayed in the "Debug Settings" floater (in the [[advanced menu]]);
* (optional) its persistence, i.e. whether it will be saved between sessions.
* (optional) persistence, that is, whether it is saved between sessions.


The following example (taken from "indra/newview/llcontroldef.cpp") declares a preference which stores a 4-channel (RGBA) color, called "EffectColor", with a default value of totally-opaque white (1, 1, 1, 1), and a documentation string, "Particle effects color":
The following example (taken from "indra/newview/llcontroldef.cpp") declares a preference which stores a 4-channel (RGBA) color, called "EffectColor", with a default value of totally-opaque white (1, 1, 1, 1), and a documentation string, "Particle effects color":
Line 22: Line 26:
  gSavedSettings.declareBOOL("ShowTools", FALSE, "", NO_PERSIST);
  gSavedSettings.declareBOOL("ShowTools", FALSE, "", NO_PERSIST);


The full list of data types, their declaration function names, and data type descriptions follows. Note that for data types which start with "LL" (e.g. LLString), the declare function name does not contain the leading "LL" (thus it becomes "declareString", not "declare'''LL'''String")
=== Data types ===
The following table describes the data types valid for preferences. For data types that start with "LL", the declare function name does not contain the leading "LL." For example data type  LLString the declare function is "declareString."


{|border="1" cellpadding="10px"
{| {{Prettytable}}
|-{{Hl2}}
!Data Type !! Declare Function !! Description
!Data Type !! Declare Function !! Description
|-
|-
Line 50: Line 56:
|}
|}


== Accessing preference data ==


== Accessing Preference Data ==
The LLControlGroup class (of which gSavedSettings is an instance) defines "get" and "set" functions for each of the data types. The functions follow this format, where "DataType" is replaced with the proper data type, e.g. BOOL, F32, LLColor4. As with the declare functions, the get and set function names to not contain the leading "LL" for data types like LLString and LLColor4.
 
The LLControlGroup class (of which gSavedSettings is an instance) defines "get" and "set" functions for each of the data types. The functions follow this format, where "DataType" is replaced with the proper data type, e.g. BOOL, F32, LLColor4. (As with the declare functions, the get and set function names to not contain the leading "LL" for data types like LLString and LLColor4.)


  LLControlGroup::getDataType( LLString name );
  LLControlGroup::getDataType( LLString name );
Line 66: Line 71:
There are three additional "get" functions for certain special cases:
There are three additional "get" functions for certain special cases:


{|border="1" cellpadding="10px"
{| {{Prettytable}}
|-{{Hl2}}
!Function Name!! Return Type !! Description
!Function Name!! Return Type !! Description
|-
|-

Latest revision as of 02:46, 16 March 2009

This articles describes how the Second Life Viewer stores and manipulates preferences. For a description of all the preferences settings, see Debug Settings.

The gSavedSettings control group

The values for user preferences are stored in gSavedSettings, a global variable of the class LLControlGroup (see "indra/llxml/llcontrol.cpp" for the definition of that class). At the end of the session (i.e. when the viewer client is quit), persistent settings are saved to "settings.xml". They will be loaded from that file at the beginning of the next session.

Declaring a New Preference

As of Viewer relese 1.20 the settings system uses an XML file, app_settings/settings.xml, to control settings values. This file provides the following information for each preference setting:

  • Data type
  • Name
  • Default value
  • Documentation string, displayed in the "Debug Settings" floater (in the advanced menu);
  • (optional) persistence, that is, whether it is saved between sessions.

The following example (taken from "indra/newview/llcontroldef.cpp") declares a preference which stores a 4-channel (RGBA) color, called "EffectColor", with a default value of totally-opaque white (1, 1, 1, 1), and a documentation string, "Particle effects color":

gSavedSettings.declareColor4("EffectColor", LLColor4(1.f, 1.f, 1.f, 1.f), "Particle effects color");

This next example shows how you can specify that the preference should NOT persist between sessions, by giving NO_PERSIST as a fourth argument to the declaration:

gSavedSettings.declareBOOL("ShowTools", FALSE, "", NO_PERSIST);

Data types

The following table describes the data types valid for preferences. For data types that start with "LL", the declare function name does not contain the leading "LL." For example data type LLString the declare function is "declareString."

Data Type Declare Function Description
U32 declareU32 Unsigned 32-bit Integer
S32 declareS32 Signed 32-bit Integer
F32 declareF32 32-bit Float
BOOL declareBOOL Boolean (True/False)
LLString declareString Character String (Text)
LLVector3 declareVec3 3D Vector
LLVector3d declareVec3d 3D Vector (double data size)
LLRect declareRect Rectangle (left, bottom, width, height)
LLColor4U declareColor4U Unsigned 4-Channel Color (RGBA)
LLColor4 declareColor4 4-Channel Color (RGBA)
LLColor3 declareColor3 3-Channel Color (RGB)

Accessing preference data

The LLControlGroup class (of which gSavedSettings is an instance) defines "get" and "set" functions for each of the data types. The functions follow this format, where "DataType" is replaced with the proper data type, e.g. BOOL, F32, LLColor4. As with the declare functions, the get and set function names to not contain the leading "LL" for data types like LLString and LLColor4.

LLControlGroup::getDataType( LLString name );
LLControlGroup::setDataType( LLString name, DataType new_value );

A contrived example of retrieving and then setting an LLColor4-typed preference:

LLColor4 my_color;
my_color = gSavedSettings.getColor4( "EffectColor" );
gSavedSettings.setColor4( "EffectColor", my_color );

There are three additional "get" functions for certain special cases:

Function Name Return Type Description
getWString LLWString Wide-Data Strings (multiple bytes per char)
getText LLString Special handler for strings from a file?
getColor LLColor4 Handles both LLColor4 and LLColor4u types.