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