[gvfs] Add "default location" support for mounts
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gvfs] Add "default location" support for mounts
- Date: Thu, 26 Nov 2009 15:29:46 +0000 (UTC)
commit 6ad0cb9175acc635057232fec96d32eaad4e0237
Author: Christian Kellner <gicmo gnome org>
Date: Fri Oct 9 17:07:46 2009 +0200
Add "default location" support for mounts
The "default location" of the given mount is a path that reflects
the main entry point for the user (e.g. the home directory, or the
root of the volume).
Backends can use g_vfs_backend_set_default_location () to set the
default location (before registering the mount).
https://bugzilla.gnome.org/show_bug.cgi?id=561998
client/gdaemonmount.c | 14 ++++++++++++++
common/gmounttracker.c | 14 ++++++++++++--
common/gmounttracker.h | 1 +
daemon/gvfsbackend.c | 34 ++++++++++++++++++++++++++++++++++
daemon/gvfsbackend.h | 3 +++
daemon/mount.c | 18 +++++++++++++++---
programs/gvfs-mount.c | 11 ++++++++++-
7 files changed, 89 insertions(+), 6 deletions(-)
---
diff --git a/client/gdaemonmount.c b/client/gdaemonmount.c
index 2f7e2d6..1f0e4c2 100644
--- a/client/gdaemonmount.c
+++ b/client/gdaemonmount.c
@@ -130,6 +130,19 @@ g_daemon_mount_get_name (GMount *mount)
return g_strdup (daemon_mount->mount_info->display_name);
}
+static GFile *
+g_daemon_mount_get_default_location (GMount *mount)
+{
+ GDaemonMount *daemon_mount = G_DAEMON_MOUNT (mount);
+ const char *location = daemon_mount->mount_info->default_location;
+
+ if (location == NULL || location[0] == '\0')
+ location = daemon_mount->mount_info->mount_spec->mount_prefix;
+
+ return g_daemon_file_new (daemon_mount->mount_info->mount_spec,
+ location);
+}
+
static char *
g_daemon_mount_get_uuid (GMount *mount)
{
@@ -301,6 +314,7 @@ g_daemon_mount_mount_iface_init (GMountIface *iface)
iface->get_uuid = g_daemon_mount_get_uuid;
iface->get_volume = g_daemon_mount_get_volume;
iface->get_drive = g_daemon_mount_get_drive;
+ iface->get_default_location = g_daemon_mount_get_default_location;
iface->can_unmount = g_daemon_mount_can_unmount;
iface->can_eject = g_daemon_mount_can_eject;
iface->unmount = g_daemon_mount_unmount;
diff --git a/common/gmounttracker.c b/common/gmounttracker.c
index 2855068..2b5147a 100644
--- a/common/gmounttracker.c
+++ b/common/gmounttracker.c
@@ -97,7 +97,8 @@ g_mount_info_dup (GMountInfo *info)
copy->user_visible = info->user_visible;
copy->prefered_filename_encoding = g_strdup (info->prefered_filename_encoding);
copy->fuse_mountpoint = g_strdup (info->fuse_mountpoint);
-
+ copy->default_location = g_strdup (info->default_location);
+
return copy;
}
@@ -122,6 +123,7 @@ g_mount_info_unref (GMountInfo *info)
g_mount_spec_unref (info->mount_spec);
g_free (info->prefered_filename_encoding);
g_free (info->fuse_mountpoint);
+ g_free (info->default_location);
g_free (info);
}
}
@@ -166,6 +168,7 @@ g_mount_info_from_dbus (DBusMessageIter *iter)
char *dbus_id;
char *obj_path;
char *fuse_mountpoint;
+ char *default_location;
GIcon *icon;
GError *error;
@@ -193,6 +196,12 @@ g_mount_info_from_dbus (DBusMessageIter *iter)
return NULL;
}
+ if (!_g_dbus_message_iter_get_args (&struct_iter, NULL,
+ G_DBUS_TYPE_CSTRING, &default_location,
+ 0))
+ default_location = g_strdup ("");
+
+
if (icon_str == NULL || strlen (icon_str) == 0)
icon_str = "drive-removable-media";
error = NULL;
@@ -216,7 +225,8 @@ g_mount_info_from_dbus (DBusMessageIter *iter)
info->user_visible = user_visible;
info->prefered_filename_encoding = g_strdup (prefered_filename_encoding);
info->fuse_mountpoint = fuse_mountpoint;
-
+ info->default_location = default_location;
+
return info;
}
diff --git a/common/gmounttracker.h b/common/gmounttracker.h
index efad24a..4892baa 100644
--- a/common/gmounttracker.h
+++ b/common/gmounttracker.h
@@ -50,6 +50,7 @@ typedef struct {
gboolean user_visible;
char *prefered_filename_encoding; /* NULL -> UTF8 */
char *fuse_mountpoint;
+ char *default_location;
GMountSpec *mount_spec;
} GMountInfo;
diff --git a/daemon/gvfsbackend.c b/daemon/gvfsbackend.c
index 3bc877e..0d13b1b 100644
--- a/daemon/gvfsbackend.c
+++ b/daemon/gvfsbackend.c
@@ -78,6 +78,7 @@ struct _GVfsBackendPrivate
GIcon *icon;
char *prefered_filename_encoding;
gboolean user_visible;
+ char *default_location;
GMountSpec *mount_spec;
};
@@ -153,6 +154,7 @@ g_vfs_backend_finalize (GObject *object)
if (backend->priv->icon != NULL)
g_object_unref (backend->priv->icon);
g_free (backend->priv->prefered_filename_encoding);
+ g_free (backend->priv->default_location);
if (backend->priv->mount_spec)
g_mount_spec_unref (backend->priv->mount_spec);
@@ -204,6 +206,7 @@ g_vfs_backend_init (GVfsBackend *backend)
backend->priv->display_name = g_strdup ("");
backend->priv->stable_name = g_strdup ("");
backend->priv->user_visible = TRUE;
+ backend->priv->default_location = g_strdup ("");
}
static void
@@ -367,6 +370,26 @@ g_vfs_backend_set_user_visible (GVfsBackend *backend,
backend->priv->user_visible = user_visible;
}
+/**
+ * g_vfs_backend_set_default_location:
+ * @backend: backend
+ * @location: the default location
+ *
+ * With this function the backend can set a "default location", which is a path
+ * that reflects the main entry point for the user (e.g. * the home directory,
+ * or the root of the volume).
+ *
+ * NB: Does not include the mount prefix, you need to prepend that if there is
+ * one.
+ **/
+void
+g_vfs_backend_set_default_location (GVfsBackend *backend,
+ const char *location)
+{
+ g_free (backend->priv->default_location);
+ backend->priv->default_location = g_strdup (location);
+}
+
void
g_vfs_backend_set_mount_spec (GVfsBackend *backend,
GMountSpec *mount_spec)
@@ -408,6 +431,12 @@ g_vfs_backend_get_icon (GVfsBackend *backend)
return backend->priv->icon;
}
+const char *
+g_vfs_backend_get_default_location (GVfsBackend *backend)
+{
+ return backend->priv->default_location;
+}
+
GMountSpec *
g_vfs_backend_get_mount_spec (GVfsBackend *backend)
{
@@ -665,6 +694,11 @@ g_vfs_backend_register_mount (GVfsBackend *backend,
dbus_message_iter_init_append (message, &iter);
g_mount_spec_to_dbus (&iter, backend->priv->mount_spec);
+ _g_dbus_message_append_args (message,
+ G_DBUS_TYPE_CSTRING, &backend->priv->default_location,
+ 0);
+
+
dbus_message_set_auto_start (message, TRUE);
_g_dbus_connection_call_async (NULL, message, -1,
diff --git a/daemon/gvfsbackend.h b/daemon/gvfsbackend.h
index 137001e..88fd97b 100644
--- a/daemon/gvfsbackend.h
+++ b/daemon/gvfsbackend.h
@@ -473,6 +473,8 @@ void g_vfs_backend_set_prefered_filename_encoding (GVfsBackend *ba
const char *prefered_filename_encoding);
void g_vfs_backend_set_user_visible (GVfsBackend *backend,
gboolean user_visible);
+void g_vfs_backend_set_default_location (GVfsBackend *backend,
+ const char *location);
void g_vfs_backend_set_mount_spec (GVfsBackend *backend,
GMountSpec *mount_spec);
void g_vfs_backend_register_mount (GVfsBackend *backend,
@@ -486,6 +488,7 @@ const char *g_vfs_backend_get_display_name (GVfsBackend *ba
const char *g_vfs_backend_get_stable_name (GVfsBackend *backend);
char **g_vfs_backend_get_x_content_types (GVfsBackend *backend);
GIcon *g_vfs_backend_get_icon (GVfsBackend *backend);
+const char *g_vfs_backend_get_default_location (GVfsBackend *backend);
GMountSpec *g_vfs_backend_get_mount_spec (GVfsBackend *backend);
GVfsDaemon *g_vfs_backend_get_daemon (GVfsBackend *backend);
gboolean g_vfs_backend_is_mounted (GVfsBackend *backend);
diff --git a/daemon/mount.c b/daemon/mount.c
index 172728f..31d6cb2 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -43,6 +43,7 @@ typedef struct {
char *icon;
char *prefered_filename_encoding;
gboolean user_visible;
+ char *default_location;
char *fuse_mountpoint; /* Always set, even if fuse not availible */
/* Daemon object ref */
@@ -189,6 +190,7 @@ vfs_mount_free (VfsMount *mount)
g_free (mount->icon);
g_free (mount->fuse_mountpoint);
g_free (mount->prefered_filename_encoding);
+ g_free (mount->default_location);
g_free (mount->dbus_id);
g_free (mount->object_path);
g_mount_spec_unref (mount->mount_spec);
@@ -250,7 +252,6 @@ vfs_mount_to_dbus (VfsMount *mount,
DBUS_TYPE_BOOLEAN,
&user_visible))
_g_dbus_oom ();
-
fuse_mountpoint = "";
if (fuse_available && mount->fuse_mountpoint)
@@ -259,6 +260,8 @@ vfs_mount_to_dbus (VfsMount *mount,
g_mount_spec_to_dbus (&struct_iter, mount->mount_spec);
+ _g_dbus_message_iter_append_cstring (&struct_iter, mount->default_location);
+
if (!dbus_message_iter_close_container (iter, &struct_iter))
_g_dbus_oom ();
}
@@ -671,7 +674,8 @@ register_mount (DBusConnection *connection,
VfsMount *mount;
DBusMessage *reply;
DBusError error;
- const char *display_name, *stable_name, *x_content_types, *icon, *obj_path, *id, *prefered_filename_encoding;
+ const char *display_name, *stable_name, *x_content_types, *icon, *obj_path;
+ const char *id, *prefered_filename_encoding, *default_location;
dbus_bool_t user_visible;
DBusMessageIter iter;
GMountSpec *mount_spec;
@@ -717,6 +721,13 @@ register_mount (DBusConnection *connection,
mount->object_path = g_strdup (obj_path);
mount->mount_spec = mount_spec;
+ if (_g_dbus_message_iter_get_args (&iter, NULL,
+ G_DBUS_TYPE_CSTRING, &default_location,
+ 0))
+ mount->default_location = default_location;
+ else
+ mount->default_location = g_strdup ("");
+
if (user_visible)
{
char *fs_name;
@@ -918,7 +929,7 @@ list_mounts (DBusConnection *connection,
dbus_message_iter_init_append (reply, &iter);
-
+
if (!dbus_message_iter_open_container (&iter,
DBUS_TYPE_ARRAY,
DBUS_STRUCT_BEGIN_CHAR_AS_STRING
@@ -932,6 +943,7 @@ list_mounts (DBusConnection *connection,
DBUS_TYPE_BOOLEAN_AS_STRING
DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING
G_MOUNT_SPEC_TYPE_AS_STRING
+ DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING,
&array_iter))
_g_dbus_oom ();
diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c
index 9ec68a5..27c78e7 100644
--- a/programs/gvfs-mount.c
+++ b/programs/gvfs-mount.c
@@ -359,7 +359,7 @@ list_mounts (GList *mounts,
GMount *mount;
GVolume *volume;
char *name, *uuid, *uri;
- GFile *root;
+ GFile *root, *default_location;
GIcon *icon;
char **x_content_types;
char *type_name;
@@ -394,6 +394,15 @@ list_mounts (GList *mounts,
if (uuid)
g_print ("%*suuid=%s\n", indent + 2, "", uuid);
+ default_location = g_mount_get_default_location (mount);
+ if (default_location)
+ {
+ char *loc_uri = g_file_get_uri (default_location);
+ g_print ("%*sdefault_location=%s\n", indent + 2, "", loc_uri);
+ g_free (loc_uri);
+ g_object_unref (default_location);
+ }
+
icon = g_mount_get_icon (mount);
if (icon)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]