[gnome-disk-utility] Start reworking "Create RAID Array" dialog and hook it up



commit f2ae280724efeb26039e2a97ad74fe841ebd251b
Author: David Zeuthen <zeuthen gmail com>
Date:   Thu Oct 11 11:06:51 2012 -0400

    Start reworking "Create RAID Array" dialog and hook it up
    
    Signed-off-by: David Zeuthen <zeuthen gmail com>

 data/ui/create-raid-array-dialog.ui  |  351 ++++----------------
 src/disks/gducreateraidarraydialog.c |  621 ++--------------------------------
 src/disks/gducreateraidarraydialog.h |    3 +-
 src/disks/gduwindow.c                |   59 +++-
 4 files changed, 144 insertions(+), 890 deletions(-)
---
diff --git a/data/ui/create-raid-array-dialog.ui b/data/ui/create-raid-array-dialog.ui
index a9208dd..305245f 100644
--- a/data/ui/create-raid-array-dialog.ui
+++ b/data/ui/create-raid-array-dialog.ui
@@ -3,7 +3,6 @@
   <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkDialog" id="create-raid-array-dialog">
     <property name="width_request">500</property>
-    <property name="height_request">550</property>
     <property name="can_focus">False</property>
     <property name="border_width">12</property>
     <property name="title" translatable="yes">Create RAID Array</property>
@@ -59,7 +58,21 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
-            <property name="spacing">12</property>
+            <child>
+              <object class="GtkBox" id="infobar-vbox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
             <child>
               <object class="GtkGrid" id="grid1">
                 <property name="visible">True</property>
@@ -163,312 +176,76 @@
                     <property name="height">1</property>
                   </packing>
                 </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="label4">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes">&lt;b&gt;_Disks&lt;/b&gt;</property>
-                <property name="use_markup">True</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">treeview</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox" id="box2">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="margin_left">24</property>
-                <property name="orientation">vertical</property>
-                <property name="spacing">12</property>
                 <child>
-                  <object class="GtkBox" id="box3">
+                  <object class="GtkLabel" id="label5">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">RAID Array Size</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">4</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Number of Disks</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">3</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="num-disks-label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="orientation">vertical</property>
-                    <child>
-                      <object class="GtkScrolledWindow" id="scrolledwindow">
-                        <property name="width_request">300</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="shadow_type">in</property>
-                        <child>
-                          <object class="GtkTreeView" id="treeview">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="show_expanders">False</property>
-                            <property name="level_indentation">12</property>
-                            <child internal-child="selection">
-                              <object class="GtkTreeSelection" id="treeview-selection1"/>
-                            </child>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkToolbar" id="toolbar">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="icon_size">1</property>
-                        <child>
-                          <object class="GtkToolButton" id="add-toolbutton">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="has_tooltip">True</property>
-                            <property name="tooltip_markup" translatable="yes">Add Disk...</property>
-                            <property name="tooltip_text" translatable="yes">Add Disk...</property>
-                            <property name="label" translatable="yes">Add Disk...</property>
-                            <property name="use_underline">True</property>
-                            <property name="icon_name">list-add-symbolic</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="homogeneous">True</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkToolButton" id="remove-toolbutton">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="has_tooltip">True</property>
-                            <property name="tooltip_markup" translatable="yes">Remove Disk...</property>
-                            <property name="tooltip_text" translatable="yes">Remove Disk...</property>
-                            <property name="label" translatable="yes">Remove Disk...</property>
-                            <property name="use_underline">True</property>
-                            <property name="icon_name">list-remove-symbolic</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="homogeneous">True</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkSeparatorToolItem" id="toolbutton1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="homogeneous">True</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkToolButton" id="up-toolbutton">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="has_tooltip">True</property>
-                            <property name="tooltip_markup" translatable="yes">Move Disk Up</property>
-                            <property name="tooltip_text" translatable="yes">Move Disk Up</property>
-                            <property name="label" translatable="yes">Move Disk Up</property>
-                            <property name="use_underline">True</property>
-                            <property name="icon_name">go-up-symbolic</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="homogeneous">True</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkToolButton" id="down-toolbutton">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="tooltip_markup" translatable="yes">Move Disk Down</property>
-                            <property name="tooltip_text" translatable="yes">Move Disk Down</property>
-                            <property name="label" translatable="yes">Move Disk Down</property>
-                            <property name="use_underline">True</property>
-                            <property name="icon_name">go-down-symbolic</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="homogeneous">True</property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
+                    <property name="xalign">0</property>
                   </object>
                   <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">3</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkGrid" id="grid2">
+                  <object class="GtkLabel" id="size-label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="row_spacing">10</property>
-                    <property name="column_spacing">10</property>
-                    <child>
-                      <object class="GtkLabel" id="label7">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
-                        <property name="label" translatable="yes">Serial Number</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label8">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
-                        <property name="label" translatable="yes">Assessment</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="serial-label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="xalign">0</property>
-                        <property name="selectable">True</property>
-                        <property name="ellipsize">end</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="assessment-label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="xalign">0</property>
-                        <property name="selectable">True</property>
-                        <property name="ellipsize">end</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label9">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
-                        <property name="label" translatable="yes">Model or Name</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="model-label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="xalign">0</property>
-                        <property name="selectable">True</property>
-                        <property name="ellipsize">end</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label10">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">1</property>
-                        <property name="label" translatable="yes">Device</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                      <packing>
-                        <property name="left_attach">0</property>
-                        <property name="top_attach">1</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="device-label">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="hexpand">True</property>
-                        <property name="xalign">0</property>
-                        <property name="selectable">True</property>
-                        <property name="ellipsize">end</property>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="top_attach">1</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
-                      </packing>
-                    </child>
+                    <property name="xalign">0</property>
                   </object>
                   <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">4</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
                   </packing>
                 </child>
               </object>
               <packing>
-                <property name="expand">True</property>
+                <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">2</property>
+                <property name="position">1</property>
               </packing>
             </child>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
             <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
diff --git a/src/disks/gducreateraidarraydialog.c b/src/disks/gducreateraidarraydialog.c
index 694bb00..c0e37c5 100644
--- a/src/disks/gducreateraidarraydialog.c
+++ b/src/disks/gducreateraidarraydialog.c
@@ -27,74 +27,39 @@ typedef struct
 
   gboolean in_update;
 
+  GList *objects;
+
   UDisksClient *client;
   GduWindow *window;
   GtkBuilder *builder;
 
   GtkWidget *dialog;
 
-  GtkWidget *scrolledwindow;
-  GtkWidget *treeview;
-
-  GtkWidget *toolbar;
-  GtkWidget *add_toolbutton;
-  GtkWidget *remove_toolbutton;
-  GtkWidget *up_toolbutton;
-  GtkWidget *down_toolbutton;
+  GtkWidget *infobar_vbox;
 
   GtkWidget *level_combobox;
   GtkWidget *chunk_combobox;
   GtkWidget *name_entry;
-
-  GtkWidget *model_label;
-  GtkWidget *device_label;
-  GtkWidget *serial_label;
-  GtkWidget *assessment_label;
-
-  GtkListStore *store;
+  GtkWidget *num_disks_label;
+  GtkWidget *size_label;
 } DialogData;
 
 static const struct {
   goffset offset;
   const gchar *name;
 } widget_mapping[] = {
-  {G_STRUCT_OFFSET (DialogData, scrolledwindow), "scrolledwindow"},
-  {G_STRUCT_OFFSET (DialogData, treeview), "treeview"},
 
-  {G_STRUCT_OFFSET (DialogData, toolbar), "toolbar"},
-  {G_STRUCT_OFFSET (DialogData, add_toolbutton), "add-toolbutton"},
-  {G_STRUCT_OFFSET (DialogData, remove_toolbutton), "remove-toolbutton"},
-  {G_STRUCT_OFFSET (DialogData, up_toolbutton), "up-toolbutton"},
-  {G_STRUCT_OFFSET (DialogData, down_toolbutton), "down-toolbutton"},
+  {G_STRUCT_OFFSET (DialogData, infobar_vbox), "infobar-vbox"},
 
   {G_STRUCT_OFFSET (DialogData, level_combobox), "level-combobox"},
   {G_STRUCT_OFFSET (DialogData, chunk_combobox), "chunk-combobox"},
   {G_STRUCT_OFFSET (DialogData, name_entry), "name-entry"},
-
-  {G_STRUCT_OFFSET (DialogData, model_label), "model-label"},
-  {G_STRUCT_OFFSET (DialogData, device_label), "device-label"},
-  {G_STRUCT_OFFSET (DialogData, serial_label), "serial-label"},
-  {G_STRUCT_OFFSET (DialogData, assessment_label), "assessment-label"},
+  {G_STRUCT_OFFSET (DialogData, num_disks_label), "num-disks-label"},
+  {G_STRUCT_OFFSET (DialogData, size_label), "size-label"},
 
   {0, NULL}
 };
 
-enum
-{
-  COMBOBOX_MODEL_COLUMN_ID,
-  COMBOBOX_MODEL_COLUMN_MARKUP,
-  COMBOBOX_MODEL_COLUMN_SEPARATOR,
-  COMBOBOX_MODEL_COLUMN_SENSITIVE,
-  COMBOBOX_MODEL_N_COLUMNS,
-};
-
-enum
-{
-  DISKS_MODEL_COLUMN_SLOT,
-  DISKS_MODEL_COLUMN_BLOCK,
-  DISKS_MODEL_N_COLUMNS
-};
-
 static void update_dialog (DialogData *data);
 
 
@@ -102,9 +67,6 @@ static void on_client_changed (UDisksClient  *client,
                                gpointer       user_data);
 
 
-static void on_tree_selection_changed (GtkTreeSelection *selection,
-                                       gpointer          user_data);
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 G_GNUC_UNUSED static DialogData *
@@ -119,10 +81,6 @@ dialog_data_unref (DialogData *data)
 {
   if (g_atomic_int_dec_and_test (&data->ref_count))
     {
-      g_signal_handlers_disconnect_by_func (data->treeview,
-                                            G_CALLBACK (on_tree_selection_changed),
-                                            data);
-
       if (data->dialog != NULL)
         {
           gtk_widget_hide (data->dialog);
@@ -137,6 +95,7 @@ dialog_data_unref (DialogData *data)
       g_clear_object (&data->window);
       g_clear_object (&data->builder);
 
+      g_list_free_full (data->objects, g_object_unref);
       g_free (data);
     }
 }
@@ -149,122 +108,6 @@ dialog_data_close (DialogData *data)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-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 */
-                                       &titer))
-    {
-      gtk_tree_model_get (GTK_TREE_MODEL (data->store),
-                          &titer,
-                          DISKS_MODEL_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 */
-      device_markup = g_strdup_printf (_("%s <span size=\"smaller\">(Read-Only)</span>"),
-                                       udisks_block_get_preferred_device (block));
-    }
-  else
-    {
-      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)
-    {
-      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,
-                                                                      NULL,  /* out_smart_is_supported */
-                                                                      NULL); /* out_warning */
-        }
-    }
-
-  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 : "â");
-  gtk_label_set_markup (GTK_LABEL (data->serial_label),     serial_markup != NULL ?     serial_markup : "â");
-  gtk_label_set_markup (GTK_LABEL (data->assessment_label), assessment_markup != NULL ? assessment_markup : "â");
-
-  g_free (model_markup);
-  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);
-}
-
-static void
-update_dialog_toolbuttons (DialogData *data)
-{
-  gboolean remove_sensitive = FALSE;
-  gboolean up_sensitive = FALSE;
-  gboolean down_sensitive = FALSE;
-  GtkTreeIter iter;
-
-  if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview)),
-                                       NULL, /* out_model */
-                                       &iter))
-    {
-      GtkTreeIter iter2;
-      remove_sensitive = TRUE;
-      iter2 = iter;
-      if (gtk_tree_model_iter_previous (GTK_TREE_MODEL (data->store), &iter2))
-        up_sensitive = TRUE;
-      iter2 = iter;
-      if (gtk_tree_model_iter_next (GTK_TREE_MODEL (data->store), &iter2))
-        down_sensitive = TRUE;
-    }
-
-  gtk_widget_set_sensitive (data->remove_toolbutton, remove_sensitive);
-  gtk_widget_set_sensitive (data->up_toolbutton, up_sensitive);
-  gtk_widget_set_sensitive (data->down_toolbutton, down_sensitive);
-}
-
 
 static void
 update_dialog (DialogData *data)
@@ -274,8 +117,7 @@ update_dialog (DialogData *data)
     goto out;
 
   data->in_update = TRUE;
-  update_dialog_labels (data);
-  update_dialog_toolbuttons (data);
+  /* TODO */
   data->in_update = FALSE;
 
  out:
@@ -295,332 +137,15 @@ on_property_changed (GObject     *object,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static gboolean
-has_block (DialogData  *data,
-           UDisksBlock *block)
-{
-  GtkTreeIter iter;
-  gboolean ret = FALSE;
-
-  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (data->store), &iter))
-    {
-      do
-        {
-          UDisksBlock *iter_block = NULL;
-          gtk_tree_model_get (GTK_TREE_MODEL (data->store), &iter,
-                              DISKS_MODEL_COLUMN_BLOCK, &iter_block,
-                              -1);
-          if (iter_block != NULL)
-            {
-              if (iter_block == block)
-                {
-                  ret = TRUE;
-                  g_object_unref (iter_block);
-                  goto out;
-                }
-              else
-                {
-                  g_object_unref (iter_block);
-                }
-            }
-        }
-      while (gtk_tree_model_iter_next (GTK_TREE_MODEL (data->store), &iter));
-    }
-
- out:
-  return ret;
-}
-
-static gint
-get_num_blocks (DialogData *data)
-{
-  GtkTreeIter iter;
-  gint ret = 0;
-
-  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (data->store), &iter))
-    {
-      do
-        {
-          ret += 1;
-        }
-      while (gtk_tree_model_iter_next (GTK_TREE_MODEL (data->store), &iter));
-    }
-
-  return ret;
-}
-
-static void
-on_add_toolbutton_clicked (GtkToolButton   *tool_button,
-                           gpointer         user_data)
-{
-  DialogData *data = user_data;
-  GList *blocks, *l;
-
-  blocks = gdu_select_disk_dialog_show (gdu_window_get_application (data->window),
-                                        GTK_WINDOW (data->dialog),
-                                        0, /* TODO: size */
-                                        GDU_SELECT_DISK_FLAGS_ALLOW_MULTIPLE);
-  for (l = blocks; l != NULL; l = l->next)
-    {
-      UDisksBlock *block = UDISKS_BLOCK (l->data);
-      gint next_slot;
-
-      if (has_block (data, block))
-        continue;
-
-      next_slot = get_num_blocks (data);
-
-      gtk_list_store_insert_with_values (data->store, NULL /* out_iter */, G_MAXINT, /* position */
-                                         DISKS_MODEL_COLUMN_SLOT, next_slot,
-                                         DISKS_MODEL_COLUMN_BLOCK, block,
-                                         -1);
-
-    }
-  g_list_free_full (blocks, g_object_unref);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static void
-on_remove_toolbutton_clicked (GtkToolButton   *tool_button,
-                              gpointer         user_data)
-{
-  DialogData *data = user_data;
-  GtkTreeIter iter;
-
-  if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview)),
-                                       NULL, /* out_model */
-                                       &iter))
-    {
-      if (gtk_list_store_remove (data->store, &iter))
-        {
-          gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview)),
-                                          &iter);
-        }
-    }
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static gint
-disks_row_sort_func (GtkTreeModel *model,
-                     GtkTreeIter  *a,
-                     GtkTreeIter  *b,
-                     gpointer      user_data);
-
-static void
-on_updown_toolbutton_clicked (GtkToolButton   *tool_button,
-                              DialogData      *data,
-                              gboolean         is_up)
-{
-  GtkTreeIter iter1;
-  GtkTreeIter iter2;
-  gint slot1, slot2;
-
-  if (!gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview)),
-                                        NULL, /* out_model */
-                                        &iter1))
-    goto out;
-
-  iter2 = iter1;
-  if (is_up)
-    {
-      if (!gtk_tree_model_iter_previous (GTK_TREE_MODEL (data->store), &iter2))
-        goto out;
-    }
-  else
-    {
-      if (!gtk_tree_model_iter_next (GTK_TREE_MODEL (data->store), &iter2))
-        goto out;
-    }
-
-  gtk_tree_model_get (GTK_TREE_MODEL (data->store), &iter1,
-                      DISKS_MODEL_COLUMN_SLOT, &slot1,
-                      -1);
-  gtk_tree_model_get (GTK_TREE_MODEL (data->store), &iter2,
-                      DISKS_MODEL_COLUMN_SLOT, &slot2,
-                      -1);
-
-  gtk_list_store_set (data->store, &iter1,
-                      DISKS_MODEL_COLUMN_SLOT, slot2,
-                      -1);
-  gtk_list_store_set (data->store, &iter2,
-                      DISKS_MODEL_COLUMN_SLOT, slot1,
-                      -1);
-
-  update_dialog (data);
- out:
-  ;
-}
-
-static void
-on_down_toolbutton_clicked (GtkToolButton   *tool_button,
-                            gpointer         user_data)
-{
-  DialogData *data = user_data;
-  on_updown_toolbutton_clicked (tool_button, data, FALSE);
-}
-
-static void
-on_up_toolbutton_clicked (GtkToolButton   *tool_button,
-                          gpointer         user_data)
-{
-  DialogData *data = user_data;
-  on_updown_toolbutton_clicked (tool_button, data, TRUE);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static gint
-disks_row_sort_func (GtkTreeModel *model,
-                     GtkTreeIter  *a,
-                     GtkTreeIter  *b,
-                     gpointer      user_data)
-{
-  gint ret;
-  gint slot_a, slot_b;
-  UDisksBlock *block_a = NULL, *block_b = NULL;
-
-  gtk_tree_model_get (model, a,
-                      DISKS_MODEL_COLUMN_SLOT, &slot_a,
-                      DISKS_MODEL_COLUMN_BLOCK, &block_a,
-                      -1);
-  gtk_tree_model_get (model, b,
-                      DISKS_MODEL_COLUMN_SLOT, &slot_b,
-                      DISKS_MODEL_COLUMN_BLOCK, &block_b,
-                      -1);
-
-  ret = slot_a - slot_b;
-  if (ret != 0)
-    goto out;
-
-  ret = g_strcmp0 (udisks_block_get_preferred_device (block_a),
-                   udisks_block_get_preferred_device (block_b));
-
- out:
-  g_clear_object (&block_a);
-  g_clear_object (&block_b);
-  return ret;
-}
-
-static void
-disks_slot_cell_func (GtkTreeViewColumn *column,
-                      GtkCellRenderer   *renderer,
-                      GtkTreeModel      *model,
-                      GtkTreeIter       *iter,
-                      gpointer           user_data)
-{
-  /* DialogData *data = user_data; */
-  gint slot = -1;
-  gchar *markup = NULL;
-
-  gtk_tree_model_get (model,
-                      iter,
-                      DISKS_MODEL_COLUMN_SLOT, &slot,
-                      -1);
-
-  if (slot == -1)
-    {
-      markup = g_strdup_printf ("â");
-    }
-  else
-    {
-      markup = g_strdup_printf ("%d", slot);
-    }
-
-  g_object_set (renderer,
-                "markup", markup,
-                NULL);
-
-  g_free (markup);
-}
-
-static void
-disks_pixbuf_cell_func (GtkTreeViewColumn *column,
-                        GtkCellRenderer   *renderer,
-                        GtkTreeModel      *model,
-                        GtkTreeIter       *iter,
-                        gpointer           user_data)
-{
-  DialogData *data = user_data;
-  UDisksBlock *block = NULL;
-  UDisksObject *object = NULL;
-  UDisksObjectInfo *info = NULL;
-  GIcon *icon = NULL;
-
-  gtk_tree_model_get (model,
-                      iter,
-                      DISKS_MODEL_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;
-
-  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
-disks_name_cell_func (GtkTreeViewColumn *column,
-                      GtkCellRenderer   *renderer,
-                      GtkTreeModel      *model,
-                      GtkTreeIter       *iter,
-                      gpointer           user_data)
+enum
 {
-  DialogData *data = user_data;
-  UDisksBlock *block = NULL;
-  UDisksObject *object = NULL;
-  UDisksObjectInfo *info = NULL;
-  gchar *markup = NULL;
-
-  gtk_tree_model_get (model,
-                      iter,
-                      DISKS_MODEL_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;
-
-  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);
-}
+  COMBOBOX_MODEL_COLUMN_ID,
+  COMBOBOX_MODEL_COLUMN_MARKUP,
+  COMBOBOX_MODEL_COLUMN_SEPARATOR,
+  COMBOBOX_MODEL_COLUMN_SENSITIVE,
+  COMBOBOX_MODEL_N_COLUMNS,
+};
 
-/* ---------------------------------------------------------------------------------------------------- */
 
 static gboolean
 combobox_separator_func (GtkTreeModel *model,
@@ -691,17 +216,8 @@ combobox_add_separator (GtkListStore *model)
 static void
 init_dialog (DialogData *data)
 {
-  GtkTreeViewColumn *column;
-  GtkCellRenderer *renderer;
-  GtkStyleContext *context;
-  GtkListStore *model;
   gchar *s;
-
-  context = gtk_widget_get_style_context (data->scrolledwindow);
-  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
-  context = gtk_widget_get_style_context (data->toolbar);
-  gtk_style_context_add_class (context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
-  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+  GtkListStore *model;
 
   /* ---------- */
   /* 'RAID Level' combobox */
@@ -728,68 +244,6 @@ init_dialog (DialogData *data)
   s = udisks_client_get_size_for_display (data->client,2048*1024, TRUE, FALSE); combobox_add_item (model, s, "chunk_2048"); g_free (s);
 
 
-  /* ---------- */
-  /* Disks list */
-
-  {G_STATIC_ASSERT (DISKS_MODEL_N_COLUMNS == 2);}
-  data->store = gtk_list_store_new (2,
-                                    G_TYPE_INT,
-                                    UDISKS_TYPE_BLOCK);
-
-  gtk_tree_view_set_model (GTK_TREE_VIEW (data->treeview), GTK_TREE_MODEL (data->store));
-  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (data->store),
-                                        DISKS_MODEL_COLUMN_SLOT,
-                                        GTK_SORT_ASCENDING);
-  gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (data->store),
-                                   DISKS_MODEL_COLUMN_SLOT,
-                                   disks_row_sort_func,
-                                   data, /* user_data */
-                                   NULL); /* GDestroyNotify */
-
-  column = gtk_tree_view_column_new ();
-  gtk_tree_view_append_column (GTK_TREE_VIEW (data->treeview), column);
-  /* Translators: column name for the position of the disk in the RAID array */
-  gtk_tree_view_column_set_title (column, C_("mdraid-disks", "Position"));
-  /* -- */
-  renderer = gtk_cell_renderer_text_new ();
-  gtk_tree_view_column_pack_start (column, renderer, TRUE);
-  g_object_set (G_OBJECT (renderer),
-                "yalign", 0.5,
-                NULL);
-  gtk_tree_view_column_set_cell_data_func (column,
-                                           renderer,
-                                           disks_slot_cell_func,
-                                           data,  /* user_data */
-                                           NULL); /* user_data GDestroyNotify */
-
-  column = gtk_tree_view_column_new ();
-  gtk_tree_view_append_column (GTK_TREE_VIEW (data->treeview), column);
-  /* Translators: column name for the disk in the RAID array */
-  gtk_tree_view_column_set_title (column, C_("mdraid-disks", "Disk"));
-  gtk_tree_view_column_set_expand (column, TRUE);
-  /* -- */
-  renderer = gtk_cell_renderer_pixbuf_new ();
-  g_object_set (G_OBJECT (renderer),
-                "stock-size", GTK_ICON_SIZE_SMALL_TOOLBAR,
-                NULL);
-  gtk_tree_view_column_pack_start (column, renderer, FALSE);
-  gtk_tree_view_column_set_cell_data_func (column,
-                                           renderer,
-                                           disks_pixbuf_cell_func,
-                                           data,  /* user_data */
-                                           NULL); /* user_data GDestroyNotify */
-  /* -- */
-  renderer = gtk_cell_renderer_text_new ();
-  gtk_tree_view_column_pack_start (column, renderer, TRUE);
-  g_object_set (G_OBJECT (renderer),
-                "yalign", 0.5,
-                "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
-                NULL);
-  gtk_tree_view_column_set_cell_data_func (column,
-                                           renderer,
-                                           disks_name_cell_func,
-                                           data,  /* user_data */
-                                           NULL); /* user_data GDestroyNotify */
 
   /* ---------- */
   /* defaults: RAID6, 512 KiB Chunk */
@@ -798,33 +252,6 @@ init_dialog (DialogData *data)
 
   /* ---------- */
 
-  g_signal_connect (data->add_toolbutton,
-                    "clicked",
-                    G_CALLBACK (on_add_toolbutton_clicked),
-                    data);
-
-  g_signal_connect (data->remove_toolbutton,
-                    "clicked",
-                    G_CALLBACK (on_remove_toolbutton_clicked),
-                    data);
-
-  g_signal_connect (data->up_toolbutton,
-                    "clicked",
-                    G_CALLBACK (on_up_toolbutton_clicked),
-                    data);
-
-  g_signal_connect (data->down_toolbutton,
-                    "clicked",
-                    G_CALLBACK (on_down_toolbutton_clicked),
-                    data);
-
-  g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (data->treeview)),
-                    "changed",
-                    G_CALLBACK (on_tree_selection_changed),
-                    data);
-
-  /* ---------- */
-
   update_dialog (data);
 }
 
@@ -836,19 +263,12 @@ on_client_changed (UDisksClient   *client,
   update_dialog (data);
 }
 
-static void
-on_tree_selection_changed (GtkTreeSelection *selection,
-                           gpointer          user_data)
-{
-  DialogData *data = user_data;
-  update_dialog (data);
-}
-
 /* ---------------------------------------------------------------------------------------------------- */
 
 
 void
-gdu_create_raid_array_dialog_show (GduWindow    *window)
+gdu_create_raid_array_dialog_show (GduWindow *window,
+                                   GList     *objects)
 {
   DialogData *data;
   guint n;
@@ -857,6 +277,7 @@ gdu_create_raid_array_dialog_show (GduWindow    *window)
   data->ref_count = 1;
   data->window = g_object_ref (window);
   data->client = gdu_window_get_client (data->window);
+  data->objects = g_list_copy_deep (objects, (GCopyFunc) g_object_ref, NULL);
 
   data->dialog = GTK_WIDGET (gdu_application_new_widget (gdu_window_get_application (window),
                                                          "create-raid-array-dialog.ui",
diff --git a/src/disks/gducreateraidarraydialog.h b/src/disks/gducreateraidarraydialog.h
index f8fd39e..1d15229 100644
--- a/src/disks/gducreateraidarraydialog.h
+++ b/src/disks/gducreateraidarraydialog.h
@@ -15,7 +15,8 @@
 
 G_BEGIN_DECLS
 
-void   gdu_create_raid_array_dialog_show (GduWindow    *window);
+void   gdu_create_raid_array_dialog_show (GduWindow *window,
+                                          GList     *objects);
 
 G_END_DECLS
 
diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c
index 8094c2f..2b26a5c 100644
--- a/src/disks/gduwindow.c
+++ b/src/disks/gduwindow.c
@@ -419,6 +419,15 @@ static gboolean on_activate_link (GtkLabel    *label,
                                   const gchar *uri,
                                   gpointer     user_data);
 
+static void on_overlay_toolbar_erase_button_clicked (GtkButton *menu_item,
+                                                     gpointer   user_data);
+
+static void on_ms_raid_menu_item_add_to_activated (GtkMenuItem *menu_item,
+                                                   gpointer   user_data);
+
+static void on_ms_raid_menu_item_create_activated (GtkMenuItem *menu_item,
+                                                   gpointer   user_data);
+
 G_DEFINE_TYPE (GduWindow, gdu_window, GTK_TYPE_APPLICATION_WINDOW);
 
 static void
@@ -926,8 +935,6 @@ static void
 on_device_tree_menu_item_create_raid_array (GtkMenuItem *menu_item,
                                             gpointer   user_data)
 {
-  GduWindow *window = GDU_WINDOW (user_data);
-  gdu_create_raid_array_dialog_show (window);
 }
 #endif
 
@@ -1533,6 +1540,22 @@ gdu_window_constructed (GObject *object)
                     G_CALLBACK (on_activate_link),
                     window);
 
+  /* multiple-selection toolbar */
+  g_signal_connect (window->overlay_toolbar_erase_button,
+                    "clicked",
+                    G_CALLBACK (on_overlay_toolbar_erase_button_clicked),
+                    window);
+
+  /* multiple-selection RAID menu */
+  g_signal_connect (window->ms_raid_menu_item_add_to,
+                    "activate",
+                    G_CALLBACK (on_ms_raid_menu_item_add_to_activated),
+                    window);
+  g_signal_connect (window->ms_raid_menu_item_create,
+                    "activate",
+                    G_CALLBACK (on_ms_raid_menu_item_create_activated),
+                    window);
+
   ensure_something_selected (window);
   device_tree_selection_toolbar_select_done_toggle (window, FALSE);
   gtk_widget_grab_focus (window->device_tree_treeview);
@@ -4428,3 +4451,35 @@ update_for_multi_selection (GduWindow *window, ShowFlags *show_flags)
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_overlay_toolbar_erase_button_clicked (GtkButton *menu_item,
+                                         gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  g_print ("TODO: erase multiple %p\n", window);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_ms_raid_menu_item_add_to_activated (GtkMenuItem *menu_item,
+                                       gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  g_print ("TODO: add to RAID array %p\n", window);
+}
+
+static void
+on_ms_raid_menu_item_create_activated (GtkMenuItem *menu_item,
+                                       gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GList *selected;
+
+  selected = gdu_device_tree_model_get_selected (window->model);
+  /* exit multiple selection mode */
+  device_tree_selection_toolbar_select_done_toggle (window, FALSE);
+  gdu_create_raid_array_dialog_show (window, selected);
+  g_list_free_full (selected, g_object_unref);
+}



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