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