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, const char *value);
35 /** @brief Called when the quit option is activated
39 static void quit_program(gpointer attribute((unused)) callback_data,
40 guint attribute((unused)) callback_action,
41 GtkWidget attribute((unused)) *menu_item) {
46 /* TODO can we have a single parameterized callback for all these */
48 /** @brief Called when the select all option is activated
50 * Calls the per-tab select all function.
52 static void select_all(gpointer attribute((unused)) callback_data,
53 guint attribute((unused)) callback_action,
54 GtkWidget attribute((unused)) *menu_item) {
55 GtkWidget *tab = gtk_notebook_get_nth_page
56 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
57 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
59 t->selectall_activate(tab);
62 /** @brief Called when the select none option is activated
64 * Calls the per-tab select none function.
66 static void select_none(gpointer attribute((unused)) callback_data,
67 guint attribute((unused)) callback_action,
68 GtkWidget attribute((unused)) *menu_item) {
69 GtkWidget *tab = gtk_notebook_get_nth_page
70 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
71 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
73 t->selectnone_activate(tab);
76 /** @brief Called when the track properties option is activated
78 * Calls the per-tab properties function.
80 static void properties_item(gpointer attribute((unused)) callback_data,
81 guint attribute((unused)) callback_action,
82 GtkWidget attribute((unused)) *menu_item) {
83 GtkWidget *tab = gtk_notebook_get_nth_page
84 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
85 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
87 t->properties_activate(tab);
90 /** @brief Called when the login option is activated */
91 static void login(gpointer attribute((unused)) callback_data,
92 guint attribute((unused)) callback_action,
93 GtkWidget attribute((unused)) *menu_item) {
97 /** @brief Called when the login option is activated */
98 static void users(gpointer attribute((unused)) callback_data,
99 guint attribute((unused)) callback_action,
100 GtkWidget attribute((unused)) *menu_item) {
105 /** @brief Called when the settings option is activated */
106 static void settings(gpointer attribute((unused)) callback_data,
107 guint attribute((unused)) callback_action,
108 GtkWidget attribute((unused)) *menu_item) {
113 /** @brief Update menu state
115 * Determines option sensitivity according to the current tab and adjusts the
116 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
119 void menu_update(int page) {
120 GtkWidget *tab = gtk_notebook_get_nth_page
122 page < 0 ? gtk_notebook_current_page(GTK_NOTEBOOK(tabs)) : page);
123 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
126 gtk_widget_set_sensitive(properties_widget,
127 (t->properties_sensitive(tab)
128 && (disorder_eclient_state(client) & DISORDER_CONNECTED)));
129 gtk_widget_set_sensitive(selectall_widget,
130 t->selectall_sensitive(tab));
131 gtk_widget_set_sensitive(selectnone_widget,
132 t->selectnone_sensitive(tab));
135 /** @brief Fetch version in order to display the about... popup */
136 static void about_popup(gpointer attribute((unused)) callback_data,
137 guint attribute((unused)) callback_action,
138 GtkWidget attribute((unused)) *menu_item) {
141 gtk_label_set_text(GTK_LABEL(report_label), "getting server version");
142 disorder_eclient_version(client,
143 about_popup_got_version,
147 static void manual_popup(gpointer attribute((unused)) callback_data,
148 guint attribute((unused)) callback_action,
149 GtkWidget attribute((unused)) *menu_item) {
155 /** @brief Called when version arrives, displays about... popup */
156 static void about_popup_got_version(void attribute((unused)) *v,
159 char *server_version_string;
160 char *short_version_string;
161 GtkWidget *hbox, *vbox, *title;
163 byte_xasprintf(&server_version_string, "Server version %s", value);
164 byte_xasprintf(&short_version_string, "Disobedience %s",
165 disorder_short_version_string);
166 w = gtk_dialog_new_with_buttons("About Disobedience",
167 GTK_WINDOW(toplevel),
169 |GTK_DIALOG_DESTROY_WITH_PARENT),
173 hbox = gtk_hbox_new(FALSE/*homogeneous*/, 1/*padding*/);
174 vbox = gtk_vbox_new(FALSE/*homogeneous*/, 1/*padding*/);
175 gtk_box_pack_start(GTK_BOX(hbox),
176 gtk_image_new_from_pixbuf(find_image("duck.png")),
180 gtk_box_pack_start(GTK_BOX(vbox),
181 gtk_label_new(short_version_string),
185 gtk_box_pack_start(GTK_BOX(vbox),
186 gtk_label_new(server_version_string),
190 gtk_box_pack_start(GTK_BOX(vbox),
191 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
195 gtk_box_pack_end(GTK_BOX(hbox),
200 title = gtk_label_new(0);
201 gtk_label_set_markup(GTK_LABEL(title),
202 "<span font_desc=\"Sans 36\">Disobedience</span>");
203 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), title,
207 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), hbox,
212 gtk_widget_show_all(w);
213 gtk_dialog_run(GTK_DIALOG(w));
214 gtk_widget_destroy(w);
217 /** @brief Create the menu bar widget */
218 GtkWidget *menubar(GtkWidget *w) {
221 static const GtkItemFactoryEntry entries[] = {
223 (char *)"/File", /* path */
226 0, /* callback_action */
227 (char *)"<Branch>", /* item_type */
231 (char *)"/File/Login", /* path */
232 (char *)"<CTRL>L", /* accelerator */
233 login, /* callback */
234 0, /* callback_action */
239 (char *)"/File/Users", /* path */
241 users, /* callback */
242 0, /* callback_action */
248 (char *)"/File/Settings", /* path */
250 settings, /* callback */
251 0, /* callback_action */
257 (char *)"/File/Quit Disobedience", /* path */
258 (char *)"<CTRL>Q", /* accelerator */
259 quit_program, /* callback */
260 0, /* callback_action */
261 (char *)"<StockItem>", /* item_type */
262 GTK_STOCK_QUIT /* extra_data */
266 (char *)"/Edit", /* path */
269 0, /* callback_action */
270 (char *)"<Branch>", /* item_type */
274 (char *)"/Edit/Select all tracks", /* path */
275 (char *)"<CTRL>A", /* accelerator */
276 select_all, /* callback */
277 0, /* callback_action */
282 (char *)"/Edit/Deselect all tracks", /* path */
283 (char *)"<CTRL><SHIFT>A", /* accelerator */
284 select_none, /* callback */
285 0, /* callback_action */
290 (char *)"/Edit/Track properties", /* path */
292 properties_item, /* callback */
293 0, /* callback_action */
299 (char *)"/Control", /* path */
302 0, /* callback_action */
303 (char *)"<Branch>", /* item_type */
307 (char *)"/Control/Scratch", /* path */
308 (char *)"<CTRL>S", /* accelerator */
310 0, /* callback_action */
315 (char *)"/Control/Playing", /* path */
316 (char *)"<CTRL>P", /* accelerator */
318 0, /* callback_action */
319 (char *)"<CheckItem>", /* item_type */
323 (char *)"/Control/Random play", /* path */
324 (char *)"<CTRL>R", /* accelerator */
326 0, /* callback_action */
327 (char *)"<CheckItem>", /* item_type */
331 (char *)"/Control/Network player", /* path */
332 (char *)"<CTRL>N", /* accelerator */
334 0, /* callback_action */
335 (char *)"<CheckItem>", /* item_type */
340 (char *)"/Help", /* path */
343 0, /* callback_action */
344 (char *)"<Branch>", /* item_type */
348 (char *)"/Help/Manual page", /* path */
350 manual_popup, /* callback */
351 0, /* callback_action */
356 (char *)"/Help/About DisOrder", /* path */
358 about_popup, /* callback */
359 0, /* callback_action */
360 (char *)"<StockItem>", /* item_type */
361 GTK_STOCK_ABOUT /* extra_data */
365 GtkAccelGroup *accel = gtk_accel_group_new();
368 /* TODO: item factories are deprecated in favour of some XML thing */
369 mainmenufactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
371 gtk_item_factory_create_items(mainmenufactory,
372 sizeof entries / sizeof *entries,
373 (GtkItemFactoryEntry *)entries,
375 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
376 selectall_widget = gtk_item_factory_get_widget(mainmenufactory,
377 "<GdisorderMain>/Edit/Select all tracks");
378 selectnone_widget = gtk_item_factory_get_widget(mainmenufactory,
379 "<GdisorderMain>/Edit/Deselect all tracks");
380 properties_widget = gtk_item_factory_get_widget(mainmenufactory,
381 "<GdisorderMain>/Edit/Track properties");
382 assert(selectall_widget != 0);
383 assert(selectnone_widget != 0);
384 assert(properties_widget != 0);
385 m = gtk_item_factory_get_widget(mainmenufactory,