chiark / gitweb /
typo fix
[disorder] / disobedience / menu.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
73f1b9f3 3 * Copyright (C) 2006, 2007 Richard Kettlewell
460b9539 4 *
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.
9 *
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.
14 *
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
18 * USA
19 */
2c348789
RK
20/** @file disobedience/menu.c
21 * @brief Main menu
22 */
460b9539 23
24#include "disobedience.h"
25
26static GtkWidget *selectall_widget;
27static GtkWidget *properties_widget;
28
ac6bf2ba
RK
29/** @brief Main menu widgets */
30GtkItemFactory *mainmenufactory;
31
460b9539 32static void about_popup_got_version(void *v, const char *value);
33
2c348789
RK
34/** @brief Called when the quit option is activated
35 *
36 * Just exits.
37 */
460b9539 38static void quit_program(gpointer attribute((unused)) callback_data,
39 guint attribute((unused)) callback_action,
40 GtkWidget attribute((unused)) *menu_item) {
41 D(("quit_program"));
42 exit(0);
43}
44
45/* TODO can we have a single parameterized callback for all these */
2c348789
RK
46
47/** @brief Called when the select all option is activated
48 *
49 * Calls the per-tab select all function.
50 */
460b9539 51static 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");
57
58 t->selectall_activate(tab);
59}
60
2c348789
RK
61/** @brief Called when the track properties option is activated
62 *
63 * Calls the per-tab properties function.
64 */
460b9539 65static 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");
71
72 t->properties_activate(tab);
73}
74
73f1b9f3
RK
75/** @brief Called when the login option is activated */
76static void login(gpointer attribute((unused)) callback_data,
77 guint attribute((unused)) callback_action,
78 GtkWidget attribute((unused)) *menu_item) {
79 login_box();
80}
81
2c348789
RK
82/** @brief Update menu state
83 *
84 * Determines option sensitivity according to the current tab and adjusts the
85 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
86 * need not.
87 */
460b9539 88void menu_update(int page) {
89 GtkWidget *tab = gtk_notebook_get_nth_page
90 (GTK_NOTEBOOK(tabs),
91 page < 0 ? gtk_notebook_current_page(GTK_NOTEBOOK(tabs)) : page);
92 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
93
94 assert(t != 0);
95 gtk_widget_set_sensitive(properties_widget,
e836b1aa 96 (t->properties_sensitive(tab)
8f763f1b 97 && (disorder_eclient_state(client) & DISORDER_CONNECTED)));
460b9539 98 gtk_widget_set_sensitive(selectall_widget,
99 t->selectall_sensitive(tab));
100}
2c348789
RK
101
102/** @brief Fetch version in order to display the about... popup */
460b9539 103static void about_popup(gpointer attribute((unused)) callback_data,
104 guint attribute((unused)) callback_action,
105 GtkWidget attribute((unused)) *menu_item) {
106 D(("about_popup"));
107
108 gtk_label_set_text(GTK_LABEL(report_label), "getting server version");
109 disorder_eclient_version(client,
110 about_popup_got_version,
111 0);
112}
113
13affe66
RK
114static void manual_popup(gpointer attribute((unused)) callback_data,
115 guint attribute((unused)) callback_action,
116 GtkWidget attribute((unused)) *menu_item) {
117 D(("manual_popup"));
118
119 popup_help();
120}
121
883a4e96 122/** @brief Called when version arrives, displays about... popup */
460b9539 123static void about_popup_got_version(void attribute((unused)) *v,
124 const char *value) {
125 GtkWidget *w;
126 char *server_version_string;
54cca6d6 127 char *short_version_string;
413b30a4 128 GtkWidget *hbox, *vbox, *title;
460b9539 129
130 byte_xasprintf(&server_version_string, "Server version %s", value);
54cca6d6
RK
131 byte_xasprintf(&short_version_string, "Disobedience %s",
132 disorder_short_version_string);
413b30a4 133 w = gtk_dialog_new_with_buttons("About Disobedience",
460b9539 134 GTK_WINDOW(toplevel),
135 (GTK_DIALOG_MODAL
136 |GTK_DIALOG_DESTROY_WITH_PARENT),
137 GTK_STOCK_OK,
138 GTK_RESPONSE_ACCEPT,
139 (char *)NULL);
413b30a4
RK
140 hbox = gtk_hbox_new(FALSE/*homogeneous*/, 1/*padding*/);
141 vbox = gtk_vbox_new(FALSE/*homogeneous*/, 1/*padding*/);
142 gtk_box_pack_start(GTK_BOX(hbox),
143 gtk_image_new_from_pixbuf(find_image("duck.png")),
144 FALSE/*expand*/,
145 FALSE/*fill*/,
146 4/*padding*/);
147 gtk_box_pack_start(GTK_BOX(vbox),
54cca6d6 148 gtk_label_new(short_version_string),
413b30a4
RK
149 FALSE/*expand*/,
150 FALSE/*fill*/,
151 1/*padding*/);
152 gtk_box_pack_start(GTK_BOX(vbox),
153 gtk_label_new(server_version_string),
154 FALSE/*expand*/,
155 FALSE/*fill*/,
156 1/*padding*/);
157 gtk_box_pack_start(GTK_BOX(vbox),
8f9616f1 158 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
413b30a4
RK
159 FALSE/*expand*/,
160 FALSE/*fill*/,
161 1/*padding*/);
162 gtk_box_pack_end(GTK_BOX(hbox),
163 vbox,
164 FALSE/*expand*/,
165 FALSE/*fill*/,
166 0/*padding*/);
167 title = gtk_label_new(0);
168 gtk_label_set_markup(GTK_LABEL(title),
169 "<span font_desc=\"Sans 36\">Disobedience</span>");
170 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), title,
171 FALSE/*expand*/,
172 FALSE/*fill*/,
173 0/*padding*/);
174 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), hbox,
175 FALSE/*expand*/,
176 FALSE/*fill*/,
177 0/*padding*/);
76fc02c5 178 set_tool_colors(w);
460b9539 179 gtk_widget_show_all(w);
180 gtk_dialog_run(GTK_DIALOG(w));
181 gtk_widget_destroy(w);
182}
183
2c348789 184/** @brief Create the menu bar widget */
460b9539 185GtkWidget *menubar(GtkWidget *w) {
d4ef4132
RK
186 GtkWidget *m;
187
460b9539 188 static const GtkItemFactoryEntry entries[] = {
2d504956
RK
189 {
190 (char *)"/File", /* path */
191 0, /* accelerator */
192 0, /* callback */
193 0, /* callback_action */
194 (char *)"<Branch>", /* item_type */
195 0 /* extra_data */
196 },
197 {
198 (char *)"/File/Login", /* path */
199 (char *)"<CTRL>L", /* accelerator */
200 login, /* callback */
201 0, /* callback_action */
202 0, /* item_type */
203 0 /* extra_data */
204 },
205 {
206 (char *)"/File/Quit Disobedience", /* path */
207 (char *)"<CTRL>Q", /* accelerator */
208 quit_program, /* callback */
209 0, /* callback_action */
210 (char *)"<StockItem>", /* item_type */
211 GTK_STOCK_QUIT /* extra_data */
212 },
ac6bf2ba 213
2d504956
RK
214 {
215 (char *)"/Edit", /* path */
216 0, /* accelerator */
217 0, /* callback */
218 0, /* callback_action */
219 (char *)"<Branch>", /* item_type */
220 0 /* extra_data */
221 },
222 {
223 (char *)"/Edit/Select all tracks", /* path */
224 (char *)"<CTRL>A", /* accelerator */
225 select_all, /* callback */
226 0, /* callback_action */
227 0, /* item_type */
228 0 /* extra_data */
229 },
230 {
231 (char *)"/Edit/Track properties", /* path */
232 0, /* accelerator */
233 properties_item, /* callback */
234 0, /* callback_action */
235 0, /* item_type */
236 0 /* extra_data */
237 },
238
239 {
240 (char *)"/Control", /* path */
241 0, /* accelerator */
242 0, /* callback */
243 0, /* callback_action */
244 (char *)"<Branch>", /* item_type */
245 0 /* extra_data */
246 },
247 {
248 (char *)"/Control/Scratch", /* path */
249 (char *)"<CTRL>S", /* accelerator */
250 0, /* callback */
251 0, /* callback_action */
252 0, /* item_type */
253 0 /* extra_data */
254 },
255 {
685bdfbd
RK
256 (char *)"/Control/Playing", /* path */
257 (char *)"<CTRL>P", /* accelerator */
258 0, /* callback */
259 0, /* callback_action */
260 (char *)"<CheckItem>", /* item_type */
261 0 /* extra_data */
262 },
263 {
2d504956
RK
264 (char *)"/Control/Random play", /* path */
265 (char *)"<CTRL>R", /* accelerator */
266 0, /* callback */
685bdfbd
RK
267 0, /* callback_action */
268 (char *)"<CheckItem>", /* item_type */
269 0 /* extra_data */
270 },
271 {
272 (char *)"/Control/Network player", /* path */
273 (char *)"<CTRL>N", /* accelerator */
274 0, /* callback */
2d504956
RK
275 0, /* callback_action */
276 (char *)"<CheckItem>", /* item_type */
277 0 /* extra_data */
278 },
279
280 {
281 (char *)"/Help", /* path */
282 0, /* accelerator */
283 0, /* callback */
284 0, /* callback_action */
285 (char *)"<Branch>", /* item_type */
286 0 /* extra_data */
287 },
288 {
13affe66
RK
289 (char *)"/Help/Manual page", /* path */
290 0, /* accelerator */
291 manual_popup, /* callback */
292 0, /* callback_action */
293 0, /* item_type */
294 0 /* extra_data */
295 },
296 {
2d504956
RK
297 (char *)"/Help/About DisOrder", /* path */
298 0, /* accelerator */
299 about_popup, /* callback */
300 0, /* callback_action */
301 (char *)"<StockItem>", /* item_type */
302 GTK_STOCK_ABOUT /* extra_data */
303 },
460b9539 304 };
305
460b9539 306 GtkAccelGroup *accel = gtk_accel_group_new();
307
308 D(("add_menubar"));
309 /* TODO: item factories are deprecated in favour of some XML thing */
ac6bf2ba
RK
310 mainmenufactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
311 accel);
312 gtk_item_factory_create_items(mainmenufactory,
460b9539 313 sizeof entries / sizeof *entries,
314 (GtkItemFactoryEntry *)entries,
315 0);
316 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
ac6bf2ba 317 selectall_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 318 "<GdisorderMain>/Edit/Select all tracks");
ac6bf2ba 319 properties_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 320 "<GdisorderMain>/Edit/Track properties");
460b9539 321 assert(selectall_widget != 0);
322 assert(properties_widget != 0);
d4ef4132
RK
323 m = gtk_item_factory_get_widget(mainmenufactory,
324 "<GdisorderMain>");
325 set_tool_colors(m);
326 return m;
460b9539 327}
328
329/*
330Local Variables:
331c-basic-offset:2
332comment-column:40
333fill-column:79
334indent-tabs-mode:nil
335End:
336*/