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