somewhat illogical and temporary workaround to the problems with consolidate & bounce...
[ardour2.git] / gtk2_ardour / export_preset_selector.cc
blob3898916bc05899d767ec871c5a8accf20ad62f97
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "export_preset_selector.h"
23 #include "ardour/export_preset.h"
25 #include "i18n.h"
27 ExportPresetSelector::ExportPresetSelector () :
28 label (_("Preset"), Gtk::ALIGN_LEFT),
29 save_button (Gtk::Stock::SAVE),
30 remove_button (Gtk::Stock::REMOVE),
31 new_button (Gtk::Stock::NEW)
33 list = Gtk::ListStore::create (cols);
34 list->set_sort_column (cols.label, Gtk::SORT_ASCENDING);
35 entry.set_model (list);
36 entry.set_text_column (cols.label);
38 pack_start (label, false, false, 0);
39 pack_start (entry, true, true, 6);
40 pack_start (save_button, false, false, 0);
41 pack_start (remove_button, false, false, 6);
42 pack_start (new_button, false, false, 0);
44 entry.set_name ("PaddedButton");
45 save_button.set_name ("PaddedButton");
46 remove_button.set_name ("PaddedButton");
47 new_button.set_name ("PaddedButton");
49 save_button.set_sensitive (false);
50 remove_button.set_sensitive (false);
51 new_button.set_sensitive (false);
53 select_connection = entry.signal_changed().connect (sigc::mem_fun (*this, &ExportPresetSelector::update_selection));
54 save_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportPresetSelector::save_current));
55 new_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportPresetSelector::create_new));
56 remove_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportPresetSelector::remove_current));
58 show_all_children ();
61 void
62 ExportPresetSelector::set_manager (boost::shared_ptr<ARDOUR::ExportProfileManager> manager)
64 profile_manager = manager;
65 sync_with_manager ();
68 void
69 ExportPresetSelector::sync_with_manager ()
71 list->clear();
73 PresetList const & presets = profile_manager->get_presets();
74 Gtk::ListStore::iterator tree_it;
76 for (PresetList::const_iterator it = presets.begin(); it != presets.end(); ++it) {
77 tree_it = list->append();
78 tree_it->set_value (cols.preset, *it);
79 tree_it->set_value (cols.label, std::string ((*it)->name()));
81 if (*it == current) {
82 select_connection.block (true);
83 entry.set_active (tree_it);
84 select_connection.block (false);
89 void
90 ExportPresetSelector::update_selection ()
92 Gtk::ListStore::iterator it = entry.get_active ();
93 std::string text = entry.get_entry()->get_text();
94 bool preset_name_exists = false;
96 for (PresetList::const_iterator it = profile_manager->get_presets().begin(); it != profile_manager->get_presets().end(); ++it) {
97 if (!(*it)->name().compare (text)) { preset_name_exists = true; }
100 if (list->iter_is_valid (it)) {
102 previous = current = it->get_value (cols.preset);
103 if (!profile_manager->load_preset (current)) {
104 Gtk::MessageDialog dialog (_("The selected preset did not load successfully!\nPerhaps it references a format that has been removed?"),
105 false, Gtk::MESSAGE_WARNING);
106 dialog.run ();
108 sync_with_manager ();
109 CriticalSelectionChanged();
111 /* Make an edit, so that signal changed will be emitted on re-selection */
113 select_connection.block (true);
114 entry.get_entry()->set_text ("");
115 entry.get_entry()->set_text (text);
116 select_connection.block (false);
118 } else { // Text has been edited, this should not make any changes in the profile manager
119 if (previous && !text.compare (previous->name())) {
120 current = previous;
121 } else {
122 current.reset ();
126 save_button.set_sensitive (current);
127 remove_button.set_sensitive (current);
128 new_button.set_sensitive (!current && !text.empty() && !preset_name_exists);
131 void
132 ExportPresetSelector::create_new ()
134 if (!profile_manager) { return; }
136 previous = current = profile_manager->new_preset (entry.get_entry()->get_text());
137 sync_with_manager ();
138 update_selection (); // Update preset widget states
141 void
142 ExportPresetSelector::save_current ()
144 if (!profile_manager) { return; }
146 previous = current = profile_manager->save_preset (entry.get_entry()->get_text());
147 sync_with_manager ();
148 update_selection (); // Update preset widget states
151 void
152 ExportPresetSelector::remove_current ()
154 if (!profile_manager) { return; }
156 profile_manager->remove_preset();
157 entry.get_entry()->set_text ("");
158 sync_with_manager ();