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