More Export GUI tweaks....
[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 "export_filename_selector.h"
22
23 #include <ardour/export_handler.h>
24 #include <ardour/session.h>
25 #include <ardour/session_directory.h>
26
27 #include "i18n.h"
28
29 using namespace ARDOUR;
30
31 ExportFilenameSelector::ExportFilenameSelector () :
32   session (0),
33
34   include_label (_("Include in Filename(s):"), Gtk::ALIGN_LEFT),
35
36   label_label (_("Label:"), Gtk::ALIGN_LEFT),
37   session_checkbox (_("Session Name")),
38   revision_checkbox (_("Revision:")),
39
40   path_label (_("Folder:"), Gtk::ALIGN_LEFT),
41   browse_button (_("Browse"))
42 {
43         pack_start (include_label, false, false, 6);
44         pack_start (include_hbox, false, false, 0);
45         pack_start (path_hbox, false, false, 12);
46         
47         include_hbox.pack_start (label_label, false, false, 3);
48         include_hbox.pack_start (label_entry, false, false, 3);
49         include_hbox.pack_start (session_checkbox, false, false, 3);
50         include_hbox.pack_start (date_format_combo, false, false, 3);
51         include_hbox.pack_start (time_format_combo, false, false, 3);
52         include_hbox.pack_start (revision_checkbox, false, false, 3);
53         include_hbox.pack_start (revision_spinbutton, false, false, 3);
54         
55         path_hbox.pack_start (path_label, false, false, 3);
56         path_hbox.pack_start (path_entry, true, true, 3);
57         path_hbox.pack_start (browse_button, false, false, 3);
58         
59         date_format_combo.set_name ("PaddedButton");
60         time_format_combo.set_name ("PaddedButton");
61         browse_button.set_name ("PaddedButton");
62         
63         label_sizegroup = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_HORIZONTAL);
64         label_sizegroup->add_widget (label_label);
65         label_sizegroup->add_widget (path_label);
66         
67         /* Date */
68         
69         date_format_list = Gtk::ListStore::create (date_format_cols);
70         date_format_combo.set_model (date_format_list);
71         date_format_combo.pack_start (date_format_cols.label);
72         
73         date_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_date_format));
74         
75         /* Time */
76         
77         time_format_list = Gtk::ListStore::create (time_format_cols);
78         time_format_combo.set_model (time_format_list);
79         time_format_combo.pack_start (time_format_cols.label);
80         
81         time_format_combo.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_time_format));
82         
83         /* Revision */
84         
85         revision_spinbutton.set_digits (0);
86         revision_spinbutton.set_increments (1, 10);
87         revision_spinbutton.set_range (1, 1000);
88         revision_spinbutton.set_sensitive (false);
89         
90         /* Signals */
91         
92         label_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_label));
93         path_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::update_folder));
94         
95         session_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_session_selection));
96         
97         revision_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_selection));
98         revision_spinbutton.signal_value_changed().connect (sigc::mem_fun (*this, &ExportFilenameSelector::change_revision_value));
99         
100         browse_button.signal_clicked().connect (sigc::mem_fun (*this, &ExportFilenameSelector::open_browse_dialog));    
101 }
102
103 ExportFilenameSelector::~ExportFilenameSelector ()
104 {
105
106 }
107
108 void
109 ExportFilenameSelector::load_state ()
110 {
111         if (!filename) {
112                 return;
113         }
114
115         label_entry.set_text (filename->include_label ? filename->get_label() : "");
116         session_checkbox.set_active (filename->include_session);
117         revision_checkbox.set_active (filename->include_revision);
118         revision_spinbutton.set_value (filename->get_revision());
119         path_entry.set_text (filename->get_folder());
120         
121         Gtk::TreeModel::Children::iterator it;
122         
123         for (it = date_format_list->children().begin(); it != date_format_list->children().end(); ++it) {
124                 if (it->get_value (date_format_cols.format) == filename->get_date_format()) {
125                         date_format_combo.set_active (it);
126                 }
127         }
128         
129         for (it = time_format_list->children().begin(); it != time_format_list->children().end(); ++it) {
130                 if (it->get_value (time_format_cols.format) == filename->get_time_format()) {
131                         time_format_combo.set_active (it);
132                 }
133         }
134 }
135
136 void
137 ExportFilenameSelector::set_state (ARDOUR::ExportProfileManager::FilenameStatePtr state_, ARDOUR::Session * session_)
138 {
139         session = session_;
140         
141         filename = state_->filename;
142         
143         /* Fill combo boxes */
144         
145         Gtk::TreeModel::iterator iter;
146         Gtk::TreeModel::Row row;
147         
148         /* Dates */
149         
150         date_format_list->clear();
151         
152         iter = date_format_list->append();
153         row = *iter;
154         row[date_format_cols.format] = ExportFilename::D_None;
155         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_None);
156         
157         iter = date_format_list->append();
158         row = *iter;
159         row[date_format_cols.format] = ExportFilename::D_ISO;
160         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISO);
161         
162         iter = date_format_list->append();
163         row = *iter;
164         row[date_format_cols.format] = ExportFilename::D_ISOShortY;
165         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_ISOShortY);
166         
167         iter = date_format_list->append();
168         row = *iter;
169         row[date_format_cols.format] = ExportFilename::D_BE;
170         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BE);
171         
172         iter = date_format_list->append();
173         row = *iter;
174         row[date_format_cols.format] = ExportFilename::D_BEShortY;
175         row[date_format_cols.label] = filename->get_date_format_str (ExportFilename::D_BEShortY);
176         
177         /* Times */
178         
179         time_format_list->clear();
180         
181         iter = time_format_list->append();
182         row = *iter;
183         row[time_format_cols.format] = ExportFilename::T_None;
184         row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_None);
185         
186         iter = time_format_list->append();
187         row = *iter;
188         row[time_format_cols.format] = ExportFilename::T_NoDelim;
189         row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_NoDelim);
190         
191         iter = time_format_list->append();
192         row = *iter;
193         row[time_format_cols.format] = ExportFilename::T_Delim;
194         row[time_format_cols.label] = filename->get_time_format_str (ExportFilename::T_Delim);
195
196         /* Load state */
197
198         load_state();
199
200 }
201
202 void
203 ExportFilenameSelector::update_label ()
204 {
205         if (!filename) {
206                 return;
207         }
208         
209         filename->set_label (label_entry.get_text());
210         
211         filename->include_label = !label_entry.get_text().empty();
212         CriticalSelectionChanged();
213 }
214
215 void
216 ExportFilenameSelector::update_folder ()
217 {
218         if (!filename) {
219                 return;
220         }
221         
222         filename->set_folder (path_entry.get_text());
223         CriticalSelectionChanged();
224 }
225
226 void
227 ExportFilenameSelector::change_date_format ()
228 {
229         if (!filename) {
230                 return;
231         }
232         
233         DateFormat format = date_format_combo.get_active()->get_value (date_format_cols.format);
234         filename->set_date_format (format);
235         CriticalSelectionChanged();
236 }
237
238 void
239 ExportFilenameSelector::change_time_format ()
240 {
241         if (!filename) {
242                 return;
243         }
244         
245         TimeFormat format = time_format_combo.get_active()->get_value (time_format_cols.format);
246         filename->set_time_format (format);
247         CriticalSelectionChanged();
248 }
249
250 void
251 ExportFilenameSelector::change_session_selection ()
252 {
253         if (!filename) {
254                 return;
255         }
256         
257         filename->include_session = session_checkbox.get_active();
258         CriticalSelectionChanged();
259 }
260
261 void
262 ExportFilenameSelector::change_revision_selection ()
263 {
264         if (!filename) {
265                 return;
266         }
267         
268         bool selected = revision_checkbox.get_active();
269         filename->include_revision = selected;
270         
271         revision_spinbutton.set_sensitive (selected);
272         CriticalSelectionChanged();
273 }
274
275 void
276 ExportFilenameSelector::change_revision_value ()
277 {
278         if (!filename) {
279                 return;
280         }
281         
282         filename->set_revision ((uint32_t) revision_spinbutton.get_value_as_int());
283         CriticalSelectionChanged();
284 }
285
286 void
287 ExportFilenameSelector::open_browse_dialog ()
288 {
289         Gtk::FileChooserDialog dialog(_("Choose export folder"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
290         //dialog.set_transient_for(*this);
291         dialog.set_filename (path_entry.get_text());
292
293         dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
294         dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
295
296         int result = dialog.run();
297
298         if (result == Gtk::RESPONSE_OK) {
299                 Glib::ustring filename = dialog.get_filename();
300         
301                 if (filename.length()) {
302                         path_entry.set_text (filename);
303                 }
304         }
305         
306         CriticalSelectionChanged();
307 }