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