chiark / gitweb /
quieten compiler
[disorder] / disobedience / queue.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2006 Richard Kettlewell
4 *
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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20
21#include "disobedience.h"
22
23#define HCELLPADDING 4
24#define VCELLPADDING 2
25
26/* A queue layout is structured as follows:
27 *
28 * vbox
29 * titlescroll
30 * titlelayout
31 * titlecells[col] eventbox (made by wrap_queue_cell)
32 * titlecells[col]->child label (from columns[])
33 * mainscroll
34 * mainlayout
35 * cells[row * N + c] eventbox (made by wrap_queue_cell)
36 * cells[row * N + c]->child label (from column constructors)
37 *
38 * titlescroll never has any scrollbars. Instead whenever mainscroll's
39 * horizontal adjustment is changed, queue_scrolled adjusts titlescroll to
40 * match, forcing the title and the queue to pan in sync but allowing the queue
41 * to scroll independently.
42 *
43 * Whenever the queue changes everything below mainlayout is thrown away and
44 * reconstructed from scratch. Name lookups are cached, so this doesn't imply
45 * lots of disorder protocol traffic.
46 *
47 * The last cell on each row is the padding cell, and this extends ridiculously
48 * far to the right. (Can we do better?)
49 *
50 * When drag and drop is active we create extra eventboxes to act as dropzones.
51 * These only exist while the drag proceeds, as otherwise they steal events
52 * from more deserving widgets. (It might work to hide them when not in use
53 * too but this way around the d+d code is a bit more self-contained.)
54 */
55
56/* Queue management -------------------------------------------------------- */
57
e9b70a84 58WT(label);
59WT(event_box);
60WT(menu);
61WT(menu_item);
62WT(layout);
63WT(vbox);
64
460b9539 65struct queuelike;
66
67static void add_drag_targets(struct queuelike *ql);
68static void remove_drag_targets(struct queuelike *ql);
69static void redisplay_queue(struct queuelike *ql);
70static GtkWidget *column_when(const struct queuelike *ql,
71 const struct queue_entry *q,
72 const char *data);
73static GtkWidget *column_who(const struct queuelike *ql,
74 const struct queue_entry *q,
75 const char *data);
76static GtkWidget *column_namepart(const struct queuelike *ql,
77 const struct queue_entry *q,
78 const char *data);
79static GtkWidget *column_length(const struct queuelike *ql,
80 const struct queue_entry *q,
81 const char *data);
82static int draggable_row(const struct queue_entry *q);
83
84static const struct tabtype tabtype_queue; /* forward */
85
86static const GtkTargetEntry dragtargets[] = {
87 { (char *)"disobedience-queue", GTK_TARGET_SAME_APP, 0 }
88};
89#define NDRAGTARGETS (int)(sizeof dragtargets / sizeof *dragtargets)
90
91/* Definition of a column */
92struct column {
93 const char *name; /* Column name */
94 GtkWidget *(*widget)(const struct queuelike *ql,
95 const struct queue_entry *q,
96 const char *data); /* Make a label for this column */
97 const char *data; /* Data to pass to widget() */
98 gfloat xalign; /* Alignment of the label */
99};
100
101/* Need this in the middle of the types for NCOLUMNS */
102static const struct column columns[] = {
103 { "When", column_when, 0, 1 },
104 { "Who", column_who, 0, 0 },
105 { "Artist", column_namepart, "artist", 0 },
106 { "Album", column_namepart, "album", 0 },
107 { "Title", column_namepart, "title", 0 },
108 { "Length", column_length, 0, 1 }
109};
110#define NCOLUMNS (int)(sizeof columns / sizeof *columns)
111
112/* Data passed to menu item activation handlers */
113struct menuiteminfo {
114 struct queuelike *ql; /* which queue we're dealing with */
115 struct queue_entry *q; /* hovered entry or 0 */
116};
117
118struct menuitem {
119 /* Parameters */
120 const char *name; /* name */
121
122 /* Callbacks */
123 void (*activate)(GtkMenuItem *menuitem,
124 gpointer user_data);
125 /* Called to activate the menu item. The user data is the queue entry that
126 * the pointer was over when the menu popped up. */
127
128 int (*sensitive)(struct queuelike *ql,
129 struct menuitem *m,
130 struct queue_entry *q);
131 /* Called to determine whether the menu item is usable. Returns TRUE if it
132 * should be sensitive and FALSE otherwise. Q points to the queue entry the
133 * pointer is over. */
134
135 /* State */
136 gulong handlerid; /* signal handler ID */
137 GtkWidget *w; /* menu item widget */
138};
139
140struct queuelike {
141 /* Parameters */
142 const char *name; /* queue or recent */
143
144 /* Callbacks */
145 void (*notify)(void);
146 /* Called when an update completes. */
147
148 struct queue_entry *(*fixup)(struct queue_entry *q);
149 /* Fix up the queue after update, or 0. Q is the list passed back from the
150 * server, the return value is assigned to ql->q. */
151
152 /* Widgets */
153 GtkWidget *mainlayout; /* main layout */
154 GtkWidget *mainscroll; /* scroller for main layout */
155 GtkWidget *titlelayout; /* title layout */
156 GtkWidget *titlecells[NCOLUMNS + 1]; /* title cells */
157 GtkWidget **cells; /* all the cells */
158 GtkWidget *menu; /* popup menu */
159 struct menuitem *menuitems; /* menu items */
160 GtkWidget *dragmark; /* drag destination marker */
161 GtkWidget **dropzones; /* drag targets */
162
163 /* State */
164 struct queue_entry *q; /* head of queue */
165 struct queue_entry *last_click; /* last click */
166 int nrows; /* number of rows */
167 int mainrowheight; /* height of one row */
168 hash *selection; /* currently selected items */
169 int swallow_release; /* swallow button release from drag */
170};
171
172static struct queuelike ql_queue, ql_recent; /* queue and recently played */
173static struct queue_entry *actual_queue; /* actual queue */
174static struct queue_entry *playing_track; /* currenty playing */
175static time_t last_playing = (time_t)-1; /* when last got playing */
176static int namepart_lookups_outstanding;
177static int namepart_completions_deferred; /* # of completions not processed */
178static const struct cache_type cachetype_string = { 3600 };
179static const struct cache_type cachetype_integer = { 3600 };
180static GtkWidget *playing_length_label;
181
182/* Debugging --------------------------------------------------------------- */
183
184#if 0
185static void describe_widget(const char *name, GtkWidget *w, int indent) {
186 int ww, wh, wx, wy;
187
188 if(name)
189 fprintf(stderr, "%*s[%s]: '%s'\n", indent, "",
190 name, gtk_widget_get_name(w));
191 gdk_window_get_position(w->window, &wx, &wy);
192 gdk_drawable_get_size(GDK_DRAWABLE(w->window), &ww, &wh);
193 fprintf(stderr, "%*s window %p: %dx%d at %dx%d\n",
194 indent, "", w->window, ww, wh, wx, wy);
195}
196
197static void dump_layout(const struct queuelike *ql) {
198 GtkWidget *w;
199 char s[20];
200 int row, col;
201 const struct queue_entry *q;
202
203 describe_widget("mainscroll", ql->mainscroll, 0);
204 describe_widget("mainlayout", ql->mainlayout, 1);
205 for(q = ql->q, row = 0; q; q = q->next, ++row)
206 for(col = 0; col < NCOLUMNS + 1; ++col)
207 if((w = ql->cells[row * (NCOLUMNS + 1) + col])) {
208 sprintf(s, "%dx%d", row, col);
209 describe_widget(s, w, 2);
210 if(GTK_BIN(w)->child)
211 describe_widget(0, w, 3);
212 }
213}
214#endif
215
216/* Track detail lookup ----------------------------------------------------- */
217
218/* A namepart lookup has completed or failed. */
219static void namepart_completed_or_failed(void) {
220 D(("namepart_completed_or_failed"));
221 --namepart_lookups_outstanding;
222 if(!namepart_lookups_outstanding || namepart_completions_deferred > 24) {
223 redisplay_queue(&ql_queue);
224 redisplay_queue(&ql_recent);
225 namepart_completions_deferred = 0;
226 }
227}
228
229/* A namepart lookup has completed. */
230static void namepart_completed(void *v, const char *value) {
231 struct callbackdata *cbd = v;
232
233 D(("namepart_completed"));
234 cache_put(&cachetype_string, cbd->u.key, value);
235 ++namepart_completions_deferred;
236 namepart_completed_or_failed();
237}
238
239/* A length lookup has completed. */
240static void length_completed(void *v, long l) {
241 struct callbackdata *cbd = v;
242 long *value;
243
244 D(("namepart_completed"));
245 value = xmalloc(sizeof *value);
246 *value = l;
247 cache_put(&cachetype_integer, cbd->u.key, value);
248 ++namepart_completions_deferred;
249 namepart_completed_or_failed();
250}
251
252/* A length or namepart lookup has failed. */
253static void namepart_protocol_error(
254 struct callbackdata attribute((unused)) *cbd,
255 int attribute((unused)) code,
256 const char *msg) {
257 D(("namepart_protocol_error"));
258 gtk_label_set_text(GTK_LABEL(report_label), msg);
259 namepart_completed_or_failed();
260}
261
262/* Arrange to fill in a namepart cache entry */
263static void namepart_fill(const char *track,
264 const char *context,
265 const char *part,
266 const char *key) {
267 struct callbackdata *cbd;
268
269 ++namepart_lookups_outstanding;
270 cbd = xmalloc(sizeof *cbd);
271 cbd->onerror = namepart_protocol_error;
272 cbd->u.key = key;
273 disorder_eclient_namepart(client, namepart_completed,
274 track, context, part, cbd);
275}
276
277/* Look up a namepart. If it is in the cache then just return its value. If
278 * not then look it up and arrange for the queues to be updated when its value
279 * is available. */
280static const char *namepart(const char *track,
281 const char *context,
282 const char *part) {
283 char *key;
284 const char *value;
285
286 D(("namepart %s %s %s", track, context, part));
287 byte_xasprintf(&key, "namepart context=%s part=%s track=%s",
288 context, part, track);
289 value = cache_get(&cachetype_string, key);
290 if(!value) {
291 D(("deferring..."));
292 /* stick a value in the cache so we don't issue another lookup if we
293 * revisit */
294 cache_put(&cachetype_string, key, value = "?");
295 namepart_fill(track, context, part, key);
296 }
297 return value;
298}
299
300/* Called from properties.c when we know a name part has changed */
301void namepart_update(const char *track,
302 const char *context,
303 const char *part) {
304 char *key;
305
306 byte_xasprintf(&key, "namepart context=%s part=%s track=%s",
307 context, part, track);
308 /* Only refetch if it's actually in the cache */
309 if(cache_get(&cachetype_string, key))
310 namepart_fill(track, context, part, key);
311}
312
313/* Look up a track length. If it is in the cache then just return its value.
314 * If not then look it up and arrange for the queues to be updated when its
315 * value is available. */
316static long getlength(const char *track) {
317 char *key;
318 const long *value;
319 struct callbackdata *cbd;
320 static const long bogus = -1;
321
322 D(("getlength %s", track));
323 byte_xasprintf(&key, "length track=%s", track);
324 value = cache_get(&cachetype_integer, key);
325 if(!value) {
326 D(("deferring..."));;
327 cache_put(&cachetype_integer, key, value = &bogus);
328 ++namepart_lookups_outstanding;
329 cbd = xmalloc(sizeof *cbd);
330 cbd->onerror = namepart_protocol_error;
331 cbd->u.key = key;
332 disorder_eclient_length(client, length_completed, track, cbd);
333 }
334 return *value;
335}
336
337/* Column constructors ----------------------------------------------------- */
338
339/* Format the 'when' column */
340static GtkWidget *column_when(const struct queuelike attribute((unused)) *ql,
341 const struct queue_entry *q,
342 const char attribute((unused)) *data) {
343 char when[64];
344 struct tm tm;
345 time_t t;
346
347 D(("column_when"));
348 switch(q->state) {
349 case playing_isscratch:
350 case playing_unplayed:
351 case playing_random:
352 t = q->expected;
353 break;
354 case playing_failed:
355 case playing_no_player:
356 case playing_ok:
357 case playing_scratched:
358 case playing_started:
359 case playing_paused:
360 case playing_quitting:
361 t = q->played;
362 break;
363 default:
364 t = 0;
365 break;
366 }
367 if(t)
368 strftime(when, sizeof when, "%H:%M", localtime_r(&t, &tm));
369 else
370 when[0] = 0;
e9b70a84 371 NW(label);
460b9539 372 return gtk_label_new(when);
373}
374
375/* Format the 'who' column */
376static GtkWidget *column_who(const struct queuelike attribute((unused)) *ql,
377 const struct queue_entry *q,
378 const char attribute((unused)) *data) {
379 D(("column_who"));
e9b70a84 380 NW(label);
460b9539 381 return gtk_label_new(q->submitter ? q->submitter : "");
382}
383
384/* Format one of the track name columns */
385static GtkWidget *column_namepart(const struct queuelike
386 attribute((unused)) *ql,
387 const struct queue_entry *q,
388 const char *data) {
389 D(("column_namepart"));
e9b70a84 390 NW(label);
460b9539 391 return gtk_label_new(namepart(q->track, "display", data));
392}
393
394/* Compute the length field */
395static const char *text_length(const struct queue_entry *q) {
396 long l;
397 time_t now;
398 char *played = 0, *length = 0;
399
400 /* Work out what to say for the length */
401 l = getlength(q->track);
402 if(l > 0)
403 byte_xasprintf(&length, "%ld:%02ld", l / 60, l % 60);
404 else
405 byte_xasprintf(&length, "?:??");
406 /* For the currently playing track we want to report how much of the track
407 * has been played */
408 if(q == playing_track) {
409 /* log_state() arranges that we re-get the playing data whenever the
410 * pause/resume state changes */
411 if(last_state & DISORDER_TRACK_PAUSED)
412 l = playing_track->sofar;
413 else {
414 time(&now);
415 l = playing_track->sofar + (now - last_playing);
416 }
417 byte_xasprintf(&played, "%ld:%02ld/%s", l / 60, l % 60, length);
418 return played;
419 } else
420 return length;
421}
422
423/* Format the length column */
424static GtkWidget *column_length(const struct queuelike attribute((unused)) *ql,
425 const struct queue_entry *q,
426 const char attribute((unused)) *data) {
427 D(("column_length"));
428 if(q == playing_track) {
429 assert(!playing_length_label);
e9b70a84 430 NW(label);
460b9539 431 playing_length_label = gtk_label_new(text_length(q));
432 /* Zot playing_length_label when it is destroyed */
433 g_signal_connect(playing_length_label, "destroy",
434 G_CALLBACK(gtk_widget_destroyed), &playing_length_label);
435 return playing_length_label;
e9b70a84 436 } else {
437 NW(label);
460b9539 438 return gtk_label_new(text_length(q));
e9b70a84 439 }
440
460b9539 441}
442
443/* Apply a new queue contents, transferring the selection from the old value */
444static void update_queue(struct queuelike *ql, struct queue_entry *newq) {
445 struct queue_entry *q;
446
447 D(("update_queue"));
448 /* Propagate last_click across the change */
449 if(ql->last_click) {
450 for(q = newq; q; q = q->next) {
451 if(!strcmp(q->id, ql->last_click->id))
452 break;
453 ql->last_click = q;
454 }
455 }
456 /* Tell every queue entry which queue owns it */
457 for(q = newq; q; q = q->next)
458 q->ql = ql;
459 /* Switch to the new queue */
460 ql->q = newq;
461 /* Clean up any selected items that have fallen off */
462 for(q = ql->q; q; q = q->next)
463 selection_live(ql->selection, q->id);
464 selection_cleanup(ql->selection);
465}
466
467/* Wrap up a widget for putting into the queue or title */
468static GtkWidget *wrap_queue_cell(GtkWidget *label,
469 const char *name,
470 int *wp) {
471 GtkRequisition req;
472 GtkWidget *bg;
473
474 D(("wrap_queue_cell"));
475 /* Padding should be in the label so there are no gaps in the
476 * background */
477 gtk_misc_set_padding(GTK_MISC(label), HCELLPADDING, VCELLPADDING);
478 /* Event box is just to hold a background color */
e9b70a84 479 NW(event_box);
460b9539 480 bg = gtk_event_box_new();
481 gtk_container_add(GTK_CONTAINER(bg), label);
482 if(wp) {
483 /* Update maximum width */
484 gtk_widget_size_request(label, &req);
485 if(req.width > *wp) *wp = req.width;
486 }
487 /* Set widget names */
488 gtk_widget_set_name(bg, name);
489 gtk_widget_set_name(label, name);
490 return bg;
491}
492
493/* Create the wrapped widget for a cell in the queue display */
494static GtkWidget *get_queue_cell(struct queuelike *ql,
495 const struct queue_entry *q,
496 int row,
497 int col,
498 const char *name,
499 int *wp) {
500 GtkWidget *label;
501 D(("get_queue_cell %d %d", row, col));
502 label = columns[col].widget(ql, q, columns[col].data);
503 gtk_misc_set_alignment(GTK_MISC(label), columns[col].xalign, 0);
504 return wrap_queue_cell(label, name, wp);
505}
506
507/* Add a padding cell to the end of a row */
508static GtkWidget *get_padding_cell(const char *name) {
509 D(("get_padding_cell"));
e9b70a84 510 NW(label);
460b9539 511 return wrap_queue_cell(gtk_label_new(""), name, 0);
512}
513
514/* User button press and menu ---------------------------------------------- */
515
516/* Update widget states in order to reflect the selection status */
517static void set_widget_states(struct queuelike *ql) {
518 struct queue_entry *q;
519 int row, col;
520
521 for(q = ql->q, row = 0; q; q = q->next, ++row) {
522 for(col = 0; col < NCOLUMNS + 1; ++col)
523 gtk_widget_set_state(ql->cells[row * (NCOLUMNS + 1) + col],
524 selection_selected(ql->selection, q->id) ?
525 GTK_STATE_SELECTED : GTK_STATE_NORMAL);
526 }
527 /* Might need to change sensitivity of 'Properties' in main menu */
528 menu_update(-1);
529}
530
531static int queue_before(const struct queue_entry *a,
532 const struct queue_entry *b) {
533 while(a && a != b)
534 a = a->next;
535 return !!a;
536}
537
538/* A button was pressed and released */
539static gboolean queuelike_button_released(GtkWidget attribute((unused)) *widget,
540 GdkEventButton *event,
541 gpointer user_data) {
542 struct queue_entry *q = user_data, *qq;
543 struct queuelike *ql = q->ql;
544 struct menuiteminfo *mii;
545 int n;
546
547 /* Might be a release left over from a drag */
548 if(ql->swallow_release) {
549 ql->swallow_release = 0;
550 return FALSE; /* propagate */
551 }
552
553 if(event->type == GDK_BUTTON_PRESS
554 && event->button == 3) {
555 /* Right button click.
556 * If the current item is not selected then switch the selection to just
557 * this item */
558 if(q && !selection_selected(ql->selection, q->id)) {
559 selection_empty(ql->selection);
560 selection_set(ql->selection, q->id, 1);
561 ql->last_click = q;
562 set_widget_states(ql);
563 }
564 /* Set the sensitivity of each menu item and (re-)establish the signal
565 * handlers */
566 for(n = 0; ql->menuitems[n].name; ++n) {
567 if(ql->menuitems[n].handlerid)
568 g_signal_handler_disconnect(ql->menuitems[n].w,
569 ql->menuitems[n].handlerid);
570 gtk_widget_set_sensitive(ql->menuitems[n].w,
571 ql->menuitems[n].sensitive(ql,
572 &ql->menuitems[n],
573 q));
574 mii = xmalloc(sizeof *mii);
575 mii->ql = ql;
576 mii->q = q;
577 ql->menuitems[n].handlerid = g_signal_connect
578 (ql->menuitems[n].w, "activate",
579 G_CALLBACK(ql->menuitems[n].activate), mii);
580 }
581 /* Update the menu according to context */
582 gtk_widget_show_all(ql->menu);
583 gtk_menu_popup(GTK_MENU(ql->menu), 0, 0, 0, 0,
584 event->button, event->time);
585 return TRUE; /* hide the click from other widgets */
586 }
587 if(event->type == GDK_BUTTON_RELEASE
588 && event->button == 1) {
589 /* no modifiers: select this, unselect everything else, set last click
590 * +ctrl: flip selection of this, set last click
591 * +shift: select from last click to here, don't set last click
592 * +ctrl+shift: select from last click to here, set last click
593 */
594 switch(event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) {
595 case 0:
596 selection_empty(ql->selection);
597 selection_set(ql->selection, q->id, 1);
598 ql->last_click = q;
599 break;
600 case GDK_CONTROL_MASK:
601 selection_flip(ql->selection, q->id);
602 ql->last_click = q;
603 break;
604 case GDK_SHIFT_MASK:
605 case GDK_SHIFT_MASK|GDK_CONTROL_MASK:
606 if(ql->last_click) {
607 if(!(event->state & GDK_CONTROL_MASK))
608 selection_empty(ql->selection);
609 selection_set(ql->selection, q->id, 1);
610 qq = q;
611 if(queue_before(ql->last_click, q))
612 while(qq != ql->last_click) {
613 qq = qq->prev;
614 selection_set(ql->selection, qq->id, 1);
615 }
616 else
617 while(qq != ql->last_click) {
618 qq = qq->next;
619 selection_set(ql->selection, qq->id, 1);
620 }
621 if(event->state & GDK_CONTROL_MASK)
622 ql->last_click = q;
623 }
624 break;
625 }
626 set_widget_states(ql);
627 gtk_widget_queue_draw(ql->mainlayout);
628 }
629 return FALSE; /* propagate */
630}
631
632/* A button was pressed or released on the mainlayout. For debugging only at
633 * the moment. */
634static gboolean mainlayout_button(GtkWidget attribute((unused)) *widget,
635 GdkEventButton attribute((unused)) *event,
636 gpointer attribute((unused)) user_data) {
637 return FALSE; /* propagate */
638}
639
640void queue_select_all(struct queuelike *ql) {
641 struct queue_entry *qq;
642
643 for(qq = ql->q; qq; qq = qq->next)
644 selection_set(ql->selection, qq->id, 1);
645 ql->last_click = 0;
646 set_widget_states(ql);
647}
648
649void queue_properties(struct queuelike *ql) {
650 struct vector v;
651 const struct queue_entry *qq;
652
653 vector_init(&v);
654 for(qq = ql->q; qq; qq = qq->next)
655 if(selection_selected(ql->selection, qq->id))
656 vector_append(&v, (char *)qq->track);
657 if(v.nvec)
658 properties(v.nvec, v.vec);
659}
660
661/* Drag and drop rearrangement --------------------------------------------- */
662
663static int draggable_row(const struct queue_entry *q) {
664 return q->ql == &ql_queue && q != playing_track;
665}
666
667/* Called when a drag begings */
668static void queue_drag_begin(GtkWidget attribute((unused)) *widget,
669 GdkDragContext attribute((unused)) *dc,
670 gpointer data) {
671 struct queue_entry *q = data;
672 struct queuelike *ql = q->ql;
673
674 /* Make sure the playing track is not selected, since it cannot be dragged */
675 if(playing_track)
676 selection_set(ql->selection, playing_track->id, 0);
677 /* If the dragged item is not in the selection then change the selection to
678 * just that */
679 if(!selection_selected(ql->selection, q->id)) {
680 selection_empty(ql->selection);
681 selection_set(ql->selection, q->id, 1);
682 set_widget_states(ql);
683 }
684 /* Ignore the eventual button release */
685 ql->swallow_release = 1;
686 /* Create dropzones */
687 add_drag_targets(ql);
688}
689
690/* Convert an ID back into a queue entry and a screen row number */
691static struct queue_entry *findentry(struct queuelike *ql,
692 const char *id,
693 int *rowp) {
694 int row;
695 struct queue_entry *q;
696
697 if(id) {
698 for(q = ql->q, row = 0; q && strcmp(q->id, id); q = q->next, ++row)
699 ;
700 } else {
701 q = 0;
702 row = playing_track ? 0 : -1;
703 }
704 if(rowp) *rowp = row;
705 return q;
706}
707
708/* Called when data is dropped */
709static gboolean queue_drag_drop(GtkWidget attribute((unused)) *widget,
710 GdkDragContext *drag_context,
711 gint attribute((unused)) x,
712 gint attribute((unused)) y,
713 guint when,
714 gpointer user_data) {
715 struct queuelike *ql = &ql_queue;
716 const char *id = user_data;
717 struct vector vec;
718 struct queue_entry *q;
719
720 if(!id || (playing_track && !strcmp(id, playing_track->id)))
721 id = "";
722 vector_init(&vec);
723 for(q = ql->q; q; q = q->next)
724 if(q != playing_track && selection_selected(ql->selection, q->id))
725 vector_append(&vec, (char *)q->id);
726 disorder_eclient_moveafter(client, id, vec.nvec, (const char **)vec.vec,
727 0/*completed*/, 0/*v*/);
728 gtk_drag_finish(drag_context, TRUE, TRUE, when);
729 /* Destroy dropzones */
730 remove_drag_targets(ql);
731 return TRUE;
732}
733
734/* Called when we enter, or move within, a drop zone */
735static gboolean queue_drag_motion(GtkWidget attribute((unused)) *widget,
736 GdkDragContext *drag_context,
737 gint attribute((unused)) x,
738 gint attribute((unused)) y,
739 guint when,
740 gpointer user_data) {
741 struct queuelike *ql = &ql_queue;
742 const char *id = user_data;
743 int row;
744 struct queue_entry *q = findentry(ql, id, &row);
745
746 if(!id || q) {
747 if(!ql->dragmark) {
e9b70a84 748 NW(event_box);
460b9539 749 ql->dragmark = gtk_event_box_new();
750 g_signal_connect(ql->dragmark, "destroy",
751 G_CALLBACK(gtk_widget_destroyed), &ql->dragmark);
752 gtk_widget_set_size_request(ql->dragmark, 10240, row ? 4 : 2);
753 gtk_widget_set_name(ql->dragmark, "queue-drag");
754 gtk_layout_put(GTK_LAYOUT(ql->mainlayout), ql->dragmark, 0,
755 (row + 1) * ql->mainrowheight - !!row);
756 } else
757 gtk_layout_move(GTK_LAYOUT(ql->mainlayout), ql->dragmark, 0,
758 (row + 1) * ql->mainrowheight - !!row);
759 gtk_widget_show(ql->dragmark);
760 gdk_drag_status(drag_context, GDK_ACTION_MOVE, when);
761 return TRUE;
762 } else
763 /* ID has gone AWOL */
764 return FALSE;
765}
766
767/* Called when we leave a drop zone */
768static void queue_drag_leave(GtkWidget attribute((unused)) *widget,
769 GdkDragContext attribute((unused)) *drag_context,
770 guint attribute((unused)) when,
771 gpointer attribute((unused)) user_data) {
772 struct queuelike *ql = &ql_queue;
773
774 if(ql->dragmark)
775 gtk_widget_hide(ql->dragmark);
776}
777
778/* Add a drag target at position Y. ID is the track to insert the moved tracks
779 * after, and might be 0 to insert before the start. */
780static void add_drag_target(struct queuelike *ql, int y, int row,
781 const char *id) {
782 GtkWidget *eventbox;
783
784 assert(ql->dropzones[row] == 0);
e9b70a84 785 NW(event_box);
460b9539 786 eventbox = gtk_event_box_new();
787 /* Make the target zone invisible */
788 gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox), FALSE);
789 /* Make it large enough */
790 gtk_widget_set_size_request(eventbox, 10240,
791 y ? ql->mainrowheight : ql->mainrowheight / 2);
792 /* Position it */
793 gtk_layout_put(GTK_LAYOUT(ql->mainlayout), eventbox, 0,
794 y ? y - ql->mainrowheight / 2 : 0);
795 /* Mark it as capable of receiving drops */
796 gtk_drag_dest_set(eventbox,
797 0,
798 dragtargets, NDRAGTARGETS, GDK_ACTION_MOVE);
799 g_signal_connect(eventbox, "drag-drop",
800 G_CALLBACK(queue_drag_drop), (char *)id);
801 /* Monitor drag motion */
802 g_signal_connect(eventbox, "drag-motion",
803 G_CALLBACK(queue_drag_motion), (char *)id);
804 g_signal_connect(eventbox, "drag-leave",
805 G_CALLBACK(queue_drag_leave), (char *)id);
806 /* The widget needs to be shown to receive drags */
807 gtk_widget_show(eventbox);
808 /* Remember the drag targets */
809 ql->dropzones[row] = eventbox;
810 g_signal_connect(eventbox, "destroy",
811 G_CALLBACK(gtk_widget_destroyed), &ql->dropzones[row]);
812}
813
814/* Create dropzones for dragging into */
815static void add_drag_targets(struct queuelike *ql) {
816 int row, y;
817 struct queue_entry *q;
818
819 /* Create an array to store the widgets */
820 ql->dropzones = xcalloc(ql->nrows, sizeof (GtkWidget *));
821 y = 0;
822 /* Add a drag target before the first row provided it's not the playing
823 * track */
824 if(!playing_track || ql->q != playing_track)
825 add_drag_target(ql, 0, 0, 0);
826 /* Put a drag target at the bottom of every row */
827 for(q = ql->q, row = 0; q; q = q->next, ++row) {
828 y += ql->mainrowheight;
829 add_drag_target(ql, y, row, q->id);
830 }
831}
832
833/* Remove the dropzones */
834static void remove_drag_targets(struct queuelike *ql) {
835 int row;
836
837 for(row = 0; row < ql->nrows; ++row) {
838 if(ql->dropzones[row]) {
e9b70a84 839 DW(event_box);
460b9539 840 gtk_widget_destroy(ql->dropzones[row]);
841 }
842 assert(ql->dropzones[row] == 0);
843 }
844}
845
846/* Layout ------------------------------------------------------------------ */
847
848/* Redisplay the queue. */
849static void redisplay_queue(struct queuelike *ql) {
850 struct queue_entry *q;
851 int row, col;
852 GList *c;
853 const char *name;
854 GtkRequisition req;
855 GtkWidget *w;
856 int maxwidths[NCOLUMNS], x, y, titlerowheight;
857 int totalwidth = 10240; /* TODO: can we be less blunt */
858
859 D(("redisplay_queue"));
860 /* Eliminate all the existing widgets and start from scratch */
861 for(c = gtk_container_get_children(GTK_CONTAINER(ql->mainlayout));
862 c;
863 c = c->next) {
864 /* Destroy both the label and the eventbox */
e9b70a84 865 if(GTK_BIN(c->data)->child) {
866 DW(label);
460b9539 867 gtk_widget_destroy(GTK_BIN(c->data)->child);
e9b70a84 868 }
869 DW(event_box);
460b9539 870 gtk_widget_destroy(GTK_WIDGET(c->data));
871 }
872 /* Adjust the row count */
873 for(q = ql->q, ql->nrows = 0; q; q = q->next)
874 ++ql->nrows;
875 /* We need to create all the widgets before we can position them */
876 ql->cells = xcalloc(ql->nrows * (NCOLUMNS + 1), sizeof *ql->cells);
877 /* Minimum width is given by the column headings */
878 for(col = 0; col < NCOLUMNS; ++col) {
879 /* Reset size so we don't inherit last iteration's maximum size */
880 gtk_widget_set_size_request(GTK_BIN(ql->titlecells[col])->child, -1, -1);
881 gtk_widget_size_request(GTK_BIN(ql->titlecells[col])->child, &req);
882 maxwidths[col] = req.width;
883 }
884 /* Find the vertical size of the title bar */
885 gtk_widget_size_request(GTK_BIN(ql->titlecells[0])->child, &req);
886 titlerowheight = req.height;
887 y = 0;
888 if(ql->nrows) {
889 /* Construct the widgets */
890 for(q = ql->q, row = 0; q; q = q->next, ++row) {
891 /* Figure out the widget name for this row */
892 if(q == playing_track) name = "row-playing";
893 else name = row % 2 ? "row-even" : "row-odd";
894 /* Make the widget for each column */
895 for(col = 0; col <= NCOLUMNS; ++col) {
896 /* Create and store the widget */
897 if(col < NCOLUMNS)
898 w = get_queue_cell(ql, q, row, col, name, &maxwidths[col]);
899 else
900 w = get_padding_cell(name);
901 ql->cells[row * (NCOLUMNS + 1) + col] = w;
902 /* Maybe mark it draggable */
903 if(draggable_row(q)) {
904 gtk_drag_source_set(w, GDK_BUTTON1_MASK,
905 dragtargets, NDRAGTARGETS, GDK_ACTION_MOVE);
906 g_signal_connect(w, "drag-begin", G_CALLBACK(queue_drag_begin), q);
907 }
908 /* Catch button presses */
909 g_signal_connect(w, "button-release-event",
910 G_CALLBACK(queuelike_button_released), q);
911 g_signal_connect(w, "button-press-event",
912 G_CALLBACK(queuelike_button_released), q);
913 }
914 }
915 /* ...and of each row in the main layout */
916 gtk_widget_size_request(GTK_BIN(ql->cells[0])->child, &req);
917 ql->mainrowheight = req.height;
918 /* Now we know the maximum width of each column we can set the size of
919 * everything and position it */
920 for(row = 0, q = ql->q; row < ql->nrows; ++row, q = q->next) {
921 x = 0;
922 for(col = 0; col < NCOLUMNS; ++col) {
923 w = ql->cells[row * (NCOLUMNS + 1) + col];
924 gtk_widget_set_size_request(GTK_BIN(w)->child,
925 maxwidths[col], -1);
926 gtk_layout_put(GTK_LAYOUT(ql->mainlayout), w, x, y);
927 x += maxwidths[col];
928 }
929 w = ql->cells[row * (NCOLUMNS + 1) + col];
930 gtk_widget_set_size_request(GTK_BIN(w)->child,
931 totalwidth - x, -1);
932 gtk_layout_put(GTK_LAYOUT(ql->mainlayout), w, x, y);
933 y += ql->mainrowheight;
934 }
935 }
936 /* Titles */
937 x = 0;
938 for(col = 0; col < NCOLUMNS; ++col) {
939 gtk_widget_set_size_request(GTK_BIN(ql->titlecells[col])->child,
940 maxwidths[col], -1);
941 gtk_layout_move(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], x, 0);
942 x += maxwidths[col];
943 }
944 gtk_widget_set_size_request(GTK_BIN(ql->titlecells[col])->child,
945 totalwidth - x, -1);
946 gtk_layout_move(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], x, 0);
947 /* Set the states */
948 set_widget_states(ql);
949 /* Make sure it's all visible */
950 gtk_widget_show_all(ql->mainlayout);
951 gtk_widget_show_all(ql->titlelayout);
952 /* Layouts might shrink to arrange for the area they shrink out of to be
953 * redrawn */
954 gtk_widget_queue_draw(ql->mainlayout);
955 gtk_widget_queue_draw(ql->titlelayout);
956 /* Adjust the size of the layout */
957 gtk_layout_set_size(GTK_LAYOUT(ql->mainlayout), x, y);
958 gtk_layout_set_size(GTK_LAYOUT(ql->titlelayout), x, titlerowheight);
959 gtk_widget_set_size_request(ql->titlelayout, -1, titlerowheight);
960}
961
962/* Called with new queue/recent contents */
963static void queuelike_completed(void *v, struct queue_entry *q) {
964 struct callbackdata *cbd = v;
965 struct queuelike *ql = cbd->u.ql;
966
967 D(("queuelike_complete"));
968 /* Install the new queue */
969 update_queue(ql, ql->fixup(q));
970 /* Update the display */
971 redisplay_queue(ql);
972 if(ql->notify)
973 ql->notify();
974 /* Update sensitivity of main menu items */
975 menu_update(-1);
976}
977
978/* Called with a new currently playing track */
979static void playing_completed(void attribute((unused)) *v,
980 struct queue_entry *q) {
981 struct callbackdata cbd;
982 D(("playing_completed"));
983 playing_track = q;
984 /* Record when we got the playing track data so we know how old the 'sofar'
985 * field is */
986 time(&last_playing);
987 cbd.u.ql = &ql_queue;
988 queuelike_completed(&cbd, actual_queue);
989}
990
991static void queue_scrolled(GtkAdjustment *adjustment,
992 gpointer user_data) {
993 GtkAdjustment *titleadj = user_data;
994
995 D(("queue_scrolled"));
996 gtk_adjustment_set_value(titleadj, adjustment->value);
997}
998
999/* Create a queuelike thing (queue/recent) */
1000static GtkWidget *queuelike(struct queuelike *ql,
1001 struct queue_entry *(*fixup)(struct queue_entry *),
1002 void (*notify)(void),
1003 struct menuitem *menuitems,
1004 const char *name) {
1005 GtkWidget *vbox, *mainscroll, *titlescroll, *label;
1006 GtkAdjustment *mainadj, *titleadj;
1007 int col, n;
1008
1009 D(("queuelike"));
1010 ql->fixup = fixup;
1011 ql->notify = notify;
1012 ql->menuitems = menuitems;
1013 ql->name = name;
1014 ql->mainrowheight = !0; /* else division by 0 */
1015 ql->selection = selection_new();
1016 /* Create the layouts */
e9b70a84 1017 NW(layout);
460b9539 1018 ql->mainlayout = gtk_layout_new(0, 0);
e9b70a84 1019 NW(layout);
460b9539 1020 ql->titlelayout = gtk_layout_new(0, 0);
1021 /* Scroll the layouts */
1022 ql->mainscroll = mainscroll = scroll_widget(ql->mainlayout, name);
1023 titlescroll = scroll_widget(ql->titlelayout, name);
1024 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(titlescroll),
1025 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
1026 mainadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(mainscroll));
1027 titleadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(titlescroll));
1028 g_signal_connect(mainadj, "changed", G_CALLBACK(queue_scrolled), titleadj);
1029 g_signal_connect(mainadj, "value-changed", G_CALLBACK(queue_scrolled), titleadj);
1030 /* Fill the titles and put them anywhere */
1031 for(col = 0; col < NCOLUMNS; ++col) {
e9b70a84 1032 NW(label);
460b9539 1033 label = gtk_label_new(columns[col].name);
1034 gtk_misc_set_alignment(GTK_MISC(label), columns[col].xalign, 0);
1035 ql->titlecells[col] = wrap_queue_cell(label, "row-title", 0);
1036 gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0);
1037 }
1038 ql->titlecells[col] = get_padding_cell("row-title");
1039 gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0);
1040 /* Pack the lot together in a vbox */
e9b70a84 1041 NW(vbox);
460b9539 1042 vbox = gtk_vbox_new(0, 0);
1043 gtk_box_pack_start(GTK_BOX(vbox), titlescroll, 0, 0, 0);
1044 gtk_box_pack_start(GTK_BOX(vbox), mainscroll, 1, 1, 0);
1045 /* Create the popup menu */
e9b70a84 1046 NW(menu);
460b9539 1047 ql->menu = gtk_menu_new();
1048 g_signal_connect(ql->menu, "destroy",
1049 G_CALLBACK(gtk_widget_destroyed), &ql->menu);
1050 for(n = 0; menuitems[n].name; ++n) {
e9b70a84 1051 NW(menu_item);
460b9539 1052 menuitems[n].w = gtk_menu_item_new_with_label(menuitems[n].name);
1053 gtk_menu_attach(GTK_MENU(ql->menu), menuitems[n].w, 0, 1, n, n + 1);
1054 }
1055 g_object_set_data(G_OBJECT(vbox), "type", (void *)&tabtype_queue);
1056 g_object_set_data(G_OBJECT(vbox), "queue", ql);
1057 /* Catch button presses */
1058 g_signal_connect(ql->mainlayout, "button-release-event",
1059 G_CALLBACK(mainlayout_button), ql);
1060#if 0
1061 g_signal_connect(ql->mainlayout, "button-press-event",
1062 G_CALLBACK(mainlayout_button), ql);
1063#endif
1064 return vbox;
1065}
1066
1067/* Popup menu items -------------------------------------------------------- */
1068
1069/* Count the number of items selected */
1070static int queue_count_selected(const struct queuelike *ql) {
1071 return hash_count(ql->selection);
1072}
1073
1074/* Count the number of items selected */
1075static int queue_count_entries(const struct queuelike *ql) {
1076 int nitems = 0;
1077 const struct queue_entry *q;
1078
1079 for(q = ql->q; q; q = q->next)
1080 ++nitems;
1081 return nitems;
1082}
1083
1084/* Count the number of items selected, excluding the playing track if there is
1085 * one */
1086static int count_selected_nonplaying(const struct queuelike *ql) {
1087 int nselected = queue_count_selected(ql);
1088
1089 if(ql->q == playing_track && selection_selected(ql->selection, ql->q->id))
1090 --nselected;
1091 return nselected;
1092}
1093
1094static int scratch_sensitive(struct queuelike attribute((unused)) *ql,
1095 struct menuitem attribute((unused)) *m,
1096 struct queue_entry attribute((unused)) *q) {
1097 /* We can scratch if the playing track is selected */
1098 return playing_track && selection_selected(ql->selection, playing_track->id);
1099}
1100
1101static void scratch_activate(GtkMenuItem attribute((unused)) *menuitem,
1102 gpointer attribute((unused)) user_data) {
1103 if(playing_track)
1104 disorder_eclient_scratch(client, playing_track->id, 0, 0);
1105}
1106
1107static int remove_sensitive(struct queuelike *ql,
1108 struct menuitem attribute((unused)) *m,
1109 struct queue_entry *q) {
1110 /* We can remove if we're hovering over a particular track or any non-playing
1111 * tracks are selected */
1112 return (q && q != playing_track) || count_selected_nonplaying(ql);
1113}
1114
1115static void remove_activate(GtkMenuItem attribute((unused)) *menuitem,
1116 gpointer user_data) {
1117 const struct menuiteminfo *mii = user_data;
1118 struct queue_entry *q = mii->q;
1119 struct queuelike *ql = mii->ql;
1120
1121 if(count_selected_nonplaying(mii->ql)) {
1122 /* Remove selected tracks */
1123 for(q = ql->q; q; q = q->next)
1124 if(selection_selected(ql->selection, q->id) && q != playing_track)
1125 disorder_eclient_remove(client, q->id, 0, 0);
1126 } else if(q)
1127 /* Remove just the hovered track */
1128 disorder_eclient_remove(client, q->id, 0, 0);
1129}
1130
1131static int properties_sensitive(struct queuelike *ql,
1132 struct menuitem attribute((unused)) *m,
1133 struct queue_entry attribute((unused)) *q) {
1134 /* "Properties" is sensitive if at least something is selected */
1135 return hash_count(ql->selection) > 0;
1136}
1137
1138static void properties_activate(GtkMenuItem attribute((unused)) *menuitem,
1139 gpointer user_data) {
1140 const struct menuiteminfo *mii = user_data;
1141
1142 queue_properties(mii->ql);
1143}
1144
1145static int selectall_sensitive(struct queuelike *ql,
1146 struct menuitem attribute((unused)) *m,
1147 struct queue_entry attribute((unused)) *q) {
1148 /* Sensitive if there is anything to select */
1149 return !!ql->q;
1150}
1151
1152static void selectall_activate(GtkMenuItem attribute((unused)) *menuitem,
1153 gpointer user_data) {
1154 const struct menuiteminfo *mii = user_data;
1155 queue_select_all(mii->ql);
1156}
1157
1158/* The queue --------------------------------------------------------------- */
1159
1160/* Fix up the queue by sticking the currently playing track on the front */
1161static struct queue_entry *fixup_queue(struct queue_entry *q) {
1162 D(("fixup_queue"));
1163 actual_queue = q;
1164 if(playing_track) {
1165 if(actual_queue)
1166 actual_queue->prev = playing_track;
1167 playing_track->next = actual_queue;
1168 return playing_track;
1169 } else
1170 return actual_queue;
1171}
1172
1173/* Called regularly to adjust the so-far played label (redrawing the whole
1174 * queue once a second makes disobedience occupy >10% of the CPU on my Athlon
1175 * which is ureasonable expensive) */
1176static gboolean adjust_sofar(gpointer attribute((unused)) data) {
1177 if(playing_length_label && playing_track)
1178 gtk_label_set_text(GTK_LABEL(playing_length_label),
1179 text_length(playing_track));
1180 return TRUE;
1181}
1182
1183/* Popup menu for the queue. Put the properties first so that finger trouble
1184 * is less dangerous. */
1185static struct menuitem queue_menu[] = {
1186 { "Properties", properties_activate, properties_sensitive, 0, 0 },
1187 { "Select all", selectall_activate, selectall_sensitive, 0, 0 },
1188 { "Scratch", scratch_activate, scratch_sensitive, 0, 0 },
1189 { "Remove", remove_activate, remove_sensitive, 0, 0 },
1190 { 0, 0, 0, 0, 0 }
1191};
1192
1193GtkWidget *queue_widget(void) {
1194 D(("queue_widget"));
1195 /* Arrange periodic update of the so-far played field */
1196 g_timeout_add(1000/*ms*/, adjust_sofar, 0);
1197 /* We pass choose_update() as our notify function since the choose screen
1198 * marks tracks that are playing/in the queue. */
1199 return queuelike(&ql_queue, fixup_queue, choose_update, queue_menu,
1200 "queue");
1201}
1202
1203void queue_update(void) {
1204 struct callbackdata *cbd;
1205
1206 D(("queue_update"));
1207 cbd = xmalloc(sizeof *cbd);
1208 cbd->onerror = 0;
1209 cbd->u.ql = &ql_queue;
1210 gtk_label_set_text(GTK_LABEL(report_label), "updating queue");
1211 disorder_eclient_queue(client, queuelike_completed, cbd);
1212}
1213
1214void playing_update(void) {
1215 D(("playing_update"));
1216 gtk_label_set_text(GTK_LABEL(report_label), "updating playing track");
1217 disorder_eclient_playing(client, playing_completed, 0);
1218}
1219
1220/* Recently played tracks -------------------------------------------------- */
1221
1222static struct queue_entry *fixup_recent(struct queue_entry *q) {
1223 /* 'recent' is in the wrong order. TODO: globally fix this! */
1224 struct queue_entry *qr = 0, *qn;
1225
1226 D(("fixup_recent"));
1227 while(q) {
1228 qn = q->next;
1229 /* Swap next/prev pointers */
1230 q->next = q->prev;
1231 q->prev = qn;
1232 /* Remember last node for new head */
1233 qr = q;
1234 /* Next node */
1235 q = qn;
1236 }
1237 return qr;
1238}
1239
1240static struct menuitem recent_menu[] = {
1241 { "Properties", properties_activate, properties_sensitive,0, 0 },
1242 { "Select all", selectall_activate, selectall_sensitive, 0, 0 },
1243 { 0, 0, 0, 0, 0 }
1244};
1245
1246GtkWidget *recent_widget(void) {
1247 D(("recent_widget"));
1248 return queuelike(&ql_recent, fixup_recent, 0, recent_menu, "recent");
1249}
1250
1251void recent_update(void) {
1252 struct callbackdata *cbd;
1253
1254 D(("recent_update"));
1255 cbd = xmalloc(sizeof *cbd);
1256 cbd->onerror = 0;
1257 cbd->u.ql = &ql_recent;
1258 gtk_label_set_text(GTK_LABEL(report_label), "updating recently played list");
1259 disorder_eclient_recent(client, queuelike_completed, cbd);
1260}
1261
1262/* Main menu plumbing ------------------------------------------------------ */
1263
1264static int queue_properties_sensitive(GtkWidget *w) {
1265 return !!queue_count_selected(g_object_get_data(G_OBJECT(w), "queue"));
1266}
1267
1268static int queue_selectall_sensitive(GtkWidget *w) {
1269 return !!queue_count_entries(g_object_get_data(G_OBJECT(w), "queue"));
1270}
1271
1272static void queue_properties_activate(GtkWidget *w) {
1273 queue_properties(g_object_get_data(G_OBJECT(w), "queue"));
1274}
1275
1276static void queue_selectall_activate(GtkWidget *w) {
1277 queue_select_all(g_object_get_data(G_OBJECT(w), "queue"));
1278}
1279
1280static const struct tabtype tabtype_queue = {
1281 queue_properties_sensitive,
1282 queue_selectall_sensitive,
1283 queue_properties_activate,
1284 queue_selectall_activate,
1285};
1286
1287/* Other entry points ------------------------------------------------------ */
1288
1289int queued(const char *track) {
1290 struct queue_entry *q;
1291
1292 D(("queued %s", track));
1293 for(q = ql_queue.q; q; q = q->next)
1294 if(!strcmp(q->track, track))
1295 return 1;
1296 return 0;
1297}
1298
1299/*
1300Local Variables:
1301c-basic-offset:2
1302comment-column:40
1303fill-column:79
1304indent-tabs-mode:nil
1305End:
1306*/