[gnome-disk-utility] Add a get_volumes() method to GduDrive



commit c2bd825657c538c075570760314c7d7d0c4f8db1
Author: David Zeuthen <davidz redhat com>
Date:   Fri Feb 19 12:41:35 2010 -0500

    Add a get_volumes() method to GduDrive
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 src/gdu/gdu-drive.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gdu/gdu-drive.h |    2 +
 2 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/src/gdu/gdu-drive.c b/src/gdu/gdu-drive.c
index ad56f61..03cb9b4 100644
--- a/src/gdu/gdu-drive.c
+++ b/src/gdu/gdu-drive.c
@@ -1413,3 +1413,56 @@ gdu_drive_create_volume_finish (GduDrive              *drive,
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
+
+static void
+get_volumes_add_enclosed (GduPresentable  *p,
+                          GList          **ret)
+{
+        GList *enclosed;
+        GList *l;
+        GduPool *pool;
+
+        pool = gdu_presentable_get_pool (p);
+        enclosed = gdu_pool_get_enclosed_presentables (pool, p);
+
+        for (l = enclosed; l != NULL; l = l->next) {
+                GduPresentable *ep = GDU_PRESENTABLE (l->data);
+
+                if (!GDU_IS_VOLUME (ep))
+                        continue;
+
+                get_volumes_add_enclosed (ep, ret);
+
+                *ret = g_list_prepend (*ret, g_object_ref (p));
+        }
+
+        g_list_foreach (enclosed, (GFunc) g_object_unref, NULL);
+        g_list_free (enclosed);
+        g_object_unref (pool);
+}
+
+/**
+ * gdu_drive_get_volumes:
+ * @drive: A #GduDrive
+ *
+ * Returns a list of all #GduVolume<!-- -->s for @drive.
+ *
+ * Returns: A #GList of #GduVolume objects. The caller must free the list and each element.
+ */
+GList *
+gdu_drive_get_volumes (GduDrive *drive)
+{
+        GList *ret;
+
+        /* TODO: do we need a vfunc for this? */
+
+        ret = NULL;
+
+        get_volumes_add_enclosed (GDU_PRESENTABLE (drive), &ret);
+
+        ret = g_list_reverse (ret);
+
+        return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/gdu/gdu-drive.h b/src/gdu/gdu-drive.h
index 5559fb9..8232b03 100644
--- a/src/gdu/gdu-drive.h
+++ b/src/gdu/gdu-drive.h
@@ -135,6 +135,8 @@ gboolean    gdu_drive_count_mbr_partitions  (GduDrive        *drive,
                                              guint           *out_num_primary_partitions,
                                              gboolean        *out_has_extended_partition);
 
+GList      *gdu_drive_get_volumes           (GduDrive  *drive);
+
 G_END_DECLS
 
 #endif /* __GDU_DRIVE_H */



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