diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2007-08-16 23:17:35 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2007-08-16 23:17:35 +0000 |
commit | 327275f4c9381575021be96f2c67e23b378bd98c (patch) | |
tree | 0df7621510154ea6db6d7f53085d2686a2b602cf | |
parent | f433b4e735ab5ff5f7f7d89d38d0c25de3641cfa (diff) |
support DnD in native/gtk-quartz implementation (note: multifile DnD requires a patch to GTK that is not in distribution yet, so for now, this works only with 1 file at a time, or it requires my patch/library).
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2319 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/editor.cc | 33 | ||||
-rw-r--r-- | gtk2_ardour/editor.h | 4 | ||||
-rw-r--r-- | gtk2_ardour/editor_audio_import.cc | 28 | ||||
-rw-r--r-- | libs/midi++2/SConscript | 2 | ||||
-rw-r--r-- | libs/pbd/convert.cc | 47 | ||||
-rw-r--r-- | libs/pbd/pbd/convert.h | 2 |
6 files changed, 105 insertions, 11 deletions
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 3f84140232..b161c1498a 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2695,8 +2695,10 @@ Editor::convert_drop_to_paths (vector<ustring>& paths, vector<ustring> uris = data.get_uris(); + cerr << "there were " << uris.size() << " in that drag data\n"; + if (uris.empty()) { - + /* This is seriously fucked up. Nautilus doesn't say that its URI lists are actually URI lists. So do it by hand. */ @@ -2746,10 +2748,35 @@ Editor::convert_drop_to_paths (vector<ustring>& paths, } for (vector<ustring>::iterator i = uris.begin(); i != uris.end(); ++i) { + if ((*i).substr (0,7) == "file://") { - string p = *i; + + + ustring p = *i; PBD::url_decode (p); - paths.push_back (p.substr (7)); + + // scan forward past three slashes + + ustring::size_type slashcnt = 0; + ustring::size_type n = 0; + ustring::iterator x = p.begin(); + + while (slashcnt < 3 && x != p.end()) { + if ((*x) == '/') { + slashcnt++; + } else if (slashcnt == 3) { + break; + } + ++n; + ++x; + } + + if (slashcnt != 3 || x == p.end()) { + error << _("malformed URL passed to drag-n-drop code") << endmsg; + continue; + } + + paths.push_back (p.substr (n - 1)); } } diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index c21becc1ae..c5a99d44ca 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -964,7 +964,11 @@ class Editor : public PublicEditor void bring_in_external_audio (Editing::ImportMode mode, ARDOUR::AudioTrack*, nframes_t& pos, bool prompt); void do_import (vector<Glib::ustring> paths, bool split, Editing::ImportMode mode, ARDOUR::AudioTrack*, nframes_t&, bool); + + void _do_embed (vector<Glib::ustring> paths, bool split, Editing::ImportMode mode, ARDOUR::AudioTrack*, nframes_t&, bool); void do_embed (vector<Glib::ustring> paths, bool split, Editing::ImportMode mode, ARDOUR::AudioTrack*, nframes_t&, bool); + bool idle_do_embed (vector<Glib::ustring> paths, bool split, Editing::ImportMode mode, ARDOUR::AudioTrack*, nframes_t&, bool); + int import_sndfile (vector<Glib::ustring> paths, Editing::ImportMode mode, ARDOUR::AudioTrack* track, nframes_t& pos); int embed_sndfile (vector<Glib::ustring> paths, bool split, bool multiple_files, bool& check_sample_rate, Editing::ImportMode mode, ARDOUR::AudioTrack* track, nframes_t& pos, bool prompt); diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 5a70425480..2a81f85d7f 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -130,17 +130,32 @@ Editor::do_import (vector<ustring> paths, bool split, ImportMode mode, AudioTrac interthread_progress_window->hide_all (); } +bool +Editor::idle_do_embed (vector<ustring> paths, bool split, ImportMode mode, AudioTrack* track, nframes_t& pos, bool prompt) +{ + _do_embed (paths, split, mode, track, pos, prompt); + return false; +} + void Editor::do_embed (vector<ustring> paths, bool split, ImportMode mode, AudioTrack* track, nframes_t& pos, bool prompt) { +#ifdef GTKOSX + Glib::signal_idle().connect (bind (mem_fun (*this, &Editor::idle_do_embed), paths, split, mode, track, pos, prompt)); +#else + _do_embed (paths, split, mode, track, pos, prompt); +#endif +} + +void +Editor::_do_embed (vector<ustring> paths, bool split, ImportMode mode, AudioTrack* track, nframes_t& pos, bool prompt) +{ bool multiple_files = paths.size() > 1; bool check_sample_rate = true; vector<ustring>::iterator a; for (a = paths.begin(); a != paths.end(); ) { - cerr << "Considering embed of " << (*a) << endl; - Glib::ustring path = *a; Glib::ustring pair_base; vector<ustring> to_embed; @@ -208,7 +223,7 @@ Editor::do_embed (vector<ustring> paths, bool split, ImportMode mode, AudioTrack } } else { - + if (embed_sndfile (to_embed, split, multiple_files, check_sample_rate, mode, track, pos, prompt) < -1) { break; } @@ -321,15 +336,14 @@ Editor::embed_sndfile (vector<Glib::ustring> paths, bool split, bool multiple_fi } } } - } /* note that we temporarily truncated _id at the colon */ string error_msg; - + if (!AudioFileSource::get_soundfile_info (path, finfo, error_msg)) { - error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), selection, error_msg ) << endmsg; + error << string_compose(_("Editor: cannot open file \"%1\", (%2)"), path, error_msg ) << endmsg; goto out; } @@ -388,7 +402,7 @@ Editor::embed_sndfile (vector<Glib::ustring> paths, bool split, bool multiple_fi } track_canvas.get_window()->set_cursor (Gdk::Cursor (Gdk::WATCH)); - ARDOUR_UI::instance()->flush_pending (); + // ARDOUR_UI::instance()->flush_pending (); /* make the proper number of channels in the region */ diff --git a/libs/midi++2/SConscript b/libs/midi++2/SConscript index bc2c50cb2c..e3bf52df2b 100644 --- a/libs/midi++2/SConscript +++ b/libs/midi++2/SConscript @@ -7,7 +7,7 @@ import glob Import('env libraries install_prefix') midi2 = env.Copy() -midi2.Merge([ libraries['sigc2'], libraries['xml'], libraries['glib2'], libraries['pbd'] ]) +midi2.Merge([ libraries['sigc2'], libraries['xml'], libraries['glibmm2'], libraries['glib2'], libraries['pbd'] ]) domain = 'midipp' diff --git a/libs/pbd/convert.cc b/libs/pbd/convert.cc index ff426cfb80..3c27026546 100644 --- a/libs/pbd/convert.cc +++ b/libs/pbd/convert.cc @@ -32,6 +32,7 @@ using std::string; using std::vector; +using Glib::ustring; namespace PBD { @@ -196,6 +197,52 @@ url_decode (string& url) } } +void +url_decode (ustring& url) +{ + ustring::iterator last; + ustring::iterator next; + + for (ustring::iterator i = url.begin(); i != url.end(); ++i) { + if ((*i) == '+') { + next = i; + ++next; + url.replace (i, next, 1, ' '); + } + } + + if (url.length() <= 3) { + return; + } + + last = url.end(); + + --last; /* points at last char */ + --last; /* points at last char - 1 */ + + for (ustring::iterator i = url.begin(); i != last; ) { + + if (*i == '%') { + + next = i; + + url.erase (i); + + i = next; + ++next; + + if (isxdigit (*i) && isxdigit (*next)) { + /* replace first digit with char */ + url.replace (i, next, 1, (gunichar) int_from_hex (*i,*next)); + ++i; /* points at 2nd of 2 digits */ + url.erase (i); + } + } else { + ++i; + } + } +} + #if 0 string length2string (const int32_t frames, const float sample_rate) diff --git a/libs/pbd/pbd/convert.h b/libs/pbd/pbd/convert.h index 458e4aebe9..83cd285098 100644 --- a/libs/pbd/pbd/convert.h +++ b/libs/pbd/pbd/convert.h @@ -24,6 +24,7 @@ #include <vector> #include <sstream> #include <iostream> +#include <glibmm/ustring.h> namespace PBD { @@ -32,6 +33,7 @@ std::string short_version (std::string, std::string::size_type target_length); int atoi (const std::string&); double atof (const std::string&); void url_decode (std::string&); +void url_decode (Glib::ustring&); // std::string length2string (const int32_t frames, const float sample_rate); std::string length2string (const int64_t frames, const double sample_rate); |