chiark / gitweb /
Assume initial digits in a track name are a sort key even without the
[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
06bfbba4 33static void about_popup_got_version(void *v,
e2717131 34 const char *err,
06bfbba4 35 const char *value);
460b9539 36
2c348789
RK
37/** @brief Called when the quit option is activated
38 *
39 * Just exits.
40 */
460b9539 41static void quit_program(gpointer attribute((unused)) callback_data,
42 guint attribute((unused)) callback_action,
43 GtkWidget attribute((unused)) *menu_item) {
44 D(("quit_program"));
45 exit(0);
46}
47
d9a92920 48/** @brief Called when an edit menu item is selected
2c348789 49 *
d9a92920
RK
50 * Shared by several menu items; callback_action is expected to be the offset
51 * of the activate member of struct tabtype.
2c348789 52 */
d9a92920
RK
53static void menu_tab_action(gpointer attribute((unused)) callback_data,
54 guint callback_action,
460b9539 55 GtkWidget attribute((unused)) *menu_item) {
56 GtkWidget *tab = gtk_notebook_get_nth_page
57 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
58 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
59
d9a92920
RK
60 void (**activatep)(GtkMenuItem *, gpointer)
61 = (void *)((const char *)t + callback_action);
62 void (*activate)(GtkMenuItem *, gpointer) = *activatep;
63
64 if(activate)
65 activate(NULL, t->extra);
460b9539 66}
67
73f1b9f3
RK
68/** @brief Called when the login option is activated */
69static void login(gpointer attribute((unused)) callback_data,
70 guint attribute((unused)) callback_action,
71 GtkWidget attribute((unused)) *menu_item) {
72 login_box();
73}
74
ffc4dbaf
RK
75/** @brief Called when the login option is activated */
76static void users(gpointer attribute((unused)) callback_data,
77 guint attribute((unused)) callback_action,
78 GtkWidget attribute((unused)) *menu_item) {
79 manage_users();
80}
81
46fb1b05
RK
82#if 0
83/** @brief Called when the settings option is activated */
84static void settings(gpointer attribute((unused)) callback_data,
85 guint attribute((unused)) callback_action,
86 GtkWidget attribute((unused)) *menu_item) {
87 popup_settings();
88}
89#endif
90
229d327f 91/** @brief Called when edit menu is shown
2c348789
RK
92 *
93 * Determines option sensitivity according to the current tab and adjusts the
94 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
95 * need not.
96 */
229d327f
RK
97static void edit_menu_show(GtkWidget attribute((unused)) *widget,
98 gpointer attribute((unused)) user_data) {
961d31f6
RK
99 if(tabs) {
100 GtkWidget *tab = gtk_notebook_get_nth_page
101 (GTK_NOTEBOOK(tabs),
229d327f 102 gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
961d31f6
RK
103 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
104
105 assert(t != 0);
106 gtk_widget_set_sensitive(properties_widget,
ee7552f8
RK
107 (t->properties_sensitive
108 && t->properties_sensitive(t->extra)
961d31f6
RK
109 && (disorder_eclient_state(client) & DISORDER_CONNECTED)));
110 gtk_widget_set_sensitive(selectall_widget,
ee7552f8
RK
111 t->selectall_sensitive
112 && t->selectall_sensitive(t->extra));
961d31f6 113 gtk_widget_set_sensitive(selectnone_widget,
ee7552f8
RK
114 t->selectnone_sensitive
115 && t->selectnone_sensitive(t->extra));
961d31f6 116 }
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,
abf99697 141 const char attribute((unused)) *err,
460b9539 142 const char *value) {
143 GtkWidget *w;
144 char *server_version_string;
54cca6d6 145 char *short_version_string;
413b30a4 146 GtkWidget *hbox, *vbox, *title;
460b9539 147
06bfbba4
RK
148 if(!value)
149 value = "[error]";
460b9539 150 byte_xasprintf(&server_version_string, "Server version %s", value);
54cca6d6
RK
151 byte_xasprintf(&short_version_string, "Disobedience %s",
152 disorder_short_version_string);
413b30a4 153 w = gtk_dialog_new_with_buttons("About Disobedience",
460b9539 154 GTK_WINDOW(toplevel),
155 (GTK_DIALOG_MODAL
156 |GTK_DIALOG_DESTROY_WITH_PARENT),
157 GTK_STOCK_OK,
158 GTK_RESPONSE_ACCEPT,
159 (char *)NULL);
413b30a4
RK
160 hbox = gtk_hbox_new(FALSE/*homogeneous*/, 1/*padding*/);
161 vbox = gtk_vbox_new(FALSE/*homogeneous*/, 1/*padding*/);
162 gtk_box_pack_start(GTK_BOX(hbox),
163 gtk_image_new_from_pixbuf(find_image("duck.png")),
164 FALSE/*expand*/,
165 FALSE/*fill*/,
166 4/*padding*/);
167 gtk_box_pack_start(GTK_BOX(vbox),
54cca6d6 168 gtk_label_new(short_version_string),
413b30a4
RK
169 FALSE/*expand*/,
170 FALSE/*fill*/,
171 1/*padding*/);
172 gtk_box_pack_start(GTK_BOX(vbox),
173 gtk_label_new(server_version_string),
174 FALSE/*expand*/,
175 FALSE/*fill*/,
176 1/*padding*/);
177 gtk_box_pack_start(GTK_BOX(vbox),
8f9616f1 178 gtk_label_new("\xC2\xA9 2004-2008 Richard Kettlewell"),
413b30a4
RK
179 FALSE/*expand*/,
180 FALSE/*fill*/,
181 1/*padding*/);
182 gtk_box_pack_end(GTK_BOX(hbox),
183 vbox,
184 FALSE/*expand*/,
185 FALSE/*fill*/,
186 0/*padding*/);
187 title = gtk_label_new(0);
188 gtk_label_set_markup(GTK_LABEL(title),
189 "<span font_desc=\"Sans 36\">Disobedience</span>");
190 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), title,
191 FALSE/*expand*/,
192 FALSE/*fill*/,
193 0/*padding*/);
194 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), hbox,
195 FALSE/*expand*/,
196 FALSE/*fill*/,
197 0/*padding*/);
76fc02c5 198 set_tool_colors(w);
460b9539 199 gtk_widget_show_all(w);
200 gtk_dialog_run(GTK_DIALOG(w));
201 gtk_widget_destroy(w);
202}
203
c73bd6c1
RK
204/** @brief Set 'Manage Users' menu item sensitivity */
205void users_set_sensitive(int sensitive) {
206 GtkWidget *w = gtk_item_factory_get_widget(mainmenufactory,
207 "<GdisorderMain>/Server/Manage users");
208 gtk_widget_set_sensitive(w, sensitive);
209}
210
6f09d54d
RK
211/** @brief Called when our rights change */
212static void menu_rights_changed(const char attribute((unused)) *event,
213 void attribute((unused)) *eventdata,
214 void attribute((unused)) *callbackdata) {
215 users_set_sensitive(!!(last_rights & RIGHT_ADMIN));
c73bd6c1
RK
216}
217
2c348789 218/** @brief Create the menu bar widget */
460b9539 219GtkWidget *menubar(GtkWidget *w) {
d4ef4132
RK
220 GtkWidget *m;
221
460b9539 222 static const GtkItemFactoryEntry entries[] = {
2d504956 223 {
eb80584d 224 (char *)"/Server", /* path */
2d504956
RK
225 0, /* accelerator */
226 0, /* callback */
227 0, /* callback_action */
228 (char *)"<Branch>", /* item_type */
229 0 /* extra_data */
230 },
231 {
eb80584d 232 (char *)"/Server/Login", /* path */
2d504956
RK
233 (char *)"<CTRL>L", /* accelerator */
234 login, /* callback */
235 0, /* callback_action */
236 0, /* item_type */
237 0 /* extra_data */
238 },
ffc4dbaf 239 {
eb80584d 240 (char *)"/Server/Manage users", /* path */
ffc4dbaf
RK
241 0, /* accelerator */
242 users, /* callback */
243 0, /* callback_action */
244 0, /* item_type */
245 0 /* extra_data */
246 },
46fb1b05
RK
247#if 0
248 {
eb80584d 249 (char *)"/Server/Settings", /* path */
46fb1b05
RK
250 0, /* accelerator */
251 settings, /* callback */
252 0, /* callback_action */
253 0, /* item_type */
254 0 /* extra_data */
255 },
256#endif
2d504956 257 {
eb80584d 258 (char *)"/Server/Quit Disobedience", /* path */
2d504956
RK
259 (char *)"<CTRL>Q", /* accelerator */
260 quit_program, /* callback */
261 0, /* callback_action */
262 (char *)"<StockItem>", /* item_type */
263 GTK_STOCK_QUIT /* extra_data */
264 },
ac6bf2ba 265
2d504956
RK
266 {
267 (char *)"/Edit", /* path */
268 0, /* accelerator */
269 0, /* callback */
270 0, /* callback_action */
271 (char *)"<Branch>", /* item_type */
272 0 /* extra_data */
273 },
274 {
275 (char *)"/Edit/Select all tracks", /* path */
52d45ac3 276 0, /* accelerator */
d9a92920
RK
277 menu_tab_action, /* callback */
278 offsetof(struct tabtype, selectall_activate), /* callback_action */
2d504956
RK
279 0, /* item_type */
280 0 /* extra_data */
281 },
282 {
fb009628 283 (char *)"/Edit/Deselect all tracks", /* path */
52d45ac3 284 0, /* accelerator */
d9a92920
RK
285 menu_tab_action, /* callback */
286 offsetof(struct tabtype, selectnone_activate), /* callback_action */
fb009628
RK
287 0, /* item_type */
288 0 /* extra_data */
289 },
290 {
2d504956
RK
291 (char *)"/Edit/Track properties", /* path */
292 0, /* accelerator */
d9a92920
RK
293 menu_tab_action, /* callback */
294 offsetof(struct tabtype, properties_activate), /* callback_action */
2d504956
RK
295 0, /* item_type */
296 0 /* extra_data */
297 },
298
299 {
300 (char *)"/Control", /* path */
301 0, /* accelerator */
302 0, /* callback */
303 0, /* callback_action */
304 (char *)"<Branch>", /* item_type */
305 0 /* extra_data */
306 },
307 {
308 (char *)"/Control/Scratch", /* path */
309 (char *)"<CTRL>S", /* accelerator */
310 0, /* callback */
311 0, /* callback_action */
312 0, /* item_type */
313 0 /* extra_data */
314 },
315 {
685bdfbd
RK
316 (char *)"/Control/Playing", /* path */
317 (char *)"<CTRL>P", /* accelerator */
318 0, /* callback */
319 0, /* callback_action */
320 (char *)"<CheckItem>", /* item_type */
321 0 /* extra_data */
322 },
323 {
2d504956
RK
324 (char *)"/Control/Random play", /* path */
325 (char *)"<CTRL>R", /* accelerator */
326 0, /* callback */
685bdfbd
RK
327 0, /* callback_action */
328 (char *)"<CheckItem>", /* item_type */
329 0 /* extra_data */
330 },
331 {
332 (char *)"/Control/Network player", /* path */
333 (char *)"<CTRL>N", /* accelerator */
334 0, /* callback */
2d504956
RK
335 0, /* callback_action */
336 (char *)"<CheckItem>", /* item_type */
337 0 /* extra_data */
338 },
339
340 {
341 (char *)"/Help", /* path */
342 0, /* accelerator */
343 0, /* callback */
344 0, /* callback_action */
345 (char *)"<Branch>", /* item_type */
346 0 /* extra_data */
347 },
348 {
13affe66
RK
349 (char *)"/Help/Manual page", /* path */
350 0, /* accelerator */
351 manual_popup, /* callback */
352 0, /* callback_action */
353 0, /* item_type */
354 0 /* extra_data */
355 },
356 {
2d504956
RK
357 (char *)"/Help/About DisOrder", /* path */
358 0, /* accelerator */
359 about_popup, /* callback */
360 0, /* callback_action */
361 (char *)"<StockItem>", /* item_type */
362 GTK_STOCK_ABOUT /* extra_data */
363 },
460b9539 364 };
365
460b9539 366 GtkAccelGroup *accel = gtk_accel_group_new();
367
368 D(("add_menubar"));
369 /* TODO: item factories are deprecated in favour of some XML thing */
ac6bf2ba
RK
370 mainmenufactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
371 accel);
372 gtk_item_factory_create_items(mainmenufactory,
460b9539 373 sizeof entries / sizeof *entries,
374 (GtkItemFactoryEntry *)entries,
375 0);
376 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
ac6bf2ba 377 selectall_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 378 "<GdisorderMain>/Edit/Select all tracks");
fb009628
RK
379 selectnone_widget = gtk_item_factory_get_widget(mainmenufactory,
380 "<GdisorderMain>/Edit/Deselect all tracks");
ac6bf2ba 381 properties_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 382 "<GdisorderMain>/Edit/Track properties");
460b9539 383 assert(selectall_widget != 0);
fb009628 384 assert(selectnone_widget != 0);
460b9539 385 assert(properties_widget != 0);
229d327f
RK
386
387
388 GtkWidget *edit_widget = gtk_item_factory_get_widget(mainmenufactory,
389 "<GdisorderMain>/Edit");
229d327f
RK
390 g_signal_connect(edit_widget, "show", G_CALLBACK(edit_menu_show), 0);
391
6f09d54d
RK
392 event_register("rights-changed", menu_rights_changed, 0);
393 users_set_sensitive(0);
d4ef4132
RK
394 m = gtk_item_factory_get_widget(mainmenufactory,
395 "<GdisorderMain>");
396 set_tool_colors(m);
397 return m;
460b9539 398}
399
400/*
401Local Variables:
402c-basic-offset:2
403comment-column:40
404fill-column:79
405indent-tabs-mode:nil
406End:
407*/