ui: callbacks - added callbacks
[nova.git] / src / ui / glade.c
blob353a3d0b5348f492a4a7189b8cb6274f64f66bb6
1 /*
2 * Copyright (C) 2008 Liam Girdwood
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <string.h>
25 #include <gtk/gtk.h>
26 #include <glade/glade.h>
27 #include <errno.h>
30 * Glade dialogs
33 struct ui_glade {
34 gchar *glade_file;
35 const gchar *name;
36 GtkWidget *widget;
37 GladeXML *xml;
38 };
40 /* needed for linking and glade signal connection */
41 extern const gchar date_time_name[];
42 extern const gchar catalog_name[];
43 extern const gchar deep_sky_name[];
44 extern const gchar markers_name[];
45 extern const gchar observer_name[];
46 extern const gchar solar_system_name[];
48 static struct ui_glade splash[] = {
49 {"/splash.glade", "Splash", NULL, NULL},
52 static struct ui_glade ui[] = {
53 {"/date-time-dlg.glade", date_time_name, NULL, NULL},
54 {"/observer-dlg.glade", observer_name, NULL, NULL},
55 {"/sky-catalog-dlg.glade", catalog_name, NULL, NULL},
56 {"/sky-deep-dlg.glade", deep_sky_name, NULL, NULL},
57 {"/sky-near-dlg.glade", solar_system_name, NULL, NULL},
58 {"/sky-markers-dlg.glade", markers_name, NULL, NULL},
61 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
63 gint ui_init(void)
65 gint i;
67 for (i = 0; i < ARRAY_SIZE(ui); i++) {
68 GString *interface = NULL;
70 if (ui[i].widget)
71 continue;
73 interface = g_string_new(NOVA_GLADE_DIR);
74 interface = g_string_append(interface, ui[i].glade_file);
76 g_print("%s: loading %s\n", __func__, interface->str);
77 ui[i].xml = glade_xml_new(interface->str, ui[i].name, NULL);
79 g_string_free(interface, TRUE);
81 if (!ui[i].xml) {
82 g_critical("%s: failed to load\n", __func__);
83 return -EINVAL;
86 glade_xml_signal_autoconnect(ui[i].xml);
87 ui[i].widget = glade_xml_get_widget(ui[i].xml, ui[i].name);
89 if (!ui[i].widget) {
90 g_critical("%s: failed to get widget %s\n", __func__,
91 ui[i].name);
92 return -EINVAL;
96 return 0;
99 GtkWidget* ui_get_dialog(gchar* name)
101 gint i;
103 if (ui_init()) {
104 g_critical("%s: can't load glade UI files", __func__);
105 return NULL;
108 for (i = 0; i < ARRAY_SIZE(ui); i++) {
109 if (!strcmp(name, ui[i].name))
110 return ui[i].widget;
113 g_critical("%s: can't find glade UI %s", __func__, name);
114 return NULL;
117 void ui_put_dialog(gchar* name)
119 gint i = 0;
121 for (i = 0; i < ARRAY_SIZE(ui); i++) {
122 if (!strcmp(name, ui[i].name)) {
123 ui[i].widget = NULL;
124 g_object_unref(ui[i].xml);
125 return;
128 g_critical("%s: can't find glade UI %s", __func__, name);