2 * This file is part of DisOrder
3 * Copyright (C) 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"
24 /** @brief Popup menu */
25 static GtkWidget
*choose_menu
;
27 /** @brief Recursion step for choose_get_visible()
28 * @param parent A visible node, or NULL for the root
29 * @param callback Called for each visible node
30 * @param userdata Passed to @p callback
32 * If @p callback returns nonzero, the walk stops immediately.
34 static int choose_visible_recurse(GtkTreeIter
*parent
,
35 int (*callback
)(GtkTreeIter
*it
,
41 /* Skip placeholders */
42 if(choose_is_placeholder(parent
))
44 const int isfile
= choose_is_file(parent
);
45 if(callback(parent
, isfile
, userdata
))
48 return 0; /* Files never have children */
49 GtkTreePath
*parent_path
50 = gtk_tree_model_get_path(GTK_TREE_MODEL(choose_store
),
52 expanded
= gtk_tree_view_row_expanded(GTK_TREE_VIEW(choose_view
),
54 gtk_tree_path_free(parent_path
);
57 /* See if parent is expanded */
59 /* Parent is expanded, visit all its children */
61 gboolean itv
= gtk_tree_model_iter_children(GTK_TREE_MODEL(choose_store
),
65 if(choose_visible_recurse(it
, callback
, userdata
))
67 itv
= gtk_tree_model_iter_next(GTK_TREE_MODEL(choose_store
), it
);
73 static void choose_visible_visit(int (*callback
)(GtkTreeIter
*it
,
77 choose_visible_recurse(NULL
, callback
, userdata
);
80 static int choose_selectall_sensitive_callback
81 (GtkTreeIter
attribute((unused
)) *it
,
91 /** @brief Should 'select all' be sensitive?
93 * Yes if there are visible files.
95 static int choose_selectall_sensitive(void attribute((unused
)) *extra
) {
97 choose_visible_visit(choose_selectall_sensitive_callback
, &files
);
101 static int choose_selectall_activate_callback
104 void attribute((unused
)) *userdata
) {
106 gtk_tree_selection_select_iter(choose_selection
, it
);
108 gtk_tree_selection_unselect_iter(choose_selection
, it
);
112 /** @brief Activate select all
114 * Selects all files and deselects everything else.
116 static void choose_selectall_activate(GtkMenuItem
attribute((unused
)) *item
,
117 gpointer
attribute((unused
)) userdata
) {
118 choose_visible_visit(choose_selectall_activate_callback
, 0);
121 /** @brief Should 'select none' be sensitive
123 * Yes if anything is selected.
125 static int choose_selectnone_sensitive(void attribute((unused
)) *extra
) {
126 return gtk_tree_selection_count_selected_rows(choose_selection
) > 0;
129 /** @brief Activate select none */
130 static void choose_selectnone_activate(GtkMenuItem
attribute((unused
)) *item
,
131 gpointer
attribute((unused
)) userdata
) {
132 gtk_tree_selection_unselect_all(choose_selection
);
135 static void choose_play_sensitive_callback(GtkTreeModel
attribute((unused
)) *model
,
136 GtkTreePath
attribute((unused
)) *path
,
143 if(choose_is_dir(iter
))
145 else if(choose_is_file(iter
))
149 /** @brief Should 'play' be sensitive?
151 * Yes if tracks are selected and no directories are */
152 static int choose_play_sensitive(void attribute((unused
)) *extra
) {
155 gtk_tree_selection_selected_foreach(choose_selection
,
156 choose_play_sensitive_callback
,
161 static void choose_gather_selected_files_callback(GtkTreeModel
attribute((unused
)) *model
,
162 GtkTreePath
attribute((unused
)) *path
,
165 struct vector
*v
= data
;
167 if(choose_is_file(iter
))
168 vector_append(v
, choose_get_track(iter
));
172 static void choose_play_activate(GtkMenuItem
attribute((unused
)) *item
,
173 gpointer
attribute((unused
)) userdata
) {
176 gtk_tree_selection_selected_foreach(choose_selection
,
177 choose_gather_selected_files_callback
,
179 for(int n
= 0; n
< v
->nvec
; ++n
)
180 disorder_eclient_play(client
, v
->vec
[n
], choose_play_completed
, 0);
183 static int choose_properties_sensitive(void *extra
) {
184 return choose_play_sensitive(extra
);
187 static void choose_properties_activate(GtkMenuItem
attribute((unused
)) *item
,
188 gpointer
attribute((unused
)) userdata
) {
191 gtk_tree_selection_selected_foreach(choose_selection
,
192 choose_gather_selected_files_callback
,
194 properties(v
->nvec
, (const char **)v
->vec
);
197 /** @brief Pop-up menu for choose */
198 static struct menuitem choose_menuitems
[] = {
201 choose_play_activate
,
202 choose_play_sensitive
,
208 choose_properties_activate
,
209 choose_properties_sensitive
,
215 choose_selectall_activate
,
216 choose_selectall_sensitive
,
221 "Deselect all tracks",
222 choose_selectnone_activate
,
223 choose_selectnone_sensitive
,
229 const struct tabtype choose_tabtype
= {
230 choose_properties_sensitive
,
231 choose_selectall_sensitive
,
232 choose_selectnone_sensitive
,
233 choose_properties_activate
,
234 choose_selectall_activate
,
235 choose_selectnone_activate
,
240 /** @brief Called when a mouse button is pressed or released */
241 gboolean
choose_button_event(GtkWidget
attribute((unused
)) *widget
,
242 GdkEventButton
*event
,
243 gpointer
attribute((unused
)) user_data
) {
244 if(event
->type
== GDK_BUTTON_RELEASE
&& event
->button
== 2) {
245 /* Middle click release - play track */
246 ensure_selected(GTK_TREE_VIEW(choose_view
), event
);
247 choose_play_activate(NULL
, NULL
);
248 } else if(event
->type
== GDK_BUTTON_PRESS
&& event
->button
== 3) {
249 /* Right click press - pop up the menu */
250 ensure_selected(GTK_TREE_VIEW(choose_view
), event
);
251 popup(&choose_menu
, event
,
252 choose_menuitems
, sizeof choose_menuitems
/ sizeof *choose_menuitems
,