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