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 "export_format_selector.h"
23 #include "export_format_dialog.h"
25 #include <ardour/export_format_specification.h>
26 #include <ardour/export_profile_manager.h>
27 #include <ardour/session.h>
31 ExportFormatSelector::ExportFormatSelector () :
32 edit_button (Gtk::Stock::EDIT),
33 remove_button (Gtk::Stock::REMOVE),
34 new_button (Gtk::Stock::NEW)
36 pack_start (format_combo, true, true, 0);
37 pack_start (edit_button, false, false, 3);
38 pack_start (remove_button, false, false, 3);
39 pack_start (new_button, false, false, 3);
41 edit_button.signal_clicked().connect (sigc::hide_return (sigc::bind (sigc::mem_fun (*this, &ExportFormatSelector::open_edit_dialog), false)));
42 remove_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFormatSelector::remove_format));
43 new_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFormatSelector::add_new_format));
47 format_list = Gtk::ListStore::create (format_cols);
48 format_combo.set_model (format_list);
49 format_combo.pack_start (format_cols.label);
50 format_combo.set_active (0);
52 format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatSelector::update_format_combo));
55 ExportFormatSelector::~ExportFormatSelector ()
61 ExportFormatSelector::set_state (ARDOUR::ExportProfileManager::FormatStatePtr const state_, ARDOUR::Session * session_)
66 update_format_list ();
70 ExportFormatSelector::update_format_list ()
72 FormatPtr format_to_select = state->format;
75 if (state->list->empty()) {
76 edit_button.set_sensitive (false);
77 remove_button.set_sensitive (false);
80 edit_button.set_sensitive (true);
81 remove_button.set_sensitive (true);
84 Gtk::ListStore::iterator tree_it;
86 for (FormatList::const_iterator it = state->list->begin(); it != state->list->end(); ++it) {
87 tree_it = format_list->append();
88 tree_it->set_value (format_cols.format, *it);
89 tree_it->set_value (format_cols.label, (*it)->description());
92 if (format_combo.get_active_row_number() == -1) {
93 format_combo.set_active (0);
96 select_format (format_to_select);
100 ExportFormatSelector::select_format (FormatPtr f)
102 Gtk::TreeModel::Children::iterator it;
103 for (it = format_list->children().begin(); it != format_list->children().end(); ++it) {
104 if (it->get_value (format_cols.format) == f) {
105 format_combo.set_active (it);
110 CriticalSelectionChanged();
114 ExportFormatSelector::add_new_format ()
116 FormatPtr new_format = state->format = NewFormat (state->format);
118 if (open_edit_dialog (true) != Gtk::RESPONSE_APPLY) {
120 if (state->list->empty()) {
121 state->format.reset ();
127 ExportFormatSelector::remove_format ()
130 Gtk::TreeModel::iterator it = format_combo.get_active();
131 remove = it->get_value (format_cols.format);
132 FormatRemoved (remove);
136 ExportFormatSelector::open_edit_dialog (bool new_dialog)
138 ExportFormatDialog dialog (state->format, new_dialog);
139 dialog.set_session (session);
140 Gtk::ResponseType response = (Gtk::ResponseType) dialog.run();
141 if (response == Gtk::RESPONSE_APPLY) {
142 update_format_description ();
143 FormatEdited (state->format);
144 CriticalSelectionChanged();
150 ExportFormatSelector::update_format_combo ()
152 Gtk::TreeModel::iterator it = format_combo.get_active();
153 if (format_list->iter_is_valid (it)) {
154 state->format = it->get_value(format_cols.format);
155 } else if (!format_list->children().empty()) {
156 format_combo.set_active (0);
158 edit_button.set_sensitive (false);
159 remove_button.set_sensitive (false);
162 CriticalSelectionChanged();
166 ExportFormatSelector::update_format_description ()
168 format_combo.get_active()->set_value(format_cols.label, state->format->description());