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