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