ardour
configuration_variable.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 1999-2009 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <iostream>
21 
22 #include "pbd/compose.h"
24 #include "pbd/debug.h"
25 
26 using namespace std;
27 using namespace PBD;
28 
29 void
30 ConfigVariableBase::add_to_node (XMLNode& node)
31 {
32  const std::string v = get_as_string ();
33  DEBUG_TRACE (DEBUG::Configuration, string_compose ("Config variable %1 stored as [%2]\n", _name, v));
34  XMLNode* child = new XMLNode ("Option");
35  child->add_property ("name", _name);
36  child->add_property ("value", v);
37  node.add_child_nocopy (*child);
38 }
39 
40 bool
41 ConfigVariableBase::set_from_node (XMLNode const & node)
42 {
43  if (node.name() == "Config" || node.name() == "Canvas" || node.name() == "UI") {
44 
45  /* ardour.rc */
46 
47  const XMLProperty* prop;
48  XMLNodeList nlist;
50  XMLNode* child;
51 
52  nlist = node.children();
53 
54  for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
55 
56  child = *niter;
57 
58  if (child->name() == "Option") {
59  if ((prop = child->property ("name")) != 0) {
60  if (prop->value() == _name) {
61  if ((prop = child->property ("value")) != 0) {
62  set_from_string (prop->value());
63  return true;
64  }
65  }
66  }
67  }
68  }
69 
70  } else if (node.name() == "Options") {
71 
72  /* session file */
73 
74  XMLNodeList olist;
76  XMLNode* option;
77  const XMLProperty* opt_prop;
78 
79  olist = node.children();
80 
81  for (oiter = olist.begin(); oiter != olist.end(); ++oiter) {
82 
83  option = *oiter;
84 
85  if (option->name() == _name) {
86  if ((opt_prop = option->property ("val")) != 0) {
87  set_from_string (opt_prop->value());
88  return true;
89  }
90  }
91  }
92  }
93 
94  return false;
95 }
96 
97 void
98 ConfigVariableBase::notify ()
99 {
100  // placeholder for any debugging desired when a config variable is modified
101 }
102 
103 void
104 ConfigVariableBase::miss ()
105 {
106  // placeholder for any debugging desired when a config variable
107  // is set but to the same value as it already has
108 }
109 
const std::string & value() const
Definition: xml++.h:159
const std::string & name() const
Definition: xml++.h:104
Definition: Beats.hpp:239
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
Definition: getopt.h:74
XMLProperty * property(const char *)
Definition: xml++.cc:413
LIBPBD_API uint64_t Configuration
Definition: debug.cc:53
#define DEBUG_TRACE(bits, str)
Definition: debug.h:55
XMLProperty * add_property(const char *name, const std::string &value)
void add_child_nocopy(XMLNode &)
Definition: xml++.cc:357
Definition: xml++.h:95
Definition: debug.h:30
XMLNodeList::const_iterator XMLNodeConstIterator
Definition: xml++.h:49
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208