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 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 #include "disobedience.h"
22 /** @brief Popup menu */
23 static GtkWidget
*choose_menu
;
25 /** @brief Recursion step for choose_get_visible()
26 * @param parent A visible node, or NULL for the root
27 * @param callback Called for each visible node
28 * @param userdata Passed to @p callback
30 * If @p callback returns nonzero, the walk stops immediately.
32 static int choose_visible_recurse(GtkTreeIter
*parent
,
33 int (*callback
)(GtkTreeIter
*it
,
39 /* Skip placeholders */
40 if(choose_is_placeholder(parent
))
42 const int isfile
= choose_is_file(parent
);
43 if(callback(parent
, isfile
, userdata
))
46 return 0; /* Files never have children */
47 GtkTreePath
*parent_path
48 = gtk_tree_model_get_path(GTK_TREE_MODEL(choose_store
),
50 expanded
= gtk_tree_view_row_expanded(GTK_TREE_VIEW(choose_view
),
52 gtk_tree_path_free(parent_path
);
55 /* See if parent is expanded */
57 /* Parent is expanded, visit all its children */
59 gboolean itv
= gtk_tree_model_iter_children(GTK_TREE_MODEL(choose_store
),
63 if(choose_visible_recurse(it
, callback
, userdata
))
65 itv
= gtk_tree_model_iter_next(GTK_TREE_MODEL(choose_store
), it
);
71 static void choose_visible_visit(int (*callback
)(GtkTreeIter
*it
,
75 choose_visible_recurse(NULL
, callback
, userdata
);
78 static int choose_selectall_sensitive_callback
79 (GtkTreeIter
attribute((unused
)) *it
,
89 /** @brief Should 'select all' be sensitive?
91 * Yes if there are visible files.
93 static int choose_selectall_sensitive(void attribute((unused
)) *extra
) {
95 choose_visible_visit(choose_selectall_sensitive_callback
, &files
);
99 static int choose_selectall_activate_callback
102 void attribute((unused
)) *userdata
) {
104 gtk_tree_selection_select_iter(choose_selection
, it
);
106 gtk_tree_selection_unselect_iter(choose_selection
, it
);
110 /** @brief Activate select all
112 * Selects all files and deselects everything else.
114 static void choose_selectall_activate(GtkMenuItem
attribute((unused
)) *item
,
115 gpointer
attribute((unused
)) userdata
) {
116 choose_visible_visit(choose_selectall_activate_callback
, 0);
119 /** @brief Should 'select none' be sensitive
121 * Yes if anything is selected.
123 static int choose_selectnone_sensitive(void attribute((unused
)) *extra
) {
124 return gtk_tree_selection_count_selected_rows(choose_selection
) > 0;
127 /** @brief Activate select none */
128 static void choose_selectnone_activate(GtkMenuItem
attribute((unused
)) *item
,
129 gpointer
attribute((unused
)) userdata
) {
130 gtk_tree_selection_unselect_all(choose_selection
);
133 static void choose_play_sensitive_callback(GtkTreeModel
attribute((unused
)) *model
,
134 GtkTreePath
attribute((unused
)) *path
,
141 if(choose_is_dir(iter
))
143 else if(choose_is_file(iter
))
147 /** @brief Should 'play' be sensitive?
149 * Yes if tracks are selected and no directories are */
150 static int choose_play_sensitive(void attribute((unused
)) *extra
) {
153 gtk_tree_selection_selected_foreach(choose_selection
,
154 choose_play_sensitive_callback
,
159 static void choose_gather_selected_files_callback(GtkTreeModel
attribute((unused
)) *model
,
160 GtkTreePath
attribute((unused
)) *path
,
163 struct vector
*v
= data
;
165 if(choose_is_file(iter
))
166 vector_append(v
, choose_get_track(iter
));
170 static void choose_play_activate(GtkMenuItem
attribute((unused
)) *item
,
171 gpointer
attribute((unused
)) userdata
) {
174 gtk_tree_selection_selected_foreach(choose_selection
,
175 choose_gather_selected_files_callback
,
177 for(int n
= 0; n
< v
->nvec
; ++n
)
178 disorder_eclient_play(client
, v
->vec
[n
], choose_play_completed
, 0);
181 static int choose_properties_sensitive(void *extra
) {
182 return choose_play_sensitive(extra
);
185 static void choose_properties_activate(GtkMenuItem
attribute((unused
)) *item
,
186 gpointer
attribute((unused
)) userdata
) {
189 gtk_tree_selection_selected_foreach(choose_selection
,
190 choose_gather_selected_files_callback
,
192 properties(v
->nvec
, (const char **)v
->vec
);
195 /** @brief Pop-up menu for choose */
196 static struct menuitem choose_menuitems
[] = {
199 choose_play_activate
,
200 choose_play_sensitive
,
206 choose_properties_activate
,
207 choose_properties_sensitive
,
213 choose_selectall_activate
,
214 choose_selectall_sensitive
,
219 "Deselect all tracks",
220 choose_selectnone_activate
,
221 choose_selectnone_sensitive
,
227 const struct tabtype choose_tabtype
= {
228 choose_properties_sensitive
,
229 choose_selectall_sensitive
,
230 choose_selectnone_sensitive
,
231 choose_properties_activate
,
232 choose_selectall_activate
,
233 choose_selectnone_activate
,
238 /** @brief Called when a mouse button is pressed or released */
239 gboolean
choose_button_event(GtkWidget
attribute((unused
)) *widget
,
240 GdkEventButton
*event
,
241 gpointer
attribute((unused
)) user_data
) {
242 if(event
->type
== GDK_BUTTON_RELEASE
&& event
->button
== 2) {
243 /* Middle click release - play track */
244 ensure_selected(GTK_TREE_VIEW(choose_view
), event
);
245 choose_play_activate(NULL
, NULL
);
246 } else if(event
->type
== GDK_BUTTON_PRESS
&& event
->button
== 3) {
247 /* Right click press - pop up the menu */
248 ensure_selected(GTK_TREE_VIEW(choose_view
), event
);
249 popup(&choose_menu
, event
,
250 choose_menuitems
, sizeof choose_menuitems
/ sizeof *choose_menuitems
,