2 * This file is part of DisOrder.
3 * Copyright (C) 2006-2009 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
;
27 GtkWidget
*menu_playlists_widget
;
28 GtkWidget
*playlists_menu
;
29 GtkWidget
*menu_editplaylists_widget
;
31 /** @brief Main menu widgets */
32 GtkItemFactory
*mainmenufactory
;
34 static void about_popup_got_version(void *v
,
38 /** @brief Called when the quit option is activated
42 static void quit_program(gpointer
attribute((unused
)) callback_data
,
43 guint
attribute((unused
)) callback_action
,
44 GtkWidget
attribute((unused
)) *menu_item
) {
49 /** @brief Called when an edit menu item is selected
51 * Shared by several menu items; callback_action is expected to be the offset
52 * of the activate member of struct tabtype.
54 static void menu_tab_action(gpointer
attribute((unused
)) callback_data
,
55 guint 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 void (**activatep
)(GtkMenuItem
*, gpointer
)
62 = (void *)((const char *)t
+ callback_action
);
63 void (*activate
)(GtkMenuItem
*, gpointer
) = *activatep
;
66 activate(NULL
, t
->extra
);
69 /** @brief Called when the login option is activated */
70 static void login(gpointer
attribute((unused
)) callback_data
,
71 guint
attribute((unused
)) callback_action
,
72 GtkWidget
attribute((unused
)) *menu_item
) {
76 /** @brief Called when the login option is activated */
77 static void users(gpointer
attribute((unused
)) callback_data
,
78 guint
attribute((unused
)) callback_action
,
79 GtkWidget
attribute((unused
)) *menu_item
) {
84 /** @brief Called when the settings option is activated */
85 static void settings(gpointer
attribute((unused
)) callback_data
,
86 guint
attribute((unused
)) callback_action
,
87 GtkWidget
attribute((unused
)) *menu_item
) {
92 /** @brief Called when edit menu is shown
94 * Determines option sensitivity according to the current tab and adjusts the
95 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
98 static void edit_menu_show(GtkWidget
attribute((unused
)) *widget
,
99 gpointer
attribute((unused
)) user_data
) {
101 GtkWidget
*tab
= gtk_notebook_get_nth_page
103 gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
104 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
107 gtk_widget_set_sensitive(properties_widget
,
108 (t
->properties_sensitive
109 && t
->properties_sensitive(t
->extra
)
110 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
111 gtk_widget_set_sensitive(selectall_widget
,
112 t
->selectall_sensitive
113 && t
->selectall_sensitive(t
->extra
));
114 gtk_widget_set_sensitive(selectnone_widget
,
115 t
->selectnone_sensitive
116 && t
->selectnone_sensitive(t
->extra
));
120 /** @brief Fetch version in order to display the about... popup */
121 static void about_popup(gpointer
attribute((unused
)) callback_data
,
122 guint
attribute((unused
)) callback_action
,
123 GtkWidget
attribute((unused
)) *menu_item
) {
126 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
127 disorder_eclient_version(client
,
128 about_popup_got_version
,
132 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
133 guint
attribute((unused
)) callback_action
,
134 GtkWidget
attribute((unused
)) *menu_item
) {
140 /** @brief Called when version arrives, displays about... popup */
141 static void about_popup_got_version(void attribute((unused
)) *v
,
142 const char attribute((unused
)) *err
,
145 char *server_version_string
;
146 char *short_version_string
;
147 GtkWidget
*hbox
, *vbox
, *title
;
151 byte_xasprintf(&server_version_string
, "Server version %s", value
);
152 byte_xasprintf(&short_version_string
, "Disobedience %s",
153 disorder_short_version_string
);
154 w
= gtk_dialog_new_with_buttons("About Disobedience",
155 GTK_WINDOW(toplevel
),
157 |GTK_DIALOG_DESTROY_WITH_PARENT
),
161 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
162 vbox
= gtk_vbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
163 gtk_box_pack_start(GTK_BOX(hbox
),
164 gtk_image_new_from_pixbuf(find_image("duck.png")),
168 gtk_box_pack_start(GTK_BOX(vbox
),
169 gtk_label_new(short_version_string
),
173 gtk_box_pack_start(GTK_BOX(vbox
),
174 gtk_label_new(server_version_string
),
178 gtk_box_pack_start(GTK_BOX(vbox
),
179 gtk_label_new("\xC2\xA9 2004-2009 Richard Kettlewell"),
183 gtk_box_pack_end(GTK_BOX(hbox
),
188 title
= gtk_label_new(0);
189 gtk_label_set_markup(GTK_LABEL(title
),
190 "<span font_desc=\"Sans 36\">Disobedience</span>");
191 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), title
,
195 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), hbox
,
200 gtk_widget_show_all(w
);
201 gtk_dialog_run(GTK_DIALOG(w
));
202 gtk_widget_destroy(w
);
205 /** @brief Set 'Manage Users' menu item sensitivity */
206 void users_set_sensitive(int sensitive
) {
207 GtkWidget
*w
= gtk_item_factory_get_widget(mainmenufactory
,
208 "<GdisorderMain>/Server/Manage users");
209 gtk_widget_set_sensitive(w
, sensitive
);
212 /** @brief Called when our rights change */
213 static void menu_rights_changed(const char attribute((unused
)) *event
,
214 void attribute((unused
)) *eventdata
,
215 void attribute((unused
)) *callbackdata
) {
216 users_set_sensitive(!!(last_rights
& RIGHT_ADMIN
));
219 /** @brief Create the menu bar widget */
220 GtkWidget
*menubar(GtkWidget
*w
) {
223 static const GtkItemFactoryEntry entries
[] = {
225 (char *)"/Server", /* path */
228 0, /* callback_action */
229 (char *)"<Branch>", /* item_type */
233 (char *)"/Server/Login", /* path */
234 (char *)"<CTRL>L", /* accelerator */
235 login
, /* callback */
236 0, /* callback_action */
241 (char *)"/Server/Manage users", /* path */
243 users
, /* callback */
244 0, /* callback_action */
250 (char *)"/Server/Settings", /* path */
252 settings
, /* callback */
253 0, /* callback_action */
259 (char *)"/Server/Quit Disobedience", /* path */
260 (char *)"<CTRL>Q", /* accelerator */
261 quit_program
, /* callback */
262 0, /* callback_action */
263 (char *)"<StockItem>", /* item_type */
264 GTK_STOCK_QUIT
/* extra_data */
268 (char *)"/Edit", /* path */
271 0, /* callback_action */
272 (char *)"<Branch>", /* item_type */
276 (char *)"/Edit/Select all tracks", /* path */
277 (char *)"<CTRL>A", /* accelerator */
278 menu_tab_action
, /* callback */
279 offsetof(struct tabtype
, selectall_activate
), /* callback_action */
284 (char *)"/Edit/Deselect all tracks", /* path */
285 (char *)"<CTRL><SHIFT>A", /* accelerator */
286 menu_tab_action
, /* callback */
287 offsetof(struct tabtype
, selectnone_activate
), /* callback_action */
292 (char *)"/Edit/Track properties", /* path */
294 menu_tab_action
, /* callback */
295 offsetof(struct tabtype
, properties_activate
), /* callback_action */
300 (char *)"/Edit/Edit playlists", /* path */
302 playlist_window_create
, /* callback */
303 0, /* callback_action */
310 (char *)"/Control", /* path */
313 0, /* callback_action */
314 (char *)"<Branch>", /* item_type */
318 (char *)"/Control/Scratch", /* path */
319 (char *)"<CTRL>S", /* accelerator */
321 0, /* callback_action */
326 (char *)"/Control/Playing", /* path */
327 (char *)"<CTRL>P", /* accelerator */
329 0, /* callback_action */
330 (char *)"<CheckItem>", /* item_type */
334 (char *)"/Control/Random play", /* path */
335 (char *)"<CTRL>R", /* accelerator */
337 0, /* callback_action */
338 (char *)"<CheckItem>", /* item_type */
342 (char *)"/Control/Network player", /* path */
343 (char *)"<CTRL>N", /* accelerator */
345 0, /* callback_action */
346 (char *)"<CheckItem>", /* item_type */
350 (char *)"/Control/Activate playlist", /* path */
353 0, /* callback_action */
354 (char *)"<Branch>", /* item_type */
359 (char *)"/Help", /* path */
362 0, /* callback_action */
363 (char *)"<Branch>", /* item_type */
367 (char *)"/Help/Manual", /* path */
369 manual_popup
, /* callback */
370 0, /* callback_action */
375 (char *)"/Help/About DisOrder", /* path */
377 about_popup
, /* callback */
378 0, /* callback_action */
379 (char *)"<StockItem>", /* item_type */
380 GTK_STOCK_ABOUT
/* extra_data */
384 GtkAccelGroup
*accel
= gtk_accel_group_new();
387 /* TODO: item factories are deprecated in favour of some XML thing */
388 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
390 gtk_item_factory_create_items(mainmenufactory
,
391 sizeof entries
/ sizeof *entries
,
392 (GtkItemFactoryEntry
*)entries
,
394 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
395 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
396 "<GdisorderMain>/Edit/Select all tracks");
397 selectnone_widget
= gtk_item_factory_get_widget(mainmenufactory
,
398 "<GdisorderMain>/Edit/Deselect all tracks");
399 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
400 "<GdisorderMain>/Edit/Track properties");
401 menu_playlists_widget
= gtk_item_factory_get_item(mainmenufactory
,
402 "<GdisorderMain>/Control/Activate playlist");
403 playlists_menu
= gtk_item_factory_get_widget(mainmenufactory
,
404 "<GdisorderMain>/Control/Activate playlist");
405 menu_editplaylists_widget
= gtk_item_factory_get_widget(mainmenufactory
,
406 "<GdisorderMain>/Edit/Edit playlists");
407 assert(selectall_widget
!= 0);
408 assert(selectnone_widget
!= 0);
409 assert(properties_widget
!= 0);
410 assert(menu_playlists_widget
!= 0);
411 assert(playlists_menu
!= 0);
412 assert(menu_editplaylists_widget
!= 0);
414 GtkWidget
*edit_widget
= gtk_item_factory_get_widget(mainmenufactory
,
415 "<GdisorderMain>/Edit");
416 g_signal_connect(edit_widget
, "show", G_CALLBACK(edit_menu_show
), 0);
418 event_register("rights-changed", menu_rights_changed
, 0);
419 users_set_sensitive(0);
420 m
= gtk_item_factory_get_widget(mainmenufactory
,