[gnome-disk-utility/udisks2-port] Support new .Encrypted interface



commit af08bbf0400a4f4c24bf65bd1c6541484b485421
Author: David Zeuthen <davidz redhat com>
Date:   Wed Jun 22 15:09:56 2011 -0400

    Support new .Encrypted interface
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/palimpsest.ui      |  146 +++++++++++++++++++++++++++++++++++++++++++-
 src/palimpsest/gduwindow.c |  106 +++++++++++++++++++++++++++++++-
 2 files changed, 248 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index 57a7f00..245ba2b 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -137,7 +137,9 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="xalign">1</property>
-                <property name="label" translatable="yes">Label:</property>
+                <property name="label" translatable="yes">_Label:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">change-filesystem-label-entry</property>
               </object>
               <packing>
                 <property name="x_options">GTK_FILL</property>
@@ -251,7 +253,9 @@
                 <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="label" translatable="yes">_Type:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">change-partition-type-combo-box</property>
               </object>
               <packing>
                 <property name="x_options">GTK_FILL</property>
@@ -1258,4 +1262,142 @@
       </object>
     </child>
   </object>
+  <object class="GtkDialog" id="unlock-device-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</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-vbox5">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkLabel" id="label8">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">&lt;big&gt;Enter passphrase to unlock&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">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkTable" id="table3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="n_rows">2</property>
+            <property name="n_columns">2</property>
+            <property name="column_spacing">12</property>
+            <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">_Passphrase:</property>
+                <property name="use_underline">True</property>
+                <property name="mnemonic_widget">unlock-device-passphrase-entry</property>
+              </object>
+              <packing>
+                <property name="x_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="unlock-device-passphrase-entry">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="visibility">False</property>
+                <property name="invisible_char">â</property>
+                <property name="activates_default">True</property>
+                <property name="invisible_char_set">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="unlock-device-show-passphrase-check-button">
+                <property name="label" translatable="yes">Sho_w passphrase</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="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area5">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button5">
+                <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="button6">
+                <property name="label" translatable="yes">_Unlock</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">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button5</action-widget>
+      <action-widget response="-5">button6</action-widget>
+    </action-widgets>
+  </object>
 </interface>
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 786b87b..a9f4b6f 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -1554,6 +1554,8 @@ on_change_filesystem_label (GduWindow *window)
   gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
 
   gtk_widget_show_all (dialog);
+  gtk_widget_grab_focus (entry);
+
   response = gtk_dialog_run (GTK_DIALOG (dialog));
   if (response != GTK_RESPONSE_OK)
     goto out;
@@ -1663,6 +1665,8 @@ on_change_partition_type (GduWindow *window)
     gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), active_index);
 
   gtk_widget_show_all (dialog);
+  gtk_widget_grab_focus (combo_box);
+
   response = gtk_dialog_run (GTK_DIALOG (dialog));
   if (response != GTK_RESPONSE_OK)
     goto out;
@@ -1826,19 +1830,117 @@ on_devtab_action_eject_activated (GtkAction *action,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
+unlock_cb (UDisksEncrypted *encrypted,
+           GAsyncResult    *res,
+           gpointer         user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GError *error;
+
+  error = NULL;
+  if (!udisks_encrypted_call_unlock_finish (encrypted,
+                                            NULL, /* out_cleartext_device */
+                                            res,
+                                            &error))
+    {
+      gdu_window_show_error (window,
+                             _("Error unlocking encrypted device"),
+                             error);
+      g_error_free (error);
+    }
+  g_object_unref (window);
+}
+
+static void
 on_devtab_action_unlock_activated (GtkAction *action,
                                    gpointer   user_data)
 {
-  g_debug ("%s: TODO", G_STRFUNC);
+  GduWindow *window = GDU_WINDOW (user_data);
+  gint response;
+  GtkWidget *dialog;
+  GtkWidget *entry;
+  GtkWidget *show_passphrase_check_button;
+  UDisksObject *object;
+  UDisksEncrypted *encrypted;
+
+  /* TODO: look up passphrase from gnome-keyring */
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  encrypted = udisks_object_peek_encrypted (object);
+
+  dialog = gdu_window_get_widget (window, "unlock-device-dialog");
+  entry = gdu_window_get_widget (window, "unlock-device-passphrase-entry");
+  show_passphrase_check_button = gdu_window_get_widget (window, "unlock-device-show-passphrase-check-button");
+
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_passphrase_check_button), FALSE);
+  gtk_entry_set_text (GTK_ENTRY (entry), "");
+
+  g_object_bind_property (show_passphrase_check_button,
+                          "active",
+                          entry,
+                          "visibility",
+                          G_BINDING_SYNC_CREATE);
+
+  gtk_widget_show_all (dialog);
+  gtk_widget_grab_focus (entry);
+
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+  if (response != GTK_RESPONSE_OK)
+    goto out;
+
+  udisks_encrypted_call_unlock (encrypted,
+                                gtk_entry_get_text (GTK_ENTRY (entry)), /* passphrase */
+                                g_variant_new ("a{sv}", NULL), /* options */
+                                NULL, /* cancellable */
+                                (GAsyncReadyCallback) unlock_cb,
+                                g_object_ref (window));
+
+ out:
+  gtk_widget_hide (dialog);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
+lock_cb (UDisksEncrypted *encrypted,
+         GAsyncResult    *res,
+         gpointer         user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GError *error;
+
+  error = NULL;
+  if (!udisks_encrypted_call_lock_finish (encrypted,
+                                          res,
+                                          &error))
+    {
+      gdu_window_show_error (window,
+                             _("Error locking encrypted device"),
+                             error);
+      g_error_free (error);
+    }
+  g_object_unref (window);
+}
+
+static void
 on_devtab_action_lock_activated (GtkAction *action,
                                  gpointer   user_data)
 {
-  g_debug ("%s: TODO", G_STRFUNC);
+  GduWindow *window = GDU_WINDOW (user_data);
+  UDisksObject *object;
+  UDisksEncrypted *encrypted;
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  encrypted = udisks_object_peek_encrypted (object);
+
+  udisks_encrypted_call_lock (encrypted,
+                              g_variant_new ("a{sv}", NULL), /* options */
+                              NULL, /* cancellable */
+                              (GAsyncReadyCallback) lock_cb,
+                              g_object_ref (window));
 }
 
 /* ---------------------------------------------------------------------------------------------------- */



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