[nautilus/wip/oholy/encrypted-archives: 5/6] compress-dialog: Add password visibility icon




commit a52d2eac844f79170e64bd4ee3736bc783b552e6
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Jun 23 10:15:11 2021 +0200

    compress-dialog: Add password visibility icon
    
    There is not an extra entry for password verification. Let's add an icon
    for toggling password visibility at least.
    
    https://gitlab.gnome.org/GNOME/nautilus/-/issues/822

 src/nautilus-compress-dialog-controller.c    | 24 ++++++++++++++++++++++++
 src/resources/ui/nautilus-compress-dialog.ui |  1 +
 2 files changed, 25 insertions(+)
---
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c
index 3c6c137c4..afc302de3 100644
--- a/src/nautilus-compress-dialog-controller.c
+++ b/src/nautilus-compress-dialog-controller.c
@@ -191,9 +191,13 @@ update_selected_format (NautilusCompressDialogController *self,
 
     gtk_widget_set_sensitive (self->passphrase_label, passphrase_sensitive);
     gtk_widget_set_sensitive (self->passphrase_entry, passphrase_sensitive);
+    gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self->passphrase_entry),
+                                       GTK_ENTRY_ICON_SECONDARY,
+                                       passphrase_sensitive ? "view-conceal" : "");
     if (!passphrase_sensitive)
     {
         gtk_entry_set_text (GTK_ENTRY (self->passphrase_entry), "");
+        gtk_entry_set_visibility (GTK_ENTRY (self->passphrase_entry), FALSE);
     }
 
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_button),
@@ -302,6 +306,24 @@ passphrase_entry_on_changed (GtkEditable *editable,
     g_signal_emit_by_name (self->name_entry, "changed");
 }
 
+static void
+passphrase_entry_on_icon_press (GtkEntry            *entry,
+                                GtkEntryIconPosition icon_pos,
+                                GdkEvent            *event,
+                                gpointer             user_data)
+{
+    NautilusCompressDialogController *self;
+    gboolean visibility;
+
+    self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
+    visibility = gtk_entry_get_visibility (GTK_ENTRY (self->passphrase_entry));
+
+    gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self->passphrase_entry),
+                                       GTK_ENTRY_ICON_SECONDARY,
+                                       visibility ? "view-conceal" : "view-reveal");
+    gtk_entry_set_visibility (GTK_ENTRY (self->passphrase_entry), !visibility);
+}
+
 NautilusCompressDialogController *
 nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
                                          NautilusDirectory *destination_directory,
@@ -372,6 +394,8 @@ nautilus_compress_dialog_controller_new (GtkWindow         *parent_window,
                                       G_CALLBACK (seven_zip_radio_button_on_toggled),
                                       "passphrase_entry_on_changed",
                                       G_CALLBACK (passphrase_entry_on_changed),
+                                      "passphrase_entry_on_icon_press",
+                                      G_CALLBACK (passphrase_entry_on_icon_press),
                                       NULL);
     gtk_builder_connect_signals (builder, self);
 
diff --git a/src/resources/ui/nautilus-compress-dialog.ui b/src/resources/ui/nautilus-compress-dialog.ui
index bd2965ab1..098671b6c 100644
--- a/src/resources/ui/nautilus-compress-dialog.ui
+++ b/src/resources/ui/nautilus-compress-dialog.ui
@@ -283,6 +283,7 @@
             <property name="input-purpose">GTK_INPUT_PURPOSE_PASSWORD</property>
             <property name="visibility">False</property>
             <signal name="changed" handler="passphrase_entry_on_changed"/>
+            <signal name="icon-press" handler="passphrase_entry_on_icon_press"/>
           </object>
           <packing>
             <property name="expand">False</property>


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