summaryrefslogtreecommitdiffstats
path: root/src/gdu
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2009-02-15 13:12:29 -0500
committerDavid Zeuthen <davidz@redhat.com>2009-02-15 13:12:29 -0500
commita5db333c76cfdea7745c3060d2d0e4830fc6c8da (patch)
treebb2883739954296f3bdd5e96aa71883fdffda2cc /src/gdu
parentfc223a4290a6c66a3a7ad5bc0cd5b7f43a0f3f83 (diff)
downloadgnome-disk-utility-a5db333c76cfdea7745c3060d2d0e4830fc6c8da.tar.gz
gnome-disk-utility-a5db333c76cfdea7745c3060d2d0e4830fc6c8da.tar.xz
gnome-disk-utility-a5db333c76cfdea7745c3060d2d0e4830fc6c8da.zip
add new gdu_presentable_get_id function
Diffstat (limited to 'src/gdu')
-rw-r--r--src/gdu/gdu-activatable-drive.c59
-rw-r--r--src/gdu/gdu-drive.c8
-rw-r--r--src/gdu/gdu-pool.c11
-rw-r--r--src/gdu/gdu-presentable.c21
-rw-r--r--src/gdu/gdu-presentable.h3
-rw-r--r--src/gdu/gdu-volume-hole.c16
-rw-r--r--src/gdu/gdu-volume.c20
7 files changed, 136 insertions, 2 deletions
diff --git a/src/gdu/gdu-activatable-drive.c b/src/gdu/gdu-activatable-drive.c
index e405a3f..064f3fd 100644
--- a/src/gdu/gdu-activatable-drive.c
+++ b/src/gdu/gdu-activatable-drive.c
@@ -59,6 +59,8 @@ struct _GduActivatableDrivePrivate
GduPool *pool;
GList *slaves;
+
+ gchar *id;
};
static GObjectClass *parent_class = NULL;
@@ -99,6 +101,8 @@ gdu_activatable_drive_finalize (GduActivatableDrive *activatable_drive)
}
g_list_free (activatable_drive->priv->slaves);
+ g_free (activatable_drive->priv->id);
+
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (G_OBJECT (activatable_drive));
}
@@ -165,8 +169,16 @@ _gdu_activatable_drive_has_uuid (GduActivatableDrive *activatable_drive,
ret = FALSE;
- if (activatable_drive->priv->slaves == NULL)
+ if (activatable_drive->priv->slaves == NULL) {
+ if (activatable_drive->priv->device != NULL) {
+ if (strcmp (uuid, gdu_device_linux_md_get_uuid (activatable_drive->priv->device)) == 0) {
+ ret = TRUE;
+ }
+ } else {
+ g_warning ("No slave for activatable drive and no device");
+ }
goto out;
+ }
first_slave = GDU_DEVICE (activatable_drive->priv->slaves->data);
if (strcmp (gdu_device_linux_md_component_get_uuid (first_slave), uuid) == 0)
@@ -216,6 +228,50 @@ gdu_activatable_drive_get_kind (GduActivatableDrive *activatable_drive)
return activatable_drive->priv->kind;
}
+static const gchar *
+gdu_activatable_drive_get_id (GduPresentable *presentable)
+{
+ GduActivatableDrive *activatable_drive = GDU_ACTIVATABLE_DRIVE (presentable);
+ GduDevice *first_slave;
+ const gchar *ret;
+
+ if (activatable_drive->priv->id != NULL) {
+ ret = activatable_drive->priv->id;
+ goto out;
+ }
+
+ ret = "(notset)";
+
+ if (activatable_drive->priv->slaves == NULL) {
+ if (activatable_drive->priv->device == NULL) {
+ g_warning ("No slave for activatable drive and no device");
+ goto out;
+ }
+
+ activatable_drive->priv->id = g_strdup_printf ("linux_md_uuid_%s",
+ gdu_device_linux_md_get_uuid (activatable_drive->priv->device));
+ ret = activatable_drive->priv->id;
+ goto out;
+ }
+
+ first_slave = GDU_DEVICE (activatable_drive->priv->slaves->data);
+
+ switch (activatable_drive->priv->kind) {
+ default:
+ g_warning ("Cannot get id for unknown kind %d", activatable_drive->priv->kind);
+ break;
+
+ case GDU_ACTIVATABLE_DRIVE_KIND_LINUX_MD:
+ activatable_drive->priv->id = g_strdup_printf ("linux_md_uuid_%s",
+ gdu_device_linux_md_component_get_uuid (first_slave));
+ ret = activatable_drive->priv->id;
+ break;
+ }
+
+ out:
+ return ret;
+}
+
static GduDevice *
gdu_activatable_drive_get_device (GduPresentable *presentable)
{
@@ -605,6 +661,7 @@ gdu_activatable_drive_get_num_ready_slaves (GduActivatableDrive *activatable_dri
static void
gdu_activatable_drive_presentable_iface_init (GduPresentableIface *iface)
{
+ iface->get_id = gdu_activatable_drive_get_id;
iface->get_device = gdu_activatable_drive_get_device;
iface->get_enclosing_presentable = gdu_activatable_drive_get_enclosing_presentable;
iface->get_name = gdu_activatable_drive_get_name;
diff --git a/src/gdu/gdu-drive.c b/src/gdu/gdu-drive.c
index 5e58d4d..a0f5930 100644
--- a/src/gdu/gdu-drive.c
+++ b/src/gdu/gdu-drive.c
@@ -134,6 +134,13 @@ _gdu_drive_new_from_device (GduPool *pool, GduDevice *device)
return drive;
}
+static const gchar *
+gdu_drive_get_id (GduPresentable *presentable)
+{
+ GduDrive *drive = GDU_DRIVE (presentable);
+ return gdu_device_get_device_file (drive->priv->device);
+}
+
static GduDevice *
gdu_drive_get_device (GduPresentable *presentable)
{
@@ -294,6 +301,7 @@ gdu_drive_is_recognized (GduPresentable *presentable)
static void
gdu_drive_presentable_iface_init (GduPresentableIface *iface)
{
+ iface->get_id = gdu_drive_get_id;
iface->get_device = gdu_drive_get_device;
iface->get_enclosing_presentable = gdu_drive_get_enclosing_presentable;
iface->get_name = gdu_drive_get_name;
diff --git a/src/gdu/gdu-pool.c b/src/gdu/gdu-pool.c
index 9ab0799..b0b06b9 100644
--- a/src/gdu/gdu-pool.c
+++ b/src/gdu/gdu-pool.c
@@ -574,9 +574,12 @@ static void
ensure_activatable_drive_for_linux_md_component (GduPool *pool, GduDevice *device)
{
GduActivatableDrive *activatable_drive;
+ gboolean emit_added;
activatable_drive = find_activatable_drive_for_linux_md_component (pool, device);
+ emit_added = FALSE;
+
/* create it unless we have it already */
if (activatable_drive == NULL) {
activatable_drive = _gdu_activatable_drive_new (pool,
@@ -588,12 +591,17 @@ ensure_activatable_drive_for_linux_md_component (GduPool *pool, GduDevice *devic
/* and we're part of the gang */
pool->priv->presentables = g_list_prepend (pool->priv->presentables,
GDU_PRESENTABLE (activatable_drive));
- g_signal_emit (pool, signals[PRESENTABLE_ADDED], 0, GDU_PRESENTABLE (activatable_drive));
+
+ /* don't emit the added signal until we are sure there are slaves for it */
+ emit_added = TRUE;
}
/* add ourselves to the drive if we're not already part of it */
if (!gdu_activatable_drive_has_slave (activatable_drive, device))
_gdu_activatable_drive_add_slave (activatable_drive, device);
+
+ if (emit_added)
+ g_signal_emit (pool, signals[PRESENTABLE_ADDED], 0, GDU_PRESENTABLE (activatable_drive));
}
static GduActivatableDrive *
@@ -683,6 +691,7 @@ gdu_pool_add_device_by_object_path (GduPool *pool, const char *object_path)
g_hash_table_insert (pool->priv->drives, g_strdup (object_path),
g_object_ref (drive));
+ g_signal_emit (pool, signals[PRESENTABLE_ADDED], 0, GDU_PRESENTABLE (drive));
}
/* otherwise do create a new GduDrive object */
diff --git a/src/gdu/gdu-presentable.c b/src/gdu/gdu-presentable.c
index a7bec38..a102b45 100644
--- a/src/gdu/gdu-presentable.c
+++ b/src/gdu/gdu-presentable.c
@@ -247,6 +247,27 @@ gdu_presentable_base_init (gpointer g_class)
}
/**
+ * gdu_presentable_get_id:
+ * @presentable: A #GduPresentable.
+ *
+ * Gets a stable identifier for @presentable.
+ *
+ * Returns: An stable identifier for @presentable. Do not free, the string is
+ * owned by @presentable.
+ **/
+const gchar *
+gdu_presentable_get_id (GduPresentable *presentable)
+{
+ GduPresentableIface *iface;
+
+ g_return_val_if_fail (GDU_IS_PRESENTABLE (presentable), NULL);
+
+ iface = GDU_PRESENTABLE_GET_IFACE (presentable);
+
+ return (* iface->get_id) (presentable);
+}
+
+/**
* gdu_presentable_get_device:
* @presentable: A #GduPresentable.
*
diff --git a/src/gdu/gdu-presentable.h b/src/gdu/gdu-presentable.h
index c10448a..da6589c 100644
--- a/src/gdu/gdu-presentable.h
+++ b/src/gdu/gdu-presentable.h
@@ -42,6 +42,7 @@ typedef struct _GduPresentable GduPresentable;
* @changed: Signal emitted when the presentable is changed.
* @removed: Signal emitted when the presentable is removed. Recipients should release all references to the object.
* @job_changed: Signal emitted when the job state on the underlying #GduDevice changes.
+ * @get_id: Returns a unique id for the presentable.
* @get_device: Returns the underlying #GduDevice.
* @get_enclosing_presentable: Returns the #GduPresentable that is the parent or #NULL if there is no parent.
* @get_name: Returns a name for the presentable suitable for presentation in an user interface.
@@ -66,6 +67,7 @@ struct _GduPresentableIface
void (*job_changed) (GduPresentable *presentable);
/* virtual table */
+ const gchar * (*get_id) (GduPresentable *presentable);
GduDevice * (*get_device) (GduPresentable *presentable);
GduPresentable * (*get_enclosing_presentable) (GduPresentable *presentable);
char * (*get_name) (GduPresentable *presentable);
@@ -78,6 +80,7 @@ struct _GduPresentableIface
};
GType gdu_presentable_get_type (void) G_GNUC_CONST;
+const gchar *gdu_presentable_get_id (GduPresentable *presentable);
GduDevice *gdu_presentable_get_device (GduPresentable *presentable);
GduPresentable *gdu_presentable_get_enclosing_presentable (GduPresentable *presentable);
char *gdu_presentable_get_name (GduPresentable *presentable);
diff --git a/src/gdu/gdu-volume-hole.c b/src/gdu/gdu-volume-hole.c
index be9ad42..cf51d10 100644
--- a/src/gdu/gdu-volume-hole.c
+++ b/src/gdu/gdu-volume-hole.c
@@ -49,6 +49,7 @@ struct _GduVolumeHolePrivate
guint64 size;
GduPresentable *enclosing_presentable;
GduPool *pool;
+ gchar *id;
};
static GObjectClass *parent_class = NULL;
@@ -66,6 +67,8 @@ gdu_volume_hole_finalize (GduVolumeHole *volume_hole)
if (volume_hole->priv->enclosing_presentable != NULL)
g_object_unref (volume_hole->priv->enclosing_presentable);
+ g_free (volume_hole->priv->id);
+
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (G_OBJECT (volume_hole));
}
@@ -98,9 +101,21 @@ _gdu_volume_hole_new (GduPool *pool, guint64 offset, guint64 size, GduPresentabl
volume_hole->priv->enclosing_presentable =
enclosing_presentable != NULL ? g_object_ref (enclosing_presentable) : NULL;
+ volume_hole->priv->id = g_strdup_printf ("hole_%s_%" G_GUINT64_FORMAT "_%" G_GUINT64_FORMAT,
+ enclosing_presentable != NULL ? gdu_presentable_get_id (enclosing_presentable) : "(none)",
+ offset,
+ size);
+
return volume_hole;
}
+static const gchar *
+gdu_volume_hole_get_id (GduPresentable *presentable)
+{
+ GduVolumeHole *volume_hole = GDU_VOLUME_HOLE (presentable);
+ return volume_hole->priv->id;
+}
+
static GduDevice *
gdu_volume_hole_get_device (GduPresentable *presentable)
{
@@ -246,6 +261,7 @@ gdu_volume_hole_is_recognized (GduPresentable *presentable)
static void
gdu_volume_hole_presentable_iface_init (GduPresentableIface *iface)
{
+ iface->get_id = gdu_volume_hole_get_id;
iface->get_device = gdu_volume_hole_get_device;
iface->get_enclosing_presentable = gdu_volume_hole_get_enclosing_presentable;
iface->get_name = gdu_volume_hole_get_name;
diff --git a/src/gdu/gdu-volume.c b/src/gdu/gdu-volume.c
index bc2caa7..8064374 100644
--- a/src/gdu/gdu-volume.c
+++ b/src/gdu/gdu-volume.c
@@ -31,6 +31,7 @@
#include "gdu-pool.h"
#include "gdu-volume.h"
#include "gdu-presentable.h"
+#include "gdu-activatable-drive.h"
/**
* SECTION:gdu-volume
@@ -138,6 +139,13 @@ _gdu_volume_new_from_device (GduPool *pool, GduDevice *device, GduPresentable *e
return volume;
}
+static const gchar *
+gdu_volume_get_id (GduPresentable *presentable)
+{
+ GduVolume *volume = GDU_VOLUME (presentable);
+ return gdu_device_get_device_file (volume->priv->device);
+}
+
static GduDevice *
gdu_volume_get_device (GduPresentable *presentable)
{
@@ -261,6 +269,17 @@ gdu_volume_get_icon (GduPresentable *presentable)
if (p == NULL)
goto out;
+ if (GDU_IS_ACTIVATABLE_DRIVE (p)) {
+ GduActivableDriveKind kind;
+
+ kind = gdu_activatable_drive_get_kind (GDU_ACTIVATABLE_DRIVE (p));
+
+ if (kind == GDU_ACTIVATABLE_DRIVE_KIND_LINUX_MD)
+ name = "gdu-raid-array";
+
+ goto out;
+ }
+
d = gdu_presentable_get_device (p);
if (d == NULL)
goto out;
@@ -414,6 +433,7 @@ gdu_volume_is_recognized (GduPresentable *presentable)
static void
gdu_volume_presentable_iface_init (GduPresentableIface *iface)
{
+ iface->get_id = gdu_volume_get_id;
iface->get_device = gdu_volume_get_device;
iface->get_enclosing_presentable = gdu_volume_get_enclosing_presentable;
iface->get_name = gdu_volume_get_name;