[gnome-disk-utility/wip/mdraid] Port from udisks_client_get_drive_info() to udisks_client_get_object_info()



commit 95d6b7d86cb5b4839dfe93d461a4a57cb104c34f
Author: David Zeuthen <zeuthen gmail com>
Date:   Wed Sep 19 17:39:33 2012 -0400

    Port from udisks_client_get_drive_info() to udisks_client_get_object_info()
    
    Signed-off-by: David Zeuthen <zeuthen gmail com>

 src/disks/gdubenchmarkdialog.c   |   51 +++++--------
 src/disks/gdudevicetreemodel.c   |   33 ++------
 src/disks/gdumdraiddisksdialog.c |  151 +++++++++++++++-----------------------
 src/disks/gduwindow.c            |   36 +++------
 4 files changed, 98 insertions(+), 173 deletions(-)
---
diff --git a/src/disks/gdubenchmarkdialog.c b/src/disks/gdubenchmarkdialog.c
index f02f77d..8f8be0a 100644
--- a/src/disks/gdubenchmarkdialog.c
+++ b/src/disks/gdubenchmarkdialog.c
@@ -821,7 +821,8 @@ update_dialog (DialogData *data)
   gdouble access_time_avg = 0.0;
   gchar *s = NULL;
   UDisksDrive *drive = NULL;
-  UDisksPartition *partition = NULL;
+  const gchar *drive_revision = NULL;
+  UDisksObjectInfo *info = NULL;
 
   G_LOCK (bm_lock);
   if (data->bm_error != NULL)
@@ -855,42 +856,25 @@ update_dialog (DialogData *data)
 
   /* disk / device label */
   drive = udisks_client_get_drive_for_block (gdu_window_get_client (data->window), data->block);
-  partition = udisks_object_get_partition (data->object);
   if (drive != NULL)
+    drive_revision = udisks_drive_get_revision (drive);
+  info = udisks_client_get_object_info (gdu_window_get_client (data->window), data->object);
+  if (drive_revision != NULL && strlen (drive_revision) > 0)
     {
-      gchar *name;
-      gchar *desc;
-      udisks_client_get_drive_info (gdu_window_get_client (data->window),
-                                    drive,
-                                    &name,
-                                    &desc,
-                                    NULL,   /* out_drive_icon */
-                                    NULL,   /* out_media_desc */
-                                    NULL);  /* out_media_icon */
-      if (partition != NULL)
-        {
-          gchar *str_size = g_format_size (udisks_block_get_size (data->block));
-          /* Translators: The first %s is the partition size (e.g. "10.0 GB") and the two
-           * following %s are make/model (e.g. "ST 3160A") and description (e.g. "60 GB Hard Disk")
-           */
-          s = g_strdup_printf (C_("benchmark-drive-name", "%s partition on %s (%s)"),
-                               str_size,
-                               name, desc);
-          g_free (str_size);
-        }
-      else
-        {
-          /* Translators: The first %s is the make/model (e.g. "ST 3160A"), the second %s is
-           * the description (e.g. "60 GB Hard Disk")
-           */
-          s = g_strdup_printf (C_("benchmark-drive-name", "%s (%s)"), name, desc);
-        }
-      g_free (name);
-      g_free (desc);
+      /* Translators: Shown for "Disk / Device" field.
+       *              The first %s is the description of the object (e.g. "80 GB Disk").
+       *              The second %s is the name of the object (e.g. "INTEL SSDSA2MH080G1GC").
+       *              The third %s is the fw revision (e.g "45ABX21").
+       */
+      s = g_strdup_printf (C_("benchmark", "%s â %s (%s)"), info->description, info->name, drive_revision);
     }
   else
     {
-      s = udisks_block_dup_preferred_device (data->block);
+      /* Translators: Shown for "Disk / Device" field.
+       *              The first %s is the description of the object (e.g. "80 GB Disk").
+       *              The second %s is the name of the object (e.g. "INTEL SSDSA2MH080G1GC").
+       */
+      s = g_strdup_printf (C_("benchmark", "%s â %s"), info->description, info->name);
     }
   gtk_label_set_text (GTK_LABEL (data->device_label), s);
   g_free (s);
@@ -968,7 +952,8 @@ update_dialog (DialogData *data)
     gdk_window_invalidate_rect (window, NULL, TRUE);
 
   g_clear_object (&drive);
-  g_clear_object (&partition);
+  if (info != NULL)
+    udisks_object_info_unref (info);
 }
 
 
diff --git a/src/disks/gdudevicetreemodel.c b/src/disks/gdudevicetreemodel.c
index 4118533..8819135 100644
--- a/src/disks/gdudevicetreemodel.c
+++ b/src/disks/gdudevicetreemodel.c
@@ -880,11 +880,7 @@ update_drive (GduDeviceTreeModel *model,
 {
   UDisksDrive *drive = NULL;
   UDisksDriveAta *ata = NULL;
-  GIcon *drive_icon = NULL;
-  GIcon *media_icon = NULL;
-  gchar *name = NULL;
-  gchar *description = NULL;
-  gchar *media_description = NULL;
+  UDisksObjectInfo *info = NULL;
   gchar *s = NULL;
   gchar *sort_key = NULL;
   gboolean warning = FALSE;
@@ -912,13 +908,7 @@ update_drive (GduDeviceTreeModel *model,
       g_free (s);
     }
 
-  udisks_client_get_drive_info (model->client,
-                                drive,
-                                &name,
-                                &description,
-                                &drive_icon,
-                                &media_description,
-                                &media_icon);
+  info = udisks_client_get_object_info (model->client, object);
   if (warning)
     {
       /* TODO: once https://bugzilla.gnome.org/show_bug.cgi?id=657194 is resolved, use that instead
@@ -926,8 +916,8 @@ update_drive (GduDeviceTreeModel *model,
        */
       s = g_strdup_printf ("<span foreground=\"#ff0000\">%s</span>\n"
                            "<small><span foreground=\"#ff0000\">%s</span></small>",
-                           description,
-                           name);
+                           info->description,
+                           info->name);
     }
   else
     {
@@ -936,8 +926,8 @@ update_drive (GduDeviceTreeModel *model,
        */
       s = g_strdup_printf ("%s\n"
                            "<small><span foreground=\"#555555\">%s</span></small>",
-                           description,
-                           name);
+                           info->description,
+                           info->name);
     }
 
   jobs_running = drive_has_jobs (model->client, drive);
@@ -951,7 +941,7 @@ update_drive (GduDeviceTreeModel *model,
 
   gtk_tree_store_set (GTK_TREE_STORE (model),
                       &iter,
-                      GDU_DEVICE_TREE_MODEL_COLUMN_ICON, drive_icon,
+                      GDU_DEVICE_TREE_MODEL_COLUMN_ICON, info->icon,
                       GDU_DEVICE_TREE_MODEL_COLUMN_NAME, s,
                       GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, sort_key,
                       GDU_DEVICE_TREE_MODEL_COLUMN_WARNING, warning,
@@ -969,15 +959,10 @@ update_drive (GduDeviceTreeModel *model,
     }
 
  out:
-  if (media_icon != NULL)
-    g_object_unref (media_icon);
-  if (drive_icon != NULL)
-    g_object_unref (drive_icon);
+  if (info != NULL)
+    udisks_object_info_unref (info);
   g_free (sort_key);
   g_free (s);
-  g_free (media_description);
-  g_free (description);
-  g_free (name);
   return jobs_running;
 }
 
diff --git a/src/disks/gdumdraiddisksdialog.c b/src/disks/gdumdraiddisksdialog.c
index b609138..5c5ee4a 100644
--- a/src/disks/gdumdraiddisksdialog.c
+++ b/src/disks/gdumdraiddisksdialog.c
@@ -217,12 +217,17 @@ static void
 update_dialog_labels (DialogData *data)
 {
   GtkTreeIter titer;
+  UDisksObject *object = NULL;
   UDisksBlock *block = NULL;
   UDisksDrive *drive = NULL;
   gchar *model_markup = NULL;
   gchar *device_markup = NULL;
   gchar *serial_markup = NULL;
   gchar *assessment_markup = NULL;
+  const gchar *drive_revision = NULL;
+  UDisksObjectInfo *info = NULL;
+  UDisksObject *drive_object = NULL;
+  UDisksDriveAta *ata = NULL;
 
   if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview)),
                                        NULL, /* out_model */
@@ -233,10 +238,13 @@ update_dialog_labels (DialogData *data)
                           COLUMN_BLOCK, &block,
                           -1);
     }
-
   if (block == NULL)
     goto out;
 
+  object = (UDisksObject *) g_dbus_interface_dup_object (G_DBUS_INTERFACE (block));
+  if (object == NULL)
+    goto out;
+
   if (udisks_block_get_read_only (block))
     {
       /* Translators: Shown for a read-only device. The %s is the device file, e.g. /dev/sdb1 */
@@ -248,27 +256,14 @@ update_dialog_labels (DialogData *data)
       device_markup = g_strdup (udisks_block_get_preferred_device (block));
     }
 
+  info = udisks_client_get_object_info (data->client, object);
   drive = udisks_client_get_drive_for_block (data->client, block);
   if (drive != NULL)
     {
-      UDisksObject *drive_object = NULL;
-      UDisksDriveAta *ata = NULL;
-      gchar *name = NULL;
-
-      udisks_client_get_drive_info (data->client,
-                                    drive,
-                                    &name,  /* out_name */
-                                    NULL,   /* out_description */
-                                    NULL,   /* out_drive_icon */
-                                    NULL,   /* out_media_description */
-                                    NULL);  /* out_media_icon */
-      model_markup = g_strdup_printf ("%s (%s)", name,
-                                      udisks_drive_get_revision (drive));
-      g_free (name);
-      serial_markup = udisks_drive_dup_serial (drive);
-
+      drive_revision = udisks_drive_get_revision (drive);
       drive_object = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (drive));
       ata = udisks_object_peek_drive_ata (drive_object);
+      serial_markup = udisks_drive_dup_serial (drive);
       if (ata != NULL && !udisks_drive_get_media_removable (drive))
         {
           assessment_markup = gdu_ata_smart_get_one_liner_assessment (ata,
@@ -277,6 +272,19 @@ update_dialog_labels (DialogData *data)
         }
     }
 
+  if (drive_revision != NULL && strlen (drive_revision) > 0)
+    {
+      /* Translators: Shown for "Model" field.
+       *              The first %s is the name of the object (e.g. "INTEL SSDSA2MH080G1GC").
+       *              The second %s is the fw revision (e.g "45ABX21").
+       */
+      model_markup = g_strdup_printf (C_("mdraid-disks", "%s (%s)"), info->name, drive_revision);
+    }
+  else
+    {
+      model_markup = g_strdup (info->name);
+    }
+
  out:
   gtk_label_set_markup (GTK_LABEL (data->model_label),      model_markup != NULL ?      model_markup : "â");
   gtk_label_set_markup (GTK_LABEL (data->device_label),     device_markup != NULL ?     device_markup : "â");
@@ -287,7 +295,10 @@ update_dialog_labels (DialogData *data)
   g_free (device_markup);
   g_free (serial_markup);
   g_free (assessment_markup);
+  if (info != NULL)
+    udisks_object_info_unref (info);
   g_clear_object (&drive);
+  g_clear_object (&object);
   g_clear_object (&block);
 }
 
@@ -474,6 +485,8 @@ pixbuf_cell_func (GtkTreeViewColumn *column,
 {
   DialogData *data = user_data;
   UDisksBlock *block = NULL;
+  UDisksObject *object = NULL;
+  UDisksObjectInfo *info = NULL;
   GIcon *icon = NULL;
 
   gtk_tree_model_get (model,
@@ -482,36 +495,29 @@ pixbuf_cell_func (GtkTreeViewColumn *column,
                       -1);
 
   if (block == NULL)
-    {
-      icon = NULL;
-    }
-  else
-    {
-      UDisksDrive *drive;
-      drive = udisks_client_get_drive_for_block (data->client, block);
-      if (drive != NULL)
-        {
-          udisks_client_get_drive_info (data->client,
-                                        drive,
-                                        NULL,  /* out_name */
-                                        NULL,  /* out_description */
-                                        &icon, /* out_drive_icon */
-                                        NULL,  /* out_media_description */
-                                        NULL); /* out_media_icon */
-          g_object_unref (drive);
-        }
-      else
-        {
-          icon = g_themed_icon_new ("drive-removable-media"); /* for now */
-        }
-    }
+    goto out;
 
+  object = (UDisksObject *) g_dbus_interface_dup_object (G_DBUS_INTERFACE (block));
+  if (object == NULL)
+    goto out;
+
+  info = udisks_client_get_object_info (data->client, object);
+  if (info->icon != NULL)
+    icon = g_object_ref (info->icon);
+
+  if (icon == NULL)
+    icon = g_themed_icon_new ("drive-removable-media"); /* fallback - for now */
+
+ out:
   g_object_set (renderer,
                 "gicon", icon,
                 NULL);
 
   g_clear_object (&icon);
+  g_clear_object (&object);
   g_clear_object (&block);
+  if (info != NULL)
+    udisks_object_info_unref (info);
 }
 
 static void
@@ -523,8 +529,9 @@ name_cell_func (GtkTreeViewColumn *column,
 {
   DialogData *data = user_data;
   UDisksBlock *block = NULL;
+  UDisksObject *object = NULL;
+  UDisksObjectInfo *info = NULL;
   gchar *markup = NULL;
-  gchar *s;
 
   gtk_tree_model_get (model,
                       iter,
@@ -532,64 +539,26 @@ name_cell_func (GtkTreeViewColumn *column,
                       -1);
 
   if (block == NULL)
-    {
-      /* Translators: Shown in 'Disk' column when there is no disk for the position in question */
-      markup = g_strdup_printf ("<i>%s</i>",
-                                C_("mdraid-disks", "None"));
-    }
-  else
-    {
-      UDisksDrive *drive = NULL;
+    goto out;
 
-      drive = udisks_client_get_drive_for_block (data->client, block);
-      if (drive != NULL)
-        {
-          UDisksPartition *partition = NULL;
-          UDisksObject *object = NULL;
-          gchar *desc = NULL;
-
-          udisks_client_get_drive_info (data->client,
-                                        drive,
-                                        NULL,     /* out_name */
-                                        &desc,    /* out_description */
-                                        NULL,     /* out_drive_icon */
-                                        NULL,     /* out_media_description */
-                                        NULL);    /* out_media_icon */
-
-          object = (UDisksObject *) g_dbus_interface_get_object (G_DBUS_INTERFACE (block));
-          if (object != NULL)
-            partition = udisks_object_peek_partition (object);
-          if (partition != NULL)
-            {
-              markup = g_strdup_printf (C_("mdraid-disks", "Partition %d of %s"),
-                                        udisks_partition_get_number (partition),
-                                        desc);
-              g_free (desc);
-            }
-          else
-            {
-              markup = desc;
-            }
+  object = (UDisksObject *) g_dbus_interface_dup_object (G_DBUS_INTERFACE (block));
+  if (object == NULL)
+    goto out;
 
-          g_object_unref (drive);
-        }
-      else
-        {
-          s = udisks_client_get_size_for_display (data->client, udisks_block_get_size (block), FALSE, FALSE);
-          /* Translators: Shown in list for a disk/member that is not a drive.
-           *              The %s is the size (e.g. "42.0 GB").
-           */
-          markup = g_strdup_printf (C_("mdraid-disks", "%s Block Device"), s);
-          g_free (s);
-        }
-    }
+  info = udisks_client_get_object_info (data->client, object);
+  markup = g_strdup (info->description);
+
+ out:
 
   g_object_set (renderer,
                 "markup", markup,
                 NULL);
 
   g_free (markup);
+  g_clear_object (&object);
   g_clear_object (&block);
+  if (info != NULL)
+    udisks_object_info_unref (info);
 }
 
 static void
diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c
index 97a5796..7e0d7d5 100644
--- a/src/disks/gduwindow.c
+++ b/src/disks/gduwindow.c
@@ -2263,11 +2263,7 @@ update_device_page_for_drive (GduWindow      *window,
   const gchar *drive_vendor;
   const gchar *drive_model;
   const gchar *drive_revision;
-  gchar *name;
-  gchar *description;
-  gchar *media_description;
-  GIcon *drive_icon;
-  GIcon *media_icon;
+  UDisksObjectInfo *info = NULL;
   guint64 size;
   UDisksDriveAta *ata;
   const gchar *our_seat;
@@ -2286,13 +2282,7 @@ update_device_page_for_drive (GduWindow      *window,
 
   ata = udisks_object_peek_drive_ata (object);
 
-  udisks_client_get_drive_info (window->client,
-                                drive,
-                                &name,
-                                &description,
-                                &drive_icon,
-                                &media_description,
-                                &media_icon);
+  info = udisks_client_get_object_info (window->client, object);
 
   drive_vendor = udisks_drive_get_vendor (drive);
   drive_model = udisks_drive_get_model (drive);
@@ -2308,8 +2298,7 @@ update_device_page_for_drive (GduWindow      *window,
       g_string_append (str, s);
       g_free (s);
     }
-  s = g_strdup_printf ("<big><b>%s</b></big>",
-                       description);
+  s = g_strdup_printf ("<big><b>%s</b></big>", info->description);
   gtk_label_set_markup (GTK_LABEL (window->devtab_drive_desc_label), s);
   gtk_widget_show (window->devtab_drive_desc_label);
   g_free (s);
@@ -2324,10 +2313,10 @@ update_device_page_for_drive (GduWindow      *window,
   gtk_widget_show (window->devtab_drive_eject_button);
   gtk_widget_show (window->devtab_drive_generic_button);
 
-  if (media_icon != NULL)
-    gtk_image_set_from_gicon (GTK_IMAGE (window->devtab_drive_image), media_icon, GTK_ICON_SIZE_DIALOG);
+  if (info->media_icon != NULL)
+    gtk_image_set_from_gicon (GTK_IMAGE (window->devtab_drive_image), info->media_icon, GTK_ICON_SIZE_DIALOG);
   else
-    gtk_image_set_from_gicon (GTK_IMAGE (window->devtab_drive_image), drive_icon, GTK_ICON_SIZE_DIALOG);
+    gtk_image_set_from_gicon (GTK_IMAGE (window->devtab_drive_image), info->icon, GTK_ICON_SIZE_DIALOG);
   gtk_widget_show (window->devtab_drive_image);
 
   str = g_string_new (NULL);
@@ -2341,7 +2330,8 @@ update_device_page_for_drive (GduWindow      *window,
     g_string_append_printf (str, " (%s)", drive_revision);
   set_markup (window,
               "devtab-drive-model-label",
-              "devtab-drive-model-value-label", str->str, SET_MARKUP_FLAGS_HYPHEN_IF_EMPTY);
+              "devtab-drive-model-value-label",
+              str->str, SET_MARKUP_FLAGS_HYPHEN_IF_EMPTY);
   g_string_free (str, TRUE);
 
   serial = udisks_drive_get_serial (drive);
@@ -2468,7 +2458,7 @@ update_device_page_for_drive (GduWindow      *window,
       set_markup (window,
                   "devtab-drive-media-label",
                   "devtab-drive-media-value-label",
-                  media_description, SET_MARKUP_FLAGS_NONE);
+                  info->media_description, SET_MARKUP_FLAGS_NONE);
     }
   else
     {
@@ -2525,12 +2515,8 @@ update_device_page_for_drive (GduWindow      *window,
 
   g_list_foreach (blocks, (GFunc) g_object_unref, NULL);
   g_list_free (blocks);
-  if (media_icon != NULL)
-    g_object_unref (media_icon);
-  g_object_unref (drive_icon);
-  g_free (description);
-  g_free (media_description);
-  g_free (name);
+  if (info != NULL)
+    udisks_object_info_unref (info);
 }
 
 static UDisksObject *



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