1 | /* |
---|
2 | test-libglade.c: a test program for the libglade library |
---|
3 | Copyright (C) 1998, 1999, 2000 James Henstridge <james@daa.com.au> |
---|
4 | GNOME option parsing code by Miguel de Icaza. |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software |
---|
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | |
---|
20 | |
---|
21 | At your option, you may use this alternative X style licence: |
---|
22 | |
---|
23 | Permission is hereby granted, free of charge, to any person obtaining |
---|
24 | a copy of this software and associated documentation files (the |
---|
25 | "Software"), to deal in the Software without restriction, including |
---|
26 | without limitation the rights to use, copy, modify, merge, publish, |
---|
27 | distribute, sublicense, and/or sell copies of the Software, and to |
---|
28 | permit persons to whom the Software is furnished to do so, subject to |
---|
29 | the following conditions: |
---|
30 | |
---|
31 | The above copyright notice and this permission notice shall be |
---|
32 | included in all copies or substantial portions of the Software. |
---|
33 | |
---|
34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
---|
35 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
---|
36 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
---|
37 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES |
---|
38 | OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
39 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR |
---|
40 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|
41 | */ |
---|
42 | |
---|
43 | |
---|
44 | #include <config.h> |
---|
45 | #include <string.h> |
---|
46 | #ifdef ENABLE_GNOME |
---|
47 | # include <gnome.h> |
---|
48 | #else |
---|
49 | # include <gtk/gtk.h> |
---|
50 | #endif |
---|
51 | #include <glade/glade.h> |
---|
52 | |
---|
53 | const char *filename = NULL, *rootnode = NULL; |
---|
54 | gboolean no_connect = FALSE; |
---|
55 | |
---|
56 | #ifdef ENABLE_GNOME |
---|
57 | static poptContext ctx; |
---|
58 | |
---|
59 | static const struct poptOption options [] = { |
---|
60 | { "no-connect", '\0', POPT_ARG_INT, &no_connect, 0, |
---|
61 | N_("Do not connect signals") }, |
---|
62 | { NULL, '\0', 0, NULL, 0 } |
---|
63 | }; |
---|
64 | #endif |
---|
65 | |
---|
66 | int main (int argc, char **argv) |
---|
67 | { |
---|
68 | int i; |
---|
69 | GladeXML *xml; |
---|
70 | |
---|
71 | #ifdef ENABLE_GNOME |
---|
72 | const char **list = NULL; |
---|
73 | |
---|
74 | gnome_init_with_popt_table ("test-libglade", VERSION, argc, argv, options, 0, &ctx); |
---|
75 | glade_gnome_init(); |
---|
76 | |
---|
77 | list = poptGetArgs (ctx); |
---|
78 | if (list){ |
---|
79 | for (i = 0; list [i]; i++){ |
---|
80 | if (filename == NULL) |
---|
81 | filename = list [i]; |
---|
82 | else if (rootnode == NULL) |
---|
83 | rootnode = list [i]; |
---|
84 | } |
---|
85 | } |
---|
86 | if (filename == NULL){ |
---|
87 | g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]); |
---|
88 | return 1; |
---|
89 | } |
---|
90 | #else |
---|
91 | gtk_init(&argc, &argv); |
---|
92 | glade_init(); |
---|
93 | |
---|
94 | for (i = 1; i < argc; i++) { |
---|
95 | if (!strcmp(argv[i], "--no-connect")) |
---|
96 | no_connect = TRUE; |
---|
97 | else if (filename == NULL) |
---|
98 | filename = argv[i]; |
---|
99 | else if (rootnode == NULL) |
---|
100 | rootnode = argv[i]; |
---|
101 | else { |
---|
102 | g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]); |
---|
103 | return 1; |
---|
104 | } |
---|
105 | } |
---|
106 | if (filename == NULL) { |
---|
107 | g_print("Usage: %s [--no-connect] filename [rootnode]\n", argv[0]); |
---|
108 | return 1; |
---|
109 | } |
---|
110 | #endif |
---|
111 | |
---|
112 | xml = glade_xml_new(filename, rootnode); |
---|
113 | |
---|
114 | if (!xml) { |
---|
115 | g_warning("something bad happened while creating the interface"); |
---|
116 | return 1; |
---|
117 | } |
---|
118 | |
---|
119 | if (rootnode) { |
---|
120 | GtkWidget *wid = glade_xml_get_widget(xml, rootnode); |
---|
121 | if (!GTK_IS_WINDOW(wid)) { |
---|
122 | GtkWidget *win, *frame; |
---|
123 | |
---|
124 | win = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
---|
125 | gtk_signal_connect(GTK_OBJECT(win), "destroy", |
---|
126 | GTK_SIGNAL_FUNC(gtk_main_quit), NULL); |
---|
127 | gtk_container_set_border_width(GTK_CONTAINER(win), 5); |
---|
128 | frame = gtk_frame_new(NULL); |
---|
129 | gtk_container_set_border_width(GTK_CONTAINER(frame), 5); |
---|
130 | gtk_container_add(GTK_CONTAINER(win), frame); |
---|
131 | gtk_widget_show(frame); |
---|
132 | gtk_container_add(GTK_CONTAINER(frame), wid); |
---|
133 | gtk_widget_show(win); |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | if (!no_connect) |
---|
138 | glade_xml_signal_autoconnect(xml); |
---|
139 | |
---|
140 | gtk_object_unref(GTK_OBJECT(xml)); |
---|
141 | |
---|
142 | gtk_main(); |
---|
143 | |
---|
144 | return 0; |
---|
145 | } |
---|