fix compiler warning
[ardour.git] / gtk2_ardour / ui_config.h
1 /*
2     Copyright (C) 2000-2007 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 #ifndef __ardour_ui_configuration_h__
21 #define __ardour_ui_configuration_h__
22
23 #include <sstream>
24 #include <ostream>
25 #include <iostream>
26
27 #include <pbd/stateful.h> 
28 #include <pbd/xml++.h>
29
30 template<class T>
31 class UIConfigVariable 
32 {
33   public:
34         UIConfigVariable (std::string str) : _name (str) {}
35         UIConfigVariable (std::string str, T val) : _name (str), value(val) {}
36
37         std::string name() const { return _name; }
38
39         bool set (T val) {
40                 if (val == value) {
41                         return false;
42                 }
43                 value = val;
44                 return true;
45         }
46
47         T get() const {
48                 return value;
49         }
50
51         void add_to_node (XMLNode& node) {
52                 std::stringstream ss;
53                 ss << std::hex;
54                 ss.fill('0');
55                 ss.width(8);
56                 ss << value;
57                 XMLNode* child = new XMLNode ("Option");
58                 child->add_property ("name", _name);
59                 child->add_property ("value", ss.str());
60                 node.add_child_nocopy (*child);
61         }
62         
63         bool set_from_node (const XMLNode& node) {
64
65                 const XMLProperty* prop;
66                 XMLNodeList nlist;
67                 XMLNodeConstIterator niter;
68                 XMLNode* child;
69                         
70                 nlist = node.children();
71                         
72                 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
73                                 
74                         child = *niter;
75                                 
76                         if (child->name() == "Option") {
77                                 if ((prop = child->property ("name")) != 0) {
78                                         if (prop->value() == _name) {
79                                                 if ((prop = child->property ("value")) != 0) {
80                                                         std::stringstream ss;
81                                                         ss << std::hex;
82                                                         ss << prop->value();
83                                                         ss >> value;
84
85                                                         return true;
86                                                 }
87                                         }
88                                 }
89                         }
90                 }
91                 return false;
92         }
93
94   protected:
95         T get_for_save() { return value; }
96         std::string _name;
97         T value;
98         
99 };
100
101 class UIConfiguration : public PBD::Stateful
102 {
103   public:
104         UIConfiguration();
105         ~UIConfiguration();
106
107         std::vector<UIConfigVariable<uint32_t> *> canvas_colors;
108
109         int load_state ();
110         int save_state ();
111
112         int set_state (const XMLNode&);
113         XMLNode& get_state (void);
114         XMLNode& get_variables (std::string);
115         void set_variables (const XMLNode&);
116         void pack_canvasvars ();
117
118         sigc::signal<void,const char*> ParameterChanged;
119
120 #undef  UI_CONFIG_VARIABLE
121 #undef  CANVAS_VARIABLE
122 #define UI_CONFIG_VARIABLE(Type,var,name,val) UIConfigVariable<Type> var;
123 #define CANVAS_VARIABLE(var,name) UIConfigVariable<uint32_t> var;
124 #include "ui_config_vars.h"
125 #include "canvas_vars.h"
126 #undef  UI_CONFIG_VARIABLE
127 #undef  CANVAS_VARIABLE
128
129   private:
130         XMLNode& state ();
131         bool hack;
132 };
133
134 #endif /* __ardour_ui_configuration_h__ */
135