2 Copyright (C) 2011 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "gui_object.h"
28 const string GUIObjectState::xml_node_name (X_("GUIObjectState"));
30 GUIObjectState::GUIObjectState ()
31 : _state (X_("GUIObjectState"))
37 GUIObjectState::get_node (const XMLNode* parent, const string& id)
39 XMLNodeList const & children = parent->children ();
40 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
42 if ((*i)->name() != X_("Object")) {
46 XMLProperty* p = (*i)->property (X_("id"));
47 if (p && p->value() == id) {
56 GUIObjectState::get_or_add_node (XMLNode* parent, const string& id)
58 XMLNode* child = get_node (parent, id);
60 child = new XMLNode (X_("Object"));
61 child->add_property (X_("id"), id);
62 parent->add_child_nocopy (*child);
69 GUIObjectState::get_or_add_node (const string& id)
71 return get_or_add_node (&_state, id);
74 /** Get a string from our state.
75 * @param id property of Object node to look for.
76 * @param prop_name name of the Object property to return.
77 * @param empty if non-0, filled in with true if the property is currently non-existant, otherwise false.
78 * @return value of property `prop_name', or empty.
82 GUIObjectState::get_string (const string& id, const string& prop_name, bool* empty)
84 XMLNode* child = get_node (&_state, id);
93 XMLProperty* p = child->property (prop_name);
109 GUIObjectState::get_state () const
111 return *new XMLNode (_state);
115 GUIObjectState::set_state (const XMLNode& node)
117 if (node.name() != xml_node_name) {
126 GUIObjectState::load (const XMLNode& node)
128 (void) set_state (node);
132 GUIObjectState::all_ids () const
134 std::list<string> ids;
135 XMLNodeList const & children = _state.children ();
136 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
137 if ((*i)->name() != X_("Object")) {
141 XMLProperty* p = (*i)->property (X_("id"));
143 ids.push_back (p->value ());