summaryrefslogtreecommitdiffstats
path: root/src/prefs-utils.cpp
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2008-09-16 17:15:22 +0000
committertweenk <tweenk@users.sourceforge.net>2008-09-16 17:15:22 +0000
commit9d87d30b72145fdee954992a9dc70f8c60174d7d (patch)
tree194a94ece6ed668ad7dc529de2cdd09b7565c6fe /src/prefs-utils.cpp
parentfix leak of the arena and arenaitem (diff)
downloadinkscape-9d87d30b72145fdee954992a9dc70f8c60174d7d.tar.gz
inkscape-9d87d30b72145fdee954992a9dc70f8c60174d7d.zip
Refactored preferences handling into a new version of
the Inkscape::Preferences class. Removed all use of prefs_get_string_attribute(), pref_path_get_nth_child() and create_pref() in favor of the new API. Replaced some "0 or 1" integer preferences with booleans. (bzr r6823)
Diffstat (limited to 'src/prefs-utils.cpp')
-rw-r--r--src/prefs-utils.cpp147
1 files changed, 1 insertions, 146 deletions
diff --git a/src/prefs-utils.cpp b/src/prefs-utils.cpp
index 7a950c3c3..004626ac6 100644
--- a/src/prefs-utils.cpp
+++ b/src/prefs-utils.cpp
@@ -14,155 +14,10 @@
# include "config.h"
#endif
+#include "prefs-utils.h"
#include "inkscape.h"
#include "xml/repr.h"
-/**
-\brief Checks if the path exists in the preference file
-*/
-bool pref_path_exists(gchar const *path){
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- return (repr != NULL);
-}
-
-/**
-\brief returns the number of sub-prefs
-*/
-unsigned int pref_path_number_of_children(gchar const *path){
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- Inkscape::XML::Node *child_repr = sp_repr_children(repr);
- int nb_child = 0;
- while (child_repr) {
- nb_child ++;
- child_repr = sp_repr_next(child_repr);
- }
- return nb_child;
-}
-
-/**
-\brief creates a new preference and returns its key on success.
-*/
-gchar * create_pref(gchar const *father_path, gchar const *child){
- Inkscape::XML::Node *father = inkscape_get_repr(INKSCAPE, father_path);
- if (! father ) return NULL;
- Inkscape::XML::Node *repr = father->document()->createElement("group");
- repr->setAttribute("id", child, false);
- father->appendChild(repr);
- return g_strdup_printf("%s.%s", father_path,child);
-}
-
-/**
-\brief gets the nth children of a pref, starting from one (first child <=> n=1). returns NULL if out of bounds or father does not exist. Please free all that stuff after use.
-*/
-gchar *get_pref_nth_child(gchar const *father_path, unsigned int n){
- if (n <= 0) return NULL;
- Inkscape::XML::Node *father = inkscape_get_repr(INKSCAPE, father_path);
- if (! father ) return NULL;
- Inkscape::XML::Node *child_repr = sp_repr_children(father);
- unsigned int index = 0;
- while (child_repr && (++index < n)) {
- child_repr = sp_repr_next(child_repr);
- }
- if (child_repr) return g_strdup_printf("%s.%s",father_path,child_repr->attribute("id"));
- return NULL;
-}
-
-void
-prefs_set_int_attribute(gchar const *path, gchar const *attr, long long int value)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- sp_repr_set_int(repr, attr, value);
- }
-}
-
-long long int
-prefs_get_int_attribute(gchar const *path, gchar const *attr, long long int def)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- return sp_repr_get_int_attribute(repr, attr, def);
- } else {
- return def;
- }
-}
-
-/**
-\brief Retrieves an int attribute guarding against screwed-up data; if the value is beyond limits, default is returned
-*/
-long long int
-prefs_get_int_attribute_limited(gchar const *path, gchar const *attr, long long int def, long long int min, long long int max)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- long long int const v = sp_repr_get_int_attribute(repr, attr, def);
- if (v >= min && v <= max) {
- return v;
- } else {
- return def;
- }
- } else {
- return def;
- }
-}
-
-void
-prefs_set_double_attribute(gchar const *path, gchar const *attr, double value)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- sp_repr_set_svg_double(repr, attr, value);
- }
-}
-
-double
-prefs_get_double_attribute(gchar const *path, gchar const *attr, double def)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- return sp_repr_get_double_attribute(repr, attr, def);
- } else {
- return def;
- }
-}
-
-/**
-\brief Retrieves an int attribute guarding against screwed-up data; if the value is beyond limits, default is returned
-*/
-double
-prefs_get_double_attribute_limited(gchar const *path, gchar const *attr, double def, double min, double max)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- double const v = sp_repr_get_double_attribute(repr, attr, def);
- if (v >= min && v <= max) {
- return v;
- } else {
- return def;
- }
- } else {
- return def;
- }
-}
-
-gchar const *
-prefs_get_string_attribute(gchar const *path, gchar const *attr)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- return repr->attribute(attr);
- }
- return NULL;
-}
-
-void
-prefs_set_string_attribute(gchar const *path, gchar const *attr, gchar const *value)
-{
- Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
- if (repr) {
- repr->setAttribute(attr, value);
- }
-}
void
prefs_set_recent_file(gchar const *uri, gchar const *name)