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>
23 #include "export_filename_selector.h"
27 using namespace ARDOUR;
29 ExportFilenameSelector::ExportFilenameSelector () :
30 include_label (_("Include in Filename(s):"), Gtk::ALIGN_LEFT),
32 label_label (_("Label:"), Gtk::ALIGN_LEFT),
33 session_checkbox (_("Session Name")),
34 revision_checkbox (_("Revision:")),
36 path_label (_("Folder:"), Gtk::ALIGN_LEFT),
37 browse_button (_("Browse")),
39 example_filename_label ("", Gtk::ALIGN_LEFT)
41 pack_start (include_label, false, false, 6);
42 pack_start (include_hbox, false, false, 0);
43 pack_start (path_hbox, false, false, 12);
44 pack_start (example_filename_label, false, false, 0);
46 include_hbox.pack_start (label_label, false, false, 3);
47 include_hbox.pack_start (label_entry, false, false, 3);
48 include_hbox.pack_start (session_checkbox, false, false, 3);
49 include_hbox.pack_start (date_format_combo, false, false, 3);
50 include_hbox.pack_start (time_format_combo, false, false, 3);
51 include_hbox.pack_start (revision_checkbox, false, false, 3);
52 include_hbox.pack_start (revision_spinbutton, false, false, 3);
54 label_entry.set_activates_default ();
56 path_hbox.pack_start (path_label, false, false, 3);
57 path_hbox.pack_start (path_entry, true, true, 3);
58 path_hbox.pack_start (browse_button, false, false, 3);
60 path_entry.set_activates_default ();
62 date_format_combo.set_name ("PaddedButton");
63 time_format_combo.set_name ("PaddedButton");
64 browse_button.set_name ("PaddedButton");
66 label_sizegroup = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
67 label_sizegroup->add_widget (label_label);
68 label_sizegroup->add_widget (path_label);
72 date_format_list = Gtk::ListStore::create (date_format_cols);
73 date_format_combo.set_model (date_format_list);
74 date_format_combo.pack_start (date_format_cols.label);
76 date_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_date_format));
80 time_format_list = Gtk::ListStore::create (time_format_cols);
81 time_format_combo.set_model (time_format_list);
82 time_format_combo.pack_start (time_format_cols.label);
84 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_time_format));
88 revision_spinbutton.set_digits (0);
89 revision_spinbutton.set_increments (1, 10);
90 revision_spinbutton.set_range (1, 1000);
91 revision_spinbutton.set_sensitive (false);
95 label_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_label));
96 path_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_folder));
97 path_entry.signal_activate().connect (sigc::mem_fun (*this, &ExportFilenameSelector::check_folder), false);
99 session_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_session_selection));
101 revision_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_selection));
102 revision_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_value));
104 browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_browse_dialog));
107 ExportFilenameSelector::~ExportFilenameSelector ()
113 ExportFilenameSelector::load_state ()
119 label_entry.set_text (filename->include_label ? filename->get_label() : "");
120 session_checkbox.set_active (filename->include_session);
121 revision_checkbox.set_active (filename->include_revision);
122 revision_spinbutton.set_value (filename->get_revision());
123 path_entry.set_text (filename->get_folder());
125 Gtk::TreeModel::Children::iterator it;
127 for (it = date_format_list->children().begin(); it != date_format_list->children().end(); ++it) {
128 if (it->get_value (date_format_cols.format) == filename->get_date_format()) {
129 date_format_combo.set_active (it);
133 for (it = time_format_list->children().begin(); it != time_format_list->children().end(); ++it) {
134 if (it->get_value (time_format_cols.format) == filename->get_time_format()) {
135 time_format_combo.set_active (it);
141 ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_)
143 SessionHandlePtr::set_session (session_);
145 filename = state_->filename;
147 /* Fill combo boxes */
149 Gtk::TreeModel::iterator iter;
150 Gtk::TreeModel::Row row;
154 date_format_list->clear();
156 iter = date_format_list->append();
158 row[date_format_cols.format] = ExportFilename::D_None;
159 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_None);
161 iter = date_format_list->append();
163 row[date_format_cols.format] = ExportFilename::D_ISO;
164 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISO);
166 iter = date_format_list->append();
168 row[date_format_cols.format] = ExportFilename::D_ISOShortY;
169 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISOShortY);
171 iter = date_format_list->append();
173 row[date_format_cols.format] = ExportFilename::D_BE;
174 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BE);
176 iter = date_format_list->append();
178 row[date_format_cols.format] = ExportFilename::D_BEShortY;
179 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BEShortY);
183 time_format_list->clear();
185 iter = time_format_list->append();
187 row[time_format_cols.format] = ExportFilename::T_None;
188 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_None);
190 iter = time_format_list->append();
192 row[time_format_cols.format] = ExportFilename::T_NoDelim;
193 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_NoDelim);
195 iter = time_format_list->append();
197 row[time_format_cols.format] = ExportFilename::T_Delim;
198 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_Delim);
207 ExportFilenameSelector::set_example_filename (std::string filename)
209 if (filename == "") {
210 example_filename_label.set_text (_("Sorry, no example filename can be shown at the moment"));
212 example_filename_label.set_text (string_compose(_("Example filename: \"%1\""),
218 ExportFilenameSelector::update_label ()
224 filename->set_label (label_entry.get_text());
226 filename->include_label = !label_entry.get_text().empty();
227 CriticalSelectionChanged();
231 ExportFilenameSelector::update_folder ()
237 filename->set_folder (path_entry.get_text());
238 CriticalSelectionChanged();
242 ExportFilenameSelector::check_folder ()
248 if (!Glib::file_test (path_entry.get_text(), Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
249 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
250 The filename will be chosen from the information just above the folder selector."), path_entry.get_text()));
252 path_entry.set_text (Glib::path_get_dirname (path_entry.get_text()));
253 filename->set_folder (path_entry.get_text());
254 CriticalSelectionChanged();
259 ExportFilenameSelector::change_date_format ()
265 DateFormat format = date_format_combo.get_active()->get_value (date_format_cols.format);
266 filename->set_date_format (format);
267 CriticalSelectionChanged();
271 ExportFilenameSelector::change_time_format ()
277 TimeFormat format = time_format_combo.get_active()->get_value (time_format_cols.format);
278 filename->set_time_format (format);
279 CriticalSelectionChanged();
283 ExportFilenameSelector::change_session_selection ()
289 filename->include_session = session_checkbox.get_active();
290 CriticalSelectionChanged();
294 ExportFilenameSelector::change_revision_selection ()
300 bool selected = revision_checkbox.get_active();
301 filename->include_revision = selected;
303 revision_spinbutton.set_sensitive (selected);
304 CriticalSelectionChanged();
308 ExportFilenameSelector::change_revision_value ()
314 filename->set_revision ((uint32_t) revision_spinbutton.get_value_as_int());
315 CriticalSelectionChanged();
319 ExportFilenameSelector::open_browse_dialog ()
321 Gtk::FileChooserDialog dialog(_("Choose export folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
322 //dialog.set_transient_for(*this);
323 dialog.set_filename (path_entry.get_text());
325 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
326 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
329 int result = dialog.run();
331 if (result == Gtk::RESPONSE_OK) {
332 std::string filename = dialog.get_filename();
334 if (!Glib::file_test (filename, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
335 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
336 The filename will be chosen from the information just above the folder selector."), filename));
341 if (filename.length()) {
342 path_entry.set_text (filename);
348 CriticalSelectionChanged();