2 * This file is part of DisOrder
3 * Copyright (C) 2006, 2007 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 2 of the License, or
8 * (at your option) any later version.
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.
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
20 /** @file disobedience/queue.c
21 * @brief Queue widgets
23 * This file provides both the queue widget and the recently-played widget.
25 * A queue layout is structured as follows:
31 * titlecells[col] eventbox (made by wrap_queue_cell)
32 * titlecells[col]->child label (from columns[])
35 * cells[row * N + c] eventbox (made by wrap_queue_cell)
36 * cells[row * N + c]->child label (from column constructors)
39 * titlescroll never has any scrollbars. Instead whenever mainscroll's
40 * horizontal adjustment is changed, queue_scrolled adjusts titlescroll to
41 * match, forcing the title and the queue to pan in sync but allowing the queue
42 * to scroll independently.
44 * Whenever the queue changes everything below mainlayout is thrown away and
45 * reconstructed from scratch. Name lookups are cached, so this doesn't imply
46 * lots of disorder protocol traffic.
48 * The last cell on each row is the padding cell, and this extends ridiculously
49 * far to the right. (Can we do better?)
51 * When drag and drop is active we create extra eventboxes to act as dropzones.
52 * These only exist while the drag proceeds, as otherwise they steal events
53 * from more deserving widgets. (It might work to hide them when not in use
54 * too but this way around the d+d code is a bit more self-contained.)
57 #include "disobedience.h"
60 /** @brief Horizontal padding for queue cells */
61 #define HCELLPADDING 4
63 /** @brief Vertical padding for queue cells */
64 #define VCELLPADDING 2
66 /* Queue management -------------------------------------------------------- */
77 static void add_drag_targets(struct queuelike
*ql
);
78 static void remove_drag_targets(struct queuelike
*ql
);
79 static void redisplay_queue(struct queuelike
*ql
);
80 static GtkWidget
*column_when(const struct queuelike
*ql
,
81 const struct queue_entry
*q
,
83 static GtkWidget
*column_who(const struct queuelike
*ql
,
84 const struct queue_entry
*q
,
86 static GtkWidget
*column_namepart(const struct queuelike
*ql
,
87 const struct queue_entry
*q
,
89 static GtkWidget
*column_length(const struct queuelike
*ql
,
90 const struct queue_entry
*q
,
92 static int draggable_row(const struct queue_entry
*q
);
94 static const struct tabtype tabtype_queue
; /* forward */
96 static const GtkTargetEntry dragtargets
[] = {
97 { (char *)"disobedience-queue", GTK_TARGET_SAME_APP
, 0 }
99 #define NDRAGTARGETS (int)(sizeof dragtargets / sizeof *dragtargets)
101 /** @brief Definition of a column */
103 const char *name
; /* Column name */
104 GtkWidget
*(*widget
)(const struct queuelike
*ql
,
105 const struct queue_entry
*q
,
106 const char *data
); /* Make a label for this column */
107 const char *data
; /* Data to pass to widget() */
108 gfloat xalign
; /* Alignment of the label */
111 /** @brief Table of columns for queue and recently played list */
112 static const struct column maincolumns
[] = {
113 { "When", column_when
, 0, 1 },
114 { "Who", column_who
, 0, 0 },
115 { "Artist", column_namepart
, "artist", 0 },
116 { "Album", column_namepart
, "album", 0 },
117 { "Title", column_namepart
, "title", 0 },
118 { "Length", column_length
, 0, 1 }
121 /** @brief Number of columns in queue and recnetly played list */
122 #define NMAINCOLUMNS (int)(sizeof maincolumns / sizeof *maincolumns)
124 /** @brief Table of columns for recently added tracks */
125 static const struct column addedcolumns
[] = {
126 { "Artist", column_namepart
, "artist", 0 },
127 { "Album", column_namepart
, "album", 0 },
128 { "Title", column_namepart
, "title", 0 },
129 { "Length", column_length
, 0, 1 }
132 /** @brief Number of columns in recently added list */
133 #define NADDEDCOLUMNS (int)(sizeof addedcolumns / sizeof *addedcolumns)
135 /** @brief Maximum number of column in any @ref queuelike */
136 #define MAXCOLUMNS (NMAINCOLUMNS > NADDEDCOLUMNS ? NMAINCOLUMNS : NADDEDCOLUMNS)
138 /** @brief Data passed to menu item activation handlers */
139 struct menuiteminfo
{
140 struct queuelike
*ql
; /**< @brief which queue we're dealing with */
141 struct queue_entry
*q
; /**< @brief hovered entry or 0 */
144 /** @brief An item in the queue's popup menu */
145 struct queue_menuitem
{
146 /** @brief Menu item name */
149 /** @brief Called to activate the menu item
151 * The user data is the queue entry that the pointer was over when the menu
153 void (*activate
)(GtkMenuItem
*menuitem
,
156 /** @brief Called to determine whether the menu item is usable.
158 * Returns @c TRUE if it should be sensitive and @c FALSE otherwise. @p q
159 * points to the queue entry the pointer is over.
161 int (*sensitive
)(struct queuelike
*ql
,
162 struct queue_menuitem
*m
,
163 struct queue_entry
*q
);
165 /** @brief Signal handler ID */
168 /** @brief Widget for menu item */
172 /** @brief A queue-like object
174 * There are (currently) three of these: @ref ql_queue, @ref ql_recent and @ref
178 /** @brief Called when an update completes */
179 void (*notify
)(void);
181 /** @brief Called to fix up the queue after update
182 * @param q The list passed back from the server
183 * @return Assigned to @c ql->q
185 struct queue_entry
*(*fixup
)(struct queue_entry
*q
);
188 GtkWidget
*mainlayout
; /**< @brief main layout */
189 GtkWidget
*mainscroll
; /**< @brief scroller for main layout */
190 GtkWidget
*titlelayout
; /**< @brief title layout */
191 GtkWidget
*titlecells
[MAXCOLUMNS
+ 1]; /**< @brief title cells */
192 GtkWidget
**cells
; /**< @brief all the cells */
193 GtkWidget
*menu
; /**< @brief popup menu */
194 struct queue_menuitem
*menuitems
; /**< @brief menu items */
195 GtkWidget
*dragmark
; /**< @brief drag destination marker */
196 GtkWidget
**dropzones
; /**< @brief drag targets */
199 struct queue_entry
*q
; /**< @brief head of queue */
200 struct queue_entry
*last_click
; /**< @brief last click */
201 int nrows
; /**< @brief number of rows */
202 int mainrowheight
; /**< @brief height of one row */
203 hash
*selection
; /**< @brief currently selected items */
204 int swallow_release
; /**< @brief swallow button release from drag */
206 const struct column
*columns
; /**< @brief Table of columns */
207 int ncolumns
; /**< @brief Number of columns */
210 static struct queuelike ql_queue
; /**< @brief The main queue */
211 static struct queuelike ql_recent
; /*< @brief Recently-played tracks */
212 static struct queuelike ql_added
; /*< @brief Newly added tracks */
213 static struct queue_entry
*actual_queue
; /**< @brief actual queue */
214 static struct queue_entry
*playing_track
; /**< @brief currenty playing */
215 static time_t last_playing
= (time_t)-1; /**< @brief when last got playing */
216 static int namepart_lookups_outstanding
;
217 static int namepart_completions_deferred
; /* # of completions not processed */
218 static const struct cache_type cachetype_string
= { 3600 };
219 static const struct cache_type cachetype_integer
= { 3600 };
220 static GtkWidget
*playing_length_label
;
222 /* Debugging --------------------------------------------------------------- */
225 static void describe_widget(const char *name
, GtkWidget
*w
, int indent
) {
229 fprintf(stderr
, "%*s[%s]: '%s'\n", indent
, "",
230 name
, gtk_widget_get_name(w
));
231 gdk_window_get_position(w
->window
, &wx
, &wy
);
232 gdk_drawable_get_size(GDK_DRAWABLE(w
->window
), &ww
, &wh
);
233 fprintf(stderr
, "%*s window %p: %dx%d at %dx%d\n",
234 indent
, "", w
->window
, ww
, wh
, wx
, wy
);
237 static void dump_layout(const struct queuelike
*ql
) {
241 const struct queue_entry
*q
;
243 describe_widget("mainscroll", ql
->mainscroll
, 0);
244 describe_widget("mainlayout", ql
->mainlayout
, 1);
245 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
)
246 for(col
= 0; col
< ql
->ncolumns
+ 1; ++col
)
247 if((w
= ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
])) {
248 sprintf(s
, "%dx%d", row
, col
);
249 describe_widget(s
, w
, 2);
250 if(GTK_BIN(w
)->child
)
251 describe_widget(0, w
, 3);
256 /* Track detail lookup ----------------------------------------------------- */
258 /** @brief Called when a namepart lookup has completed or failed */
259 static void namepart_completed_or_failed(void) {
260 D(("namepart_completed_or_failed"));
261 --namepart_lookups_outstanding
;
262 if(!namepart_lookups_outstanding
) {
263 redisplay_queue(&ql_queue
);
264 redisplay_queue(&ql_recent
);
265 redisplay_queue(&ql_added
);
266 namepart_completions_deferred
= 0;
270 /** @brief Called when A namepart lookup has completed */
271 static void namepart_completed(void *v
, const char *value
) {
272 struct callbackdata
*cbd
= v
;
274 D(("namepart_completed"));
275 cache_put(&cachetype_string
, cbd
->u
.key
, value
);
276 ++namepart_completions_deferred
;
277 namepart_completed_or_failed();
280 /** @brief Called when a length lookup has completed */
281 static void length_completed(void *v
, long l
) {
282 struct callbackdata
*cbd
= v
;
285 D(("namepart_completed"));
286 value
= xmalloc(sizeof *value
);
288 cache_put(&cachetype_integer
, cbd
->u
.key
, value
);
289 ++namepart_completions_deferred
;
290 namepart_completed_or_failed();
293 /** @brief Called when a length or namepart lookup has failed */
294 static void namepart_protocol_error(
295 struct callbackdata
attribute((unused
)) *cbd
,
296 int attribute((unused
)) code
,
298 D(("namepart_protocol_error"));
299 gtk_label_set_text(GTK_LABEL(report_label
), msg
);
300 namepart_completed_or_failed();
303 /** @brief Arrange to fill in a namepart cache entry */
304 static void namepart_fill(const char *track
,
308 struct callbackdata
*cbd
;
310 ++namepart_lookups_outstanding
;
311 cbd
= xmalloc(sizeof *cbd
);
312 cbd
->onerror
= namepart_protocol_error
;
314 disorder_eclient_namepart(client
, namepart_completed
,
315 track
, context
, part
, cbd
);
318 /** @brief Look up a namepart
320 * If it is in the cache then just return its value. If not then look it up
321 * and arrange for the queues to be updated when its value is available. */
322 static const char *namepart(const char *track
,
328 D(("namepart %s %s %s", track
, context
, part
));
329 byte_xasprintf(&key
, "namepart context=%s part=%s track=%s",
330 context
, part
, track
);
331 value
= cache_get(&cachetype_string
, key
);
334 /* stick a value in the cache so we don't issue another lookup if we
336 cache_put(&cachetype_string
, key
, value
= "?");
337 namepart_fill(track
, context
, part
, key
);
342 /** @brief Called from @ref disobedience/properties.c when we know a name part has changed */
343 void namepart_update(const char *track
,
348 byte_xasprintf(&key
, "namepart context=%s part=%s track=%s",
349 context
, part
, track
);
350 /* Only refetch if it's actually in the cache */
351 if(cache_get(&cachetype_string
, key
))
352 namepart_fill(track
, context
, part
, key
);
355 /** @brief Look up a track length
357 * If it is in the cache then just return its value. If not then look it up
358 * and arrange for the queues to be updated when its value is available. */
359 static long getlength(const char *track
) {
362 struct callbackdata
*cbd
;
363 static const long bogus
= -1;
365 D(("getlength %s", track
));
366 byte_xasprintf(&key
, "length track=%s", track
);
367 value
= cache_get(&cachetype_integer
, key
);
369 D(("deferring..."));;
370 cache_put(&cachetype_integer
, key
, value
= &bogus
);
371 ++namepart_lookups_outstanding
;
372 cbd
= xmalloc(sizeof *cbd
);
373 cbd
->onerror
= namepart_protocol_error
;
375 disorder_eclient_length(client
, length_completed
, track
, cbd
);
380 /* Column constructors ----------------------------------------------------- */
382 /** @brief Format the 'when' column */
383 static GtkWidget
*column_when(const struct queuelike
attribute((unused
)) *ql
,
384 const struct queue_entry
*q
,
385 const char attribute((unused
)) *data
) {
392 case playing_isscratch
:
393 case playing_unplayed
:
398 case playing_no_player
:
400 case playing_scratched
:
401 case playing_started
:
403 case playing_quitting
:
411 strftime(when
, sizeof when
, "%H:%M", localtime_r(&t
, &tm
));
415 return gtk_label_new(when
);
418 /** @brief Format the 'who' column */
419 static GtkWidget
*column_who(const struct queuelike
attribute((unused
)) *ql
,
420 const struct queue_entry
*q
,
421 const char attribute((unused
)) *data
) {
424 return gtk_label_new(q
->submitter ? q
->submitter
: "");
427 /** @brief Format one of the track name columns */
428 static GtkWidget
*column_namepart(const struct queuelike
429 attribute((unused
)) *ql
,
430 const struct queue_entry
*q
,
432 D(("column_namepart"));
434 return gtk_label_new(truncate_for_display(namepart(q
->track
, "display", data
),
435 config
->short_display
));
438 /** @brief Compute the length field */
439 static const char *text_length(const struct queue_entry
*q
) {
442 char *played
= 0, *length
= 0;
444 /* Work out what to say for the length */
445 l
= getlength(q
->track
);
447 byte_xasprintf(&length
, "%ld:%02ld", l
/ 60, l
% 60);
449 byte_xasprintf(&length
, "?:??");
450 /* For the currently playing track we want to report how much of the track
452 if(q
== playing_track
) {
453 /* log_state() arranges that we re-get the playing data whenever the
454 * pause/resume state changes */
455 if(last_state
& DISORDER_TRACK_PAUSED
)
456 l
= playing_track
->sofar
;
459 l
= playing_track
->sofar
+ (now
- last_playing
);
461 byte_xasprintf(&played
, "%ld:%02ld/%s", l
/ 60, l
% 60, length
);
467 /** @brief Format the length column */
468 static GtkWidget
*column_length(const struct queuelike
attribute((unused
)) *ql
,
469 const struct queue_entry
*q
,
470 const char attribute((unused
)) *data
) {
471 D(("column_length"));
472 if(q
== playing_track
) {
473 assert(!playing_length_label
);
475 playing_length_label
= gtk_label_new(text_length(q
));
476 /* Zot playing_length_label when it is destroyed */
477 g_signal_connect(playing_length_label
, "destroy",
478 G_CALLBACK(gtk_widget_destroyed
), &playing_length_label
);
479 return playing_length_label
;
482 return gtk_label_new(text_length(q
));
487 /** @brief Apply a new queue contents, transferring the selection from the old value */
488 static void update_queue(struct queuelike
*ql
, struct queue_entry
*newq
) {
489 struct queue_entry
*q
;
492 /* Propagate last_click across the change */
494 for(q
= newq
; q
; q
= q
->next
) {
495 if(!strcmp(q
->id
, ql
->last_click
->id
))
500 /* Tell every queue entry which queue owns it */
501 for(q
= newq
; q
; q
= q
->next
)
503 /* Switch to the new queue */
505 /* Clean up any selected items that have fallen off */
506 for(q
= ql
->q
; q
; q
= q
->next
)
507 selection_live(ql
->selection
, q
->id
);
508 selection_cleanup(ql
->selection
);
511 /** @brief Wrap up a widget for putting into the queue or title
512 * @param label Label to contain
513 * @param style Pointer to style to use
514 * @param wp Updated with maximum width (or NULL)
517 static GtkWidget
*wrap_queue_cell(GtkWidget
*label
,
523 D(("wrap_queue_cell"));
524 /* Padding should be in the label so there are no gaps in the
526 gtk_misc_set_padding(GTK_MISC(label
), HCELLPADDING
, VCELLPADDING
);
527 /* Event box is just to hold a background color */
529 bg
= gtk_event_box_new();
530 gtk_container_add(GTK_CONTAINER(bg
), label
);
532 /* Update maximum width */
533 gtk_widget_size_request(label
, &req
);
534 if(req
.width
> *wp
) *wp
= req
.width
;
537 gtk_widget_set_style(bg
, style
);
538 gtk_widget_set_style(label
, style
);
542 /** @brief Create the wrapped widget for a cell in the queue display */
543 static GtkWidget
*get_queue_cell(struct queuelike
*ql
,
544 const struct queue_entry
*q
,
550 D(("get_queue_cell %d %d", row
, col
));
551 label
= ql
->columns
[col
].widget(ql
, q
, ql
->columns
[col
].data
);
552 gtk_misc_set_alignment(GTK_MISC(label
), ql
->columns
[col
].xalign
, 0);
553 return wrap_queue_cell(label
, style
, wp
);
556 /** @brief Add a padding cell to the end of a row */
557 static GtkWidget
*get_padding_cell(GtkStyle
*style
) {
558 D(("get_padding_cell"));
560 return wrap_queue_cell(gtk_label_new(""), style
, 0);
563 /* User button press and menu ---------------------------------------------- */
565 /** @brief Update widget states in order to reflect the selection status */
566 static void set_widget_states(struct queuelike
*ql
) {
567 struct queue_entry
*q
;
570 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
) {
571 for(col
= 0; col
< ql
->ncolumns
+ 1; ++col
)
572 gtk_widget_set_state(ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
],
573 selection_selected(ql
->selection
, q
->id
) ?
574 GTK_STATE_SELECTED
: GTK_STATE_NORMAL
);
576 /* Might need to change sensitivity of 'Properties' in main menu */
580 /** @brief Ordering function for queue entries */
581 static int queue_before(const struct queue_entry
*a
,
582 const struct queue_entry
*b
) {
588 /** @brief A button was pressed and released */
589 static gboolean
queuelike_button_released(GtkWidget
attribute((unused
)) *widget
,
590 GdkEventButton
*event
,
591 gpointer user_data
) {
592 struct queue_entry
*q
= user_data
, *qq
;
593 struct queuelike
*ql
= q
->ql
;
594 struct menuiteminfo
*mii
;
597 /* Might be a release left over from a drag */
598 if(ql
->swallow_release
) {
599 ql
->swallow_release
= 0;
600 return FALSE
; /* propagate */
603 if(event
->type
== GDK_BUTTON_PRESS
604 && event
->button
== 3) {
605 /* Right button click.
606 * If the current item is not selected then switch the selection to just
608 if(q
&& !selection_selected(ql
->selection
, q
->id
)) {
609 selection_empty(ql
->selection
);
610 selection_set(ql
->selection
, q
->id
, 1);
612 set_widget_states(ql
);
614 /* Set the sensitivity of each menu item and (re-)establish the signal
616 for(n
= 0; ql
->menuitems
[n
].name
; ++n
) {
617 if(ql
->menuitems
[n
].handlerid
)
618 g_signal_handler_disconnect(ql
->menuitems
[n
].w
,
619 ql
->menuitems
[n
].handlerid
);
620 gtk_widget_set_sensitive(ql
->menuitems
[n
].w
,
621 ql
->menuitems
[n
].sensitive(ql
,
624 mii
= xmalloc(sizeof *mii
);
627 ql
->menuitems
[n
].handlerid
= g_signal_connect
628 (ql
->menuitems
[n
].w
, "activate",
629 G_CALLBACK(ql
->menuitems
[n
].activate
), mii
);
631 /* Update the menu according to context */
632 gtk_widget_show_all(ql
->menu
);
633 gtk_menu_popup(GTK_MENU(ql
->menu
), 0, 0, 0, 0,
634 event
->button
, event
->time
);
635 return TRUE
; /* hide the click from other widgets */
637 if(event
->type
== GDK_BUTTON_RELEASE
638 && event
->button
== 1) {
639 /* no modifiers: select this, unselect everything else, set last click
640 * +ctrl: flip selection of this, set last click
641 * +shift: select from last click to here, don't set last click
642 * +ctrl+shift: select from last click to here, set last click
644 switch(event
->state
& (GDK_SHIFT_MASK
|GDK_CONTROL_MASK
)) {
646 selection_empty(ql
->selection
);
647 selection_set(ql
->selection
, q
->id
, 1);
650 case GDK_CONTROL_MASK
:
651 selection_flip(ql
->selection
, q
->id
);
655 case GDK_SHIFT_MASK
|GDK_CONTROL_MASK
:
657 if(!(event
->state
& GDK_CONTROL_MASK
))
658 selection_empty(ql
->selection
);
659 selection_set(ql
->selection
, q
->id
, 1);
661 if(queue_before(ql
->last_click
, q
))
662 while(qq
!= ql
->last_click
) {
664 selection_set(ql
->selection
, qq
->id
, 1);
667 while(qq
!= ql
->last_click
) {
669 selection_set(ql
->selection
, qq
->id
, 1);
671 if(event
->state
& GDK_CONTROL_MASK
)
676 set_widget_states(ql
);
677 gtk_widget_queue_draw(ql
->mainlayout
);
679 return FALSE
; /* propagate */
682 /** @brief A button was pressed or released on the mainlayout
684 * For debugging only at the moment. */
685 static gboolean
mainlayout_button(GtkWidget
attribute((unused
)) *widget
,
686 GdkEventButton
attribute((unused
)) *event
,
687 gpointer
attribute((unused
)) user_data
) {
688 return FALSE
; /* propagate */
691 /** @brief Select all entries in a queue */
692 void queue_select_all(struct queuelike
*ql
) {
693 struct queue_entry
*qq
;
695 for(qq
= ql
->q
; qq
; qq
= qq
->next
)
696 selection_set(ql
->selection
, qq
->id
, 1);
698 set_widget_states(ql
);
701 /** @brief Pop up properties for selected tracks */
702 void queue_properties(struct queuelike
*ql
) {
704 const struct queue_entry
*qq
;
707 for(qq
= ql
->q
; qq
; qq
= qq
->next
)
708 if(selection_selected(ql
->selection
, qq
->id
))
709 vector_append(&v
, (char *)qq
->track
);
711 properties(v
.nvec
, (const char **)v
.vec
);
714 /* Drag and drop rearrangement --------------------------------------------- */
716 /** @brief Return nonzero if @p is a draggable row
718 * Only tracks in the main queue are draggable (and the currently playing track
721 static int draggable_row(const struct queue_entry
*q
) {
722 return q
->ql
== &ql_queue
&& q
!= playing_track
;
725 /** @brief Called when a drag begings */
726 static void queue_drag_begin(GtkWidget
attribute((unused
)) *widget
,
727 GdkDragContext
attribute((unused
)) *dc
,
729 struct queue_entry
*q
= data
;
730 struct queuelike
*ql
= q
->ql
;
732 /* Make sure the playing track is not selected, since it cannot be dragged */
734 selection_set(ql
->selection
, playing_track
->id
, 0);
735 /* If the dragged item is not in the selection then change the selection to
737 if(!selection_selected(ql
->selection
, q
->id
)) {
738 selection_empty(ql
->selection
);
739 selection_set(ql
->selection
, q
->id
, 1);
740 set_widget_states(ql
);
742 /* Ignore the eventual button release */
743 ql
->swallow_release
= 1;
744 /* Create dropzones */
745 add_drag_targets(ql
);
748 /** @brief Convert @p id back into a queue entry and a screen row number */
749 static struct queue_entry
*findentry(struct queuelike
*ql
,
753 struct queue_entry
*q
;
756 for(q
= ql
->q
, row
= 0; q
&& strcmp(q
->id
, id
); q
= q
->next
, ++row
)
760 row
= playing_track ?
0 : -1;
762 if(rowp
) *rowp
= row
;
766 /** @brief Called when data is dropped */
767 static gboolean
queue_drag_drop(GtkWidget
attribute((unused
)) *widget
,
768 GdkDragContext
*drag_context
,
769 gint
attribute((unused
)) x
,
770 gint
attribute((unused
)) y
,
772 gpointer user_data
) {
773 struct queuelike
*ql
= &ql_queue
;
774 const char *id
= user_data
;
776 struct queue_entry
*q
;
778 if(!id
|| (playing_track
&& !strcmp(id
, playing_track
->id
)))
781 for(q
= ql
->q
; q
; q
= q
->next
)
782 if(q
!= playing_track
&& selection_selected(ql
->selection
, q
->id
))
783 vector_append(&vec
, (char *)q
->id
);
784 disorder_eclient_moveafter(client
, id
, vec
.nvec
, (const char **)vec
.vec
,
785 0/*completed*/, 0/*v*/);
786 gtk_drag_finish(drag_context
, TRUE
, TRUE
, when
);
787 /* Destroy dropzones */
788 remove_drag_targets(ql
);
792 /** @brief Called when we enter, or move within, a drop zone */
793 static gboolean
queue_drag_motion(GtkWidget
attribute((unused
)) *widget
,
794 GdkDragContext
*drag_context
,
795 gint
attribute((unused
)) x
,
796 gint
attribute((unused
)) y
,
798 gpointer user_data
) {
799 struct queuelike
*ql
= &ql_queue
;
800 const char *id
= user_data
;
802 struct queue_entry
*q
= findentry(ql
, id
, &row
);
807 ql
->dragmark
= gtk_event_box_new();
808 g_signal_connect(ql
->dragmark
, "destroy",
809 G_CALLBACK(gtk_widget_destroyed
), &ql
->dragmark
);
810 gtk_widget_set_size_request(ql
->dragmark
, 10240, row ?
4 : 2);
811 gtk_widget_set_style(ql
->dragmark
, drag_style
);
812 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), ql
->dragmark
, 0,
813 (row
+ 1) * ql
->mainrowheight
- !!row
);
815 gtk_layout_move(GTK_LAYOUT(ql
->mainlayout
), ql
->dragmark
, 0,
816 (row
+ 1) * ql
->mainrowheight
- !!row
);
817 gtk_widget_show(ql
->dragmark
);
818 gdk_drag_status(drag_context
, GDK_ACTION_MOVE
, when
);
821 /* ID has gone AWOL */
825 /** @brief Called when we leave a drop zone */
826 static void queue_drag_leave(GtkWidget
attribute((unused
)) *widget
,
827 GdkDragContext
attribute((unused
)) *drag_context
,
828 guint
attribute((unused
)) when
,
829 gpointer
attribute((unused
)) user_data
) {
830 struct queuelike
*ql
= &ql_queue
;
833 gtk_widget_hide(ql
->dragmark
);
836 /** @brief Add a drag target at position @p y
838 * @p id is the track to insert the moved tracks after, and might be 0 to
839 * insert before the start. */
840 static void add_drag_target(struct queuelike
*ql
, int y
, int row
,
844 assert(ql
->dropzones
[row
] == 0);
846 eventbox
= gtk_event_box_new();
847 /* Make the target zone invisible */
848 gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox
), FALSE
);
849 /* Make it large enough */
850 gtk_widget_set_size_request(eventbox
, 10240,
851 y ? ql
->mainrowheight
: ql
->mainrowheight
/ 2);
853 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), eventbox
, 0,
854 y ? y
- ql
->mainrowheight
/ 2 : 0);
855 /* Mark it as capable of receiving drops */
856 gtk_drag_dest_set(eventbox
,
858 dragtargets
, NDRAGTARGETS
, GDK_ACTION_MOVE
);
859 g_signal_connect(eventbox
, "drag-drop",
860 G_CALLBACK(queue_drag_drop
), (char *)id
);
861 /* Monitor drag motion */
862 g_signal_connect(eventbox
, "drag-motion",
863 G_CALLBACK(queue_drag_motion
), (char *)id
);
864 g_signal_connect(eventbox
, "drag-leave",
865 G_CALLBACK(queue_drag_leave
), (char *)id
);
866 /* The widget needs to be shown to receive drags */
867 gtk_widget_show(eventbox
);
868 /* Remember the drag targets */
869 ql
->dropzones
[row
] = eventbox
;
870 g_signal_connect(eventbox
, "destroy",
871 G_CALLBACK(gtk_widget_destroyed
), &ql
->dropzones
[row
]);
874 /** @brief Create dropzones for dragging into */
875 static void add_drag_targets(struct queuelike
*ql
) {
877 struct queue_entry
*q
;
879 /* Create an array to store the widgets */
880 ql
->dropzones
= xcalloc(ql
->nrows
, sizeof (GtkWidget
*));
882 /* Add a drag target before the first row provided it's not the playing
884 if(!playing_track
|| ql
->q
!= playing_track
)
885 add_drag_target(ql
, 0, 0, 0);
886 /* Put a drag target at the bottom of every row */
887 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
) {
888 y
+= ql
->mainrowheight
;
889 add_drag_target(ql
, y
, row
, q
->id
);
893 /** @brief Remove the dropzones */
894 static void remove_drag_targets(struct queuelike
*ql
) {
897 for(row
= 0; row
< ql
->nrows
; ++row
) {
898 if(ql
->dropzones
[row
]) {
900 gtk_widget_destroy(ql
->dropzones
[row
]);
902 assert(ql
->dropzones
[row
] == 0);
906 /* Layout ------------------------------------------------------------------ */
908 /** @brief Redisplay a queue */
909 static void redisplay_queue(struct queuelike
*ql
) {
910 struct queue_entry
*q
;
916 int maxwidths
[MAXCOLUMNS
], x
, y
, titlerowheight
;
917 int totalwidth
= 10240; /* TODO: can we be less blunt */
919 D(("redisplay_queue"));
920 /* Eliminate all the existing widgets and start from scratch */
921 for(c
= children
= gtk_container_get_children(GTK_CONTAINER(ql
->mainlayout
));
924 /* Destroy both the label and the eventbox */
925 if(GTK_BIN(c
->data
)->child
) {
927 gtk_widget_destroy(GTK_BIN(c
->data
)->child
);
930 gtk_widget_destroy(GTK_WIDGET(c
->data
));
932 g_list_free(children
);
933 /* Adjust the row count */
934 for(q
= ql
->q
, ql
->nrows
= 0; q
; q
= q
->next
)
936 /* We need to create all the widgets before we can position them */
937 ql
->cells
= xcalloc(ql
->nrows
* (ql
->ncolumns
+ 1), sizeof *ql
->cells
);
938 /* Minimum width is given by the column headings */
939 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
940 /* Reset size so we don't inherit last iteration's maximum size */
941 gtk_widget_set_size_request(GTK_BIN(ql
->titlecells
[col
])->child
, -1, -1);
942 gtk_widget_size_request(GTK_BIN(ql
->titlecells
[col
])->child
, &req
);
943 maxwidths
[col
] = req
.width
;
945 /* Find the vertical size of the title bar */
946 gtk_widget_size_request(GTK_BIN(ql
->titlecells
[0])->child
, &req
);
947 titlerowheight
= req
.height
;
950 /* Construct the widgets */
951 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
) {
952 /* Figure out the widget name for this row */
953 if(q
== playing_track
) style
= active_style
;
954 else style
= row
% 2 ? even_style
: odd_style
;
955 /* Make the widget for each column */
956 for(col
= 0; col
<= ql
->ncolumns
; ++col
) {
957 /* Create and store the widget */
958 if(col
< ql
->ncolumns
)
959 w
= get_queue_cell(ql
, q
, row
, col
, style
, &maxwidths
[col
]);
961 w
= get_padding_cell(style
);
962 ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
] = w
;
963 /* Maybe mark it draggable */
964 if(draggable_row(q
)) {
965 gtk_drag_source_set(w
, GDK_BUTTON1_MASK
,
966 dragtargets
, NDRAGTARGETS
, GDK_ACTION_MOVE
);
967 g_signal_connect(w
, "drag-begin", G_CALLBACK(queue_drag_begin
), q
);
969 /* Catch button presses */
970 g_signal_connect(w
, "button-release-event",
971 G_CALLBACK(queuelike_button_released
), q
);
972 g_signal_connect(w
, "button-press-event",
973 G_CALLBACK(queuelike_button_released
), q
);
976 /* ...and of each row in the main layout */
977 gtk_widget_size_request(GTK_BIN(ql
->cells
[0])->child
, &req
);
978 ql
->mainrowheight
= req
.height
;
979 /* Now we know the maximum width of each column we can set the size of
980 * everything and position it */
981 for(row
= 0, q
= ql
->q
; row
< ql
->nrows
; ++row
, q
= q
->next
) {
983 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
984 w
= ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
];
985 gtk_widget_set_size_request(GTK_BIN(w
)->child
,
987 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), w
, x
, y
);
990 w
= ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
];
991 gtk_widget_set_size_request(GTK_BIN(w
)->child
,
993 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), w
, x
, y
);
994 y
+= ql
->mainrowheight
;
999 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
1000 gtk_widget_set_size_request(GTK_BIN(ql
->titlecells
[col
])->child
,
1001 maxwidths
[col
], -1);
1002 gtk_layout_move(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], x
, 0);
1003 x
+= maxwidths
[col
];
1005 gtk_widget_set_size_request(GTK_BIN(ql
->titlecells
[col
])->child
,
1006 totalwidth
- x
, -1);
1007 gtk_layout_move(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], x
, 0);
1008 /* Set the states */
1009 set_widget_states(ql
);
1010 /* Make sure it's all visible */
1011 gtk_widget_show_all(ql
->mainlayout
);
1012 gtk_widget_show_all(ql
->titlelayout
);
1013 /* Layouts might shrink to arrange for the area they shrink out of to be
1015 gtk_widget_queue_draw(ql
->mainlayout
);
1016 gtk_widget_queue_draw(ql
->titlelayout
);
1017 /* Adjust the size of the layout */
1018 gtk_layout_set_size(GTK_LAYOUT(ql
->mainlayout
), x
, y
);
1019 gtk_layout_set_size(GTK_LAYOUT(ql
->titlelayout
), x
, titlerowheight
);
1020 gtk_widget_set_size_request(ql
->titlelayout
, -1, titlerowheight
);
1023 /** @brief Called with new queue/recent contents */
1024 static void queuelike_completed(void *v
, struct queue_entry
*q
) {
1025 struct callbackdata
*cbd
= v
;
1026 struct queuelike
*ql
= cbd
->u
.ql
;
1028 D(("queuelike_complete"));
1029 /* Install the new queue */
1030 update_queue(ql
, ql
->fixup ? ql
->fixup(q
) : q
);
1031 /* Update the display */
1032 redisplay_queue(ql
);
1035 /* Update sensitivity of main menu items */
1039 /** @brief Called with a new currently playing track */
1040 static void playing_completed(void attribute((unused
)) *v
,
1041 struct queue_entry
*q
) {
1042 struct callbackdata cbd
;
1043 D(("playing_completed"));
1045 /* Record when we got the playing track data so we know how old the 'sofar'
1047 time(&last_playing
);
1048 cbd
.u
.ql
= &ql_queue
;
1049 queuelike_completed(&cbd
, actual_queue
);
1052 /** @brief Called when the queue is scrolled */
1053 static void queue_scrolled(GtkAdjustment
*adjustment
,
1054 gpointer user_data
) {
1055 GtkAdjustment
*titleadj
= user_data
;
1057 D(("queue_scrolled"));
1058 gtk_adjustment_set_value(titleadj
, adjustment
->value
);
1061 /** @brief Create a queuelike thing (queue/recent) */
1062 static GtkWidget
*queuelike(struct queuelike
*ql
,
1063 struct queue_entry
*(*fixup
)(struct queue_entry
*),
1064 void (*notify
)(void),
1065 struct queue_menuitem
*menuitems
,
1066 const struct column
*columns
,
1068 GtkWidget
*vbox
, *mainscroll
, *titlescroll
, *label
;
1069 GtkAdjustment
*mainadj
, *titleadj
;
1074 ql
->notify
= notify
;
1075 ql
->menuitems
= menuitems
;
1076 ql
->mainrowheight
= !0; /* else division by 0 */
1077 ql
->selection
= selection_new();
1078 ql
->columns
= columns
;
1079 ql
->ncolumns
= ncolumns
;
1080 /* Create the layouts */
1082 ql
->mainlayout
= gtk_layout_new(0, 0);
1083 gtk_widget_set_style(ql
->mainlayout
, layout_style
);
1085 ql
->titlelayout
= gtk_layout_new(0, 0);
1086 gtk_widget_set_style(ql
->titlelayout
, title_style
);
1087 /* Scroll the layouts */
1088 ql
->mainscroll
= mainscroll
= scroll_widget(ql
->mainlayout
);
1089 titlescroll
= scroll_widget(ql
->titlelayout
);
1090 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(titlescroll
),
1091 GTK_POLICY_NEVER
, GTK_POLICY_NEVER
);
1092 mainadj
= gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(mainscroll
));
1093 titleadj
= gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(titlescroll
));
1094 g_signal_connect(mainadj
, "changed", G_CALLBACK(queue_scrolled
), titleadj
);
1095 g_signal_connect(mainadj
, "value-changed", G_CALLBACK(queue_scrolled
), titleadj
);
1096 /* Fill the titles and put them anywhere */
1097 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
1099 label
= gtk_label_new(ql
->columns
[col
].name
);
1100 gtk_misc_set_alignment(GTK_MISC(label
), ql
->columns
[col
].xalign
, 0);
1101 ql
->titlecells
[col
] = wrap_queue_cell(label
, title_style
, 0);
1102 gtk_layout_put(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], 0, 0);
1104 ql
->titlecells
[col
] = get_padding_cell(title_style
);
1105 gtk_layout_put(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], 0, 0);
1106 /* Pack the lot together in a vbox */
1108 vbox
= gtk_vbox_new(0, 0);
1109 gtk_box_pack_start(GTK_BOX(vbox
), titlescroll
, 0, 0, 0);
1110 gtk_box_pack_start(GTK_BOX(vbox
), mainscroll
, 1, 1, 0);
1111 /* Create the popup menu */
1113 ql
->menu
= gtk_menu_new();
1114 g_signal_connect(ql
->menu
, "destroy",
1115 G_CALLBACK(gtk_widget_destroyed
), &ql
->menu
);
1116 for(n
= 0; menuitems
[n
].name
; ++n
) {
1118 menuitems
[n
].w
= gtk_menu_item_new_with_label(menuitems
[n
].name
);
1119 gtk_menu_attach(GTK_MENU(ql
->menu
), menuitems
[n
].w
, 0, 1, n
, n
+ 1);
1121 g_object_set_data(G_OBJECT(vbox
), "type", (void *)&tabtype_queue
);
1122 g_object_set_data(G_OBJECT(vbox
), "queue", ql
);
1123 /* Catch button presses */
1124 g_signal_connect(ql
->mainlayout
, "button-release-event",
1125 G_CALLBACK(mainlayout_button
), ql
);
1127 g_signal_connect(ql
->mainlayout
, "button-press-event",
1128 G_CALLBACK(mainlayout_button
), ql
);
1130 set_tool_colors(ql
->menu
);
1134 /* Popup menu items -------------------------------------------------------- */
1136 /** @brief Count the number of items selected */
1137 static int queue_count_selected(const struct queuelike
*ql
) {
1138 return hash_count(ql
->selection
);
1141 /** @brief Count the number of items selected */
1142 static int queue_count_entries(const struct queuelike
*ql
) {
1144 const struct queue_entry
*q
;
1146 for(q
= ql
->q
; q
; q
= q
->next
)
1151 /** @brief Count the number of items selected, excluding the playing track if
1153 static int count_selected_nonplaying(const struct queuelike
*ql
) {
1154 int nselected
= queue_count_selected(ql
);
1156 if(ql
->q
== playing_track
&& selection_selected(ql
->selection
, ql
->q
->id
))
1161 /** @brief Determine whether the scratch option should be sensitive */
1162 static int scratch_sensitive(struct queuelike
attribute((unused
)) *ql
,
1163 struct queue_menuitem
attribute((unused
)) *m
,
1164 struct queue_entry
attribute((unused
)) *q
) {
1165 /* We can scratch if the playing track is selected */
1166 return (playing_track
1167 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)
1168 && selection_selected(ql
->selection
, playing_track
->id
));
1171 /** @brief Scratch the playing track */
1172 static void scratch_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1173 gpointer
attribute((unused
)) user_data
) {
1175 disorder_eclient_scratch(client
, playing_track
->id
, 0, 0);
1178 /** @brief Determine whether the remove option should be sensitive */
1179 static int remove_sensitive(struct queuelike
*ql
,
1180 struct queue_menuitem
attribute((unused
)) *m
,
1181 struct queue_entry
*q
) {
1182 /* We can remove if we're hovering over a particular track or any non-playing
1183 * tracks are selected */
1184 return ((disorder_eclient_state(client
) & DISORDER_CONNECTED
)
1186 && q
!= playing_track
)
1187 || count_selected_nonplaying(ql
)));
1190 /** @brief Remove selected track(s) */
1191 static void remove_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1192 gpointer user_data
) {
1193 const struct menuiteminfo
*mii
= user_data
;
1194 struct queue_entry
*q
= mii
->q
;
1195 struct queuelike
*ql
= mii
->ql
;
1197 if(count_selected_nonplaying(mii
->ql
)) {
1198 /* Remove selected tracks */
1199 for(q
= ql
->q
; q
; q
= q
->next
)
1200 if(selection_selected(ql
->selection
, q
->id
) && q
!= playing_track
)
1201 disorder_eclient_remove(client
, q
->id
, 0, 0);
1203 /* Remove just the hovered track */
1204 disorder_eclient_remove(client
, q
->id
, 0, 0);
1207 /** @brief Determine whether the properties menu option should be sensitive */
1208 static int properties_sensitive(struct queuelike
*ql
,
1209 struct queue_menuitem
attribute((unused
)) *m
,
1210 struct queue_entry
attribute((unused
)) *q
) {
1211 /* "Properties" is sensitive if at least something is selected */
1212 return (hash_count(ql
->selection
) > 0
1213 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
));
1216 /** @brief Pop up properties for the selected tracks */
1217 static void properties_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1218 gpointer user_data
) {
1219 const struct menuiteminfo
*mii
= user_data
;
1221 queue_properties(mii
->ql
);
1224 /** @brief Determine whether the select all menu option should be sensitive */
1225 static int selectall_sensitive(struct queuelike
*ql
,
1226 struct queue_menuitem
attribute((unused
)) *m
,
1227 struct queue_entry
attribute((unused
)) *q
) {
1228 /* Sensitive if there is anything to select */
1232 /** @brief Select all tracks */
1233 static void selectall_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1234 gpointer user_data
) {
1235 const struct menuiteminfo
*mii
= user_data
;
1236 queue_select_all(mii
->ql
);
1239 /** @brief Determine whether the play menu option should be sensitive */
1240 static int play_sensitive(struct queuelike
*ql
,
1241 struct queue_menuitem
attribute((unused
)) *m
,
1242 struct queue_entry
attribute((unused
)) *q
) {
1243 /* "Play" is sensitive if at least something is selected */
1244 return (hash_count(ql
->selection
) > 0
1245 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
));
1248 /** @brief Play the selected tracks */
1249 static void play_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1250 gpointer user_data
) {
1251 const struct menuiteminfo
*mii
= user_data
;
1252 struct queue_entry
*q
= mii
->q
;
1253 struct queuelike
*ql
= mii
->ql
;
1255 if(queue_count_selected(ql
)) {
1256 /* Play selected tracks */
1257 for(q
= ql
->q
; q
; q
= q
->next
)
1258 if(selection_selected(ql
->selection
, q
->id
))
1259 disorder_eclient_play(client
, q
->track
, 0, 0);
1261 /* Nothing is selected, so play the hovered track */
1262 disorder_eclient_play(client
, q
->track
, 0, 0);
1265 /* The queue --------------------------------------------------------------- */
1267 /** @brief Fix up the queue by sticking the currently playing track on the front */
1268 static struct queue_entry
*fixup_queue(struct queue_entry
*q
) {
1273 actual_queue
->prev
= playing_track
;
1274 playing_track
->next
= actual_queue
;
1275 return playing_track
;
1277 return actual_queue
;
1280 /** @brief Adjust track played label
1282 * Called regularly to adjust the so-far played label (redrawing the whole
1283 * queue once a second makes disobedience occupy >10% of the CPU on my Athlon
1284 * which is ureasonable expensive) */
1285 static gboolean
adjust_sofar(gpointer
attribute((unused
)) data
) {
1286 if(playing_length_label
&& playing_track
)
1287 gtk_label_set_text(GTK_LABEL(playing_length_label
),
1288 text_length(playing_track
));
1292 /** @brief Popup menu for the queue
1294 * Properties first so that finger trouble is less dangerous. */
1295 static struct queue_menuitem queue_menu
[] = {
1296 { "Track properties", properties_activate
, properties_sensitive
, 0, 0 },
1297 { "Select all tracks", selectall_activate
, selectall_sensitive
, 0, 0 },
1298 { "Scratch track", scratch_activate
, scratch_sensitive
, 0, 0 },
1299 { "Remove track from queue", remove_activate
, remove_sensitive
, 0, 0 },
1303 /** @brief Called whenever @ref DISORDER_PLAYING or @ref DISORDER_TRACK_PAUSED changes
1305 * We monitor pause/resume as well as whether the track is playing in order to
1306 * keep the time played so far up to date correctly. See playing_completed().
1308 static void playing_update(void attribute((unused
)) *v
) {
1309 D(("playing_update"));
1310 gtk_label_set_text(GTK_LABEL(report_label
), "updating playing track");
1311 disorder_eclient_playing(client
, playing_completed
, 0);
1314 /** @brief Create the queue widget */
1315 GtkWidget
*queue_widget(void) {
1316 D(("queue_widget"));
1317 /* Arrange periodic update of the so-far played field */
1318 g_timeout_add(1000/*ms*/, adjust_sofar
, 0);
1319 /* Arrange a callback whenever the playing state changes */
1320 register_monitor(playing_update
, 0, DISORDER_PLAYING
|DISORDER_TRACK_PAUSED
);
1321 register_reset(queue_update
);
1322 /* We pass choose_update() as our notify function since the choose screen
1323 * marks tracks that are playing/in the queue. */
1324 return queuelike(&ql_queue
, fixup_queue
, choose_update
, queue_menu
,
1325 maincolumns
, NMAINCOLUMNS
);
1328 /** @brief Arrange an update of the queue widget
1330 * Called when a track is added to the queue, removed from the queue (by user
1331 * cmmand or because it is to be played) or moved within the queue
1333 void queue_update(void) {
1334 struct callbackdata
*cbd
;
1336 D(("queue_update"));
1337 cbd
= xmalloc(sizeof *cbd
);
1339 cbd
->u
.ql
= &ql_queue
;
1340 gtk_label_set_text(GTK_LABEL(report_label
), "updating queue");
1341 disorder_eclient_queue(client
, queuelike_completed
, cbd
);
1344 /* Recently played tracks -------------------------------------------------- */
1346 /** @brief Fix up the recently played list
1348 * It's in the wrong order! TODO fix this globally */
1349 static struct queue_entry
*fixup_recent(struct queue_entry
*q
) {
1350 struct queue_entry
*qr
= 0, *qn
;
1352 D(("fixup_recent"));
1355 /* Swap next/prev pointers */
1358 /* Remember last node for new head */
1366 /** @brief Pop-up menu for recently played list */
1367 static struct queue_menuitem recent_menu
[] = {
1368 { "Track properties", properties_activate
, properties_sensitive
,0, 0 },
1369 { "Select all tracks", selectall_activate
, selectall_sensitive
, 0, 0 },
1373 /** @brief Create the recently-played list */
1374 GtkWidget
*recent_widget(void) {
1375 D(("recent_widget"));
1376 register_reset(recent_update
);
1377 return queuelike(&ql_recent
, fixup_recent
, 0, recent_menu
,
1378 maincolumns
, NMAINCOLUMNS
);
1381 /** @brief Update the recently played list
1383 * Called whenever a track is added to it or removed from it.
1385 void recent_update(void) {
1386 struct callbackdata
*cbd
;
1388 D(("recent_update"));
1389 cbd
= xmalloc(sizeof *cbd
);
1391 cbd
->u
.ql
= &ql_recent
;
1392 gtk_label_set_text(GTK_LABEL(report_label
), "updating recently played list");
1393 disorder_eclient_recent(client
, queuelike_completed
, cbd
);
1396 /* Newly added tracks ------------------------------------------------------ */
1398 /** @brief Pop-up menu for recently played list */
1399 static struct queue_menuitem added_menu
[] = {
1400 { "Track properties", properties_activate
, properties_sensitive
, 0, 0 },
1401 { "Play track", play_activate
, play_sensitive
, 0, 0 },
1402 { "Select all tracks", selectall_activate
, selectall_sensitive
, 0, 0 },
1406 /** @brief Create the newly-added list */
1407 GtkWidget
*added_widget(void) {
1408 D(("added_widget"));
1409 register_reset(added_update
);
1410 return queuelike(&ql_added
, 0/*fixup*/, 0/*notify*/, added_menu
,
1411 addedcolumns
, NADDEDCOLUMNS
);
1414 /** @brief Called with an updated list of newly-added tracks
1416 * This is called with a raw list of track names but the rest of @ref
1417 * disobedience/queue.c requires @ref queue_entry structures with a valid and
1418 * unique @c id field. This function fakes it.
1420 static void new_completed(void *v
, int nvec
, char **vec
) {
1421 struct queue_entry
*q
, *qh
, *qlast
= 0, **qq
= &qh
;
1424 for(n
= 0; n
< nvec
; ++n
) {
1425 q
= xmalloc(sizeof *q
);
1434 queuelike_completed(v
, qh
);
1437 /** @brief Update the newly-added list */
1438 void added_update(void) {
1439 struct callbackdata
*cbd
;
1442 cbd
= xmalloc(sizeof *cbd
);
1444 cbd
->u
.ql
= &ql_added
;
1445 gtk_label_set_text(GTK_LABEL(report_label
),
1446 "updating newly added track list");
1447 disorder_eclient_new_tracks(client
, new_completed
, 0/*all*/, cbd
);
1450 /* Main menu plumbing ------------------------------------------------------ */
1452 static int queue_properties_sensitive(GtkWidget
*w
) {
1453 return (!!queue_count_selected(g_object_get_data(G_OBJECT(w
), "queue"))
1454 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
));
1457 static int queue_selectall_sensitive(GtkWidget
*w
) {
1458 return !!queue_count_entries(g_object_get_data(G_OBJECT(w
), "queue"));
1461 static void queue_properties_activate(GtkWidget
*w
) {
1462 queue_properties(g_object_get_data(G_OBJECT(w
), "queue"));
1465 static void queue_selectall_activate(GtkWidget
*w
) {
1466 queue_select_all(g_object_get_data(G_OBJECT(w
), "queue"));
1469 static const struct tabtype tabtype_queue
= {
1470 queue_properties_sensitive
,
1471 queue_selectall_sensitive
,
1472 queue_properties_activate
,
1473 queue_selectall_activate
,
1476 /* Other entry points ------------------------------------------------------ */
1478 /** @brief Return nonzero if @p track is in the queue */
1479 int queued(const char *track
) {
1480 struct queue_entry
*q
;
1482 D(("queued %s", track
));
1483 for(q
= ql_queue
.q
; q
; q
= q
->next
)
1484 if(!strcmp(q
->track
, track
))
1494 indent-tabs-mode:nil