[gvfs/wip/udisks2: 6/6] udisks2: implement get_sort_key() methods
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/wip/udisks2: 6/6] udisks2: implement get_sort_key() methods
- Date: Fri, 14 Oct 2011 17:40:53 +0000 (UTC)
commit 3347b1f9a4aedb8235542b7b4ccc5306dc8b6650
Author: David Zeuthen <davidz redhat com>
Date: Fri Oct 14 13:39:38 2011 -0400
udisks2: implement get_sort_key() methods
This depends on the GIO patch in https://bugzilla.gnome.org/show_bug.cgi?id=661711
Signed-off-by: David Zeuthen <davidz redhat com>
monitor/udisks2/gvfsudisks2drive.c | 25 ++++++++++++++++++++++++-
monitor/udisks2/gvfsudisks2mount.c | 22 +++++++++++++++++-----
monitor/udisks2/gvfsudisks2volume.c | 14 ++++++++++++++
3 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/monitor/udisks2/gvfsudisks2drive.c b/monitor/udisks2/gvfsudisks2drive.c
index ef99793..c58b858 100644
--- a/monitor/udisks2/gvfsudisks2drive.c
+++ b/monitor/udisks2/gvfsudisks2drive.c
@@ -53,6 +53,7 @@ struct _GVfsUDisks2Drive
GIcon *icon;
gchar *name;
+ gchar *sort_key;
gchar *device_file;
dev_t dev;
gboolean is_media_removable;
@@ -90,6 +91,7 @@ gvfs_udisks2_drive_finalize (GObject *object)
if (drive->icon != NULL)
g_object_unref (drive->icon);
g_free (drive->name);
+ g_free (drive->sort_key);
g_free (drive->device_file);
G_OBJECT_CLASS (gvfs_udisks2_drive_parent_class)->finalize (object);
@@ -122,12 +124,14 @@ update_drive (GVfsUDisks2Drive *drive)
gboolean changed;
GIcon *old_icon;
gchar *old_name;
+ gchar *old_sort_key;
gchar *old_device_file;
dev_t old_dev;
gboolean old_is_media_removable;
gboolean old_has_media;
gboolean old_can_eject;
UDisksBlock *block;
+ gint64 time_detected;
/* ---------------------------------------------------------------------------------------------------- */
/* save old values */
@@ -137,6 +141,7 @@ update_drive (GVfsUDisks2Drive *drive)
old_can_eject = drive->can_eject;
old_name = g_strdup (drive->name);
+ old_sort_key = g_strdup (drive->sort_key);
old_device_file = g_strdup (drive->device_file);
old_dev = drive->dev;
old_icon = drive->icon != NULL ? g_object_ref (drive->icon) : NULL;
@@ -146,6 +151,7 @@ update_drive (GVfsUDisks2Drive *drive)
drive->is_media_removable = drive->has_media = drive->can_eject = FALSE;
g_free (drive->name); drive->name = NULL;
+ g_free (drive->sort_key); drive->sort_key = NULL;
g_free (drive->device_file); drive->device_file = NULL;
drive->dev = 0;
g_clear_object (&drive->icon);
@@ -160,9 +166,15 @@ update_drive (GVfsUDisks2Drive *drive)
{
drive->device_file = udisks_block_dup_device (block);
drive->dev = makedev (udisks_block_get_major (block), udisks_block_get_minor (block));
+
g_object_unref (block);
}
+ time_detected = udisks_drive_get_time_media_detected (drive->udisks_drive);
+ if (time_detected == 0)
+ udisks_drive_get_time_detected (drive->udisks_drive);
+ drive->sort_key = g_strdup_printf ("gvfs.time_detected_usec.%" G_GINT64_FORMAT, time_detected);
+
drive->is_media_removable = udisks_drive_get_media_removable (drive->udisks_drive);
if (drive->is_media_removable)
{
@@ -207,6 +219,7 @@ update_drive (GVfsUDisks2Drive *drive)
(old_has_media == drive->has_media) &&
(old_can_eject == drive->can_eject) &&
(g_strcmp0 (old_name, drive->name) == 0) &&
+ (g_strcmp0 (old_sort_key, drive->sort_key) == 0) &&
(g_strcmp0 (old_device_file, drive->device_file) == 0) &&
(old_dev == drive->dev) &&
g_icon_equal (old_icon, drive->icon)
@@ -214,6 +227,7 @@ update_drive (GVfsUDisks2Drive *drive)
/* free old values */
g_free (old_name);
+ g_free (old_sort_key);
g_free (old_device_file);
if (old_icon != NULL)
g_object_unref (old_icon);
@@ -680,6 +694,15 @@ gvfs_udisks2_drive_eject_finish (GDrive *drive,
/* ---------------------------------------------------------------------------------------------------- */
+static const gchar *
+gvfs_udisks2_drive_get_sort_key (GDrive *_drive)
+{
+ GVfsUDisks2Drive *drive = GVFS_UDISKS2_DRIVE (_drive);
+ return drive->sort_key;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
gvfs_udisks2_drive_drive_iface_init (GDriveIface *iface)
{
@@ -698,11 +721,11 @@ gvfs_udisks2_drive_drive_iface_init (GDriveIface *iface)
iface->can_start = gvfs_udisks2_drive_can_start;
iface->can_start_degraded = gvfs_udisks2_drive_can_start_degraded;
iface->can_stop = gvfs_udisks2_drive_can_stop;
-
iface->eject = gvfs_udisks2_drive_eject;
iface->eject_finish = gvfs_udisks2_drive_eject_finish;
iface->eject_with_operation = gvfs_udisks2_drive_eject_with_operation;
iface->eject_with_operation_finish = gvfs_udisks2_drive_eject_with_operation_finish;
+ iface->get_sort_key = gvfs_udisks2_drive_get_sort_key;
#if 0
iface->poll_for_media = gvfs_udisks2_drive_poll_for_media;
iface->poll_for_media_finish = gvfs_udisks2_drive_poll_for_media_finish;
diff --git a/monitor/udisks2/gvfsudisks2mount.c b/monitor/udisks2/gvfsudisks2mount.c
index 58b341a..31ccca3 100644
--- a/monitor/udisks2/gvfsudisks2mount.c
+++ b/monitor/udisks2/gvfsudisks2mount.c
@@ -68,6 +68,7 @@ struct _GVfsUDisks2Mount
GFile *root;
GIcon *icon;
gchar *name;
+ gchar *sort_key;
gchar *uuid;
gchar *device_file;
gchar *mount_path;
@@ -115,6 +116,7 @@ gvfs_udisks2_mount_finalize (GObject *object)
if (mount->icon != NULL)
g_object_unref (mount->icon);
g_free (mount->name);
+ g_free (mount->sort_key);
g_free (mount->uuid);
g_free (mount->device_file);
g_free (mount->mount_path);
@@ -207,14 +209,16 @@ update_mount (GVfsUDisks2Mount *mount)
old_name = g_strdup (mount->name);
old_icon = mount->icon != NULL ? g_object_ref (mount->icon) : NULL;
+ /* reset */
+ mount->can_unmount = FALSE;
+ g_clear_object (&mount->icon);
+ g_free (mount->name); mount->name = NULL;
+
/* in with the new */
if (mount->volume != NULL)
{
mount->can_unmount = TRUE;
- if (mount->icon != NULL)
- g_object_unref (mount->icon);
-
/* icon order of preference: bdmv, xdg, autorun, probed */
if (mount->bdmv_volume_info_icon != NULL)
mount->icon = g_object_ref (mount->bdmv_volume_info_icon);
@@ -225,8 +229,6 @@ update_mount (GVfsUDisks2Mount *mount)
else
mount->icon = g_volume_get_icon (G_VOLUME (mount->volume));
- g_free (mount->name);
-
/* name order of preference : bdmv, xdg, probed */
if (mount->bdmv_volume_info_name != NULL)
mount->name = g_strdup (mount->bdmv_volume_info_name);
@@ -332,6 +334,7 @@ gvfs_udisks2_mount_new (GVfsUDisks2VolumeMonitor *monitor,
mount = g_object_new (GVFS_TYPE_UDISKS2_MOUNT, NULL);
mount->monitor = monitor;
+ mount->sort_key = g_strdup_printf ("gvfs.time_detected_usec.%" G_GINT64_FORMAT, g_get_real_time ());
if (mount_entry != NULL)
{
@@ -1224,6 +1227,14 @@ gvfs_udisks2_mount_guess_content_type_finish (GMount *mount,
{
return gvfs_udisks2_mount_guess_content_type_sync (mount, FALSE, NULL, error);
}
+/* ---------------------------------------------------------------------------------------------------- */
+
+static const gchar *
+gvfs_udisks2_mount_get_sort_key (GMount *_mount)
+{
+ GVfsUDisks2Mount *mount = GVFS_UDISKS2_MOUNT (_mount);
+ return mount->sort_key;
+}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1249,6 +1260,7 @@ gvfs_udisks2_mount_mount_iface_init (GMountIface *iface)
iface->guess_content_type = gvfs_udisks2_mount_guess_content_type;
iface->guess_content_type_finish = gvfs_udisks2_mount_guess_content_type_finish;
iface->guess_content_type_sync = gvfs_udisks2_mount_guess_content_type_sync;
+ iface->get_sort_key = gvfs_udisks2_mount_get_sort_key;
}
gboolean
diff --git a/monitor/udisks2/gvfsudisks2volume.c b/monitor/udisks2/gvfsudisks2volume.c
index 5bc7465..2aad2e0 100644
--- a/monitor/udisks2/gvfsudisks2volume.c
+++ b/monitor/udisks2/gvfsudisks2volume.c
@@ -64,6 +64,7 @@ struct _GVfsUDisks2Volume
GIcon *icon;
GFile *activation_root;
gchar *name;
+ gchar *sort_key;
gchar *device_file;
dev_t dev;
gchar *uuid;
@@ -123,6 +124,7 @@ gvfs_udisks2_volume_finalize (GObject *object)
g_object_unref (volume->activation_root);
g_free (volume->name);
+ g_free (volume->sort_key);
g_free (volume->device_file);
g_free (volume->uuid);
@@ -437,6 +439,8 @@ gvfs_udisks2_volume_new (GVfsUDisks2VolumeMonitor *monitor,
volume = g_object_new (GVFS_TYPE_UDISKS2_VOLUME, NULL);
volume->monitor = monitor;
+ volume->sort_key = g_strdup_printf ("gvfs.time_detected_usec.%" G_GINT64_FORMAT, g_get_real_time ());
+
if (block != NULL)
{
volume->block = g_object_ref (block);
@@ -1201,6 +1205,15 @@ gvfs_udisks2_volume_eject_finish (GVolume *volume,
/* ---------------------------------------------------------------------------------------------------- */
+static const gchar *
+gvfs_udisks2_volume_get_sort_key (GVolume *_volume)
+{
+ GVfsUDisks2Volume *volume = GVFS_UDISKS2_VOLUME (_volume);
+ return volume->sort_key;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
gvfs_udisks2_volume_volume_iface_init (GVolumeIface *iface)
{
@@ -1222,6 +1235,7 @@ gvfs_udisks2_volume_volume_iface_init (GVolumeIface *iface)
iface->eject_finish = gvfs_udisks2_volume_eject_finish;
iface->eject_with_operation = gvfs_udisks2_volume_eject_with_operation;
iface->eject_with_operation_finish = gvfs_udisks2_volume_eject_with_operation_finish;
+ iface->get_sort_key = gvfs_udisks2_volume_get_sort_key;
}
/* ---------------------------------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]