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
;
29 GtkWidget
*playlists_widget
;
30 GtkWidget
*playlists_menu
;
32 /** @brief Main menu widgets */
33 GtkItemFactory
*mainmenufactory
;
35 static void about_popup_got_version(void *v
,
39 /** @brief Called when the quit option is activated
43 static void quit_program(gpointer
attribute((unused
)) callback_data
,
44 guint
attribute((unused
)) callback_action
,
45 GtkWidget
attribute((unused
)) *menu_item
) {
50 /** @brief Called when an edit menu item is selected
52 * Shared by several menu items; callback_action is expected to be the offset
53 * of the activate member of struct tabtype.
55 static void menu_tab_action(gpointer
attribute((unused
)) callback_data
,
56 guint callback_action
,
57 GtkWidget
attribute((unused
)) *menu_item
) {
58 GtkWidget
*tab
= gtk_notebook_get_nth_page
59 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
60 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
62 void (**activatep
)(GtkMenuItem
*, gpointer
)
63 = (void *)((const char *)t
+ callback_action
);
64 void (*activate
)(GtkMenuItem
*, gpointer
) = *activatep
;
67 activate(NULL
, t
->extra
);
70 /** @brief Called when the login option is activated */
71 static void login(gpointer
attribute((unused
)) callback_data
,
72 guint
attribute((unused
)) callback_action
,
73 GtkWidget
attribute((unused
)) *menu_item
) {
77 /** @brief Called when the login option is activated */
78 static void users(gpointer
attribute((unused
)) callback_data
,
79 guint
attribute((unused
)) callback_action
,
80 GtkWidget
attribute((unused
)) *menu_item
) {
85 /** @brief Called when the settings option is activated */
86 static void settings(gpointer
attribute((unused
)) callback_data
,
87 guint
attribute((unused
)) callback_action
,
88 GtkWidget
attribute((unused
)) *menu_item
) {
93 /** @brief Called when edit menu is shown
95 * Determines option sensitivity according to the current tab and adjusts the
96 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
99 static void edit_menu_show(GtkWidget
attribute((unused
)) *widget
,
100 gpointer
attribute((unused
)) user_data
) {
102 GtkWidget
*tab
= gtk_notebook_get_nth_page
104 gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
105 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
108 gtk_widget_set_sensitive(properties_widget
,
109 (t
->properties_sensitive
110 && t
->properties_sensitive(t
->extra
)
111 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
112 gtk_widget_set_sensitive(selectall_widget
,
113 t
->selectall_sensitive
114 && t
->selectall_sensitive(t
->extra
));
115 gtk_widget_set_sensitive(selectnone_widget
,
116 t
->selectnone_sensitive
117 && t
->selectnone_sensitive(t
->extra
));
121 /** @brief Fetch version in order to display the about... popup */
122 static void about_popup(gpointer
attribute((unused
)) callback_data
,
123 guint
attribute((unused
)) callback_action
,
124 GtkWidget
attribute((unused
)) *menu_item
) {
127 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
128 disorder_eclient_version(client
,
129 about_popup_got_version
,
133 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
134 guint
attribute((unused
)) callback_action
,
135 GtkWidget
attribute((unused
)) *menu_item
) {
141 /** @brief Called when version arrives, displays about... popup */
142 static void about_popup_got_version(void attribute((unused
)) *v
,
143 const char attribute((unused
)) *err
,
146 char *server_version_string
;
147 char *short_version_string
;
148 GtkWidget
*hbox
, *vbox
, *title
;
152 byte_xasprintf(&server_version_string
, "Server version %s", value
);
153 byte_xasprintf(&short_version_string
, "Disobedience %s",
154 disorder_short_version_string
);
155 w
= gtk_dialog_new_with_buttons("About Disobedience",
156 GTK_WINDOW(toplevel
),
158 |GTK_DIALOG_DESTROY_WITH_PARENT
),
162 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
163 vbox
= gtk_vbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
164 gtk_box_pack_start(GTK_BOX(hbox
),
165 gtk_image_new_from_pixbuf(find_image("duck.png")),
169 gtk_box_pack_start(GTK_BOX(vbox
),
170 gtk_label_new(short_version_string
),
174 gtk_box_pack_start(GTK_BOX(vbox
),
175 gtk_label_new(server_version_string
),
179 gtk_box_pack_start(GTK_BOX(vbox
),
180 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
184 gtk_box_pack_end(GTK_BOX(hbox
),
189 title
= gtk_label_new(0);
190 gtk_label_set_markup(GTK_LABEL(title
),
191 "<span font_desc=\"Sans 36\">Disobedience</span>");
192 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), title
,
196 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), hbox
,
201 gtk_widget_show_all(w
);
202 gtk_dialog_run(GTK_DIALOG(w
));
203 gtk_widget_destroy(w
);
206 /** @brief Set 'Manage Users' menu item sensitivity */
207 void users_set_sensitive(int sensitive
) {
208 GtkWidget
*w
= gtk_item_factory_get_widget(mainmenufactory
,
209 "<GdisorderMain>/Server/Manage users");
210 gtk_widget_set_sensitive(w
, sensitive
);
213 /** @brief Called when our rights change */
214 static void menu_rights_changed(const char attribute((unused
)) *event
,
215 void attribute((unused
)) *eventdata
,
216 void attribute((unused
)) *callbackdata
) {
217 users_set_sensitive(!!(last_rights
& RIGHT_ADMIN
));
220 /** @brief Create the menu bar widget */
221 GtkWidget
*menubar(GtkWidget
*w
) {
224 static const GtkItemFactoryEntry entries
[] = {
226 (char *)"/Server", /* path */
229 0, /* callback_action */
230 (char *)"<Branch>", /* item_type */
234 (char *)"/Server/Login", /* path */
235 (char *)"<CTRL>L", /* accelerator */
236 login
, /* callback */
237 0, /* callback_action */
242 (char *)"/Server/Manage users", /* path */
244 users
, /* callback */
245 0, /* callback_action */
251 (char *)"/Server/Settings", /* path */
253 settings
, /* callback */
254 0, /* callback_action */
260 (char *)"/Server/Quit Disobedience", /* path */
261 (char *)"<CTRL>Q", /* accelerator */
262 quit_program
, /* callback */
263 0, /* callback_action */
264 (char *)"<StockItem>", /* item_type */
265 GTK_STOCK_QUIT
/* extra_data */
269 (char *)"/Edit", /* path */
272 0, /* callback_action */
273 (char *)"<Branch>", /* item_type */
277 (char *)"/Edit/Select all tracks", /* path */
279 menu_tab_action
, /* callback */
280 offsetof(struct tabtype
, selectall_activate
), /* callback_action */
285 (char *)"/Edit/Deselect all tracks", /* path */
287 menu_tab_action
, /* callback */
288 offsetof(struct tabtype
, selectnone_activate
), /* callback_action */
293 (char *)"/Edit/Track properties", /* path */
295 menu_tab_action
, /* callback */
296 offsetof(struct tabtype
, properties_activate
), /* callback_action */
301 (char *)"/Edit/Edit playlists", /* path */
303 edit_playlists
, /* callback */
304 0, /* callback_action */
311 (char *)"/Control", /* path */
314 0, /* callback_action */
315 (char *)"<Branch>", /* item_type */
319 (char *)"/Control/Scratch", /* path */
320 (char *)"<CTRL>S", /* accelerator */
322 0, /* callback_action */
327 (char *)"/Control/Playing", /* path */
328 (char *)"<CTRL>P", /* accelerator */
330 0, /* callback_action */
331 (char *)"<CheckItem>", /* item_type */
335 (char *)"/Control/Random play", /* path */
336 (char *)"<CTRL>R", /* accelerator */
338 0, /* callback_action */
339 (char *)"<CheckItem>", /* item_type */
343 (char *)"/Control/Network player", /* path */
344 (char *)"<CTRL>N", /* accelerator */
346 0, /* callback_action */
347 (char *)"<CheckItem>", /* item_type */
351 (char *)"/Control/Activate playlist", /* path */
354 0, /* callback_action */
355 (char *)"<Branch>", /* item_type */
360 (char *)"/Help", /* path */
363 0, /* callback_action */
364 (char *)"<Branch>", /* item_type */
368 (char *)"/Help/Manual page", /* path */
370 manual_popup
, /* callback */
371 0, /* callback_action */
376 (char *)"/Help/About DisOrder", /* path */
378 about_popup
, /* callback */
379 0, /* callback_action */
380 (char *)"<StockItem>", /* item_type */
381 GTK_STOCK_ABOUT
/* extra_data */
385 GtkAccelGroup
*accel
= gtk_accel_group_new();
388 /* TODO: item factories are deprecated in favour of some XML thing */
389 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
391 gtk_item_factory_create_items(mainmenufactory
,
392 sizeof entries
/ sizeof *entries
,
393 (GtkItemFactoryEntry
*)entries
,
395 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
396 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
397 "<GdisorderMain>/Edit/Select all tracks");
398 selectnone_widget
= gtk_item_factory_get_widget(mainmenufactory
,
399 "<GdisorderMain>/Edit/Deselect all tracks");
400 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
401 "<GdisorderMain>/Edit/Track properties");
402 playlists_widget
= gtk_item_factory_get_item(mainmenufactory
,
403 "<GdisorderMain>/Control/Activate playlist");
404 playlists_menu
= gtk_item_factory_get_widget(mainmenufactory
,
405 "<GdisorderMain>/Control/Activate playlist");
406 assert(selectall_widget
!= 0);
407 assert(selectnone_widget
!= 0);
408 assert(properties_widget
!= 0);
409 assert(playlists_widget
!= 0);
410 assert(playlists_menu
!= 0);
412 GtkWidget
*edit_widget
= gtk_item_factory_get_widget(mainmenufactory
,
413 "<GdisorderMain>/Edit");
414 g_signal_connect(edit_widget
, "show", G_CALLBACK(edit_menu_show
), 0);
416 event_register("rights-changed", menu_rights_changed
, 0);
417 users_set_sensitive(0);
418 m
= gtk_item_factory_get_widget(mainmenufactory
,