24ecba6b71444cf3f75d848a20507532c99f57ca
[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
23 #include "ardour/session.h"
24
25 #include "session_archive_dialog.h"
26
27 #include "pbd/i18n.h"
28
29 using namespace std;
30 using namespace Gtk;
31 using namespace ARDOUR;
32
33 SessionArchiveDialog::SessionArchiveDialog ()
34         : ArdourDialog (_("Zip/Archive Session"))
35         , ProgressReporter ()
36 {
37         VBox* vbox = get_vbox();
38
39         vbox->set_spacing (6);
40
41         HBox* hbox;
42         Label* label;
43
44         format_selector.append_text (".tar.xz");
45         format_selector.set_active_text (".tar.xz");
46
47         encode_selector.append_text (_("None"));
48         encode_selector.append_text (_("FLAC 16bit"));
49         encode_selector.append_text (_("FLAC 24bit"));
50         encode_selector.set_active_text ("FLAC 16bit"); // TODO remember
51
52         hbox = manage (new HBox);
53         hbox->set_spacing (6);
54         label = manage (new Label (_("Archive Name")));
55         hbox->pack_start (*label, false, false);
56         hbox->pack_start (name_entry, true, true);
57         hbox->pack_start (format_selector, false, false);
58         vbox->pack_start (*hbox, false, false);
59
60         hbox = manage (new HBox);
61         hbox->set_spacing (6);
62         label = manage (new Label (_("Target directory/folder")));
63         hbox->pack_start (*label, false, false);
64         hbox->pack_start (target_folder_selector, true, true);
65         vbox->pack_start (*hbox, false, false);
66
67         hbox = manage (new HBox);
68         hbox->set_spacing (6);
69         label = manage (new Label (_("Audio Compression")));
70         hbox->pack_start (*label, false, false);
71         hbox->pack_start (encode_selector, true, true);
72         vbox->pack_start (*hbox, false, false);
73
74         vbox->pack_start (progress_bar, true, true, 12);
75
76         vbox->show_all ();
77         progress_bar.hide ();
78
79         add_button (Stock::CANCEL, RESPONSE_CANCEL);
80         add_button (Stock::OK, RESPONSE_OK);
81
82         target_folder_selector.set_action (FILE_CHOOSER_ACTION_SELECT_FOLDER);
83         target_folder_selector.set_current_folder (Config->get_default_session_parent_dir ()); // TODO get/set default_archive_dir
84         name_entry.signal_changed().connect (sigc::mem_fun (*this, &SessionArchiveDialog::name_entry_changed));
85         target_folder_selector.signal_current_folder_changed().connect (sigc::mem_fun (*this, &SessionArchiveDialog::name_entry_changed));
86         target_folder_selector.signal_selection_changed().connect (sigc::mem_fun (*this, &SessionArchiveDialog::name_entry_changed));
87         set_response_sensitive (RESPONSE_OK, false);
88 }
89
90
91 void
92 SessionArchiveDialog::name_entry_changed ()
93 {
94         if (name_entry.get_text().empty()) {
95                 set_response_sensitive (RESPONSE_OK, false);
96                 return;
97         }
98
99         std::string dir = Glib::build_filename (target_folder(), name_entry.get_text() + format_selector.get_active_text ());
100
101         if (Glib::file_test (dir, Glib::FILE_TEST_EXISTS)) {
102                 set_response_sensitive (RESPONSE_OK, false);
103                 return;
104         }
105
106         set_response_sensitive (RESPONSE_OK);
107 }
108
109 string
110 SessionArchiveDialog::target_folder () const
111 {
112         return target_folder_selector.get_filename ();
113 }
114
115 void
116 SessionArchiveDialog::set_target_folder (const std::string& name)
117 {
118         target_folder_selector.set_current_folder (name);
119         name_entry_changed ();
120 }
121
122 string
123 SessionArchiveDialog::name () const
124 {
125         return name_entry.get_text ();
126 }
127
128 void
129 SessionArchiveDialog::set_name (const std::string& name)
130 {
131         name_entry.set_text (name);
132         name_entry_changed ();
133 }
134
135 ARDOUR::Session::ArchiveEncode
136 SessionArchiveDialog::encode_option () const
137 {
138         string codec = encode_selector.get_active_text ();
139         if (codec == _("FLAC 16bit")) {
140                 return ARDOUR::Session::FLAC_16BIT;
141         }
142         if (codec == _("FLAC 24bit")) {
143                 return ARDOUR::Session::FLAC_24BIT;
144         }
145         return ARDOUR::Session::NO_ENCODE;
146 }
147
148 void
149 SessionArchiveDialog::set_encode_option (ARDOUR::Session::ArchiveEncode e)
150 {
151         switch (e) {
152                 case ARDOUR::Session::FLAC_16BIT:
153                         encode_selector.set_active_text (_("FLAC 16bit"));
154                         break;
155                 case ARDOUR::Session::FLAC_24BIT:
156                         encode_selector.set_active_text (_("FLAC 24bit"));
157                         break;
158                 default:
159                         encode_selector.set_active_text (_("None"));
160                         break;
161         }
162 }
163
164 void
165 SessionArchiveDialog::update_progress_gui (float p)
166 {
167         set_response_sensitive (RESPONSE_OK, false);
168         set_response_sensitive (RESPONSE_CANCEL, false);
169         progress_bar.show ();
170         if (p < 0) {
171                 progress_bar.set_text (_("Archiving Session"));
172                 return;
173         }
174         if (p > 1.0) {
175                 progress_bar.set_text (_("Encoding Audio"));
176                 return;
177         }
178         progress_bar.set_fraction (p);
179 }