2 Copyright (C) 2008 Paul Davis
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 <gtkmm/messagedialog.h>
22 #include <gtkmm/stock.h>
24 #include "ardour/export_preset.h"
26 #include "export_preset_selector.h"
30 ExportPresetSelector::ExportPresetSelector () :
31 label (_("Preset"), Gtk::ALIGN_LEFT),
32 save_button (Gtk::Stock::SAVE),
33 remove_button (Gtk::Stock::REMOVE),
34 new_button (Gtk::Stock::NEW)
36 list = Gtk::ListStore::create (cols);
37 list->set_sort_column (cols.label, Gtk::SORT_ASCENDING);
38 entry.set_model (list);
39 entry.set_text_column (cols.label);
41 pack_start (label, false, false, 0);
42 pack_start (entry, true, true, 6);
43 pack_start (save_button, false, false, 0);
44 pack_start (remove_button, false, false, 6);
45 pack_start (new_button, false, false, 0);
47 save_button.set_sensitive (false);
48 remove_button.set_sensitive (false);
49 new_button.set_sensitive (false);
51 select_connection = entry.signal_changed().connect (sigc::mem_fun (*this, &ExportPresetSelector::update_selection));
52 save_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportPresetSelector::save_current));
53 new_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportPresetSelector::create_new));
54 remove_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportPresetSelector::remove_current));
60 ExportPresetSelector::set_manager (boost::shared_ptr<ARDOUR::ExportProfileManager> manager)
62 profile_manager = manager;
67 ExportPresetSelector::sync_with_manager ()
71 PresetList const & presets = profile_manager->get_presets();
72 Gtk::ListStore::iterator tree_it;
74 for (PresetList::const_iterator it = presets.begin(); it != presets.end(); ++it) {
75 tree_it = list->append();
76 tree_it->set_value (cols.preset, *it);
77 tree_it->set_value (cols.label, std::string ((*it)->name()));
80 select_connection.block (true);
81 entry.set_active (tree_it);
82 select_connection.block (false);
88 ExportPresetSelector::update_selection ()
90 Gtk::ListStore::iterator it = entry.get_active ();
91 std::string text = entry.get_entry()->get_text();
92 bool preset_name_exists = false;
94 for (PresetList::const_iterator it = profile_manager->get_presets().begin(); it != profile_manager->get_presets().end(); ++it) {
95 if (!(*it)->name().compare (text)) { preset_name_exists = true; }
98 if (list->iter_is_valid (it)) {
100 previous = current = it->get_value (cols.preset);
101 if (!profile_manager->load_preset (current)) {
102 Gtk::MessageDialog dialog (_("The selected preset did not load successfully!\nPerhaps it references a format that has been removed?"),
103 false, Gtk::MESSAGE_WARNING);
106 sync_with_manager ();
107 CriticalSelectionChanged();
109 /* Make an edit, so that signal changed will be emitted on re-selection */
111 select_connection.block (true);
112 entry.get_entry()->set_text ("");
113 entry.get_entry()->set_text (text);
114 select_connection.block (false);
116 } else { // Text has been edited, this should not make any changes in the profile manager
117 if (previous && !text.compare (previous->name())) {
124 save_button.set_sensitive (current != 0);
125 remove_button.set_sensitive (current != 0);
126 new_button.set_sensitive (!current && !text.empty() && !preset_name_exists);
130 ExportPresetSelector::create_new ()
132 if (!profile_manager) { return; }
134 previous = current = profile_manager->new_preset (entry.get_entry()->get_text());
135 sync_with_manager ();
136 update_selection (); // Update preset widget states
140 ExportPresetSelector::save_current ()
142 if (!profile_manager) { return; }
144 previous = current = profile_manager->save_preset (entry.get_entry()->get_text());
145 sync_with_manager ();
146 update_selection (); // Update preset widget states
150 ExportPresetSelector::remove_current ()
152 if (!profile_manager) { return; }
154 Gtk::MessageDialog dialog (_("Do you really want to remove this preset?"),
156 Gtk::MESSAGE_QUESTION,
157 Gtk::BUTTONS_YES_NO);
159 if (Gtk::RESPONSE_YES != dialog.run ()) {
160 /* User has selected "no" or closed the dialog, better
166 profile_manager->remove_preset();
167 entry.get_entry()->set_text ("");
168 sync_with_manager ();