2 Copyright (C) 2001-2009 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 <gtkmm/box.h>
21 #include <gtkmm/alignment.h>
22 #include "ardour/configuration.h"
23 #include "option_editor.h"
24 #include "gui_thread.h"
29 using namespace ARDOUR;
32 OptionEditorComponent::add_widget_to_page (OptionEditorPage* p, Gtk::Widget* w)
34 int const n = p->table.property_n_rows();
35 p->table.resize (n + 1, 3);
36 p->table.attach (*w, 1, 3, n, n + 1, FILL | EXPAND);
40 OptionEditorComponent::add_widgets_to_page (OptionEditorPage* p, Gtk::Widget* wa, Gtk::Widget* wb)
42 int const n = p->table.property_n_rows();
43 p->table.resize (n + 1, 3);
44 p->table.attach (*wa, 1, 2, n, n + 1, FILL);
45 p->table.attach (*wb, 2, 3, n, n + 1, FILL | EXPAND);
48 OptionEditorHeading::OptionEditorHeading (string const & h)
51 s << "<b>" << h << "</b>";
52 _label = manage (new Label (s.str()));
53 _label->set_alignment (0, 0.5);
54 _label->set_use_markup (true);
58 OptionEditorHeading::add_to_page (OptionEditorPage* p)
60 int const n = p->table.property_n_rows();
61 p->table.resize (n + 2, 3);
63 p->table.attach (*manage (new Label ("")), 0, 3, n, n + 1, FILL | EXPAND);
64 p->table.attach (*_label, 0, 3, n + 1, n + 2, FILL | EXPAND);
68 OptionEditorBox::add_to_page (OptionEditorPage* p)
70 add_widget_to_page (p, _box);
73 BoolOption::BoolOption (string const & i, string const & n, sigc::slot<bool> g, sigc::slot<bool, bool> s)
78 _button = manage (new CheckButton (n));
79 _button->set_active (_get ());
80 _button->signal_toggled().connect (sigc::mem_fun (*this, &BoolOption::toggled));
84 BoolOption::add_to_page (OptionEditorPage* p)
86 add_widget_to_page (p, _button);
90 BoolOption::set_state_from_config ()
92 _button->set_active (_get ());
96 BoolOption::toggled ()
98 _set (_button->get_active ());
101 EntryOption::EntryOption (string const & i, string const & n, sigc::slot<string> g, sigc::slot<bool, string> s)
106 _label = manage (new Label (n + ":"));
107 _label->set_alignment (1, 0.5);
108 _entry = manage (new Entry);
109 _entry->signal_activate().connect (sigc::mem_fun (*this, &EntryOption::activated));
113 EntryOption::add_to_page (OptionEditorPage* p)
115 add_widgets_to_page (p, _label, _entry);
119 EntryOption::set_state_from_config ()
121 _entry->set_text (_get ());
125 EntryOption::activated ()
127 _set (_entry->get_text ());
130 OptionEditorPage::OptionEditorPage (Gtk::Notebook& n, std::string const & t)
133 table.set_spacings (4);
134 table.set_col_spacing (0, 32);
135 box.pack_start (table, false, false);
136 box.set_border_width (4);
137 n.append_page (box, t);
140 /** Construct an OptionEditor.
141 * @param o Configuration to edit.
142 * @param t Title for the dialog.
144 OptionEditor::OptionEditor (Configuration* c, std::string const & t)
145 : ArdourDialog (t, false), _config (c)
147 using namespace Notebook_Helpers;
149 set_default_size (300, 300);
150 set_wmclass (X_("ardour_preferences"), "Ardour");
152 set_name ("Preferences");
153 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
155 set_border_width (4);
157 get_vbox()->set_spacing (4);
158 get_vbox()->pack_start (_notebook);
160 _notebook.set_show_tabs (true);
161 _notebook.set_show_border (true);
162 _notebook.set_name ("OptionsNotebook");
166 /* Watch out for changes to parameters */
167 _config->ParameterChanged.connect (config_connection, invalidator (*this), ui_bind (&OptionEditor::parameter_changed, this, _1), gui_context());
170 OptionEditor::~OptionEditor ()
172 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
173 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
180 /** Called when a configuration parameter has been changed.
181 * @param p Parameter name.
184 OptionEditor::parameter_changed (std::string const & p)
186 ENSURE_GUI_THREAD (*this, &OptionEditor::parameter_changed, p)
188 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
189 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
190 (*j)->parameter_changed (p);
195 /** Add a component to a given page.
196 * @param pn Page name (will be created if it doesn't already exist)
197 * @param o Component.
200 OptionEditor::add_option (std::string const & pn, OptionEditorComponent* o)
202 if (_pages.find (pn) == _pages.end()) {
203 _pages[pn] = new OptionEditorPage (_notebook, pn);
206 OptionEditorPage* p = _pages[pn];
207 p->components.push_back (o);
210 o->set_state_from_config ();