chiark / gitweb /
include configure and compiler details in version output
[disorder] / disobedience / menu.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
73f1b9f3 3 * Copyright (C) 2006, 2007 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
26static GtkWidget *selectall_widget;
27static GtkWidget *properties_widget;
28
ac6bf2ba
RK
29/** @brief Main menu widgets */
30GtkItemFactory *mainmenufactory;
31
460b9539 32static void about_popup_got_version(void *v, const char *value);
33
2c348789
RK
34/** @brief Called when the quit option is activated
35 *
36 * Just exits.
37 */
460b9539 38static void quit_program(gpointer attribute((unused)) callback_data,
39 guint attribute((unused)) callback_action,
40 GtkWidget attribute((unused)) *menu_item) {
41 D(("quit_program"));
42 exit(0);
43}
44
45/* TODO can we have a single parameterized callback for all these */
2c348789
RK
46
47/** @brief Called when the select all option is activated
48 *
49 * Calls the per-tab select all function.
50 */
460b9539 51static void select_all(gpointer attribute((unused)) callback_data,
52 guint attribute((unused)) callback_action,
53 GtkWidget attribute((unused)) *menu_item) {
54 GtkWidget *tab = gtk_notebook_get_nth_page
55 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
56 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
57
58 t->selectall_activate(tab);
59}
60
2c348789
RK
61/** @brief Called when the track properties option is activated
62 *
63 * Calls the per-tab properties function.
64 */
460b9539 65static void properties_item(gpointer attribute((unused)) callback_data,
66 guint attribute((unused)) callback_action,
67 GtkWidget attribute((unused)) *menu_item) {
68 GtkWidget *tab = gtk_notebook_get_nth_page
69 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
70 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
71
72 t->properties_activate(tab);
73}
74
73f1b9f3
RK
75/** @brief Called when the login option is activated */
76static void login(gpointer attribute((unused)) callback_data,
77 guint attribute((unused)) callback_action,
78 GtkWidget attribute((unused)) *menu_item) {
79 login_box();
80}
81
2c348789
RK
82/** @brief Update menu state
83 *
84 * Determines option sensitivity according to the current tab and adjusts the
85 * widgets accordingly. Knows about @ref DISORDER_CONNECTED so the callbacks
86 * need not.
87 */
460b9539 88void menu_update(int page) {
89 GtkWidget *tab = gtk_notebook_get_nth_page
90 (GTK_NOTEBOOK(tabs),
91 page < 0 ? gtk_notebook_current_page(GTK_NOTEBOOK(tabs)) : page);
92 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
93
94 assert(t != 0);
95 gtk_widget_set_sensitive(properties_widget,
e836b1aa 96 (t->properties_sensitive(tab)
8f763f1b 97 && (disorder_eclient_state(client) & DISORDER_CONNECTED)));
460b9539 98 gtk_widget_set_sensitive(selectall_widget,
99 t->selectall_sensitive(tab));
100}
2c348789
RK
101
102/** @brief Fetch version in order to display the about... popup */
460b9539 103static void about_popup(gpointer attribute((unused)) callback_data,
104 guint attribute((unused)) callback_action,
105 GtkWidget attribute((unused)) *menu_item) {
106 D(("about_popup"));
107
108 gtk_label_set_text(GTK_LABEL(report_label), "getting server version");
109 disorder_eclient_version(client,
110 about_popup_got_version,
111 0);
112}
113
13affe66
RK
114static void manual_popup(gpointer attribute((unused)) callback_data,
115 guint attribute((unused)) callback_action,
116 GtkWidget attribute((unused)) *menu_item) {
117 D(("manual_popup"));
118
119 popup_help();
120}
121
2c348789 122/** @brief Callde when version arrives, displays about... popup */
460b9539 123static void about_popup_got_version(void attribute((unused)) *v,
124 const char *value) {
125 GtkWidget *w;
126 char *server_version_string;
413b30a4 127 GtkWidget *hbox, *vbox, *title;
460b9539 128
129 byte_xasprintf(&server_version_string, "Server version %s", value);
413b30a4 130 w = gtk_dialog_new_with_buttons("About Disobedience",
460b9539 131 GTK_WINDOW(toplevel),
132 (GTK_DIALOG_MODAL
133 |GTK_DIALOG_DESTROY_WITH_PARENT),
134 GTK_STOCK_OK,
135 GTK_RESPONSE_ACCEPT,
136 (char *)NULL);
413b30a4
RK
137 hbox = gtk_hbox_new(FALSE/*homogeneous*/, 1/*padding*/);
138 vbox = gtk_vbox_new(FALSE/*homogeneous*/, 1/*padding*/);
139 gtk_box_pack_start(GTK_BOX(hbox),
140 gtk_image_new_from_pixbuf(find_image("duck.png")),
141 FALSE/*expand*/,
142 FALSE/*fill*/,
143 4/*padding*/);
144 gtk_box_pack_start(GTK_BOX(vbox),
145 gtk_label_new("Disobedience " VERSION),
146 FALSE/*expand*/,
147 FALSE/*fill*/,
148 1/*padding*/);
149 gtk_box_pack_start(GTK_BOX(vbox),
150 gtk_label_new(server_version_string),
151 FALSE/*expand*/,
152 FALSE/*fill*/,
153 1/*padding*/);
154 gtk_box_pack_start(GTK_BOX(vbox),
155 gtk_label_new("(c) 2004-2007 Richard Kettlewell"),
156 FALSE/*expand*/,
157 FALSE/*fill*/,
158 1/*padding*/);
159 gtk_box_pack_end(GTK_BOX(hbox),
160 vbox,
161 FALSE/*expand*/,
162 FALSE/*fill*/,
163 0/*padding*/);
164 title = gtk_label_new(0);
165 gtk_label_set_markup(GTK_LABEL(title),
166 "<span font_desc=\"Sans 36\">Disobedience</span>");
167 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), title,
168 FALSE/*expand*/,
169 FALSE/*fill*/,
170 0/*padding*/);
171 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(w)->vbox), hbox,
172 FALSE/*expand*/,
173 FALSE/*fill*/,
174 0/*padding*/);
76fc02c5 175 set_tool_colors(w);
460b9539 176 gtk_widget_show_all(w);
177 gtk_dialog_run(GTK_DIALOG(w));
178 gtk_widget_destroy(w);
179}
180
2c348789 181/** @brief Create the menu bar widget */
460b9539 182GtkWidget *menubar(GtkWidget *w) {
d4ef4132
RK
183 GtkWidget *m;
184
460b9539 185 static const GtkItemFactoryEntry entries[] = {
2d504956
RK
186 {
187 (char *)"/File", /* path */
188 0, /* accelerator */
189 0, /* callback */
190 0, /* callback_action */
191 (char *)"<Branch>", /* item_type */
192 0 /* extra_data */
193 },
194 {
195 (char *)"/File/Login", /* path */
196 (char *)"<CTRL>L", /* accelerator */
197 login, /* callback */
198 0, /* callback_action */
199 0, /* item_type */
200 0 /* extra_data */
201 },
202 {
203 (char *)"/File/Quit Disobedience", /* path */
204 (char *)"<CTRL>Q", /* accelerator */
205 quit_program, /* callback */
206 0, /* callback_action */
207 (char *)"<StockItem>", /* item_type */
208 GTK_STOCK_QUIT /* extra_data */
209 },
ac6bf2ba 210
2d504956
RK
211 {
212 (char *)"/Edit", /* path */
213 0, /* accelerator */
214 0, /* callback */
215 0, /* callback_action */
216 (char *)"<Branch>", /* item_type */
217 0 /* extra_data */
218 },
219 {
220 (char *)"/Edit/Select all tracks", /* path */
221 (char *)"<CTRL>A", /* accelerator */
222 select_all, /* callback */
223 0, /* callback_action */
224 0, /* item_type */
225 0 /* extra_data */
226 },
227 {
228 (char *)"/Edit/Track properties", /* path */
229 0, /* accelerator */
230 properties_item, /* callback */
231 0, /* callback_action */
232 0, /* item_type */
233 0 /* extra_data */
234 },
235
236 {
237 (char *)"/Control", /* path */
238 0, /* accelerator */
239 0, /* callback */
240 0, /* callback_action */
241 (char *)"<Branch>", /* item_type */
242 0 /* extra_data */
243 },
244 {
245 (char *)"/Control/Scratch", /* path */
246 (char *)"<CTRL>S", /* accelerator */
247 0, /* callback */
248 0, /* callback_action */
249 0, /* item_type */
250 0 /* extra_data */
251 },
252 {
685bdfbd
RK
253 (char *)"/Control/Playing", /* path */
254 (char *)"<CTRL>P", /* accelerator */
255 0, /* callback */
256 0, /* callback_action */
257 (char *)"<CheckItem>", /* item_type */
258 0 /* extra_data */
259 },
260 {
2d504956
RK
261 (char *)"/Control/Random play", /* path */
262 (char *)"<CTRL>R", /* accelerator */
263 0, /* callback */
685bdfbd
RK
264 0, /* callback_action */
265 (char *)"<CheckItem>", /* item_type */
266 0 /* extra_data */
267 },
268 {
269 (char *)"/Control/Network player", /* path */
270 (char *)"<CTRL>N", /* accelerator */
271 0, /* callback */
2d504956
RK
272 0, /* callback_action */
273 (char *)"<CheckItem>", /* item_type */
274 0 /* extra_data */
275 },
276
277 {
278 (char *)"/Help", /* path */
279 0, /* accelerator */
280 0, /* callback */
281 0, /* callback_action */
282 (char *)"<Branch>", /* item_type */
283 0 /* extra_data */
284 },
285 {
13affe66
RK
286 (char *)"/Help/Manual page", /* path */
287 0, /* accelerator */
288 manual_popup, /* callback */
289 0, /* callback_action */
290 0, /* item_type */
291 0 /* extra_data */
292 },
293 {
2d504956
RK
294 (char *)"/Help/About DisOrder", /* path */
295 0, /* accelerator */
296 about_popup, /* callback */
297 0, /* callback_action */
298 (char *)"<StockItem>", /* item_type */
299 GTK_STOCK_ABOUT /* extra_data */
300 },
460b9539 301 };
302
460b9539 303 GtkAccelGroup *accel = gtk_accel_group_new();
304
305 D(("add_menubar"));
306 /* TODO: item factories are deprecated in favour of some XML thing */
ac6bf2ba
RK
307 mainmenufactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
308 accel);
309 gtk_item_factory_create_items(mainmenufactory,
460b9539 310 sizeof entries / sizeof *entries,
311 (GtkItemFactoryEntry *)entries,
312 0);
313 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
ac6bf2ba 314 selectall_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 315 "<GdisorderMain>/Edit/Select all tracks");
ac6bf2ba 316 properties_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 317 "<GdisorderMain>/Edit/Track properties");
460b9539 318 assert(selectall_widget != 0);
319 assert(properties_widget != 0);
d4ef4132
RK
320 m = gtk_item_factory_get_widget(mainmenufactory,
321 "<GdisorderMain>");
322 set_tool_colors(m);
323 return m;
460b9539 324}
325
326/*
327Local Variables:
328c-basic-offset:2
329comment-column:40
330fill-column:79
331indent-tabs-mode:nil
332End:
333*/