1
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
|
|
5 *
|
|
6 * some code: (most in this file)
|
|
7 * Copyright (C) 1996 Netscape Communications Corporation, all rights reserved.
|
|
8 * Created: Jamie Zawinski <jwz@netscape.com>, 24-Dec-94.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 *
|
|
24 * This code is mainly taken from Netscape's sample implementation of
|
|
25 * their protocol. Nifty.
|
|
26 *
|
|
27 */
|
|
28
|
|
29
|
|
30 #include <stdio.h>
|
|
31 #include <stdlib.h>
|
|
32 #include <unistd.h>
|
|
33 #include <string.h>
|
|
34
|
|
35
|
|
36
|
|
37
|
|
38 #include <gtk/gtk.h>
|
|
39 #include <gdk/gdkprivate.h>
|
|
40 #include <gdk/gdkx.h>
|
|
41 #include "gaim.h"
|
|
42
|
|
43 #ifndef _WIN32
|
|
44
|
|
45
|
|
46
|
|
47
|
|
48 #include <X11/Xlib.h>
|
|
49 #include <X11/Xatom.h>
|
|
50
|
|
51
|
|
52 static const char *progname = "gaim";
|
|
53 static const char *expected_mozilla_version = "1.1";
|
|
54
|
|
55 #define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
|
|
56 #define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
|
|
57 #define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND"
|
|
58 #define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE"
|
|
59
|
|
60 static GdkAtom XA_MOZILLA_VERSION = 0;
|
|
61 static GdkAtom XA_MOZILLA_LOCK = 0;
|
|
62 static GdkAtom XA_MOZILLA_COMMAND = 0;
|
|
63 static GdkAtom XA_MOZILLA_RESPONSE = 0;
|
|
64
|
|
65
|
|
66 static int netscape_lock;
|
|
67
|
|
68
|
|
69 static Window
|
|
70 VirtualRootWindowOfScreen(screen)
|
|
71 Screen *screen;
|
|
72 {
|
|
73 static Screen *save_screen = (Screen *)0;
|
|
74 static Window root = (Window)0;
|
|
75
|
|
76 if (screen != save_screen) {
|
|
77 Display *dpy = DisplayOfScreen(screen);
|
|
78 Atom __SWM_VROOT = None;
|
|
79 int i;
|
|
80 Window rootReturn, parentReturn, *children;
|
|
81 unsigned int numChildren;
|
|
82
|
|
83 root = RootWindowOfScreen(screen);
|
|
84
|
|
85 /* go look for a virtual root */
|
|
86 __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
|
|
87 if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
|
|
88 &children, &numChildren)) {
|
|
89 for (i = 0; i < numChildren; i++) {
|
|
90 Atom actual_type;
|
|
91 int actual_format;
|
|
92 unsigned long nitems, bytesafter;
|
|
93 Window *newRoot = (Window *)0;
|
|
94
|
|
95 if (XGetWindowProperty(dpy, children[i],
|
|
96 __SWM_VROOT, 0, 1, False, XA_WINDOW,
|
|
97 &actual_type, &actual_format,
|
|
98 &nitems, &bytesafter,
|
|
99 (unsigned char **) &newRoot) == Success
|
|
100 && newRoot) {
|
|
101 root = *newRoot;
|
|
102 break;
|
|
103 }
|
|
104 }
|
|
105 if (children)
|
|
106 XFree((char *)children);
|
|
107 }
|
|
108
|
|
109 save_screen = screen;
|
|
110 }
|
|
111
|
|
112 return root;
|
|
113 }
|
|
114
|
|
115 /* The following code is Copyright (C) 1989 X Consortium */
|
|
116
|
|
117 static Window TryChildren();
|
|
118
|
|
119 /* Find a window with WM_STATE, else return win itself, as per ICCCM */
|
|
120
|
|
121 static Window GClientWindow (dpy, win)
|
|
122 Display *dpy;
|
|
123 Window win;
|
|
124 {
|
|
125 Atom WM_STATE;
|
|
126 Atom type = None;
|
|
127 int format;
|
|
128 unsigned long nitems, after;
|
|
129 unsigned char *data;
|
|
130 Window inf;
|
|
131
|
|
132 WM_STATE = XInternAtom(dpy, "WM_STATE", True);
|
|
133 if (!WM_STATE)
|
|
134 return win;
|
|
135 XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType,
|
|
136 &type, &format, &nitems, &after, &data);
|
|
137 if (type)
|
|
138 return win;
|
|
139 inf = TryChildren(dpy, win, WM_STATE);
|
|
140 if (!inf)
|
|
141 inf = win;
|
|
142 return inf;
|
|
143 }
|
|
144
|
|
145 static
|
|
146 Window TryChildren (dpy, win, WM_STATE)
|
|
147 Display *dpy;
|
|
148 Window win;
|
|
149 Atom WM_STATE;
|
|
150 {
|
|
151 Window root, parent;
|
|
152 Window *children;
|
|
153 unsigned int nchildren;
|
|
154 unsigned int i;
|
|
155 Atom type = None;
|
|
156 int format;
|
|
157 unsigned long nitems, after;
|
|
158 unsigned char *data;
|
|
159 Window inf = 0;
|
|
160
|
|
161 if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren))
|
|
162 return 0;
|
|
163 for (i = 0; !inf && (i < nchildren); i++) {
|
|
164 XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False,
|
|
165 AnyPropertyType, &type, &format, &nitems,
|
|
166 &after, &data);
|
|
167 if (type)
|
|
168 inf = children[i];
|
|
169 }
|
|
170 for (i = 0; !inf && (i < nchildren); i++)
|
|
171 inf = TryChildren(dpy, children[i], WM_STATE);
|
|
172 if (children) XFree((char *)children);
|
|
173 return inf;
|
|
174 }
|
|
175
|
|
176 /* END X Consortium code */
|
|
177
|
|
178
|
|
179
|
|
180 static void mozilla_remote_init_atoms()
|
|
181 {
|
|
182 if (!XA_MOZILLA_VERSION)
|
|
183 XA_MOZILLA_VERSION = gdk_atom_intern(MOZILLA_VERSION_PROP, 0);
|
|
184 if (!XA_MOZILLA_LOCK)
|
|
185 XA_MOZILLA_LOCK = gdk_atom_intern(MOZILLA_LOCK_PROP, 0);
|
|
186 if (! XA_MOZILLA_COMMAND)
|
|
187 XA_MOZILLA_COMMAND = gdk_atom_intern(MOZILLA_COMMAND_PROP, 0);
|
|
188 if (! XA_MOZILLA_RESPONSE)
|
|
189 XA_MOZILLA_RESPONSE = gdk_atom_intern(MOZILLA_RESPONSE_PROP, 0);
|
|
190 }
|
|
191
|
|
192 static GdkWindow *mozilla_remote_find_window()
|
|
193 {
|
|
194 int i;
|
|
195 Window root = VirtualRootWindowOfScreen(DefaultScreenOfDisplay(gdk_display));
|
|
196 Window root2, parent, *kids;
|
|
197 unsigned int nkids;
|
|
198 Window result = 0;
|
|
199 Window tenative = 0;
|
|
200 unsigned char *tenative_version = 0;
|
|
201
|
|
202 if (!XQueryTree (gdk_display, root, &root2, &parent, &kids, &nkids))
|
|
203 {
|
|
204 sprintf (debug_buff, "%s: XQueryTree failed on display %s\n", progname,
|
|
205 DisplayString (gdk_display));
|
|
206 debug_print(debug_buff);
|
|
207 return NULL;
|
|
208 }
|
|
209
|
|
210 /* root != root2 is possible with virtual root WMs. */
|
|
211
|
|
212 if (!(kids && nkids)) {
|
|
213 sprintf (debug_buff, "%s: root window has no children on display %s\n",
|
|
214 progname, DisplayString (gdk_display));
|
|
215 debug_print(debug_buff);
|
|
216 return NULL;
|
|
217 }
|
|
218
|
|
219 for (i = nkids-1; i >= 0; i--)
|
|
220 {
|
|
221 Atom type;
|
|
222 int format;
|
|
223 unsigned long nitems, bytesafter;
|
|
224 unsigned char *version = 0;
|
|
225 Window w = GClientWindow (gdk_display, kids[i]);
|
|
226 int status = XGetWindowProperty (gdk_display, w, XA_MOZILLA_VERSION,
|
|
227 0, (65536 / sizeof (long)),
|
|
228 False, XA_STRING,
|
|
229 &type, &format, &nitems, &bytesafter,
|
|
230 &version);
|
|
231 if (! version)
|
|
232 continue;
|
|
233 if (strcmp ((char *) version, expected_mozilla_version) &&
|
|
234 !tenative)
|
|
235 {
|
|
236 tenative = w;
|
|
237 tenative_version = version;
|
|
238 continue;
|
|
239 }
|
|
240 g_free (version);
|
|
241 if (status == Success && type != None)
|
|
242 {
|
|
243 result = w;
|
|
244 break;
|
|
245 }
|
|
246 }
|
|
247
|
|
248 if (result && tenative)
|
|
249 {
|
|
250 sprintf (debug_buff,
|
|
251 "%s: warning: both version %s (0x%x) and version\n"
|
|
252 "\t%s (0x%x) are running. Using version %s.\n",
|
|
253 progname, tenative_version, (unsigned int) tenative,
|
|
254 expected_mozilla_version, (unsigned int) result,
|
|
255 expected_mozilla_version);
|
|
256 debug_print(debug_buff);
|
|
257 g_free (tenative_version);
|
|
258 return gdk_window_foreign_new(result);
|
|
259 }
|
|
260 else if (tenative)
|
|
261 {
|
|
262 sprintf (debug_buff,
|
|
263 "%s: warning: expected version %s but found version\n"
|
|
264 "\t%s (0x%x) instead.\n",
|
|
265 progname, expected_mozilla_version,
|
|
266 tenative_version, (unsigned int) tenative);
|
|
267 debug_print(debug_buff);
|
|
268 g_free (tenative_version);
|
|
269 return gdk_window_foreign_new(tenative);
|
|
270 }
|
|
271 else if (result)
|
|
272 {
|
|
273 return gdk_window_foreign_new(result);
|
|
274 }
|
|
275 else
|
|
276 {
|
|
277 sprintf (debug_buff, "%s: not running on display %s\n", progname,
|
|
278 DisplayString (gdk_display));
|
|
279 debug_print(debug_buff);
|
|
280 return NULL;
|
|
281 }
|
|
282 }
|
|
283
|
|
284
|
|
285 static char *lock_data = 0;
|
|
286
|
|
287 static void mozilla_remote_obtain_lock (GdkWindow *window)
|
|
288 {
|
|
289 Bool locked = False;
|
|
290
|
|
291 if (!lock_data) {
|
|
292 lock_data = (char *)g_malloc (255);
|
|
293 sprintf (lock_data, "pid%d@", getpid ());
|
|
294 if (gethostname (lock_data + strlen (lock_data), 100)) {
|
|
295 return;
|
|
296 }
|
|
297 }
|
|
298
|
|
299 do {
|
|
300 int result;
|
|
301 GdkAtom actual_type;
|
|
302 gint actual_format;
|
|
303 gint nitems;
|
|
304 unsigned char *data = 0;
|
|
305
|
|
306 result = gdk_property_get (window, XA_MOZILLA_LOCK,
|
|
307 XA_STRING, 0,
|
|
308 (65536 / sizeof (long)), 0,
|
|
309 &actual_type, &actual_format,
|
|
310 &nitems, &data);
|
|
311 if (result != Success || actual_type == None)
|
|
312 {
|
|
313 /* It's not now locked - lock it. */
|
|
314 sprintf (debug_buff, "%s: (writing " MOZILLA_LOCK_PROP
|
|
315 " \"%s\" to 0x%x)\n",
|
|
316 progname, lock_data, (unsigned int) window);
|
|
317 debug_print(debug_buff);
|
|
318
|
|
319 gdk_property_change(window, XA_MOZILLA_LOCK, XA_STRING,
|
|
320 8, PropModeReplace,
|
|
321 (unsigned char *) lock_data,
|
|
322 strlen (lock_data));
|
|
323 locked = True;
|
|
324 }
|
|
325
|
|
326 if (!locked) {
|
|
327 /* Then just fuck it. */
|
|
328 if (data)
|
|
329 g_free(data);
|
|
330 return;
|
|
331 }
|
|
332 if (data)
|
|
333 g_free(data);
|
|
334 } while (!locked);
|
|
335 }
|
|
336
|
|
337
|
|
338 static void mozilla_remote_free_lock (GdkWindow *window)
|
|
339 {
|
|
340 int result = 0;
|
|
341 GdkAtom actual_type;
|
|
342 gint actual_format;
|
|
343 gint nitems;
|
|
344 unsigned char *data = 0;
|
|
345
|
|
346 sprintf (debug_buff, "%s: (deleting " MOZILLA_LOCK_PROP
|
|
347 " \"%s\" from 0x%x)\n",
|
|
348 progname, lock_data, (unsigned int) window);
|
|
349 debug_print(debug_buff);
|
|
350
|
|
351 result = gdk_property_get(window, XA_MOZILLA_LOCK, XA_STRING,
|
|
352 0, (65536 / sizeof (long)),
|
|
353 1, &actual_type, &actual_format,
|
|
354 &nitems, &data);
|
|
355 if (result != Success)
|
|
356 {
|
|
357 sprintf (debug_buff, "%s: unable to read and delete " MOZILLA_LOCK_PROP
|
|
358 " property\n",
|
|
359 progname);
|
|
360 debug_print(debug_buff);
|
|
361 return;
|
|
362 }
|
|
363 else if (!data || !*data)
|
|
364 {
|
|
365 sprintf (debug_buff, "%s: invalid data on " MOZILLA_LOCK_PROP
|
|
366 " of window 0x%x.\n",
|
|
367 progname, (unsigned int) window);
|
|
368 debug_print(debug_buff);
|
|
369 return;
|
|
370 }
|
|
371 else if (strcmp ((char *) data, lock_data))
|
|
372 {
|
|
373 sprintf (debug_buff, "%s: " MOZILLA_LOCK_PROP
|
|
374 " was stolen! Expected \"%s\", saw \"%s\"!\n",
|
|
375 progname, lock_data, data);
|
|
376 debug_print(debug_buff);
|
|
377 return;
|
|
378 }
|
|
379
|
|
380 if (data)
|
|
381 g_free(data);
|
|
382 }
|
|
383
|
|
384
|
|
385 static int
|
|
386 mozilla_remote_command (GdkWindow *window, const char *command,
|
|
387 Bool raise_p)
|
|
388 {
|
|
389 int result = 0;
|
|
390 Bool done = False;
|
|
391 char *new_command = 0;
|
|
392
|
|
393 /* The -noraise option is implemented by passing a "noraise" argument
|
|
394 to each command to which it should apply.
|
|
395 */
|
|
396 if (!raise_p)
|
|
397 {
|
|
398 char *close;
|
|
399 new_command = (char *) malloc (strlen (command) + 20);
|
|
400 strcpy (new_command, command);
|
|
401 close = strrchr (new_command, ')');
|
|
402 if (close)
|
|
403 strcpy (close, ", noraise)");
|
|
404 else
|
|
405 strcat (new_command, "(noraise)");
|
|
406 command = new_command;
|
|
407 }
|
|
408
|
|
409 sprintf (debug_buff, "%s: (writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x)\n",
|
|
410 progname, command, (unsigned int) window);
|
|
411 debug_print(debug_buff);
|
|
412
|
|
413 gdk_property_change(window, XA_MOZILLA_COMMAND, XA_STRING, 8,
|
|
414 GDK_PROP_MODE_REPLACE, (unsigned char *) command,
|
|
415 strlen (command));
|
|
416
|
|
417 while (!done) {
|
|
418 GdkEvent *event;
|
|
419
|
|
420 event = gdk_event_get();
|
|
421
|
|
422 if (!event)
|
|
423 continue;
|
|
424
|
|
425 if (event->any.window != window) {
|
|
426 gtk_main_do_event(event);
|
|
427 continue;
|
|
428 }
|
|
429
|
|
430 if (event->type == GDK_DESTROY &&
|
|
431 event->any.window == window) {
|
|
432
|
|
433 /* Print to warn user...*/
|
|
434 sprintf (debug_buff, "%s: window 0x%x was destroyed.\n",
|
|
435 progname, (unsigned int) window);
|
|
436 debug_print(debug_buff);
|
|
437 result = 6;
|
|
438 goto DONE;
|
|
439 } else if (event->type == GDK_PROPERTY_NOTIFY &&
|
|
440 event->property.state == GDK_PROPERTY_NEW_VALUE &&
|
|
441 event->property.window == window &&
|
|
442 event->property.atom == XA_MOZILLA_RESPONSE) {
|
|
443 GdkAtom actual_type;
|
|
444 gint actual_format, nitems;
|
|
445 unsigned char *data = 0;
|
|
446
|
|
447 result = gdk_property_get (window, XA_MOZILLA_RESPONSE,
|
|
448 XA_STRING, 0,
|
|
449 (65536 / sizeof (long)),
|
|
450 1,
|
|
451 &actual_type, &actual_format,
|
|
452 &nitems, &data);
|
|
453
|
|
454
|
|
455 if (result == Success && data && *data) {
|
|
456 sprintf (debug_buff, "%s: (server sent " MOZILLA_RESPONSE_PROP
|
|
457 " \"%s\" to 0x%x.)\n",
|
|
458 progname, data, (unsigned int) window);
|
|
459 debug_print(debug_buff);
|
|
460 }
|
|
461
|
|
462 if (result != Success) {
|
|
463 sprintf (debug_buff, "%s: failed reading " MOZILLA_RESPONSE_PROP
|
|
464 " from window 0x%0x.\n",
|
|
465 progname, (unsigned int) window);
|
|
466 debug_print(debug_buff);
|
|
467 result = 6;
|
|
468 done = True;
|
|
469 } else if (!data || strlen((char *) data) < 5) {
|
|
470 sprintf (debug_buff, "%s: invalid data on " MOZILLA_RESPONSE_PROP
|
|
471 " property of window 0x%0x.\n",
|
|
472 progname, (unsigned int) window);
|
|
473 debug_print(debug_buff);
|
|
474 result = 6;
|
|
475 done = True;
|
|
476 } else if (*data == '1') { /* positive preliminary reply */
|
|
477 sprintf (debug_buff, "%s: %s\n", progname, data + 4);
|
|
478 debug_print(debug_buff);
|
|
479 /* keep going */
|
|
480 done = False;
|
|
481 } else if (!strncmp ((char *)data, "200", 3)) {
|
|
482 result = 0;
|
|
483 done = True;
|
|
484 } else if (*data == '2') {
|
|
485 sprintf (debug_buff, "%s: %s\n", progname, data + 4);
|
|
486 debug_print(debug_buff);
|
|
487 result = 0;
|
|
488 done = True;
|
|
489 } else if (*data == '3') {
|
|
490 sprintf (debug_buff, "%s: internal error: "
|
|
491 "server wants more information? (%s)\n",
|
|
492 progname, data);
|
|
493 debug_print(debug_buff);
|
|
494 result = 3;
|
|
495 done = True;
|
|
496 } else if (*data == '4' || *data == '5') {
|
|
497 sprintf (debug_buff, "%s: %s\n", progname, data + 4);
|
|
498 debug_print(debug_buff);
|
|
499 result = (*data - '0');
|
|
500 done = True;
|
|
501 } else {
|
|
502 sprintf (debug_buff,
|
|
503 "%s: unrecognised " MOZILLA_RESPONSE_PROP
|
|
504 " from window 0x%x: %s\n",
|
|
505 progname, (unsigned int) window, data);
|
|
506 debug_print(debug_buff);
|
|
507 result = 6;
|
|
508 done = True;
|
|
509 }
|
|
510
|
|
511 if (data)
|
|
512 g_free(data);
|
|
513 }
|
|
514 else if (event->type == GDK_PROPERTY_NOTIFY &&
|
|
515 event->property.window == window &&
|
|
516 event->property.state == GDK_PROPERTY_DELETE &&
|
|
517 event->property.atom == XA_MOZILLA_COMMAND) {
|
|
518 sprintf (debug_buff, "%s: (server 0x%x has accepted "
|
|
519 MOZILLA_COMMAND_PROP ".)\n",
|
|
520 progname, (unsigned int) window);
|
|
521 debug_print(debug_buff);
|
|
522 }
|
|
523 gdk_event_free(event);
|
|
524 }
|
|
525
|
|
526 DONE:
|
|
527
|
|
528 if (new_command)
|
|
529 g_free (new_command);
|
|
530
|
|
531 return result;
|
|
532 }
|
|
533
|
|
534
|
|
535 gint check_netscape(char *msg)
|
|
536 {
|
|
537 int status;
|
|
538 GdkWindow *window;
|
|
539
|
|
540 mozilla_remote_init_atoms ();
|
|
541 window = mozilla_remote_find_window();
|
|
542
|
|
543 if (window) {
|
|
544
|
|
545 XSelectInput(gdk_display, ((GdkWindowPrivate *)window)->xwindow,
|
|
546 (PropertyChangeMask|StructureNotifyMask));
|
|
547
|
|
548
|
|
549 mozilla_remote_obtain_lock(window);
|
|
550
|
|
551 status = mozilla_remote_command(window, msg, False);
|
|
552
|
|
553 if (status != 6)
|
|
554 mozilla_remote_free_lock(window);
|
|
555
|
|
556 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
|
|
557
|
|
558 netscape_lock = 0;
|
|
559
|
|
560 g_free(msg);
|
|
561 return FALSE;
|
|
562 } else
|
|
563 return TRUE;
|
|
564 }
|
|
565
|
|
566
|
|
567 static void netscape_command(char *command)
|
|
568 {
|
|
569 int status;
|
|
570 pid_t pid;
|
|
571 GdkWindow *window;
|
|
572
|
|
573 if (netscape_lock)
|
|
574 return;
|
|
575
|
|
576 netscape_lock = 1;
|
|
577
|
|
578
|
|
579
|
|
580 mozilla_remote_init_atoms();
|
|
581 window = mozilla_remote_find_window();
|
|
582
|
|
583 if (window) {
|
|
584
|
|
585 XSelectInput(gdk_display, ((GdkWindowPrivate *)window)->xwindow,
|
|
586 (PropertyChangeMask|StructureNotifyMask));
|
|
587
|
|
588 mozilla_remote_obtain_lock(window);
|
|
589
|
|
590 status = mozilla_remote_command(window, command, False);
|
|
591
|
|
592 if (status != 6)
|
|
593 mozilla_remote_free_lock(window);
|
|
594
|
|
595 netscape_lock = 0;
|
|
596
|
|
597 } else {
|
|
598 pid = fork();
|
|
599 if (pid == 0) {
|
|
600 char *args[2];
|
|
601 int e;
|
|
602
|
|
603 args[0] = g_strdup("netscape");
|
|
604 args[1] = NULL;
|
|
605 e = execvp(args[0], args);
|
|
606 printf("Hello%d\n");
|
|
607
|
|
608 _exit(0);
|
|
609 } else {
|
|
610 char *tmp = g_strdup(command);
|
|
611 gtk_timeout_add(200, (GtkFunction)check_netscape, tmp);
|
|
612 }
|
|
613 }
|
|
614
|
|
615 }
|
|
616
|
|
617 void open_url(GtkWidget *w, char *url) {
|
|
618 if (web_browser == BROWSER_NETSCAPE) {
|
|
619 char *command = g_malloc(1024);
|
|
620
|
|
621 g_snprintf(command, 1024, "OpenURL(%s)", url);
|
|
622
|
|
623 netscape_command(command);
|
|
624 g_free(command);
|
|
625 } else if (web_browser == BROWSER_KFM) {
|
|
626 pid_t pid;
|
|
627
|
|
628 pid = fork();
|
|
629
|
|
630 if (pid == 0) {
|
|
631 char *args[4];
|
|
632
|
|
633 args[0] = g_strdup("kfmclient");
|
|
634 args[1] = g_strdup("openURL");
|
|
635 args[2] = url;;
|
|
636 args[3] = NULL;
|
|
637
|
|
638 execvp(args[0], args);
|
|
639 _exit(0);
|
|
640 } else {
|
|
641 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
|
|
642 }
|
|
643 } else if (web_browser == BROWSER_MANUAL) {
|
|
644 pid_t pid;
|
|
645
|
|
646 pid = fork();
|
|
647
|
|
648 if (pid == 0) {
|
|
649 char *args[4];
|
|
650
|
|
651 char command[1024];
|
|
652
|
|
653 g_snprintf(command, sizeof(command), web_command, url);
|
|
654
|
|
655 args[0] = "sh";
|
|
656 args[1] = "-c";
|
|
657 args[2] = command;
|
|
658 args[3] = NULL;
|
|
659
|
|
660 execvp(args[0], args);
|
|
661
|
|
662 _exit(0);
|
|
663 } else {
|
|
664 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
|
|
665 }
|
|
666 } else if (web_browser == BROWSER_INTERNAL) {
|
|
667 g_show_info(url);
|
|
668 }
|
|
669 }
|
|
670
|
|
671 void add_bookmark(GtkWidget *w, char *url) {
|
|
672 if (web_browser == BROWSER_NETSCAPE) {
|
|
673 char *command = g_malloc(1024);
|
|
674
|
|
675 g_snprintf(command, 1024, "AddBookmark(%s)", url);
|
|
676
|
|
677 netscape_command(command);
|
|
678 g_free(command);
|
|
679 }
|
|
680 }
|
|
681
|
|
682 void open_url_nw(GtkWidget *w, char *url) {
|
|
683 if (web_browser == BROWSER_NETSCAPE) {
|
|
684 char *command = g_malloc(1024);
|
|
685
|
|
686 g_snprintf(command, 1024, "OpenURL(%s, new-window)", url);
|
|
687
|
|
688 netscape_command(command);
|
|
689 g_free(command);
|
|
690 }
|
|
691 }
|
|
692
|
|
693 #else
|
|
694
|
|
695 /* Sooner or later, I shall support Windows clicking! */
|
|
696
|
|
697 void add_bookmark(GtkWidget *w, char *url) { }
|
|
698 void open_url_nw(GtkWidget *w, char *url) { }
|
|
699 void open_url(GtkWidget *w, char *url) { }
|
|
700
|
|
701
|
|
702 #endif _WIN32
|