From 4720a4586874001ee5cd8150676016b17886d8bc Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 13 Dec 2021 22:50:04 +0100 Subject: [PATCH] Make convert_drop_to_paths() reusable --- gtk2_ardour/editor.cc | 85 ----------------------------------- gtk2_ardour/editor.h | 10 ----- gtk2_ardour/editor_canvas.cc | 5 +-- gtk2_ardour/editor_regions.cc | 2 +- gtk2_ardour/utils.cc | 68 ++++++++++++++++++++++++++++ gtk2_ardour/utils.h | 2 + 6 files changed, 73 insertions(+), 99 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 51a5edf1fe..9e951c622c 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -3499,91 +3499,6 @@ Editor::setup_tooltips () set_tooltip (nudge_clock, _("Nudge Clock\n(controls distance used to nudge regions and selections)")); } -int -Editor::convert_drop_to_paths ( - vector& paths, - const RefPtr& /*context*/, - gint /*x*/, - gint /*y*/, - const SelectionData& data, - guint /*info*/, - guint /*time*/) -{ - if (_session == 0) { - return -1; - } - - vector uris = data.get_uris(); - - 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. - */ - - if (data.get_target() != "text/plain") { - return -1; - } - - /* Parse the "uri-list" format that Nautilus provides, - where each pathname is delimited by \r\n. - - THERE MAY BE NO NULL TERMINATING CHAR!!! - */ - - string txt = data.get_text(); - char* p; - const char* q; - - p = (char *) malloc (txt.length() + 1); - txt.copy (p, txt.length(), 0); - p[txt.length()] = '\0'; - - while (p) - { - if (*p != '#') - { - while (g_ascii_isspace (*p)) - p++; - - q = p; - while (*q && (*q != '\n') && (*q != '\r')) { - q++; - } - - if (q > p) - { - q--; - while (q > p && g_ascii_isspace (*q)) - q--; - - if (q > p) - { - uris.push_back (string (p, q - p + 1)); - } - } - } - p = strchr (p, '\n'); - if (p) - p++; - } - - free ((void*)p); - - if (uris.empty()) { - return -1; - } - } - - for (vector::iterator i = uris.begin(); i != uris.end(); ++i) { - if ((*i).substr (0,7) == "file://") { - paths.push_back (Glib::filename_from_uri (*i)); - } - } - - return 0; -} - void Editor::new_tempo_section () { diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 4ee78a54e5..442757334a 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -2076,16 +2076,6 @@ private: bool show_gain_after_trim; /* Drag-n-Drop */ - - int convert_drop_to_paths ( - std::vector& paths, - const Glib::RefPtr& context, - gint x, - gint y, - const Gtk::SelectionData& data, - guint info, - guint time); - void track_canvas_drag_data_received ( const Glib::RefPtr& context, gint x, diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 168f6ee91a..193b338fb3 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -464,10 +464,9 @@ Editor::drop_paths (const RefPtr& context, GdkEvent ev; double cy; - if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) { + if (_session && convert_drop_to_paths (paths, data)) { - /* D-n-D coordinates are window-relative, so convert to canvas coordinates - */ + /* D-n-D coordinates are window-relative, so convert to canvas coordinates */ ev.type = GDK_BUTTON_RELEASE; ev.button.x = x; diff --git a/gtk2_ardour/editor_regions.cc b/gtk2_ardour/editor_regions.cc index d8428cb186..b714645884 100644 --- a/gtk2_ardour/editor_regions.cc +++ b/gtk2_ardour/editor_regions.cc @@ -1029,7 +1029,7 @@ EditorRegions::drag_data_received (const RefPtr& context, return; } - if (_editor->convert_drop_to_paths (paths, context, x, y, data, info, dtime) == 0) { + if (_session && convert_drop_to_paths (paths, data)) { timepos_t pos; bool copy = ((context->get_actions () & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY); diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 1fd4f7c26d..62c8084619 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -869,3 +869,71 @@ ARDOUR_UI_UTILS::shared_popup_menu () { return ARDOUR_UI::instance()->shared_popup_menu (); } + +bool +ARDOUR_UI_UTILS::convert_drop_to_paths (vector& paths, const SelectionData& data) +{ + vector uris = data.get_uris(); + + 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. + */ + if (data.get_target() != "text/plain") { + return false; + } + + /* Parse the "uri-list" format that Nautilus provides, + * where each pathname is delimited by \r\n. + * + * THERE MAY BE NO NULL TERMINATING CHAR!!! + */ + string txt = data.get_text(); + + char* p = (char *) malloc (txt.length() + 1); + txt.copy (p, txt.length(), 0); + p[txt.length()] = '\0'; + + while (p) { + if (*p != '#') { + while (g_ascii_isspace (*p)) { + p++; + } + + const char* q = p; + while (*q && (*q != '\n') && (*q != '\r')) { + q++; + } + + if (q > p) { + --q; + while (q > p && g_ascii_isspace (*q)) { + --q; + } + + if (q > p) { + uris.push_back (string (p, q - p + 1)); + } + } + } + p = strchr (p, '\n'); + if (p) { + ++p; + } + } + + free ((void*)p); + + if (uris.empty()) { + return false; + } + } + + for (vector::iterator i = uris.begin(); i != uris.end(); ++i) { + if ((*i).substr (0,7) == "file://") { + paths.push_back (Glib::filename_from_uri (*i)); + } + } + + return !paths.empty (); +} diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index bbf4233398..71d4981cf6 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -110,5 +110,7 @@ bool running_from_source_tree (); void inhibit_screensaver (bool); +bool convert_drop_to_paths (std::vector&, const Gtk::SelectionData&); + } // namespace #endif /* __ardour_gtk_utils_h__ */