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