+/** @brief Called to extract the dragged data from the source queuelike
+ * @param w Source widget (the tree view)
+ * @param dc Drag context
+ * @param data Where to put the answer
+ * @param info_ Target @c info parameter
+ * @param time_ Time data requested (for some reason not a @c time_t)
+ * @param user_data The queuelike
+ *
+ * The list of tracks is converted into a single string, consisting of IDs
+ * and track names. Each is terminated by a newline. Including both ID and
+ * track name means that the receiver can use whichever happens to be more
+ * convenient.
+ *
+ * If there are no IDs for rows in this widget then the ID half is undefined.
+ *
+ * This is the handler for the "drag-data-get" signal.
+ */
+static void ql_drag_data_get(GtkWidget attribute((unused)) *w,
+ GdkDragContext attribute((unused)) *dc,
+ GtkSelectionData *data,
+ guint attribute((unused)) info,
+ guint attribute((unused)) time_,
+ gpointer user_data) {
+ struct queuelike *const ql = user_data;
+ struct dynstr result[1];
+
+ //fprintf(stderr, "ql_drag_data_get %s info=%d\n", ql->name, info);
+ dynstr_init(result);
+ gtk_tree_selection_selected_foreach(ql->selection,
+ ql_drag_data_get_collect,
+ result);
+ // TODO must not be able to drag playing track!
+ //fprintf(stderr, "drag-data-get: %.*s\n",
+ // result->nvec, result->vec);
+ /* gtk_selection_data_set_text() insists that data->target is one of a
+ * variety of stringy atoms. TODO: where does this value actually come
+ * from? */
+ gtk_selection_data_set(data,
+ GDK_TARGET_STRING,
+ 8, (guchar *)result->vec, result->nvec);
+}
+
+/** @brief Called when drag data is received
+ * @param w Target widget (the tree view)
+ * @param dc Drag context
+ * @param x The drop location
+ * @param y The drop location
+ * @param data The selection data
+ * @param info_ The target type that was chosen
+ * @param time_ Time data received (for some reason not a @c time_t)
+ * @param user_data The queuelike
+ *
+ * This is the handler for the "drag-data-received" signal.
+ */
+static void ql_drag_data_received(GtkWidget attribute((unused)) *w,
+ GdkDragContext attribute((unused)) *dc,
+ gint x,
+ gint y,
+ GtkSelectionData *data,
+ guint info_,
+ guint attribute((unused)) time_,
+ gpointer user_data) {
+ struct queuelike *const ql = user_data;
+ char *result, *p;
+ struct vector ids[1], tracks[1];
+ int parity = 0;
+
+ //fprintf(stderr, "drag-data-received: %d,%d info=%u\n", x, y, info_);
+ /* Get the selection string */
+ p = result = (char *)gtk_selection_data_get_text(data);
+ if(!result) {
+ //fprintf(stderr, "gtk_selection_data_get_text() returned NULL\n");
+ return;
+ }
+ //fprintf(stderr, "%s--\n", result);
+ /* Parse it back into IDs and track names */
+ vector_init(ids);
+ vector_init(tracks);
+ while(*p) {
+ char *nl = strchr(p, '\n');
+ if(!nl)
+ break;
+ *nl = 0;
+ //fprintf(stderr, " %s\n", p);
+ vector_append(parity++ & 1 ? tracks : ids, xstrdup(p));
+ p = nl + 1;