chiark / gitweb /
Sorting for Disobedience track chooser. A rewrite: we now do a single
[disorder] / disobedience / added.c
CommitLineData
c133bd3c
RK
1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2006-2008 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20#include "disobedience.h"
6982880f 21#include "popup.h"
c133bd3c
RK
22#include "queue-generic.h"
23
24/** @brief Called with an updated list of newly-added tracks
25 *
26 * This is called with a raw list of track names but the rest of @ref
27 * disobedience/queue-generic.c requires @ref queue_entry structures
28 * with a valid and unique @c id field. This function fakes it.
29 */
30static void added_completed(void attribute((unused)) *v,
31 const char *error,
32 int nvec, char **vec) {
33 if(error) {
34 popup_protocol_error(0, error);
35 return;
36 }
37 /* Convert the vector result to a queue linked list */
38 struct queue_entry *q, *qh, *qlast = 0, **qq = &qh;
39 int n;
40
41 for(n = 0; n < nvec; ++n) {
42 q = xmalloc(sizeof *q);
43 q->prev = qlast;
44 q->track = vec[n];
45 q->id = vec[n]; /* unique because a track is only added once */
46 *qq = q;
47 qq = &q->next;
48 qlast = q;
49 }
50 *qq = 0;
51 ql_new_queue(&ql_added, qh);
52 /* Tell anyone who cares */
53 event_raise("added-list-changed", qh);
54}
55
56/** @brief Update the newly-added list */
57static void added_changed(const char attribute((unused)) *event,
58 void attribute((unused)) *eventdata,
59 void attribute((unused)) *callbackdata) {
60 D(("added_changed"));
61
62 gtk_label_set_text(GTK_LABEL(report_label),
63 "updating newly added track list");
64 disorder_eclient_new_tracks(client, added_completed, 0/*all*/, 0);
65}
66
67/** @brief Called at startup */
68static void added_init(void) {
69 event_register("added-changed", added_changed, 0);
70}
71
72/** @brief Columns for the new tracks list */
73static const struct queue_column added_columns[] = {
b0b15b7c
RK
74 { "Artist", column_namepart, "artist", COL_EXPAND|COL_ELLIPSIZE },
75 { "Album", column_namepart, "album", COL_EXPAND|COL_ELLIPSIZE },
76 { "Title", column_namepart, "title", COL_EXPAND|COL_ELLIPSIZE },
77 { "Length", column_length, 0, COL_RIGHT }
c133bd3c
RK
78};
79
80/** @brief Pop-up menu for new tracks list */
6982880f 81static struct menuitem added_menuitems[] = {
c133bd3c
RK
82 { "Track properties", ql_properties_activate, ql_properties_sensitive, 0, 0 },
83 { "Play track", ql_play_activate, ql_play_sensitive, 0, 0 },
84 { "Select all tracks", ql_selectall_activate, ql_selectall_sensitive, 0, 0 },
85 { "Deselect all tracks", ql_selectnone_activate, ql_selectnone_sensitive, 0, 0 },
86};
87
88struct queuelike ql_added = {
ee7552f8 89 .name = "added",
c133bd3c
RK
90 .init = added_init,
91 .columns = added_columns,
92 .ncolumns = sizeof added_columns / sizeof *added_columns,
93 .menuitems = added_menuitems,
94 .nmenuitems = sizeof added_menuitems / sizeof *added_menuitems,
95};
96
97GtkWidget *added_widget(void) {
98 return init_queuelike(&ql_added);
99}
100
101/*
102Local Variables:
103c-basic-offset:2
104comment-column:40
105fill-column:79
106indent-tabs-mode:nil
107End:
108*/