| Yattm - unified GTK instant-messaging client | ![]() |
| [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003] |
#include "intl.h"#include <stdio.h>#include <string.h>#include <gdk/gdkx.h>#include <stdlib.h>#include <gdk/gdkprivate.h>#include "dialog.h"#include "util.h"#include "gtk_globals.h"#include "prefs.h"#include <X11/Xlib.h>#include <X11/Xatom.h>Include dependency graph for browser.c:

Go to the source code of this file.
Defines | |
| #define | MOZILLA_VERSION_PROP "_MOZILLA_VERSION" |
| #define | MOZILLA_LOCK_PROP "_MOZILLA_LOCK" |
| #define | MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND" |
| #define | MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE" |
Enumerations | |
| enum | { BROWSER_NETSCAPE, BROWSER_KFM, BROWSER_MANUAL, BROWSER_INTERNAL } |
Functions | |
| Window | VirtualRootWindowOfScreen (screen) Screen *screen |
| Window | GClientWindow (dpy, win) Display *dpy |
| void | mozilla_remote_obtain_lock (GdkWindow *window) |
| void | mozilla_remote_free_lock (GdkWindow *window) |
| int | mozilla_remote_command (GdkWindow *window, const char *command, Bool raise_p) |
| gint | check_netscape (char *msg) |
| void | netscape_command (char *command) |
| void | open_url (GtkWidget *w, char *url) |
| void | add_bookmark (GtkWidget *w, char *url) |
| void | open_url_nw (GtkWidget *w, char *url) |
Variables | |
| gint | web_browser = BROWSER_NETSCAPE |
| const char * | expected_mozilla_version = "1.1" |
| GdkAtom | XA_MOZILLA_VERSION = 0 |
| GdkAtom | XA_MOZILLA_LOCK = 0 |
| GdkAtom | XA_MOZILLA_COMMAND = 0 |
| GdkAtom | XA_MOZILLA_RESPONSE = 0 |
| int | netscape_lock |
| Window | win |
| Atom | WM_STATE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 49 of file browser.c.
00050 {
00051 BROWSER_NETSCAPE,
00052 BROWSER_KFM,
00053 BROWSER_MANUAL,
00054 BROWSER_INTERNAL
00055 };
|
|
||||||||||||
|
Definition at line 579 of file browser.c. References BROWSER_NETSCAPE, netscape_command(), and web_browser.
00579 {
00580 if (web_browser == BROWSER_NETSCAPE) {
00581 char *command = g_malloc(1024);
00582
00583 g_snprintf(command, 1024, "AddBookmark(%s)", url);
00584
00585 netscape_command(command);
00586 g_free(command);
00587 }
00588 }
|
|
|
Definition at line 469 of file browser.c. References mozilla_remote_command(), mozilla_remote_free_lock(), mozilla_remote_obtain_lock(), and netscape_lock. Referenced by netscape_command().
00470 {
00471 int status;
00472 GdkWindow *window;
00473
00474 mozilla_remote_init_atoms ();
00475 window = mozilla_remote_find_window();
00476
00477 if (window) {
00478
00479 XSelectInput(gdk_display, ((GdkWindowPrivate *)window)->xwindow,
00480 (PropertyChangeMask|StructureNotifyMask));
00481
00482
00483 mozilla_remote_obtain_lock(window);
00484
00485 status = mozilla_remote_command(window, msg, False);
00486
00487 if (status != 6)
00488 mozilla_remote_free_lock(window);
00489
00490 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
00491
00492 netscape_lock = 0;
00493
00494 g_free(msg);
00495 return FALSE;
00496 } else
00497 return TRUE;
00498 }
|
|
||||||||||||
|
|
|
||||||||||||||||
|
Definition at line 359 of file browser.c. References XA_MOZILLA_COMMAND, and XA_MOZILLA_RESPONSE. Referenced by check_netscape(), and netscape_command().
00361 {
00362 int result = 0;
00363 Bool done = False;
00364 char *new_command = 0;
00365
00366 /* The -noraise option is implemented by passing a "noraise" argument
00367 to each command to which it should apply.
00368 */
00369 if (!raise_p)
00370 {
00371 char *close;
00372 new_command = (char *) malloc (strlen (command) + 20);
00373 strcpy (new_command, command);
00374 close = strrchr (new_command, ')');
00375 if (close)
00376 strcpy (close, ", noraise)");
00377 else
00378 strcat (new_command, "(noraise)");
00379 command = new_command;
00380 }
00381
00382
00383 gdk_property_change(window, XA_MOZILLA_COMMAND, XA_STRING, 8,
00384 GDK_PROP_MODE_REPLACE, (unsigned char *) command,
00385 strlen (command));
00386
00387 while (!done) {
00388 GdkEvent *event;
00389
00390 event = gdk_event_get();
00391
00392 if (!event)
00393 continue;
00394
00395 if (event->any.window != window) {
00396 gtk_main_do_event(event);
00397 continue;
00398 }
00399
00400 if (event->type == GDK_DESTROY &&
00401 event->any.window == window) {
00402
00403 /* Print to warn user...*/
00404 result = 6;
00405 goto DONE;
00406 } else if (event->type == GDK_PROPERTY_NOTIFY &&
00407 event->property.state == GDK_PROPERTY_NEW_VALUE &&
00408 event->property.window == window &&
00409 event->property.atom == XA_MOZILLA_RESPONSE) {
00410 GdkAtom actual_type;
00411 gint actual_format, nitems;
00412 unsigned char *data = 0;
00413
00414 result = gdk_property_get (window, XA_MOZILLA_RESPONSE,
00415 XA_STRING, 0,
00416 (65536 / sizeof (long)),
00417 1,
00418 &actual_type, &actual_format,
00419 &nitems, &data);
00420
00421
00422 if (result == Success && data && *data) {
00423 }
00424
00425 if (result != Success) {
00426 result = 6;
00427 done = True;
00428 } else if (!data || strlen((char *) data) < 5) {
00429 result = 6;
00430 done = True;
00431 } else if (*data == '1') { /* positive preliminary reply */
00432 } else if (!strncmp ((char *)data, "200", 3)) {
00433 result = 0;
00434 done = True;
00435 } else if (*data == '2') {
00436 result = 0;
00437 done = True;
00438 } else if (*data == '3') {
00439 result = 3;
00440 done = True;
00441 } else if (*data == '4' || *data == '5') {
00442 result = (*data - '0');
00443 done = True;
00444 } else {
00445 result = 6;
00446 done = True;
00447 }
00448
00449 if (data)
00450 g_free(data);
00451 }
00452 else if (event->type == GDK_PROPERTY_NOTIFY &&
00453 event->property.window == window &&
00454 event->property.state == GDK_PROPERTY_DELETE &&
00455 event->property.atom == XA_MOZILLA_COMMAND) {
00456 }
00457 gdk_event_free(event);
00458 }
00459
00460 DONE:
00461
00462 if (new_command)
00463 g_free (new_command);
00464
00465 return result;
00466 }
|
|
|
Definition at line 327 of file browser.c. References XA_MOZILLA_LOCK. Referenced by check_netscape(), and netscape_command().
00328 {
00329 int result = 0;
00330 GdkAtom actual_type;
00331 gint actual_format;
00332 gint nitems;
00333 unsigned char *data = 0;
00334
00335
00336 result = gdk_property_get(window, XA_MOZILLA_LOCK, XA_STRING,
00337 0, (65536 / sizeof (long)),
00338 1, &actual_type, &actual_format,
00339 &nitems, &data);
00340 if (result != Success)
00341 {
00342 return;
00343 }
00344 else if (!data || !*data)
00345 {
00346 return;
00347 }
00348 else if (strcmp ((char *) data, lock_data))
00349 {
00350 return;
00351 }
00352
00353 if (data)
00354 g_free(data);
00355 }
|
|
|
Definition at line 280 of file browser.c. References XA_MOZILLA_LOCK. Referenced by check_netscape(), and netscape_command().
00281 {
00282 Bool locked = False;
00283
00284 if (!lock_data) {
00285 lock_data = (char *)g_malloc (255);
00286 sprintf (lock_data, "pid%d@", getpid ());
00287 if (gethostname (lock_data + strlen (lock_data), 100)) {
00288 return;
00289 }
00290 }
00291
00292 do {
00293 int result;
00294 GdkAtom actual_type;
00295 gint actual_format;
00296 gint nitems;
00297 unsigned char *data = 0;
00298
00299 result = gdk_property_get (window, XA_MOZILLA_LOCK,
00300 XA_STRING, 0,
00301 (65536 / sizeof (long)), 0,
00302 &actual_type, &actual_format,
00303 &nitems, &data);
00304 if (result != Success || actual_type == None)
00305 {
00306 /* It's not now locked - lock it. */
00307
00308 gdk_property_change(window, XA_MOZILLA_LOCK, XA_STRING,
00309 8, PropModeReplace,
00310 (unsigned char *) lock_data,
00311 strlen (lock_data));
00312 locked = True;
00313 }
00314
00315 if (!locked) {
00316 /* Then just fuck it. */
00317 if (data)
00318 g_free(data);
00319 return;
00320 }
00321 if (data)
00322 g_free(data);
00323 } while (!locked);
00324 }
|
|
|
Definition at line 501 of file browser.c. References check_netscape(), mozilla_remote_command(), mozilla_remote_free_lock(), mozilla_remote_obtain_lock(), and netscape_lock. Referenced by add_bookmark(), open_url(), and open_url_nw().
00502 {
00503 int status;
00504 pid_t pid;
00505 GdkWindow *window;
00506
00507 if (netscape_lock)
00508 return;
00509
00510 netscape_lock = 1;
00511
00512
00513
00514 mozilla_remote_init_atoms();
00515 window = mozilla_remote_find_window();
00516
00517 if (window) {
00518
00519 XSelectInput(gdk_display, ((GdkWindowPrivate *)window)->xwindow,
00520 (PropertyChangeMask|StructureNotifyMask));
00521
00522 mozilla_remote_obtain_lock(window);
00523
00524 status = mozilla_remote_command(window, command, False);
00525
00526 if (status != 6)
00527 mozilla_remote_free_lock(window);
00528
00529 netscape_lock = 0;
00530
00531 } else {
00532 pid = fork();
00533 if (pid == 0) {
00534 char *args[2];
00535 int e;
00536
00537 args[0] = g_strdup("netscape");
00538 args[1] = NULL;
00539 e = execvp(args[0], args);
00540
00541 _exit(0);
00542 } else {
00543 char *tmp = g_strdup(command);
00544 gtk_timeout_add(200, (GtkFunction)check_netscape, tmp);
00545 }
00546 }
00547
00548 }
|
|
||||||||||||
|
Definition at line 550 of file browser.c. References BROWSER_KFM, BROWSER_NETSCAPE, netscape_command(), and web_browser.
00550 {
00551 if (web_browser == BROWSER_NETSCAPE) {
00552 char *command = g_malloc(1024);
00553
00554 g_snprintf(command, 1024, "OpenURL(%s)", url);
00555
00556 netscape_command(command);
00557 g_free(command);
00558 } else if (web_browser == BROWSER_KFM) {
00559 pid_t pid;
00560
00561 pid = fork();
00562
00563 if (pid == 0) {
00564 char *args[4];
00565
00566 args[0] = g_strdup("kfmclient");
00567 args[1] = g_strdup("openURL");
00568 args[2] = url;;
00569 args[3] = NULL;
00570
00571 execvp(args[0], args);
00572 _exit(0);
00573 } else {
00574 gtk_timeout_add(1000, (GtkFunction)clean_pid, NULL);
00575 }
00576 }
00577 }
|
|
||||||||||||
|
Definition at line 590 of file browser.c. References BROWSER_NETSCAPE, cGetLocalPref(), DBG_CORE, eb_debug, netscape_command(), and web_browser. Referenced by handle_click(), show_manual(), and show_website().
00590 {
00591 char *alternate_browser=cGetLocalPref("alternate_browser");
00592 if ((use_alternate_browser == 1) && (strlen(alternate_browser) > 0)) {
00593 char *command = g_malloc(1024);
00594 char *url_pos = strstr(alternate_browser, "%s");
00595 /*
00596 * if alternate_browser contains a %s, then we put
00597 * the url in place of the %s, else, put the url
00598 * at the end.
00599 */
00600 if(url_pos) {
00601 int pre_len = url_pos-alternate_browser;
00602 strncpy(command, alternate_browser, pre_len);
00603 command[pre_len] = 0;
00604 strncat(command, url, 1024 - pre_len);
00605 strncat(command, url_pos+2, 1024 - strlen(command));
00606 strncat(command, " &", 1024 - strlen(command));
00607 } else
00608 g_snprintf(command, 1024, "%s \"%s\" &", alternate_browser, url);
00609 eb_debug(DBG_CORE, "launching %s\n", command);
00610 system(command);
00611 g_free(command);
00612 } else if (web_browser == BROWSER_NETSCAPE) {
00613 char *command = g_malloc(1024);
00614 g_snprintf(command, 1024, "OpenURL(%s, new-window)", url);
00615
00616 netscape_command(command);
00617 g_free(command);
00618 }
00619 }
|
|
|
|
|
|
|
|
|
Definition at line 82 of file browser.c. Referenced by check_netscape(), and netscape_command(). |
|
|
Definition at line 58 of file browser.c. Referenced by add_bookmark(), open_url(), and open_url_nw(). |
|
|
|
|
|
|
|
|
Definition at line 78 of file browser.c. Referenced by mozilla_remote_command(). |
|
|
Definition at line 77 of file browser.c. Referenced by mozilla_remote_free_lock(), and mozilla_remote_obtain_lock(). |
|
|
Definition at line 79 of file browser.c. Referenced by mozilla_remote_command(). |
|
|
|