chiark / gitweb /
even chattier logging
[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;
127
128 byte_xasprintf(&server_version_string, "Server version %s", value);
129 w = gtk_dialog_new_with_buttons("About DisOrder",
130 GTK_WINDOW(toplevel),
131 (GTK_DIALOG_MODAL
132 |GTK_DIALOG_DESTROY_WITH_PARENT),
133 GTK_STOCK_OK,
134 GTK_RESPONSE_ACCEPT,
135 (char *)NULL);
136 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
137 gtk_label_new("DisOrder client " VERSION));
138 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
139 gtk_label_new(server_version_string));
140 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
eb525fcd 141 gtk_label_new("(c) 2004-2007 Richard Kettlewell"));
460b9539 142 gtk_widget_show_all(w);
143 gtk_dialog_run(GTK_DIALOG(w));
144 gtk_widget_destroy(w);
145}
146
2c348789 147/** @brief Create the menu bar widget */
460b9539 148GtkWidget *menubar(GtkWidget *w) {
149 static const GtkItemFactoryEntry entries[] = {
2d504956
RK
150 {
151 (char *)"/File", /* path */
152 0, /* accelerator */
153 0, /* callback */
154 0, /* callback_action */
155 (char *)"<Branch>", /* item_type */
156 0 /* extra_data */
157 },
158 {
159 (char *)"/File/Login", /* path */
160 (char *)"<CTRL>L", /* accelerator */
161 login, /* callback */
162 0, /* callback_action */
163 0, /* item_type */
164 0 /* extra_data */
165 },
166 {
167 (char *)"/File/Quit Disobedience", /* path */
168 (char *)"<CTRL>Q", /* accelerator */
169 quit_program, /* callback */
170 0, /* callback_action */
171 (char *)"<StockItem>", /* item_type */
172 GTK_STOCK_QUIT /* extra_data */
173 },
ac6bf2ba 174
2d504956
RK
175 {
176 (char *)"/Edit", /* path */
177 0, /* accelerator */
178 0, /* callback */
179 0, /* callback_action */
180 (char *)"<Branch>", /* item_type */
181 0 /* extra_data */
182 },
183 {
184 (char *)"/Edit/Select all tracks", /* path */
185 (char *)"<CTRL>A", /* accelerator */
186 select_all, /* callback */
187 0, /* callback_action */
188 0, /* item_type */
189 0 /* extra_data */
190 },
191 {
192 (char *)"/Edit/Track properties", /* path */
193 0, /* accelerator */
194 properties_item, /* callback */
195 0, /* callback_action */
196 0, /* item_type */
197 0 /* extra_data */
198 },
199
200 {
201 (char *)"/Control", /* path */
202 0, /* accelerator */
203 0, /* callback */
204 0, /* callback_action */
205 (char *)"<Branch>", /* item_type */
206 0 /* extra_data */
207 },
208 {
209 (char *)"/Control/Scratch", /* path */
210 (char *)"<CTRL>S", /* accelerator */
211 0, /* callback */
212 0, /* callback_action */
213 0, /* item_type */
214 0 /* extra_data */
215 },
685bdfbd
RK
216 {
217 (char *)"/Control/Playing", /* path */
218 (char *)"<CTRL>P", /* accelerator */
219 0, /* callback */
220 0, /* callback_action */
221 (char *)"<CheckItem>", /* item_type */
222 0 /* extra_data */
223 },
2d504956
RK
224 {
225 (char *)"/Control/Random play", /* path */
226 (char *)"<CTRL>R", /* accelerator */
227 0, /* callback */
685bdfbd
RK
228 0, /* callback_action */
229 (char *)"<CheckItem>", /* item_type */
230 0 /* extra_data */
231 },
232 {
233 (char *)"/Control/Network player", /* path */
234 (char *)"<CTRL>N", /* accelerator */
235 0, /* callback */
2d504956
RK
236 0, /* callback_action */
237 (char *)"<CheckItem>", /* item_type */
238 0 /* extra_data */
239 },
240
241 {
242 (char *)"/Help", /* path */
243 0, /* accelerator */
244 0, /* callback */
245 0, /* callback_action */
246 (char *)"<Branch>", /* item_type */
247 0 /* extra_data */
248 },
13affe66
RK
249 {
250 (char *)"/Help/Manual page", /* path */
251 0, /* accelerator */
252 manual_popup, /* callback */
253 0, /* callback_action */
254 0, /* item_type */
255 0 /* extra_data */
256 },
2d504956
RK
257 {
258 (char *)"/Help/About DisOrder", /* path */
259 0, /* accelerator */
260 about_popup, /* callback */
261 0, /* callback_action */
262 (char *)"<StockItem>", /* item_type */
263 GTK_STOCK_ABOUT /* extra_data */
264 },
460b9539 265 };
266
460b9539 267 GtkAccelGroup *accel = gtk_accel_group_new();
268
269 D(("add_menubar"));
270 /* TODO: item factories are deprecated in favour of some XML thing */
ac6bf2ba
RK
271 mainmenufactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
272 accel);
273 gtk_item_factory_create_items(mainmenufactory,
460b9539 274 sizeof entries / sizeof *entries,
275 (GtkItemFactoryEntry *)entries,
276 0);
277 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
ac6bf2ba 278 selectall_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 279 "<GdisorderMain>/Edit/Select all tracks");
ac6bf2ba 280 properties_widget = gtk_item_factory_get_widget(mainmenufactory,
39fe1014 281 "<GdisorderMain>/Edit/Track properties");
460b9539 282 assert(selectall_widget != 0);
283 assert(properties_widget != 0);
ac6bf2ba 284 return gtk_item_factory_get_widget(mainmenufactory,
460b9539 285 "<GdisorderMain>");
286 /* menu bar had better not expand vertically if the window is too big */
287}
288
289/*
290Local Variables:
291c-basic-offset:2
292comment-column:40
293fill-column:79
294indent-tabs-mode:nil
295End:
296*/