[gnome-disk-utility] Add support for new DriveDetach() method and :drive-can-detach property



commit f76001f6f6beca8b21ff81e70f2633c60783479f
Author: David Zeuthen <davidz redhat com>
Date:   Mon Jun 8 20:18:16 2009 -0400

    Add support for new DriveDetach() method and :drive-can-detach property
---
 src/gdu/gdu-callbacks.h |    4 +++
 src/gdu/gdu-device.c    |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 src/gdu/gdu-device.h    |    7 ++++++
 3 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/src/gdu/gdu-callbacks.h b/src/gdu/gdu-callbacks.h
index 1d68603..b8f5114 100644
--- a/src/gdu/gdu-callbacks.h
+++ b/src/gdu/gdu-callbacks.h
@@ -132,6 +132,10 @@ typedef void (*GduDeviceDriveEjectCompletedFunc) (GduDevice    *device,
                                                   GError       *error,
                                                   gpointer      user_data);
 
+typedef void (*GduDeviceDriveDetachCompletedFunc) (GduDevice    *device,
+                                                   GError       *error,
+                                                   gpointer      user_data);
+
 typedef void (*GduDeviceDrivePollMediaCompletedFunc) (GduDevice    *device,
                                                       GError       *error,
                                                       gpointer      user_data);
diff --git a/src/gdu/gdu-device.c b/src/gdu/gdu-device.c
index fa00c69..f2b1c98 100644
--- a/src/gdu/gdu-device.c
+++ b/src/gdu/gdu-device.c
@@ -118,6 +118,7 @@ typedef struct
         char    *drive_media;
         gboolean drive_is_media_ejectable;
         gboolean drive_requires_eject;
+        gboolean drive_can_detach;
 
         gboolean optical_disc_is_blank;
         gboolean optical_disc_is_appendable;
@@ -315,6 +316,8 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props)
                 props->drive_is_media_ejectable = g_value_get_boolean (value);
         else if (strcmp (key, "drive-requires-eject") == 0)
                 props->drive_requires_eject = g_value_get_boolean (value);
+        else if (strcmp (key, "drive-can-detach") == 0)
+                props->drive_can_detach = g_value_get_boolean (value);
 
         else if (strcmp (key, "optical-disc-is-blank") == 0)
                 props->optical_disc_is_blank = g_value_get_boolean (value);
@@ -1100,6 +1103,12 @@ gdu_device_drive_get_requires_eject (GduDevice *device)
 }
 
 gboolean
+gdu_device_drive_get_can_detach (GduDevice *device)
+{
+        return device->priv->props->drive_can_detach;
+}
+
+gboolean
 gdu_device_optical_disc_get_is_blank (GduDevice *device)
 {
         return device->priv->props->optical_disc_is_blank;
@@ -2444,6 +2453,45 @@ gdu_device_op_drive_eject (GduDevice                        *device,
 
 typedef struct {
         GduDevice *device;
+        GduDeviceDriveDetachCompletedFunc callback;
+        gpointer user_data;
+} DriveDetachData;
+
+static void
+op_detach_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
+{
+        DriveDetachData *data = user_data;
+        _gdu_error_fixup (error);
+        if (data->callback != NULL)
+                data->callback (data->device, error, data->user_data);
+        g_object_unref (data->device);
+        g_free (data);
+}
+
+void
+gdu_device_op_drive_detach (GduDevice                        *device,
+                           GduDeviceDriveDetachCompletedFunc  callback,
+                           gpointer                           user_data)
+{
+        char *options[16];
+        DriveDetachData *data;
+
+        data = g_new0 (DriveDetachData, 1);
+        data->device = g_object_ref (device);
+        data->callback = callback;
+        data->user_data = user_data;
+        options[0] = NULL;
+
+        org_freedesktop_DeviceKit_Disks_Device_drive_detach_async (device->priv->proxy,
+                                                                   (const char **) options,
+                                                                   op_detach_cb,
+                                                                   data);
+}
+
+/* -------------------------------------------------------------------------------- */
+
+typedef struct {
+        GduDevice *device;
         GduDeviceDrivePollMediaCompletedFunc callback;
         gpointer user_data;
 } DrivePollMediaData;
diff --git a/src/gdu/gdu-device.h b/src/gdu/gdu-device.h
index 69580d1..404aeb4 100644
--- a/src/gdu/gdu-device.h
+++ b/src/gdu/gdu-device.h
@@ -137,6 +137,7 @@ char **gdu_device_drive_get_media_compatibility (GduDevice *device);
 const char *gdu_device_drive_get_media (GduDevice *device);
 gboolean gdu_device_drive_get_is_media_ejectable (GduDevice *device);
 gboolean gdu_device_drive_get_requires_eject (GduDevice *device);
+gboolean gdu_device_drive_get_can_detach (GduDevice *device);
 
 gboolean gdu_device_optical_disc_get_is_blank (GduDevice *device);
 gboolean gdu_device_optical_disc_get_is_appendable (GduDevice *device);
@@ -377,6 +378,12 @@ void gdu_device_op_drive_eject                 (GduDevice
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+void gdu_device_op_drive_detach                (GduDevice                        *device,
+                                                GduDeviceDriveDetachCompletedFunc callback,
+                                                gpointer                          user_data);
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 void gdu_device_op_drive_poll_media                 (GduDevice                        *device,
                                                      GduDeviceDrivePollMediaCompletedFunc   callback,
                                                      gpointer                          user_data);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]