OSC: Changed gainVCA to gainfader as VCA is already used.
[ardour.git] / gtk2_ardour / export_filename_selector.cc
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #include <gtkmm/messagedialog.h>
22
23 #include "export_filename_selector.h"
24
25 #include "i18n.h"
26
27 using namespace ARDOUR;
28
29 ExportFilenameSelector::ExportFilenameSelector () :
30         include_label ("", Gtk::ALIGN_LEFT),
31
32         label_label (_("Label:"), Gtk::ALIGN_LEFT),
33         session_checkbox (_("Session Name")),
34         timespan_checkbox (_("Timespan Name")),
35         revision_checkbox (_("Revision:")),
36
37         path_label (_("Folder:"), Gtk::ALIGN_LEFT),
38         browse_button (_("Browse")),
39
40         example_filename_label ("", Gtk::ALIGN_LEFT),
41         _require_timespan (false)
42 {
43         include_label.set_markup (_("Build filename(s) from these components:"));
44
45         pack_start (path_hbox, false, false, 12);
46         pack_start (include_label, false, false, 6);
47         pack_start (include_hbox, false, false, 0);
48         pack_start (example_filename_label, false, false, 12);
49
50         include_hbox.pack_start (session_checkbox, false, false, 3);
51         include_hbox.pack_start (label_label, false, false, 3);
52         include_hbox.pack_start (label_entry, false, false, 3);
53         include_hbox.pack_start (revision_checkbox, false, false, 3);
54         include_hbox.pack_start (revision_spinbutton, false, false, 3);
55         include_hbox.pack_start (timespan_checkbox, false, false, 3);
56         include_hbox.pack_start (date_format_combo, false, false, 3);
57         include_hbox.pack_start (time_format_combo, false, false, 3);
58
59         label_entry.set_activates_default ();
60
61         path_hbox.pack_start (path_label, false, false, 3);
62         path_hbox.pack_start (path_entry, true, true, 3);
63         path_hbox.pack_start (browse_button, false, false, 3);
64
65         path_entry.set_activates_default ();
66
67         label_sizegroup = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
68         label_sizegroup->add_widget (label_label);
69         label_sizegroup->add_widget (path_label);
70
71         /* Date */
72
73         date_format_list = Gtk::ListStore::create (date_format_cols);
74         date_format_combo.set_model (date_format_list);
75         date_format_combo.pack_start (date_format_cols.label);
76
77         date_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_date_format));
78
79         /* Time */
80
81         time_format_list = Gtk::ListStore::create (time_format_cols);
82         time_format_combo.set_model (time_format_list);
83         time_format_combo.pack_start (time_format_cols.label);
84
85         time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_time_format));
86
87         /* Revision */
88
89         revision_spinbutton.set_digits (0);
90         revision_spinbutton.set_increments (1, 10);
91         revision_spinbutton.set_range (1, 1000);
92         revision_spinbutton.set_sensitive (false);
93
94         /* Signals */
95
96         label_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_label));
97         path_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_folder));
98         path_entry.signal_activate().connect (sigc::mem_fun (*this, &ExportFilenameSelector::check_folder), false);
99
100         session_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_session_selection));
101         timespan_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_timespan_selection));
102
103         revision_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_selection));
104         revision_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_value));
105
106         browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_browse_dialog));
107 }
108
109 ExportFilenameSelector::~ExportFilenameSelector ()
110 {
111
112 }
113
114 void
115 ExportFilenameSelector::load_state ()
116 {
117         if (!filename) {
118                 return;
119         }
120
121         label_entry.set_text (filename->include_label ? filename->get_label() : "");
122         session_checkbox.set_active (filename->include_session);
123         timespan_checkbox.set_active (filename->include_timespan);
124         revision_checkbox.set_active (filename->include_revision);
125         revision_spinbutton.set_value (filename->get_revision());
126         path_entry.set_text (filename->get_folder());
127
128         Gtk::TreeModel::Children::iterator it;
129
130         for (it = date_format_list->children().begin(); it != date_format_list->children().end(); ++it) {
131                 if (it->get_value (date_format_cols.format) == filename->get_date_format()) {
132                         date_format_combo.set_active (it);
133                 }
134         }
135
136         for (it = time_format_list->children().begin(); it != time_format_list->children().end(); ++it) {
137                 if (it->get_value (time_format_cols.format) == filename->get_time_format()) {
138                         time_format_combo.set_active (it);
139                 }
140         }
141 }
142
143 void
144 ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_)
145 {
146         SessionHandlePtr::set_session (session_);
147
148         filename = state_->filename;
149
150         /* Fill combo boxes */
151
152         Gtk::TreeModel::iterator iter;
153         Gtk::TreeModel::Row row;
154
155         /* Dates */
156
157         date_format_list->clear();
158
159         iter = date_format_list->append();
160         row = *iter;
161         row[date_format_cols.format] = ExportFilename::D_None;
162         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_None);
163
164         iter = date_format_list->append();
165         row = *iter;
166         row[date_format_cols.format] = ExportFilename::D_ISO;
167         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISO);
168
169         iter = date_format_list->append();
170         row = *iter;
171         row[date_format_cols.format] = ExportFilename::D_ISOShortY;
172         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISOShortY);
173
174         iter = date_format_list->append();
175         row = *iter;
176         row[date_format_cols.format] = ExportFilename::D_BE;
177         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BE);
178
179         iter = date_format_list->append();
180         row = *iter;
181         row[date_format_cols.format] = ExportFilename::D_BEShortY;
182         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BEShortY);
183
184         /* Times */
185
186         time_format_list->clear();
187
188         iter = time_format_list->append();
189         row = *iter;
190         row[time_format_cols.format] = ExportFilename::T_None;
191         row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_None);
192
193         iter = time_format_list->append();
194         row = *iter;
195         row[time_format_cols.format] = ExportFilename::T_NoDelim;
196         row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_NoDelim);
197
198         iter = time_format_list->append();
199         row = *iter;
200         row[time_format_cols.format] = ExportFilename::T_Delim;
201         row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_Delim);
202
203         /* Load state */
204
205         load_state();
206
207 }
208
209 void
210 ExportFilenameSelector::set_example_filename (std::string filename)
211 {
212         if (filename == "") {
213                 example_filename_label.set_markup (_("<small><i>Sorry, no example filename can be shown at the moment</i></small>"));
214         } else {
215                 example_filename_label.set_markup (string_compose(_("<i>Current (approximate) filename</i>: \"%1\""), filename));
216         }
217 }
218
219 void
220 ExportFilenameSelector::update_label ()
221 {
222         if (!filename) {
223                 return;
224         }
225
226         filename->set_label (label_entry.get_text());
227
228         filename->include_label = !label_entry.get_text().empty();
229         CriticalSelectionChanged();
230 }
231
232 void
233 ExportFilenameSelector::update_folder ()
234 {
235         if (!filename) {
236                 return;
237         }
238
239         filename->set_folder (path_entry.get_text());
240         CriticalSelectionChanged();
241 }
242
243 void
244 ExportFilenameSelector::check_folder ()
245 {
246         if (!filename) {
247                 return;
248         }
249
250         if (!Glib::file_test (path_entry.get_text(), Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
251                 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
252 The filename will be chosen from the information just above the folder selector."), path_entry.get_text()));
253                 msg.run ();
254                 path_entry.set_text (Glib::path_get_dirname (path_entry.get_text()));
255                 filename->set_folder (path_entry.get_text());
256                 CriticalSelectionChanged();
257         }
258 }
259
260 void
261 ExportFilenameSelector::change_date_format ()
262 {
263         if (!filename) {
264                 return;
265         }
266
267         DateFormat format = date_format_combo.get_active()->get_value (date_format_cols.format);
268         filename->set_date_format (format);
269         CriticalSelectionChanged();
270 }
271
272 void
273 ExportFilenameSelector::change_time_format ()
274 {
275         if (!filename) {
276                 return;
277         }
278
279         TimeFormat format = time_format_combo.get_active()->get_value (time_format_cols.format);
280         filename->set_time_format (format);
281         CriticalSelectionChanged();
282 }
283
284 void
285 ExportFilenameSelector::require_timespan (bool r)
286 {
287         _require_timespan = r;
288         update_timespan_sensitivity ();
289 }
290
291 void
292 ExportFilenameSelector::update_timespan_sensitivity ()
293 {
294         bool implicit = _require_timespan;
295
296         if (!implicit
297                         && !filename->include_session
298                         && !filename->include_label
299                         && !filename->include_revision
300                         && !filename->include_channel_config
301                         && !filename->include_channel
302                         && !filename->include_date
303                         && !filename->include_format_name) {
304                 implicit = true;
305         }
306
307         // remember prev state, force enable if implicit active.
308         if (implicit && !timespan_checkbox.get_inconsistent()) {
309                 timespan_checkbox.set_inconsistent (true);
310                 filename->include_timespan = true;
311         }
312         else if (!implicit && timespan_checkbox.get_inconsistent()) {
313                 filename->include_timespan = timespan_checkbox.get_active();
314                 timespan_checkbox.set_inconsistent (false);
315         }
316
317 }
318
319 void
320 ExportFilenameSelector::change_timespan_selection ()
321 {
322         if (!filename) {
323                 return;
324         }
325         if (timespan_checkbox.get_inconsistent()) {
326                 return;
327         }
328
329         filename->include_timespan = timespan_checkbox.get_active();
330         CriticalSelectionChanged();
331 }
332
333 void
334 ExportFilenameSelector::change_session_selection ()
335 {
336         if (!filename) {
337                 return;
338         }
339
340         filename->include_session = session_checkbox.get_active();
341         CriticalSelectionChanged();
342 }
343
344 void
345 ExportFilenameSelector::change_revision_selection ()
346 {
347         if (!filename) {
348                 return;
349         }
350
351         bool selected = revision_checkbox.get_active();
352         filename->include_revision = selected;
353
354         revision_spinbutton.set_sensitive (selected);
355         CriticalSelectionChanged();
356 }
357
358 void
359 ExportFilenameSelector::change_revision_value ()
360 {
361         if (!filename) {
362                 return;
363         }
364
365         filename->set_revision ((uint32_t) revision_spinbutton.get_value_as_int());
366         CriticalSelectionChanged();
367 }
368
369 void
370 ExportFilenameSelector::open_browse_dialog ()
371 {
372         Gtk::FileChooserDialog dialog(_("Choose export folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
373         //dialog.set_transient_for(*this);
374         dialog.set_filename (path_entry.get_text());
375
376         dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
377         dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
378
379         while (true) {
380                 int result = dialog.run();
381
382                 if (result == Gtk::RESPONSE_OK) {
383                         std::string filename = dialog.get_filename();
384
385                         if (!Glib::file_test (filename, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
386                                 Gtk::MessageDialog msg (string_compose (_("%1: this is only the directory/folder name, not the filename.\n\
387 The filename will be chosen from the information just above the folder selector."), filename));
388                                 msg.run ();
389                                 continue;
390                         }
391
392                         if (filename.length()) {
393                                 path_entry.set_text (filename);
394                                 break;
395                         }
396                 }
397                 break;
398         }
399
400         CriticalSelectionChanged();
401 }