tempo map debugging with dlp
[ardour.git] / gtk2_ardour / missing_file_dialog.cc
1 /*
2     Copyright (C) 2010 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 #include "pbd/compose.h"
20 #include "pbd/replace_all.h"
21 #include "pbd/strsplit.h"
22
23 #include "ardour/session.h"
24
25 #include "missing_file_dialog.h"
26 #include "i18n.h"
27
28 using namespace Gtk;
29 using namespace std;
30 using namespace ARDOUR;
31 using namespace PBD;
32
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)
42 {
43         set_session (s);
44
45         add_button (_("Done"), RESPONSE_OK);
46         set_default_response (RESPONSE_OK);
47
48         string typestr;
49
50         switch (type) {
51         case DataType::AUDIO:
52                 typestr = _("audio");
53                 break;
54         case DataType::MIDI:
55                 typestr = _("MIDI");
56                 break;
57         }
58
59         string dirstr;
60
61         dirstr = s->source_search_path (type);
62         cerr << "Search path = " << dirstr << endl;
63         replace_all (dirstr, ":", "\n");
64
65         msg.set_justify (JUSTIFY_CENTER);
66         msg.set_markup (string_compose (_("%1 cannot find the %2 file\n\n<i>%3</i>\n\nin any of these folders:\n\n\
67 <tt>%4</tt>\n\n"), PROGRAM_NAME, typestr, path, dirstr));
68
69         HBox* hbox = manage (new HBox);
70         hbox->pack_start (msg, false, true);
71         hbox->show ();
72
73         get_vbox()->pack_start (*hbox, false, false);
74
75         VBox* button_packer_box = manage (new VBox);
76
77         button_packer_box->set_spacing (6);
78         button_packer_box->set_border_width (12);
79
80         button_packer_box->pack_start (use_chosen, false, false);
81         button_packer_box->pack_start (this_missing_ok, false, false);
82         button_packer_box->pack_start (all_missing_ok, false, false);
83         button_packer_box->pack_start (stop_loading_button, false, false);
84
85         button_packer_box->show_all ();
86
87         get_vbox()->set_spacing (6);
88         get_vbox()->set_border_width (25);
89         get_vbox()->set_homogeneous (false);
90
91
92         hbox = manage (new HBox);
93         hbox->pack_start (*button_packer_box, false, true);
94         hbox->show ();
95
96         get_vbox()->pack_start (*hbox, false, false);
97
98         hbox = manage (new HBox);
99         Label* label = manage (new Label);
100         label->set_text (_("Click to choose an additional folder"));
101
102         hbox->set_spacing (6);
103         hbox->set_border_width (12);
104         hbox->pack_start (*label, false, false);
105         hbox->pack_start (chooser, true, true);
106         hbox->show_all ();
107
108         get_vbox()->pack_start (*hbox, true, true);
109
110         msg.show ();
111
112         chooser.set_current_folder (Glib::get_home_dir());
113         chooser.set_create_folders (false);
114 }
115
116 void
117 MissingFileDialog::add_chosen ()
118 {
119         string str;
120         string newdir;
121         vector<string> dirs;
122
123         switch (filetype) {
124         case DataType::AUDIO:
125                 str = _session->config.get_audio_search_path();
126                 break;
127         case DataType::MIDI:
128                 str = _session->config.get_midi_search_path();
129                 break;
130         }
131
132         split (str, dirs, ':');
133
134         newdir = chooser.get_filename ();
135
136         for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); d++) {
137                 if (*d == newdir) {
138                         return;
139                 }
140         }
141
142         if (!str.empty()) {
143                 str += ':';
144         }
145
146         str += newdir;
147
148         switch (filetype) {
149         case DataType::AUDIO:
150                 _session->config.set_audio_search_path (str);
151                 break;
152         case DataType::MIDI:
153                 _session->config.set_midi_search_path (str);
154                 break;
155         }
156 }
157
158 int
159 MissingFileDialog::get_action ()
160 {
161         if (use_chosen.get_active ()) {
162                 add_chosen ();
163                 return 0;
164         }
165
166         if (this_missing_ok.get_active()) {
167                 return -1;
168         }
169
170         if (all_missing_ok.get_active ()) {
171                 return 3;
172         }
173
174         return 1;
175 }