From ccee0f7b75f490d22f134f9c7e03603c748fd7f1 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 2 Jun 2008 20:19:28 +0100 Subject: [PATCH] Opening files works again. We pass the pathname for files, or the full URI otherwise. --- ROX-Filer/src/run.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/ROX-Filer/src/run.c b/ROX-Filer/src/run.c index a5926bcb..efecc662 100644 --- a/ROX-Filer/src/run.c +++ b/ROX-Filer/src/run.c @@ -46,13 +46,13 @@ static void write_data(gpointer data, gint fd, GdkInputCondition cond); static gboolean follow_symlink(GFile *path, FilerWindow *filer_window, FilerWindow *src_window); -static gboolean open_file(const guchar *path, MIME_type *type); +static gboolean open_file(GFile *path, MIME_type *type); static void open_mountpoint(const guchar *full_path, DirItem *item, FilerWindow *filer_window, FilerWindow *src_window, gboolean edit); static gboolean run_desktop(const char *full_path, const char **args, const char *dir); -static gboolean type_open(const char *path, MIME_type *type); +static gboolean type_open(GFile *path, MIME_type *type); typedef struct _PipedData PipedData; @@ -301,22 +301,28 @@ gboolean run_diritem_gfile(GFile *path, case TYPE_FILE: if (EXECUTABLE_FILE(item) && !edit) { + gboolean retval; const char *argv[] = {NULL, NULL}; + char *arg; guchar *dir = filer_window ? filer_window->sym_path : NULL; if (item->mime_type == application_x_desktop) - return run_desktop(full_path, - NULL, dir); - else - argv[0] = full_path; + return run_desktop(full_path, NULL, dir); - return rox_spawn(dir, argv) != 0; + arg = g_file_get_path(path); + if (arg == NULL) + arg = g_file_get_uri(path); + + argv[0] = arg; + retval = rox_spawn(dir, argv) != 0; + g_free(arg); + + return retval; } - return open_file(full_path, edit ? text_plain - : item->mime_type); + return open_file(path, edit ? text_plain : item->mime_type); case TYPE_ERROR: delayed_error(_("File doesn't exist, or I can't " "access it: %s"), full_path); @@ -580,7 +586,7 @@ static gboolean follow_symlink(GFile *path, } /* Load this file into an appropriate editor */ -static gboolean open_file(const guchar *path, MIME_type *type) +static gboolean open_file(GFile *path, MIME_type *type) { g_return_val_if_fail(type != NULL, FALSE); @@ -743,15 +749,23 @@ err: return success; } +static char *path_or_uri(GFile *path) +{ + char *retval; + + retval = g_file_get_path(path); + if (retval == NULL) + retval = g_file_get_uri(path); + return retval; +} + /* Returns FALSE is no run action is set for this type. */ -static gboolean type_open(const char *path, MIME_type *type) +static gboolean type_open(GFile *path, MIME_type *type) { gchar *argv[] = {NULL, NULL, NULL}; char *open; struct stat info; - argv[1] = (char *) path; - open = handler_for(type); if (!open) return FALSE; @@ -788,6 +802,8 @@ static gboolean type_open(const char *path, MIME_type *type) return TRUE; } + argv[1] = path_or_uri(path); + if (S_ISDIR(info.st_mode)) { argv[0] = g_strconcat(open, "/AppRun", NULL); @@ -804,6 +820,8 @@ static gboolean type_open(const char *path, MIME_type *type) rox_spawn(home_dir, (const gchar **) argv); } + g_free(argv[1]); + if (argv[0] != open) g_free(argv[0]); -- 2.11.4.GIT