enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / save_as_dialog.cc
1 /*
2     Copyright (C) 2015 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gtkmm/stock.h>
21
22 #include "ardour/session.h"
23
24 #include "save_as_dialog.h"
25
26 #include "pbd/i18n.h"
27
28 using namespace std;
29 using namespace Gtk;
30 using namespace ARDOUR;
31
32 SaveAsDialog::SaveAsDialog ()
33         : ArdourDialog (_("Save As"))
34         , switch_to_button (_("Switch to newly-saved version"))
35         , copy_media_button (_("Copy media to new session"))
36         , copy_external_button (_("Copy external media into new session"))
37         , no_include_media_button (_("Newly-saved session should be empty"))
38 {
39         VBox* vbox = get_vbox();
40
41         vbox->set_spacing (6);
42
43         HBox* hbox;
44         Label* label;
45
46         hbox = manage (new HBox);
47         hbox->set_spacing (6);
48         label = manage (new Label (_("Save as session name")));
49         hbox->pack_start (*label, false, false);
50         hbox->pack_start (new_name_entry, true, true);
51         vbox->pack_start (*hbox, false, false);
52
53         hbox = manage (new HBox);
54         hbox->set_spacing (6);
55         label = manage (new Label (_("Parent directory/folder")));
56         hbox->pack_start (*label, false, false);
57         hbox->pack_start (new_parent_folder_selector, true, true);
58         vbox->pack_start (*hbox, false, false);
59
60         vbox->pack_start (switch_to_button, false, false);
61
62         VBox* sub_vbox = manage (new VBox);
63         HBox* sub_hbox = manage (new HBox);
64         HBox* empty = manage (new HBox);
65
66         sub_vbox->pack_start (copy_media_button, false, false);
67         sub_vbox->pack_start (copy_external_button, false, false);
68
69         /* indent the two media-related buttons by some amount */
70         sub_hbox->set_spacing (24);
71         sub_hbox->pack_start (*empty, false, false);
72         sub_hbox->pack_start (*sub_vbox, false, false);
73
74         vbox->pack_start (no_include_media_button, false, false);
75         vbox->pack_start (*sub_hbox, false, false);
76
77         switch_to_button.set_active (true);
78         copy_media_button.set_active (true);
79
80         vbox->show_all ();
81
82         add_button (Stock::CANCEL, RESPONSE_CANCEL);
83         add_button (Stock::OK, RESPONSE_OK);
84
85         no_include_media_button.signal_toggled ().connect (sigc::mem_fun (*this, &SaveAsDialog::no_include_toggled));
86
87         new_parent_folder_selector.set_action (FILE_CHOOSER_ACTION_SELECT_FOLDER);
88         new_parent_folder_selector.set_current_folder (Config->get_default_session_parent_dir ());
89         new_name_entry.signal_changed().connect (sigc::mem_fun (*this, &SaveAsDialog::name_entry_changed));
90         new_parent_folder_selector.signal_current_folder_changed().connect (sigc::mem_fun (*this, &SaveAsDialog::name_entry_changed));
91         new_parent_folder_selector.signal_selection_changed().connect (sigc::mem_fun (*this, &SaveAsDialog::name_entry_changed));
92         set_response_sensitive (RESPONSE_OK, false);
93 }
94
95 void
96 SaveAsDialog::no_include_toggled ()
97 {
98         if (no_include_media_button.get_active()) {
99                 copy_media_button.set_sensitive (false);
100                 copy_external_button.set_sensitive (false);
101         } else {
102                 copy_media_button.set_sensitive (true);
103                 copy_external_button.set_sensitive (true);
104         }
105 }
106
107 void
108 SaveAsDialog::name_entry_changed ()
109 {
110         if (new_name_entry.get_text().empty()) {
111                 set_response_sensitive (RESPONSE_OK, false);
112                 return;
113         }
114
115         std::string dir = Glib::build_filename (new_parent_folder(), new_name_entry.get_text());
116
117         if (Glib::file_test (dir, Glib::FILE_TEST_EXISTS)) {
118                 set_response_sensitive (RESPONSE_OK, false);
119                 return;
120         }
121
122         set_response_sensitive (RESPONSE_OK);
123 }
124
125 string
126 SaveAsDialog::new_parent_folder () const
127 {
128         return new_parent_folder_selector.get_filename ();
129 }
130
131 string
132 SaveAsDialog::new_name () const
133 {
134         return new_name_entry.get_text ();
135 }
136
137 bool
138 SaveAsDialog::switch_to () const
139 {
140         return switch_to_button.get_active ();
141 }
142
143 bool
144 SaveAsDialog::copy_media () const
145 {
146         return copy_media_button.get_active ();
147 }
148
149 bool
150 SaveAsDialog::copy_external () const
151 {
152         return copy_external_button.get_active ();
153 }
154
155 void
156 SaveAsDialog::clear_name ()
157 {
158         new_name_entry.set_text ("");
159         set_response_sensitive (RESPONSE_OK, false);
160 }
161
162 void
163 SaveAsDialog::set_name (std::string name)
164 {
165         new_name_entry.set_text (name);
166         name_entry_changed ();
167 }
168
169 bool
170 SaveAsDialog::include_media () const
171 {
172         return !no_include_media_button.get_active ();
173 }