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 void toggled_minimode(GtkCheckMenuItem
*item
, gpointer userdata
);
26 static GtkWidget
*selectall_widget
;
27 static GtkWidget
*selectnone_widget
;
28 static GtkWidget
*properties_widget
;
29 GtkWidget
*menu_playlists_widget
;
30 GtkWidget
*playlists_menu
;
31 GtkWidget
*menu_editplaylists_widget
;
32 static GtkWidget
*menu_minimode_widget
;
34 /** @brief Main menu widgets */
35 GtkItemFactory
*mainmenufactory
;
37 /** @brief Set for full mode, clear for mini mode */
40 static void about_popup_got_version(void *v
,
44 /** @brief Called when the quit option is activated
48 static void quit_program(gpointer
attribute((unused
)) callback_data
,
49 guint
attribute((unused
)) callback_action
,
50 GtkWidget
attribute((unused
)) *menu_item
) {
55 /** @brief Called when an edit menu item is selected
57 * Shared by several menu items; callback_action is expected to be the offset
58 * of the activate member of struct tabtype.
60 static void menu_tab_action(gpointer
attribute((unused
)) callback_data
,
61 guint callback_action
,
62 GtkWidget
attribute((unused
)) *menu_item
) {
63 GtkWidget
*tab
= gtk_notebook_get_nth_page
64 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
65 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
67 void (**activatep
)(GtkMenuItem
*, gpointer
)
68 = (void *)((const char *)t
+ callback_action
);
69 void (*activate
)(GtkMenuItem
*, gpointer
) = *activatep
;
72 activate(NULL
, t
->extra
);
75 /** @brief Called when the login option is activated */
76 static void login(gpointer
attribute((unused
)) callback_data
,
77 guint
attribute((unused
)) callback_action
,
78 GtkWidget
attribute((unused
)) *menu_item
) {
82 /** @brief Called when the login option is activated */
83 static void users(gpointer
attribute((unused
)) callback_data
,
84 guint
attribute((unused
)) callback_action
,
85 GtkWidget
attribute((unused
)) *menu_item
) {
90 /** @brief Called when the settings option is activated */
91 static void settings(gpointer
attribute((unused
)) callback_data
,
92 guint
attribute((unused
)) callback_action
,
93 GtkWidget
attribute((unused
)) *menu_item
) {
98 /** @brief Called when edit menu is shown
100 * Determines option sensitivity according to the current tab and adjusts the
101 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
104 static void edit_menu_show(GtkWidget
attribute((unused
)) *widget
,
105 gpointer
attribute((unused
)) user_data
) {
107 GtkWidget
*tab
= gtk_notebook_get_nth_page
109 gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
110 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
113 gtk_widget_set_sensitive(properties_widget
,
114 (t
->properties_sensitive
115 && t
->properties_sensitive(t
->extra
)
116 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
117 gtk_widget_set_sensitive(selectall_widget
,
118 t
->selectall_sensitive
119 && t
->selectall_sensitive(t
->extra
));
120 gtk_widget_set_sensitive(selectnone_widget
,
121 t
->selectnone_sensitive
122 && t
->selectnone_sensitive(t
->extra
));
126 /** @brief Fetch version in order to display the about... popup */
127 static void about_popup(gpointer
attribute((unused
)) callback_data
,
128 guint
attribute((unused
)) callback_action
,
129 GtkWidget
attribute((unused
)) *menu_item
) {
132 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
133 disorder_eclient_version(client
,
134 about_popup_got_version
,
138 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
139 guint
attribute((unused
)) callback_action
,
140 GtkWidget
attribute((unused
)) *menu_item
) {
146 /** @brief Called when version arrives, displays about... popup */
147 static void about_popup_got_version(void attribute((unused
)) *v
,
148 const char attribute((unused
)) *err
,
151 char *server_version_string
;
152 char *short_version_string
;
153 GtkWidget
*hbox
, *vbox
, *title
;
157 byte_xasprintf(&server_version_string
, "Server version %s", value
);
158 byte_xasprintf(&short_version_string
, "Disobedience %s",
159 disorder_short_version_string
);
160 w
= gtk_dialog_new_with_buttons("About Disobedience",
161 GTK_WINDOW(toplevel
),
163 |GTK_DIALOG_DESTROY_WITH_PARENT
),
167 hbox
= gtk_hbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
168 vbox
= gtk_vbox_new(FALSE
/*homogeneous*/, 1/*padding*/);
169 gtk_box_pack_start(GTK_BOX(hbox
),
170 gtk_image_new_from_pixbuf(find_image("duck.png")),
174 gtk_box_pack_start(GTK_BOX(vbox
),
175 gtk_label_new(short_version_string
),
179 gtk_box_pack_start(GTK_BOX(vbox
),
180 gtk_label_new(server_version_string
),
184 gtk_box_pack_start(GTK_BOX(vbox
),
185 gtk_label_new("\xC2\xA9 2004-2009 Richard Kettlewell"),
189 gtk_box_pack_end(GTK_BOX(hbox
),
194 title
= gtk_label_new(0);
195 gtk_label_set_markup(GTK_LABEL(title
),
196 "<span font_desc=\"Sans 36\">Disobedience</span>");
197 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), title
,
201 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w
)->vbox
), hbox
,
206 gtk_widget_show_all(w
);
207 gtk_dialog_run(GTK_DIALOG(w
));
208 gtk_widget_destroy(w
);
211 /** @brief Set 'Manage Users' menu item sensitivity */
212 void users_set_sensitive(int sensitive
) {
213 GtkWidget
*w
= gtk_item_factory_get_widget(mainmenufactory
,
214 "<GdisorderMain>/Server/Manage users");
215 gtk_widget_set_sensitive(w
, sensitive
);
218 /** @brief Called when our rights change */
219 static void menu_rights_changed(const char attribute((unused
)) *event
,
220 void attribute((unused
)) *eventdata
,
221 void attribute((unused
)) *callbackdata
) {
222 users_set_sensitive(!!(last_rights
& RIGHT_ADMIN
));
225 /** @brief Create the menu bar widget */
226 GtkWidget
*menubar(GtkWidget
*w
) {
229 static const GtkItemFactoryEntry entries
[] = {
231 (char *)"/Server", /* path */
234 0, /* callback_action */
235 (char *)"<Branch>", /* item_type */
239 (char *)"/Server/Login", /* path */
240 (char *)"<CTRL>L", /* accelerator */
241 login
, /* callback */
242 0, /* callback_action */
247 (char *)"/Server/Manage users", /* path */
249 users
, /* callback */
250 0, /* callback_action */
256 (char *)"/Server/Settings", /* path */
258 settings
, /* callback */
259 0, /* callback_action */
265 (char *)"/Server/Quit Disobedience", /* path */
266 (char *)"<CTRL>Q", /* accelerator */
267 quit_program
, /* callback */
268 0, /* callback_action */
269 (char *)"<StockItem>", /* item_type */
270 GTK_STOCK_QUIT
/* extra_data */
274 (char *)"/Edit", /* path */
277 0, /* callback_action */
278 (char *)"<Branch>", /* item_type */
282 (char *)"/Edit/Select all tracks", /* path */
283 (char *)"<CTRL>A", /* accelerator */
284 menu_tab_action
, /* callback */
285 offsetof(struct tabtype
, selectall_activate
), /* callback_action */
290 (char *)"/Edit/Deselect all tracks", /* path */
291 (char *)"<CTRL><SHIFT>A", /* accelerator */
292 menu_tab_action
, /* callback */
293 offsetof(struct tabtype
, selectnone_activate
), /* callback_action */
298 (char *)"/Edit/Track properties", /* path */
300 menu_tab_action
, /* callback */
301 offsetof(struct tabtype
, properties_activate
), /* callback_action */
306 (char *)"/Edit/Edit playlists", /* path */
308 playlist_window_create
, /* callback */
309 0, /* callback_action */
316 (char *)"/Control", /* path */
319 0, /* callback_action */
320 (char *)"<Branch>", /* item_type */
324 (char *)"/Control/Scratch", /* path */
325 (char *)"<CTRL>S", /* accelerator */
327 0, /* callback_action */
332 (char *)"/Control/Playing", /* path */
333 (char *)"<CTRL>P", /* accelerator */
335 0, /* callback_action */
336 (char *)"<CheckItem>", /* item_type */
340 (char *)"/Control/Random play", /* path */
341 (char *)"<CTRL>R", /* accelerator */
343 0, /* callback_action */
344 (char *)"<CheckItem>", /* item_type */
348 (char *)"/Control/Network player", /* path */
349 (char *)"<CTRL>N", /* accelerator */
351 0, /* callback_action */
352 (char *)"<CheckItem>", /* item_type */
357 (char *)"/Control/Compact mode", /* path */
358 (char *)"<CTRL>M", /* accelerator */
360 0, /* callback_action */
361 (char *)"<CheckItem>", /* item_type */
366 (char *)"/Control/Activate playlist", /* path */
369 0, /* callback_action */
370 (char *)"<Branch>", /* item_type */
375 (char *)"/Help", /* path */
378 0, /* callback_action */
379 (char *)"<Branch>", /* item_type */
383 (char *)"/Help/Manual", /* path */
385 manual_popup
, /* callback */
386 0, /* callback_action */
391 (char *)"/Help/About DisOrder", /* path */
393 about_popup
, /* callback */
394 0, /* callback_action */
395 (char *)"<StockItem>", /* item_type */
396 GTK_STOCK_ABOUT
/* extra_data */
400 GtkAccelGroup
*accel
= gtk_accel_group_new();
403 /* TODO: item factories are deprecated in favour of some XML thing */
404 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
406 gtk_item_factory_create_items(mainmenufactory
,
407 sizeof entries
/ sizeof *entries
,
408 (GtkItemFactoryEntry
*)entries
,
410 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
411 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
412 "<GdisorderMain>/Edit/Select all tracks");
413 selectnone_widget
= gtk_item_factory_get_widget(mainmenufactory
,
414 "<GdisorderMain>/Edit/Deselect all tracks");
415 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
416 "<GdisorderMain>/Edit/Track properties");
417 menu_playlists_widget
= gtk_item_factory_get_item(mainmenufactory
,
418 "<GdisorderMain>/Control/Activate playlist");
419 playlists_menu
= gtk_item_factory_get_widget(mainmenufactory
,
420 "<GdisorderMain>/Control/Activate playlist");
421 menu_editplaylists_widget
= gtk_item_factory_get_widget(mainmenufactory
,
422 "<GdisorderMain>/Edit/Edit playlists");
423 menu_minimode_widget
= gtk_item_factory_get_widget(mainmenufactory
,
424 "<GdisorderMain>/Control/Compact mode");
425 assert(selectall_widget
!= 0);
426 assert(selectnone_widget
!= 0);
427 assert(properties_widget
!= 0);
428 assert(menu_playlists_widget
!= 0);
429 assert(playlists_menu
!= 0);
430 assert(menu_editplaylists_widget
!= 0);
432 GtkWidget
*edit_widget
= gtk_item_factory_get_widget(mainmenufactory
,
433 "<GdisorderMain>/Edit");
434 g_signal_connect(edit_widget
, "show", G_CALLBACK(edit_menu_show
), 0);
436 event_register("rights-changed", menu_rights_changed
, 0);
437 users_set_sensitive(0);
438 m
= gtk_item_factory_get_widget(mainmenufactory
,
441 if(menu_minimode_widget
)
442 g_signal_connect(G_OBJECT(menu_minimode_widget
), "toggled",
443 G_CALLBACK(toggled_minimode
), NULL
);
447 static void toggled_minimode(GtkCheckMenuItem
*item
,
448 gpointer
attribute((unused
)) userdata
) {
449 int new_full_mode
= !gtk_check_menu_item_get_active(item
);
450 if(full_mode
!= new_full_mode
) {
451 full_mode
= new_full_mode
;
452 event_raise("mini-mode-changed", NULL
);