From: Alexander Larsson Date: Thu, 24 Jan 2008 16:06:33 +0000 (+0000) Subject: Add g_drive_get_identifier and g_drive_enumerate_identifiers X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=753428dcf85cb5fc73009bd4ffb457d6a9166023;p=dana%2Fcg-glib.git Add g_drive_get_identifier and g_drive_enumerate_identifiers 2008-01-24 Alexander Larsson * gdrive.[ch]: Add g_drive_get_identifier and g_drive_enumerate_identifiers * gvolume.[ch]: Add g_volume_get_identifier and g_volume_enumerate_identifiers * gio.symbols: Add symbols * gunixvolume.c: Implement identifiers for unix backend svn path=/trunk/; revision=6364 --- diff --git a/gio/ChangeLog b/gio/ChangeLog index 15d6d2b6..4454d970 100644 --- a/gio/ChangeLog +++ b/gio/ChangeLog @@ -1,3 +1,19 @@ +2008-01-24 Alexander Larsson + + * gdrive.[ch]: + Add g_drive_get_identifier and + g_drive_enumerate_identifiers + + * gvolume.[ch]: + Add g_volume_get_identifier and + g_volume_enumerate_identifiers + + * gio.symbols: + Add symbols + + * gunixvolume.c: + Implement identifiers for unix backend + 2008-01-24 Alexander Larsson * gfile.[ch]: diff --git a/gio/gdrive.c b/gio/gdrive.c index 22616fbb..2eb02375 100644 --- a/gio/gdrive.c +++ b/gio/gdrive.c @@ -474,5 +474,37 @@ g_drive_poll_for_media_finish (GDrive *drive, return (* iface->poll_for_media_finish) (drive, result, error); } +char * +g_drive_get_identifier (GDrive *drive, + const char *kind) +{ + GDriveIface *iface; + + g_return_val_if_fail (G_IS_DRIVE (drive), NULL); + g_return_val_if_fail (kind != NULL, NULL); + + iface = G_DRIVE_GET_IFACE (drive); + + if (iface->get_identifier == NULL) + return NULL; + + return (* iface->get_identifier) (drive, kind); +} + +char ** +g_drive_enumerate_identifiers (GDrive *drive) +{ + GDriveIface *iface; + + g_return_val_if_fail (G_IS_DRIVE (drive), NULL); + iface = G_DRIVE_GET_IFACE (drive); + + if (iface->enumerate_identifiers == NULL) + return NULL; + + return (* iface->enumerate_identifiers) (drive); +} + + #define __G_DRIVE_C__ #include "gioaliasdef.c" diff --git a/gio/gdrive.h b/gio/gdrive.h index 0901099f..e8afcb33 100644 --- a/gio/gdrive.h +++ b/gio/gdrive.h @@ -98,6 +98,10 @@ struct _GDriveIface gboolean (*poll_for_media_finish) (GDrive *drive, GAsyncResult *result, GError **error); + + char * (*get_identifier) (GDrive *drive, + const char *kind); + char ** (*enumerate_identifiers) (GDrive *drive); }; GType g_drive_get_type (void) G_GNUC_CONST; @@ -126,6 +130,9 @@ void g_drive_poll_for_media (GDrive *drive, gboolean g_drive_poll_for_media_finish (GDrive *drive, GAsyncResult *result, GError **error); +char * g_drive_get_identifier (GDrive *drive, + const char *kind); +char ** g_drive_enumerate_identifiers (GDrive *drive); G_END_DECLS diff --git a/gio/gio.symbols b/gio/gio.symbols index bbb7b108..058b5104 100644 --- a/gio/gio.symbols +++ b/gio/gio.symbols @@ -194,6 +194,8 @@ g_drive_eject g_drive_eject_finish g_drive_poll_for_media g_drive_poll_for_media_finish +g_drive_get_identifier +g_drive_enumerate_identifiers #endif #endif @@ -701,7 +703,9 @@ g_volume_can_eject g_volume_mount g_volume_mount_finish g_volume_eject -g_volume_eject_finish +g_volume_eject_finish +g_volume_get_identifier +g_volume_enumerate_identifiers #endif #endif diff --git a/gio/gunixvolume.c b/gio/gunixvolume.c index 23516f1f..6b126255 100644 --- a/gio/gunixvolume.c +++ b/gio/gunixvolume.c @@ -49,6 +49,9 @@ struct _GUnixVolume { char *mount_path; gboolean can_eject; + char *identifier; + char *identifier_type; + char *name; GIcon *icon; }; @@ -77,6 +80,8 @@ g_unix_volume_finalize (GObject *object) g_free (volume->name); g_free (volume->mount_path); g_free (volume->device_path); + g_free (volume->identifier); + g_free (volume->identifier_type); if (G_OBJECT_CLASS (g_unix_volume_parent_class)->finalize) (*G_OBJECT_CLASS (g_unix_volume_parent_class)->finalize) (object); @@ -121,6 +126,29 @@ _g_unix_volume_new (GVolumeMonitor *volume_monitor, volume->name = g_unix_mount_point_guess_name (mountpoint); volume->icon = g_unix_mount_point_guess_icon (mountpoint); + + + if (strcmp (g_unix_mount_point_get_fs_type (mountpoint), "nfs") == 0) + { + volume->identifier_type = g_strdup (G_VOLUME_IDENTIFIER_KIND_NFS_MOUNT); + volume->identifier = g_strdup (volume->device_path); + } + else if (g_str_has_prefix (volume->device_path, "LABEL=")) + { + volume->identifier_type = g_strdup (G_VOLUME_IDENTIFIER_KIND_LABEL); + volume->identifier = g_strdup (volume->device_path + 6); + } + else if (g_str_has_prefix (volume->device_path, "UUID=")) + { + volume->identifier_type = g_strdup (G_VOLUME_IDENTIFIER_KIND_UUID); + volume->identifier = g_strdup (volume->device_path + 5); + } + else if (g_path_is_absolute (volume->device_path)) + { + volume->identifier_type = g_strdup (G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE); + volume->identifier = g_strdup (volume->device_path); + } + return volume; } @@ -402,6 +430,39 @@ g_unix_volume_eject_finish (GVolume *volume, return TRUE; } +static char * +g_unix_volume_get_identifier (GVolume *volume, + const char *kind) +{ + GUnixVolume *unix_volume = G_UNIX_VOLUME (volume); + + if (strcmp (kind, unix_volume->identifier_type) == 0) + return g_strdup (unix_volume->identifier); + return NULL; +} + +static char ** +g_unix_volume_enumerate_identifiers (GVolume *volume) +{ + GUnixVolume *unix_volume = G_UNIX_VOLUME (volume); + char **res; + + if (unix_volume->identifier_type) + { + res = g_new (char *, 2); + res[0] = g_strdup (unix_volume->identifier_type); + res[1] = NULL; + } + else + { + res = g_new (char *, 1); + res[0] = NULL; + } + + return res; +} + + static void g_unix_volume_volume_iface_init (GVolumeIface *iface) { @@ -416,4 +477,6 @@ g_unix_volume_volume_iface_init (GVolumeIface *iface) iface->mount_finish = g_unix_volume_mount_finish; iface->eject = g_unix_volume_eject; iface->eject_finish = g_unix_volume_eject_finish; + iface->get_identifier = g_unix_volume_get_identifier; + iface->enumerate_identifiers = g_unix_volume_enumerate_identifiers; } diff --git a/gio/gvolume.c b/gio/gvolume.c index 3ccd0cdf..8eebc9a6 100644 --- a/gio/gvolume.c +++ b/gio/gvolume.c @@ -420,5 +420,37 @@ g_volume_eject_finish (GVolume *volume, return (* iface->eject_finish) (volume, result, error); } +char * +g_volume_get_identifier (GVolume *volume, + const char *kind) +{ + GVolumeIface *iface; + + g_return_val_if_fail (G_IS_VOLUME (volume), NULL); + g_return_val_if_fail (kind != NULL, NULL); + + iface = G_VOLUME_GET_IFACE (volume); + + if (iface->get_identifier == NULL) + return NULL; + + return (* iface->get_identifier) (volume, kind); +} + +char ** +g_volume_enumerate_identifiers (GVolume *volume) +{ + GVolumeIface *iface; + + g_return_val_if_fail (G_IS_VOLUME (volume), NULL); + iface = G_VOLUME_GET_IFACE (volume); + + if (iface->enumerate_identifiers == NULL) + return NULL; + + return (* iface->enumerate_identifiers) (volume); +} + + #define __G_VOLUME_C__ #include "gioaliasdef.c" diff --git a/gio/gvolume.h b/gio/gvolume.h index 2d71ae26..3a99c69e 100644 --- a/gio/gvolume.h +++ b/gio/gvolume.h @@ -34,6 +34,13 @@ G_BEGIN_DECLS +#define G_VOLUME_IDENTIFIER_KIND_HAL_UDI "hal-udi" +#define G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE "unix-device" +#define G_VOLUME_IDENTIFIER_KIND_LABEL "label" +#define G_VOLUME_IDENTIFIER_KIND_UUID "uuid" +#define G_VOLUME_IDENTIFIER_KIND_NFS_MOUNT "nfs-mount" + + #define G_TYPE_VOLUME (g_volume_get_type ()) #define G_VOLUME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_VOLUME, GVolume)) #define G_IS_VOLUME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_VOLUME)) @@ -94,33 +101,41 @@ struct _GVolumeIface gboolean (*eject_finish) (GVolume *volume, GAsyncResult *result, GError **error); + + char * (*get_identifier) (GVolume *volume, + const char *kind); + char ** (*enumerate_identifiers) (GVolume *volume); }; GType g_volume_get_type (void) G_GNUC_CONST; -char * g_volume_get_name (GVolume *volume); -GIcon * g_volume_get_icon (GVolume *volume); -char * g_volume_get_uuid (GVolume *volume); -GDrive * g_volume_get_drive (GVolume *volume); -GMount * g_volume_get_mount (GVolume *volume); -gboolean g_volume_can_mount (GVolume *volume); -gboolean g_volume_can_eject (GVolume *volume); -void g_volume_mount (GVolume *volume, - GMountOperation *mount_operation, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean g_volume_mount_finish (GVolume *volume, - GAsyncResult *result, - GError **error); -void g_volume_eject (GVolume *volume, - GMountUnmountFlags flags, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean g_volume_eject_finish (GVolume *volume, - GAsyncResult *result, - GError **error); +char * g_volume_get_name (GVolume *volume); +GIcon * g_volume_get_icon (GVolume *volume); +char * g_volume_get_uuid (GVolume *volume); +GDrive * g_volume_get_drive (GVolume *volume); +GMount * g_volume_get_mount (GVolume *volume); +gboolean g_volume_can_mount (GVolume *volume); +gboolean g_volume_can_eject (GVolume *volume); +void g_volume_mount (GVolume *volume, + GMountOperation *mount_operation, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean g_volume_mount_finish (GVolume *volume, + GAsyncResult *result, + GError **error); +void g_volume_eject (GVolume *volume, + GMountUnmountFlags flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean g_volume_eject_finish (GVolume *volume, + GAsyncResult *result, + GError **error); +char * g_volume_get_identifier (GVolume *volume, + const char *kind); +char ** g_volume_enumerate_identifiers (GVolume *volume); + G_END_DECLS