[gnome-disk-utility/new-ui] Use the name from GduHub in the Location: element for drives



commit 78d31fe9cb6e5f84920c403c9f328cb67f51c4ae
Author: David Zeuthen <davidz redhat com>
Date:   Mon Nov 30 21:20:44 2009 -0500

    Use the name from GduHub in the Location: element for drives

 src/gdu/gdu-pool.c                 |   33 +++++++++++++++++
 src/gdu/gdu-pool.h                 |    2 +
 src/palimpsest/gdu-section-drive.c |   70 ++++++++++++-----------------------
 3 files changed, 59 insertions(+), 46 deletions(-)
---
diff --git a/src/gdu/gdu-pool.c b/src/gdu/gdu-pool.c
index e5c4719..307034a 100644
--- a/src/gdu/gdu-pool.c
+++ b/src/gdu/gdu-pool.c
@@ -2358,6 +2358,39 @@ gdu_pool_get_presentable_by_id (GduPool *pool, const gchar *id)
         return ret;
 }
 
+GduPresentable *
+gdu_pool_get_hub_by_object_path (GduPool *pool, const gchar *object_path)
+{
+        GduPresentable *ret;
+        GList *l;
+
+        /* TODO: use lookaside hash table */
+
+        ret = NULL;
+        for (l = pool->priv->presentables; l != NULL && ret == NULL; l = l->next) {
+                GduPresentable *p = GDU_PRESENTABLE (l->data);
+                GduAdapter *a;
+                GduExpander *e;
+
+                if (!GDU_IS_HUB (p))
+                        continue;
+
+                a = gdu_hub_get_adapter (GDU_HUB (p));
+                e = gdu_hub_get_expander (GDU_HUB (p));
+
+                if (g_strcmp0 (gdu_adapter_get_object_path (a), object_path) == 0) {
+                        ret = g_object_ref (p);
+                } else if (e != NULL && g_strcmp0 (gdu_expander_get_object_path (e), object_path) == 0) {
+                        ret = g_object_ref (p);
+                }
+
+                g_object_unref (a);
+                if (e != NULL)
+                        g_object_unref (e);
+        }
+
+        return ret;
+}
 
 /* ---------------------------------------------------------------------------------------------------- */
 
diff --git a/src/gdu/gdu-pool.h b/src/gdu/gdu-pool.h
index 532a5d8..c94e879 100644
--- a/src/gdu/gdu-pool.h
+++ b/src/gdu/gdu-pool.h
@@ -108,6 +108,8 @@ GList      *gdu_pool_get_expanders               (GduPool *pool);
 GduPort    *gdu_pool_get_port_by_object_path (GduPool *pool, const char *object_path);
 GList      *gdu_pool_get_ports               (GduPool *pool);
 
+GduPresentable *gdu_pool_get_hub_by_object_path (GduPool *pool, const gchar *object_path);
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 void gdu_pool_op_linux_md_start (GduPool *pool,
diff --git a/src/palimpsest/gdu-section-drive.c b/src/palimpsest/gdu-section-drive.c
index f98952f..6114173 100644
--- a/src/palimpsest/gdu-section-drive.c
+++ b/src/palimpsest/gdu-section-drive.c
@@ -138,61 +138,43 @@ gdu_section_drive_update (GduSection *_section)
                 g_object_unref (pool);
         }
         if (port != NULL) {
-                gint port_number;
                 GduPool *pool;
-                GduAdapter *adapter;
-                GduExpander *expander;
-                const gchar *port_parent_object_path;
-                const gchar *fabric;
-                gchar *s;
+                GduPresentable *hub;
 
-                pool = gdu_device_get_pool (d);
-
-                port_parent_object_path = gdu_port_get_parent (port);
+                s = NULL;
 
-                expander = NULL;
-                adapter = gdu_pool_get_adapter_by_object_path (pool, port_parent_object_path);
-                if (adapter == NULL) {
-                        expander = gdu_pool_get_expander_by_object_path (pool, port_parent_object_path);
-                        adapter = gdu_pool_get_adapter_by_object_path (pool, gdu_device_drive_get_adapter (d));
-                }
-                fabric = NULL;
-                if (adapter != NULL)
+                pool = gdu_device_get_pool (d);
+                hub = gdu_pool_get_hub_by_object_path (pool, gdu_port_get_parent (port));
+                if (hub != NULL) {
+                        gchar *hub_name;
+                        GduAdapter *adapter;
+                        gint port_number;
+                        const gchar *fabric;
+
+                        adapter = gdu_hub_get_adapter (GDU_HUB (hub));
                         fabric = gdu_adapter_get_fabric (adapter);
+                        hub_name = gdu_presentable_get_name (hub);
+                        port_number = gdu_port_get_number (port);
 
-                s = NULL;
-                port_number = gdu_port_get_number (port);
-                if (port_number >= 0) {
-                        /* TODO: provide a link to the HBA? Probably */
-
-                        if (expander == NULL) {
+                        if (port_number >= 0) {
                                 if (g_strcmp0 (fabric, "scsi_sas") == 0) {
                                         /* Translators: This is used in the "Location" element for a disk
-                                         * directly connected to the SAS Host Adapter - PHY numbers
-                                         * start at 1
+                                         * connected to a SAS Adapter or Expander - The %d is the
+                                         * PHY number (starts at 1) and the %s is the Adapter/Expander name.
                                          */
-                                        s = g_strdup_printf (_("PHY %d of SAS Host Adapter"), port_number + 1);
+                                        s = g_strdup_printf (_("PHY %d of %s"), port_number + 1, hub_name);
                                 } else {
                                         /* Translators: This is used in the "Location" element for a disk
-                                         * directly connected to the Host Adapter (aka HBA) - port numbers
-                                         * start at 1
+                                         * connected to a Adapter or Expander - The %d is the
+                                         * PHY number (starts at 1) and the %s is the Adapter/Expander name.
                                          */
-                                        s = g_strdup_printf (_("Port %d of Host Adapter"), port_number + 1);
-                                }
-                        } else {
-                                if (g_strcmp0 (fabric, "scsi_sas") == 0) {
-                                        /* Translators: This is used in the "Location" element for a disk
-                                         * connected to a SAS expander - PHY numbers start at 1
-                                         */
-                                        s = g_strdup_printf (_("PHY %d of Expander"), port_number + 1);
-                                } else {
-                                        /* Translators: This is used in the "Location" element for a disk
-                                         * connected to an expander / port multiplier - port numbers
-                                         * start at 1
-                                         */
-                                        s = g_strdup_printf (_("Port %d of Expander"), port_number + 1);
+                                        s = g_strdup_printf (_("Port %d of %s"), port_number + 1, hub_name);
                                 }
                         }
+
+                        g_free (hub_name);
+                        g_object_unref (adapter);
+                        g_object_unref (hub);
                 }
                 if (s == NULL)
                         s = g_strdup ("â??");
@@ -200,10 +182,6 @@ gdu_section_drive_update (GduSection *_section)
                 g_free (s);
 
                 g_object_unref (pool);
-                if (adapter != NULL)
-                        g_object_unref (adapter);
-                if (expander != NULL)
-                        g_object_unref (expander);
         } else {
                 gdu_details_element_set_text (section->priv->location_element, "â??");
         }



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