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