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.
21 #include <cstdio> /* for snprintf, grrr */
23 #include <pbd/failed_constructor.h>
24 #include <pbd/xml++.h>
25 #include <pbd/filesystem.h>
26 #include <pbd/file_utils.h>
27 #include <pbd/error.h>
29 #include <ardour/ardour.h>
30 #include <ardour/filesystem_paths.h>
32 #include "ui_config.h"
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
55 UIConfiguration::~UIConfiguration ()
60 UIConfiguration::load_defaults ()
63 sys::path default_ui_rc_file;
65 if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
66 "ardour3_ui_default.conf", default_ui_rc_file) )
71 string rcfile = default_ui_rc_file.to_string();
73 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
75 if (!tree.read (rcfile.c_str())) {
76 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
80 if (set_state (*tree.root())) {
81 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
89 UIConfiguration::load_state ()
93 sys::path default_ui_rc_file;
95 if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
96 "ardour3_ui_default.conf", default_ui_rc_file) )
101 string rcfile = default_ui_rc_file.to_string();
103 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
105 if (!tree.read (rcfile.c_str())) {
106 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
110 if (set_state (*tree.root())) {
111 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
116 sys::path user_ui_rc_file;
118 if (find_file_in_search_path (ardour_search_path() + user_config_directory(),
119 "ardour3_ui.conf", user_ui_rc_file))
124 string rcfile = user_ui_rc_file.to_string();
126 cerr << string_compose (_("loading user ui configuration file %1"), rcfile) << endl;
128 if (!tree.read (rcfile)) {
129 error << string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile) << endmsg;
133 if (set_state (*tree.root())) {
134 error << string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
140 error << "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg;
147 UIConfiguration::save_state()
153 sys::create_directories (user_config_directory ());
155 catch (const sys::filesystem_error& ex)
157 error << "Could not create user configuration directory" << endmsg;
161 sys::path rcfile_path(user_config_directory());
163 rcfile_path /= "ardour3_ui.conf";
164 const string rcfile = rcfile_path.to_string();
166 // this test seems bogus?
167 if (rcfile.length()) {
168 tree.set_root (&get_state());
169 if (!tree.write (rcfile.c_str())){
170 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
179 UIConfiguration::get_state ()
182 LocaleGuard lg (X_("POSIX"));
184 root = new XMLNode("Ardour");
186 root->add_child_nocopy (get_variables ("UI"));
187 root->add_child_nocopy (get_variables ("Canvas"));
190 root->add_child_copy (*_extra_xml);
197 UIConfiguration::get_variables (std::string which_node)
200 LocaleGuard lg (X_("POSIX"));
202 node = new XMLNode(which_node);
204 #undef UI_CONFIG_VARIABLE
205 #undef CANVAS_VARIABLE
206 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
207 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
208 #include "ui_config_vars.h"
209 #include "canvas_vars.h"
210 #undef UI_CONFIG_VARIABLE
211 #undef CANVAS_VARIABLE
217 UIConfiguration::set_state (const XMLNode& root)
219 if (root.name() != "Ardour") {
223 XMLNodeList nlist = root.children();
224 XMLNodeConstIterator niter;
227 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
230 if (node->name() == "Canvas" || node->name() == "UI") {
231 set_variables (*node);
233 } else if (node->name() == "extra") {
234 _extra_xml = new XMLNode (*node);
242 UIConfiguration::set_variables (const XMLNode& node)
244 #undef UI_CONFIG_VARIABLE
245 #undef CANVAS_VARIABLE
246 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
247 if (var.set_from_node (node)) { \
248 ParameterChanged (name); \
250 #define CANVAS_VARIABLE(var,name) \
251 if (var.set_from_node (node)) { \
252 ParameterChanged (name); \
254 #include "ui_config_vars.h"
255 #include "canvas_vars.h"
256 #undef UI_CONFIG_VARIABLE
257 #undef CANVAS_VARIABLE
261 UIConfiguration::pack_canvasvars ()
263 #undef CANVAS_VARIABLE
264 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
265 #include "canvas_vars.h"
266 #undef CANVAS_VARIABLE