Moved canvas colors and theme file selection into new ui specific config system,...
[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         T value;
97         std::string _name;
98 };
99
100 class UIConfiguration : public PBD::Stateful
101 {
102   public:
103         UIConfiguration();
104         ~UIConfiguration();
105
106         std::vector<UIConfigVariable<uint32_t> *> canvas_colors;
107
108         int load_state ();
109         int save_state ();
110
111         int set_state (const XMLNode&);
112         XMLNode& get_state (void);
113         XMLNode& get_variables (std::string);
114         void set_variables (const XMLNode&);
115         void pack_canvasvars ();
116
117         sigc::signal<void,const char*> ParameterChanged;
118
119 #undef  UI_CONFIG_VARIABLE
120 #undef  CANVAS_VARIABLE
121 #define UI_CONFIG_VARIABLE(Type,var,name,val) UIConfigVariable<Type> var;
122 #define CANVAS_VARIABLE(var,name) UIConfigVariable<uint32_t> var;
123 #include "ui_config_vars.h"
124 #include "canvas_vars.h"
125 #undef  UI_CONFIG_VARIABLE
126 #undef  CANVAS_VARIABLE
127
128   private:
129         XMLNode& state ();
130         bool hack;
131 };
132
133 #endif /* __ardour_ui_configuration_h__ */
134