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