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




commit 24d9fb03211e1fe94e3b141d18b964701cb85acd
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 12c52f10e..7f3d8b571 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),
@@ -291,6 +295,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,
@@ -359,6 +381,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 8410bd3ab..d46437f07 100644
--- a/src/resources/ui/nautilus-compress-dialog.ui
+++ b/src/resources/ui/nautilus-compress-dialog.ui
@@ -146,6 +146,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]