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 /** Remove node with provided id.
75 * @param id property of Object node to look for.
79 GUIObjectState::remove_node (const std::string& id)
81 _state.remove_nodes_and_delete(X_("id"), id );
84 /** Get a string from our state.
85 * @param id property of Object node to look for.
86 * @param prop_name name of the Object property to return.
87 * @param empty if non-0, filled in with true if the property is currently non-existant, otherwise false.
88 * @return value of property `prop_name', or empty.
92 GUIObjectState::get_string (const string& id, const string& prop_name, bool* empty)
94 XMLNode* child = get_node (&_state, id);
103 XMLProperty* p = child->property (prop_name);
119 GUIObjectState::get_state () const
121 return *new XMLNode (_state);
125 GUIObjectState::set_state (const XMLNode& node)
127 if (node.name() != xml_node_name) {
136 GUIObjectState::load (const XMLNode& node)
138 (void) set_state (node);
142 GUIObjectState::all_ids () const
144 std::list<string> ids;
145 XMLNodeList const & children = _state.children ();
146 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
147 if ((*i)->name() != X_("Object")) {
151 XMLProperty* p = (*i)->property (X_("id"));
153 ids.push_back (p->value ());