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