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 /** @brief Called when an edit menu item is selected
50 * Shared by several menu items; callback_action is expected to be the offset
51 * of the activate member of struct tabtype.
53 static void menu_tab_action(gpointer
attribute((unused
)) callback_data
,
54 guint callback_action
,
55 GtkWidget
attribute((unused
)) *menu_item
) {
56 GtkWidget
*tab
= gtk_notebook_get_nth_page
57 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
58 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
60 void (**activatep
)(GtkMenuItem
*, gpointer
)
61 = (void *)((const char *)t
+ callback_action
);
62 void (*activate
)(GtkMenuItem
*, gpointer
) = *activatep
;
65 activate(NULL
, t
->extra
);
68 /** @brief Called when the login option is activated */
69 static void login(gpointer
attribute((unused
)) callback_data
,
70 guint
attribute((unused
)) callback_action
,
71 GtkWidget
attribute((unused
)) *menu_item
) {
75 /** @brief Called when the login option is activated */
76 static void users(gpointer
attribute((unused
)) callback_data
,
77 guint
attribute((unused
)) callback_action
,
78 GtkWidget
attribute((unused
)) *menu_item
) {
83 /** @brief Called when the settings option is activated */
84 static void settings(gpointer
attribute((unused
)) callback_data
,
85 guint
attribute((unused
)) callback_action
,
86 GtkWidget
attribute((unused
)) *menu_item
) {
91 /** @brief Called when edit menu is shown
93 * Determines option sensitivity according to the current tab and adjusts the
94 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
97 static void edit_menu_show(GtkWidget
attribute((unused
)) *widget
,
98 gpointer
attribute((unused
)) user_data
) {
100 GtkWidget
*tab
= gtk_notebook_get_nth_page
102 gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
103 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
106 gtk_widget_set_sensitive(properties_widget
,
107 (t
->properties_sensitive
108 && t
->properties_sensitive(t
->extra
)
109 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
110 gtk_widget_set_sensitive(selectall_widget
,
111 t
->selectall_sensitive
112 && t
->selectall_sensitive(t
->extra
));
113 gtk_widget_set_sensitive(selectnone_widget
,
114 t
->selectnone_sensitive
115 && t
->selectnone_sensitive(t
->extra
));
119 /** @brief Fetch version in order to display the about... popup */
120 static void about_popup(gpointer
attribute((unused
)) callback_data
,
121 guint
attribute((unused
)) callback_action
,
122 GtkWidget
attribute((unused
)) *menu_item
) {
125 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
126 disorder_eclient_version(client
,
127 about_popup_got_version
,
131 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
132 guint
attribute((unused
)) callback_action
,
133 GtkWidget
attribute((unused
)) *menu_item
) {
139 /** @brief Called when version arrives, displays about... popup */
140 static void about_popup_got_version(void attribute((unused
)) *v
,
141 const char attribute((unused
)) *err
,
144 char *server_version_string
;
145 char *short_version_string
;
146 GtkWidget
*hbox
, *vbox
, *title
;
150 byte_xasprintf(&server_version_string
, "Server version %s", value
);
151 byte_xasprintf(&short_version_string
, "Disobedience %s",
152 disorder_short_version_string
);
153 w
= gtk_dialog_new_with_buttons("About Disobedience",
154 GTK_WINDOW(toplevel
),
156 |GTK_DIALOG_DESTROY_WITH_PARENT
),
160 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
161 vbox
= gtk_vbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
162 gtk_box_pack_start(GTK_BOX(hbox
),
163 gtk_image_new_from_pixbuf(find_image("duck.png")),
167 gtk_box_pack_start(GTK_BOX(vbox
),
168 gtk_label_new(short_version_string
),
172 gtk_box_pack_start(GTK_BOX(vbox
),
173 gtk_label_new(server_version_string
),
177 gtk_box_pack_start(GTK_BOX(vbox
),
178 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
182 gtk_box_pack_end(GTK_BOX(hbox
),
187 title
= gtk_label_new(0);
188 gtk_label_set_markup(GTK_LABEL(title
),
189 "<span font_desc=\"Sans 36\">Disobedience</span>");
190 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), title
,
194 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), hbox
,
199 gtk_widget_show_all(w
);
200 gtk_dialog_run(GTK_DIALOG(w
));
201 gtk_widget_destroy(w
);
204 /** @brief Set 'Manage Users' menu item sensitivity */
205 void users_set_sensitive(int sensitive
) {
206 GtkWidget
*w
= gtk_item_factory_get_widget(mainmenufactory
,
207 "<GdisorderMain>/Server/Manage users");
208 gtk_widget_set_sensitive(w
, sensitive
);
211 /** @brief Called when our rights change */
212 static void menu_rights_changed(const char attribute((unused
)) *event
,
213 void attribute((unused
)) *eventdata
,
214 void attribute((unused
)) *callbackdata
) {
215 users_set_sensitive(!!(last_rights
& RIGHT_ADMIN
));
218 /** @brief Create the menu bar widget */
219 GtkWidget
*menubar(GtkWidget
*w
) {
222 static const GtkItemFactoryEntry entries
[] = {
224 (char *)"/Server", /* path */
227 0, /* callback_action */
228 (char *)"<Branch>", /* item_type */
232 (char *)"/Server/Login", /* path */
233 (char *)"<CTRL>L", /* accelerator */
234 login
, /* callback */
235 0, /* callback_action */
240 (char *)"/Server/Manage users", /* path */
242 users
, /* callback */
243 0, /* callback_action */
249 (char *)"/Server/Settings", /* path */
251 settings
, /* callback */
252 0, /* callback_action */
258 (char *)"/Server/Quit Disobedience", /* path */
259 (char *)"<CTRL>Q", /* accelerator */
260 quit_program
, /* callback */
261 0, /* callback_action */
262 (char *)"<StockItem>", /* item_type */
263 GTK_STOCK_QUIT
/* extra_data */
267 (char *)"/Edit", /* path */
270 0, /* callback_action */
271 (char *)"<Branch>", /* item_type */
275 (char *)"/Edit/Select all tracks", /* path */
277 menu_tab_action
, /* callback */
278 offsetof(struct tabtype
, selectall_activate
), /* callback_action */
283 (char *)"/Edit/Deselect all tracks", /* path */
285 menu_tab_action
, /* callback */
286 offsetof(struct tabtype
, selectnone_activate
), /* callback_action */
291 (char *)"/Edit/Track properties", /* path */
293 menu_tab_action
, /* callback */
294 offsetof(struct tabtype
, properties_activate
), /* callback_action */
300 (char *)"/Control", /* path */
303 0, /* callback_action */
304 (char *)"<Branch>", /* item_type */
308 (char *)"/Control/Scratch", /* path */
309 (char *)"<CTRL>S", /* accelerator */
311 0, /* callback_action */
316 (char *)"/Control/Playing", /* path */
317 (char *)"<CTRL>P", /* accelerator */
319 0, /* callback_action */
320 (char *)"<CheckItem>", /* item_type */
324 (char *)"/Control/Random play", /* path */
325 (char *)"<CTRL>R", /* accelerator */
327 0, /* callback_action */
328 (char *)"<CheckItem>", /* item_type */
332 (char *)"/Control/Network player", /* path */
333 (char *)"<CTRL>N", /* accelerator */
335 0, /* callback_action */
336 (char *)"<CheckItem>", /* item_type */
341 (char *)"/Help", /* path */
344 0, /* callback_action */
345 (char *)"<Branch>", /* item_type */
349 (char *)"/Help/Manual page", /* path */
351 manual_popup
, /* callback */
352 0, /* callback_action */
357 (char *)"/Help/About DisOrder", /* path */
359 about_popup
, /* callback */
360 0, /* callback_action */
361 (char *)"<StockItem>", /* item_type */
362 GTK_STOCK_ABOUT
/* extra_data */
366 GtkAccelGroup
*accel
= gtk_accel_group_new();
369 /* TODO: item factories are deprecated in favour of some XML thing */
370 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
372 gtk_item_factory_create_items(mainmenufactory
,
373 sizeof entries
/ sizeof *entries
,
374 (GtkItemFactoryEntry
*)entries
,
376 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
377 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
378 "<GdisorderMain>/Edit/Select all tracks");
379 selectnone_widget
= gtk_item_factory_get_widget(mainmenufactory
,
380 "<GdisorderMain>/Edit/Deselect all tracks");
381 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
382 "<GdisorderMain>/Edit/Track properties");
383 assert(selectall_widget
!= 0);
384 assert(selectnone_widget
!= 0);
385 assert(properties_widget
!= 0);
388 GtkWidget
*edit_widget
= gtk_item_factory_get_widget(mainmenufactory
,
389 "<GdisorderMain>/Edit");
390 g_signal_connect(edit_widget
, "show", G_CALLBACK(edit_menu_show
), 0);
392 event_register("rights-changed", menu_rights_changed
, 0);
393 users_set_sensitive(0);
394 m
= gtk_item_factory_get_widget(mainmenufactory
,