[gnome-disk-utility/udisks2-port] Add GPT and MBR specific flags / name to the Edit Partition dialog



commit fe018c504408c6f3be59f2dbeea6b1c893d24dde
Author: David Zeuthen <davidz redhat com>
Date:   Mon Oct 31 12:47:11 2011 -0400

    Add GPT and MBR specific flags / name to the Edit Partition dialog
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/edit-dos-partition-dialog.ui |  146 ++++++++++++++++
 data/ui/edit-gpt-partition-dialog.ui |  260 ++++++++++++++++++++++++++++
 data/ui/edit-partition-dialog.ui     |   29 +++-
 src/palimpsest/gdupartitiondialog.c  |  308 +++++++++++++++++++++++++---------
 src/palimpsest/gdupartitiondialog.h  |    4 +-
 src/palimpsest/gduwindow.c           |    9 +-
 6 files changed, 668 insertions(+), 88 deletions(-)
---
diff --git a/data/ui/edit-dos-partition-dialog.ui b/data/ui/edit-dos-partition-dialog.ui
new file mode 100644
index 0000000..45ec3ed
--- /dev/null
+++ b/data/ui/edit-dos-partition-dialog.ui
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="edit-dos-partition-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button2">
+                <property name="label" translatable="yes">C_hange</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">&lt;big&gt;Edit Partition&lt;/big&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">10</property>
+            <property name="n_rows">2</property>
+            <property name="n_columns">2</property>
+            <child>
+              <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">_Type:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">type-combobox</property>
+              </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="GtkComboBoxText" id="type-combobox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</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="GtkCheckButton" id="bootable-checkbutton">
+                <property name="label" translatable="yes">_Bootable</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</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>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button1</action-widget>
+      <action-widget response="-5">button2</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/data/ui/edit-gpt-partition-dialog.ui b/data/ui/edit-gpt-partition-dialog.ui
new file mode 100644
index 0000000..c87f5d7
--- /dev/null
+++ b/data/ui/edit-gpt-partition-dialog.ui
@@ -0,0 +1,260 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="edit-gpt-partition-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button2">
+                <property name="label" translatable="yes">C_hange</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">&lt;big&gt;Edit Partition&lt;/big&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_left">12</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">10</property>
+            <property name="n_rows">7</property>
+            <property name="n_columns">2</property>
+            <child>
+              <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">_Type:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">type-combobox</property>
+              </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="GtkComboBoxText" id="type-combobox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</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="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">1</property>
+                <property name="label" translatable="yes">_Name:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">name-entry</property>
+              </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="GtkEntry" id="name-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="max_length">36</property>
+                <property name="invisible_char">â</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>
+            <child>
+              <object class="GtkCheckButton" id="system-checkbutton">
+                <property name="label" translatable="yes">_System partition</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</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="GtkCheckButton" id="bootable-checkbutton">
+                <property name="label" translatable="yes">Legacy BIOS _Bootable</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</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="GtkCheckButton" id="readonly-checkbutton">
+                <property name="label" translatable="yes">_Read-Only</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">4</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="hidden-checkbutton">
+                <property name="label" translatable="yes">_Hidden</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">5</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="do-not-automount-checkbutton">
+                <property name="label" translatable="yes">Do Not _Automount</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+                <property name="xalign">0</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">6</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button1</action-widget>
+      <action-widget response="-5">button2</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/data/ui/edit-partition-dialog.ui b/data/ui/edit-partition-dialog.ui
index 1a1adc9..8f5612a 100644
--- a/data/ui/edit-partition-dialog.ui
+++ b/data/ui/edit-partition-dialog.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkDialog" id="change-partition-type-dialog">
+  <object class="GtkDialog" id="edit-partition-dialog">
     <property name="can_focus">False</property>
     <property name="border_width">12</property>
     <property name="resizable">False</property>
@@ -62,7 +62,7 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="xalign">0</property>
-            <property name="label" translatable="yes">&lt;big&gt;Change Partition Type&lt;/big&gt;</property>
+            <property name="label" translatable="yes">&lt;big&gt;Edit Partition&lt;/big&gt;</property>
             <property name="use_markup">True</property>
           </object>
           <packing>
@@ -84,7 +84,7 @@
                 <property name="xalign">1</property>
                 <property name="label" translatable="yes">_Type:</property>
                 <property name="use_underline">True</property>
-                <property name="mnemonic_widget">change-partition-type-combo-box</property>
+                <property name="mnemonic_widget">type-combobox</property>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -94,7 +94,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkComboBoxText" id="change-partition-type-combo-box">
+              <object class="GtkComboBoxText" id="type-combobox">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
               </object>
@@ -105,6 +105,27 @@
                 <property name="height">1</property>
               </packing>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/src/palimpsest/gdupartitiondialog.c b/src/palimpsest/gdupartitiondialog.c
index 6c83f01..94668f1 100644
--- a/src/palimpsest/gdupartitiondialog.c
+++ b/src/palimpsest/gdupartitiondialog.c
@@ -35,111 +35,263 @@
 
 typedef struct
 {
+  GduWindow *window;
+  UDisksObject *object;
+  UDisksPartition *partition;
+  UDisksPartitionTable *partition_table;
+  gchar *partition_table_type;
+
+  GtkBuilder *builder;
   GtkWidget *dialog;
-  gchar *orig_type;
+  GtkWidget *type_combobox;
+  GtkWidget *name_entry;
+  GtkWidget *system_checkbutton;
+  GtkWidget *bootable_checkbutton;
+  GtkWidget *readonly_checkbutton;
+  GtkWidget *hidden_checkbutton;
+  GtkWidget *do_not_automount_checkbutton;
+
   const gchar **part_types;
-} ChangePartitionTypeData;
+} EditPartitionData;
+
+static void
+edit_partition_data_free (EditPartitionData *data)
+{
+  g_object_unref (data->window);
+  g_object_unref (data->object);
+  g_object_unref (data->partition);
+  g_object_unref (data->partition_table);
+  g_free (data->partition_table_type);
+  g_free (data->part_types);
+  if (data->dialog != NULL)
+    {
+      gtk_widget_hide (data->dialog);
+      gtk_widget_destroy (data->dialog);
+    }
+  if (data->builder != NULL)
+    g_object_unref (data->builder);
+  g_free (data);
+}
 
 static void
-on_change_partition_type_combo_box_changed (GtkComboBox *combo_box,
-                                            gpointer     user_data)
+edit_partition_get (EditPartitionData   *data,
+                    gchar              **out_type,
+                    gchar              **out_name,
+                    guint64             *out_flags)
 {
-  ChangePartitionTypeData *data = user_data;
+  gchar *type = NULL;
+  gchar *name = NULL;
+  guint64 flags = 0;
   gint active;
-  gboolean sensitive;
 
-  sensitive = FALSE;
-  active = gtk_combo_box_get_active (combo_box);
+  active = gtk_combo_box_get_active (GTK_COMBO_BOX (data->type_combobox));
   if (active > 0)
+    type = g_strdup (data->part_types[active]);
+
+  if (g_strcmp0 (data->partition_table_type, "gpt") == 0)
     {
-      if (g_strcmp0 (data->part_types[active], data->orig_type) != 0)
-        {
-          sensitive = TRUE;
-        }
+      name = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->name_entry)));
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->system_checkbutton)))
+        flags |= (1UL<<0);
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->bootable_checkbutton)))
+        flags |= (1UL<<2);
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->readonly_checkbutton)))
+        flags |= (1UL<<60);
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->hidden_checkbutton)))
+        flags |= (1UL<<62);
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->do_not_automount_checkbutton)))
+        flags |= (1UL<<63);
+    }
+  else if (g_strcmp0 (data->partition_table_type, "dos") == 0)
+    {
+      name = g_strdup ("");
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->bootable_checkbutton)))
+        flags |= (1UL<<7);
+    }
+  else
+    {
+      name = g_strdup ("");
     }
 
-  gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog),
-                                     GTK_RESPONSE_OK,
-                                     sensitive);
+  *out_type = type;
+  *out_name = name;
+  *out_flags = flags;
 }
 
-void
-gdu_partition_dialog_show (GduWindow    *window,
-                           UDisksObject *object)
+static void
+edit_partition_update (EditPartitionData *data)
+{
+  gboolean differs = FALSE;
+  gchar *type;
+  gchar *name;
+  guint64 flags;
+
+  edit_partition_get (data, &type, &name, &flags);
+
+  if (g_strcmp0 (udisks_partition_get_type_ (data->partition), type) != 0)
+    differs = TRUE;
+  if (g_strcmp0 (udisks_partition_get_name (data->partition), name) != 0)
+    differs = TRUE;
+  if (udisks_partition_get_flags (data->partition) != flags)
+    differs = TRUE;
+
+  gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, differs);
+
+  g_free (type);
+  g_free (name);
+}
+
+static void
+edit_partition_property_changed (GObject     *object,
+                                 GParamSpec  *pspec,
+                                 gpointer     user_data)
+{
+  EditPartitionData *data = user_data;
+  edit_partition_update (data);
+}
+
+static void
+edit_partition_populate (EditPartitionData *data)
 {
-  gint response;
-  GtkBuilder *builder;
-  GtkWidget *dialog;
-  GtkWidget *combo_box;
-  UDisksPartition *partition;
-  UDisksPartitionTable *partition_table;
-  const gchar *scheme;
   const gchar *cur_type;
-  const gchar **part_types;
   guint n;
   gint active_index;
-  ChangePartitionTypeData data;
-  const gchar *type_to_set;
-
-  partition = udisks_object_peek_partition (object);
-  g_assert (partition != NULL);
-
-  partition_table = udisks_client_get_partition_table (gdu_window_get_client (window), partition);
-  g_assert (partition_table != NULL);
-  g_object_unref (partition_table);
-
-  dialog = gdu_application_new_widget (gdu_window_get_application (window),
-                                       "edit-partition-dialog.ui",
-                                       "change-partition-type-dialog",
-                                       &builder);
-  combo_box = GTK_WIDGET (gtk_builder_get_object (builder, "change-partition-type-combo-box"));
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
-  scheme = udisks_partition_table_get_type_ (partition_table);
-  cur_type = udisks_partition_get_type_ (partition);
-  part_types = udisks_client_get_part_types_for_scheme (gdu_window_get_client (window), scheme);
+
+  cur_type = udisks_partition_get_type_ (data->partition);
+  data->part_types = udisks_client_get_partition_types (gdu_window_get_client (data->window),
+                                                        data->partition_table_type);
   active_index = -1;
-  gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (combo_box));
-  for (n = 0; part_types != NULL && part_types[n] != NULL; n++)
+  gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT (data->type_combobox));
+  for (n = 0; data->part_types != NULL && data->part_types[n] != NULL; n++)
     {
-      const gchar *type;
-      gchar *type_for_display;
-      type = part_types[n];
-      type_for_display = udisks_client_get_part_type_for_display (gdu_window_get_client (window), scheme, type, TRUE);
+      const gchar *type = data->part_types[n];
+      const gchar *type_for_display;
+      gchar *s;
+
+      type_for_display = udisks_client_get_partition_type_for_display (gdu_window_get_client (data->window),
+                                                                       data->partition_table_type,
+                                                                       type);
       if (g_strcmp0 (type, cur_type) == 0)
         active_index = n;
-      gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo_box), NULL, type_for_display);
-      g_free (type_for_display);
+      s = g_strdup_printf ("%s (%s)", type_for_display, type);
+      gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (data->type_combobox), NULL, s);
+      g_free (s);
     }
+  if (active_index > 0)
+    gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), active_index);
 
-  g_signal_connect (combo_box,
-                    "changed",
-                    G_CALLBACK (on_change_partition_type_combo_box_changed),
-                    &data);
-  memset (&data, '\0', sizeof (ChangePartitionTypeData));
-  data.dialog = dialog;
-  data.orig_type = g_strdup (cur_type);
-  data.part_types = part_types;
+  if (g_strcmp0 (data->partition_table_type, "gpt") == 0)
+    {
+      guint64 flags;
+      gtk_entry_set_text (GTK_ENTRY (data->name_entry), udisks_partition_get_name (data->partition));
+      flags = udisks_partition_get_flags (data->partition);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->system_checkbutton),           (flags & (1UL<< 0)) != 0);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->bootable_checkbutton),         (flags & (1UL<< 2)) != 0);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->readonly_checkbutton),         (flags & (1UL<<60)) != 0);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->hidden_checkbutton),           (flags & (1UL<<62)) != 0);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->do_not_automount_checkbutton), (flags & (1UL<<63)) != 0);
+    }
+  else if (g_strcmp0 (data->partition_table_type, "dos") == 0)
+    {
+      guint64 flags;
+      flags = udisks_partition_get_flags (data->partition);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data->bootable_checkbutton),         (flags & (1UL<< 7)) != 0);
+    }
+}
 
-  if (active_index > 0)
-    gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), active_index);
+void
+gdu_partition_dialog_show (GduWindow    *window,
+                           UDisksObject *object)
+{
+  EditPartitionData *data;
+  gint response;
+
+  data = g_new0 (EditPartitionData, 1);
+  data->window = g_object_ref (window);
+  data->object = g_object_ref (object);
+  data->partition = udisks_object_get_partition (object);
+  g_assert (data->partition != NULL);
+  data->partition_table = udisks_client_get_partition_table (gdu_window_get_client (window), data->partition);
+  g_assert (data->partition_table != NULL);
+  data->partition_table_type = udisks_partition_table_dup_type_ (data->partition_table);
+
+  if (g_strcmp0 (data->partition_table_type, "gpt") == 0)
+    {
+      data->dialog = gdu_application_new_widget (gdu_window_get_application (window),
+                                                 "edit-gpt-partition-dialog.ui",
+                                                 "edit-gpt-partition-dialog",
+                                                 &data->builder);
+      data->name_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "name-entry"));
+      data->system_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "system-checkbutton"));
+      data->bootable_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "bootable-checkbutton"));
+      data->readonly_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "readonly-checkbutton"));
+      data->hidden_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "hidden-checkbutton"));
+      data->do_not_automount_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "do-not-automount-checkbutton"));
+      g_signal_connect (data->name_entry,
+                        "notify::text", G_CALLBACK (edit_partition_property_changed), data);
+      g_signal_connect (data->system_checkbutton,
+                        "notify::active", G_CALLBACK (edit_partition_property_changed), data);
+      g_signal_connect (data->bootable_checkbutton,
+                        "notify::active", G_CALLBACK (edit_partition_property_changed), data);
+      g_signal_connect (data->readonly_checkbutton,
+                        "notify::active", G_CALLBACK (edit_partition_property_changed), data);
+      g_signal_connect (data->hidden_checkbutton,
+                        "notify::active", G_CALLBACK (edit_partition_property_changed), data);
+      g_signal_connect (data->do_not_automount_checkbutton,
+                        "notify::active", G_CALLBACK (edit_partition_property_changed), data);
+    }
+  else if (g_strcmp0 (data->partition_table_type, "dos") == 0)
+    {
+      data->dialog = gdu_application_new_widget (gdu_window_get_application (window),
+                                                 "edit-dos-partition-dialog.ui",
+                                                 "edit-dos-partition-dialog",
+                                                 &data->builder);
+      data->bootable_checkbutton = GTK_WIDGET (gtk_builder_get_object (data->builder, "bootable-checkbutton"));
+      g_signal_connect (data->bootable_checkbutton,
+                        "notify::active", G_CALLBACK (edit_partition_property_changed), data);
+    }
+  else
+    {
+      data->dialog = gdu_application_new_widget (gdu_window_get_application (window),
+                                                 "edit-partition-dialog.ui",
+                                                 "edit-partition-dialog",
+                                                 &data->builder);
+    }
+  data->type_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "type-combobox"));
+  g_signal_connect (data->type_combobox,
+                    "notify::active", G_CALLBACK (edit_partition_property_changed), data);
 
-  gtk_widget_show_all (dialog);
-  gtk_widget_grab_focus (combo_box);
+  gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window));
+  gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);
 
-  response = gtk_dialog_run (GTK_DIALOG (dialog));
-  if (response != GTK_RESPONSE_OK)
-    goto out;
+  edit_partition_populate (data);
+  edit_partition_update (data);
 
-  type_to_set = part_types[gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box))];
+  gtk_widget_show_all (data->dialog);
+  gtk_widget_grab_focus (data->type_combobox);
 
-  g_debug ("TODO: set partition type to %s", type_to_set);
+  response = gtk_dialog_run (GTK_DIALOG (data->dialog));
+  if (response == GTK_RESPONSE_OK)
+    {
+      gchar *type;
+      gchar *name;
+      guint64 flags;
+      edit_partition_get (data, &type, &name, &flags);
+      if (g_strcmp0 (udisks_partition_get_type_ (data->partition), type) != 0)
+        {
+          g_debug ("TODO: set partition type to %s", type);
+        }
+      if (g_strcmp0 (udisks_partition_get_name (data->partition), name) != 0)
+        {
+          g_debug ("TODO: set partition name to %s", type);
+        }
+      if (udisks_partition_get_flags (data->partition) != flags)
+        {
+          g_debug ("TODO: set partition flags");
+        }
+      g_free (type);
+      g_free (name);
+    }
 
- out:
-  g_free (part_types);
-  g_free (data.orig_type);
-  gtk_widget_hide (dialog);
-  gtk_widget_destroy (dialog);
-  g_object_unref (builder);
+  edit_partition_data_free (data);
 }
diff --git a/src/palimpsest/gdupartitiondialog.h b/src/palimpsest/gdupartitiondialog.h
index 8b8eb5b..307e40e 100644
--- a/src/palimpsest/gdupartitiondialog.h
+++ b/src/palimpsest/gdupartitiondialog.h
@@ -28,8 +28,8 @@
 
 G_BEGIN_DECLS
 
-void   gdu_partition_dialog_show (GduWindow    *window,
-                                  UDisksObject *object);
+void     gdu_partition_dialog_show (GduWindow    *window,
+                                    UDisksObject *object);
 
 G_END_DECLS
 
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 4d13c52..a9bdb79 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -1866,13 +1866,14 @@ update_device_page_for_free_space (GduWindow          *window,
 
   if (table_type != NULL)
     {
-      gchar *s2;
-      s2 = udisks_client_get_part_scheme_for_display (window->client, table_type);
+      const gchar *table_type_for_display;
+      table_type_for_display = udisks_client_get_partition_table_type_for_display (window->client, table_type);
+      if (table_type_for_display == NULL)
+        table_type_for_display = table_type;
       /* Translators: used to convey free space for partitions - the %s is the
        * partition table format e.g. "Master Boot Record" or "GUID Partition Table"
        */
-      s = g_strdup_printf (_("Unallocated Space (%s)"), s2 != NULL ? s2 : table_type);
-      g_free (s2);
+      s = g_strdup_printf (_("Unallocated Space (%s)"), table_type_for_display);
     }
   else
     {



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