Commit | Line | Data |
---|---|---|
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" | |
21 | #include "queue-generic.h" | |
22 | ||
23 | /* Select All */ | |
24 | ||
25 | int ql_selectall_sensitive(struct queuelike *ql) { | |
26 | return !!ql->q; | |
27 | } | |
28 | ||
29 | void ql_selectall_activate(GtkMenuItem attribute((unused)) *menuitem, | |
30 | gpointer user_data) { | |
31 | struct queuelike *ql = user_data; | |
32 | ||
33 | gtk_tree_selection_select_all(ql->selection); | |
34 | } | |
35 | ||
36 | /* Select None */ | |
37 | ||
38 | int ql_selectnone_sensitive(struct queuelike *ql) { | |
39 | return gtk_tree_selection_count_selected_rows(ql->selection) > 0; | |
40 | } | |
41 | ||
42 | void ql_selectnone_activate(GtkMenuItem attribute((unused)) *menuitem, | |
43 | gpointer user_data) { | |
44 | struct queuelike *ql = user_data; | |
45 | ||
46 | gtk_tree_selection_unselect_all(ql->selection); | |
47 | } | |
48 | ||
49 | /* Properties */ | |
50 | ||
51 | int ql_properties_sensitive(struct queuelike *ql) { | |
52 | return gtk_tree_selection_count_selected_rows(ql->selection) > 0; | |
53 | } | |
54 | ||
55 | void ql_properties_activate(GtkMenuItem attribute((unused)) *menuitem, | |
56 | gpointer user_data) { | |
57 | struct queuelike *ql = user_data; | |
58 | struct vector v[1]; | |
59 | GtkTreeIter iter[1]; | |
60 | ||
61 | vector_init(v); | |
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); | |
67 | } | |
68 | if(v->nvec) | |
69 | properties(v->nvec, (const char **)v->vec); | |
70 | } | |
71 | ||
72 | /* Scratch */ | |
73 | ||
74 | int ql_scratch_sensitive(struct queuelike attribute((unused)) *ql) { | |
75 | return !!playing_track; | |
76 | } | |
77 | ||
78 | void ql_scratch_activate(GtkMenuItem attribute((unused)) *menuitem, | |
79 | gpointer attribute((unused)) user_data) { | |
80 | /* TODO */ | |
81 | } | |
82 | ||
83 | /* Remove */ | |
84 | ||
85 | int ql_remove_sensitive(struct queuelike *ql) { | |
86 | return gtk_tree_selection_count_selected_rows(ql->selection) > 0; | |
87 | /* TODO ... but not if only selected track is playing track */ | |
88 | } | |
89 | ||
90 | void ql_remove_activate(GtkMenuItem attribute((unused)) *menuitem, | |
91 | gpointer attribute((unused)) user_data) { | |
92 | /* TODO */ | |
93 | } | |
94 | ||
95 | /* Play */ | |
96 | ||
97 | int ql_play_sensitive(struct queuelike *ql) { | |
98 | return gtk_tree_selection_count_selected_rows(ql->selection) > 0; | |
99 | } | |
100 | ||
101 | void ql_play_activate(GtkMenuItem attribute((unused)) *menuitem, | |
102 | gpointer attribute((unused)) user_data) { | |
103 | /* TODO */ | |
104 | } | |
105 | ||
106 | ||
107 | /** @brief Create @c ql->menu if it does not already exist */ | |
108 | static void ql_create_menu(struct queuelike *ql) { | |
109 | if(ql->menu) | |
110 | return; | |
111 | ql->menu = gtk_menu_new(); | |
112 | g_signal_connect(ql->menu, "destroy", | |
113 | G_CALLBACK(gtk_widget_destroyed), &ql->menu); | |
114 | for(int n = 0; n < ql->nmenuitems; ++n) { | |
115 | ql->menuitems[n].w = gtk_menu_item_new_with_label(ql->menuitems[n].name); | |
116 | gtk_menu_attach(GTK_MENU(ql->menu), ql->menuitems[n].w, 0, 1, n, n + 1); | |
117 | } | |
118 | set_tool_colors(ql->menu); | |
119 | } | |
120 | ||
121 | /** @brief Configure @c ql->menu */ | |
122 | static void ql_configure_menu(struct queuelike *ql) { | |
123 | /* Set the sensitivity of each menu item and (re-)establish the signal | |
124 | * handlers */ | |
125 | for(int n = 0; n < ql->nmenuitems; ++n) { | |
126 | if(ql->menuitems[n].handlerid) | |
127 | g_signal_handler_disconnect(ql->menuitems[n].w, | |
128 | ql->menuitems[n].handlerid); | |
129 | gtk_widget_set_sensitive(ql->menuitems[n].w, | |
130 | ql->menuitems[n].sensitive(ql)); | |
131 | ql->menuitems[n].handlerid = g_signal_connect | |
132 | (ql->menuitems[n].w, "activate", | |
133 | G_CALLBACK(ql->menuitems[n].activate), ql); | |
134 | } | |
135 | } | |
136 | ||
137 | /** @brief Called when a button is released over a queuelike */ | |
138 | gboolean ql_button_release(GtkWidget attribute((unused)) *widget, | |
139 | GdkEventButton *event, | |
140 | gpointer user_data) { | |
141 | struct queuelike *ql = user_data; | |
142 | ||
143 | if(event->type == GDK_BUTTON_PRESS | |
144 | && event->button == 3) { | |
145 | /* Right button click. */ | |
146 | ql_create_menu(ql); | |
147 | ql_configure_menu(ql); | |
148 | gtk_widget_show_all(ql->menu); | |
149 | gtk_menu_popup(GTK_MENU(ql->menu), 0, 0, 0, 0, | |
150 | event->button, event->time); | |
151 | return TRUE; /* hide the click from other widgets */ | |
152 | } | |
153 | ||
154 | return FALSE; | |
155 | } | |
156 | ||
157 | /* | |
158 | Local Variables: | |
159 | c-basic-offset:2 | |
160 | comment-column:40 | |
161 | fill-column:79 | |
162 | indent-tabs-mode:nil | |
163 | End: | |
164 | */ |