r3259 - software/ui/src
Miriam Ruiz
baby-guest at alioth.debian.org
Fri Jul 6 20:40:18 UTC 2007
Author: baby-guest
Date: 2007-07-06 20:40:18 +0000 (Fri, 06 Jul 2007)
New Revision: 3259
Modified:
software/ui/src/common.h
software/ui/src/pkgbrowser.cpp
Log:
web links spawn external browser now
Modified: software/ui/src/common.h
===================================================================
--- software/ui/src/common.h 2007-07-06 19:36:41 UTC (rev 3258)
+++ software/ui/src/common.h 2007-07-06 20:40:18 UTC (rev 3259)
@@ -60,4 +60,6 @@
#include <stdlib.h>
#include <stdio.h>
+#define ERROR_PRINTF(...) { fprintf(stderr, "%s:%s:%u Error: ", __FILE__, __PRETTY_FUNCTION__, __LINE__); fprintf(stderr,__VA_ARGS__); fflush(stderr); }
+
#endif
Modified: software/ui/src/pkgbrowser.cpp
===================================================================
--- software/ui/src/pkgbrowser.cpp 2007-07-06 19:36:41 UTC (rev 3258)
+++ software/ui/src/pkgbrowser.cpp 2007-07-06 20:40:18 UTC (rev 3259)
@@ -44,6 +44,12 @@
#include <limits.h>
#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_BMP_Image.H>
@@ -488,8 +494,37 @@
link(PackageView::link_cb);
}
+static bool ExternalBrowser(const char *uri)
+{
+ pid_t pid = -1;
+ if ((pid=fork()) == -1)
+ {
+ ERROR_PRINTF("fork: %s\n", strerror(errno));
+ return false;
+ }
+
+ if (strchr(uri, '"')) return false; /* No "s allowed in the uri for the moment */
+
+ if (pid) /* A positive (non-negative) PID indicates the parent process */
+ return true;
+
+ /* A zero PID indicates that this is the child process */
+ string command = string("/usr/bin/x-www-browser \"") + uri +"\"";
+ if (execl("/bin/sh", "sh", "-c", command.c_str(), (char *) 0) == -1)
+ ERROR_PRINTF("exec: %s\n", strerror(errno));
+
+ exit(1); /* This point should never be reached */
+}
+
const char *PackageView::link_cb(Fl_Widget *w, const char *uri)
{
printf("PackageView::link_cb(): Widget=0x%lX, URI=\"%s\"\n", (unsigned long)w, uri);
+
+ if (!strncasecmp("http:", uri, 5) || !strncasecmp("mailto:", uri, 7) ||
+ !strncasecmp("ftp:", uri, 4) || !strncasecmp("https:", uri, 6))
+ {
+ ExternalBrowser(uri);
+ }
+
return NULL;
}
More information about the Pkg-games-commits
mailing list