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

Inkscape::XML::Node * Inkscape::Preferences::_getNode ( Glib::ustring const &  pref_key,
bool  create = false 
) [private]

Get the XML node corresponding to the given pref key.

Parameters:
pref_keyPreference key (path) to get
createWhether to create the corresponding node if it doesn't exist
separatorThe character used to separate parts of the pref key
Returns:
XML node corresponding to the specified key

Derived from former inkscape_get_repr(). Private because it assumes that the backend is a flat XML file, which may not be the case e.g. if we are using GConf (in future).

Definition at line 625 of file preferences.cpp.

References _prefs_doc, Inkscape::XML::Node::attribute(), Inkscape::XML::Node::document(), Inkscape::XML::Node::firstChild(), Inkscape::XML::Node::next(), Inkscape::XML::Node::root(), and Inkscape::XML::Node::setAttribute().

Referenced by _findObserverNode(), getAllDirs(), and getAllEntries().

{
    // verify path
    g_assert( pref_key.at(0) == '/' );
    // No longer necessary, can cause problems with input devices which have a dot in the name
    // g_assert( pref_key.find('.') == Glib::ustring::npos );

    Inkscape::XML::Node *node = _prefs_doc->root();
    Inkscape::XML::Node *child = NULL;
    gchar **splits = g_strsplit(pref_key.c_str(), "/", 0);

    if ( splits ) {
        for (int part_i = 0; splits[part_i]; ++part_i) {
            // skip empty path segments
            if (!splits[part_i][0]) {
                continue;
            }

            for (child = node->firstChild(); child; child = child->next()) {
                if (!strcmp(splits[part_i], child->attribute("id"))) {
                    break;
                }
            }

            // If the previous loop found a matching key, child now contains the node
            // matching the processed key part. If no node was found then it is NULL.
            if (!child) {
                if (create) {
                    // create the rest of the key
                    while(splits[part_i]) {
                        child = node->document()->createElement("group");
                        child->setAttribute("id", splits[part_i]);
                        node->appendChild(child);

                        ++part_i;
                        node = child;
                    }
                    g_strfreev(splits);
                    return node;
                } else {
                    return NULL;
                }
            }

            node = child;
        }
        g_strfreev(splits);
    }
    return node;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index