update drobilla's fascistic dir-locals.el to force emacs users into whitespace submis...
[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
27 using namespace Gtk;
28 using namespace std;
29 using namespace ARDOUR;
30 using namespace PBD;
31
32 MissingFileDialog::MissingFileDialog (Session* s, const std::string& path, DataType type)
33         : ArdourDialog (_("Missing File!"), true, false)
34         , filetype (type)
35         , chooser (_("Select a folder to search"), FILE_CHOOSER_ACTION_SELECT_FOLDER)
36         , use_chosen (_("Add chosen folder to search path, and try again"))
37         , choice_group (use_chosen.get_group())
38         , stop_loading_button (choice_group, _("Stop loading this session"), false)
39         , all_missing_ok (choice_group, _("Skip all missing files"), false)
40         , this_missing_ok (choice_group, _("Skip this file"), false)
41 {
42         set_session (s);
43
44         add_button (_("Done"), RESPONSE_OK);
45
46         string typestr;
47
48         switch (type) {
49         case DataType::AUDIO:
50                 typestr = _("audio");
51                 break;
52         case DataType::MIDI:
53                 typestr = _("MIDI");
54                 break;
55         }
56
57         string dirstr;
58
59         dirstr = s->source_search_path (type);
60         cerr << "Search path = " << dirstr << endl;
61         replace_all (dirstr, ":", "\n");
62
63         msg.set_justify (JUSTIFY_CENTER);
64         msg.set_markup (string_compose (_("%1 cannot find the %2 file\n\n<i>%3</i>\n\nin any of these folders:\n\n\
65 <tt>%4</tt>\n\n"), PROGRAM_NAME, typestr, path, dirstr));
66
67         HBox* hbox = manage (new HBox);
68         hbox->pack_start (msg, false, true);
69         hbox->show ();
70
71         get_vbox()->pack_start (*hbox, false, false);
72
73         VBox* button_packer_box = manage (new VBox);
74
75         button_packer_box->set_spacing (6);
76         button_packer_box->set_border_width (12);
77
78         button_packer_box->pack_start (use_chosen, false, false);
79         button_packer_box->pack_start (this_missing_ok, false, false);
80         button_packer_box->pack_start (all_missing_ok, false, false);
81         button_packer_box->pack_start (stop_loading_button, false, false);
82
83         button_packer_box->show_all ();
84         
85         get_vbox()->set_spacing (6);
86         get_vbox()->set_border_width (25);
87         get_vbox()->set_homogeneous (false);
88
89
90         hbox = manage (new HBox);
91         hbox->pack_start (*button_packer_box, false, true);
92         hbox->show ();
93
94         get_vbox()->pack_start (*hbox, false, false);
95
96         hbox = manage (new HBox);
97         Label* label = manage (new Label);
98         label->set_text (_("Click to choose an additional folder"));
99
100         hbox->set_spacing (6);
101         hbox->set_border_width (12);
102         hbox->pack_start (*label, false, false);
103         hbox->pack_start (chooser, true, true);
104         hbox->show_all ();
105
106         get_vbox()->pack_start (*hbox, true, true);
107
108         msg.show ();
109
110         chooser.set_current_folder (Glib::get_home_dir());
111         chooser.set_create_folders (false);
112 }
113
114 void
115 MissingFileDialog::add_chosen ()
116 {
117         string str;
118         string newdir;
119         vector<string> dirs;
120
121         switch (filetype) {
122         case DataType::AUDIO:
123                 str = _session->config.get_audio_search_path();
124                 break;
125         case DataType::MIDI:
126                 str = _session->config.get_midi_search_path();
127                 break;
128         }
129
130         split (str, dirs, ':');
131
132         newdir = chooser.get_filename ();
133
134         for (vector<string>::iterator d = dirs.begin(); d != dirs.end(); d++) {
135                 if (*d == newdir) {
136                         return;
137                 }
138         }
139
140         if (!str.empty()) {
141                 str += ':';
142         } 
143         
144         str += newdir;
145
146         switch (filetype) {
147         case DataType::AUDIO:
148                 _session->config.set_audio_search_path (str);
149                 break;
150         case DataType::MIDI:
151                 _session->config.set_midi_search_path (str);
152                 break;
153         }
154 }
155
156 int
157 MissingFileDialog::get_action ()
158 {
159         if (use_chosen.get_active ()) {
160                 add_chosen ();
161                 return 0;
162         }
163
164         if (this_missing_ok.get_active()) {
165                 return -1;
166         }
167
168         if (all_missing_ok.get_active ()) {
169                 return 3;
170         }
171
172         return 1;
173 }