Code

Remove unused and buggy-looking function get_pref_children.
[inkscape.git] / src / prefs-utils.cpp
index 5e01b1903c135503bcefe24bf02b19424b5eed6f..7a950c3c3c60a54bff5dfbe76e1aa95301c5281e 100644 (file)
@@ -24,6 +24,49 @@ 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)
 {
@@ -107,7 +150,7 @@ prefs_get_string_attribute(gchar const *path, gchar const *attr)
 {
     Inkscape::XML::Node *repr = inkscape_get_repr(INKSCAPE, path);
     if (repr) {
-        return (char *) repr->attribute(attr);
+        return repr->attribute(attr);
     }
     return NULL;
 }