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>
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.
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.
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.
23 #include "pbd/compose.h"
24 #include "pbd/replace_all.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/search_path.h"
28 #include "ardour/session.h"
29 #include "gtkmm2ext/utils.h"
31 #include "missing_file_dialog.h"
36 using namespace ARDOUR;
39 MissingFileDialog::MissingFileDialog (Session* s, const std::string& path, DataType type)
40 : ArdourDialog (_("Missing File"), true, false)
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)
50 /* This dialog is always shown programatically. Center the window.*/
51 set_position (Gtk::WIN_POS_CENTER);
55 add_button (_("Done"), RESPONSE_OK);
56 set_default_response (RESPONSE_OK);
69 vector<string> source_dirs = s->source_search_path (type);
70 vector<string>::iterator i = source_dirs.begin();
74 while (++i != source_dirs.end()) {
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())));
82 HBox* hbox = manage (new HBox);
83 hbox->pack_start (msg, false, true);
86 get_vbox()->pack_start (*hbox, false, false);
88 VBox* button_packer_box = manage (new VBox);
90 button_packer_box->set_spacing (6);
91 button_packer_box->set_border_width (12);
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);
98 button_packer_box->show_all ();
100 get_vbox()->set_spacing (6);
101 get_vbox()->set_border_width (25);
102 get_vbox()->set_homogeneous (false);
105 hbox = manage (new HBox);
106 hbox->pack_start (*button_packer_box, false, true);
109 get_vbox()->pack_start (*hbox, false, false);
111 hbox = manage (new HBox);
112 Label* label = manage (new Label);
113 label->set_text (_("Click to choose an additional folder"));
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);
121 get_vbox()->pack_start (*hbox, true, true);
125 Gtkmm2ext::add_volume_shortcuts (chooser);
126 chooser.set_current_folder (Glib::get_home_dir());
127 chooser.set_create_folders (false);
131 MissingFileDialog::set_absolute ()
133 _session->set_missing_file_replacement (chooser.get_filename ());
137 MissingFileDialog::add_chosen ()
144 case DataType::AUDIO:
145 str = _session->config.get_audio_search_path();
148 str = _session->config.get_midi_search_path();
152 split (str, dirs, G_SEARCHPATH_SEPARATOR);
154 newdir = chooser.get_filename ();
156 for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); d++) {
163 str += G_SEARCHPATH_SEPARATOR;
169 case DataType::AUDIO:
170 _session->config.set_audio_search_path (str);
173 _session->config.set_midi_search_path (str);
179 MissingFileDialog::get_action ()
181 if (use_chosen.get_active ()) {
182 if (is_absolute_path) {
190 if (this_missing_ok.get_active()) {
194 if (all_missing_ok.get_active ()) {