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"
21 #include "queue-generic.h"
25 int ql_selectall_sensitive(struct queuelike
*ql
) {
29 void ql_selectall_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
31 struct queuelike
*ql
= user_data
;
33 gtk_tree_selection_select_all(ql
->selection
);
38 int ql_selectnone_sensitive(struct queuelike
*ql
) {
39 return gtk_tree_selection_count_selected_rows(ql
->selection
) > 0;
42 void ql_selectnone_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
44 struct queuelike
*ql
= user_data
;
46 gtk_tree_selection_unselect_all(ql
->selection
);
51 int ql_properties_sensitive(struct queuelike
*ql
) {
52 return gtk_tree_selection_count_selected_rows(ql
->selection
) > 0;
55 void ql_properties_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
57 struct queuelike
*ql
= user_data
;
62 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ql
->store
), iter
);
63 for(struct queue_entry
*q
= ql
->q
; q
; q
= q
->next
) {
64 if(gtk_tree_selection_iter_is_selected(ql
->selection
, iter
))
65 vector_append(v
, (char *)q
->track
);
66 gtk_tree_model_iter_next(GTK_TREE_MODEL(ql
->store
), iter
);
69 properties(v
->nvec
, (const char **)v
->vec
);
74 int ql_scratch_sensitive(struct queuelike
attribute((unused
)) *ql
) {
75 return !!(last_state
& DISORDER_PLAYING
)
76 && right_scratchable(last_rights
, config
->username
, playing_track
);
79 static void scratch_completed(void attribute((unused
)) *v
, const char *error
) {
81 popup_protocol_error(0, error
);
84 void ql_scratch_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
85 gpointer
attribute((unused
)) user_data
) {
86 disorder_eclient_scratch_playing(client
, scratch_completed
, 0);
91 static void remove_sensitive_callback(GtkTreeModel
*model
,
92 GtkTreePath
attribute((unused
)) *path
,
95 struct queuelike
*ql
= g_object_get_data(G_OBJECT(model
), "ql");
96 struct queue_entry
*q
= ql_iter_to_q(ql
, iter
);
97 const int removable
= (q
!= playing_track
98 && right_removable(last_rights
, config
->username
, q
));
99 int *const counts
= data
;
103 int ql_remove_sensitive(struct queuelike
*ql
) {
104 int counts
[2] = { 0, 0 };
105 gtk_tree_selection_selected_foreach(ql
->selection
,
106 remove_sensitive_callback
,
108 /* Remove will work if we have at least some removable tracks selected, and
109 * no unremovable ones */
110 return counts
[1] > 0 && counts
[0] == 0;
113 static void remove_completed(void attribute((unused
)) *v
, const char *error
) {
115 popup_protocol_error(0, error
);
118 static void remove_activate_callback(GtkTreeModel
*model
,
119 GtkTreePath
attribute((unused
)) *path
,
121 gpointer
attribute((unused
)) data
) {
122 struct queuelike
*ql
= g_object_get_data(G_OBJECT(model
), "ql");
123 struct queue_entry
*q
= ql_iter_to_q(ql
, iter
);
125 disorder_eclient_remove(client
, q
->id
, remove_completed
, q
);
128 void ql_remove_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
129 gpointer user_data
) {
130 struct queuelike
*ql
= user_data
;
131 gtk_tree_selection_selected_foreach(ql
->selection
,
132 remove_activate_callback
,
138 int ql_play_sensitive(struct queuelike
*ql
) {
139 return gtk_tree_selection_count_selected_rows(ql
->selection
) > 0;
142 void ql_play_activate(GtkMenuItem
attribute((unused
)) *menuitem
,
143 gpointer
attribute((unused
)) user_data
) {
148 /** @brief Create @c ql->menu if it does not already exist */
149 static void ql_create_menu(struct queuelike
*ql
) {
152 ql
->menu
= gtk_menu_new();
153 g_signal_connect(ql
->menu
, "destroy",
154 G_CALLBACK(gtk_widget_destroyed
), &ql
->menu
);
155 for(int n
= 0; n
< ql
->nmenuitems
; ++n
) {
156 ql
->menuitems
[n
].w
= gtk_menu_item_new_with_label(ql
->menuitems
[n
].name
);
157 gtk_menu_attach(GTK_MENU(ql
->menu
), ql
->menuitems
[n
].w
, 0, 1, n
, n
+ 1);
159 set_tool_colors(ql
->menu
);
162 /** @brief Configure @c ql->menu */
163 static void ql_configure_menu(struct queuelike
*ql
) {
164 /* Set the sensitivity of each menu item and (re-)establish the signal
166 for(int n
= 0; n
< ql
->nmenuitems
; ++n
) {
167 if(ql
->menuitems
[n
].handlerid
)
168 g_signal_handler_disconnect(ql
->menuitems
[n
].w
,
169 ql
->menuitems
[n
].handlerid
);
170 gtk_widget_set_sensitive(ql
->menuitems
[n
].w
,
171 ql
->menuitems
[n
].sensitive(ql
));
172 ql
->menuitems
[n
].handlerid
= g_signal_connect
173 (ql
->menuitems
[n
].w
, "activate",
174 G_CALLBACK(ql
->menuitems
[n
].activate
), ql
);
178 /** @brief Called when a button is released over a queuelike */
179 gboolean
ql_button_release(GtkWidget
*widget
,
180 GdkEventButton
*event
,
181 gpointer user_data
) {
182 struct queuelike
*ql
= user_data
;
184 if(event
->type
== GDK_BUTTON_PRESS
185 && event
->button
== 3) {
186 /* Right button click. */
187 if(gtk_tree_selection_count_selected_rows(ql
->selection
) == 0) {
188 /* Nothing is selected, select whatever is under the pointer */
190 if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget
),
195 gtk_tree_selection_select_path(ql
->selection
, path
);
198 ql_configure_menu(ql
);
199 gtk_widget_show_all(ql
->menu
);
200 gtk_menu_popup(GTK_MENU(ql
->menu
), 0, 0, 0, 0,
201 event
->button
, event
->time
);
202 return TRUE
; /* hide the click from other widgets */
208 static int ql_tab_selectall_sensitive(void *extra
) {
209 return ql_selectall_sensitive(extra
);
212 static void ql_tab_selectall_activate(void *extra
) {
213 ql_selectall_activate(NULL
, extra
);
216 static int ql_tab_selectnone_sensitive(void *extra
) {
217 return ql_selectnone_sensitive(extra
);
220 static void ql_tab_selectnone_activate(void *extra
) {
221 ql_selectnone_activate(NULL
, extra
);
224 static int ql_tab_properties_sensitive(void *extra
) {
225 return ql_properties_sensitive(extra
);
228 static void ql_tab_properties_activate(void *extra
) {
229 ql_properties_activate(NULL
, extra
);
232 struct tabtype
*ql_tabtype(struct queuelike
*ql
) {
233 static const struct tabtype ql_tabtype
= {
234 ql_tab_properties_sensitive
,
235 ql_tab_selectall_sensitive
,
236 ql_tab_selectnone_sensitive
,
237 ql_tab_properties_activate
,
238 ql_tab_selectall_activate
,
239 ql_tab_selectnone_activate
,
244 struct tabtype
*t
= xmalloc(sizeof *t
);