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