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