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 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU 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, see <http://www.gnu.org/licenses/>.
18 /** @file disobedience/menu.c
22 #include "disobedience.h"
24 static GtkWidget
*selectall_widget
;
25 static GtkWidget
*selectnone_widget
;
26 static GtkWidget
*properties_widget
;
28 GtkWidget
*playlists_widget
;
29 GtkWidget
*playlists_menu
;
30 GtkWidget
*editplaylists_widget
;
33 /** @brief Main menu widgets */
34 GtkItemFactory
*mainmenufactory
;
36 static void about_popup_got_version(void *v
,
40 /** @brief Called when the quit option is activated
44 static void quit_program(gpointer
attribute((unused
)) callback_data
,
45 guint
attribute((unused
)) callback_action
,
46 GtkWidget
attribute((unused
)) *menu_item
) {
51 /** @brief Called when an edit menu item is selected
53 * Shared by several menu items; callback_action is expected to be the offset
54 * of the activate member of struct tabtype.
56 static void menu_tab_action(gpointer
attribute((unused
)) callback_data
,
57 guint callback_action
,
58 GtkWidget
attribute((unused
)) *menu_item
) {
59 GtkWidget
*tab
= gtk_notebook_get_nth_page
60 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
61 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
63 void (**activatep
)(GtkMenuItem
*, gpointer
)
64 = (void *)((const char *)t
+ callback_action
);
65 void (*activate
)(GtkMenuItem
*, gpointer
) = *activatep
;
68 activate(NULL
, t
->extra
);
71 /** @brief Called when the login option is activated */
72 static void login(gpointer
attribute((unused
)) callback_data
,
73 guint
attribute((unused
)) callback_action
,
74 GtkWidget
attribute((unused
)) *menu_item
) {
78 /** @brief Called when the login option is activated */
79 static void users(gpointer
attribute((unused
)) callback_data
,
80 guint
attribute((unused
)) callback_action
,
81 GtkWidget
attribute((unused
)) *menu_item
) {
86 /** @brief Called when the settings option is activated */
87 static void settings(gpointer
attribute((unused
)) callback_data
,
88 guint
attribute((unused
)) callback_action
,
89 GtkWidget
attribute((unused
)) *menu_item
) {
94 /** @brief Called when edit menu is shown
96 * Determines option sensitivity according to the current tab and adjusts the
97 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
100 static void edit_menu_show(GtkWidget
attribute((unused
)) *widget
,
101 gpointer
attribute((unused
)) user_data
) {
103 GtkWidget
*tab
= gtk_notebook_get_nth_page
105 gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
106 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
109 gtk_widget_set_sensitive(properties_widget
,
110 (t
->properties_sensitive
111 && t
->properties_sensitive(t
->extra
)
112 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
113 gtk_widget_set_sensitive(selectall_widget
,
114 t
->selectall_sensitive
115 && t
->selectall_sensitive(t
->extra
));
116 gtk_widget_set_sensitive(selectnone_widget
,
117 t
->selectnone_sensitive
118 && t
->selectnone_sensitive(t
->extra
));
122 /** @brief Fetch version in order to display the about... popup */
123 static void about_popup(gpointer
attribute((unused
)) callback_data
,
124 guint
attribute((unused
)) callback_action
,
125 GtkWidget
attribute((unused
)) *menu_item
) {
128 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
129 disorder_eclient_version(client
,
130 about_popup_got_version
,
134 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
135 guint
attribute((unused
)) callback_action
,
136 GtkWidget
attribute((unused
)) *menu_item
) {
142 /** @brief Called when version arrives, displays about... popup */
143 static void about_popup_got_version(void attribute((unused
)) *v
,
144 const char attribute((unused
)) *err
,
147 char *server_version_string
;
148 char *short_version_string
;
149 GtkWidget
*hbox
, *vbox
, *title
;
153 byte_xasprintf(&server_version_string
, "Server version %s", value
);
154 byte_xasprintf(&short_version_string
, "Disobedience %s",
155 disorder_short_version_string
);
156 w
= gtk_dialog_new_with_buttons("About Disobedience",
157 GTK_WINDOW(toplevel
),
159 |GTK_DIALOG_DESTROY_WITH_PARENT
),
163 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
164 vbox
= gtk_vbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
165 gtk_box_pack_start(GTK_BOX(hbox
),
166 gtk_image_new_from_pixbuf(find_image("duck.png")),
170 gtk_box_pack_start(GTK_BOX(vbox
),
171 gtk_label_new(short_version_string
),
175 gtk_box_pack_start(GTK_BOX(vbox
),
176 gtk_label_new(server_version_string
),
180 gtk_box_pack_start(GTK_BOX(vbox
),
181 gtk_label_new("\xC2\xA9 2004-2009 Richard Kettlewell"),
185 gtk_box_pack_end(GTK_BOX(hbox
),
190 title
= gtk_label_new(0);
191 gtk_label_set_markup(GTK_LABEL(title
),
192 "<span font_desc=\"Sans 36\">Disobedience</span>");
193 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), title
,
197 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), hbox
,
202 gtk_widget_show_all(w
);
203 gtk_dialog_run(GTK_DIALOG(w
));
204 gtk_widget_destroy(w
);
207 /** @brief Set 'Manage Users' menu item sensitivity */
208 void users_set_sensitive(int sensitive
) {
209 GtkWidget
*w
= gtk_item_factory_get_widget(mainmenufactory
,
210 "<GdisorderMain>/Server/Manage users");
211 gtk_widget_set_sensitive(w
, sensitive
);
214 /** @brief Called when our rights change */
215 static void menu_rights_changed(const char attribute((unused
)) *event
,
216 void attribute((unused
)) *eventdata
,
217 void attribute((unused
)) *callbackdata
) {
218 users_set_sensitive(!!(last_rights
& RIGHT_ADMIN
));
221 /** @brief Create the menu bar widget */
222 GtkWidget
*menubar(GtkWidget
*w
) {
225 static const GtkItemFactoryEntry entries
[] = {
227 (char *)"/Server", /* path */
230 0, /* callback_action */
231 (char *)"<Branch>", /* item_type */
235 (char *)"/Server/Login", /* path */
236 (char *)"<CTRL>L", /* accelerator */
237 login
, /* callback */
238 0, /* callback_action */
243 (char *)"/Server/Manage users", /* path */
245 users
, /* callback */
246 0, /* callback_action */
252 (char *)"/Server/Settings", /* path */
254 settings
, /* callback */
255 0, /* callback_action */
261 (char *)"/Server/Quit Disobedience", /* path */
262 (char *)"<CTRL>Q", /* accelerator */
263 quit_program
, /* callback */
264 0, /* callback_action */
265 (char *)"<StockItem>", /* item_type */
266 GTK_STOCK_QUIT
/* extra_data */
270 (char *)"/Edit", /* path */
273 0, /* callback_action */
274 (char *)"<Branch>", /* item_type */
278 (char *)"/Edit/Select all tracks", /* path */
280 menu_tab_action
, /* callback */
281 offsetof(struct tabtype
, selectall_activate
), /* callback_action */
286 (char *)"/Edit/Deselect all tracks", /* path */
288 menu_tab_action
, /* callback */
289 offsetof(struct tabtype
, selectnone_activate
), /* callback_action */
294 (char *)"/Edit/Track properties", /* path */
296 menu_tab_action
, /* callback */
297 offsetof(struct tabtype
, properties_activate
), /* callback_action */
303 (char *)"/Edit/Edit playlists", /* path */
305 edit_playlists
, /* callback */
306 0, /* callback_action */
314 (char *)"/Control", /* path */
317 0, /* callback_action */
318 (char *)"<Branch>", /* item_type */
322 (char *)"/Control/Scratch", /* path */
323 (char *)"<CTRL>S", /* accelerator */
325 0, /* callback_action */
330 (char *)"/Control/Playing", /* path */
331 (char *)"<CTRL>P", /* accelerator */
333 0, /* callback_action */
334 (char *)"<CheckItem>", /* item_type */
338 (char *)"/Control/Random play", /* path */
339 (char *)"<CTRL>R", /* accelerator */
341 0, /* callback_action */
342 (char *)"<CheckItem>", /* item_type */
346 (char *)"/Control/Network player", /* path */
347 (char *)"<CTRL>N", /* accelerator */
349 0, /* callback_action */
350 (char *)"<CheckItem>", /* item_type */
355 (char *)"/Control/Activate playlist", /* path */
358 0, /* callback_action */
359 (char *)"<Branch>", /* item_type */
365 (char *)"/Help", /* path */
368 0, /* callback_action */
369 (char *)"<Branch>", /* item_type */
373 (char *)"/Help/Manual page", /* path */
375 manual_popup
, /* callback */
376 0, /* callback_action */
381 (char *)"/Help/About DisOrder", /* path */
383 about_popup
, /* callback */
384 0, /* callback_action */
385 (char *)"<StockItem>", /* item_type */
386 GTK_STOCK_ABOUT
/* extra_data */
390 GtkAccelGroup
*accel
= gtk_accel_group_new();
393 /* TODO: item factories are deprecated in favour of some XML thing */
394 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
396 gtk_item_factory_create_items(mainmenufactory
,
397 sizeof entries
/ sizeof *entries
,
398 (GtkItemFactoryEntry
*)entries
,
400 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
401 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
402 "<GdisorderMain>/Edit/Select all tracks");
403 selectnone_widget
= gtk_item_factory_get_widget(mainmenufactory
,
404 "<GdisorderMain>/Edit/Deselect all tracks");
405 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
406 "<GdisorderMain>/Edit/Track properties");
408 playlists_widget
= gtk_item_factory_get_item(mainmenufactory
,
409 "<GdisorderMain>/Control/Activate playlist");
410 playlists_menu
= gtk_item_factory_get_widget(mainmenufactory
,
411 "<GdisorderMain>/Control/Activate playlist");
412 editplaylists_widget
= gtk_item_factory_get_widget(mainmenufactory
,
413 "<GdisorderMain>/Edit/Edit playlists");
415 assert(selectall_widget
!= 0);
416 assert(selectnone_widget
!= 0);
417 assert(properties_widget
!= 0);
419 assert(playlists_widget
!= 0);
420 assert(playlists_menu
!= 0);
421 assert(editplaylists_widget
!= 0);
424 GtkWidget
*edit_widget
= gtk_item_factory_get_widget(mainmenufactory
,
425 "<GdisorderMain>/Edit");
426 g_signal_connect(edit_widget
, "show", G_CALLBACK(edit_menu_show
), 0);
428 event_register("rights-changed", menu_rights_changed
, 0);
429 users_set_sensitive(0);
430 m
= gtk_item_factory_get_widget(mainmenufactory
,