Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends

Inkscape::Preferences Class Reference

Preference storage class. More...

#include <preferences.h>

Collaboration diagram for Inkscape::Preferences:
Collaboration graph
[legend]

List of all members.

Classes

class  Entry
 Data type representing a typeless value of a preference. More...
class  Observer
 Base class for preference observers. More...
class  PrefNodeObserver
 XML - prefs observer bridge. More...

Public Member Functions

bool getLastError (Glib::ustring &primary, Glib::ustring &secondary)
 Return details of the last encountered error, if any.
bool isWritable ()
 Check whether saving the preferences will have any effect.
void save ()
 Save all preferences to the hard disk.
Iterate over directories and entries.
std::vector< EntrygetAllEntries (Glib::ustring const &path)
 Get all entries from the specified directory.
std::vector< Glib::ustring > getAllDirs (Glib::ustring const &path)
 Get all subdirectories of the specified directory.
Retrieve data from the preference storage.
bool getBool (Glib::ustring const &pref_path, bool def=false)
 Retrieve a Boolean value.
int getInt (Glib::ustring const &pref_path, int def=0)
 Retrieve an integer.
int getIntLimited (Glib::ustring const &pref_path, int def=0, int min=INT_MIN, int max=INT_MAX)
 Retrieve a limited integer.
double getDouble (Glib::ustring const &pref_path, double def=0.0)
double getDoubleLimited (Glib::ustring const &pref_path, double def=0.0, double min=DBL_MIN, double max=DBL_MAX)
 Retrieve a limited floating point value.
Glib::ustring getString (Glib::ustring const &pref_path)
 Retrieve an UTF-8 string.
guint32 getColor (Glib::ustring const &pref_path, guint32 def=0x000000ff)
SPCSSAttrgetStyle (Glib::ustring const &pref_path)
 Retrieve a CSS style.
SPCSSAttrgetInheritedStyle (Glib::ustring const &pref_path)
 Retrieve an inherited CSS style.
Entry const getEntry (Glib::ustring const &pref_path)
 Retrieve a preference entry without specifying its type.
Update preference values.
void setBool (Glib::ustring const &pref_path, bool value)
 Set a Boolean value.
void setInt (Glib::ustring const &pref_path, int value)
 Set an integer value.
void setDouble (Glib::ustring const &pref_path, double value)
 Set a floating point value.
void setString (Glib::ustring const &pref_path, Glib::ustring const &value)
 Set an UTF-8 string value.
void setColor (Glib::ustring const &pref_path, guint32 value)
 Set an RGBA color value.
void setStyle (Glib::ustring const &pref_path, SPCSSAttr *style)
 Set a CSS style.
void mergeStyle (Glib::ustring const &pref_path, SPCSSAttr *style)
 Merge a CSS style with the current preference value.
Receive notifications about preference changes.
void addObserver (Observer &)
 Register a preference observer.
void removeObserver (Observer &)
 Remove an observer an prevent further notifications to it.

Protected Member Functions

bool _extractBool (Entry const &v)
guint32 _extractColor (Entry const &v)
double _extractDouble (Entry const &v)
SPCSSAttr_extractInheritedStyle (Entry const &v)
int _extractInt (Entry const &v)
Glib::ustring _extractString (Entry const &v)
SPCSSAttr_extractStyle (Entry const &v)

Private Types

typedef std::map< Observer
*, PrefNodeObserver * > 
_ObsMap

Private Member Functions

XML::Node_findObserverNode (Glib::ustring const &pref_path, Glib::ustring &node_key, Glib::ustring &attr_key, bool create)
 Find the XML node to observe.
XML::Node_getNode (Glib::ustring const &pref_path, bool create=false)
 Get the XML node corresponding to the given pref key.
void _getRawValue (Glib::ustring const &path, gchar const *&result)
void _keySplit (Glib::ustring const &pref_path, Glib::ustring &node_key, Glib::ustring &attr_key)
void _load ()
 Load the user's customized preferences.
void _loadDefaults ()
 Load internal defaults.
void _reportError (Glib::ustring const &, Glib::ustring const &)
void _setRawValue (Glib::ustring const &path, gchar const *value)
Preferences operator= (Preferences const &)
 Preferences (Preferences const &)

Static Private Member Functions

static Entry const _create_pref_value (Glib::ustring const &, void const *ptr)
static void * _get_pref_observer_data (Observer &o)

Private Attributes

ErrorReporter_errorHandler
 Pointer to object reporting errors.
bool _hasError
 Indication that some error has occurred;.
Glib::ustring _lastErrPrimary
 Last primary error message, if any.
Glib::ustring _lastErrSecondary
 Last secondary error message, if any.
_ObsMap _observer_map
 Map that keeps track of wrappers assigned to PrefObservers.
std::string _prefs_basename
 Basename of the prefs file.
std::string _prefs_dir
 Directory in which to look for the prefs file.
XML::Document_prefs_doc
 XML document storing all the preferences.
std::string _prefs_filename
 Full filename (with directory) of the prefs file.
bool _writable
 Will the preferences be saved at exit?

Static Private Attributes

static Preferences_instance = NULL

Friends

class Entry
class PrefNodeObserver

Access and manipulate the Preferences object.

void setErrorHandler (ErrorReporter *handler)
static void migrate (std::string const &legacyDir, std::string const &prefdir)
static Preferencesget ()
 Access the singleton Preferences object.
static void unload (bool save=true)
 Unload all preferences.

Detailed Description

Preference storage class.

This is a singleton that allows one to access the user preferences stored in the preferences.xml file. The preferences are stored in a file system-like hierarchy. They are generally typeless - it's up to the programmer to ensure that a given preference is always accessed as the correct type. The backend is not guaranteed to be tolerant to type mismatches.

Preferences are identified by paths similar to file system paths. Components of the path are separated by a slash (/). As an additional requirement, the path must start with a slash, and not contain a trailing slash. An example of a correct path would be "/options/some_group/some_option".

All preferences are loaded when the first singleton pointer is requested. To save the preferences, the method save() or the static function unload() can be used.

In future, this will be a virtual base from which specific backends derive (e.g. GConf, flat XML file...)

Definition at line 56 of file preferences.h.


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

Generated by  Doxygen 1.6.0   Back to index