2 * This file is part of DisOrder
3 * Copyright (C) 2006-2009 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file disobedience/queue-generic.c
19 * @brief Disobedience queue widgets
21 * This file provides contains code shared between all the queue-like
22 * widgets - the queue, the recent list and the added tracks list.
24 * This code is in the process of being rewritten to use the native list
27 * There are three @ref queuelike objects: @ref ql_queue, @ref
28 * ql_recent and @ref ql_added. Each has an associated queue linked
29 * list and a list store containing the contents.
31 * When new contents turn up we rearrange the list store accordingly.
33 * NB that while in the server the playing track is not in the queue, in
34 * Disobedience, the playing does live in @c ql_queue.q, despite its different
35 * status to everything else found in that list.
38 * - display playing row in a different color?
40 #include "disobedience.h"
42 #include "queue-generic.h"
45 static const GtkTargetEntry queuelike_targets[] = {
47 (char *)"text/x-disorder-track-data", /* drag type */
48 GTK_TARGET_SAME_WIDGET, /* rearrangement only for now */
53 /* Track detail lookup ----------------------------------------------------- */
55 static void queue_lookups_completed(const char attribute((unused)) *event,
56 void attribute((unused)) *eventdata,
58 struct queuelike *ql = callbackdata;
59 ql_update_list_store(ql);
62 /* Column formatting -------------------------------------------------------- */
64 /** @brief Format the 'when' column */
65 const char *column_when(const struct queue_entry *q,
66 const char attribute((unused)) *data) {
73 case playing_isscratch:
74 case playing_unplayed:
79 case playing_no_player:
81 case playing_scratched:
84 case playing_quitting:
92 strftime(when, sizeof when, "%H:%M", localtime_r(&t, &tm));
98 /** @brief Format the 'who' column */
99 const char *column_who(const struct queue_entry *q,
100 const char attribute((unused)) *data) {
102 return q->submitter ? q->submitter : "";
105 /** @brief Format one of the track name columns */
106 const char *column_namepart(const struct queue_entry *q,
108 D(("column_namepart"));
109 return namepart(q->track, "display", data);
112 /** @brief Format the length column */
113 const char *column_length(const struct queue_entry *q,
114 const char attribute((unused)) *data) {
115 D(("column_length"));
118 char *played = 0, *length = 0;
120 /* Work out what to say for the length */
121 l = namepart_length(q->track);
123 byte_xasprintf(&length, "%ld:%02ld", l / 60, l % 60);
125 byte_xasprintf(&length, "?:??");
126 /* For the currently playing track we want to report how much of the track
128 if(q == playing_track) {
129 /* log_state() arranges that we re-get the playing data whenever the
130 * pause/resume state changes */
131 if(last_state & DISORDER_TRACK_PAUSED)
132 l = playing_track->sofar;
137 l = playing_track->sofar + (now - last_playing);
139 byte_xasprintf(&played, "%ld:%02ld/%s", l / 60, l % 60, length);
145 /* List store maintenance -------------------------------------------------- */
147 /** @brief Return the @ref queue_entry corresponding to @p iter
148 * @param model Model that owns @p iter
149 * @param iter Tree iterator
150 * @return Pointer to queue entry
152 struct queue_entry *ql_iter_to_q(GtkTreeModel *model,
154 struct queuelike *ql = g_object_get_data(G_OBJECT(model), "ql");
156 memset(v, 0, sizeof v);
157 gtk_tree_model_get_value(model, iter, ql->ncolumns + QUEUEPOINTER_COLUMN, v);
158 assert(G_VALUE_TYPE(v) == G_TYPE_POINTER);
159 struct queue_entry *const q = g_value_get_pointer(v);
164 /** @brief Return the @ref queue_entry corresponding to @p path
165 * @param model Model to query
166 * @param path Path into tree
167 * @return Pointer to queue entry or NULL
169 struct queue_entry *ql_path_to_q(GtkTreeModel *model,
172 if(!gtk_tree_model_get_iter(model, iter, path))
174 return ql_iter_to_q(model, iter);
177 /** @brief Update one row of a list store
178 * @param q Queue entry
179 * @param iter Iterator referring to row or NULL to work it out
181 void ql_update_row(struct queue_entry *q,
183 const struct queuelike *const ql = q->ql;
185 D(("ql_update_row"));
186 /* If no iter was supplied, work it out */
187 GtkTreeIter my_iter[1];
189 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store), my_iter);
190 struct queue_entry *qq;
191 for(qq = ql->q; qq && q != qq; qq = qq->next)
192 gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), my_iter);
197 /* Update all the columns */
198 for(int col = 0; col < ql->ncolumns; ++col) {
199 const char *const v = ql->columns[col].value(q,
200 ql->columns[col].data);
202 gtk_list_store_set(ql->store, iter,
206 gtk_list_store_set(ql->store, iter,
207 ql->ncolumns + QUEUEPOINTER_COLUMN, q,
209 if(q == playing_track)
210 gtk_list_store_set(ql->store, iter,
211 ql->ncolumns + BACKGROUND_COLUMN, BG_PLAYING,
212 ql->ncolumns + FOREGROUND_COLUMN, FG_PLAYING,
215 gtk_list_store_set(ql->store, iter,
216 ql->ncolumns + BACKGROUND_COLUMN, (char *)0,
217 ql->ncolumns + FOREGROUND_COLUMN, (char *)0,
221 /** @brief Update the list store
222 * @param ql Queuelike to update
224 * Called when new namepart data is available (and initially). Doesn't change
225 * the rows, just updates the cell values.
227 void ql_update_list_store(struct queuelike *ql) {
228 D(("ql_update_list_store"));
230 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store), iter);
231 for(struct queue_entry *q = ql->q; q; q = q->next) {
232 ql_update_row(q, iter);
233 gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), iter);
237 struct newqueue_data {
238 struct queue_entry *old, *new;
241 static void record_queue_map(hash *h,
243 struct queue_entry *old,
244 struct queue_entry *new) {
245 struct newqueue_data *nqd;
247 if(!(nqd = hash_find(h, id))) {
248 static const struct newqueue_data empty[1];
249 hash_add(h, id, empty, HASH_INSERT);
250 nqd = hash_find(h, id);
259 static void dump_queue(struct queue_entry *head, struct queue_entry *mark) {
260 for(struct queue_entry *q = head; q; q = q->next) {
262 fprintf(stderr, "!");
263 fprintf(stderr, "%s", q->id);
265 fprintf(stderr, " ");
267 fprintf(stderr, "\n");
270 static void dump_rows(struct queuelike *ql) {
272 gboolean it = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store),
275 struct queue_entry *q = ql_iter_to_q(GTK_TREE_MODEL(ql->store), iter);
276 it = gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), iter);
277 fprintf(stderr, "%s", q->id);
279 fprintf(stderr, " ");
281 fprintf(stderr, "\n");
285 /** @brief Reset the list store
286 * @param ql Queuelike to reset
287 * @param newq New queue contents/ordering
289 * Updates the queue to match @p newq
291 void ql_new_queue(struct queuelike *ql,
292 struct queue_entry *newq) {
296 /* Tell every queue entry which queue owns it */
297 //fprintf(stderr, "%s: filling in q->ql\n", ql->name);
298 for(struct queue_entry *q = newq; q; q = q->next)
301 //fprintf(stderr, "%s: constructing h\n", ql->name);
302 /* Construct map from id to new and old structures */
303 hash *h = hash_new(sizeof(struct newqueue_data));
304 for(struct queue_entry *q = ql->q; q; q = q->next)
305 record_queue_map(h, q->id, q, NULL);
306 for(struct queue_entry *q = newq; q; q = q->next)
307 record_queue_map(h, q->id, NULL, q);
309 /* The easy bit: delete rows not present any more. In the same pass we
310 * update the secret column containing the queue_entry pointer. */
311 //fprintf(stderr, "%s: deleting rows...\n", ql->name);
313 gboolean it = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store),
315 int inserted = 0, deleted = 0, kept = 0;
317 struct queue_entry *q = ql_iter_to_q(GTK_TREE_MODEL(ql->store), iter);
318 const struct newqueue_data *nqd = hash_find(h, q->id);
320 /* Tell this row that it belongs to the new version of the queue */
321 gtk_list_store_set(ql->store, iter,
322 ql->ncolumns + QUEUEPOINTER_COLUMN, nqd->new,
324 it = gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), iter);
327 /* Delete this row (and move iter to the next one) */
328 //fprintf(stderr, " delete %s", q->id);
329 it = gtk_list_store_remove(ql->store, iter);
334 /* Now every row's secret column is right, but we might be missing new rows
335 * and they might be in the wrong order */
337 /* We're going to have to support arbitrary rearrangements, so we might as
338 * well add new elements at the end. */
339 //fprintf(stderr, "%s: adding rows...\n", ql->name);
340 struct queue_entry *after = 0;
341 for(struct queue_entry *q = newq; q; q = q->next) {
342 const struct newqueue_data *nqd = hash_find(h, q->id);
345 /* Try to insert at the right sort of place */
346 GtkTreeIter where[1];
347 gboolean wit = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store),
349 while(wit && ql_iter_to_q(GTK_TREE_MODEL(ql->store), where) != after)
350 wit = gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), where);
352 gtk_list_store_insert_after(ql->store, iter, where);
354 gtk_list_store_append(ql->store, iter);
356 gtk_list_store_prepend(ql->store, iter);
357 gtk_list_store_set(ql->store, iter,
358 ql->ncolumns + QUEUEPOINTER_COLUMN, q,
360 //fprintf(stderr, " add %s", q->id);
366 /* Now exactly the right set of rows are present, and they have the right
367 * queue_entry pointers in their secret column, but they may be in the wrong
370 * The current code is simple but amounts to a bubble-sort - we might easily
371 * called gtk_tree_model_iter_next a couple of thousand times.
373 //fprintf(stderr, "%s: rearranging rows\n", ql->name);
374 //fprintf(stderr, "%s: queue state: ", ql->name);
375 //dump_queue(newq, 0);
376 //fprintf(stderr, "%s: row state: ", ql->name);
378 it = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store),
380 struct queue_entry *rq = newq; /* r for 'right, correct' */
381 int swaps = 0, searches = 0;
383 struct queue_entry *q = ql_iter_to_q(GTK_TREE_MODEL(ql->store), iter);
384 //fprintf(stderr, " rq = %p, q = %p\n", rq, q);
385 //fprintf(stderr, " rq->id = %s, q->id = %s\n", rq->id, q->id);
388 //fprintf(stderr, " mismatch\n");
389 GtkTreeIter next[1] = { *iter };
390 gboolean nit = gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), next);
392 struct queue_entry *nq = ql_iter_to_q(GTK_TREE_MODEL(ql->store), next);
393 //fprintf(stderr, " candidate: %s\n", nq->id);
396 nit = gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), next);
400 //fprintf(stderr, " found it\n");
401 gtk_list_store_swap(ql->store, iter, next);
403 //fprintf(stderr, "%s: new row state: ", ql->name);
407 /* ...and onto the next one */
408 it = gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), iter);
412 fprintf(stderr, "%6s: %3d kept %3d inserted %3d deleted %3d swaps %4d searches\n", ql->name,
413 kept, inserted, deleted, swaps, searches);
415 //fprintf(stderr, "done\n");
417 /* Set the rest of the columns in new rows */
418 ql_update_list_store(ql);
422 /** @brief State for ql_drag_begin() and its callbacks */
423 struct ql_drag_begin_state {
424 struct queuelike *ql;
430 /** @brief Callback to construct a row pixmap */
431 static void ql_drag_make_row_pixmaps(GtkTreeModel attribute((unused)) *model,
433 GtkTreeIter attribute((unused)) *iter,
435 struct ql_drag_begin_state *qdbs = data;
437 qdbs->pixmaps[qdbs->index++]
438 = gtk_tree_view_create_row_drag_icon(GTK_TREE_VIEW(qdbs->ql->view),
442 /** @brief Called when a drag operation from this queuelike begins
443 * @param w Source widget (the tree view)
444 * @param dc Drag context
445 * @param user_data The queuelike
447 static void ql_drag_begin(GtkWidget attribute((unused)) *w,
448 GdkDragContext attribute((unused)) *dc,
449 gpointer user_data) {
450 struct queuelike *const ql = user_data;
451 struct ql_drag_begin_state qdbs[1];
454 //fprintf(stderr, "drag-begin\n");
455 memset(qdbs, 0, sizeof *qdbs);
457 /* Find out how many rows there are */
458 if(!(qdbs->rows = gtk_tree_selection_count_selected_rows(ql->selection)))
459 return; /* doesn't make sense */
460 /* Generate a pixmap for each row */
461 qdbs->pixmaps = xcalloc(qdbs->rows, sizeof *qdbs->pixmaps);
462 gtk_tree_selection_selected_foreach(ql->selection,
463 ql_drag_make_row_pixmaps,
465 /* Determine the size of the final icon */
466 int height = 0, width = 0;
467 for(int n = 0; n < qdbs->rows; ++n) {
469 gdk_drawable_get_size(qdbs->pixmaps[n], &pxw, &pxh);
474 if(!width || !height)
475 return; /* doesn't make sense */
476 /* Construct the icon */
477 icon = gdk_pixmap_new(qdbs->pixmaps[0], width, height, -1);
478 GdkGC *gc = gdk_gc_new(icon);
479 gdk_gc_set_colormap(gc, gtk_widget_get_colormap(ql->view));
481 for(int n = 0; n < qdbs->rows; ++n) {
483 gdk_drawable_get_size(qdbs->pixmaps[n], &pxw, &pxh);
484 gdk_draw_drawable(icon,
487 0, 0, /* source coords */
488 0, y, /* dest coords */
489 pxw, pxh); /* size */
492 // TODO scale down a bit, the resulting icons are currently a bit on the
494 gtk_drag_source_set_icon(ql->view,
495 gtk_widget_get_colormap(ql->view),
500 /** @brief Called when a drag moves within a candidate destination
501 * @param w Destination widget
502 * @param dc Drag context
503 * @param x Current pointer location
504 * @param y Current pointer location
505 * @param time_ Current time
506 * @param user_data Pointer to queuelike
507 * @return TRUE in a dropzone, otherwise FALSE
509 static gboolean ql_drag_motion(GtkWidget *w,
514 gpointer attribute((unused)) user_data) {
515 //struct queuelike *const ql = user_data;
516 GdkDragAction action = 0;
518 // GTK_DEST_DEFAULT_MOTION vets actions as follows:
519 // 1) if dc->suggested_action is in the gtk_drag_dest_set actions
520 // then dc->suggested_action is taken as the action.
521 // 2) otherwise if dc->actions intersects the gtk_drag_dest_set actions
522 // then the lowest-numbered member of the intersection is chosen.
523 // 3) otherwise no member is chosen and gdk_drag_status() is called
524 // with action=0 to refuse the drop.
525 // Currently we can only accept _MOVE. But in the future we will
526 // need to accept _COPY in some cases.
527 if(dc->suggested_action) {
528 if(dc->suggested_action == GDK_ACTION_MOVE)
529 action = dc->suggested_action;
530 } else if(dc->actions & GDK_ACTION_MOVE)
531 action = dc->actions;
532 /*fprintf(stderr, "suggested %#x actions %#x result %#x\n",
533 dc->suggested_action, dc->actions, action);*/
535 // If the action is acceptable then we see if this widget is acceptable
536 if(!gtk_drag_dest_find_target(w, dc, NULL))
540 gdk_drag_status(dc, action, time_);
542 // Highlight the drop area
544 GtkTreeViewDropPosition pos;
546 if(gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(w),
550 //fprintf(stderr, "gtk_tree_view_get_dest_row_at_pos() -> TRUE\n");
551 // Normalize drop position
553 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
554 pos = GTK_TREE_VIEW_DROP_BEFORE;
556 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER:
557 pos = GTK_TREE_VIEW_DROP_AFTER;
561 // Highlight drop target
562 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(w), path, pos);
564 //fprintf(stderr, "gtk_tree_view_get_dest_row_at_pos() -> FALSE\n");
565 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(w), NULL, 0);
571 /** @brief Called when a drag moves leaves a candidate destination
572 * @param w Destination widget
573 * @param dc Drag context
574 * @param time_ Current time
575 * @param user_data Pointer to queuelike
577 static void ql_drag_leave(GtkWidget *w,
578 GdkDragContext attribute((unused)) *dc,
579 guint attribute((unused)) time_,
580 gpointer attribute((unused)) user_data) {
581 //struct queuelike *const ql = user_data;
583 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(w), NULL, 0);
586 /** @brief Callback to add selected tracks to the selection data
588 * Called from ql_drag_data_get().
590 static void ql_drag_data_get_collect(GtkTreeModel *model,
591 GtkTreePath attribute((unused)) *path,
594 struct dynstr *const result = data;
595 struct queue_entry *const q = ql_iter_to_q(model, iter);
597 dynstr_append_string(result, q->id);
598 dynstr_append(result, '\n');
599 dynstr_append_string(result, q->track);
600 dynstr_append(result, '\n');
603 /** @brief Called to extract the dragged data from the source queuelike
604 * @param w Source widget (the tree view)
605 * @param dc Drag context
606 * @param data Where to put the answer
607 * @param info_ Target @c info parameter
608 * @param time_ Time data requested (for some reason not a @c time_t)
609 * @param user_data The queuelike
611 static void ql_drag_data_get(GtkWidget attribute((unused)) *w,
612 GdkDragContext attribute((unused)) *dc,
613 GtkSelectionData *data,
614 guint attribute((unused)) info_,
615 guint attribute((unused)) time_,
616 gpointer user_data) {
617 struct queuelike *const ql = user_data;
618 struct dynstr result[1];
620 /* The list of tracks is converted into a single string, consisting of IDs
621 * and track names. Each is terminated by a newline. Including both ID and
622 * track name means that the receiver can use whichever happens to be more
625 gtk_tree_selection_selected_foreach(ql->selection,
626 ql_drag_data_get_collect,
628 //fprintf(stderr, "drag-data-get: %.*s\n",
629 // result->nvec, result->vec);
630 /* gtk_selection_data_set_text() insists that data->target is one of a
631 * variety of stringy atoms. TODO: where does this value actually come
633 gtk_selection_data_set(data,
635 8, (guchar *)result->vec, result->nvec);
638 /** @brief Called when drag data is received
639 * @param w Target widget (the tree view)
640 * @param dc Drag context
641 * @param x The drop location
642 * @param y The drop location
643 * @param data The selection data
644 * @param info_ The target type that was chosen
645 * @param time_ Time data received (for some reason not a @c time_t)
646 * @param user_data The queuelike
648 static void ql_drag_data_received(GtkWidget attribute((unused)) *w,
649 GdkDragContext attribute((unused)) *dc,
652 GtkSelectionData *data,
653 guint attribute((unused)) info_,
654 guint attribute((unused)) time_,
655 gpointer user_data) {
656 struct queuelike *const ql = user_data;
658 struct vector ids[1], tracks[1];
661 //fprintf(stderr, "drag-data-received: %d,%d\n", x, y);
662 /* Get the selection string */
663 p = result = (char *)gtk_selection_data_get_text(data);
665 //fprintf(stderr, "gtk_selection_data_get_text() returned NULL\n");
668 //fprintf(stderr, "%s--\n", result);
669 /* Parse it back into IDs and track names */
673 char *nl = strchr(p, '\n');
677 //fprintf(stderr, " %s\n", p);
678 vector_append(parity++ & 1 ? tracks : ids, xstrdup(p));
682 if(ids->nvec != tracks->nvec) {
683 //fprintf(stderr, " inconsistent drag data!\n");
686 vector_terminate(ids);
687 vector_terminate(tracks);
688 /* Figure out which row the drop precedes (if any) */
690 GtkTreeViewDropPosition pos;
691 struct queue_entry *q;
692 if(!gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(ql->view), x, y,
694 //fprintf(stderr, "gtk_tree_view_get_dest_row_at_pos returned FALSE\n");
695 /* This generally means a drop past the end of the queue. We find the last
696 * element in the queue and ask to move after that. */
697 for(q = ql->q; q && q->next; q = q->next)
700 /* Convert the path to a queue entry pointer. */
701 q = ql_path_to_q(GTK_TREE_MODEL(ql->store), path);
702 //fprintf(stderr, " tree view likes to drop near %s\n",
703 // q->id ? q->id : "NULL");
704 /* TODO interpretation of q=NULL */
705 /* Q should point to the entry just before the insertion point, so that
706 * moveafter works, or NULL to insert right at the start. We don't support
707 * dropping into a row, since that doesn't make sense for us. */
709 case GTK_TREE_VIEW_DROP_BEFORE:
710 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE:
713 //fprintf(stderr, " ...but we like to drop near %s\n",
714 // q ? q->id : "NULL");
721 /* Note that q->id can match one of ids[]. This doesn't matter for
722 * moveafter but TODO may matter for playlist support. */
723 ql->drop(ql, tracks->nvec, tracks->vec, ids->vec, q);
726 /** @brief Initialize a @ref queuelike */
727 GtkWidget *init_queuelike(struct queuelike *ql) {
728 D(("init_queuelike"));
729 /* Create the list store. We add an extra column to hold a pointer to the
731 GType *types = xcalloc(ql->ncolumns + EXTRA_COLUMNS, sizeof (GType));
732 for(int n = 0; n < ql->ncolumns + EXTRA_COLUMNS; ++n)
733 types[n] = G_TYPE_STRING;
734 types[ql->ncolumns + QUEUEPOINTER_COLUMN] = G_TYPE_POINTER;
735 ql->store = gtk_list_store_newv(ql->ncolumns + EXTRA_COLUMNS, types);
736 g_object_set_data(G_OBJECT(ql->store), "ql", (void *)ql);
738 /* Create the view */
739 ql->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ql->store));
740 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(ql->view), TRUE);
742 /* Create cell renderers and label columns */
743 for(int n = 0; n < ql->ncolumns; ++n) {
744 GtkCellRenderer *r = gtk_cell_renderer_text_new();
745 if(ql->columns[n].flags & COL_ELLIPSIZE)
746 g_object_set(r, "ellipsize", PANGO_ELLIPSIZE_END, (char *)0);
747 if(ql->columns[n].flags & COL_RIGHT)
748 g_object_set(r, "xalign", (gfloat)1.0, (char *)0);
749 GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes
750 (ql->columns[n].name,
753 "background", ql->ncolumns + BACKGROUND_COLUMN,
754 "foreground", ql->ncolumns + FOREGROUND_COLUMN,
756 gtk_tree_view_column_set_resizable(c, TRUE);
757 gtk_tree_view_column_set_reorderable(c, TRUE);
758 if(ql->columns[n].flags & COL_EXPAND)
759 g_object_set(c, "expand", TRUE, (char *)0);
760 gtk_tree_view_append_column(GTK_TREE_VIEW(ql->view), c);
763 /* The selection should support multiple things being selected */
764 ql->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ql->view));
765 gtk_tree_selection_set_mode(ql->selection, GTK_SELECTION_MULTIPLE);
767 /* Catch button presses */
768 g_signal_connect(ql->view, "button-press-event",
769 G_CALLBACK(ql_button_release), ql);
773 /* Originally this was:
775 * gtk_tree_view_set_reorderable(GTK_TREE_VIEW(ql->view), TRUE);
777 * However this has a two deficiencies:
779 * 1) Only one row can be dragged at once. It would be nice
780 * to be able to do bulk rearrangements since the server
781 * can cope with that well.
782 * 2) Dragging between windows is not possible. When playlist
783 * support appears, it should be possible to drag tracks
784 * from the choose tag into the playlist.
786 * At the time of writing neither of these problems are fully solved, the
787 * code as it stands is just a stepping stone in that direction.
790 /* This view will act as a drag source */
791 gtk_drag_source_set(ql->view,
794 sizeof queuelike_targets / sizeof *queuelike_targets,
796 /* This view will act as a drag destination */
797 gtk_drag_dest_set(ql->view,
798 GTK_DEST_DEFAULT_HIGHLIGHT|GTK_DEST_DEFAULT_DROP,
800 sizeof queuelike_targets / sizeof *queuelike_targets,
802 g_signal_connect(ql->view, "drag-begin",
803 G_CALLBACK(ql_drag_begin), ql);
804 g_signal_connect(ql->view, "drag-motion",
805 G_CALLBACK(ql_drag_motion), ql);
806 g_signal_connect(ql->view, "drag-leave",
807 G_CALLBACK(ql_drag_leave), ql);
808 g_signal_connect(ql->view, "drag-data-get",
809 G_CALLBACK(ql_drag_data_get), ql);
810 g_signal_connect(ql->view, "drag-data-received",
811 G_CALLBACK(ql_drag_data_received), ql);
812 make_treeview_multidrag(ql->view);
814 /* TODO: support copy-dragging out of non-rearrangeable queues. Will need
815 * to support copy dropping into the rearrangeable ones. */
822 /* Update display text when lookups complete */
823 event_register("lookups-completed", queue_lookups_completed, ql);
825 GtkWidget *scrolled = scroll_widget(ql->view);
826 g_object_set_data(G_OBJECT(scrolled), "type", (void *)ql_tabtype(ql));