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 3 of the License, or
8 * (at your option) any later version.
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.
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/>.
18 /** @file disobedience/queue-menu.c
19 * @brief Disobedience queue widget popup menu
21 #include "disobedience.h"
23 #include "queue-generic.h"
27 int ql_selectall_sensitive(void *extra
) {
28 struct queuelike
*ql
= extra
;
32 void ql_selectall_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
34 struct queuelike
*ql
= user_data
;
36 gtk_tree_selection_select_all(ql
->selection
);
41 int ql_selectnone_sensitive(void *extra
) {
42 struct queuelike
*ql
= extra
;
43 return gtk_tree_selection_count_selected_rows(ql
->selection
) > 0;
46 void ql_selectnone_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
48 struct queuelike
*ql
= user_data
;
50 gtk_tree_selection_unselect_all(ql
->selection
);
55 int ql_properties_sensitive(void *extra
) {
56 struct queuelike
*ql
= extra
;
57 return gtk_tree_selection_count_selected_rows(ql
->selection
) > 0;
60 void ql_properties_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
62 struct queuelike
*ql
= user_data
;
67 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql
->store
), iter
);
68 for(struct queue_entry
*q
= ql
->q
; q
; q
= q
->next
) {
69 if(gtk_tree_selection_iter_is_selected(ql
->selection
, iter
))
70 vector_append(v
, (char *)q
->track
);
71 gtk_tree_model_iter_next(GTK_TREE_MODEL(ql
->store
), iter
);
74 properties(v
->nvec
, (const char **)v
->vec
, ql
->view
);
79 int ql_scratch_sensitive(void attribute((unused
)) *extra
) {
80 return !!(last_state
& DISORDER_PLAYING
)
81 && right_scratchable(last_rights
, config
->username
, playing_track
);
84 static void ql_scratch_completed(void attribute((unused
)) *v
,
87 popup_protocol_error(0, err
);
90 void ql_scratch_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
91 gpointer
attribute((unused
)) user_data
) {
92 disorder_eclient_scratch_playing(client
, ql_scratch_completed
, 0);
97 static void ql_remove_sensitive_callback(GtkTreeModel
*model
,
98 GtkTreePath
attribute((unused
)) *path
,
101 struct queue_entry
*q
= ql_iter_to_q(model
, iter
);
102 const int removable
= (q
!= playing_track
103 && right_removable(last_rights
, config
->username
, q
));
104 int *const counts
= data
;
108 int ql_remove_sensitive(void *extra
) {
109 struct queuelike
*ql
= extra
;
110 int counts
[2] = { 0, 0 };
111 gtk_tree_selection_selected_foreach(ql
->selection
,
112 ql_remove_sensitive_callback
,
114 /* Remove will work if we have at least some removable tracks selected, and
115 * no unremovable ones */
116 return counts
[1] > 0 && counts
[0] == 0;
119 static void ql_remove_completed(void attribute((unused
)) *v
,
122 popup_protocol_error(0, err
);
125 static void ql_remove_activate_callback(GtkTreeModel
*model
,
126 GtkTreePath
attribute((unused
)) *path
,
128 gpointer
attribute((unused
)) data
) {
129 struct queue_entry
*q
= ql_iter_to_q(model
, iter
);
131 if(q
!= playing_track
)
132 disorder_eclient_remove(client
, ql_remove_completed
, q
->id
, q
);
135 void ql_remove_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
136 gpointer user_data
) {
137 struct queuelike
*ql
= user_data
;
138 gtk_tree_selection_selected_foreach(ql
->selection
,
139 ql_remove_activate_callback
,
145 int ql_play_sensitive(void *extra
) {
146 struct queuelike
*ql
= extra
;
147 return (last_rights
& RIGHT_PLAY
)
148 && gtk_tree_selection_count_selected_rows(ql
->selection
) > 0;
151 static void ql_play_completed(void attribute((unused
)) *v
, const char *err
,
152 const char attribute((unused
)) *id
) {
154 popup_protocol_error(0, err
);
157 static void ql_play_activate_callback(GtkTreeModel
*model
,
158 GtkTreePath
attribute((unused
)) *path
,
160 gpointer
attribute((unused
)) data
) {
161 struct queue_entry
*q
= ql_iter_to_q(model
, iter
);
163 disorder_eclient_play(client
, ql_play_completed
, q
->track
, q
);
166 void ql_play_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
167 gpointer user_data
) {
168 struct queuelike
*ql
= user_data
;
169 gtk_tree_selection_selected_foreach(ql
->selection
,
170 ql_play_activate_callback
,
174 /** @brief Called when a button is released over a queuelike */
175 gboolean
ql_button_release(GtkWidget
*widget
,
176 GdkEventButton
*event
,
177 gpointer user_data
) {
178 struct queuelike
*ql
= user_data
;
180 if(event
->type
== GDK_BUTTON_PRESS
181 && event
->button
== 3) {
182 /* Right button click. */
183 ensure_selected(GTK_TREE_VIEW(widget
), event
);
184 popup(&ql
->menu
, event
, ql
->menuitems
, ql
->nmenuitems
, ql
);
185 return TRUE
; /* hide the click from other widgets */
193 static void ql_adopt_sensitive_callback(GtkTreeModel
*model
,
194 GtkTreePath
attribute((unused
)) *path
,
197 struct queue_entry
*const q
= ql_iter_to_q(model
, iter
);
198 int *const count
= data
;
202 if(q
->origin
== origin_random
)
208 /** @brief Determine whether we're pointing at an adoptable track */
209 int ql_adopt_sensitive(void *extra
) {
210 struct queuelike
*ql
= extra
;
213 /* We'll need RIGHT_PLAY */
214 if(!(last_rights
& RIGHT_PLAY
))
216 /* Check that (1) only random tracks are selected (2) at least something is
218 gtk_tree_selection_selected_foreach(ql
->selection
,
219 ql_adopt_sensitive_callback
,
226 static void ql_adopt_completed(void attribute((unused
)) *v
, const char *err
) {
228 popup_protocol_error(0, err
);
231 static void ql_adopt_activate_callback(GtkTreeModel
*model
,
232 GtkTreePath
attribute((unused
)) *path
,
234 gpointer
attribute((unused
)) data
) {
235 struct queue_entry
*const q
= ql_iter_to_q(model
, iter
);
237 disorder_eclient_adopt(client
, ql_adopt_completed
, q
->id
, q
);
240 /** @brief Called to adopt a track */
241 void ql_adopt_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
242 gpointer user_data
) {
243 struct queuelike
*ql
= user_data
;
244 gtk_tree_selection_selected_foreach(ql
->selection
,
245 ql_adopt_activate_callback
,
249 struct tabtype
*ql_tabtype(struct queuelike
*ql
) {
250 static const struct tabtype queuelike_tabtype
= {
251 ql_properties_sensitive
,
252 ql_selectall_sensitive
,
253 ql_selectnone_sensitive
,
254 ql_properties_activate
,
255 ql_selectall_activate
,
256 ql_selectnone_activate
,
261 ql
->tabtype
= queuelike_tabtype
;
262 ql
->tabtype
.extra
= ql
;