2 * This file is part of DisOrder.
3 * Copyright (C) 2006 Richard Kettlewell
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.
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.
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
21 #include "disobedience.h"
23 static GtkWidget *selectall_widget;
24 static GtkWidget *properties_widget;
26 static void about_popup_got_version(void *v, const char *value);
28 static void quit_program(gpointer attribute((unused)) callback_data,
29 guint attribute((unused)) callback_action,
30 GtkWidget attribute((unused)) *menu_item) {
35 /* TODO can we have a single parameterized callback for all these */
36 static 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");
43 t->selectall_activate(tab);
46 static 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");
53 t->properties_activate(tab);
56 void menu_update(int page) {
57 GtkWidget *tab = gtk_notebook_get_nth_page
59 page < 0 ? gtk_notebook_current_page(GTK_NOTEBOOK(tabs)) : page);
60 const struct tabtype *t = g_object_get_data(G_OBJECT(tab), "type");
63 gtk_widget_set_sensitive(properties_widget,
64 t->properties_sensitive(tab));
65 gtk_widget_set_sensitive(selectall_widget,
66 t->selectall_sensitive(tab));
69 static void about_popup(gpointer attribute((unused)) callback_data,
70 guint attribute((unused)) callback_action,
71 GtkWidget attribute((unused)) *menu_item) {
74 gtk_label_set_text(GTK_LABEL(report_label), "getting server version");
75 disorder_eclient_version(client,
76 about_popup_got_version,
80 static void about_popup_got_version(void attribute((unused)) *v,
83 char *server_version_string;
85 byte_xasprintf(&server_version_string, "Server version %s", value);
86 w = gtk_dialog_new_with_buttons("About DisOrder",
89 |GTK_DIALOG_DESTROY_WITH_PARENT),
93 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
94 gtk_label_new("DisOrder client " VERSION));
95 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
96 gtk_label_new(server_version_string));
97 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(w)->vbox),
98 gtk_label_new("(c) 2004-2007 Richard Kettlewell"));
99 gtk_widget_show_all(w);
100 gtk_dialog_run(GTK_DIALOG(w));
101 gtk_widget_destroy(w);
104 GtkWidget *menubar(GtkWidget *w) {
105 static const GtkItemFactoryEntry entries[] = {
106 { (char *)"/File", 0, 0, 0, (char *)"<Branch>", 0 },
107 { (char *)"/File/Quit Disobedience", (char *)"<CTRL>Q", quit_program, 0,
108 (char *)"<StockItem>", GTK_STOCK_QUIT },
109 { (char *)"/Edit", 0, 0, 0, (char *)"<Branch>", 0 },
110 { (char *)"/Edit/Select all tracks", (char *)"<CTRL>A", select_all, 0,
112 { (char *)"/Edit/Track properties", 0, properties_item, 0,
114 { (char *)"/Help", 0, 0, 0, (char *)"<Branch>", 0 },
115 { (char *)"/Help/About DisOrder", 0, about_popup, 0,
116 (char *)"<StockItem>", GTK_STOCK_ABOUT },
119 GtkItemFactory *itemfactory;
120 GtkAccelGroup *accel = gtk_accel_group_new();
123 /* TODO: item factories are deprecated in favour of some XML thing */
124 itemfactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<GdisorderMain>",
126 gtk_item_factory_create_items(itemfactory,
127 sizeof entries / sizeof *entries,
128 (GtkItemFactoryEntry *)entries,
130 gtk_window_add_accel_group(GTK_WINDOW(w), accel);
131 selectall_widget = gtk_item_factory_get_widget(itemfactory,
132 "<GdisorderMain>/Edit/Select all tracks");
133 properties_widget = gtk_item_factory_get_widget(itemfactory,
134 "<GdisorderMain>/Edit/Track properties");
135 assert(selectall_widget != 0);
136 assert(properties_widget != 0);
137 return gtk_item_factory_get_widget(itemfactory,
139 /* menu bar had better not expand vertically if the window is too big */