make AU Cocoa plugin views with "client-side-windows" versions of GTK+; make keyboard...
[ardour2.git] / gtk2_ardour / ui_config.cc
blob4e21f427a02989921a117f1f9a729d0a8e29ebc5
1 /*
2 Copyright (C) 1999-2006 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.
20 #include <unistd.h>
21 #include <cstdio> /* for snprintf, grrr */
23 #include <glibmm/miscutils.h>
25 #include <pbd/failed_constructor.h>
26 #include <pbd/xml++.h>
27 #include <pbd/error.h>
28 #include <pbd/localeguard.h>
30 #include <ardour/ardour.h>
32 #include "ui_config.h"
34 #include "i18n.h"
36 using namespace std;
37 using namespace PBD;
38 using namespace ARDOUR;
40 UIConfiguration::UIConfiguration ()
42 #undef UI_CONFIG_VARIABLE
43 #undef CANVAS_VARIABLE
44 #define UI_CONFIG_VARIABLE(Type,var,name,val) var (name,val),
45 #define CANVAS_VARIABLE(var,name) var (name),
46 #include "ui_config_vars.h"
47 #include "canvas_vars.h"
48 #undef UI_CONFIG_VARIABLE
49 #undef CANVAS_VARIABLE
50 hack(true)
52 load_state();
55 UIConfiguration::~UIConfiguration ()
59 int
60 UIConfiguration::load_defaults ()
62 int found = 0;
63 std::string rcfile;
64 const char* ui_conf;
66 ui_conf = getenv ("ARDOUR_UI_CONF");
68 if (ui_conf && ui_conf[0] != '\0') {
69 rcfile = find_config_file (ui_conf);
70 } else {
71 if (getenv ("ARDOUR_SAE")) {
72 rcfile = find_config_file ("ardour2_ui_sae.conf");
73 } else {
74 rcfile = find_config_file ("ardour2_ui_default.conf");
78 if (rcfile.length()) {
80 XMLTree tree;
81 found = 1;
83 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
85 if (!tree.read (rcfile.c_str())) {
86 error << string_compose(_("%1: cannot read default ui configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
87 return -1;
90 if (set_state (*tree.root())) {
91 error << string_compose(_("%1: default ui configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
92 return -1;
95 return found;
98 int
99 UIConfiguration::load_state ()
101 int found = load_defaults ();
102 std::string rcfile = find_config_file ("ardour2_ui.conf");
104 if (rcfile.length())
106 XMLTree tree;
107 found = true;
109 cerr << string_compose (_("loading user ui configuration file %1"), rcfile) << endl;
111 if (!tree.read (rcfile)) {
112 error << string_compose(_("%1: cannot read ui configuration file \"%2\""), PROGRAM_NAME, rcfile) << endmsg;
113 return -1;
116 if (set_state (*tree.root())) {
117 error << string_compose(_("%1: user ui configuration file \"%2\" not loaded successfully."), PROGRAM_NAME, rcfile) << endmsg;
118 return -1;
122 if (found != 1)
123 error << string_compose (_("%1: could not find any ui configuration file, canvas will look broken."), PROGRAM_NAME) << endmsg;
125 pack_canvasvars();
126 return 0;
130 UIConfiguration::save_state()
132 XMLTree tree;
133 string rcfile;
135 rcfile = Glib::build_filename (get_user_ardour_path (), "ardour2_ui.conf");
137 if (rcfile.length()) {
138 tree.set_root (&get_state());
139 if (!tree.write (rcfile.c_str())){
140 error << string_compose (_("UI config file %1 not saved"), rcfile) << endmsg;
141 return -1;
145 return 0;
148 XMLNode&
149 UIConfiguration::get_state ()
151 XMLNode* root;
152 LocaleGuard lg (X_("POSIX"));
154 root = new XMLNode("Ardour");
156 root->add_child_nocopy (get_variables ("UI"));
157 root->add_child_nocopy (get_variables ("Canvas"));
159 if (_extra_xml) {
160 root->add_child_copy (*_extra_xml);
163 return *root;
166 XMLNode&
167 UIConfiguration::get_variables (std::string which_node)
169 XMLNode* node;
170 LocaleGuard lg (X_("POSIX"));
172 node = new XMLNode(which_node);
174 #undef UI_CONFIG_VARIABLE
175 #undef CANVAS_VARIABLE
176 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
177 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
178 #include "ui_config_vars.h"
179 #include "canvas_vars.h"
180 #undef UI_CONFIG_VARIABLE
181 #undef CANVAS_VARIABLE
183 return *node;
187 UIConfiguration::set_state (const XMLNode& root)
189 if (root.name() != "Ardour") {
190 return -1;
193 XMLNodeList nlist = root.children();
194 XMLNodeConstIterator niter;
195 XMLNode *node;
197 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
199 node = *niter;
200 if (node->name() == "Canvas" || node->name() == "UI") {
201 set_variables (*node);
203 } else if (node->name() == "extra") {
204 _extra_xml = new XMLNode (*node);
208 return 0;
211 void
212 UIConfiguration::set_variables (const XMLNode& node)
214 #undef UI_CONFIG_VARIABLE
215 #undef CANVAS_VARIABLE
216 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
217 if (var.set_from_node (node)) { \
218 ParameterChanged (name); \
220 #define CANVAS_VARIABLE(var,name) \
221 if (var.set_from_node (node)) { \
222 ParameterChanged (name); \
224 #include "ui_config_vars.h"
225 #include "canvas_vars.h"
226 #undef UI_CONFIG_VARIABLE
227 #undef CANVAS_VARIABLE
230 void
231 UIConfiguration::pack_canvasvars ()
233 #undef CANVAS_VARIABLE
234 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
235 #include "canvas_vars.h"
236 #undef CANVAS_VARIABLE