2 * Copyright (C) 2008-2012 Sakari Bergen <sakari.bergen@beatwaves.net>
3 * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5 * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <gtkmm/filechooserdialog.h>
23 #include <gtkmm/messagedialog.h>
24 #include <gtkmm/stock.h>
26 #include "pbd/openuri.h"
28 #include "gtkmm2ext/utils.h"
30 #include "export_filename_selector.h"
34 using namespace ARDOUR;
36 ExportFilenameSelector::ExportFilenameSelector () :
37 include_label ("", Gtk::ALIGN_LEFT),
39 label_label (_("Label:"), Gtk::ALIGN_LEFT),
40 timespan_checkbox (_("Timespan Name")),
41 revision_checkbox (_("Revision:")),
43 path_label (_("Folder:"), Gtk::ALIGN_LEFT),
44 browse_button (_("Browse")),
45 open_button (_("Open Folder")),
47 example_filename_label ("", Gtk::ALIGN_LEFT),
48 _require_timespan (false)
50 include_label.set_markup (_("Build filename(s) from these components:"));
52 session_snap_name.append_text (_("No Name"));
53 session_snap_name.append_text (_("Session Name"));
54 session_snap_name.append_text (_("Snapshot Name"));
55 session_snap_name.set_active (0);
57 pack_start (path_hbox, false, false, 12);
58 pack_start (include_label, false, false, 6);
59 pack_start (include_hbox, false, false, 0);
60 pack_start (example_filename_label, false, false, 12);
62 include_hbox.pack_start (session_snap_name, false, false, 3);
63 include_hbox.pack_start (label_label, false, false, 3);
64 include_hbox.pack_start (label_entry, false, false, 3);
65 include_hbox.pack_start (revision_checkbox, false, false, 3);
66 include_hbox.pack_start (revision_spinbutton, false, false, 3);
67 include_hbox.pack_start (timespan_checkbox, false, false, 3);
68 include_hbox.pack_start (date_format_combo, false, false, 3);
69 include_hbox.pack_start (time_format_combo, false, false, 3);
71 label_entry.set_activates_default ();
73 path_hbox.pack_start (path_label, false, false, 3);
74 path_hbox.pack_start (path_entry, true, true, 3);
75 path_hbox.pack_start (browse_button, false, false, 3);
76 path_hbox.pack_start (open_button, false, false, 3); // maybe Mixbus only ?
78 path_entry.set_activates_default ();
80 label_sizegroup = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
81 label_sizegroup->add_widget (label_label);
82 label_sizegroup->add_widget (path_label);
86 date_format_list = Gtk::ListStore::create (date_format_cols);
87 date_format_combo.set_model (date_format_list);
88 date_format_combo.pack_start (date_format_cols.label);
90 date_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_date_format));
94 time_format_list = Gtk::ListStore::create (time_format_cols);
95 time_format_combo.set_model (time_format_list);
96 time_format_combo.pack_start (time_format_cols.label);
98 time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_time_format));
102 revision_spinbutton.set_digits (0);
103 revision_spinbutton.set_increments (1, 10);
104 revision_spinbutton.set_range (1, 1000);
105 revision_spinbutton.set_sensitive (false);
109 label_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_label));
110 path_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_folder));
111 path_entry.signal_activate().connect (sigc::mem_fun (*this, &ExportFilenameSelector::check_folder), false);
113 session_snap_name.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_session_selection));
114 timespan_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_timespan_selection));
116 revision_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_selection));
117 revision_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_value));
119 browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_browse_dialog));
120 open_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_folder));
123 ExportFilenameSelector::~ExportFilenameSelector ()
129 ExportFilenameSelector::load_state ()
135 label_entry.set_text (filename->include_label ? filename->get_label() : "");
136 if (filename->include_session) {
137 if (filename->use_session_snapshot_name) {
138 session_snap_name.set_active (2);
140 session_snap_name.set_active (1);
143 session_snap_name.set_active (0);
145 timespan_checkbox.set_active (filename->include_timespan);
146 revision_checkbox.set_active (filename->include_revision);
147 revision_spinbutton.set_value (filename->get_revision());
148 path_entry.set_text (filename->get_folder());
150 Gtk::TreeModel::Children::iterator it;
152 for (it = date_format_list->children().begin(); it != date_format_list->children().end(); ++it) {
153 if (it->get_value (date_format_cols.format) == filename->get_date_format()) {
154 date_format_combo.set_active (it);
158 for (it = time_format_list->children().begin(); it != time_format_list->children().end(); ++it) {
159 if (it->get_value (time_format_cols.format) == filename->get_time_format()) {
160 time_format_combo.set_active (it);
166 ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_)
168 SessionHandlePtr::set_session (session_);
170 filename = state_->filename;
172 /* Fill combo boxes */
174 Gtk::TreeModel::iterator iter;
175 Gtk::TreeModel::Row row;
179 date_format_list->clear();
181 iter = date_format_list->append();
183 row[date_format_cols.format] = ExportFilename::D_None;
184 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_None);
186 iter = date_format_list->append();
188 row[date_format_cols.format] = ExportFilename::D_ISO;
189 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISO);
191 iter = date_format_list->append();
193 row[date_format_cols.format] = ExportFilename::D_ISOShortY;
194 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISOShortY);
196 iter = date_format_list->append();
198 row[date_format_cols.format] = ExportFilename::D_BE;
199 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BE);
201 iter = date_format_list->append();
203 row[date_format_cols.format] = ExportFilename::D_BEShortY;
204 row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BEShortY);
208 time_format_list->clear();
210 iter = time_format_list->append();
212 row[time_format_cols.format] = ExportFilename::T_None;
213 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_None);
215 iter = time_format_list->append();
217 row[time_format_cols.format] = ExportFilename::T_NoDelim;
218 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_NoDelim);
220 iter = time_format_list->append();
222 row[time_format_cols.format] = ExportFilename::T_Delim;
223 row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_Delim);
232 ExportFilenameSelector::set_example_filename (std::string filename)
234 if (filename == "") {
235 example_filename_label.set_markup (_("<small><i>Sorry, no example filename can be shown at the moment</i></small>"));
237 example_filename_label.set_markup (string_compose(_("<i>Current (approximate) filename</i>: \"%1\""), filename));
242 ExportFilenameSelector::update_label ()
248 filename->set_label (label_entry.get_text());
250 filename->include_label = !label_entry.get_text().empty();
251 CriticalSelectionChanged();
255 ExportFilenameSelector::update_folder ()
261 filename->set_folder (path_entry.get_text());
262 CriticalSelectionChanged();
266 ExportFilenameSelector::check_folder ()
272 if (!Glib::file_test (path_entry.get_text(), Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
273 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
274 The filename will be chosen from the information just above the folder selector."), path_entry.get_text()));
276 path_entry.set_text (Glib::path_get_dirname (path_entry.get_text()));
277 filename->set_folder (path_entry.get_text());
278 CriticalSelectionChanged();
283 ExportFilenameSelector::change_date_format ()
289 DateFormat format = date_format_combo.get_active()->get_value (date_format_cols.format);
290 filename->set_date_format (format);
291 CriticalSelectionChanged();
295 ExportFilenameSelector::change_time_format ()
301 TimeFormat format = time_format_combo.get_active()->get_value (time_format_cols.format);
302 filename->set_time_format (format);
303 CriticalSelectionChanged();
307 ExportFilenameSelector::require_timespan (bool r)
309 _require_timespan = r;
310 update_timespan_sensitivity ();
314 ExportFilenameSelector::update_timespan_sensitivity ()
316 bool implicit = _require_timespan;
319 && !filename->include_session
320 && !filename->include_label
321 && !filename->include_revision
322 && !filename->include_channel_config
323 && !filename->include_channel
324 && !filename->include_date
325 && !filename->include_format_name) {
329 // remember prev state, force enable if implicit active.
330 if (implicit && !timespan_checkbox.get_inconsistent()) {
331 timespan_checkbox.set_inconsistent (true);
332 filename->include_timespan = true;
334 else if (!implicit && timespan_checkbox.get_inconsistent()) {
335 filename->include_timespan = timespan_checkbox.get_active();
336 timespan_checkbox.set_inconsistent (false);
342 ExportFilenameSelector::change_timespan_selection ()
347 if (timespan_checkbox.get_inconsistent()) {
351 filename->include_timespan = timespan_checkbox.get_active();
352 CriticalSelectionChanged();
356 ExportFilenameSelector::change_session_selection ()
362 switch (session_snap_name.get_active_row_number ()) {
364 filename->include_session = true;
365 filename->use_session_snapshot_name = false;
368 filename->include_session = true;
369 filename->use_session_snapshot_name = true;
372 filename->include_session = false;
373 filename->use_session_snapshot_name = false;
376 CriticalSelectionChanged();
380 ExportFilenameSelector::change_revision_selection ()
386 bool selected = revision_checkbox.get_active();
387 filename->include_revision = selected;
389 revision_spinbutton.set_sensitive (selected);
390 CriticalSelectionChanged();
394 ExportFilenameSelector::change_revision_value ()
400 filename->set_revision ((uint32_t) revision_spinbutton.get_value_as_int());
401 CriticalSelectionChanged();
405 ExportFilenameSelector::open_folder ()
407 const std::string& dir (path_entry.get_text());
408 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
409 Gtk::MessageDialog msg (string_compose (_("%1: this is not a valid directory/folder."), dir));
413 PBD::open_folder (dir);
417 ExportFilenameSelector::open_browse_dialog ()
419 Gtk::FileChooserDialog dialog(_("Choose export folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
420 Gtkmm2ext::add_volume_shortcuts (dialog);
421 //dialog.set_transient_for(*this);
422 dialog.set_filename (path_entry.get_text());
424 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
425 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
428 int result = dialog.run();
430 if (result == Gtk::RESPONSE_OK) {
431 std::string filename = dialog.get_filename();
433 if (!Glib::file_test (filename, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
434 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
435 The filename will be chosen from the information just above the folder selector."), filename));
440 if (filename.length()) {
441 path_entry.set_text (filename);
448 CriticalSelectionChanged();