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 RK |
17 | */ |
18 | #include "disobedience.h" | |
6982880f | 19 | #include "popup.h" |
c133bd3c RK |
20 | #include "queue-generic.h" |
21 | ||
22 | /** @brief Update the recently played list */ | |
23 | static void recent_completed(void attribute((unused)) *v, | |
abf99697 | 24 | const char *err, |
c133bd3c | 25 | struct queue_entry *q) { |
abf99697 RK |
26 | if(err) { |
27 | popup_protocol_error(0, err); | |
c133bd3c RK |
28 | return; |
29 | } | |
30 | /* The recent list is backwards compared to what we wanted */ | |
31 | struct queue_entry *qr = 0, *qn; | |
32 | while(q) { | |
33 | qn = q->next; | |
34 | /* Swap next/prev pointers */ | |
35 | q->next = q->prev; | |
36 | q->prev = qn; | |
37 | /* Remember last node for new head */ | |
38 | qr = q; | |
39 | /* Next node */ | |
40 | q = qn; | |
41 | } | |
42 | /* Update the display */ | |
43 | ql_new_queue(&ql_recent, qr); | |
44 | /* Tell anyone who cares */ | |
45 | event_raise("recent-list-changed", qr); | |
46 | } | |
47 | ||
48 | /** @brief Schedule an update to the recently played list | |
49 | * | |
50 | * Called whenever a track is added to it or removed from it. | |
51 | */ | |
52 | static void recent_changed(const char attribute((unused)) *event, | |
53 | void attribute((unused)) *eventdata, | |
54 | void attribute((unused)) *callbackdata) { | |
55 | D(("recent_changed")); | |
56 | gtk_label_set_text(GTK_LABEL(report_label), "updating recently played list"); | |
57 | disorder_eclient_recent(client, recent_completed, 0); | |
58 | } | |
59 | ||
60 | /** @brief Called at startup */ | |
61 | static void recent_init(void) { | |
62 | /* Whenever the recent list changes on the server, re-fetch it */ | |
63 | event_register("recent-changed", recent_changed, 0); | |
64 | } | |
65 | ||
66 | /** @brief Columns for the recently-played list */ | |
67 | static const struct queue_column recent_columns[] = { | |
b0b15b7c | 68 | { "When", column_when, 0, COL_RIGHT }, |
c133bd3c | 69 | { "Who", column_who, 0, 0 }, |
b0b15b7c RK |
70 | { "Artist", column_namepart, "artist", COL_EXPAND|COL_ELLIPSIZE }, |
71 | { "Album", column_namepart, "album", COL_EXPAND|COL_ELLIPSIZE }, | |
72 | { "Title", column_namepart, "title", COL_EXPAND|COL_ELLIPSIZE }, | |
73 | { "Length", column_length, 0, COL_RIGHT } | |
c133bd3c RK |
74 | }; |
75 | ||
76 | /** @brief Pop-up menu for recently played list */ | |
6982880f | 77 | static struct menuitem recent_menuitems[] = { |
c133bd3c | 78 | { "Track properties", ql_properties_activate, ql_properties_sensitive,0, 0 }, |
fa9986e2 | 79 | { "Play track", ql_play_activate, ql_play_sensitive, 0, 0 }, |
c133bd3c RK |
80 | { "Select all tracks", ql_selectall_activate, ql_selectall_sensitive, 0, 0 }, |
81 | { "Deselect all tracks", ql_selectnone_activate, ql_selectnone_sensitive, 0, 0 }, | |
82 | }; | |
83 | ||
84 | struct queuelike ql_recent = { | |
ee7552f8 | 85 | .name = "recent", |
c133bd3c RK |
86 | .init = recent_init, |
87 | .columns = recent_columns, | |
88 | .ncolumns = sizeof recent_columns / sizeof *recent_columns, | |
89 | .menuitems = recent_menuitems, | |
90 | .nmenuitems = sizeof recent_menuitems / sizeof *recent_menuitems, | |
91 | }; | |
92 | ||
93 | GtkWidget *recent_widget(void) { | |
94 | return init_queuelike(&ql_recent); | |
95 | } | |
96 | ||
97 | /* | |
98 | Local Variables: | |
99 | c-basic-offset:2 | |
100 | comment-column:40 | |
101 | fill-column:79 | |
102 | indent-tabs-mode:nil | |
103 | End: | |
104 | */ |