[gnome-disk-utility/udisks2-port] Implement UI parts of "Change Partition Type" dialog



commit 62011bf165c871335aef453ded884a252e6ed49c
Author: David Zeuthen <davidz redhat com>
Date:   Sun Mar 13 12:04:40 2011 -0400

    Implement UI parts of "Change Partition Type" dialog
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/palimpsest.ui      |  105 ++++++++++++++++++++++++++++++++++++++++++++
 src/palimpsest/gduwindow.c |  103 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 207 insertions(+), 1 deletions(-)
---
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index b62b5f1..97702ea 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -1,6 +1,111 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="change-partition-type-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="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>
+        </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;Change Partition Type&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="GtkTable" id="table1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="n_columns">2</property>
+            <property name="column_spacing">12</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>
+              </object>
+              <packing>
+                <property name="x_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="change-partition-type-combo-box">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="y_options">GTK_EXPAND</property>
+              </packing>
+            </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>
   <object class="GtkWindow" id="palimpsest-window">
     <property name="can_focus">False</property>
     <property name="border_width">12</property>
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index ba07dea..c2b172e 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -1092,12 +1092,113 @@ on_change_label (GduWindow *window)
   g_debug ("TODO: %s", G_STRFUNC);
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+typedef struct
+{
+  GtkWidget *dialog;
+  gchar *orig_type;
+  const gchar **part_types;
+} ChangePartitionTypeData;
+
+static void
+on_change_partition_type_combo_box_changed (GtkComboBox *combo_box,
+                                            gpointer     user_data)
+{
+  ChangePartitionTypeData *data = user_data;
+  gint active;
+  gboolean sensitive;
+
+  sensitive = FALSE;
+  active = gtk_combo_box_get_active (combo_box);
+  if (active > 0)
+    {
+      if (g_strcmp0 (data->part_types[active], data->orig_type) != 0)
+        {
+          sensitive = TRUE;
+        }
+    }
+
+  gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog),
+                                     GTK_RESPONSE_OK,
+                                     sensitive);
+}
+
 static void
 on_change_partition_type (GduWindow *window)
 {
-  g_debug ("TODO: %s", G_STRFUNC);
+  gint response;
+  GtkWidget *dialog;
+  GtkWidget *combo_box;
+  GDBusObjectProxy *object_proxy;
+  UDisksBlockDevice *block;
+  const gchar *scheme;
+  const gchar *cur_type;
+  const gchar **part_types;
+  guint n;
+  gint active_index;
+  ChangePartitionTypeData data;
+  const gchar *type_to_set;
+
+  object_proxy = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  g_assert (object_proxy != NULL);
+  block = UDISKS_PEEK_BLOCK_DEVICE (object_proxy);
+  g_assert (block != NULL);
+
+  dialog = gdu_window_get_widget (window, "change-partition-type-dialog");
+  combo_box = gdu_window_get_widget (window, "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_block_device_get_part_entry_scheme (block);
+  cur_type = udisks_block_device_get_part_entry_type (block);
+  part_types = udisks_util_get_part_types_for_scheme (scheme);
+  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++)
+    {
+      const gchar *type;
+      gchar *type_for_display;
+      type = part_types[n];
+      type_for_display = udisks_util_get_part_type_for_display (scheme, 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);
+    }
+
+  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 (active_index > 0)
+    gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), active_index);
+
+  gtk_widget_show_all (dialog);
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+  if (response != GTK_RESPONSE_OK)
+    goto out;
+
+  type_to_set = part_types[gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box))];
+
+  g_debug ("TODO: set partition type to %s", type_to_set);
+
+ out:
+  g_signal_handlers_disconnect_by_func (combo_box,
+                                        G_CALLBACK (on_change_partition_type_combo_box_changed),
+                                        &data);
+  gtk_widget_hide (dialog);
+  g_free (part_types);
+  g_free (data.orig_type);
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
 static void
 on_change_partition_label (GduWindow *window)
 {



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