various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / gtk2_ardour / missing_file_dialog.cc
blob9d5712ee6134aae54855d601a61b4283e128b6c9
1 /*
2 Copyright (C) 2010 Paul Davis
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.
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.
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.
19 #include "pbd/compose.h"
20 #include "pbd/replace_all.h"
21 #include "pbd/strsplit.h"
23 #include "ardour/session.h"
25 #include "missing_file_dialog.h"
26 #include "i18n.h"
28 using namespace Gtk;
29 using namespace std;
30 using namespace ARDOUR;
31 using namespace PBD;
33 MissingFileDialog::MissingFileDialog (Session* s, const std::string& path, DataType type)
34 : ArdourDialog (_("Missing File!"), true, false)
35 , filetype (type)
36 , chooser (_("Select a folder to search"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
37 , use_chosen (_("Add chosen folder to search path, and try again"))
38 , choice_group (use_chosen.get_group())
39 , stop_loading_button (choice_group, _("Stop loading this session"), false)
40 , all_missing_ok (choice_group, _("Skip all missing files"), false)
41 , this_missing_ok (choice_group, _("Skip this file"), false)
43 set_session (s);
45 add_button (_("Done"), RESPONSE_OK);
47 string typestr;
49 switch (type) {
50 case DataType::AUDIO:
51 typestr = _("audio");
52 break;
53 case DataType::MIDI:
54 typestr = _("MIDI");
55 break;
58 string dirstr;
60 dirstr = s->source_search_path (type);
61 cerr << "Search path = " << dirstr << endl;
62 replace_all (dirstr, ":", "\n");
64 msg.set_justify (JUSTIFY_CENTER);
65 msg.set_markup (string_compose (_("%1 cannot find the %2 file\n\n<i>%3</i>\n\nin any of these folders:\n\n\
66 <tt>%4</tt>\n\n"), PROGRAM_NAME, typestr, path, dirstr));
68 HBox* hbox = manage (new HBox);
69 hbox->pack_start (msg, false, true);
70 hbox->show ();
72 get_vbox()->pack_start (*hbox, false, false);
74 VBox* button_packer_box = manage (new VBox);
76 button_packer_box->set_spacing (6);
77 button_packer_box->set_border_width (12);
79 button_packer_box->pack_start (use_chosen, false, false);
80 button_packer_box->pack_start (this_missing_ok, false, false);
81 button_packer_box->pack_start (all_missing_ok, false, false);
82 button_packer_box->pack_start (stop_loading_button, false, false);
84 button_packer_box->show_all ();
86 get_vbox()->set_spacing (6);
87 get_vbox()->set_border_width (25);
88 get_vbox()->set_homogeneous (false);
91 hbox = manage (new HBox);
92 hbox->pack_start (*button_packer_box, false, true);
93 hbox->show ();
95 get_vbox()->pack_start (*hbox, false, false);
97 hbox = manage (new HBox);
98 Label* label = manage (new Label);
99 label->set_text (_("Click to choose an additional folder"));
101 hbox->set_spacing (6);
102 hbox->set_border_width (12);
103 hbox->pack_start (*label, false, false);
104 hbox->pack_start (chooser, true, true);
105 hbox->show_all ();
107 get_vbox()->pack_start (*hbox, true, true);
109 msg.show ();
111 chooser.set_current_folder (Glib::get_home_dir());
112 chooser.set_create_folders (false);
115 void
116 MissingFileDialog::add_chosen ()
118 string str;
119 string newdir;
120 vector<string> dirs;
122 switch (filetype) {
123 case DataType::AUDIO:
124 str = _session->config.get_audio_search_path();
125 break;
126 case DataType::MIDI:
127 str = _session->config.get_midi_search_path();
128 break;
131 split (str, dirs, ':');
133 newdir = chooser.get_filename ();
135 for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); d++) {
136 if (*d == newdir) {
137 return;
141 if (!str.empty()) {
142 str += ':';
145 str += newdir;
147 switch (filetype) {
148 case DataType::AUDIO:
149 _session->config.set_audio_search_path (str);
150 break;
151 case DataType::MIDI:
152 _session->config.set_midi_search_path (str);
153 break;
158 MissingFileDialog::get_action ()
160 if (use_chosen.get_active ()) {
161 add_chosen ();
162 return 0;
165 if (this_missing_ok.get_active()) {
166 return -1;
169 if (all_missing_ok.get_active ()) {
170 return 3;
173 return 1;