ui: various cleanups - gconf and glade.
[nova.git] / src / ui / glade.c
blob560b8ed4bc5bde404d1de721502c3af819e185c3
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 gchar *name;
36 GtkWidget *widget;
37 GladeXML *xml;
38 };
40 static struct ui_glade ui[] = {
41 /* {"/splash.glade", "Splash", NULL, NULL},*/
42 {"/date-time-dlg.glade", "DateTimeDialog", NULL, NULL},
43 {"/observer-dlg.glade", "ObserverDialog", NULL, NULL},
44 {"/sky-catalog-dlg.glade", "SkyCatalogDialog", NULL, NULL},
45 {"/sky-deep-dlg.glade", "SkyDeepDialog", NULL, NULL},
46 {"/sky-near-dlg.glade", "SkyNearDialog", NULL, NULL},
47 {"/sky-markers-dlg.glade", "SkyMarkersDialog", NULL, NULL},
48 {"/sky-proj-dlg.glade", "SkyProjectionDialog", NULL, NULL},
51 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
53 gint ui_init(void)
55 gint i;
57 for (i = 0; i < ARRAY_SIZE(ui); i++) {
58 GString *interface = NULL;
60 if (ui[i].widget)
61 continue;
63 interface = g_string_new(NOVA_GLADE_DIR);
64 interface = g_string_append(interface, ui[i].glade_file);
66 g_print("%s: loading %s\n", __func__, interface->str);
67 ui[i].xml = glade_xml_new(interface->str, ui[i].name, NULL);
69 g_string_free(interface, TRUE);
71 if (!ui[i].xml) {
72 g_critical("%s: failed to load\n", __func__);
73 return -EINVAL;
76 glade_xml_signal_autoconnect(ui[i].xml);
77 ui[i].widget = glade_xml_get_widget(ui[i].xml, ui[i].name);
79 if (!ui[i].widget) {
80 g_critical("%s: failed to get widget %s\n", __func__,
81 ui[i].name);
82 return -EINVAL;
86 return 0;
89 GtkWidget* ui_get_dialog(gchar* name)
91 gint i;
93 if (!ui_init()) {
94 g_critical("%s: can't load glade UI files", __func__);
95 return NULL;
98 for (i = 0; i < ARRAY_SIZE(ui); i++) {
99 if (!strcmp(name, ui[i].name))
100 return ui[i].widget;
103 g_critical("%s: can't find glade UI %s", __func__, name);
104 return NULL;
107 void ui_put_dialog(gchar* name)
109 gint i = 0;
111 for (i = 0; i < ARRAY_SIZE(ui); i++) {
112 if (!strcmp(name, ui[i].name)) {
113 ui[i].widget = NULL;
114 g_object_unref(ui[i].xml);
115 return;
118 g_critical("%s: can't find glade UI %s", __func__, name);