1 | /* gnomeui-support.c -- helper functions for GNOME binding |
---|
2 | $Id: gnomeui-support.c,v 1.1.1.2 2003-01-05 00:30:04 ghudson Exp $ */ |
---|
3 | |
---|
4 | #include <config.h> |
---|
5 | #include <assert.h> |
---|
6 | #include <gnome.h> |
---|
7 | #include "rep-gtk.h" |
---|
8 | #include "rep-gnome.h" |
---|
9 | #include <string.h> |
---|
10 | #include <signal.h> |
---|
11 | |
---|
12 | DEFSYM(_gnome_app_id_, "*gnome-app-id*"); |
---|
13 | DEFSYM(_gnome_app_version_, "*gnome-app-version*"); |
---|
14 | DEFSYM(rep_version, "rep-version"); |
---|
15 | |
---|
16 | static int sgtk_gnomeui_inited; |
---|
17 | |
---|
18 | /* grr.. */ |
---|
19 | guint |
---|
20 | gnome_app_bar_get_type (void) |
---|
21 | { |
---|
22 | return gnome_appbar_get_type (); |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | /* extra types */ |
---|
27 | |
---|
28 | void |
---|
29 | sgtk_gnome_string_callback (gchar *string, gpointer data) |
---|
30 | { |
---|
31 | rep_call_lisp1 (sgtk_get_protect (data), |
---|
32 | string != 0 ? rep_string_dup (string) : Qnil); |
---|
33 | } |
---|
34 | |
---|
35 | void |
---|
36 | sgtk_gnome_reply_callback (gint reply, gpointer data) |
---|
37 | { |
---|
38 | rep_call_lisp1 (sgtk_get_protect (data), rep_MAKE_INT (reply)); |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | /* helpers */ |
---|
43 | |
---|
44 | static int |
---|
45 | list_length (repv list) |
---|
46 | { |
---|
47 | repv len = Flength (list); |
---|
48 | return (len && rep_INTP (len)) ? rep_INT (len) : 0; |
---|
49 | } |
---|
50 | |
---|
51 | static char* |
---|
52 | xstrdup (char *str) |
---|
53 | { |
---|
54 | if (str) |
---|
55 | { |
---|
56 | char *newstr = rep_alloc (strlen(str)+1); |
---|
57 | strcpy (newstr, str); |
---|
58 | return newstr; |
---|
59 | } |
---|
60 | else |
---|
61 | return NULL; |
---|
62 | } |
---|
63 | |
---|
64 | static void |
---|
65 | make_argv (repv list, int *argc, char ***argv) |
---|
66 | { |
---|
67 | static char *argv_storage[1] = { "rep-gtk" }; |
---|
68 | |
---|
69 | int c = list_length (list), i; |
---|
70 | char **v; |
---|
71 | |
---|
72 | *argv = argv_storage; |
---|
73 | *argc = 1; |
---|
74 | |
---|
75 | if (c < 0) |
---|
76 | return; |
---|
77 | |
---|
78 | v = (char **)rep_alloc ((c+1) * sizeof(char**)); |
---|
79 | for (i = 0; i < c; i++, list = rep_CDR (list)) |
---|
80 | { |
---|
81 | if (!rep_STRINGP (rep_CAR (list))) |
---|
82 | { |
---|
83 | rep_free ((char *)v); |
---|
84 | return; |
---|
85 | } |
---|
86 | v[i] = xstrdup (rep_STR (rep_CAR (list))); |
---|
87 | } |
---|
88 | v[c] = NULL; |
---|
89 | |
---|
90 | *argv = v; |
---|
91 | *argc = c; |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | /* client code, from guile-gnome/client.c */ |
---|
96 | |
---|
97 | /* Generated by gen-typeinfo func from "gnome.defs". */ |
---|
98 | |
---|
99 | typedef void set_prop_func (GnomeClient *client, gint argc, gchar *argv[]); |
---|
100 | typedef GnomeClient *new_func (gint argc, gchar *argv[]); |
---|
101 | |
---|
102 | /* Helper function. */ |
---|
103 | static void |
---|
104 | set_prop_from_arglist (GnomeClient *client, |
---|
105 | repv list, |
---|
106 | gchar *name, |
---|
107 | set_prop_func *func) |
---|
108 | { |
---|
109 | char **argv; |
---|
110 | int argc, i; |
---|
111 | repv l, s; |
---|
112 | |
---|
113 | argc = 0; |
---|
114 | l = list; |
---|
115 | while (rep_CONSP (l)) |
---|
116 | { |
---|
117 | if (!rep_CONSP (l)) return; |
---|
118 | s = rep_CAR (l); |
---|
119 | if (!rep_STRINGP (s)) return; |
---|
120 | ++argc; |
---|
121 | l = rep_CDR (l); |
---|
122 | } |
---|
123 | if (l != Qnil) return; |
---|
124 | |
---|
125 | argv = (gchar **) malloc (argc * sizeof (gchar *)); |
---|
126 | for (i = 0, l = list; rep_CONSP (l); l = rep_CDR (l), ++i) |
---|
127 | argv[i] = rep_STR (rep_CAR (l)); |
---|
128 | (*func) (client, argc, argv); |
---|
129 | free (argv); |
---|
130 | } |
---|
131 | |
---|
132 | DEFUN ("gnome-client-set-clone-command", Fgnome_client_set_clone_command, |
---|
133 | Sgnome_client_set_clone_command, (repv p_client, repv p_list), rep_Subr2) |
---|
134 | { |
---|
135 | GnomeClient* c_client; |
---|
136 | rep_DECLARE (1, p_client, sgtk_is_a_gtkobj (gnome_client_get_type (), p_client)); |
---|
137 | |
---|
138 | c_client = (GnomeClient*)sgtk_get_gtkobj (p_client); |
---|
139 | set_prop_from_arglist (c_client, p_list, 0, gnome_client_set_clone_command); |
---|
140 | |
---|
141 | return Qnil; |
---|
142 | } |
---|
143 | |
---|
144 | DEFUN ("gnome-client-set-environment", Fgnome_client_set_environment, |
---|
145 | Sgnome_client_set_environment, (repv p_client, repv p_list), rep_Subr2) |
---|
146 | { |
---|
147 | GnomeClient* c_client; |
---|
148 | rep_DECLARE (1, p_client, sgtk_is_a_gtkobj (gnome_client_get_type (), p_client)); |
---|
149 | |
---|
150 | c_client = (GnomeClient*)sgtk_get_gtkobj (p_client); |
---|
151 | set_prop_from_arglist (c_client, p_list, 0, gnome_client_set_environment); |
---|
152 | |
---|
153 | return Qnil; |
---|
154 | } |
---|
155 | |
---|
156 | DEFUN ("gnome-client-set-restart-command", Fgnome_client_set_restart_command, |
---|
157 | Sgnome_client_set_restart_command, (repv p_client, repv p_list), rep_Subr2) |
---|
158 | { |
---|
159 | GnomeClient* c_client; |
---|
160 | rep_DECLARE (1, p_client, sgtk_is_a_gtkobj (gnome_client_get_type (), p_client)); |
---|
161 | |
---|
162 | c_client = (GnomeClient*)sgtk_get_gtkobj (p_client); |
---|
163 | set_prop_from_arglist (c_client, p_list, 0, gnome_client_set_restart_command); |
---|
164 | |
---|
165 | return Qnil; |
---|
166 | } |
---|
167 | |
---|
168 | DEFUN ("gnome-client-set-resign-command", Fgnome_client_set_resign_command, |
---|
169 | Sgnome_client_set_resign_command, (repv p_client, repv p_list), rep_Subr2) |
---|
170 | { |
---|
171 | GnomeClient* c_client; |
---|
172 | rep_DECLARE (1, p_client, sgtk_is_a_gtkobj (gnome_client_get_type (), p_client)); |
---|
173 | |
---|
174 | c_client = (GnomeClient*)sgtk_get_gtkobj (p_client); |
---|
175 | set_prop_from_arglist (c_client, p_list, 0, gnome_client_set_resign_command); |
---|
176 | |
---|
177 | return Qnil; |
---|
178 | } |
---|
179 | |
---|
180 | DEFUN ("gnome-client-set-shutdown-command", Fgnome_client_set_shutdown_command, |
---|
181 | Sgnome_client_set_shutdown_command, (repv p_client, repv p_list), rep_Subr2) |
---|
182 | { |
---|
183 | GnomeClient* c_client; |
---|
184 | rep_DECLARE (1, p_client, sgtk_is_a_gtkobj (gnome_client_get_type (), p_client)); |
---|
185 | |
---|
186 | c_client = (GnomeClient*)sgtk_get_gtkobj (p_client); |
---|
187 | set_prop_from_arglist (c_client, p_list, 0, gnome_client_set_shutdown_command); |
---|
188 | |
---|
189 | return Qnil; |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | int |
---|
195 | sgtk_gnome_init (const char *app_id, const char *app_version) |
---|
196 | { |
---|
197 | int argc; |
---|
198 | char **argv, *tem; |
---|
199 | repv head, *last; |
---|
200 | void (*fatal_signal_handler)(); |
---|
201 | |
---|
202 | if (sgtk_gnomeui_inited) |
---|
203 | return 0; |
---|
204 | |
---|
205 | tem = getenv ("REP_GTK_DONT_INITIALIZE"); |
---|
206 | if (tem != 0 && atoi (tem) != 0) |
---|
207 | return 0; |
---|
208 | |
---|
209 | #if 0 |
---|
210 | make_argv (Fcons (Fsymbol_value (Qprogram_name, Qt), |
---|
211 | Fsymbol_value (Qcommand_line_args, Qt)), &argc, &argv); |
---|
212 | #else |
---|
213 | /* fucking gnome gives error if it sees option it doesn't understand.. */ |
---|
214 | make_argv (Fcons (Fsymbol_value (Qprogram_name, Qt), Qnil), &argc, &argv); |
---|
215 | #endif |
---|
216 | |
---|
217 | /* preserve rep's error handlers */ |
---|
218 | fatal_signal_handler = signal (SIGSEGV, SIG_DFL); |
---|
219 | |
---|
220 | gnome_init (app_id, app_version, argc, argv); |
---|
221 | |
---|
222 | if (fatal_signal_handler != SIG_ERR && fatal_signal_handler != SIG_IGN) |
---|
223 | { |
---|
224 | #ifdef SIGFPE |
---|
225 | signal (SIGFPE, fatal_signal_handler); |
---|
226 | #endif |
---|
227 | #ifdef SIGILL |
---|
228 | signal (SIGILL, fatal_signal_handler); |
---|
229 | #endif |
---|
230 | #ifdef SIGSEGV |
---|
231 | signal (SIGSEGV, fatal_signal_handler); |
---|
232 | #endif |
---|
233 | #ifdef SIGBUS |
---|
234 | signal (SIGBUS, fatal_signal_handler); |
---|
235 | #endif |
---|
236 | #ifdef SIGQUIT |
---|
237 | signal (SIGQUIT, fatal_signal_handler); |
---|
238 | #endif |
---|
239 | #ifdef SIGABRT |
---|
240 | signal (SIGABRT, fatal_signal_handler); |
---|
241 | #endif |
---|
242 | } |
---|
243 | |
---|
244 | #if 0 |
---|
245 | argc--; argv++; |
---|
246 | head = Qnil; |
---|
247 | last = &head; |
---|
248 | while(argc > 0) |
---|
249 | { |
---|
250 | *last = Fcons(rep_string_dup(*argv), Qnil); |
---|
251 | last = &rep_CDR(*last); |
---|
252 | argc--; |
---|
253 | argv++; |
---|
254 | } |
---|
255 | Fset (Qcommand_line_args, head); |
---|
256 | #endif |
---|
257 | |
---|
258 | sgtk_gnomeui_inited = TRUE; |
---|
259 | return 1; |
---|
260 | } |
---|
261 | |
---|
262 | |
---|
263 | /* dl hooks / init */ |
---|
264 | |
---|
265 | repv |
---|
266 | rep_dl_init (void) |
---|
267 | { |
---|
268 | repv s = rep_push_structure ("gui.gtk-2.gnome-ui"); |
---|
269 | repv id, version; |
---|
270 | |
---|
271 | sgtk_gnome_init_gnomeui_glue (); |
---|
272 | rep_ADD_SUBR (Sgnome_client_set_clone_command); |
---|
273 | rep_ADD_SUBR (Sgnome_client_set_environment); |
---|
274 | rep_ADD_SUBR (Sgnome_client_set_resign_command); |
---|
275 | rep_ADD_SUBR (Sgnome_client_set_restart_command); |
---|
276 | rep_ADD_SUBR (Sgnome_client_set_shutdown_command); |
---|
277 | |
---|
278 | rep_INTERN_SPECIAL(_gnome_app_id_); |
---|
279 | rep_INTERN_SPECIAL(_gnome_app_version_); |
---|
280 | id = Fsymbol_value (Q_gnome_app_id_, Qt); |
---|
281 | version = Fsymbol_value (Q_gnome_app_version_, Qt); |
---|
282 | |
---|
283 | if (rep_STRINGP (id) && rep_STRINGP (version)) |
---|
284 | sgtk_gnome_init (rep_STR (id), rep_STR (version)); |
---|
285 | else |
---|
286 | { |
---|
287 | rep_INTERN(rep_version); |
---|
288 | version = Fsymbol_value (Qrep_version, Qt); |
---|
289 | sgtk_gnome_init ("rep", rep_STRINGP (version) |
---|
290 | ? (char *) rep_STR (version) : "0"); |
---|
291 | } |
---|
292 | return rep_pop_structure (s); |
---|
293 | } |
---|