From a5dfe03ccbf8e2ba9e0098ad8fcff0961f99ded1 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 21 Jul 2005 18:41:28 +0000 Subject: [PATCH] r4024: Replaced the text the Options box telling people to download and run MIME-Editor with a button that actually does it (Thomas Leonard). --- ROX-Filer/Help/Changes | 5 +++++ ROX-Filer/Options.xml | 7 +++--- ROX-Filer/src/main.c | 51 ++++++++++++++++++++++++++++++++++++++++++ ROX-Filer/src/support.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ ROX-Filer/src/support.h | 1 + 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 18967c09..eecd497f 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,11 @@ A RISC OS-like filer for X by Thomas Leonard +21-Jul-2005 +~~~~~~~~~~~ +Replaced the text the Options box telling people to download and run +MIME-Editor with a button that actually does it (Thomas Leonard). + 17-Jul-2005 ~~~~~~~~~~~ Bugfix: Opening a new filer window with a key press warped the pointer diff --git a/ROX-Filer/Options.xml b/ROX-Filer/Options.xml index 34a219b5..5497bcae 100644 --- a/ROX-Filer/Options.xml +++ b/ROX-Filer/Options.xml @@ -312,10 +312,11 @@ xterm -e wget $1
- - + + + diff --git a/ROX-Filer/src/main.c b/ROX-Filer/src/main.c index 03cb9b61..c6f9d916 100644 --- a/ROX-Filer/src/main.c +++ b/ROX-Filer/src/main.c @@ -198,6 +198,7 @@ static void child_died_callback(void); static void wake_up_cb(gpointer data, gint source, GdkInputCondition condition); static void xrandr_size_change(GdkScreen *screen, gpointer user_data); static void add_default_panel_and_pinboard(xmlNodePtr body); +static GList *build_launch(Option *option, xmlNode *node, guchar *label); /**************************************************************** * EXTERNAL INTERFACE * @@ -335,6 +336,7 @@ int main(int argc, char **argv) "Default"); option_add_string(&o_session_pinboard_name, "session_pinboard_name", "Default"); + option_register_widget("launch", build_launch); /* The idea here is to convert the command-line arguments * into a SOAP RPC. @@ -812,3 +814,52 @@ static void add_default_panel_and_pinboard(xmlNodePtr body) soap_add(body, "Panel", "Name", name, NULL, NULL); } } + +static void do_launch(GObject *button, gpointer data) +{ + char *uri; + const char *argv[] = {"0launch", NULL, NULL}; + const char *uri_0launch = "/uri/0install/zero-install.sourceforge.net" + "/bin/0launch"; + + uri = g_object_get_data(button, "rox-uri"); + g_return_if_fail(uri != NULL); + + if (!available_in_path(argv[0])) + { + if (access(uri_0launch, X_OK) == 0) + argv[0] = uri_0launch; + else + { + delayed_error("This program cannot be run, as the " + "0launch command is not available. " + "It can be downloaded from here:\n\n" + "http://0install.net/injector.html"); + return; + } + } + + argv[1] = uri; + rox_spawn(NULL, argv); +} + +static GList *build_launch(Option *option, xmlNode *node, guchar *label) +{ + GtkWidget *button, *align; + char *uri; + + g_return_val_if_fail(option == NULL, NULL); + g_return_val_if_fail(label != NULL, NULL); + + uri = xmlGetProp(node, "uri"); + + g_return_val_if_fail(uri != NULL, NULL); + + align = gtk_alignment_new(0, 0.5, 0, 0); + button = button_new_mixed(GTK_STOCK_PREFERENCES, label); + g_object_set_data_full(G_OBJECT(button), "rox-uri", uri, g_free); + gtk_container_add(GTK_CONTAINER(align), button); + g_signal_connect(button, "clicked", G_CALLBACK(do_launch), NULL); + + return g_list_append(NULL, align); +} diff --git a/ROX-Filer/src/support.c b/ROX-Filer/src/support.c index e895fd1e..c0e10d05 100644 --- a/ROX-Filer/src/support.c +++ b/ROX-Filer/src/support.c @@ -1413,3 +1413,62 @@ int stat_with_timeout(const char *path, struct stat *info) return retval; } + +/* From glib. */ +static gchar *my_strchrnul(const gchar *str, gchar c) +{ + gchar *p = (gchar*) str; + while (*p && (*p != c)) + ++p; + + return p; +} + +/* Based on code from glib. */ +gboolean available_in_path(const char *file) +{ + const gchar *path, *p; + gchar *name, *freeme; + size_t len; + size_t pathlen; + gboolean found = FALSE; + + path = g_getenv("PATH"); + if (path == NULL) + path = "/bin:/usr/bin:."; + + len = strlen(file) + 1; + pathlen = strlen(path); + freeme = name = g_malloc(pathlen + len + 1); + + /* Copy the file name at the top, including '\0' */ + memcpy(name + pathlen + 1, file, len); + name = name + pathlen; + /* And add the slash before the filename */ + *name = '/'; + + p = path; + do + { + char *startp; + + path = p; + p = my_strchrnul(path, ':'); + + if (p == path) + /* Two adjacent colons, or a colon at the beginning or the end + * of `PATH' means to search the current directory. + */ + startp = name + 1; + else + startp = memcpy (name - (p - path), path, p - path); + + /* Try to execute this name. If it works, execv will not return. */ + if (access(startp, X_OK) == 0) + found = TRUE; + } while (!found && *p++ != '\0'); + + g_free(freeme); + + return found; +} diff --git a/ROX-Filer/src/support.h b/ROX-Filer/src/support.h index fcea2ce0..1b0a9bf8 100644 --- a/ROX-Filer/src/support.h +++ b/ROX-Filer/src/support.h @@ -58,5 +58,6 @@ int stat_with_timeout(const char *path, struct stat *info); EscapedPath *escape_uri_path(const char *path); EscapedPath *encode_path_as_uri(const guchar *path); gchar *unescape_uri(const EscapedPath *uri); +gboolean available_in_path(const char *file); #endif /* _SUPPORT_H */ -- 2.11.4.GIT