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