2 * This file is part of DisOrder.
3 * Copyright (C) 2006, 2007 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
*properties_widget
;
29 /** @brief Main menu widgets */
30 GtkItemFactory
*mainmenufactory
;
32 static void about_popup_got_version(void *v
, const char *value
);
34 /** @brief Called when the quit option is activated
38 static void quit_program(gpointer
attribute((unused
)) callback_data
,
39 guint
attribute((unused
)) callback_action
,
40 GtkWidget
attribute((unused
)) *menu_item
) {
45 /* TODO can we have a single parameterized callback for all these */
47 /** @brief Called when the select all option is activated
49 * Calls the per-tab select all function.
51 static void select_all(gpointer
attribute((unused
)) callback_data
,
52 guint
attribute((unused
)) callback_action
,
53 GtkWidget
attribute((unused
)) *menu_item
) {
54 GtkWidget
*tab
= gtk_notebook_get_nth_page
55 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
56 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
58 t
->selectall_activate(tab
);
61 /** @brief Called when the track properties option is activated
63 * Calls the per-tab properties function.
65 static void properties_item(gpointer
attribute((unused
)) callback_data
,
66 guint
attribute((unused
)) callback_action
,
67 GtkWidget
attribute((unused
)) *menu_item
) {
68 GtkWidget
*tab
= gtk_notebook_get_nth_page
69 (GTK_NOTEBOOK(tabs
), gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)));
70 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
72 t
->properties_activate(tab
);
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 Update menu state
84 * Determines option sensitivity according to the current tab and adjusts the
85 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
88 void menu_update(int page
) {
89 GtkWidget
*tab
= gtk_notebook_get_nth_page
91 page
< 0 ?
gtk_notebook_current_page(GTK_NOTEBOOK(tabs
)) : page
);
92 const struct tabtype
*t
= g_object_get_data(G_OBJECT(tab
), "type");
95 gtk_widget_set_sensitive(properties_widget
,
96 (t
->properties_sensitive(tab
)
97 && (disorder_eclient_state(client
) & DISORDER_CONNECTED
)));
98 gtk_widget_set_sensitive(selectall_widget
,
99 t
->selectall_sensitive(tab
));
102 /** @brief Fetch version in order to display the about... popup */
103 static void about_popup(gpointer
attribute((unused
)) callback_data
,
104 guint
attribute((unused
)) callback_action
,
105 GtkWidget
attribute((unused
)) *menu_item
) {
108 gtk_label_set_text(GTK_LABEL(report_label
), "getting server version");
109 disorder_eclient_version(client
,
110 about_popup_got_version
,
114 static void manual_popup(gpointer
attribute((unused
)) callback_data
,
115 guint
attribute((unused
)) callback_action
,
116 GtkWidget
attribute((unused
)) *menu_item
) {
122 /** @brief Callde when version arrives, displays about... popup */
123 static void about_popup_got_version(void attribute((unused
)) *v
,
126 char *server_version_string
;
128 byte_xasprintf(&server_version_string
, "Server version %s", value
);
129 w
= gtk_dialog_new_with_buttons("About DisOrder",
130 GTK_WINDOW(toplevel
),
132 |GTK_DIALOG_DESTROY_WITH_PARENT
),
136 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w
)->vbox
),
137 gtk_label_new("DisOrder client " VERSION
));
138 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w
)->vbox
),
139 gtk_label_new(server_version_string
));
140 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w
)->vbox
),
141 gtk_label_new("(c) 2004-2007 Richard Kettlewell"));
142 gtk_widget_show_all(w
);
143 gtk_dialog_run(GTK_DIALOG(w
));
144 gtk_widget_destroy(w
);
147 /** @brief Create the menu bar widget */
148 GtkWidget
*menubar(GtkWidget
*w
) {
151 static const GtkItemFactoryEntry entries
[] = {
153 (char *)"/File", /* path */
156 0, /* callback_action */
157 (char *)"<Branch>", /* item_type */
161 (char *)"/File/Login", /* path */
162 (char *)"<CTRL>L", /* accelerator */
163 login
, /* callback */
164 0, /* callback_action */
169 (char *)"/File/Quit Disobedience", /* path */
170 (char *)"<CTRL>Q", /* accelerator */
171 quit_program
, /* callback */
172 0, /* callback_action */
173 (char *)"<StockItem>", /* item_type */
174 GTK_STOCK_QUIT
/* extra_data */
178 (char *)"/Edit", /* path */
181 0, /* callback_action */
182 (char *)"<Branch>", /* item_type */
186 (char *)"/Edit/Select all tracks", /* path */
187 (char *)"<CTRL>A", /* accelerator */
188 select_all
, /* callback */
189 0, /* callback_action */
194 (char *)"/Edit/Track properties", /* path */
196 properties_item
, /* callback */
197 0, /* callback_action */
203 (char *)"/Control", /* path */
206 0, /* callback_action */
207 (char *)"<Branch>", /* item_type */
211 (char *)"/Control/Scratch", /* path */
212 (char *)"<CTRL>S", /* accelerator */
214 0, /* callback_action */
219 (char *)"/Control/Playing", /* path */
220 (char *)"<CTRL>P", /* accelerator */
222 0, /* callback_action */
223 (char *)"<CheckItem>", /* item_type */
227 (char *)"/Control/Random play", /* path */
228 (char *)"<CTRL>R", /* accelerator */
230 0, /* callback_action */
231 (char *)"<CheckItem>", /* item_type */
235 (char *)"/Control/Network player", /* path */
236 (char *)"<CTRL>N", /* accelerator */
238 0, /* callback_action */
239 (char *)"<CheckItem>", /* item_type */
244 (char *)"/Help", /* path */
247 0, /* callback_action */
248 (char *)"<Branch>", /* item_type */
252 (char *)"/Help/Manual page", /* path */
254 manual_popup
, /* callback */
255 0, /* callback_action */
260 (char *)"/Help/About DisOrder", /* path */
262 about_popup
, /* callback */
263 0, /* callback_action */
264 (char *)"<StockItem>", /* item_type */
265 GTK_STOCK_ABOUT
/* extra_data */
269 GtkAccelGroup
*accel
= gtk_accel_group_new();
272 /* TODO: item factories are deprecated in favour of some XML thing */
273 mainmenufactory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, "<GdisorderMain>",
275 gtk_item_factory_create_items(mainmenufactory
,
276 sizeof entries
/ sizeof *entries
,
277 (GtkItemFactoryEntry
*)entries
,
279 gtk_window_add_accel_group(GTK_WINDOW(w
), accel
);
280 selectall_widget
= gtk_item_factory_get_widget(mainmenufactory
,
281 "<GdisorderMain>/Edit/Select all tracks");
282 properties_widget
= gtk_item_factory_get_widget(mainmenufactory
,
283 "<GdisorderMain>/Edit/Track properties");
284 assert(selectall_widget
!= 0);
285 assert(properties_widget
!= 0);
286 m
= gtk_item_factory_get_widget(mainmenufactory
,