# HG changeset patch # User zas_ # Date 1210694983 0 # Node ID e06947d0708694b5f57f684a00c04ea74c0d154d # Parent 9bcfd6d7a902aa12fc19d11fd8ba40524b1eb451 Expand tilde with file: and view: remote parameters. Now these are working: geeqie -r file:~/dir geeqie -r view:~user/file diff -r 9bcfd6d7a902 -r e06947d07086 src/main.c --- a/src/main.c Tue May 13 14:49:38 2008 +0000 +++ b/src/main.c Tue May 13 16:09:43 2008 +0000 @@ -45,6 +45,9 @@ #include +#ifdef G_OS_UNIX +#include +#endif static RemoteConnection *remote_connection = NULL; @@ -81,6 +84,54 @@ return text; } +/* Borrowed from gtkfilesystemunix.c */ +gchar *expand_tilde(const gchar *filename) +{ +#ifndef G_OS_UNIX + return g_strdup(filename); +#else + const char *notilde; + const char *slash; + const char *home; + + if (filename[0] != '~') + return g_strdup(filename); + + notilde = filename + 1; + slash = strchr(notilde, G_DIR_SEPARATOR); + if (slash == notilde || !*notilde) + { + home = g_get_home_dir(); + if (!home) + return g_strdup(filename); + } + else + { + gchar *username; + struct passwd *passwd; + + if (slash) + username = g_strndup(notilde, slash - notilde); + else + username = g_strdup(notilde); + + passwd = getpwnam(username); + g_free(username); + + if (!passwd) + return g_strdup(filename); + + home = passwd->pw_dir; + } + + if (slash) + return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL); + else + return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); +#endif +} + + /* *----------------------------------------------------------------------------- * keyboard functions diff -r 9bcfd6d7a902 -r e06947d07086 src/main.h --- a/src/main.h Tue May 13 14:49:38 2008 +0000 +++ b/src/main.h Tue May 13 16:09:43 2008 +0000 @@ -126,6 +126,7 @@ gdouble get_zoom_increment(void); gchar *utf8_validate_or_convert(gchar *text); +gchar *expand_tilde(const gchar *filename); void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event); gint key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data); diff -r 9bcfd6d7a902 -r e06947d07086 src/remote.c --- a/src/remote.c Tue May 13 14:49:38 2008 +0000 +++ b/src/remote.c Tue May 13 16:09:43 2008 +0000 @@ -475,30 +475,37 @@ static void gr_file_load(const gchar *text, gpointer data) { - if (isfile(text)) + gchar *filename = expand_tilde(text); + + if (isfile(filename)) { - if (file_extension_match(text, ".gqv")) + if (file_extension_match(filename, ".gqv")) { - collection_window_new(text); + collection_window_new(filename); } else { - layout_set_path(NULL, text); + layout_set_path(NULL, filename); } } - else if (isdir(text)) + else if (isdir(filename)) { - layout_set_path(NULL, text); + layout_set_path(NULL, filename); } else { - printf("remote sent filename that does not exist:\"%s\"\n", text); + printf("remote sent filename that does not exist:\"%s\"\n", filename); } + + g_free(filename); } static void gr_file_view(const gchar *text, gpointer data) { - view_window_new(file_data_new_simple(text)); + gchar *filename = expand_tilde(text); + + view_window_new(file_data_new_simple(filename)); + g_free(filename); } static void gr_list_clear(const gchar *text, gpointer data)