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