#include <math.h>
+#ifdef G_OS_UNIX
+#include <pwd.h>
+#endif
static RemoteConnection *remote_connection = NULL;
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
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);
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)