Skip to content

Commit

Permalink
Expand tilde with file: and view: remote parameters.
Browse files Browse the repository at this point in the history
Now these are working:
geeqie -r file:~/dir
geeqie -r view:~user/file
  • Loading branch information
Laurent Monin committed May 13, 2008
1 parent 38975e5 commit 86ebde9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
51 changes: 51 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@


#include <math.h>
#ifdef G_OS_UNIX
#include <pwd.h>
#endif


static RemoteConnection *remote_connection = NULL;
Expand Down Expand Up @@ -81,6 +84,54 @@ gchar *utf8_validate_or_convert(gchar *text)
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
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 15 additions & 8 deletions src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,30 +475,37 @@ static void gr_quit(const gchar *text, 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)
Expand Down

0 comments on commit 86ebde9

Please sign in to comment.