2 * This file is part of DisOrder
3 * Copyright (C) 2006-2008 Richard Kettlewell
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.
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.
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
20 #include "disobedience.h"
22 #include "queue-generic.h"
26 int ql_selectall_sensitive(void *extra) {
27 struct queuelike *ql = extra;
31 void ql_selectall_activate(GtkMenuItem attribute((unused)) *menuitem,
33 struct queuelike *ql = user_data;
35 gtk_tree_selection_select_all(ql->selection);
40 int ql_selectnone_sensitive(void *extra) {
41 struct queuelike *ql = extra;
42 return gtk_tree_selection_count_selected_rows(ql->selection) > 0;
45 void ql_selectnone_activate(GtkMenuItem attribute((unused)) *menuitem,
47 struct queuelike *ql = user_data;
49 gtk_tree_selection_unselect_all(ql->selection);
54 int ql_properties_sensitive(void *extra) {
55 struct queuelike *ql = extra;
56 return gtk_tree_selection_count_selected_rows(ql->selection) > 0;
59 void ql_properties_activate(GtkMenuItem attribute((unused)) *menuitem,
61 struct queuelike *ql = user_data;
66 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql->store), iter);
67 for(struct queue_entry *q = ql->q; q; q = q->next) {
68 if(gtk_tree_selection_iter_is_selected(ql->selection, iter))
69 vector_append(v, (char *)q->track);
70 gtk_tree_model_iter_next(GTK_TREE_MODEL(ql->store), iter);
73 properties(v->nvec, (const char **)v->vec);
78 int ql_scratch_sensitive(void attribute((unused)) *extra) {
79 return !!(last_state & DISORDER_PLAYING)
80 && right_scratchable(last_rights, config->username, playing_track);
83 static void ql_scratch_completed(void attribute((unused)) *v,
86 popup_protocol_error(0, err);
89 void ql_scratch_activate(GtkMenuItem attribute((unused)) *menuitem,
90 gpointer attribute((unused)) user_data) {
91 disorder_eclient_scratch_playing(client, ql_scratch_completed, 0);
96 static void ql_remove_sensitive_callback(GtkTreeModel *model,
97 GtkTreePath attribute((unused)) *path,
100 struct queue_entry *q = ql_iter_to_q(model, iter);
101 const int removable = (q != playing_track
102 && right_removable(last_rights, config->username, q));
103 int *const counts = data;
107 int ql_remove_sensitive(void *extra) {
108 struct queuelike *ql = extra;
109 int counts[2] = { 0, 0 };
110 gtk_tree_selection_selected_foreach(ql->selection,
111 ql_remove_sensitive_callback,
113 /* Remove will work if we have at least some removable tracks selected, and
114 * no unremovable ones */
115 return counts[1] > 0 && counts[0] == 0;
118 static void ql_remove_completed(void attribute((unused)) *v,
121 popup_protocol_error(0, err);
124 static void ql_remove_activate_callback(GtkTreeModel *model,
125 GtkTreePath attribute((unused)) *path,
127 gpointer attribute((unused)) data) {
128 struct queue_entry *q = ql_iter_to_q(model, iter);
130 if(q != playing_track)
131 disorder_eclient_remove(client, q->id, ql_remove_completed, q);
134 void ql_remove_activate(GtkMenuItem attribute((unused)) *menuitem,
135 gpointer user_data) {
136 struct queuelike *ql = user_data;
137 gtk_tree_selection_selected_foreach(ql->selection,
138 ql_remove_activate_callback,
144 int ql_play_sensitive(void *extra) {
145 struct queuelike *ql = extra;
146 return (last_rights & RIGHT_PLAY)
147 && gtk_tree_selection_count_selected_rows(ql->selection) > 0;
150 static void ql_play_completed(void attribute((unused)) *v, const char *err) {
152 popup_protocol_error(0, err);
155 static void ql_play_activate_callback(GtkTreeModel *model,
156 GtkTreePath attribute((unused)) *path,
158 gpointer attribute((unused)) data) {
159 struct queue_entry *q = ql_iter_to_q(model, iter);
161 disorder_eclient_play(client, q->track, ql_play_completed, q);
164 void ql_play_activate(GtkMenuItem attribute((unused)) *menuitem,
165 gpointer user_data) {
166 struct queuelike *ql = user_data;
167 gtk_tree_selection_selected_foreach(ql->selection,
168 ql_play_activate_callback,
172 /** @brief Called when a button is released over a queuelike */
173 gboolean ql_button_release(GtkWidget *widget,
174 GdkEventButton *event,
175 gpointer user_data) {
176 struct queuelike *ql = user_data;
178 if(event->type == GDK_BUTTON_PRESS
179 && event->button == 3) {
180 /* Right button click. */
181 ensure_selected(GTK_TREE_VIEW(widget), event);
182 popup(&ql->menu, event, ql->menuitems, ql->nmenuitems, ql);
183 return TRUE; /* hide the click from other widgets */
189 struct tabtype *ql_tabtype(struct queuelike *ql) {
190 static const struct tabtype queuelike_tabtype = {
191 ql_properties_sensitive,
192 ql_selectall_sensitive,
193 ql_selectnone_sensitive,
194 ql_properties_activate,
195 ql_selectall_activate,
196 ql_selectnone_activate,
201 ql->tabtype = queuelike_tabtype;
202 ql->tabtype.extra = ql;