VKeybd: Pass on primary (Ctrl/Cmd) shortcuts
[ardour.git] / gtk2_ardour / missing_file_dialog.cc
1 /*
2  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2010-2016 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2014-2015 Nick Mainsbridge <mainsbridge@gmail.com>
5  * Copyright (C) 2014 John Emmas <john@creativepost.co.uk>
6  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "pbd/compose.h"
24 #include "pbd/replace_all.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/search_path.h"
27
28 #include "ardour/session.h"
29 #include "gtkmm2ext/utils.h"
30
31 #include "missing_file_dialog.h"
32 #include "pbd/i18n.h"
33
34 using namespace Gtk;
35 using namespace std;
36 using namespace ARDOUR;
37 using namespace PBD;
38
39 MissingFileDialog::MissingFileDialog (Session* s, const std::string& path, DataType type)
40         : ArdourDialog (_("Missing File"), true, false)
41         , filetype (type)
42         , is_absolute_path (Glib::path_is_absolute (path))
43         , chooser (_("Select a folder to search"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
44         , use_chosen (_("Add chosen folder to search path, and try again"))
45         , choice_group (use_chosen.get_group())
46         , stop_loading_button (choice_group, _("Stop loading this session"), false)
47         , all_missing_ok (choice_group, _("Skip all missing files"), false)
48         , this_missing_ok (choice_group, _("Skip this file"), false)
49 {
50         /* This dialog is always shown programatically. Center the window.*/
51         set_position (Gtk::WIN_POS_CENTER);
52
53         set_session (s);
54
55         add_button (_("Done"), RESPONSE_OK);
56         set_default_response (RESPONSE_OK);
57
58         string typestr;
59
60         switch (type) {
61                 case DataType::AUDIO:
62                         typestr = _("audio");
63                         break;
64                 case DataType::MIDI:
65                         typestr = _("MIDI");
66                         break;
67         }
68
69         vector<string> source_dirs = s->source_search_path (type);
70         vector<string>::iterator i = source_dirs.begin();
71         ostringstream oss;
72         oss << *i << endl;
73
74         while (++i != source_dirs.end()) {
75                 oss << *i << endl;
76         }
77
78         msg.set_justify (JUSTIFY_LEFT);
79         msg.set_markup (string_compose (_("%1 cannot find the %2 file\n\n<i>%3</i>\n\nin any of these folders:\n\n\
80                                         <tt>%4</tt>\n\n"), PROGRAM_NAME, typestr, Gtkmm2ext::markup_escape_text (path), Gtkmm2ext::markup_escape_text (oss.str())));
81
82         HBox* hbox = manage (new HBox);
83         hbox->pack_start (msg, false, true);
84         hbox->show ();
85
86         get_vbox()->pack_start (*hbox, false, false);
87
88         VBox* button_packer_box = manage (new VBox);
89
90         button_packer_box->set_spacing (6);
91         button_packer_box->set_border_width (12);
92
93         button_packer_box->pack_start (use_chosen, false, false);
94         button_packer_box->pack_start (this_missing_ok, false, false);
95         button_packer_box->pack_start (all_missing_ok, false, false);
96         button_packer_box->pack_start (stop_loading_button, false, false);
97
98         button_packer_box->show_all ();
99
100         get_vbox()->set_spacing (6);
101         get_vbox()->set_border_width (25);
102         get_vbox()->set_homogeneous (false);
103
104
105         hbox = manage (new HBox);
106         hbox->pack_start (*button_packer_box, false, true);
107         hbox->show ();
108
109         get_vbox()->pack_start (*hbox, false, false);
110
111         hbox = manage (new HBox);
112         Label* label = manage (new Label);
113         label->set_text (_("Click to choose an additional folder"));
114
115         hbox->set_spacing (6);
116         hbox->set_border_width (12);
117         hbox->pack_start (*label, false, false);
118         hbox->pack_start (chooser, true, true);
119         hbox->show_all ();
120
121         get_vbox()->pack_start (*hbox, true, true);
122
123         msg.show ();
124
125         Gtkmm2ext::add_volume_shortcuts (chooser);
126         chooser.set_current_folder (Glib::get_home_dir());
127         chooser.set_create_folders (false);
128 }
129
130 void
131 MissingFileDialog::set_absolute ()
132 {
133         _session->set_missing_file_replacement (chooser.get_filename ());
134 }
135
136 void
137 MissingFileDialog::add_chosen ()
138 {
139         string str;
140         string newdir;
141         vector<string> dirs;
142
143         switch (filetype) {
144                 case DataType::AUDIO:
145                         str = _session->config.get_audio_search_path();
146                         break;
147                 case DataType::MIDI:
148                         str = _session->config.get_midi_search_path();
149                         break;
150         }
151
152         split (str, dirs, G_SEARCHPATH_SEPARATOR);
153
154         newdir = chooser.get_filename ();
155
156         for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); d++) {
157                 if (*d == newdir) {
158                         return;
159                 }
160         }
161
162         if (!str.empty()) {
163                 str += G_SEARCHPATH_SEPARATOR;
164         }
165
166         str += newdir;
167
168         switch (filetype) {
169                 case DataType::AUDIO:
170                         _session->config.set_audio_search_path (str);
171                         break;
172                 case DataType::MIDI:
173                         _session->config.set_midi_search_path (str);
174                         break;
175         }
176 }
177
178 int
179 MissingFileDialog::get_action ()
180 {
181         if (use_chosen.get_active ()) {
182                 if (is_absolute_path) {
183                         set_absolute ();
184                 } else {
185                         add_chosen ();
186                 }
187                 return 0;
188         }
189
190         if (this_missing_ok.get_active()) {
191                 return -1;
192         }
193
194         if (all_missing_ok.get_active ()) {
195                 return 3;
196         }
197
198         return 1;
199 }