chiark / gitweb /
Start rewriting Disobedience choose tab using native tree. Much
[disorder] / disobedience / added.c
... / ...
CommitLineData
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"
21#include "queue-generic.h"
22
23/** @brief Called with an updated list of newly-added tracks
24 *
25 * This is called with a raw list of track names but the rest of @ref
26 * disobedience/queue-generic.c requires @ref queue_entry structures
27 * with a valid and unique @c id field. This function fakes it.
28 */
29static void added_completed(void attribute((unused)) *v,
30 const char *error,
31 int nvec, char **vec) {
32 if(error) {
33 popup_protocol_error(0, error);
34 return;
35 }
36 /* Convert the vector result to a queue linked list */
37 struct queue_entry *q, *qh, *qlast = 0, **qq = &qh;
38 int n;
39
40 for(n = 0; n < nvec; ++n) {
41 q = xmalloc(sizeof *q);
42 q->prev = qlast;
43 q->track = vec[n];
44 q->id = vec[n]; /* unique because a track is only added once */
45 *qq = q;
46 qq = &q->next;
47 qlast = q;
48 }
49 *qq = 0;
50 ql_new_queue(&ql_added, qh);
51 /* Tell anyone who cares */
52 event_raise("added-list-changed", qh);
53}
54
55/** @brief Update the newly-added list */
56static void added_changed(const char attribute((unused)) *event,
57 void attribute((unused)) *eventdata,
58 void attribute((unused)) *callbackdata) {
59 D(("added_changed"));
60
61 gtk_label_set_text(GTK_LABEL(report_label),
62 "updating newly added track list");
63 disorder_eclient_new_tracks(client, added_completed, 0/*all*/, 0);
64}
65
66/** @brief Called at startup */
67static void added_init(void) {
68 event_register("added-changed", added_changed, 0);
69}
70
71/** @brief Columns for the new tracks list */
72static const struct queue_column added_columns[] = {
73 { "Artist", column_namepart, "artist", COL_EXPAND|COL_ELLIPSIZE },
74 { "Album", column_namepart, "album", COL_EXPAND|COL_ELLIPSIZE },
75 { "Title", column_namepart, "title", COL_EXPAND|COL_ELLIPSIZE },
76 { "Length", column_length, 0, COL_RIGHT }
77};
78
79/** @brief Pop-up menu for new tracks list */
80static struct queue_menuitem added_menuitems[] = {
81 { "Track properties", ql_properties_activate, ql_properties_sensitive, 0, 0 },
82 { "Play track", ql_play_activate, ql_play_sensitive, 0, 0 },
83 { "Select all tracks", ql_selectall_activate, ql_selectall_sensitive, 0, 0 },
84 { "Deselect all tracks", ql_selectnone_activate, ql_selectnone_sensitive, 0, 0 },
85};
86
87struct queuelike ql_added = {
88 .name = "added",
89 .init = added_init,
90 .columns = added_columns,
91 .ncolumns = sizeof added_columns / sizeof *added_columns,
92 .menuitems = added_menuitems,
93 .nmenuitems = sizeof added_menuitems / sizeof *added_menuitems,
94};
95
96GtkWidget *added_widget(void) {
97 return init_queuelike(&ql_added);
98}
99
100/*
101Local Variables:
102c-basic-offset:2
103comment-column:40
104fill-column:79
105indent-tabs-mode:nil
106End:
107*/