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"
59 /** @brief Horizontal padding for queue cells */
60 #define HCELLPADDING 4
62 /** @brief Vertical padding for queue cells */
63 #define VCELLPADDING 2
65 /* Queue management -------------------------------------------------------- */
76 static void add_drag_targets(struct queuelike
*ql
);
77 static void remove_drag_targets(struct queuelike
*ql
);
78 static void redisplay_queue(struct queuelike
*ql
);
79 static GtkWidget
*column_when(const struct queuelike
*ql
,
80 const struct queue_entry
*q
,
82 static GtkWidget
*column_who(const struct queuelike
*ql
,
83 const struct queue_entry
*q
,
85 static GtkWidget
*column_namepart(const struct queuelike
*ql
,
86 const struct queue_entry
*q
,
88 static GtkWidget
*column_length(const struct queuelike
*ql
,
89 const struct queue_entry
*q
,
91 static int draggable_row(const struct queue_entry
*q
);
93 static const struct tabtype tabtype_queue
; /* forward */
95 static const GtkTargetEntry dragtargets
[] = {
96 { (char *)"disobedience-queue", GTK_TARGET_SAME_APP
, 0 }
98 #define NDRAGTARGETS (int)(sizeof dragtargets / sizeof *dragtargets)
100 /** @brief Definition of a column */
102 const char *name
; /* Column name */
103 GtkWidget
*(*widget
)(const struct queuelike
*ql
,
104 const struct queue_entry
*q
,
105 const char *data
); /* Make a label for this column */
106 const char *data
; /* Data to pass to widget() */
107 gfloat xalign
; /* Alignment of the label */
110 /** @brief Table of columns for queue and recently played list */
111 static const struct column maincolumns
[] = {
112 { "When", column_when
, 0, 1 },
113 { "Who", column_who
, 0, 0 },
114 { "Artist", column_namepart
, "artist", 0 },
115 { "Album", column_namepart
, "album", 0 },
116 { "Title", column_namepart
, "title", 0 },
117 { "Length", column_length
, 0, 1 }
120 /** @brief Number of columns in queue and recnetly played list */
121 #define NMAINCOLUMNS (int)(sizeof maincolumns / sizeof *maincolumns)
123 /** @brief Table of columns for recently added tracks */
124 static const struct column addedcolumns
[] = {
125 { "Artist", column_namepart
, "artist", 0 },
126 { "Album", column_namepart
, "album", 0 },
127 { "Title", column_namepart
, "title", 0 },
128 { "Length", column_length
, 0, 1 }
131 /** @brief Number of columns in recently added list */
132 #define NADDEDCOLUMNS (int)(sizeof addedcolumns / sizeof *addedcolumns)
134 /** @brief Maximum number of column in any @ref queuelike */
135 #define MAXCOLUMNS (NMAINCOLUMNS > NADDEDCOLUMNS ? NMAINCOLUMNS : NADDEDCOLUMNS)
137 /** @brief Data passed to menu item activation handlers */
138 struct menuiteminfo
{
139 struct queuelike
*ql
; /**< @brief which queue we're dealing with */
140 struct queue_entry
*q
; /**< @brief hovered entry or 0 */
143 /** @brief An item in the queue's popup menu */
144 struct queue_menuitem
{
145 /** @brief Menu item name */
148 /** @brief Called to activate the menu item
150 * The user data is the queue entry that the pointer was over when the menu
152 void (*activate
)(GtkMenuItem
*menuitem
,
155 /** @brief Called to determine whether the menu item is usable.
157 * Returns @c TRUE if it should be sensitive and @c FALSE otherwise. @p q
158 * points to the queue entry the pointer is over.
160 int (*sensitive
)(struct queuelike
*ql
,
161 struct queue_menuitem
*m
,
162 struct queue_entry
*q
);
164 /** @brief Signal handler ID */
167 /** @brief Widget for menu item */
171 /** @brief A queue-like object
173 * There are (currently) three of these: @ref ql_queue, @ref ql_recent and @ref
177 /** @brief Called when an update completes */
178 void (*notify
)(void);
180 /** @brief Called to fix up the queue after update
181 * @param q The list passed back from the server
182 * @return Assigned to @c ql->q
184 struct queue_entry
*(*fixup
)(struct queue_entry
*q
);
187 GtkWidget
*mainlayout
; /**< @brief main layout */
188 GtkWidget
*mainscroll
; /**< @brief scroller for main layout */
189 GtkWidget
*titlelayout
; /**< @brief title layout */
190 GtkWidget
*titlecells
[MAXCOLUMNS
+ 1]; /**< @brief title cells */
191 GtkWidget
**cells
; /**< @brief all the cells */
192 GtkWidget
*menu
; /**< @brief popup menu */
193 struct queue_menuitem
*menuitems
; /**< @brief menu items */
194 GtkWidget
*dragmark
; /**< @brief drag destination marker */
195 GtkWidget
**dropzones
; /**< @brief drag targets */
198 struct queue_entry
*q
; /**< @brief head of queue */
199 struct queue_entry
*last_click
; /**< @brief last click */
200 int nrows
; /**< @brief number of rows */
201 int mainrowheight
; /**< @brief height of one row */
202 hash
*selection
; /**< @brief currently selected items */
203 int swallow_release
; /**< @brief swallow button release from drag */
205 const struct column
*columns
; /**< @brief Table of columns */
206 int ncolumns
; /**< @brief Number of columns */
209 static struct queuelike ql_queue
; /**< @brief The main queue */
210 static struct queuelike ql_recent
; /*< @brief Recently-played tracks */
211 static struct queuelike ql_added
; /*< @brief Newly added tracks */
212 static struct queue_entry
*actual_queue
; /**< @brief actual queue */
213 static struct queue_entry
*playing_track
; /**< @brief currenty playing */
214 static time_t last_playing
= (time_t)-1; /**< @brief when last got playing */
215 static int namepart_lookups_outstanding
;
216 static int namepart_completions_deferred
; /* # of completions not processed */
217 static const struct cache_type cachetype_string
= { 3600 };
218 static const struct cache_type cachetype_integer
= { 3600 };
219 static GtkWidget
*playing_length_label
;
221 /* Debugging --------------------------------------------------------------- */
224 static void describe_widget(const char *name
, GtkWidget
*w
, int indent
) {
228 fprintf(stderr
, "%*s[%s]: '%s'\n", indent
, "",
229 name
, gtk_widget_get_name(w
));
230 gdk_window_get_position(w
->window
, &wx
, &wy
);
231 gdk_drawable_get_size(GDK_DRAWABLE(w
->window
), &ww
, &wh
);
232 fprintf(stderr
, "%*s window %p: %dx%d at %dx%d\n",
233 indent
, "", w
->window
, ww
, wh
, wx
, wy
);
236 static void dump_layout(const struct queuelike
*ql
) {
240 const struct queue_entry
*q
;
242 describe_widget("mainscroll", ql
->mainscroll
, 0);
243 describe_widget("mainlayout", ql
->mainlayout
, 1);
244 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
)
245 for(col
= 0; col
< ql
->ncolumns
+ 1; ++col
)
246 if((w
= ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
])) {
247 sprintf(s
, "%dx%d", row
, col
);
248 describe_widget(s
, w
, 2);
249 if(GTK_BIN(w
)->child
)
250 describe_widget(0, w
, 3);
255 /* Track detail lookup ----------------------------------------------------- */
257 /** @brief Called when a namepart lookup has completed or failed */
258 static void namepart_completed_or_failed(void) {
259 D(("namepart_completed_or_failed"));
260 --namepart_lookups_outstanding
;
261 if(!namepart_lookups_outstanding
) {
262 redisplay_queue(&ql_queue
);
263 redisplay_queue(&ql_recent
);
264 redisplay_queue(&ql_added
);
265 namepart_completions_deferred
= 0;
269 /** @brief Called when A namepart lookup has completed */
270 static void namepart_completed(void *v
, const char *value
) {
271 struct callbackdata
*cbd
= v
;
273 D(("namepart_completed"));
274 cache_put(&cachetype_string
, cbd
->u
.key
, value
);
275 ++namepart_completions_deferred
;
276 namepart_completed_or_failed();
279 /** @brief Called when a length lookup has completed */
280 static void length_completed(void *v
, long l
) {
281 struct callbackdata
*cbd
= v
;
284 D(("namepart_completed"));
285 value
= xmalloc(sizeof *value
);
287 cache_put(&cachetype_integer
, cbd
->u
.key
, value
);
288 ++namepart_completions_deferred
;
289 namepart_completed_or_failed();
292 /** @brief Called when a length or namepart lookup has failed */
293 static void namepart_protocol_error(
294 struct callbackdata
attribute((unused
)) *cbd
,
295 int attribute((unused
)) code
,
297 D(("namepart_protocol_error"));
298 gtk_label_set_text(GTK_LABEL(report_label
), msg
);
299 namepart_completed_or_failed();
302 /** @brief Arrange to fill in a namepart cache entry */
303 static void namepart_fill(const char *track
,
307 struct callbackdata
*cbd
;
309 ++namepart_lookups_outstanding
;
310 cbd
= xmalloc(sizeof *cbd
);
311 cbd
->onerror
= namepart_protocol_error
;
313 disorder_eclient_namepart(client
, namepart_completed
,
314 track
, context
, part
, cbd
);
317 /** @brief Look up a namepart
319 * If it is in the cache then just return its value. If not then look it up
320 * and arrange for the queues to be updated when its value is available. */
321 static const char *namepart(const char *track
,
327 D(("namepart %s %s %s", track
, context
, part
));
328 byte_xasprintf(&key
, "namepart context=%s part=%s track=%s",
329 context
, part
, track
);
330 value
= cache_get(&cachetype_string
, key
);
333 /* stick a value in the cache so we don't issue another lookup if we
335 cache_put(&cachetype_string
, key
, value
= "?");
336 namepart_fill(track
, context
, part
, key
);
341 /** @brief Called from @ref disobedience/properties.c when we know a name part has changed */
342 void namepart_update(const char *track
,
347 byte_xasprintf(&key
, "namepart context=%s part=%s track=%s",
348 context
, part
, track
);
349 /* Only refetch if it's actually in the cache */
350 if(cache_get(&cachetype_string
, key
))
351 namepart_fill(track
, context
, part
, key
);
354 /** @brief Look up a track length
356 * If it is in the cache then just return its value. If not then look it up
357 * and arrange for the queues to be updated when its value is available. */
358 static long getlength(const char *track
) {
361 struct callbackdata
*cbd
;
362 static const long bogus
= -1;
364 D(("getlength %s", track
));
365 byte_xasprintf(&key
, "length track=%s", track
);
366 value
= cache_get(&cachetype_integer
, key
);
368 D(("deferring..."));;
369 cache_put(&cachetype_integer
, key
, value
= &bogus
);
370 ++namepart_lookups_outstanding
;
371 cbd
= xmalloc(sizeof *cbd
);
372 cbd
->onerror
= namepart_protocol_error
;
374 disorder_eclient_length(client
, length_completed
, track
, cbd
);
379 /* Column constructors ----------------------------------------------------- */
381 /** @brief Format the 'when' column */
382 static GtkWidget
*column_when(const struct queuelike
attribute((unused
)) *ql
,
383 const struct queue_entry
*q
,
384 const char attribute((unused
)) *data
) {
391 case playing_isscratch
:
392 case playing_unplayed
:
397 case playing_no_player
:
399 case playing_scratched
:
400 case playing_started
:
402 case playing_quitting
:
410 strftime(when
, sizeof when
, "%H:%M", localtime_r(&t
, &tm
));
414 return gtk_label_new(when
);
417 /** @brief Format the 'who' column */
418 static GtkWidget
*column_who(const struct queuelike
attribute((unused
)) *ql
,
419 const struct queue_entry
*q
,
420 const char attribute((unused
)) *data
) {
423 return gtk_label_new(q
->submitter ? q
->submitter
: "");
426 /** @brief Format one of the track name columns */
427 static GtkWidget
*column_namepart(const struct queuelike
428 attribute((unused
)) *ql
,
429 const struct queue_entry
*q
,
431 D(("column_namepart"));
433 return gtk_label_new(namepart(q
->track
, "display", data
));
436 /** @brief Compute the length field */
437 static const char *text_length(const struct queue_entry
*q
) {
440 char *played
= 0, *length
= 0;
442 /* Work out what to say for the length */
443 l
= getlength(q
->track
);
445 byte_xasprintf(&length
, "%ld:%02ld", l
/ 60, l
% 60);
447 byte_xasprintf(&length
, "?:??");
448 /* For the currently playing track we want to report how much of the track
450 if(q
== playing_track
) {
451 /* log_state() arranges that we re-get the playing data whenever the
452 * pause/resume state changes */
453 if(last_state
& DISORDER_TRACK_PAUSED
)
454 l
= playing_track
->sofar
;
457 l
= playing_track
->sofar
+ (now
- last_playing
);
459 byte_xasprintf(&played
, "%ld:%02ld/%s", l
/ 60, l
% 60, length
);
465 /** @brief Format the length column */
466 static GtkWidget
*column_length(const struct queuelike
attribute((unused
)) *ql
,
467 const struct queue_entry
*q
,
468 const char attribute((unused
)) *data
) {
469 D(("column_length"));
470 if(q
== playing_track
) {
471 assert(!playing_length_label
);
473 playing_length_label
= gtk_label_new(text_length(q
));
474 /* Zot playing_length_label when it is destroyed */
475 g_signal_connect(playing_length_label
, "destroy",
476 G_CALLBACK(gtk_widget_destroyed
), &playing_length_label
);
477 return playing_length_label
;
480 return gtk_label_new(text_length(q
));
485 /** @brief Apply a new queue contents, transferring the selection from the old value */
486 static void update_queue(struct queuelike
*ql
, struct queue_entry
*newq
) {
487 struct queue_entry
*q
;
490 /* Propagate last_click across the change */
492 for(q
= newq
; q
; q
= q
->next
) {
493 if(!strcmp(q
->id
, ql
->last_click
->id
))
498 /* Tell every queue entry which queue owns it */
499 for(q
= newq
; q
; q
= q
->next
)
501 /* Switch to the new queue */
503 /* Clean up any selected items that have fallen off */
504 for(q
= ql
->q
; q
; q
= q
->next
)
505 selection_live(ql
->selection
, q
->id
);
506 selection_cleanup(ql
->selection
);
509 /** @brief Wrap up a widget for putting into the queue or title
510 * @param label Label to contain
511 * @param style Pointer to style to use
512 * @param wp Updated with maximum width (or NULL)
515 static GtkWidget
*wrap_queue_cell(GtkWidget
*label
,
521 D(("wrap_queue_cell"));
522 /* Padding should be in the label so there are no gaps in the
524 gtk_misc_set_padding(GTK_MISC(label
), HCELLPADDING
, VCELLPADDING
);
525 /* Event box is just to hold a background color */
527 bg
= gtk_event_box_new();
528 gtk_container_add(GTK_CONTAINER(bg
), label
);
530 /* Update maximum width */
531 gtk_widget_size_request(label
, &req
);
532 if(req
.width
> *wp
) *wp
= req
.width
;
535 gtk_widget_set_style(bg
, style
);
536 gtk_widget_set_style(label
, style
);
540 /** @brief Create the wrapped widget for a cell in the queue display */
541 static GtkWidget
*get_queue_cell(struct queuelike
*ql
,
542 const struct queue_entry
*q
,
548 D(("get_queue_cell %d %d", row
, col
));
549 label
= ql
->columns
[col
].widget(ql
, q
, ql
->columns
[col
].data
);
550 gtk_misc_set_alignment(GTK_MISC(label
), ql
->columns
[col
].xalign
, 0);
551 return wrap_queue_cell(label
, style
, wp
);
554 /** @brief Add a padding cell to the end of a row */
555 static GtkWidget
*get_padding_cell(GtkStyle
*style
) {
556 D(("get_padding_cell"));
558 return wrap_queue_cell(gtk_label_new(""), style
, 0);
561 /* User button press and menu ---------------------------------------------- */
563 /** @brief Update widget states in order to reflect the selection status */
564 static void set_widget_states(struct queuelike
*ql
) {
565 struct queue_entry
*q
;
568 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
) {
569 for(col
= 0; col
< ql
->ncolumns
+ 1; ++col
)
570 gtk_widget_set_state(ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
],
571 selection_selected(ql
->selection
, q
->id
) ?
572 GTK_STATE_SELECTED
: GTK_STATE_NORMAL
);
574 /* Might need to change sensitivity of 'Properties' in main menu */
578 /** @brief Ordering function for queue entries */
579 static int queue_before(const struct queue_entry
*a
,
580 const struct queue_entry
*b
) {
586 /** @brief A button was pressed and released */
587 static gboolean
queuelike_button_released(GtkWidget
attribute((unused
)) *widget
,
588 GdkEventButton
*event
,
589 gpointer user_data
) {
590 struct queue_entry
*q
= user_data
, *qq
;
591 struct queuelike
*ql
= q
->ql
;
592 struct menuiteminfo
*mii
;
595 /* Might be a release left over from a drag */
596 if(ql
->swallow_release
) {
597 ql
->swallow_release
= 0;
598 return FALSE
; /* propagate */
601 if(event
->type
== GDK_BUTTON_PRESS
602 && event
->button
== 3) {
603 /* Right button click.
604 * If the current item is not selected then switch the selection to just
606 if(q
&& !selection_selected(ql
->selection
, q
->id
)) {
607 selection_empty(ql
->selection
);
608 selection_set(ql
->selection
, q
->id
, 1);
610 set_widget_states(ql
);
612 /* Set the sensitivity of each menu item and (re-)establish the signal
614 for(n
= 0; ql
->menuitems
[n
].name
; ++n
) {
615 if(ql
->menuitems
[n
].handlerid
)
616 g_signal_handler_disconnect(ql
->menuitems
[n
].w
,
617 ql
->menuitems
[n
].handlerid
);
618 gtk_widget_set_sensitive(ql
->menuitems
[n
].w
,
619 ql
->menuitems
[n
].sensitive(ql
,
622 mii
= xmalloc(sizeof *mii
);
625 ql
->menuitems
[n
].handlerid
= g_signal_connect
626 (ql
->menuitems
[n
].w
, "activate",
627 G_CALLBACK(ql
->menuitems
[n
].activate
), mii
);
629 /* Update the menu according to context */
630 gtk_widget_show_all(ql
->menu
);
631 gtk_menu_popup(GTK_MENU(ql
->menu
), 0, 0, 0, 0,
632 event
->button
, event
->time
);
633 return TRUE
; /* hide the click from other widgets */
635 if(event
->type
== GDK_BUTTON_RELEASE
636 && event
->button
== 1) {
637 /* no modifiers: select this, unselect everything else, set last click
638 * +ctrl: flip selection of this, set last click
639 * +shift: select from last click to here, don't set last click
640 * +ctrl+shift: select from last click to here, set last click
642 switch(event
->state
& (GDK_SHIFT_MASK
|GDK_CONTROL_MASK
)) {
644 selection_empty(ql
->selection
);
645 selection_set(ql
->selection
, q
->id
, 1);
648 case GDK_CONTROL_MASK
:
649 selection_flip(ql
->selection
, q
->id
);
653 case GDK_SHIFT_MASK
|GDK_CONTROL_MASK
:
655 if(!(event
->state
& GDK_CONTROL_MASK
))
656 selection_empty(ql
->selection
);
657 selection_set(ql
->selection
, q
->id
, 1);
659 if(queue_before(ql
->last_click
, q
))
660 while(qq
!= ql
->last_click
) {
662 selection_set(ql
->selection
, qq
->id
, 1);
665 while(qq
!= ql
->last_click
) {
667 selection_set(ql
->selection
, qq
->id
, 1);
669 if(event
->state
& GDK_CONTROL_MASK
)
674 set_widget_states(ql
);
675 gtk_widget_queue_draw(ql
->mainlayout
);
677 return FALSE
; /* propagate */
680 /** @brief A button was pressed or released on the mainlayout
682 * For debugging only at the moment. */
683 static gboolean
mainlayout_button(GtkWidget
attribute((unused
)) *widget
,
684 GdkEventButton
attribute((unused
)) *event
,
685 gpointer
attribute((unused
)) user_data
) {
686 return FALSE
; /* propagate */
689 /** @brief Select all entries in a queue */
690 void queue_select_all(struct queuelike
*ql
) {
691 struct queue_entry
*qq
;
693 for(qq
= ql
->q
; qq
; qq
= qq
->next
)
694 selection_set(ql
->selection
, qq
->id
, 1);
696 set_widget_states(ql
);
699 /** @brief Pop up properties for selected tracks */
700 void queue_properties(struct queuelike
*ql
) {
702 const struct queue_entry
*qq
;
705 for(qq
= ql
->q
; qq
; qq
= qq
->next
)
706 if(selection_selected(ql
->selection
, qq
->id
))
707 vector_append(&v
, (char *)qq
->track
);
709 properties(v
.nvec
, (const char **)v
.vec
);
712 /* Drag and drop rearrangement --------------------------------------------- */
714 /** @brief Return nonzero if @p is a draggable row
716 * Only tracks in the main queue are draggable (and the currently playing track
719 static int draggable_row(const struct queue_entry
*q
) {
720 return q
->ql
== &ql_queue
&& q
!= playing_track
;
723 /** @brief Called when a drag begings */
724 static void queue_drag_begin(GtkWidget
attribute((unused
)) *widget
,
725 GdkDragContext
attribute((unused
)) *dc
,
727 struct queue_entry
*q
= data
;
728 struct queuelike
*ql
= q
->ql
;
730 /* Make sure the playing track is not selected, since it cannot be dragged */
732 selection_set(ql
->selection
, playing_track
->id
, 0);
733 /* If the dragged item is not in the selection then change the selection to
735 if(!selection_selected(ql
->selection
, q
->id
)) {
736 selection_empty(ql
->selection
);
737 selection_set(ql
->selection
, q
->id
, 1);
738 set_widget_states(ql
);
740 /* Ignore the eventual button release */
741 ql
->swallow_release
= 1;
742 /* Create dropzones */
743 add_drag_targets(ql
);
746 /** @brief Convert @p id back into a queue entry and a screen row number */
747 static struct queue_entry
*findentry(struct queuelike
*ql
,
751 struct queue_entry
*q
;
754 for(q
= ql
->q
, row
= 0; q
&& strcmp(q
->id
, id
); q
= q
->next
, ++row
)
758 row
= playing_track ?
0 : -1;
760 if(rowp
) *rowp
= row
;
764 /** @brief Called when data is dropped */
765 static gboolean
queue_drag_drop(GtkWidget
attribute((unused
)) *widget
,
766 GdkDragContext
*drag_context
,
767 gint
attribute((unused
)) x
,
768 gint
attribute((unused
)) y
,
770 gpointer user_data
) {
771 struct queuelike
*ql
= &ql_queue
;
772 const char *id
= user_data
;
774 struct queue_entry
*q
;
776 if(!id
|| (playing_track
&& !strcmp(id
, playing_track
->id
)))
779 for(q
= ql
->q
; q
; q
= q
->next
)
780 if(q
!= playing_track
&& selection_selected(ql
->selection
, q
->id
))
781 vector_append(&vec
, (char *)q
->id
);
782 disorder_eclient_moveafter(client
, id
, vec
.nvec
, (const char **)vec
.vec
,
783 0/*completed*/, 0/*v*/);
784 gtk_drag_finish(drag_context
, TRUE
, TRUE
, when
);
785 /* Destroy dropzones */
786 remove_drag_targets(ql
);
790 /** @brief Called when we enter, or move within, a drop zone */
791 static gboolean
queue_drag_motion(GtkWidget
attribute((unused
)) *widget
,
792 GdkDragContext
*drag_context
,
793 gint
attribute((unused
)) x
,
794 gint
attribute((unused
)) y
,
796 gpointer user_data
) {
797 struct queuelike
*ql
= &ql_queue
;
798 const char *id
= user_data
;
800 struct queue_entry
*q
= findentry(ql
, id
, &row
);
805 ql
->dragmark
= gtk_event_box_new();
806 g_signal_connect(ql
->dragmark
, "destroy",
807 G_CALLBACK(gtk_widget_destroyed
), &ql
->dragmark
);
808 gtk_widget_set_size_request(ql
->dragmark
, 10240, row ?
4 : 2);
809 gtk_widget_set_style(ql
->dragmark
, drag_style
);
810 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), ql
->dragmark
, 0,
811 (row
+ 1) * ql
->mainrowheight
- !!row
);
813 gtk_layout_move(GTK_LAYOUT(ql
->mainlayout
), ql
->dragmark
, 0,
814 (row
+ 1) * ql
->mainrowheight
- !!row
);
815 gtk_widget_show(ql
->dragmark
);
816 gdk_drag_status(drag_context
, GDK_ACTION_MOVE
, when
);
819 /* ID has gone AWOL */
823 /** @brief Called when we leave a drop zone */
824 static void queue_drag_leave(GtkWidget
attribute((unused
)) *widget
,
825 GdkDragContext
attribute((unused
)) *drag_context
,
826 guint
attribute((unused
)) when
,
827 gpointer
attribute((unused
)) user_data
) {
828 struct queuelike
*ql
= &ql_queue
;
831 gtk_widget_hide(ql
->dragmark
);
834 /** @brief Add a drag target at position @p y
836 * @p id is the track to insert the moved tracks after, and might be 0 to
837 * insert before the start. */
838 static void add_drag_target(struct queuelike
*ql
, int y
, int row
,
842 assert(ql
->dropzones
[row
] == 0);
844 eventbox
= gtk_event_box_new();
845 /* Make the target zone invisible */
846 gtk_event_box_set_visible_window(GTK_EVENT_BOX(eventbox
), FALSE
);
847 /* Make it large enough */
848 gtk_widget_set_size_request(eventbox
, 10240,
849 y ? ql
->mainrowheight
: ql
->mainrowheight
/ 2);
851 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), eventbox
, 0,
852 y ? y
- ql
->mainrowheight
/ 2 : 0);
853 /* Mark it as capable of receiving drops */
854 gtk_drag_dest_set(eventbox
,
856 dragtargets
, NDRAGTARGETS
, GDK_ACTION_MOVE
);
857 g_signal_connect(eventbox
, "drag-drop",
858 G_CALLBACK(queue_drag_drop
), (char *)id
);
859 /* Monitor drag motion */
860 g_signal_connect(eventbox
, "drag-motion",
861 G_CALLBACK(queue_drag_motion
), (char *)id
);
862 g_signal_connect(eventbox
, "drag-leave",
863 G_CALLBACK(queue_drag_leave
), (char *)id
);
864 /* The widget needs to be shown to receive drags */
865 gtk_widget_show(eventbox
);
866 /* Remember the drag targets */
867 ql
->dropzones
[row
] = eventbox
;
868 g_signal_connect(eventbox
, "destroy",
869 G_CALLBACK(gtk_widget_destroyed
), &ql
->dropzones
[row
]);
872 /** @brief Create dropzones for dragging into */
873 static void add_drag_targets(struct queuelike
*ql
) {
875 struct queue_entry
*q
;
877 /* Create an array to store the widgets */
878 ql
->dropzones
= xcalloc(ql
->nrows
, sizeof (GtkWidget
*));
880 /* Add a drag target before the first row provided it's not the playing
882 if(!playing_track
|| ql
->q
!= playing_track
)
883 add_drag_target(ql
, 0, 0, 0);
884 /* Put a drag target at the bottom of every row */
885 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
) {
886 y
+= ql
->mainrowheight
;
887 add_drag_target(ql
, y
, row
, q
->id
);
891 /** @brief Remove the dropzones */
892 static void remove_drag_targets(struct queuelike
*ql
) {
895 for(row
= 0; row
< ql
->nrows
; ++row
) {
896 if(ql
->dropzones
[row
]) {
898 gtk_widget_destroy(ql
->dropzones
[row
]);
900 assert(ql
->dropzones
[row
] == 0);
904 /* Layout ------------------------------------------------------------------ */
906 /** @brief Redisplay a queue */
907 static void redisplay_queue(struct queuelike
*ql
) {
908 struct queue_entry
*q
;
914 int maxwidths
[MAXCOLUMNS
], x
, y
, titlerowheight
;
915 int totalwidth
= 10240; /* TODO: can we be less blunt */
917 D(("redisplay_queue"));
918 /* Eliminate all the existing widgets and start from scratch */
919 for(c
= children
= gtk_container_get_children(GTK_CONTAINER(ql
->mainlayout
));
922 /* Destroy both the label and the eventbox */
923 if(GTK_BIN(c
->data
)->child
) {
925 gtk_widget_destroy(GTK_BIN(c
->data
)->child
);
928 gtk_widget_destroy(GTK_WIDGET(c
->data
));
930 g_list_free(children
);
931 /* Adjust the row count */
932 for(q
= ql
->q
, ql
->nrows
= 0; q
; q
= q
->next
)
934 /* We need to create all the widgets before we can position them */
935 ql
->cells
= xcalloc(ql
->nrows
* (ql
->ncolumns
+ 1), sizeof *ql
->cells
);
936 /* Minimum width is given by the column headings */
937 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
938 /* Reset size so we don't inherit last iteration's maximum size */
939 gtk_widget_set_size_request(GTK_BIN(ql
->titlecells
[col
])->child
, -1, -1);
940 gtk_widget_size_request(GTK_BIN(ql
->titlecells
[col
])->child
, &req
);
941 maxwidths
[col
] = req
.width
;
943 /* Find the vertical size of the title bar */
944 gtk_widget_size_request(GTK_BIN(ql
->titlecells
[0])->child
, &req
);
945 titlerowheight
= req
.height
;
948 /* Construct the widgets */
949 for(q
= ql
->q
, row
= 0; q
; q
= q
->next
, ++row
) {
950 /* Figure out the widget name for this row */
951 if(q
== playing_track
) style
= active_style
;
952 else style
= row
% 2 ? even_style
: odd_style
;
953 /* Make the widget for each column */
954 for(col
= 0; col
<= ql
->ncolumns
; ++col
) {
955 /* Create and store the widget */
956 if(col
< ql
->ncolumns
)
957 w
= get_queue_cell(ql
, q
, row
, col
, style
, &maxwidths
[col
]);
959 w
= get_padding_cell(style
);
960 ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
] = w
;
961 /* Maybe mark it draggable */
962 if(draggable_row(q
)) {
963 gtk_drag_source_set(w
, GDK_BUTTON1_MASK
,
964 dragtargets
, NDRAGTARGETS
, GDK_ACTION_MOVE
);
965 g_signal_connect(w
, "drag-begin", G_CALLBACK(queue_drag_begin
), q
);
967 /* Catch button presses */
968 g_signal_connect(w
, "button-release-event",
969 G_CALLBACK(queuelike_button_released
), q
);
970 g_signal_connect(w
, "button-press-event",
971 G_CALLBACK(queuelike_button_released
), q
);
974 /* ...and of each row in the main layout */
975 gtk_widget_size_request(GTK_BIN(ql
->cells
[0])->child
, &req
);
976 ql
->mainrowheight
= req
.height
;
977 /* Now we know the maximum width of each column we can set the size of
978 * everything and position it */
979 for(row
= 0, q
= ql
->q
; row
< ql
->nrows
; ++row
, q
= q
->next
) {
981 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
982 w
= ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
];
983 gtk_widget_set_size_request(GTK_BIN(w
)->child
,
985 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), w
, x
, y
);
988 w
= ql
->cells
[row
* (ql
->ncolumns
+ 1) + col
];
989 gtk_widget_set_size_request(GTK_BIN(w
)->child
,
991 gtk_layout_put(GTK_LAYOUT(ql
->mainlayout
), w
, x
, y
);
992 y
+= ql
->mainrowheight
;
997 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
998 gtk_widget_set_size_request(GTK_BIN(ql
->titlecells
[col
])->child
,
1000 gtk_layout_move(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], x
, 0);
1001 x
+= maxwidths
[col
];
1003 gtk_widget_set_size_request(GTK_BIN(ql
->titlecells
[col
])->child
,
1004 totalwidth
- x
, -1);
1005 gtk_layout_move(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], x
, 0);
1006 /* Set the states */
1007 set_widget_states(ql
);
1008 /* Make sure it's all visible */
1009 gtk_widget_show_all(ql
->mainlayout
);
1010 gtk_widget_show_all(ql
->titlelayout
);
1011 /* Layouts might shrink to arrange for the area they shrink out of to be
1013 gtk_widget_queue_draw(ql
->mainlayout
);
1014 gtk_widget_queue_draw(ql
->titlelayout
);
1015 /* Adjust the size of the layout */
1016 gtk_layout_set_size(GTK_LAYOUT(ql
->mainlayout
), x
, y
);
1017 gtk_layout_set_size(GTK_LAYOUT(ql
->titlelayout
), x
, titlerowheight
);
1018 gtk_widget_set_size_request(ql
->titlelayout
, -1, titlerowheight
);
1021 /** @brief Called with new queue/recent contents */
1022 static void queuelike_completed(void *v
, struct queue_entry
*q
) {
1023 struct callbackdata
*cbd
= v
;
1024 struct queuelike
*ql
= cbd
->u
.ql
;
1026 D(("queuelike_complete"));
1027 /* Install the new queue */
1028 update_queue(ql
, ql
->fixup ? ql
->fixup(q
) : q
);
1029 /* Update the display */
1030 redisplay_queue(ql
);
1033 /* Update sensitivity of main menu items */
1037 /** @brief Called with a new currently playing track */
1038 static void playing_completed(void attribute((unused
)) *v
,
1039 struct queue_entry
*q
) {
1040 struct callbackdata cbd
;
1041 D(("playing_completed"));
1043 /* Record when we got the playing track data so we know how old the 'sofar'
1045 time(&last_playing
);
1046 cbd
.u
.ql
= &ql_queue
;
1047 queuelike_completed(&cbd
, actual_queue
);
1050 /** @brief Called when the queue is scrolled */
1051 static void queue_scrolled(GtkAdjustment
*adjustment
,
1052 gpointer user_data
) {
1053 GtkAdjustment
*titleadj
= user_data
;
1055 D(("queue_scrolled"));
1056 gtk_adjustment_set_value(titleadj
, adjustment
->value
);
1059 /** @brief Create a queuelike thing (queue/recent) */
1060 static GtkWidget
*queuelike(struct queuelike
*ql
,
1061 struct queue_entry
*(*fixup
)(struct queue_entry
*),
1062 void (*notify
)(void),
1063 struct queue_menuitem
*menuitems
,
1064 const struct column
*columns
,
1066 GtkWidget
*vbox
, *mainscroll
, *titlescroll
, *label
;
1067 GtkAdjustment
*mainadj
, *titleadj
;
1072 ql
->notify
= notify
;
1073 ql
->menuitems
= menuitems
;
1074 ql
->mainrowheight
= !0; /* else division by 0 */
1075 ql
->selection
= selection_new();
1076 ql
->columns
= columns
;
1077 ql
->ncolumns
= ncolumns
;
1078 /* Create the layouts */
1080 ql
->mainlayout
= gtk_layout_new(0, 0);
1081 gtk_widget_set_style(ql
->mainlayout
, layout_style
);
1083 ql
->titlelayout
= gtk_layout_new(0, 0);
1084 gtk_widget_set_style(ql
->titlelayout
, title_style
);
1085 /* Scroll the layouts */
1086 ql
->mainscroll
= mainscroll
= scroll_widget(ql
->mainlayout
);
1087 titlescroll
= scroll_widget(ql
->titlelayout
);
1088 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(titlescroll
),
1089 GTK_POLICY_NEVER
, GTK_POLICY_NEVER
);
1090 mainadj
= gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(mainscroll
));
1091 titleadj
= gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(titlescroll
));
1092 g_signal_connect(mainadj
, "changed", G_CALLBACK(queue_scrolled
), titleadj
);
1093 g_signal_connect(mainadj
, "value-changed", G_CALLBACK(queue_scrolled
), titleadj
);
1094 /* Fill the titles and put them anywhere */
1095 for(col
= 0; col
< ql
->ncolumns
; ++col
) {
1097 label
= gtk_label_new(ql
->columns
[col
].name
);
1098 gtk_misc_set_alignment(GTK_MISC(label
), ql
->columns
[col
].xalign
, 0);
1099 ql
->titlecells
[col
] = wrap_queue_cell(label
, title_style
, 0);
1100 gtk_layout_put(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], 0, 0);
1102 ql
->titlecells
[col
] = get_padding_cell(title_style
);
1103 gtk_layout_put(GTK_LAYOUT(ql
->titlelayout
), ql
->titlecells
[col
], 0, 0);
1104 /* Pack the lot together in a vbox */
1106 vbox
= gtk_vbox_new(0, 0);
1107 gtk_box_pack_start(GTK_BOX(vbox
), titlescroll
, 0, 0, 0);
1108 gtk_box_pack_start(GTK_BOX(vbox
), mainscroll
, 1, 1, 0);
1109 /* Create the popup menu */
1111 ql
->menu
= gtk_menu_new();
1112 g_signal_connect(ql
->menu
, "destroy",
1113 G_CALLBACK(gtk_widget_destroyed
), &ql
->menu
);
1114 for(n
= 0; menuitems
[n
].name
; ++n
) {
1116 menuitems
[n
].w
= gtk_menu_item_new_with_label(menuitems
[n
].name
);
1117 gtk_menu_attach(GTK_MENU(ql
->menu
), menuitems
[n
].w
, 0, 1, n
, n
+ 1);
1119 g_object_set_data(G_OBJECT(vbox
), "type", (void *)&tabtype_queue
);
1120 g_object_set_data(G_OBJECT(vbox
), "queue", ql
);
1121 /* Catch button presses */
1122 g_signal_connect(ql
->mainlayout
, "button-release-event",
1123 G_CALLBACK(mainlayout_button
), ql
);
1125 g_signal_connect(ql
->mainlayout
, "button-press-event",
1126 G_CALLBACK(mainlayout_button
), ql
);
1128 set_tool_colors(ql
->menu
);
1132 /* Popup menu items -------------------------------------------------------- */
1134 /** @brief Count the number of items selected */
1135 static int queue_count_selected(const struct queuelike
*ql
) {
1136 return hash_count(ql
->selection
);
1139 /** @brief Count the number of items selected */
1140 static int queue_count_entries(const struct queuelike
*ql
) {
1142 const struct queue_entry
*q
;
1144 for(q
= ql
->q
; q
; q
= q
->next
)
1149 /** @brief Count the number of items selected, excluding the playing track if
1151 static int count_selected_nonplaying(const struct queuelike
*ql
) {
1152 int nselected
= queue_count_selected(ql
);
1154 if(ql
->q
== playing_track
&& selection_selected(ql
->selection
, ql
->q
->id
))
1159 /** @brief Determine whether the scratch option should be sensitive */
1160 static int scratch_sensitive(struct queuelike
attribute((unused
)) *ql
,
1161 struct queue_menuitem
attribute((unused
)) *m
,
1162 struct queue_entry
attribute((unused
)) *q
) {
1163 /* We can scratch if the playing track is selected */
1164 return (playing_track
1165 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)
1166 && selection_selected(ql
->selection
, playing_track
->id
));
1169 /** @brief Scratch the playing track */
1170 static void scratch_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1171 gpointer
attribute((unused
)) user_data
) {
1173 disorder_eclient_scratch(client
, playing_track
->id
, 0, 0);
1176 /** @brief Determine whether the remove option should be sensitive */
1177 static int remove_sensitive(struct queuelike
*ql
,
1178 struct queue_menuitem
attribute((unused
)) *m
,
1179 struct queue_entry
*q
) {
1180 /* We can remove if we're hovering over a particular track or any non-playing
1181 * tracks are selected */
1182 return ((disorder_eclient_state(client
) & DISORDER_CONNECTED
)
1184 && q
!= playing_track
)
1185 || count_selected_nonplaying(ql
)));
1188 /** @brief Remove selected track(s) */
1189 static void remove_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1190 gpointer user_data
) {
1191 const struct menuiteminfo
*mii
= user_data
;
1192 struct queue_entry
*q
= mii
->q
;
1193 struct queuelike
*ql
= mii
->ql
;
1195 if(count_selected_nonplaying(mii
->ql
)) {
1196 /* Remove selected tracks */
1197 for(q
= ql
->q
; q
; q
= q
->next
)
1198 if(selection_selected(ql
->selection
, q
->id
) && q
!= playing_track
)
1199 disorder_eclient_remove(client
, q
->id
, 0, 0);
1201 /* Remove just the hovered track */
1202 disorder_eclient_remove(client
, q
->id
, 0, 0);
1205 /** @brief Determine whether the properties menu option should be sensitive */
1206 static int properties_sensitive(struct queuelike
*ql
,
1207 struct queue_menuitem
attribute((unused
)) *m
,
1208 struct queue_entry
attribute((unused
)) *q
) {
1209 /* "Properties" is sensitive if at least something is selected */
1210 return (hash_count(ql
->selection
) > 0
1211 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
));
1214 /** @brief Pop up properties for the selected tracks */
1215 static void properties_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1216 gpointer user_data
) {
1217 const struct menuiteminfo
*mii
= user_data
;
1219 queue_properties(mii
->ql
);
1222 /** @brief Determine whether the select all menu option should be sensitive */
1223 static int selectall_sensitive(struct queuelike
*ql
,
1224 struct queue_menuitem
attribute((unused
)) *m
,
1225 struct queue_entry
attribute((unused
)) *q
) {
1226 /* Sensitive if there is anything to select */
1230 /** @brief Select all tracks */
1231 static void selectall_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1232 gpointer user_data
) {
1233 const struct menuiteminfo
*mii
= user_data
;
1234 queue_select_all(mii
->ql
);
1237 /** @brief Determine whether the play menu option should be sensitive */
1238 static int play_sensitive(struct queuelike
*ql
,
1239 struct queue_menuitem
attribute((unused
)) *m
,
1240 struct queue_entry
attribute((unused
)) *q
) {
1241 /* "Play" is sensitive if at least something is selected */
1242 return (hash_count(ql
->selection
) > 0
1243 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
));
1246 /** @brief Play the selected tracks */
1247 static void play_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
1248 gpointer user_data
) {
1249 const struct menuiteminfo
*mii
= user_data
;
1250 struct queue_entry
*q
= mii
->q
;
1251 struct queuelike
*ql
= mii
->ql
;
1253 if(queue_count_selected(ql
)) {
1254 /* Play selected tracks */
1255 for(q
= ql
->q
; q
; q
= q
->next
)
1256 if(selection_selected(ql
->selection
, q
->id
))
1257 disorder_eclient_play(client
, q
->track
, 0, 0);
1259 /* Nothing is selected, so play the hovered track */
1260 disorder_eclient_play(client
, q
->track
, 0, 0);
1263 /* The queue --------------------------------------------------------------- */
1265 /** @brief Fix up the queue by sticking the currently playing track on the front */
1266 static struct queue_entry
*fixup_queue(struct queue_entry
*q
) {
1271 actual_queue
->prev
= playing_track
;
1272 playing_track
->next
= actual_queue
;
1273 return playing_track
;
1275 return actual_queue
;
1278 /** @brief Adjust track played label
1280 * Called regularly to adjust the so-far played label (redrawing the whole
1281 * queue once a second makes disobedience occupy >10% of the CPU on my Athlon
1282 * which is ureasonable expensive) */
1283 static gboolean
adjust_sofar(gpointer
attribute((unused
)) data
) {
1284 if(playing_length_label
&& playing_track
)
1285 gtk_label_set_text(GTK_LABEL(playing_length_label
),
1286 text_length(playing_track
));
1290 /** @brief Popup menu for the queue
1292 * Properties first so that finger trouble is less dangerous. */
1293 static struct queue_menuitem queue_menu
[] = {
1294 { "Track properties", properties_activate
, properties_sensitive
, 0, 0 },
1295 { "Select all tracks", selectall_activate
, selectall_sensitive
, 0, 0 },
1296 { "Scratch track", scratch_activate
, scratch_sensitive
, 0, 0 },
1297 { "Remove track from queue", remove_activate
, remove_sensitive
, 0, 0 },
1301 /** @brief Called whenever @ref DISORDER_PLAYING or @ref DISORDER_TRACK_PAUSED changes
1303 * We monitor pause/resume as well as whether the track is playing in order to
1304 * keep the time played so far up to date correctly. See playing_completed().
1306 static void playing_update(void attribute((unused
)) *v
) {
1307 D(("playing_update"));
1308 gtk_label_set_text(GTK_LABEL(report_label
), "updating playing track");
1309 disorder_eclient_playing(client
, playing_completed
, 0);
1312 /** @brief Create the queue widget */
1313 GtkWidget
*queue_widget(void) {
1314 D(("queue_widget"));
1315 /* Arrange periodic update of the so-far played field */
1316 g_timeout_add(1000/*ms*/, adjust_sofar
, 0);
1317 /* Arrange a callback whenever the playing state changes */
1318 register_monitor(playing_update
, 0, DISORDER_PLAYING
|DISORDER_TRACK_PAUSED
);
1319 register_reset(queue_update
);
1320 /* We pass choose_update() as our notify function since the choose screen
1321 * marks tracks that are playing/in the queue. */
1322 return queuelike(&ql_queue
, fixup_queue
, choose_update
, queue_menu
,
1323 maincolumns
, NMAINCOLUMNS
);
1326 /** @brief Arrange an update of the queue widget
1328 * Called when a track is added to the queue, removed from the queue (by user
1329 * cmmand or because it is to be played) or moved within the queue
1331 void queue_update(void) {
1332 struct callbackdata
*cbd
;
1334 D(("queue_update"));
1335 cbd
= xmalloc(sizeof *cbd
);
1337 cbd
->u
.ql
= &ql_queue
;
1338 gtk_label_set_text(GTK_LABEL(report_label
), "updating queue");
1339 disorder_eclient_queue(client
, queuelike_completed
, cbd
);
1342 /* Recently played tracks -------------------------------------------------- */
1344 /** @brief Fix up the recently played list
1346 * It's in the wrong order! TODO fix this globally */
1347 static struct queue_entry
*fixup_recent(struct queue_entry
*q
) {
1348 struct queue_entry
*qr
= 0, *qn
;
1350 D(("fixup_recent"));
1353 /* Swap next/prev pointers */
1356 /* Remember last node for new head */
1364 /** @brief Pop-up menu for recently played list */
1365 static struct queue_menuitem recent_menu
[] = {
1366 { "Track properties", properties_activate
, properties_sensitive
,0, 0 },
1367 { "Select all tracks", selectall_activate
, selectall_sensitive
, 0, 0 },
1371 /** @brief Create the recently-played list */
1372 GtkWidget
*recent_widget(void) {
1373 D(("recent_widget"));
1374 register_reset(recent_update
);
1375 return queuelike(&ql_recent
, fixup_recent
, 0, recent_menu
,
1376 maincolumns
, NMAINCOLUMNS
);
1379 /** @brief Update the recently played list
1381 * Called whenever a track is added to it or removed from it.
1383 void recent_update(void) {
1384 struct callbackdata
*cbd
;
1386 D(("recent_update"));
1387 cbd
= xmalloc(sizeof *cbd
);
1389 cbd
->u
.ql
= &ql_recent
;
1390 gtk_label_set_text(GTK_LABEL(report_label
), "updating recently played list");
1391 disorder_eclient_recent(client
, queuelike_completed
, cbd
);
1394 /* Newly added tracks ------------------------------------------------------ */
1396 /** @brief Pop-up menu for recently played list */
1397 static struct queue_menuitem added_menu
[] = {
1398 { "Track properties", properties_activate
, properties_sensitive
, 0, 0 },
1399 { "Play track", play_activate
, play_sensitive
, 0, 0 },
1400 { "Select all tracks", selectall_activate
, selectall_sensitive
, 0, 0 },
1404 /** @brief Create the newly-added list */
1405 GtkWidget
*added_widget(void) {
1406 D(("added_widget"));
1407 register_reset(added_update
);
1408 return queuelike(&ql_added
, 0/*fixup*/, 0/*notify*/, added_menu
,
1409 addedcolumns
, NADDEDCOLUMNS
);
1412 /** @brief Called with an updated list of newly-added tracks
1414 * This is called with a raw list of track names but the rest of @ref
1415 * disobedience/queue.c requires @ref queue_entry structures with a valid and
1416 * unique @c id field. This function fakes it.
1418 static void new_completed(void *v
, int nvec
, char **vec
) {
1419 struct queue_entry
*q
, *qh
, *qlast
= 0, **qq
= &qh
;
1422 for(n
= 0; n
< nvec
; ++n
) {
1423 q
= xmalloc(sizeof *q
);
1432 queuelike_completed(v
, qh
);
1435 /** @brief Update the newly-added list */
1436 void added_update(void) {
1437 struct callbackdata
*cbd
;
1440 cbd
= xmalloc(sizeof *cbd
);
1442 cbd
->u
.ql
= &ql_added
;
1443 gtk_label_set_text(GTK_LABEL(report_label
),
1444 "updating newly added track list");
1445 disorder_eclient_new_tracks(client
, new_completed
, 0/*all*/, cbd
);
1448 /* Main menu plumbing ------------------------------------------------------ */
1450 static int queue_properties_sensitive(GtkWidget
*w
) {
1451 return (!!queue_count_selected(g_object_get_data(G_OBJECT(w
), "queue"))
1452 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
));
1455 static int queue_selectall_sensitive(GtkWidget
*w
) {
1456 return !!queue_count_entries(g_object_get_data(G_OBJECT(w
), "queue"));
1459 static void queue_properties_activate(GtkWidget
*w
) {
1460 queue_properties(g_object_get_data(G_OBJECT(w
), "queue"));
1463 static void queue_selectall_activate(GtkWidget
*w
) {
1464 queue_select_all(g_object_get_data(G_OBJECT(w
), "queue"));
1467 static const struct tabtype tabtype_queue
= {
1468 queue_properties_sensitive
,
1469 queue_selectall_sensitive
,
1470 queue_properties_activate
,
1471 queue_selectall_activate
,
1474 /* Other entry points ------------------------------------------------------ */
1476 /** @brief Return nonzero if @p track is in the queue */
1477 int queued(const char *track
) {
1478 struct queue_entry
*q
;
1480 D(("queued %s", track
));
1481 for(q
= ql_queue
.q
; q
; q
= q
->next
)
1482 if(!strcmp(q
->track
, track
))
1492 indent-tabs-mode:nil