chiark / gitweb /
tooltips for search widgets
[disorder] / disobedience / menu.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2006 Richard Kettlewell
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 */
20
21#include "disobedience.h"
22
23static GtkWidget *selectall_widget;
24static GtkWidget *properties_widget;
25
26static void about_popup_got_version(void *v, const char *value);
27
28static void quit_program(gpointer attribute((unused)) callback_data,
29 guint attribute((unused)) callback_action,
30 GtkWidget attribute((unused)) *menu_item) {
31 D(("quit_program"));
32 exit(0);
33}
34
35/* TODO can we have a single parameterized callback for all these */
36static void select_all(gpointer attribute((unused)) callback_data,
37 guint attribute((unused)) callback_action,
38 GtkWidget attribute((unused)) *menu_item) {
39 GtkWidget *tab = gtk_notebook_get_nth_page
40 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
41 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
42
43 t->selectall_activate(tab);
44}
45
46static void properties_item(gpointer attribute((unused)) callback_data,
47 guint attribute((unused)) callback_action,
48 GtkWidget attribute((unused)) *menu_item) {
49 GtkWidget *tab = gtk_notebook_get_nth_page
50 (GTK_NOTEBOOK(tabs), gtk_notebook_current_page(GTK_NOTEBOOK(tabs)));
51 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
52
53 t->properties_activate(tab);
54}
55
56void menu_update(int page) {
57 GtkWidget *tab = gtk_notebook_get_nth_page
58 (GTK_NOTEBOOK(tabs),
59 page < 0 ? gtk_notebook_current_page(GTK_NOTEBOOK(tabs)) : page);
60 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
61
62 assert(t != 0);
63 gtk_widget_set_sensitive(properties_widget,
e836b1aa 64 (t->properties_sensitive(tab)
8f763f1b 65 && (disorder_eclient_state(client) & DISORDER_CONNECTED)));
460b9539 66 gtk_widget_set_sensitive(selectall_widget,
67 t->selectall_sensitive(tab));
68}
69
70static void about_popup(gpointer attribute((unused)) callback_data,
71 guint attribute((unused)) callback_action,
72 GtkWidget attribute((unused)) *menu_item) {
73 D(("about_popup"));
74
75 gtk_label_set_text(GTK_LABEL(report_label), "getting server version");
76 disorder_eclient_version(client,
77 about_popup_got_version,
78 0);
79}
80
81static void about_popup_got_version(void attribute((unused)) *v,
82 const char *value) {
83 GtkWidget *w;
84 char *server_version_string;
85
86 byte_xasprintf(&server_version_string, "Server version %s", value);
87 w = gtk_dialog_new_with_buttons("About DisOrder",
88 GTK_WINDOW(toplevel),
89 (GTK_DIALOG_MODAL
90 |GTK_DIALOG_DESTROY_WITH_PARENT),
91 GTK_STOCK_OK,
92 GTK_RESPONSE_ACCEPT,
93 (char *)NULL);
94 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
95 gtk_label_new("DisOrder client " VERSION));
96 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
97 gtk_label_new(server_version_string));
98 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
eb525fcd 99 gtk_label_new("(c) 2004-2007 Richard Kettlewell"));
460b9539 100 gtk_widget_show_all(w);
101 gtk_dialog_run(GTK_DIALOG(w));
102 gtk_widget_destroy(w);
103}
104
105GtkWidget *menubar(GtkWidget *w) {
106 static const GtkItemFactoryEntry entries[] = {
107 { (char *)"/File", 0, 0, 0, (char *)"<Branch>", 0 },
39fe1014 108 { (char *)"/File/Quit Disobedience", (char *)"<CTRL>Q", quit_program, 0,
460b9539 109 (char *)"<StockItem>", GTK_STOCK_QUIT },
110 { (char *)"/Edit", 0, 0, 0, (char *)"<Branch>", 0 },
39fe1014 111 { (char *)"/Edit/Select all tracks", (char *)"<CTRL>A", select_all, 0,
460b9539 112 0, 0 },
39fe1014 113 { (char *)"/Edit/Track properties", 0, properties_item, 0,
460b9539 114 0, 0 },
115 { (char *)"/Help", 0, 0, 0, (char *)"<Branch>", 0 },
116 { (char *)"/Help/About DisOrder", 0, about_popup, 0,
117 (char *)"<StockItem>", GTK_STOCK_ABOUT },
118 };
119
120 GtkItemFactory *itemfactory;
121 GtkAccelGroup *accel = gtk_accel_group_new();
122
123 D(("add_menubar"));
124 /* TODO: item factories are deprecated in favour of some XML thing */
125 itemfactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
126 accel);
127 gtk_item_factory_create_items(itemfactory,
128 sizeof entries / sizeof *entries,
129 (GtkItemFactoryEntry *)entries,
130 0);
131 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
132 selectall_widget = gtk_item_factory_get_widget(itemfactory,
39fe1014 133 "<GdisorderMain>/Edit/Select all tracks");
460b9539 134 properties_widget = gtk_item_factory_get_widget(itemfactory,
39fe1014 135 "<GdisorderMain>/Edit/Track properties");
460b9539 136 assert(selectall_widget != 0);
137 assert(properties_widget != 0);
138 return gtk_item_factory_get_widget(itemfactory,
139 "<GdisorderMain>");
140 /* menu bar had better not expand vertically if the window is too big */
141}
142
143/*
144Local Variables:
145c-basic-offset:2
146comment-column:40
147fill-column:79
148indent-tabs-mode:nil
149End:
150*/