From eb5870781a5173b1cbfc2dd4e975be29e5d00a99 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 14 Dec 2010 02:45:41 +0000 Subject: [PATCH] Add dialogue to ask user about ambiguous source files. Fixes #3603. git-svn-id: svn://localhost/ardour2/branches/3.0@8265 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ambiguous_file_dialog.cc | 63 ++++++++++++++++++++++++++++ gtk2_ardour/ambiguous_file_dialog.h | 35 ++++++++++++++++ gtk2_ardour/ardour_ui.cc | 17 ++++++++ gtk2_ardour/ardour_ui.h | 1 + gtk2_ardour/wscript | 1 + 5 files changed, 117 insertions(+) create mode 100644 gtk2_ardour/ambiguous_file_dialog.cc create mode 100644 gtk2_ardour/ambiguous_file_dialog.h diff --git a/gtk2_ardour/ambiguous_file_dialog.cc b/gtk2_ardour/ambiguous_file_dialog.cc new file mode 100644 index 0000000000..e14d33540e --- /dev/null +++ b/gtk2_ardour/ambiguous_file_dialog.cc @@ -0,0 +1,63 @@ +/* + Copyright (C) 2010 Paul Davis + Author: Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "ambiguous_file_dialog.h" + +using namespace std; +using namespace ARDOUR; +using namespace Gtk; + +AmbiguousFileDialog::AmbiguousFileDialog (const string& file, const vector& paths) + : ArdourDialog (_("Ambiguous File"), true, false) +{ + get_vbox()->set_spacing (6); + + Label* l = manage (new Label); + l->set_markup (string_compose (_("Ardour has found the file %1 in the following places:\n\n"), file)); + get_vbox()->pack_start (*l); + + for (vector::const_iterator i = paths.begin(); i != paths.end(); ++i) { + _radio_buttons.push_back (manage (new RadioButton (_group, *i))); + get_vbox()->pack_start (*_radio_buttons.back ()); + } + + get_vbox()->pack_start (*manage (new Label (_("\n\nPlease select the path that you want to get the file from.")))); + + add_button (_("Done"), RESPONSE_OK); + + show_all (); +} + +int +AmbiguousFileDialog::get_which () const +{ + int i = 0; + vector::const_iterator j = _radio_buttons.begin (); + while (j != _radio_buttons.end() && !(*j)->get_active ()) { + ++i; + ++j; + } + + if (j == _radio_buttons.end()) { + return 0; + } + + return i; +} diff --git a/gtk2_ardour/ambiguous_file_dialog.h b/gtk2_ardour/ambiguous_file_dialog.h new file mode 100644 index 0000000000..ea20b42151 --- /dev/null +++ b/gtk2_ardour/ambiguous_file_dialog.h @@ -0,0 +1,35 @@ +/* + Copyright (C) 2010 Paul Davis + Author: Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "ardour_dialog.h" + +class AmbiguousFileDialog : public ArdourDialog +{ +public: + AmbiguousFileDialog (const std::string &, const std::vector &); + + int get_which () const; + +private: + Gtk::RadioButtonGroup _group; + std::vector _radio_buttons; +}; + + diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 6ca987c8ab..f07153ae36 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -107,6 +107,7 @@ typedef uint64_t microseconds_t; #include "location_ui.h" #include "missing_file_dialog.h" #include "missing_plugin_dialog.h" +#include "ambiguous_file_dialog.h" #include "i18n.h" @@ -274,6 +275,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[]) ARDOUR::Session::MissingFile.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::missing_file, this, _1, _2, _3)); + /* and ambiguous files */ + + ARDOUR::FileSource::AmbiguousFileName.connect_same_thread (forever_connections, boost::bind (&ARDOUR_UI::ambiguous_file, this, _1, _2, _3)); + /* lets get this party started */ try { @@ -3733,3 +3738,15 @@ ARDOUR_UI::missing_file (Session*s, std::string str, DataType type) return result; } + +int +ARDOUR_UI::ambiguous_file (std::string file, std::string path, std::vector hits) +{ + AmbiguousFileDialog dialog (file, hits); + + dialog.show (); + dialog.present (); + + dialog.run (); + return dialog.get_which (); +} diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index fa21389741..d09084c39d 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -714,6 +714,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr std::list _window_proxies; int missing_file (ARDOUR::Session*s, std::string str, ARDOUR::DataType type); + int ambiguous_file (std::string file, std::string path, std::vector hits); }; #endif /* __ardour_gui_h__ */ diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 20ba7b3eaf..9d48504f23 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -28,6 +28,7 @@ gtk2_ardour_sources = [ 'actions.cc', 'add_midi_cc_track_dialog.cc', 'add_route_dialog.cc', + 'ambiguous_file_dialog.cc', 'analysis_window.cc', 'ardour_dialog.cc', 'ardour_ui.cc',