Blob Blame History Raw
From 68e0d368fb5d3088c5e7d7513607d24dbcb50e02 Mon Sep 17 00:00:00 2001
From: David Zeuthen <zeuthen@gmail.com>
Date: Tue, 21 May 2013 16:06:19 +0000
Subject: UDisksClient: Make it possible to get part desc based on the part table subtype

Otherwise, Disks can't populate the partition table combobox correctly
for GPT because "Generic", "Apple" and "Other" subtypes all have the
same partition type (ZFS) but with different descriptions ("ZFS",
"Apple ZFS", "Solaris /usr").

Signed-off-by: David Zeuthen <zeuthen@gmail.com>
---
diff --git a/doc/udisks2-sections.txt b/doc/udisks2-sections.txt
index 9dbeef6..897f48a 100644
--- a/doc/udisks2-sections.txt
+++ b/doc/udisks2-sections.txt
@@ -70,6 +70,7 @@ udisks_partition_type_info_free
 udisks_client_get_partition_type_infos
 udisks_client_get_partition_table_subtypes
 udisks_client_get_partition_type_for_display
+udisks_client_get_partition_type_and_subtype_for_display
 udisks_client_get_partition_table_type_for_display
 udisks_client_get_partition_table_subtype_for_display
 <SUBSECTION Standard>
diff --git a/udisks/udisksclient.c b/udisks/udisksclient.c
index aca946c..f7eaa04 100644
--- a/udisks/udisksclient.c
+++ b/udisks/udisksclient.c
@@ -2395,6 +2395,48 @@ udisks_client_get_partition_type_for_display (UDisksClient  *client,
   return ret;
 }
 
+/**
+ * udisks_client_get_partition_type_and_subtype_for_display:
+ * @client: A #UDisksClient.
+ * @partition_table_type: A partitioning type e.g. 'dos' or 'gpt'.
+ * @partition_table_subtype: A partitioning subtype or %NULL.
+ * @partition_type: A partition type.
+ *
+ * Like udisks_client_get_partition_type_for_display() but also takes
+ * the partition table subtype into account, if available. This is
+ * useful in scenarios where different subtypes is using the same
+ * partition type.
+ *
+ * Returns: A description of @partition_type or %NULL if unknown.
+ *
+ * Since: 2.1.1
+ */
+const gchar *
+udisks_client_get_partition_type_and_subtype_for_display (UDisksClient  *client,
+                                                          const gchar   *partition_table_type,
+                                                          const gchar   *partition_table_subtype,
+                                                          const gchar   *partition_type)
+{
+  const gchar *ret = NULL;
+  guint n;
+
+  for (n = 0; known_partition_types[n].name != NULL; n++)
+    {
+      if (g_strcmp0 (known_partition_types[n].table_type, partition_table_type) == 0 &&
+          g_strcmp0 (known_partition_types[n].type, partition_type) == 0)
+        {
+          if (partition_table_subtype != NULL &&
+              g_strcmp0 (known_partition_types[n].table_subtype, partition_table_subtype) != 0)
+            continue;
+          ret = g_dpgettext2 (GETTEXT_PACKAGE, "part-type", known_partition_types[n].name);
+          goto out;
+        }
+    }
+
+ out:
+  return ret;
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 /**
diff --git a/udisks/udisksclient.h b/udisks/udisksclient.h
index 93dfddf..121efc3 100644
--- a/udisks/udisksclient.h
+++ b/udisks/udisksclient.h
@@ -136,6 +136,12 @@ const gchar        *udisks_client_get_partition_type_for_display       (UDisksCl
                                                                         const gchar   *partition_table_type,
                                                                         const gchar   *partition_type);
 
+const gchar        *udisks_client_get_partition_type_and_subtype_for_display (UDisksClient  *client,
+                                                                              const gchar   *partition_table_type,
+                                                                              const gchar   *partition_table_subtype,
+                                                                              const gchar   *partition_type);
+
+
 const gchar        *udisks_client_get_partition_table_type_for_display (UDisksClient  *client,
                                                                         const gchar   *partition_table_type);
 
--
cgit v0.9.0.2-2-gbebe