additional API to make it nicer to get an existing action group
[ardour.git] / gtk2_ardour / session_archive_dialog.cc
1 /*
2     Copyright (C) 2015 Paul Davis
3     Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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/stock.h>
22 #include <gtkmm/table.h>
23
24 #include "ardour/filename_extensions.h"
25
26 #include "gtkmm2ext/utils.h"
27
28 #include "session_archive_dialog.h"
29
30 #include "pbd/i18n.h"
31
32 using namespace std;
33 using namespace Gtk;
34 using namespace ARDOUR;
35
36 SessionArchiveDialog::SessionArchiveDialog ()
37         : ArdourDialog (_("Zip/Archive Current Session"))
38         , ProgressReporter ()
39         , only_used_checkbox (_("Exclude unused audio sources"))
40 {
41         VBox* vbox = get_vbox();
42
43         vbox->set_spacing (6);
44
45         format_selector.append_text (ARDOUR::session_archive_suffix);
46         format_selector.set_active_text (ARDOUR::session_archive_suffix);
47
48         encode_selector.append_text (_("None"));
49         encode_selector.append_text (_("FLAC 16bit"));
50         encode_selector.append_text (_("FLAC 24bit"));
51         encode_selector.set_active_text ("FLAC 16bit"); // TODO remember
52
53         compression_selector.append_text (_("None"));
54         compression_selector.append_text (_("Fast"));
55         compression_selector.append_text (_("Good"));
56         compression_selector.set_active_text ("Good"); // TODO remember
57
58         Gtk::Table* table = manage (new Gtk::Table ());
59         table->set_col_spacings (10);
60         table->set_row_spacings (8);
61
62         Label* label;
63         int row = 0;
64
65         label = manage (new Label (_("Archive Name:"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
66         table->attach (*label, 0, 1, row, row + 1, Gtk::FILL, Gtk::SHRINK);
67
68         HBox* hbox = manage (new HBox);
69         hbox->set_spacing (6);
70         hbox->pack_start (name_entry, true, true);
71         hbox->pack_start (format_selector, false, false);
72         table->attach (*hbox, 1, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
73
74         ++row;
75
76         label = manage (new Label (_("Target directory/folder:"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
77         table->attach (*label, 0, 1, row, row + 1, Gtk::FILL, Gtk::SHRINK);
78         table->attach (target_folder_selector, 1, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
79
80         ++row;
81
82         label = manage (new Label (_("Audio Compression:"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
83         table->attach (*label, 0, 1, row, row + 1, Gtk::FILL, Gtk::SHRINK);
84         table->attach (encode_selector, 1, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
85
86         ++row;
87
88         label = manage (new Label (_("Archive Compression:"), Gtk::ALIGN_END, Gtk::ALIGN_CENTER, false));
89         table->attach (*label, 0, 1, row, row + 1, Gtk::FILL, Gtk::SHRINK);
90         table->attach (compression_selector, 1, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
91
92         ++row;
93
94         table->attach (only_used_checkbox, 0, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
95
96         ++row;
97
98         label = manage (new Label (_("Note: This archives only the current session state, snapshots are not included."), ALIGN_START));
99         label->set_line_wrap (true);
100         table->attach (*label, 0, 2, row, row + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);
101
102         vbox->pack_start (*table, false, false);
103         vbox->pack_start (progress_bar, true, true, 12);
104
105         vbox->show_all ();
106         progress_bar.hide ();
107
108         add_button (Stock::CANCEL, RESPONSE_CANCEL);
109         add_button (Stock::OK, RESPONSE_OK);
110
111         Gtkmm2ext::add_volume_shortcuts (target_folder_selector);
112         target_folder_selector.set_action (FILE_CHOOSER_ACTION_SELECT_FOLDER);
113         target_folder_selector.set_current_folder (Config->get_default_session_parent_dir ()); // TODO get/set default_archive_dir
114         name_entry.signal_changed().connect (sigc::mem_fun (*this, &SessionArchiveDialog::name_entry_changed));
115         target_folder_selector.signal_current_folder_changed().connect (sigc::mem_fun (*this, &SessionArchiveDialog::name_entry_changed));
116         target_folder_selector.signal_selection_changed().connect (sigc::mem_fun (*this, &SessionArchiveDialog::name_entry_changed));
117         set_response_sensitive (RESPONSE_OK, false);
118 }
119
120
121 void
122 SessionArchiveDialog::name_entry_changed ()
123 {
124         if (name_entry.get_text().empty()) {
125                 set_response_sensitive (RESPONSE_OK, false);
126                 return;
127         }
128
129         std::string dir = Glib::build_filename (target_folder(), name_entry.get_text() + format_selector.get_active_text ());
130
131         if (Glib::file_test (dir, Glib::FILE_TEST_EXISTS)) {
132                 set_response_sensitive (RESPONSE_OK, false);
133                 return;
134         }
135
136         set_response_sensitive (RESPONSE_OK);
137 }
138
139 string
140 SessionArchiveDialog::target_folder () const
141 {
142         return target_folder_selector.get_filename ();
143 }
144
145 void
146 SessionArchiveDialog::set_target_folder (const std::string& name)
147 {
148         target_folder_selector.set_current_folder (name);
149         name_entry_changed ();
150 }
151
152 string
153 SessionArchiveDialog::name () const
154 {
155         return name_entry.get_text ();
156 }
157
158 void
159 SessionArchiveDialog::set_name (const std::string& name)
160 {
161         name_entry.set_text (name);
162         name_entry_changed ();
163 }
164
165 bool
166 SessionArchiveDialog::only_used_sources () const
167 {
168         return only_used_checkbox.get_active ();
169 }
170
171 void
172 SessionArchiveDialog::set_only_used_sources (bool en)
173 {
174         only_used_checkbox.set_active (en);
175 }
176
177 ARDOUR::Session::ArchiveEncode
178 SessionArchiveDialog::encode_option () const
179 {
180         string codec = encode_selector.get_active_text ();
181         if (codec == _("FLAC 16bit")) {
182                 return ARDOUR::Session::FLAC_16BIT;
183         }
184         if (codec == _("FLAC 24bit")) {
185                 return ARDOUR::Session::FLAC_24BIT;
186         }
187         return ARDOUR::Session::NO_ENCODE;
188 }
189
190 void
191 SessionArchiveDialog::set_encode_option (ARDOUR::Session::ArchiveEncode e)
192 {
193         switch (e) {
194                 case ARDOUR::Session::FLAC_16BIT:
195                         encode_selector.set_active_text (_("FLAC 16bit"));
196                         break;
197                 case ARDOUR::Session::FLAC_24BIT:
198                         encode_selector.set_active_text (_("FLAC 24bit"));
199                         break;
200                 default:
201                         encode_selector.set_active_text (_("None"));
202                         break;
203         }
204 }
205
206 PBD::FileArchive::CompressionLevel
207 SessionArchiveDialog::compression_level () const
208 {
209         string codec = compression_selector.get_active_text ();
210         if (codec == _("Fast")) {
211                 return PBD::FileArchive::CompressFast;
212         } else if (codec == _("None")) {
213                 return PBD::FileArchive::CompressNone;
214         }
215         return PBD::FileArchive::CompressGood;
216 }
217
218 void
219 SessionArchiveDialog::set_compression_level (PBD::FileArchive::CompressionLevel l)
220 {
221         switch (l) {
222                 case PBD::FileArchive::CompressFast:
223                         encode_selector.set_active_text (_("Fast"));
224                         break;
225                 case PBD::FileArchive::CompressNone:
226                         encode_selector.set_active_text (_("None"));
227                         break;
228                 case PBD::FileArchive::CompressGood:
229                         encode_selector.set_active_text (_("Good"));
230                         break;
231         }
232 }
233
234 void
235 SessionArchiveDialog::update_progress_gui (float p)
236 {
237         set_response_sensitive (RESPONSE_OK, false);
238         set_response_sensitive (RESPONSE_CANCEL, false);
239         progress_bar.show ();
240         if (p < 0) {
241                 progress_bar.set_text (_("Archiving Session"));
242                 return;
243         }
244         if (p > 1.0) {
245                 progress_bar.set_text (_("Encoding Audio"));
246                 return;
247         }
248         progress_bar.set_fraction (p);
249 }