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_state ()
64 sys::path default_ui_rc_file;
66 if ( find_file_in_search_path (ardour_search_path() + system_config_search_path(),
67 "ardour2_ui_default.conf", default_ui_rc_file) )
72 string rcfile = default_ui_rc_file.to_string();
74 cerr << string_compose (_("loading default ui configuration file %1"), rcfile) << endl;
76 if (!tree.read (rcfile.c_str())) {
77 error << string_compose(_("Ardour: cannot read default ui configuration file \"%1\""), rcfile) << endmsg;
81 if (set_state (*tree.root())) {
82 error << string_compose(_("Ardour: default ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
87 sys::path user_ui_rc_file;
89 if (find_file_in_search_path (ardour_search_path() + user_config_directory(),
90 "ardour2_ui.conf", user_ui_rc_file))
95 string rcfile = user_ui_rc_file.to_string();
97 cerr << string_compose (_("loading user ui configuration file %1"), rcfile) << endl;
99 if (!tree.read (rcfile)) {
100 error << string_compose(_("Ardour: cannot read ui configuration file \"%1\""), rcfile) << endmsg;
104 if (set_state (*tree.root())) {
105 error << string_compose(_("Ardour: user ui configuration file \"%1\" not loaded successfully."), rcfile) << endmsg;
111 error << "Ardour: could not find any ui configuration file, canvas will look broken." << endmsg;
118 UIConfiguration::save_state()
124 sys::create_directories (user_config_directory ());
126 catch (const sys::filesystem_error& ex)
128 error << "Could not create user configuration directory" << endmsg;
132 sys::path rcfile_path(user_config_directory());
134 rcfile_path /= "ardour2_ui.conf";
135 const string rcfile = rcfile_path.to_string();
137 // this test seems bogus?
138 if (rcfile.length()) {
139 tree.set_root (&get_state());
140 if (!tree.write (rcfile.c_str())){
141 error << string_compose (_("Config file %1 not saved"), rcfile) << endmsg;
150 UIConfiguration::get_state ()
153 LocaleGuard lg (X_("POSIX"));
155 root = new XMLNode("Ardour");
157 root->add_child_nocopy (get_variables ("UI"));
158 root->add_child_nocopy (get_variables ("Canvas"));
161 root->add_child_copy (*_extra_xml);
168 UIConfiguration::get_variables (std::string which_node)
171 LocaleGuard lg (X_("POSIX"));
173 node = new XMLNode(which_node);
175 #undef UI_CONFIG_VARIABLE
176 #undef CANVAS_VARIABLE
177 #define UI_CONFIG_VARIABLE(Type,var,Name,value) if (node->name() == "UI") { var.add_to_node (*node); }
178 #define CANVAS_VARIABLE(var,Name) if (node->name() == "Canvas") { var.add_to_node (*node); }
179 #include "ui_config_vars.h"
180 #include "canvas_vars.h"
181 #undef UI_CONFIG_VARIABLE
182 #undef CANVAS_VARIABLE
188 UIConfiguration::set_state (const XMLNode& root)
190 if (root.name() != "Ardour") {
194 XMLNodeList nlist = root.children();
195 XMLNodeConstIterator niter;
198 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
201 if (node->name() == "Canvas" || node->name() == "UI") {
202 set_variables (*node);
204 } else if (node->name() == "extra") {
205 _extra_xml = new XMLNode (*node);
213 UIConfiguration::set_variables (const XMLNode& node)
215 #undef UI_CONFIG_VARIABLE
216 #undef CANVAS_VARIABLE
217 #define UI_CONFIG_VARIABLE(Type,var,name,val) \
218 if (var.set_from_node (node)) { \
219 ParameterChanged (name); \
221 #define CANVAS_VARIABLE(var,name) \
222 if (var.set_from_node (node)) { \
223 ParameterChanged (name); \
225 #include "ui_config_vars.h"
226 #include "canvas_vars.h"
227 #undef UI_CONFIG_VARIABLE
228 #undef CANVAS_VARIABLE
232 UIConfiguration::pack_canvasvars ()
234 #undef CANVAS_VARIABLE
235 #define CANVAS_VARIABLE(var,name) canvas_colors.push_back(&var);
236 #include "canvas_vars.h"
237 #undef CANVAS_VARIABLE
238 cerr << "Configuration::pack_canvasvars () called, canvas_colors.size() = " << canvas_colors.size() << endl;