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 /** @file disobedience/menu.c
24 #include "disobedience.h"
26 static GtkWidget
*selectall_widget
;
27 static GtkWidget
*selectnone_widget
;
28 static GtkWidget
*properties_widget
;
30 /** @brief Main menu widgets */
31 GtkItemFactory
*mainmenufactory
;
33 static void about_popup_got_version(void *v
,
37 /** @brief Called when the quit option is activated
41 static void quit_program(gpointer
attribute((unused
)) callback_data
,
42 guint
attribute((unused
)) callback_action
,
43 GtkWidget
attribute((unused
)) *menu_item
) {
48 /* TODO can we have a single parameterized callback for all these */
50 /** @brief Called when the select all option is activated
52 * Calls the per-tab select all function.
54 static void select_all(gpointer
attribute((unused
)) callback_data
,
55 guint
attribute((unused
)) callback_action
,
56 GtkWidget
attribute((unused
)) *menu_item
) {
57 GtkWidget
*tab
= gtk_notebook_get_nth_page
58 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
59 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
61 t
->selectall_activate(tab
);
64 /** @brief Called when the select none option is activated
66 * Calls the per-tab select none function.
68 static void select_none(gpointer
attribute((unused
)) callback_data
,
69 guint
attribute((unused
)) callback_action
,
70 GtkWidget
attribute((unused
)) *menu_item
) {
71 GtkWidget
*tab
= gtk_notebook_get_nth_page
72 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
73 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
75 t
->selectnone_activate(tab
);
78 /** @brief Called when the track properties option is activated
80 * Calls the per-tab properties function.
82 static void properties_item(gpointer
attribute((unused
)) callback_data
,
83 guint
attribute((unused
)) callback_action
,
84 GtkWidget
attribute((unused
)) *menu_item
) {
85 GtkWidget
*tab
= gtk_notebook_get_nth_page
86 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
87 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
89 t
->properties_activate(tab
);
92 /** @brief Called when the login option is activated */
93 static void login(gpointer
attribute((unused
)) callback_data
,
94 guint
attribute((unused
)) callback_action
,
95 GtkWidget
attribute((unused
)) *menu_item
) {
99 /** @brief Called when the login option is activated */
100 static void users(gpointer
attribute((unused
)) callback_data
,
101 guint
attribute((unused
)) callback_action
,
102 GtkWidget
attribute((unused
)) *menu_item
) {
107 /** @brief Called when the settings option is activated */
108 static void settings(gpointer
attribute((unused
)) callback_data
,
109 guint
attribute((unused
)) callback_action
,
110 GtkWidget
attribute((unused
)) *menu_item
) {
115 /** @brief Update menu state
117 * Determines option sensitivity according to the current tab and adjusts the
118 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
121 void menu_update(int page
) {
123 GtkWidget
*tab
= gtk_notebook_get_nth_page
125 page
< 0 ?
gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)) : page
);
126 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
129 gtk_widget_set_sensitive(properties_widget
,
130 (t
->properties_sensitive(tab
)
131 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
132 gtk_widget_set_sensitive(selectall_widget
,
133 t
->selectall_sensitive(tab
));
134 gtk_widget_set_sensitive(selectnone_widget
,
135 t
->selectnone_sensitive(tab
));
139 /** @brief Fetch version in order to display the about... popup */
140 static void about_popup(gpointer
attribute((unused
)) callback_data
,
141 guint
attribute((unused
)) callback_action
,
142 GtkWidget
attribute((unused
)) *menu_item
) {
145 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
146 disorder_eclient_version(client
,
147 about_popup_got_version
,
151 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
152 guint
attribute((unused
)) callback_action
,
153 GtkWidget
attribute((unused
)) *menu_item
) {
159 /** @brief Called when version arrives, displays about... popup */
160 static void about_popup_got_version(void attribute((unused
)) *v
,
161 const char attribute((unused
)) *error
,
164 char *server_version_string
;
165 char *short_version_string
;
166 GtkWidget
*hbox
, *vbox
, *title
;
170 byte_xasprintf(&server_version_string
, "Server version %s", value
);
171 byte_xasprintf(&short_version_string
, "Disobedience %s",
172 disorder_short_version_string
);
173 w
= gtk_dialog_new_with_buttons("About Disobedience",
174 GTK_WINDOW(toplevel
),
176 |GTK_DIALOG_DESTROY_WITH_PARENT
),
180 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
181 vbox
= gtk_vbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
182 gtk_box_pack_start(GTK_BOX(hbox
),
183 gtk_image_new_from_pixbuf(find_image("duck.png")),
187 gtk_box_pack_start(GTK_BOX(vbox
),
188 gtk_label_new(short_version_string
),
192 gtk_box_pack_start(GTK_BOX(vbox
),
193 gtk_label_new(server_version_string
),
197 gtk_box_pack_start(GTK_BOX(vbox
),
198 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
202 gtk_box_pack_end(GTK_BOX(hbox
),
207 title
= gtk_label_new(0);
208 gtk_label_set_markup(GTK_LABEL(title
),
209 "<span font_desc=\"Sans 36\">Disobedience</span>");
210 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), title
,
214 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), hbox
,
219 gtk_widget_show_all(w
);
220 gtk_dialog_run(GTK_DIALOG(w
));
221 gtk_widget_destroy(w
);
224 /** @brief Set 'Manage Users' menu item sensitivity */
225 void users_set_sensitive(int sensitive
) {
226 GtkWidget
*w
= gtk_item_factory_get_widget(mainmenufactory
,
227 "<GdisorderMain>/Server/Manage users");
228 gtk_widget_set_sensitive(w
, sensitive
);
231 /** @brief Called with current user's rights string */
232 static void menu_got_rights(void attribute((unused
)) *v
,
238 popup_protocol_error(0, error
);
241 if(parse_rights(value
, &r
, 0))
244 users_set_sensitive(!!(r
& RIGHT_ADMIN
));
247 /** @brief Called after a fresh login */
248 static void menu_logged_in(const char attribute((unused
)) *event
,
249 void attribute((unused
)) *eventdata
,
250 void attribute((unused
)) *callbackdata
) {
251 users_set_sensitive(0); /* until we know better */
252 disorder_eclient_userinfo(client
, menu_got_rights
, config
->username
, "rights",
256 /** @brief Create the menu bar widget */
257 GtkWidget
*menubar(GtkWidget
*w
) {
260 static const GtkItemFactoryEntry entries
[] = {
262 (char *)"/Server", /* path */
265 0, /* callback_action */
266 (char *)"<Branch>", /* item_type */
270 (char *)"/Server/Login", /* path */
271 (char *)"<CTRL>L", /* accelerator */
272 login
, /* callback */
273 0, /* callback_action */
278 (char *)"/Server/Manage users", /* path */
280 users
, /* callback */
281 0, /* callback_action */
287 (char *)"/Server/Settings", /* path */
289 settings
, /* callback */
290 0, /* callback_action */
296 (char *)"/Server/Quit Disobedience", /* path */
297 (char *)"<CTRL>Q", /* accelerator */
298 quit_program
, /* callback */
299 0, /* callback_action */
300 (char *)"<StockItem>", /* item_type */
301 GTK_STOCK_QUIT
/* extra_data */
305 (char *)"/Edit", /* path */
308 0, /* callback_action */
309 (char *)"<Branch>", /* item_type */
313 (char *)"/Edit/Select all tracks", /* path */
314 (char *)"<CTRL>A", /* accelerator */
315 select_all
, /* callback */
316 0, /* callback_action */
321 (char *)"/Edit/Deselect all tracks", /* path */
322 (char *)"<CTRL><SHIFT>A", /* accelerator */
323 select_none
, /* callback */
324 0, /* callback_action */
329 (char *)"/Edit/Track properties", /* path */
331 properties_item
, /* callback */
332 0, /* callback_action */
338 (char *)"/Control", /* path */
341 0, /* callback_action */
342 (char *)"<Branch>", /* item_type */
346 (char *)"/Control/Scratch", /* path */
347 (char *)"<CTRL>S", /* accelerator */
349 0, /* callback_action */
354 (char *)"/Control/Playing", /* path */
355 (char *)"<CTRL>P", /* accelerator */
357 0, /* callback_action */
358 (char *)"<CheckItem>", /* item_type */
362 (char *)"/Control/Random play", /* path */
363 (char *)"<CTRL>R", /* accelerator */
365 0, /* callback_action */
366 (char *)"<CheckItem>", /* item_type */
370 (char *)"/Control/Network player", /* path */
371 (char *)"<CTRL>N", /* accelerator */
373 0, /* callback_action */
374 (char *)"<CheckItem>", /* item_type */
379 (char *)"/Help", /* path */
382 0, /* callback_action */
383 (char *)"<Branch>", /* item_type */
387 (char *)"/Help/Manual page", /* path */
389 manual_popup
, /* callback */
390 0, /* callback_action */
395 (char *)"/Help/About DisOrder", /* path */
397 about_popup
, /* callback */
398 0, /* callback_action */
399 (char *)"<StockItem>", /* item_type */
400 GTK_STOCK_ABOUT
/* extra_data */
404 GtkAccelGroup
*accel
= gtk_accel_group_new();
407 /* TODO: item factories are deprecated in favour of some XML thing */
408 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
410 gtk_item_factory_create_items(mainmenufactory
,
411 sizeof entries
/ sizeof *entries
,
412 (GtkItemFactoryEntry
*)entries
,
414 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
415 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
416 "<GdisorderMain>/Edit/Select all tracks");
417 selectnone_widget
= gtk_item_factory_get_widget(mainmenufactory
,
418 "<GdisorderMain>/Edit/Deselect all tracks");
419 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
420 "<GdisorderMain>/Edit/Track properties");
421 assert(selectall_widget
!= 0);
422 assert(selectnone_widget
!= 0);
423 assert(properties_widget
!= 0);
424 event_register("logged-in", menu_logged_in
, 0);
425 menu_logged_in(0, 0, 0);
426 m
= gtk_item_factory_get_widget(mainmenufactory
,