| 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 3 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, |
| 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 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | /** @file disobedience/recent.c |
| 19 | * @brief Disobedience recently-played widget |
| 20 | */ |
| 21 | #include "disobedience.h" |
| 22 | #include "popup.h" |
| 23 | #include "queue-generic.h" |
| 24 | |
| 25 | /** @brief Update the recently played list */ |
| 26 | static void recent_completed(void attribute((unused)) *v, |
| 27 | const char *err, |
| 28 | struct queue_entry *q) { |
| 29 | if(err) { |
| 30 | popup_protocol_error(0, err); |
| 31 | return; |
| 32 | } |
| 33 | /* The recent list is backwards compared to what we wanted */ |
| 34 | struct queue_entry *qr = 0, *qn; |
| 35 | while(q) { |
| 36 | qn = q->next; |
| 37 | /* Swap next/prev pointers */ |
| 38 | q->next = q->prev; |
| 39 | q->prev = qn; |
| 40 | /* Remember last node for new head */ |
| 41 | qr = q; |
| 42 | /* Next node */ |
| 43 | q = qn; |
| 44 | } |
| 45 | /* Update the display */ |
| 46 | ql_new_queue(&ql_recent, qr); |
| 47 | /* Tell anyone who cares */ |
| 48 | event_raise("recent-list-changed", qr); |
| 49 | } |
| 50 | |
| 51 | /** @brief Schedule an update to the recently played list |
| 52 | * |
| 53 | * Called whenever a track is added to it or removed from it. |
| 54 | */ |
| 55 | static void recent_changed(const char attribute((unused)) *event, |
| 56 | void attribute((unused)) *eventdata, |
| 57 | void attribute((unused)) *callbackdata) { |
| 58 | D(("recent_changed")); |
| 59 | gtk_label_set_text(GTK_LABEL(report_label), "updating recently played list"); |
| 60 | disorder_eclient_recent(client, recent_completed, 0); |
| 61 | } |
| 62 | |
| 63 | /** @brief Called at startup */ |
| 64 | static void recent_init(struct queuelike attribute((unused)) *ql) { |
| 65 | /* Whenever the recent list changes on the server, re-fetch it */ |
| 66 | event_register("recent-changed", recent_changed, 0); |
| 67 | } |
| 68 | |
| 69 | /** @brief Columns for the recently-played list */ |
| 70 | static const struct queue_column recent_columns[] = { |
| 71 | { "When", column_when, 0, COL_RIGHT }, |
| 72 | { "Who", column_who, 0, 0 }, |
| 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 recently played list */ |
| 80 | static struct menuitem recent_menuitems[] = { |
| 81 | { "Track properties", GTK_STOCK_PROPERTIES, ql_properties_activate, ql_properties_sensitive,0, 0 }, |
| 82 | { "Play track", GTK_STOCK_MEDIA_PLAY, ql_play_activate, ql_play_sensitive, 0, 0 }, |
| 83 | { "Select all tracks", GTK_STOCK_SELECT_ALL, ql_selectall_activate, ql_selectall_sensitive, 0, 0 }, |
| 84 | { "Deselect all tracks", NULL, ql_selectnone_activate, ql_selectnone_sensitive, 0, 0 }, |
| 85 | }; |
| 86 | |
| 87 | struct queuelike ql_recent = { |
| 88 | .name = "recent", |
| 89 | .init = recent_init, |
| 90 | .columns = recent_columns, |
| 91 | .ncolumns = sizeof recent_columns / sizeof *recent_columns, |
| 92 | .menuitems = recent_menuitems, |
| 93 | .nmenuitems = sizeof recent_menuitems / sizeof *recent_menuitems, |
| 94 | .drag_source_targets = choose_targets, |
| 95 | .drag_source_actions = GDK_ACTION_COPY, |
| 96 | }; |
| 97 | |
| 98 | GtkWidget *recent_widget(void) { |
| 99 | return init_queuelike(&ql_recent); |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | Local Variables: |
| 104 | c-basic-offset:2 |
| 105 | comment-column:40 |
| 106 | fill-column:79 |
| 107 | indent-tabs-mode:nil |
| 108 | End: |
| 109 | */ |