chiark / gitweb /
Playing checkbox in Disobedience choose tab is now only visible for
[disorder] / disobedience / queue-menu.c
CommitLineData
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"
6982880f 21#include "popup.h"
c133bd3c
RK
22#include "queue-generic.h"
23
24/* Select All */
25
6982880f
RK
26int ql_selectall_sensitive(void *extra) {
27 struct queuelike *ql = extra;
c133bd3c
RK
28 return !!ql->q;
29}
30
31void ql_selectall_activate(GtkMenuItem attribute((unused)) *menuitem,
32 gpointer user_data) {
33 struct queuelike *ql = user_data;
34
35 gtk_tree_selection_select_all(ql->selection);
36}
37
38/* Select None */
39
6982880f
RK
40int ql_selectnone_sensitive(void *extra) {
41 struct queuelike *ql = extra;
c133bd3c
RK
42 return gtk_tree_selection_count_selected_rows(ql->selection) > 0;
43}
44
45void ql_selectnone_activate(GtkMenuItem attribute((unused)) *menuitem,
46 gpointer user_data) {
47 struct queuelike *ql = user_data;
48
49 gtk_tree_selection_unselect_all(ql->selection);
50}
51
52/* Properties */
53
6982880f
RK
54int ql_properties_sensitive(void *extra) {
55 struct queuelike *ql = extra;
c133bd3c
RK
56 return gtk_tree_selection_count_selected_rows(ql->selection) > 0;
57}
58
59void ql_properties_activate(GtkMenuItem attribute((unused)) *menuitem,
60 gpointer user_data) {
61 struct queuelike *ql = user_data;
62 struct vector v[1];
63 GtkTreeIter iter[1];
64
65 vector_init(v);
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);
71 }
72 if(v->nvec)
73 properties(v->nvec, (const char **)v->vec);
74}
75
76/* Scratch */
77
6982880f 78int ql_scratch_sensitive(void attribute((unused)) *extra) {
c9fb35f4
RK
79 return !!(last_state & DISORDER_PLAYING)
80 && right_scratchable(last_rights, config->username, playing_track);
81}
82
ac56170f
RK
83static void ql_scratch_completed(void attribute((unused)) *v,
84 const char *error) {
c9fb35f4
RK
85 if(error)
86 popup_protocol_error(0, error);
c133bd3c
RK
87}
88
89void ql_scratch_activate(GtkMenuItem attribute((unused)) *menuitem,
90 gpointer attribute((unused)) user_data) {
ac56170f 91 disorder_eclient_scratch_playing(client, ql_scratch_completed, 0);
c133bd3c
RK
92}
93
94/* Remove */
95
ac56170f
RK
96static void ql_remove_sensitive_callback(GtkTreeModel *model,
97 GtkTreePath attribute((unused)) *path,
98 GtkTreeIter *iter,
99 gpointer data) {
83fb99f9 100 struct queue_entry *q = ql_iter_to_q(model, iter);
22717074
RK
101 const int removable = (q != playing_track
102 && right_removable(last_rights, config->username, q));
103 int *const counts = data;
104 ++counts[removable];
105}
106
6982880f
RK
107int ql_remove_sensitive(void *extra) {
108 struct queuelike *ql = extra;
22717074
RK
109 int counts[2] = { 0, 0 };
110 gtk_tree_selection_selected_foreach(ql->selection,
ac56170f 111 ql_remove_sensitive_callback,
22717074
RK
112 counts);
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;
116}
117
ac56170f
RK
118static void ql_remove_completed(void attribute((unused)) *v,
119 const char *error) {
22717074
RK
120 if(error)
121 popup_protocol_error(0, error);
122}
123
ac56170f
RK
124static void ql_remove_activate_callback(GtkTreeModel *model,
125 GtkTreePath attribute((unused)) *path,
126 GtkTreeIter *iter,
127 gpointer attribute((unused)) data) {
83fb99f9 128 struct queue_entry *q = ql_iter_to_q(model, iter);
22717074 129
ac56170f 130 disorder_eclient_remove(client, q->id, ql_remove_completed, q);
c133bd3c
RK
131}
132
133void ql_remove_activate(GtkMenuItem attribute((unused)) *menuitem,
22717074
RK
134 gpointer user_data) {
135 struct queuelike *ql = user_data;
136 gtk_tree_selection_selected_foreach(ql->selection,
ac56170f 137 ql_remove_activate_callback,
22717074 138 0);
c133bd3c
RK
139}
140
141/* Play */
142
6982880f
RK
143int ql_play_sensitive(void *extra) {
144 struct queuelike *ql = extra;
ac56170f
RK
145 return (last_rights & RIGHT_PLAY)
146 && gtk_tree_selection_count_selected_rows(ql->selection) > 0;
c133bd3c
RK
147}
148
ac56170f
RK
149static void ql_play_completed(void attribute((unused)) *v, const char *error) {
150 if(error)
151 popup_protocol_error(0, error);
c133bd3c
RK
152}
153
ac56170f
RK
154static void ql_play_activate_callback(GtkTreeModel *model,
155 GtkTreePath attribute((unused)) *path,
156 GtkTreeIter *iter,
157 gpointer attribute((unused)) data) {
83fb99f9 158 struct queue_entry *q = ql_iter_to_q(model, iter);
ac56170f
RK
159
160 disorder_eclient_play(client, q->track, ql_play_completed, q);
161}
162
163void ql_play_activate(GtkMenuItem attribute((unused)) *menuitem,
164 gpointer user_data) {
165 struct queuelike *ql = user_data;
166 gtk_tree_selection_selected_foreach(ql->selection,
167 ql_play_activate_callback,
168 0);
169}
c133bd3c 170
c133bd3c 171/** @brief Called when a button is released over a queuelike */
6982880f 172gboolean ql_button_release(GtkWidget *widget,
c133bd3c
RK
173 GdkEventButton *event,
174 gpointer user_data) {
175 struct queuelike *ql = user_data;
176
177 if(event->type == GDK_BUTTON_PRESS
178 && event->button == 3) {
be909398 179 /* Right button click. */
6982880f
RK
180 ensure_selected(GTK_TREE_VIEW(widget), event);
181 popup(&ql->menu, event, ql->menuitems, ql->nmenuitems, ql);
c133bd3c
RK
182 return TRUE; /* hide the click from other widgets */
183 }
184
185 return FALSE;
186}
187
ee7552f8
RK
188struct tabtype *ql_tabtype(struct queuelike *ql) {
189 static const struct tabtype ql_tabtype = {
6982880f
RK
190 ql_properties_sensitive,
191 ql_selectall_sensitive,
192 ql_selectnone_sensitive,
193 ql_properties_activate,
194 ql_selectall_activate,
195 ql_selectnone_activate,
ee7552f8
RK
196 0,
197 0
198 };
199
54156c62
RK
200 ql->tabtype = ql_tabtype;
201 ql->tabtype.extra = ql;
202 return &ql->tabtype;
ee7552f8
RK
203}
204
c133bd3c
RK
205/*
206Local Variables:
207c-basic-offset:2
208comment-column:40
209fill-column:79
210indent-tabs-mode:nil
211End:
212*/