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_file_notebook.h"
23 #include "ardour/export_format_specification.h"
25 #include "gui_thread.h"
29 using namespace ARDOUR;
32 ExportFileNotebook::ExportFileNotebook () :
37 new_file_button.set_image (*Gtk::manage (new Gtk::Image (::get_icon("add"))));
38 new_file_button.set_label (_("Add another format"));
39 new_file_button.set_alignment (0, 0.5);
40 new_file_button.set_relief (Gtk::RELIEF_NONE);
42 new_file_hbox.pack_start (new_file_button, true, true);
43 append_page (new_file_dummy, new_file_hbox);
44 set_tab_label_packing (new_file_dummy, true, true, Gtk::PACK_START);
45 new_file_hbox.show_all_children ();
47 page_change_connection = signal_switch_page().connect (sigc::mem_fun (*this, &ExportFileNotebook::handle_page_change));
48 new_file_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFileNotebook::add_new_file_page));
52 ExportFileNotebook::set_session_and_manager (ARDOUR::Session * s, boost::shared_ptr<ARDOUR::ExportProfileManager> manager)
54 SessionHandlePtr::set_session (s);
55 profile_manager = manager;
61 ExportFileNotebook::sync_with_manager ()
63 /* Clear pages from notebook
64 The page switch handling has to be disabled during removing all pages due to a gtk bug
67 page_change_connection.block();
68 while (get_n_pages() > 1) {
71 page_change_connection.block(false);
74 last_visible_page = 0;
78 ExportProfileManager::FormatStateList const & formats = profile_manager->get_formats ();
79 ExportProfileManager::FormatStateList::const_iterator format_it;
80 ExportProfileManager::FilenameStateList const & filenames = profile_manager->get_filenames ();
81 ExportProfileManager::FilenameStateList::const_iterator filename_it;
82 for (format_it = formats.begin(), filename_it = filenames.begin();
83 format_it != formats.end() && filename_it != filenames.end();
84 ++format_it, ++filename_it) {
85 add_file_page (*format_it, *filename_it);
89 CriticalSelectionChanged ();
93 ExportFileNotebook::update_example_filenames()
97 while ((page = dynamic_cast<FilePage *> (get_nth_page (i++)))) {
98 page->update_example_filename();
103 ExportFileNotebook::get_nth_format_name (uint32_t n)
106 if ((page = dynamic_cast<FilePage *> (get_nth_page (n - 1)))) {
107 return page->get_format_name();
113 ExportFileNotebook::add_new_file_page ()
116 if ((page = dynamic_cast<FilePage *> (get_nth_page (get_current_page())))) {
117 add_file_page (profile_manager->duplicate_format_state (page->get_format_state()),
118 profile_manager->duplicate_filename_state (page->get_filename_state()));
123 ExportFileNotebook::add_file_page (ARDOUR::ExportProfileManager::FormatStatePtr format_state, ARDOUR::ExportProfileManager::FilenameStatePtr filename_state)
125 FilePage * page = Gtk::manage (new FilePage (_session, profile_manager, this, page_counter, format_state, filename_state));
126 page->CriticalSelectionChanged.connect (CriticalSelectionChanged.make_slot());
127 insert_page (*page, page->get_tab_widget(), get_n_pages() - 1);
129 update_remove_file_page_sensitivity ();
133 CriticalSelectionChanged ();
137 ExportFileNotebook::remove_file_page (FilePage * page)
139 profile_manager->remove_format_state (page->get_format_state());
140 profile_manager->remove_filename_state (page->get_filename_state());
143 update_remove_file_page_sensitivity ();
145 CriticalSelectionChanged ();
149 ExportFileNotebook::update_remove_file_page_sensitivity ()
152 if ((page = dynamic_cast<FilePage *> (get_nth_page (0)))) {
153 if (get_n_pages() > 2) {
154 page->set_remove_sensitive (true);
156 page->set_remove_sensitive (false);
162 ExportFileNotebook::handle_page_change (GtkNotebookPage*, uint32_t page)
164 if (page + 1 == (uint32_t) get_n_pages()) {
165 set_current_page (last_visible_page);
167 last_visible_page = page;
171 ExportFileNotebook::FilePage::FilePage (Session * s, ManagerPtr profile_manager, ExportFileNotebook * parent, uint32_t number,
172 ExportProfileManager::FormatStatePtr format_state,
173 ExportProfileManager::FilenameStatePtr filename_state) :
174 format_state (format_state),
175 filename_state (filename_state),
176 profile_manager (profile_manager),
178 format_label (_("Format"), Gtk::ALIGN_LEFT),
179 filename_label (_("Location"), Gtk::ALIGN_LEFT),
182 set_border_width (12);
184 pack_start (format_label, false, false, 0);
185 pack_start (format_align, false, false, 0);
186 pack_start (filename_label, false, false, 0);
187 pack_start (filename_align, false, false, 0);
189 format_align.add (format_selector);
190 format_align.set_padding (6, 12, 18, 0);
192 filename_align.add (filename_selector);
193 filename_align.set_padding (0, 12, 18, 0);
195 Pango::AttrList bold;
196 Pango::Attribute b = Pango::Attribute::create_attr_weight (Pango::WEIGHT_BOLD);
199 format_label.set_attributes (bold);
200 filename_label.set_attributes (bold);
201 tab_label.set_attributes (bold);
204 format_selector.set_state (format_state, s);
205 filename_selector.set_state (filename_state, s);
209 tab_close_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*parent, &ExportFileNotebook::remove_file_page), this));
211 profile_manager->FormatListChanged.connect (format_connection, invalidator (*this), boost::bind (&ExportFormatSelector::update_format_list, &format_selector), gui_context());
213 format_selector.FormatEdited.connect (sigc::mem_fun (*this, &ExportFileNotebook::FilePage::save_format_to_manager));
214 format_selector.FormatRemoved.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::remove_format_profile));
215 format_selector.NewFormat.connect (sigc::mem_fun (*profile_manager, &ExportProfileManager::get_new_format));
217 format_selector.CriticalSelectionChanged.connect (
218 sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed));
219 filename_selector.CriticalSelectionChanged.connect (
220 sigc::mem_fun (*this, &ExportFileNotebook::FilePage::critical_selection_changed));
224 tab_close_button.add (*Gtk::manage (new Gtk::Image (::get_icon("close"))));
225 tab_close_alignment.add (tab_close_button);
226 tab_close_alignment.set (0.5, 0.5, 0, 0);
228 tab_widget.pack_start (tab_label, false, false, 3);
229 tab_widget.pack_end (tab_close_alignment, false, false, 0);
230 tab_widget.show_all_children ();
232 update_example_filename();
236 show_all_children ();
239 ExportFileNotebook::FilePage::~FilePage ()
244 ExportFileNotebook::FilePage::set_remove_sensitive (bool value)
246 tab_close_button.set_sensitive (value);
250 ExportFileNotebook::FilePage::get_format_name () const
252 if (format_state && format_state->format) {
253 return format_state->format->name();
255 return _("No format!");
259 ExportFileNotebook::FilePage::save_format_to_manager (FormatPtr format)
261 profile_manager->save_format_to_disk (format);
265 ExportFileNotebook::FilePage::update_tab_label ()
267 tab_label.set_text (string_compose (_("Format %1: %2"), tab_number, get_format_name()));
271 ExportFileNotebook::FilePage::update_example_filename()
273 if (profile_manager) {
276 if (format_state->format) {
277 example = profile_manager->get_sample_filename_for_format (
278 filename_state->filename, format_state->format);
282 filename_selector.set_example_filename(Glib::path_get_basename (example));
284 filename_selector.set_example_filename("");
290 ExportFileNotebook::FilePage::critical_selection_changed ()
293 update_example_filename();
294 CriticalSelectionChanged();