[Xfce4-commits] <gigolo:master> Expand tilde in folder names if a username is set for the bookmark

Enrico Tröger noreply at xfce.org
Mon Jan 18 00:04:04 CET 2010


Updating branch refs/heads/master
         to 7904194c58633270be180e54f660dc62aea778a1 (commit)
       from 0ec84f42a1dc3184cab04348b9b0147d95bc4203 (commit)

commit 7904194c58633270be180e54f660dc62aea778a1
Author: Enrico Tröger <enrico at xfce.org>
Date:   Sun Jan 17 23:58:16 2010 +0100

    Expand tilde in folder names if a username is set for the bookmark

 src/bookmark.c           |   19 +++++++++++++++++++
 src/bookmark.h           |    1 +
 src/bookmarkeditdialog.c |    2 --
 src/window.c             |   12 ++++++++++--
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/bookmark.c b/src/bookmark.c
index 12c701f..9df9282 100644
--- a/src/bookmark.c
+++ b/src/bookmark.c
@@ -430,6 +430,25 @@ const gchar *gigolo_bookmark_get_folder(GigoloBookmark *bookmark)
 }
 
 
+gchar *gigolo_bookmark_get_folder_expanded(GigoloBookmark *bookmark)
+{
+	const gchar *folder;
+	const gchar *username;
+	gchar *result;
+
+	g_return_val_if_fail(bookmark != NULL, NULL);
+
+	folder = GIGOLO_BOOKMARK_GET_PRIVATE(bookmark)->folder;
+	username = gigolo_bookmark_get_user(bookmark);
+	if (NZV(folder) && username && folder[0] == '~')
+		result = g_strconcat("/home/", username, folder + 1, NULL);
+	else
+		result = g_strdup(folder);
+
+	return result;
+}
+
+
 void gigolo_bookmark_set_folder(GigoloBookmark *bookmark, const gchar *folder)
 {
 	GigoloBookmarkPrivate *priv;
diff --git a/src/bookmark.h b/src/bookmark.h
index 4c8ca56..7b82bd9 100644
--- a/src/bookmark.h
+++ b/src/bookmark.h
@@ -67,6 +67,7 @@ void				gigolo_bookmark_set_host		(GigoloBookmark *bookmark, const gchar *host);
 
 const gchar*		gigolo_bookmark_get_folder		(GigoloBookmark *bookmark);
 void				gigolo_bookmark_set_folder		(GigoloBookmark *bookmark, const gchar *folder);
+gchar*				gigolo_bookmark_get_folder_expanded(GigoloBookmark *bookmark);
 
 const gchar*		gigolo_bookmark_get_path		(GigoloBookmark *bookmark);
 void				gigolo_bookmark_set_path		(GigoloBookmark *bookmark, const gchar *path);
diff --git a/src/bookmarkeditdialog.c b/src/bookmarkeditdialog.c
index 3b1bf29..1b1398d 100644
--- a/src/bookmarkeditdialog.c
+++ b/src/bookmarkeditdialog.c
@@ -276,7 +276,6 @@ gint gigolo_bookmark_edit_dialog_run(GigoloBookmarkEditDialog *dialog)
 				if (tmp[0] == '/')
 				{	/* remove leading slashes */
 					gtk_entry_set_text(GTK_ENTRY(priv->path_entry), tmp + 1);
-
 				}
 			}
 			if (! error && gtk_widget_get_parent(priv->share_entry) != NULL)
@@ -285,7 +284,6 @@ gint gigolo_bookmark_edit_dialog_run(GigoloBookmarkEditDialog *dialog)
 				if (tmp[0] == '/')
 				{	/* remove leading slashes */
 					gtk_entry_set_text(GTK_ENTRY(priv->share_entry), tmp + 1);
-
 				}
 			}
 			if (! error)
diff --git a/src/window.c b/src/window.c
index f9b5a93..d5decd4 100644
--- a/src/window.c
+++ b/src/window.c
@@ -500,7 +500,11 @@ static void action_copy_uri_cb(G_GNUC_UNUSED GtkAction *action, GigoloWindow *wi
 
 			b = gigolo_settings_get_bookmark_by_uri(priv->settings, uri);
 			if (b != NULL)
-				setptr(uri, g_build_filename(uri, gigolo_bookmark_get_folder(b), NULL));
+			{
+				gchar *folder = gigolo_bookmark_get_folder_expanded(b);
+				setptr(uri, g_build_filename(uri, folder, NULL));
+				g_free(folder);
+			}
 
 			gtk_clipboard_set_text(gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE)), uri, -1);
 
@@ -536,7 +540,11 @@ static void action_open_cb(G_GNUC_UNUSED GtkAction *action, GigoloWindow *window
 			gigolo_backend_gvfs_get_name_and_uri_from_mount(mnt, NULL, &uri);
 			b = gigolo_settings_get_bookmark_by_uri(priv->settings, uri);
 			if (b != NULL)
-				setptr(uri, g_build_filename(uri, gigolo_bookmark_get_folder(b), NULL));
+			{
+				gchar *folder = gigolo_bookmark_get_folder_expanded(b);
+				setptr(uri, g_build_filename(uri, folder, NULL));
+				g_free(folder);
+			}
 			/* escape spaces and similar */
 			setptr(uri, g_uri_unescape_string(uri, G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO));
 



More information about the Xfce4-commits mailing list