X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/16e145a5cf55ff3826656faedfba13460e4ab28b..658c8a359409a339d71910f68452bfaa751734c0:/disobedience/queue.c diff --git a/disobedience/queue.c b/disobedience/queue.c index 920d3a8..c3d62b0 100644 --- a/disobedience/queue.c +++ b/disobedience/queue.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder - * Copyright (C) 2006, 2007 Richard Kettlewell + * Copyright (C) 2006-2008 Richard Kettlewell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,9 +52,14 @@ * These only exist while the drag proceeds, as otherwise they steal events * from more deserving widgets. (It might work to hide them when not in use * too but this way around the d+d code is a bit more self-contained.) + * + * NB that while in the server the playing track is not in the queue, in + * Disobedience, the playing does live in @c ql_queue.q, despite its different + * status to everything else found in that list. */ #include "disobedience.h" +#include "charset.h" /** @brief Horizontal padding for queue cells */ #define HCELLPADDING 4 @@ -107,11 +112,8 @@ struct column { gfloat xalign; /* Alignment of the label */ }; -/** @brief Table of columns - * - * Need this in the middle of the types for NCOLUMNS - */ -static const struct column columns[] = { +/** @brief Table of columns for queue and recently played list */ +static const struct column maincolumns[] = { { "When", column_when, 0, 1 }, { "Who", column_who, 0, 0 }, { "Artist", column_namepart, "artist", 0 }, @@ -120,8 +122,22 @@ static const struct column columns[] = { { "Length", column_length, 0, 1 } }; -/** @brief Number of columns */ -#define NCOLUMNS (int)(sizeof columns / sizeof *columns) +/** @brief Number of columns in queue and recnetly played list */ +#define NMAINCOLUMNS (int)(sizeof maincolumns / sizeof *maincolumns) + +/** @brief Table of columns for recently added tracks */ +static const struct column addedcolumns[] = { + { "Artist", column_namepart, "artist", 0 }, + { "Album", column_namepart, "album", 0 }, + { "Title", column_namepart, "title", 0 }, + { "Length", column_length, 0, 1 } +}; + +/** @brief Number of columns in recently added list */ +#define NADDEDCOLUMNS (int)(sizeof addedcolumns / sizeof *addedcolumns) + +/** @brief Maximum number of column in any @ref queuelike */ +#define MAXCOLUMNS (NMAINCOLUMNS > NADDEDCOLUMNS ? NMAINCOLUMNS : NADDEDCOLUMNS) /** @brief Data passed to menu item activation handlers */ struct menuiteminfo { @@ -159,16 +175,14 @@ struct queue_menuitem { /** @brief A queue-like object * - * There are (currently) two of these: @ref ql_queue and @ref ql_recent. + * There are (currently) three of these: @ref ql_queue, @ref ql_recent and @ref + * ql_added. */ struct queuelike { - /** @brief Name of this queue */ - const char *name; - /** @brief Called when an update completes */ void (*notify)(void); - /** @brief Called to fix up the queue after update + /** @brief Called to fix up the queue after update * @param q The list passed back from the server * @return Assigned to @c ql->q */ @@ -178,12 +192,13 @@ struct queuelike { GtkWidget *mainlayout; /**< @brief main layout */ GtkWidget *mainscroll; /**< @brief scroller for main layout */ GtkWidget *titlelayout; /**< @brief title layout */ - GtkWidget *titlecells[NCOLUMNS + 1]; /**< @brief title cells */ + GtkWidget *titlecells[MAXCOLUMNS + 1]; /**< @brief title cells */ GtkWidget **cells; /**< @brief all the cells */ GtkWidget *menu; /**< @brief popup menu */ struct queue_menuitem *menuitems; /**< @brief menu items */ GtkWidget *dragmark; /**< @brief drag destination marker */ GtkWidget **dropzones; /**< @brief drag targets */ + int ndropzones; /**< @brief number of drag targets */ /* State */ struct queue_entry *q; /**< @brief head of queue */ @@ -192,10 +207,14 @@ struct queuelike { int mainrowheight; /**< @brief height of one row */ hash *selection; /**< @brief currently selected items */ int swallow_release; /**< @brief swallow button release from drag */ + + const struct column *columns; /**< @brief Table of columns */ + int ncolumns; /**< @brief Number of columns */ }; static struct queuelike ql_queue; /**< @brief The main queue */ static struct queuelike ql_recent; /*< @brief Recently-played tracks */ +static struct queuelike ql_added; /*< @brief Newly added tracks */ static struct queue_entry *actual_queue; /**< @brief actual queue */ static struct queue_entry *playing_track; /**< @brief currenty playing */ static time_t last_playing = (time_t)-1; /**< @brief when last got playing */ @@ -229,8 +248,8 @@ static void dump_layout(const struct queuelike *ql) { describe_widget("mainscroll", ql->mainscroll, 0); describe_widget("mainlayout", ql->mainlayout, 1); for(q = ql->q, row = 0; q; q = q->next, ++row) - for(col = 0; col < NCOLUMNS + 1; ++col) - if((w = ql->cells[row * (NCOLUMNS + 1) + col])) { + for(col = 0; col < ql->ncolumns + 1; ++col) + if((w = ql->cells[row * (ql->ncolumns + 1) + col])) { sprintf(s, "%dx%d", row, col); describe_widget(s, w, 2); if(GTK_BIN(w)->child) @@ -245,43 +264,41 @@ static void dump_layout(const struct queuelike *ql) { static void namepart_completed_or_failed(void) { D(("namepart_completed_or_failed")); --namepart_lookups_outstanding; - if(!namepart_lookups_outstanding || namepart_completions_deferred > 24) { + if(!namepart_lookups_outstanding) { redisplay_queue(&ql_queue); redisplay_queue(&ql_recent); + redisplay_queue(&ql_added); namepart_completions_deferred = 0; } } -/** @brief Called when A namepart lookup has completed */ -static void namepart_completed(void *v, const char *value) { - struct callbackdata *cbd = v; +/** @brief Called when a namepart lookup has completed */ +static void namepart_completed(void *v, const char *error, const char *value) { + if(error) { + gtk_label_set_text(GTK_LABEL(report_label), error); + } else { + const char *key = v; - D(("namepart_completed")); - cache_put(&cachetype_string, cbd->u.key, value); - ++namepart_completions_deferred; + cache_put(&cachetype_string, key, value); + ++namepart_completions_deferred; + } namepart_completed_or_failed(); } /** @brief Called when a length lookup has completed */ -static void length_completed(void *v, long l) { - struct callbackdata *cbd = v; - long *value; - - D(("namepart_completed")); - value = xmalloc(sizeof *value); - *value = l; - cache_put(&cachetype_integer, cbd->u.key, value); - ++namepart_completions_deferred; - namepart_completed_or_failed(); -} - -/** @brief Called when a length or namepart lookup has failed */ -static void namepart_protocol_error( - struct callbackdata attribute((unused)) *cbd, - int attribute((unused)) code, - const char *msg) { - D(("namepart_protocol_error")); - gtk_label_set_text(GTK_LABEL(report_label), msg); +static void length_completed(void *v, const char *error, long l) { + if(error) + gtk_label_set_text(GTK_LABEL(report_label), error); + else { + const char *key = v; + long *value; + + D(("namepart_completed")); + value = xmalloc(sizeof *value); + *value = l; + cache_put(&cachetype_integer, key, value); + ++namepart_completions_deferred; + } namepart_completed_or_failed(); } @@ -290,14 +307,9 @@ static void namepart_fill(const char *track, const char *context, const char *part, const char *key) { - struct callbackdata *cbd; - ++namepart_lookups_outstanding; - cbd = xmalloc(sizeof *cbd); - cbd->onerror = namepart_protocol_error; - cbd->u.key = key; disorder_eclient_namepart(client, namepart_completed, - track, context, part, cbd); + track, context, part, (void *)key); } /** @brief Look up a namepart @@ -344,7 +356,6 @@ void namepart_update(const char *track, static long getlength(const char *track) { char *key; const long *value; - struct callbackdata *cbd; static const long bogus = -1; D(("getlength %s", track)); @@ -354,10 +365,7 @@ static long getlength(const char *track) { D(("deferring..."));; cache_put(&cachetype_integer, key, value = &bogus); ++namepart_lookups_outstanding; - cbd = xmalloc(sizeof *cbd); - cbd->onerror = namepart_protocol_error; - cbd->u.key = key; - disorder_eclient_length(client, length_completed, track, cbd); + disorder_eclient_length(client, length_completed, track, key); } return *value; } @@ -416,7 +424,8 @@ static GtkWidget *column_namepart(const struct queuelike const char *data) { D(("column_namepart")); NW(label); - return gtk_label_new(namepart(q->track, "display", data)); + return gtk_label_new(truncate_for_display(namepart(q->track, "display", data), + config->short_display)); } /** @brief Compute the length field */ @@ -492,9 +501,14 @@ static void update_queue(struct queuelike *ql, struct queue_entry *newq) { selection_cleanup(ql->selection); } -/** @brief Wrap up a widget for putting into the queue or title */ +/** @brief Wrap up a widget for putting into the queue or title + * @param label Label to contain + * @param style Pointer to style to use + * @param wp Updated with maximum width (or NULL) + * @return New widget + */ static GtkWidget *wrap_queue_cell(GtkWidget *label, - const char *name, + GtkStyle *style, int *wp) { GtkRequisition req; GtkWidget *bg; @@ -512,9 +526,9 @@ static GtkWidget *wrap_queue_cell(GtkWidget *label, gtk_widget_size_request(label, &req); if(req.width > *wp) *wp = req.width; } - /* Set widget names */ - gtk_widget_set_name(bg, name); - gtk_widget_set_name(label, name); + /* Set colors */ + gtk_widget_set_style(bg, style); + gtk_widget_set_style(label, style); return bg; } @@ -523,20 +537,20 @@ static GtkWidget *get_queue_cell(struct queuelike *ql, const struct queue_entry *q, int row, int col, - const char *name, + GtkStyle *style, int *wp) { GtkWidget *label; D(("get_queue_cell %d %d", row, col)); - label = columns[col].widget(ql, q, columns[col].data); - gtk_misc_set_alignment(GTK_MISC(label), columns[col].xalign, 0); - return wrap_queue_cell(label, name, wp); + label = ql->columns[col].widget(ql, q, ql->columns[col].data); + gtk_misc_set_alignment(GTK_MISC(label), ql->columns[col].xalign, 0); + return wrap_queue_cell(label, style, wp); } /** @brief Add a padding cell to the end of a row */ -static GtkWidget *get_padding_cell(const char *name) { +static GtkWidget *get_padding_cell(GtkStyle *style) { D(("get_padding_cell")); NW(label); - return wrap_queue_cell(gtk_label_new(""), name, 0); + return wrap_queue_cell(gtk_label_new(""), style, 0); } /* User button press and menu ---------------------------------------------- */ @@ -547,8 +561,8 @@ static void set_widget_states(struct queuelike *ql) { int row, col; for(q = ql->q, row = 0; q; q = q->next, ++row) { - for(col = 0; col < NCOLUMNS + 1; ++col) - gtk_widget_set_state(ql->cells[row * (NCOLUMNS + 1) + col], + for(col = 0; col < ql->ncolumns + 1; ++col) + gtk_widget_set_state(ql->cells[row * (ql->ncolumns + 1) + col], selection_selected(ql->selection, q->id) ? GTK_STATE_SELECTED : GTK_STATE_NORMAL); } @@ -677,6 +691,16 @@ void queue_select_all(struct queuelike *ql) { set_widget_states(ql); } +/** @brief Deselect all entries in a queue */ +void queue_select_none(struct queuelike *ql) { + struct queue_entry *qq; + + for(qq = ql->q; qq; qq = qq->next) + selection_set(ql->selection, qq->id, 0); + ql->last_click = 0; + set_widget_states(ql); +} + /** @brief Pop up properties for selected tracks */ void queue_properties(struct queuelike *ql) { struct vector v; @@ -692,7 +716,11 @@ void queue_properties(struct queuelike *ql) { /* Drag and drop rearrangement --------------------------------------------- */ -/** @brief Return nonzero if @p is a draggable row */ +/** @brief Return nonzero if @p is a draggable row + * + * Only tracks in the main queue are draggable (and the currently playing track + * is not draggable). + */ static int draggable_row(const struct queue_entry *q) { return q->ql == &ql_queue && q != playing_track; } @@ -738,6 +766,12 @@ static struct queue_entry *findentry(struct queuelike *ql, return q; } +static void move_completed(void attribute((unused)) *v, + const char *error) { + if(error) + popup_protocol_error(0, error); +} + /** @brief Called when data is dropped */ static gboolean queue_drag_drop(GtkWidget attribute((unused)) *widget, GdkDragContext *drag_context, @@ -757,7 +791,7 @@ static gboolean queue_drag_drop(GtkWidget attribute((unused)) *widget, if(q != playing_track && selection_selected(ql->selection, q->id)) vector_append(&vec, (char *)q->id); disorder_eclient_moveafter(client, id, vec.nvec, (const char **)vec.vec, - 0/*completed*/, 0/*v*/); + move_completed, 0/*v*/); gtk_drag_finish(drag_context, TRUE, TRUE, when); /* Destroy dropzones */ remove_drag_targets(ql); @@ -783,7 +817,7 @@ static gboolean queue_drag_motion(GtkWidget attribute((unused)) *widget, g_signal_connect(ql->dragmark, "destroy", G_CALLBACK(gtk_widget_destroyed), &ql->dragmark); gtk_widget_set_size_request(ql->dragmark, 10240, row ? 4 : 2); - gtk_widget_set_name(ql->dragmark, "queue-drag"); + gtk_widget_set_style(ql->dragmark, drag_style); gtk_layout_put(GTK_LAYOUT(ql->mainlayout), ql->dragmark, 0, (row + 1) * ql->mainrowheight - !!row); } else @@ -808,15 +842,23 @@ static void queue_drag_leave(GtkWidget attribute((unused)) *widget, gtk_widget_hide(ql->dragmark); } -/** @brief Add a drag target at position @p y +/** @brief Add a drag target + * @param ql The queue-like (in practice this is always @ref ql_queue) + * @param y The Y coordinate to place the drag target + * @param id Track to insert moved tracks after, or NULL * - * @p id is the track to insert the moved tracks after, and might be 0 to - * insert before the start. */ -static void add_drag_target(struct queuelike *ql, int y, int row, + * Adds a drop zone at Y coordinate @p y, which is assumed to lie between two + * tracks (or before the start of the queue or after the end of the queue). If + * tracks are dragged into this dropzone then they will be moved @em after + * track @p id, or to the start of the queue if @p id is NULL. + * + * We remember all the dropzones in @c ql->dropzones so they can be destroyed + * later. + */ +static void add_drag_target(struct queuelike *ql, int y, const char *id) { GtkWidget *eventbox; - assert(ql->dropzones[row] == 0); NW(event_box); eventbox = gtk_event_box_new(); /* Make the target zone invisible */ @@ -841,40 +883,43 @@ static void add_drag_target(struct queuelike *ql, int y, int row, /* The widget needs to be shown to receive drags */ gtk_widget_show(eventbox); /* Remember the drag targets */ - ql->dropzones[row] = eventbox; + ql->dropzones[ql->ndropzones] = eventbox; g_signal_connect(eventbox, "destroy", - G_CALLBACK(gtk_widget_destroyed), &ql->dropzones[row]); + G_CALLBACK(gtk_widget_destroyed), + &ql->dropzones[ql->ndropzones]); + ++ql->ndropzones; } /** @brief Create dropzones for dragging into */ static void add_drag_targets(struct queuelike *ql) { - int row, y; + int y; struct queue_entry *q; /* Create an array to store the widgets */ ql->dropzones = xcalloc(ql->nrows, sizeof (GtkWidget *)); + ql->ndropzones = 0; y = 0; /* Add a drag target before the first row provided it's not the playing * track */ if(!playing_track || ql->q != playing_track) - add_drag_target(ql, 0, 0, 0); + add_drag_target(ql, 0, 0); /* Put a drag target at the bottom of every row */ - for(q = ql->q, row = 0; q; q = q->next, ++row) { + for(q = ql->q; q; q = q->next) { y += ql->mainrowheight; - add_drag_target(ql, y, row, q->id); + add_drag_target(ql, y, q->id); } } /** @brief Remove the dropzones */ static void remove_drag_targets(struct queuelike *ql) { - int row; + int n; - for(row = 0; row < ql->nrows; ++row) { - if(ql->dropzones[row]) { + for(n = 0; n < ql->ndropzones; ++n) { + if(ql->dropzones[n]) { DW(event_box); - gtk_widget_destroy(ql->dropzones[row]); + gtk_widget_destroy(ql->dropzones[n]); } - assert(ql->dropzones[row] == 0); + assert(ql->dropzones[n] == 0); } } @@ -885,10 +930,10 @@ static void redisplay_queue(struct queuelike *ql) { struct queue_entry *q; int row, col; GList *c, *children; - const char *name; + GtkStyle *style; GtkRequisition req; GtkWidget *w; - int maxwidths[NCOLUMNS], x, y, titlerowheight; + int maxwidths[MAXCOLUMNS], x, y, titlerowheight; int totalwidth = 10240; /* TODO: can we be less blunt */ D(("redisplay_queue")); @@ -909,9 +954,9 @@ static void redisplay_queue(struct queuelike *ql) { for(q = ql->q, ql->nrows = 0; q; q = q->next) ++ql->nrows; /* We need to create all the widgets before we can position them */ - ql->cells = xcalloc(ql->nrows * (NCOLUMNS + 1), sizeof *ql->cells); + ql->cells = xcalloc(ql->nrows * (ql->ncolumns + 1), sizeof *ql->cells); /* Minimum width is given by the column headings */ - for(col = 0; col < NCOLUMNS; ++col) { + for(col = 0; col < ql->ncolumns; ++col) { /* Reset size so we don't inherit last iteration's maximum size */ gtk_widget_set_size_request(GTK_BIN(ql->titlecells[col])->child, -1, -1); gtk_widget_size_request(GTK_BIN(ql->titlecells[col])->child, &req); @@ -925,16 +970,16 @@ static void redisplay_queue(struct queuelike *ql) { /* Construct the widgets */ for(q = ql->q, row = 0; q; q = q->next, ++row) { /* Figure out the widget name for this row */ - if(q == playing_track) name = "row-playing"; - else name = row % 2 ? "row-even" : "row-odd"; + if(q == playing_track) style = active_style; + else style = row % 2 ? even_style : odd_style; /* Make the widget for each column */ - for(col = 0; col <= NCOLUMNS; ++col) { + for(col = 0; col <= ql->ncolumns; ++col) { /* Create and store the widget */ - if(col < NCOLUMNS) - w = get_queue_cell(ql, q, row, col, name, &maxwidths[col]); + if(col < ql->ncolumns) + w = get_queue_cell(ql, q, row, col, style, &maxwidths[col]); else - w = get_padding_cell(name); - ql->cells[row * (NCOLUMNS + 1) + col] = w; + w = get_padding_cell(style); + ql->cells[row * (ql->ncolumns + 1) + col] = w; /* Maybe mark it draggable */ if(draggable_row(q)) { gtk_drag_source_set(w, GDK_BUTTON1_MASK, @@ -955,14 +1000,14 @@ static void redisplay_queue(struct queuelike *ql) { * everything and position it */ for(row = 0, q = ql->q; row < ql->nrows; ++row, q = q->next) { x = 0; - for(col = 0; col < NCOLUMNS; ++col) { - w = ql->cells[row * (NCOLUMNS + 1) + col]; + for(col = 0; col < ql->ncolumns; ++col) { + w = ql->cells[row * (ql->ncolumns + 1) + col]; gtk_widget_set_size_request(GTK_BIN(w)->child, maxwidths[col], -1); gtk_layout_put(GTK_LAYOUT(ql->mainlayout), w, x, y); x += maxwidths[col]; } - w = ql->cells[row * (NCOLUMNS + 1) + col]; + w = ql->cells[row * (ql->ncolumns + 1) + col]; gtk_widget_set_size_request(GTK_BIN(w)->child, totalwidth - x, -1); gtk_layout_put(GTK_LAYOUT(ql->mainlayout), w, x, y); @@ -971,7 +1016,7 @@ static void redisplay_queue(struct queuelike *ql) { } /* Titles */ x = 0; - for(col = 0; col < NCOLUMNS; ++col) { + for(col = 0; col < ql->ncolumns; ++col) { gtk_widget_set_size_request(GTK_BIN(ql->titlecells[col])->child, maxwidths[col], -1); gtk_layout_move(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], x, 0); @@ -1002,7 +1047,7 @@ static void queuelike_completed(void *v, struct queue_entry *q) { D(("queuelike_complete")); /* Install the new queue */ - update_queue(ql, ql->fixup(q)); + update_queue(ql, ql->fixup ? ql->fixup(q) : q); /* Update the display */ redisplay_queue(ql); if(ql->notify) @@ -1038,7 +1083,8 @@ static GtkWidget *queuelike(struct queuelike *ql, struct queue_entry *(*fixup)(struct queue_entry *), void (*notify)(void), struct queue_menuitem *menuitems, - const char *name) { + const struct column *columns, + int ncolumns) { GtkWidget *vbox, *mainscroll, *titlescroll, *label; GtkAdjustment *mainadj, *titleadj; int col, n; @@ -1047,17 +1093,20 @@ static GtkWidget *queuelike(struct queuelike *ql, ql->fixup = fixup; ql->notify = notify; ql->menuitems = menuitems; - ql->name = name; ql->mainrowheight = !0; /* else division by 0 */ ql->selection = selection_new(); + ql->columns = columns; + ql->ncolumns = ncolumns; /* Create the layouts */ NW(layout); ql->mainlayout = gtk_layout_new(0, 0); + gtk_widget_set_style(ql->mainlayout, layout_style); NW(layout); ql->titlelayout = gtk_layout_new(0, 0); + gtk_widget_set_style(ql->titlelayout, title_style); /* Scroll the layouts */ - ql->mainscroll = mainscroll = scroll_widget(ql->mainlayout, name); - titlescroll = scroll_widget(ql->titlelayout, name); + ql->mainscroll = mainscroll = scroll_widget(ql->mainlayout); + titlescroll = scroll_widget(ql->titlelayout); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(titlescroll), GTK_POLICY_NEVER, GTK_POLICY_NEVER); mainadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(mainscroll)); @@ -1065,14 +1114,14 @@ static GtkWidget *queuelike(struct queuelike *ql, g_signal_connect(mainadj, "changed", G_CALLBACK(queue_scrolled), titleadj); g_signal_connect(mainadj, "value-changed", G_CALLBACK(queue_scrolled), titleadj); /* Fill the titles and put them anywhere */ - for(col = 0; col < NCOLUMNS; ++col) { + for(col = 0; col < ql->ncolumns; ++col) { NW(label); - label = gtk_label_new(columns[col].name); - gtk_misc_set_alignment(GTK_MISC(label), columns[col].xalign, 0); - ql->titlecells[col] = wrap_queue_cell(label, "row-title", 0); + label = gtk_label_new(ql->columns[col].name); + gtk_misc_set_alignment(GTK_MISC(label), ql->columns[col].xalign, 0); + ql->titlecells[col] = wrap_queue_cell(label, title_style, 0); gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0); } - ql->titlecells[col] = get_padding_cell("row-title"); + ql->titlecells[col] = get_padding_cell(title_style); gtk_layout_put(GTK_LAYOUT(ql->titlelayout), ql->titlecells[col], 0, 0); /* Pack the lot together in a vbox */ NW(vbox); @@ -1098,6 +1147,7 @@ static GtkWidget *queuelike(struct queuelike *ql, g_signal_connect(ql->mainlayout, "button-press-event", G_CALLBACK(mainlayout_button), ql); #endif + set_tool_colors(ql->menu); return vbox; } @@ -1138,11 +1188,18 @@ static int scratch_sensitive(struct queuelike attribute((unused)) *ql, && selection_selected(ql->selection, playing_track->id)); } +/** @brief Called when disorder_eclient_scratch completes */ +static void scratch_completed(void attribute((unused)) *v, + const char *error) { + if(error) + popup_protocol_error(0, error); +} + /** @brief Scratch the playing track */ static void scratch_activate(GtkMenuItem attribute((unused)) *menuitem, gpointer attribute((unused)) user_data) { if(playing_track) - disorder_eclient_scratch(client, playing_track->id, 0, 0); + disorder_eclient_scratch(client, playing_track->id, scratch_completed, 0); } /** @brief Determine whether the remove option should be sensitive */ @@ -1157,6 +1214,12 @@ static int remove_sensitive(struct queuelike *ql, || count_selected_nonplaying(ql))); } +static void remove_completed(void attribute((unused)) *v, + const char *error) { + if(error) + popup_protocol_error(0, error); +} + /** @brief Remove selected track(s) */ static void remove_activate(GtkMenuItem attribute((unused)) *menuitem, gpointer user_data) { @@ -1168,10 +1231,10 @@ static void remove_activate(GtkMenuItem attribute((unused)) *menuitem, /* Remove selected tracks */ for(q = ql->q; q; q = q->next) if(selection_selected(ql->selection, q->id) && q != playing_track) - disorder_eclient_remove(client, q->id, 0, 0); + disorder_eclient_remove(client, q->id, move_completed, 0); } else if(q) /* Remove just the hovered track */ - disorder_eclient_remove(client, q->id, 0, 0); + disorder_eclient_remove(client, q->id, remove_completed, 0); } /** @brief Determine whether the properties menu option should be sensitive */ @@ -1206,6 +1269,47 @@ static void selectall_activate(GtkMenuItem attribute((unused)) *menuitem, queue_select_all(mii->ql); } +/** @brief Determine whether the select none menu option should be sensitive */ +static int selectnone_sensitive(struct queuelike *ql, + struct queue_menuitem attribute((unused)) *m, + struct queue_entry attribute((unused)) *q) { + /* Sensitive if there is anything selected */ + return hash_count(ql->selection) != 0; +} + +/** @brief Select no tracks */ +static void selectnone_activate(GtkMenuItem attribute((unused)) *menuitem, + gpointer user_data) { + const struct menuiteminfo *mii = user_data; + queue_select_none(mii->ql); +} + +/** @brief Determine whether the play menu option should be sensitive */ +static int play_sensitive(struct queuelike *ql, + struct queue_menuitem attribute((unused)) *m, + struct queue_entry attribute((unused)) *q) { + /* "Play" is sensitive if at least something is selected */ + return (hash_count(ql->selection) > 0 + && (disorder_eclient_state(client) & DISORDER_CONNECTED)); +} + +/** @brief Play the selected tracks */ +static void play_activate(GtkMenuItem attribute((unused)) *menuitem, + gpointer user_data) { + const struct menuiteminfo *mii = user_data; + struct queue_entry *q = mii->q; + struct queuelike *ql = mii->ql; + + if(queue_count_selected(ql)) { + /* Play selected tracks */ + for(q = ql->q; q; q = q->next) + if(selection_selected(ql->selection, q->id)) + disorder_eclient_play(client, q->track, play_completed, 0); + } else if(q) + /* Nothing is selected, so play the hovered track */ + disorder_eclient_play(client, q->track, play_completed, 0); +} + /* The queue --------------------------------------------------------------- */ /** @brief Fix up the queue by sticking the currently playing track on the front */ @@ -1239,6 +1343,7 @@ static gboolean adjust_sofar(gpointer attribute((unused)) data) { static struct queue_menuitem queue_menu[] = { { "Track properties", properties_activate, properties_sensitive, 0, 0 }, { "Select all tracks", selectall_activate, selectall_sensitive, 0, 0 }, + { "Deselect all tracks", selectnone_activate, selectnone_sensitive, 0, 0 }, { "Scratch track", scratch_activate, scratch_sensitive, 0, 0 }, { "Remove track from queue", remove_activate, remove_sensitive, 0, 0 }, { 0, 0, 0, 0, 0 } @@ -1261,11 +1366,12 @@ GtkWidget *queue_widget(void) { /* Arrange periodic update of the so-far played field */ g_timeout_add(1000/*ms*/, adjust_sofar, 0); /* Arrange a callback whenever the playing state changes */ - register_monitor(playing_update, 0, DISORDER_PLAYING|DISORDER_TRACK_PAUSED); + register_monitor(playing_update, 0, DISORDER_PLAYING|DISORDER_TRACK_PAUSED); + register_reset(queue_update); /* We pass choose_update() as our notify function since the choose screen * marks tracks that are playing/in the queue. */ return queuelike(&ql_queue, fixup_queue, choose_update, queue_menu, - "queue"); + maincolumns, NMAINCOLUMNS); } /** @brief Arrange an update of the queue widget @@ -1310,13 +1416,16 @@ static struct queue_entry *fixup_recent(struct queue_entry *q) { static struct queue_menuitem recent_menu[] = { { "Track properties", properties_activate, properties_sensitive,0, 0 }, { "Select all tracks", selectall_activate, selectall_sensitive, 0, 0 }, + { "Deselect all tracks", selectnone_activate, selectnone_sensitive, 0, 0 }, { 0, 0, 0, 0, 0 } }; /** @brief Create the recently-played list */ GtkWidget *recent_widget(void) { D(("recent_widget")); - return queuelike(&ql_recent, fixup_recent, 0, recent_menu, "recent"); + register_reset(recent_update); + return queuelike(&ql_recent, fixup_recent, 0, recent_menu, + maincolumns, NMAINCOLUMNS); } /** @brief Update the recently played list @@ -1334,6 +1443,61 @@ void recent_update(void) { disorder_eclient_recent(client, queuelike_completed, cbd); } +/* Newly added tracks ------------------------------------------------------ */ + +/** @brief Pop-up menu for recently played list */ +static struct queue_menuitem added_menu[] = { + { "Track properties", properties_activate, properties_sensitive, 0, 0 }, + { "Play track", play_activate, play_sensitive, 0, 0 }, + { "Select all tracks", selectall_activate, selectall_sensitive, 0, 0 }, + { "Deselect all tracks", selectnone_activate, selectnone_sensitive, 0, 0 }, + { 0, 0, 0, 0, 0 } +}; + +/** @brief Create the newly-added list */ +GtkWidget *added_widget(void) { + D(("added_widget")); + register_reset(added_update); + return queuelike(&ql_added, 0/*fixup*/, 0/*notify*/, added_menu, + addedcolumns, NADDEDCOLUMNS); +} + +/** @brief Called with an updated list of newly-added tracks + * + * This is called with a raw list of track names but the rest of @ref + * disobedience/queue.c requires @ref queue_entry structures with a valid and + * unique @c id field. This function fakes it. + */ +static void new_completed(void *v, int nvec, char **vec) { + struct queue_entry *q, *qh, *qlast = 0, **qq = &qh; + int n; + + for(n = 0; n < nvec; ++n) { + q = xmalloc(sizeof *q); + q->prev = qlast; + q->track = vec[n]; + q->id = vec[n]; + *qq = q; + qq = &q->next; + qlast = q; + } + *qq = 0; + queuelike_completed(v, qh); +} + +/** @brief Update the newly-added list */ +void added_update(void) { + struct callbackdata *cbd; + D(("added_updae")); + + cbd = xmalloc(sizeof *cbd); + cbd->onerror = 0; + cbd->u.ql = &ql_added; + gtk_label_set_text(GTK_LABEL(report_label), + "updating newly added track list"); + disorder_eclient_new_tracks(client, new_completed, 0/*all*/, cbd); +} + /* Main menu plumbing ------------------------------------------------------ */ static int queue_properties_sensitive(GtkWidget *w) { @@ -1345,6 +1509,12 @@ static int queue_selectall_sensitive(GtkWidget *w) { return !!queue_count_entries(g_object_get_data(G_OBJECT(w), "queue")); } +static int queue_selectnone_sensitive(GtkWidget *w) { + struct queuelike *const ql = g_object_get_data(G_OBJECT(w), "queue"); + + return hash_count(ql->selection) != 0; +} + static void queue_properties_activate(GtkWidget *w) { queue_properties(g_object_get_data(G_OBJECT(w), "queue")); } @@ -1353,11 +1523,17 @@ static void queue_selectall_activate(GtkWidget *w) { queue_select_all(g_object_get_data(G_OBJECT(w), "queue")); } +static void queue_selectnone_activate(GtkWidget *w) { + queue_select_none(g_object_get_data(G_OBJECT(w), "queue")); +} + static const struct tabtype tabtype_queue = { queue_properties_sensitive, queue_selectall_sensitive, + queue_selectnone_sensitive, queue_properties_activate, queue_selectall_activate, + queue_selectnone_activate, }; /* Other entry points ------------------------------------------------------ */