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/filechooserdialog.h>
22 #include <gtkmm/messagedialog.h>
23 #include <gtkmm/stock.h>
25 #include "pbd/openuri.h"
27 #include "gtkmm2ext/utils.h"
29 #include "export_filename_selector.h"
33 using namespace ARDOUR;
35 ExportFilenameSelector::ExportFilenameSelector () :
36 include_label ("", Gtk::ALIGN_LEFT),
38 label_label (_("Label:"), Gtk::ALIGN_LEFT),
39 timespan_checkbox (_("Timespan Name")),
40 revision_checkbox (_("Revision:")),
42 path_label (_("Folder:"), Gtk::ALIGN_LEFT),
43 browse_button (_("Browse")),
44 open_button (_("Open Folder")),
46 example_filename_label ("", Gtk::ALIGN_LEFT),
47 _require_timespan (false)
49 include_label.set_markup (_("Build filename(s) from these components:"));
51 session_snap_name.append_text (_("No Name"));
52 session_snap_name.append_text (_("Session Name"));
53 session_snap_name.append_text (_("Snapshot Name"));
54 session_snap_name.set_active (0);
56 pack_start (path_hbox, false, false, 12);
57 pack_start (include_label, false, false, 6);
58 pack_start (include_hbox, false, false, 0);
59 pack_start (example_filename_label, false, false, 12);
61 include_hbox.pack_start (session_snap_name, false, false, 3);
62 include_hbox.pack_start (label_label, false, false, 3);
63 include_hbox.pack_start (label_entry, false, false, 3);
64 include_hbox.pack_start (revision_checkbox, false, false, 3);
65 include_hbox.pack_start (revision_spinbutton, false, false, 3);
66 include_hbox.pack_start (timespan_checkbox, false, false, 3);
67 include_hbox.pack_start (date_format_combo, false, false, 3);
68 include_hbox.pack_start (time_format_combo, false, false, 3);
70 label_entry.set_activates_default ();
72 path_hbox.pack_start (path_label, false, false, 3);
73 path_hbox.pack_start (path_entry, true, true, 3);
74 path_hbox.pack_start (browse_button, false, false, 3);
75 path_hbox.pack_start (open_button, false, false, 3); // maybe Mixbus only ?
77 path_entry.set_activates_default ();
79 label_sizegroup = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
80 label_sizegroup->add_widget (label_label);
81 label_sizegroup->add_widget (path_label);
85 date_format_list = Gtk::ListStore::create (date_format_cols);
86 date_format_combo.set_model (date_format_list);
87 date_format_combo.pack_start (date_format_cols.label);
89 date_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_date_format));
93 time_format_list = Gtk::ListStore::create (time_format_cols);
94 time_format_combo.set_model (time_format_list);
95 time_format_combo.pack_start (time_format_cols.label);
97 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_time_format));
101 revision_spinbutton.set_digits (0);
102 revision_spinbutton.set_increments (1, 10);
103 revision_spinbutton.set_range (1, 1000);
104 revision_spinbutton.set_sensitive (false);
108 label_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_label));
109 path_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_folder));
110 path_entry.signal_activate().connect (sigc::mem_fun (*this, &ExportFilenameSelector::check_folder), false);
112 session_snap_name.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_session_selection));
113 timespan_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_timespan_selection));
115 revision_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_selection));
116 revision_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_value));
118 browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_browse_dialog));
119 open_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_folder));
122 ExportFilenameSelector::~ExportFilenameSelector ()
128 ExportFilenameSelector::load_state ()
134 label_entry.set_text (filename->include_label ? filename->get_label() : "");
135 if (filename->include_session) {
136 if (filename->use_session_snapshot_name) {
137 session_snap_name.set_active (2);
139 session_snap_name.set_active (1);
142 session_snap_name.set_active (0);
144 timespan_checkbox.set_active (filename->include_timespan);
145 revision_checkbox.set_active (filename->include_revision);
146 revision_spinbutton.set_value (filename->get_revision());
147 path_entry.set_text (filename->get_folder());
149 Gtk::TreeModel::Children::iterator it;
151 for (it = date_format_list->children().begin(); it != date_format_list->children().end(); ++it) {
152 if (it->get_value (date_format_cols.format) == filename->get_date_format()) {
153 date_format_combo.set_active (it);
157 for (it = time_format_list->children().begin(); it != time_format_list->children().end(); ++it) {
158 if (it->get_value (time_format_cols.format) == filename->get_time_format()) {
159 time_format_combo.set_active (it);
165 ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_)
167 SessionHandlePtr::set_session (session_);
169 filename = state_->filename;
171 /* Fill combo boxes */
173 Gtk::TreeModel::iterator iter;
174 Gtk::TreeModel::Row row;
178 date_format_list->clear();
180 iter = date_format_list->append();
182 row[date_format_cols.format] = ExportFilename::D_None;
183 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_None);
185 iter = date_format_list->append();
187 row[date_format_cols.format] = ExportFilename::D_ISO;
188 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISO);
190 iter = date_format_list->append();
192 row[date_format_cols.format] = ExportFilename::D_ISOShortY;
193 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISOShortY);
195 iter = date_format_list->append();
197 row[date_format_cols.format] = ExportFilename::D_BE;
198 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BE);
200 iter = date_format_list->append();
202 row[date_format_cols.format] = ExportFilename::D_BEShortY;
203 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BEShortY);
207 time_format_list->clear();
209 iter = time_format_list->append();
211 row[time_format_cols.format] = ExportFilename::T_None;
212 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_None);
214 iter = time_format_list->append();
216 row[time_format_cols.format] = ExportFilename::T_NoDelim;
217 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_NoDelim);
219 iter = time_format_list->append();
221 row[time_format_cols.format] = ExportFilename::T_Delim;
222 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_Delim);
231 ExportFilenameSelector::set_example_filename (std::string filename)
233 if (filename == "") {
234 example_filename_label.set_markup (_("<small><i>Sorry, no example filename can be shown at the moment</i></small>"));
236 example_filename_label.set_markup (string_compose(_("<i>Current (approximate) filename</i>: \"%1\""), filename));
241 ExportFilenameSelector::update_label ()
247 filename->set_label (label_entry.get_text());
249 filename->include_label = !label_entry.get_text().empty();
250 CriticalSelectionChanged();
254 ExportFilenameSelector::update_folder ()
260 filename->set_folder (path_entry.get_text());
261 CriticalSelectionChanged();
265 ExportFilenameSelector::check_folder ()
271 if (!Glib::file_test (path_entry.get_text(), Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
272 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
273 The filename will be chosen from the information just above the folder selector."), path_entry.get_text()));
275 path_entry.set_text (Glib::path_get_dirname (path_entry.get_text()));
276 filename->set_folder (path_entry.get_text());
277 CriticalSelectionChanged();
282 ExportFilenameSelector::change_date_format ()
288 DateFormat format = date_format_combo.get_active()->get_value (date_format_cols.format);
289 filename->set_date_format (format);
290 CriticalSelectionChanged();
294 ExportFilenameSelector::change_time_format ()
300 TimeFormat format = time_format_combo.get_active()->get_value (time_format_cols.format);
301 filename->set_time_format (format);
302 CriticalSelectionChanged();
306 ExportFilenameSelector::require_timespan (bool r)
308 _require_timespan = r;
309 update_timespan_sensitivity ();
313 ExportFilenameSelector::update_timespan_sensitivity ()
315 bool implicit = _require_timespan;
318 && !filename->include_session
319 && !filename->include_label
320 && !filename->include_revision
321 && !filename->include_channel_config
322 && !filename->include_channel
323 && !filename->include_date
324 && !filename->include_format_name) {
328 // remember prev state, force enable if implicit active.
329 if (implicit && !timespan_checkbox.get_inconsistent()) {
330 timespan_checkbox.set_inconsistent (true);
331 filename->include_timespan = true;
333 else if (!implicit && timespan_checkbox.get_inconsistent()) {
334 filename->include_timespan = timespan_checkbox.get_active();
335 timespan_checkbox.set_inconsistent (false);
341 ExportFilenameSelector::change_timespan_selection ()
346 if (timespan_checkbox.get_inconsistent()) {
350 filename->include_timespan = timespan_checkbox.get_active();
351 CriticalSelectionChanged();
355 ExportFilenameSelector::change_session_selection ()
361 switch (session_snap_name.get_active_row_number ()) {
363 filename->include_session = true;
364 filename->use_session_snapshot_name = false;
367 filename->include_session = true;
368 filename->use_session_snapshot_name = true;
371 filename->include_session = false;
372 filename->use_session_snapshot_name = false;
375 CriticalSelectionChanged();
379 ExportFilenameSelector::change_revision_selection ()
385 bool selected = revision_checkbox.get_active();
386 filename->include_revision = selected;
388 revision_spinbutton.set_sensitive (selected);
389 CriticalSelectionChanged();
393 ExportFilenameSelector::change_revision_value ()
399 filename->set_revision ((uint32_t) revision_spinbutton.get_value_as_int());
400 CriticalSelectionChanged();
404 ExportFilenameSelector::open_folder ()
406 const std::string& dir (path_entry.get_text());
407 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
408 Gtk::MessageDialog msg (string_compose (_("%1: this is not a valid directory/folder."), dir));
412 PBD::open_folder (dir);
416 ExportFilenameSelector::open_browse_dialog ()
418 Gtk::FileChooserDialog dialog(_("Choose export folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
419 Gtkmm2ext::add_volume_shortcuts (dialog);
420 //dialog.set_transient_for(*this);
421 dialog.set_filename (path_entry.get_text());
423 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
424 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
427 int result = dialog.run();
429 if (result == Gtk::RESPONSE_OK) {
430 std::string filename = dialog.get_filename();
432 if (!Glib::file_test (filename, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
433 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
434 The filename will be chosen from the information just above the folder selector."), filename));
439 if (filename.length()) {
440 path_entry.set_text (filename);
447 CriticalSelectionChanged();