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 "pbd/openuri.h"
24 #include "export_filename_selector.h"
28 using namespace ARDOUR;
30 ExportFilenameSelector::ExportFilenameSelector () :
31 include_label ("", Gtk::ALIGN_LEFT),
33 label_label (_("Label:"), Gtk::ALIGN_LEFT),
34 timespan_checkbox (_("Timespan Name")),
35 revision_checkbox (_("Revision:")),
37 path_label (_("Folder:"), Gtk::ALIGN_LEFT),
38 browse_button (_("Browse")),
39 open_button (_("Open Folder")),
41 example_filename_label ("", Gtk::ALIGN_LEFT),
42 _require_timespan (false)
44 include_label.set_markup (_("Build filename(s) from these components:"));
46 session_snap_name.append_text (_("No Name"));
47 session_snap_name.append_text (_("Session Name"));
48 session_snap_name.append_text (_("Snapshot Name"));
49 session_snap_name.set_active (0);
51 pack_start (path_hbox, false, false, 12);
52 pack_start (include_label, false, false, 6);
53 pack_start (include_hbox, false, false, 0);
54 pack_start (example_filename_label, false, false, 12);
56 include_hbox.pack_start (session_snap_name, false, false, 3);
57 include_hbox.pack_start (label_label, false, false, 3);
58 include_hbox.pack_start (label_entry, false, false, 3);
59 include_hbox.pack_start (revision_checkbox, false, false, 3);
60 include_hbox.pack_start (revision_spinbutton, false, false, 3);
61 include_hbox.pack_start (timespan_checkbox, false, false, 3);
62 include_hbox.pack_start (date_format_combo, false, false, 3);
63 include_hbox.pack_start (time_format_combo, false, false, 3);
65 label_entry.set_activates_default ();
67 path_hbox.pack_start (path_label, false, false, 3);
68 path_hbox.pack_start (path_entry, true, true, 3);
69 path_hbox.pack_start (browse_button, false, false, 3);
70 path_hbox.pack_start (open_button, false, false, 3); // maybe Mixbus only ?
72 path_entry.set_activates_default ();
74 label_sizegroup = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
75 label_sizegroup->add_widget (label_label);
76 label_sizegroup->add_widget (path_label);
80 date_format_list = Gtk::ListStore::create (date_format_cols);
81 date_format_combo.set_model (date_format_list);
82 date_format_combo.pack_start (date_format_cols.label);
84 date_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_date_format));
88 time_format_list = Gtk::ListStore::create (time_format_cols);
89 time_format_combo.set_model (time_format_list);
90 time_format_combo.pack_start (time_format_cols.label);
92 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_time_format));
96 revision_spinbutton.set_digits (0);
97 revision_spinbutton.set_increments (1, 10);
98 revision_spinbutton.set_range (1, 1000);
99 revision_spinbutton.set_sensitive (false);
103 label_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_label));
104 path_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_folder));
105 path_entry.signal_activate().connect (sigc::mem_fun (*this, &ExportFilenameSelector::check_folder), false);
107 session_snap_name.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_session_selection));
108 timespan_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_timespan_selection));
110 revision_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_selection));
111 revision_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_value));
113 browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_browse_dialog));
114 open_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_folder));
117 ExportFilenameSelector::~ExportFilenameSelector ()
123 ExportFilenameSelector::load_state ()
129 label_entry.set_text (filename->include_label ? filename->get_label() : "");
130 if (filename->include_session) {
131 if (filename->use_session_snapshot_name) {
132 session_snap_name.set_active (2);
134 session_snap_name.set_active (1);
137 session_snap_name.set_active (0);
139 timespan_checkbox.set_active (filename->include_timespan);
140 revision_checkbox.set_active (filename->include_revision);
141 revision_spinbutton.set_value (filename->get_revision());
142 path_entry.set_text (filename->get_folder());
144 Gtk::TreeModel::Children::iterator it;
146 for (it = date_format_list->children().begin(); it != date_format_list->children().end(); ++it) {
147 if (it->get_value (date_format_cols.format) == filename->get_date_format()) {
148 date_format_combo.set_active (it);
152 for (it = time_format_list->children().begin(); it != time_format_list->children().end(); ++it) {
153 if (it->get_value (time_format_cols.format) == filename->get_time_format()) {
154 time_format_combo.set_active (it);
160 ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_)
162 SessionHandlePtr::set_session (session_);
164 filename = state_->filename;
166 /* Fill combo boxes */
168 Gtk::TreeModel::iterator iter;
169 Gtk::TreeModel::Row row;
173 date_format_list->clear();
175 iter = date_format_list->append();
177 row[date_format_cols.format] = ExportFilename::D_None;
178 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_None);
180 iter = date_format_list->append();
182 row[date_format_cols.format] = ExportFilename::D_ISO;
183 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISO);
185 iter = date_format_list->append();
187 row[date_format_cols.format] = ExportFilename::D_ISOShortY;
188 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISOShortY);
190 iter = date_format_list->append();
192 row[date_format_cols.format] = ExportFilename::D_BE;
193 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BE);
195 iter = date_format_list->append();
197 row[date_format_cols.format] = ExportFilename::D_BEShortY;
198 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BEShortY);
202 time_format_list->clear();
204 iter = time_format_list->append();
206 row[time_format_cols.format] = ExportFilename::T_None;
207 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_None);
209 iter = time_format_list->append();
211 row[time_format_cols.format] = ExportFilename::T_NoDelim;
212 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_NoDelim);
214 iter = time_format_list->append();
216 row[time_format_cols.format] = ExportFilename::T_Delim;
217 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_Delim);
226 ExportFilenameSelector::set_example_filename (std::string filename)
228 if (filename == "") {
229 example_filename_label.set_markup (_("<small><i>Sorry, no example filename can be shown at the moment</i></small>"));
231 example_filename_label.set_markup (string_compose(_("<i>Current (approximate) filename</i>: \"%1\""), filename));
236 ExportFilenameSelector::update_label ()
242 filename->set_label (label_entry.get_text());
244 filename->include_label = !label_entry.get_text().empty();
245 CriticalSelectionChanged();
249 ExportFilenameSelector::update_folder ()
255 filename->set_folder (path_entry.get_text());
256 CriticalSelectionChanged();
260 ExportFilenameSelector::check_folder ()
266 if (!Glib::file_test (path_entry.get_text(), Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
267 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
268 The filename will be chosen from the information just above the folder selector."), path_entry.get_text()));
270 path_entry.set_text (Glib::path_get_dirname (path_entry.get_text()));
271 filename->set_folder (path_entry.get_text());
272 CriticalSelectionChanged();
277 ExportFilenameSelector::change_date_format ()
283 DateFormat format = date_format_combo.get_active()->get_value (date_format_cols.format);
284 filename->set_date_format (format);
285 CriticalSelectionChanged();
289 ExportFilenameSelector::change_time_format ()
295 TimeFormat format = time_format_combo.get_active()->get_value (time_format_cols.format);
296 filename->set_time_format (format);
297 CriticalSelectionChanged();
301 ExportFilenameSelector::require_timespan (bool r)
303 _require_timespan = r;
304 update_timespan_sensitivity ();
308 ExportFilenameSelector::update_timespan_sensitivity ()
310 bool implicit = _require_timespan;
313 && !filename->include_session
314 && !filename->include_label
315 && !filename->include_revision
316 && !filename->include_channel_config
317 && !filename->include_channel
318 && !filename->include_date
319 && !filename->include_format_name) {
323 // remember prev state, force enable if implicit active.
324 if (implicit && !timespan_checkbox.get_inconsistent()) {
325 timespan_checkbox.set_inconsistent (true);
326 filename->include_timespan = true;
328 else if (!implicit && timespan_checkbox.get_inconsistent()) {
329 filename->include_timespan = timespan_checkbox.get_active();
330 timespan_checkbox.set_inconsistent (false);
336 ExportFilenameSelector::change_timespan_selection ()
341 if (timespan_checkbox.get_inconsistent()) {
345 filename->include_timespan = timespan_checkbox.get_active();
346 CriticalSelectionChanged();
350 ExportFilenameSelector::change_session_selection ()
356 switch (session_snap_name.get_active_row_number ()) {
358 filename->include_session = true;
359 filename->use_session_snapshot_name = false;
362 filename->include_session = true;
363 filename->use_session_snapshot_name = true;
366 filename->include_session = false;
367 filename->use_session_snapshot_name = false;
370 CriticalSelectionChanged();
374 ExportFilenameSelector::change_revision_selection ()
380 bool selected = revision_checkbox.get_active();
381 filename->include_revision = selected;
383 revision_spinbutton.set_sensitive (selected);
384 CriticalSelectionChanged();
388 ExportFilenameSelector::change_revision_value ()
394 filename->set_revision ((uint32_t) revision_spinbutton.get_value_as_int());
395 CriticalSelectionChanged();
399 ExportFilenameSelector::open_folder ()
401 const std::string& dir (path_entry.get_text());
402 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
403 Gtk::MessageDialog msg (string_compose (_("%1: this is not a valid directory/folder."), dir));
407 PBD::open_folder (dir);
411 ExportFilenameSelector::open_browse_dialog ()
413 Gtk::FileChooserDialog dialog(_("Choose export folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
414 //dialog.set_transient_for(*this);
415 dialog.set_filename (path_entry.get_text());
417 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
418 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
421 int result = dialog.run();
423 if (result == Gtk::RESPONSE_OK) {
424 std::string filename = dialog.get_filename();
426 if (!Glib::file_test (filename, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
427 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
428 The filename will be chosen from the information just above the folder selector."), filename));
433 if (filename.length()) {
434 path_entry.set_text (filename);
441 CriticalSelectionChanged();