chiark / gitweb /
Add jukebox user to audio group in debian setup
[disorder] / disobedience / menu.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
fb009628 3 * Copyright (C) 2006-2008 Richard Kettlewell
460b9539 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 */
2c348789
RK
20/** @file disobedience/menu.c
21 * @brief Main menu
22 */
460b9539 23
24#include "disobedience.h"
25
26static GtkWidget *selectall_widget;
fb009628 27static GtkWidget *selectnone_widget;
460b9539 28static GtkWidget *properties_widget;
29
ac6bf2ba
RK
30/** @brief Main menu widgets */
31GtkItemFactory *mainmenufactory;
32
460b9539 33static void about_popup_got_version(void *v, const char *value);
34
2c348789
RK
35/** @brief Called when the quit option is activated
36 *
37 * Just exits.
38 */
460b9539 39static void quit_program(gpointer attribute((unused)) callback_data,
40 guint attribute((unused)) callback_action,
41 GtkWidget attribute((unused)) *menu_item) {
42 D(("quit_program"));
43 exit(0);
44}
45
46/* TODO can we have a single parameterized callback for all these */
2c348789
RK
47
48/** @brief Called when the select all option is activated
49 *
50 * Calls the per-tab select all function.
51 */
460b9539 52static void select_all(gpointer attribute((unused)) callback_data,
53 guint attribute((unused)) callback_action,
54 GtkWidget attribute((unused)) *menu_item) {
55 GtkWidget *tab = gtk_notebook_get_nth_page
56 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
57 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
58
59 t->selectall_activate(tab);
60}
61
fb009628
RK
62/** @brief Called when the select none option is activated
63 *
64 * Calls the per-tab select none function.
65 */
66static void select_none(gpointer attribute((unused)) callback_data,
67 guint attribute((unused)) callback_action,
68 GtkWidget attribute((unused)) *menu_item) {
69 GtkWidget *tab = gtk_notebook_get_nth_page
70 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
71 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
72
73 t->selectnone_activate(tab);
74}
75
2c348789
RK
76/** @brief Called when the track properties option is activated
77 *
78 * Calls the per-tab properties function.
79 */
460b9539 80static void properties_item(gpointer attribute((unused)) callback_data,
81 guint attribute((unused)) callback_action,
82 GtkWidget attribute((unused)) *menu_item) {
83 GtkWidget *tab = gtk_notebook_get_nth_page
84 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
85 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
86
87 t->properties_activate(tab);
88}
89
73f1b9f3
RK
90/** @brief Called when the login option is activated */
91static void login(gpointer attribute((unused)) callback_data,
92 guint attribute((unused)) callback_action,
93 GtkWidget attribute((unused)) *menu_item) {
94 login_box();
95}
96
ffc4dbaf
RK
97/** @brief Called when the login option is activated */
98static void users(gpointer attribute((unused)) callback_data,
99 guint attribute((unused)) callback_action,
100 GtkWidget attribute((unused)) *menu_item) {
101 manage_users();
102}
103
46fb1b05
RK
104#if 0
105/** @brief Called when the settings option is activated */
106static void settings(gpointer attribute((unused)) callback_data,
107 guint attribute((unused)) callback_action,
108 GtkWidget attribute((unused)) *menu_item) {
109 popup_settings();
110}
111#endif
112
2c348789
RK
113/** @brief Update menu state
114 *
115 * Determines option sensitivity according to the current tab and adjusts the
116 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
117 * need not.
118 */
460b9539 119void menu_update(int page) {
120 GtkWidget *tab = gtk_notebook_get_nth_page
121 (GTK_NOTEBOOK(tabs),
122 page < 0 ? gtk_notebook_current_page(GTK_NOTEBOOK(tabs)) : page);
123 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
124
125 assert(t != 0);
126 gtk_widget_set_sensitive(properties_widget,
e836b1aa 127 (t->properties_sensitive(tab)
8f763f1b 128 && (disorder_eclient_state(client) & DISORDER_CONNECTED)));
460b9539 129 gtk_widget_set_sensitive(selectall_widget,
130 t->selectall_sensitive(tab));
fb009628
RK
131 gtk_widget_set_sensitive(selectnone_widget,
132 t->selectnone_sensitive(tab));
460b9539 133}
2c348789
RK
134
135/** @brief Fetch version in order to display the about... popup */
460b9539 136static void about_popup(gpointer attribute((unused)) callback_data,
137 guint attribute((unused)) callback_action,
138 GtkWidget attribute((unused)) *menu_item) {
139 D(("about_popup"));
140
141 gtk_label_set_text(GTK_LABEL(report_label), "getting server version");
142 disorder_eclient_version(client,
143 about_popup_got_version,
144 0);
145}
146
13affe66
RK
147static void manual_popup(gpointer attribute((unused)) callback_data,
148 guint attribute((unused)) callback_action,
149 GtkWidget attribute((unused)) *menu_item) {
150 D(("manual_popup"));
151
152 popup_help();
153}
154
883a4e96 155/** @brief Called when version arrives, displays about... popup */
460b9539 156static void about_popup_got_version(void attribute((unused)) *v,
157 const char *value) {
158 GtkWidget *w;
159 char *server_version_string;
54cca6d6 160 char *short_version_string;
413b30a4 161 GtkWidget *hbox, *vbox, *title;
460b9539 162
163 byte_xasprintf(&server_version_string, "Server version %s", value);
54cca6d6
RK
164 byte_xasprintf(&short_version_string, "Disobedience %s",
165 disorder_short_version_string);
413b30a4 166 w = gtk_dialog_new_with_buttons("About Disobedience",
460b9539 167 GTK_WINDOW(toplevel),
168 (GTK_DIALOG_MODAL
169 |GTK_DIALOG_DESTROY_WITH_PARENT),
170 GTK_STOCK_OK,
171 GTK_RESPONSE_ACCEPT,
172 (char *)NULL);
413b30a4
RK
173 hbox = gtk_hbox_new(FALSE/*homogeneous*/, 1/*padding*/);
174 vbox = gtk_vbox_new(FALSE/*homogeneous*/, 1/*padding*/);
175 gtk_box_pack_start(GTK_BOX(hbox),
176 gtk_image_new_from_pixbuf(find_image("duck.png")),
177 FALSE/*expand*/,
178 FALSE/*fill*/,
179 4/*padding*/);
180 gtk_box_pack_start(GTK_BOX(vbox),
54cca6d6 181 gtk_label_new(short_version_string),
413b30a4
RK
182 FALSE/*expand*/,
183 FALSE/*fill*/,
184 1/*padding*/);
185 gtk_box_pack_start(GTK_BOX(vbox),
186 gtk_label_new(server_version_string),
187 FALSE/*expand*/,
188 FALSE/*fill*/,
189 1/*padding*/);
190 gtk_box_pack_start(GTK_BOX(vbox),
8f9616f1 191 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
413b30a4
RK
192 FALSE/*expand*/,
193 FALSE/*fill*/,
194 1/*padding*/);
195 gtk_box_pack_end(GTK_BOX(hbox),
196 vbox,
197 FALSE/*expand*/,
198 FALSE/*fill*/,
199 0/*padding*/);
200 title = gtk_label_new(0);
201 gtk_label_set_markup(GTK_LABEL(title),
202 "<span font_desc=\"Sans 36\">Disobedience</span>");
203 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), title,
204 FALSE/*expand*/,
205 FALSE/*fill*/,
206 0/*padding*/);
207 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), hbox,
208 FALSE/*expand*/,
209 FALSE/*fill*/,
210 0/*padding*/);
76fc02c5 211 set_tool_colors(w);
460b9539 212 gtk_widget_show_all(w);
213 gtk_dialog_run(GTK_DIALOG(w));
214 gtk_widget_destroy(w);
215}
216
c73bd6c1
RK
217/** @brief Set 'Manage Users' menu item sensitivity */
218void users_set_sensitive(int sensitive) {
219 GtkWidget *w = gtk_item_factory_get_widget(mainmenufactory,
220 "<GdisorderMain>/Server/Manage users");
221 gtk_widget_set_sensitive(w, sensitive);
222}
223
224/** @brief Called with current user's rights string */
225static void menu_got_rights(void attribute((unused)) *v, const char *value) {
226 rights_type r;
227
228 if(parse_rights(value, &r, 0))
229 r = 0;
230 users_set_sensitive(!!(r & RIGHT_ADMIN));
231}
232
233/** @brief Called when we need to reset state */
234static void menu_reset(void) {
235 users_set_sensitive(0); /* until we know better */
236 disorder_eclient_userinfo(client, menu_got_rights, config->username, "rights",
237 0);
238}
239
2c348789 240/** @brief Create the menu bar widget */
460b9539 241GtkWidget *menubar(GtkWidget *w) {
d4ef4132
RK
242 GtkWidget *m;
243
460b9539 244 static const GtkItemFactoryEntry entries[] = {
2d504956 245 {
eb80584d 246 (char *)"/Server", /* path */
2d504956
RK
247 0, /* accelerator */
248 0, /* callback */
249 0, /* callback_action */
250 (char *)"<Branch>", /* item_type */
251 0 /* extra_data */
252 },
253 {
eb80584d 254 (char *)"/Server/Login", /* path */
2d504956
RK
255 (char *)"<CTRL>L", /* accelerator */
256 login, /* callback */
257 0, /* callback_action */
258 0, /* item_type */
259 0 /* extra_data */
260 },
ffc4dbaf 261 {
eb80584d 262 (char *)"/Server/Manage users", /* path */
ffc4dbaf
RK
263 0, /* accelerator */
264 users, /* callback */
265 0, /* callback_action */
266 0, /* item_type */
267 0 /* extra_data */
268 },
46fb1b05
RK
269#if 0
270 {
eb80584d 271 (char *)"/Server/Settings", /* path */
46fb1b05
RK
272 0, /* accelerator */
273 settings, /* callback */
274 0, /* callback_action */
275 0, /* item_type */
276 0 /* extra_data */
277 },
278#endif
2d504956 279 {
eb80584d 280 (char *)"/Server/Quit Disobedience", /* path */
2d504956
RK
281 (char *)"<CTRL>Q", /* accelerator */
282 quit_program, /* callback */
283 0, /* callback_action */
284 (char *)"<StockItem>", /* item_type */
285 GTK_STOCK_QUIT /* extra_data */
286 },
ac6bf2ba 287
2d504956
RK
288 {
289 (char *)"/Edit", /* path */
290 0, /* accelerator */
291 0, /* callback */
292 0, /* callback_action */
293 (char *)"<Branch>", /* item_type */
294 0 /* extra_data */
295 },
296 {
297 (char *)"/Edit/Select all tracks", /* path */
298 (char *)"<CTRL>A", /* accelerator */
299 select_all, /* callback */
300 0, /* callback_action */
301 0, /* item_type */
302 0 /* extra_data */
303 },
304 {
fb009628
RK
305 (char *)"/Edit/Deselect all tracks", /* path */
306 (char *)"<CTRL><SHIFT>A", /* accelerator */
307 select_none, /* callback */
308 0, /* callback_action */
309 0, /* item_type */
310 0 /* extra_data */
311 },
312 {
2d504956
RK
313 (char *)"/Edit/Track properties", /* path */
314 0, /* accelerator */
315 properties_item, /* callback */
316 0, /* callback_action */
317 0, /* item_type */
318 0 /* extra_data */
319 },
320
321 {
322 (char *)"/Control", /* path */
323 0, /* accelerator */
324 0, /* callback */
325 0, /* callback_action */
326 (char *)"<Branch>", /* item_type */
327 0 /* extra_data */
328 },
329 {
330 (char *)"/Control/Scratch", /* path */
331 (char *)"<CTRL>S", /* accelerator */
332 0, /* callback */
333 0, /* callback_action */
334 0, /* item_type */
335 0 /* extra_data */
336 },
337 {
685bdfbd
RK
338 (char *)"/Control/Playing", /* path */
339 (char *)"<CTRL>P", /* accelerator */
340 0, /* callback */
341 0, /* callback_action */
342 (char *)"<CheckItem>", /* item_type */
343 0 /* extra_data */
344 },
345 {
2d504956
RK
346 (char *)"/Control/Random play", /* path */
347 (char *)"<CTRL>R", /* accelerator */
348 0, /* callback */
685bdfbd
RK
349 0, /* callback_action */
350 (char *)"<CheckItem>", /* item_type */
351 0 /* extra_data */
352 },
353 {
354 (char *)"/Control/Network player", /* path */
355 (char *)"<CTRL>N", /* accelerator */
356 0, /* callback */
2d504956
RK
357 0, /* callback_action */
358 (char *)"<CheckItem>", /* item_type */
359 0 /* extra_data */
360 },
361
362 {
363 (char *)"/Help", /* path */
364 0, /* accelerator */
365 0, /* callback */
366 0, /* callback_action */
367 (char *)"<Branch>", /* item_type */
368 0 /* extra_data */
369 },
370 {
13affe66
RK
371 (char *)"/Help/Manual page", /* path */
372 0, /* accelerator */
373 manual_popup, /* callback */
374 0, /* callback_action */
375 0, /* item_type */
376 0 /* extra_data */
377 },
378 {
2d504956
RK
379 (char *)"/Help/About DisOrder", /* path */
380 0, /* accelerator */
381 about_popup, /* callback */
382 0, /* callback_action */
383 (char *)"<StockItem>", /* item_type */
384 GTK_STOCK_ABOUT /* extra_data */
385 },
460b9539 386 };
387
460b9539 388 GtkAccelGroup *accel = gtk_accel_group_new();
389
390 D(("add_menubar"));
391 /* TODO: item factories are deprecated in favour of some XML thing */
ac6bf2ba
RK
392 mainmenufactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
393 accel);
394 gtk_item_factory_create_items(mainmenufactory,
460b9539 395 sizeof entries / sizeof *entries,
396 (GtkItemFactoryEntry *)entries,
397 0);
398 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
ac6bf2ba 399 selectall_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 400 "<GdisorderMain>/Edit/Select all tracks");
fb009628
RK
401 selectnone_widget = gtk_item_factory_get_widget(mainmenufactory,
402 "<GdisorderMain>/Edit/Deselect all tracks");
ac6bf2ba 403 properties_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 404 "<GdisorderMain>/Edit/Track properties");
460b9539 405 assert(selectall_widget != 0);
fb009628 406 assert(selectnone_widget != 0);
460b9539 407 assert(properties_widget != 0);
c73bd6c1
RK
408 register_reset(menu_reset);
409 menu_reset();
d4ef4132
RK
410 m = gtk_item_factory_get_widget(mainmenufactory,
411 "<GdisorderMain>");
412 set_tool_colors(m);
413 return m;
460b9539 414}
415
416/*
417Local Variables:
418c-basic-offset:2
419comment-column:40
420fill-column:79
421indent-tabs-mode:nil
422End:
423*/