src: use embedded eye icon in password entry box
This improves the UI for the password auth box by using an inline icon
for showing/hiding the password text. This is the UI pattern uses by
GNOME shell and other GTK applications.
The two svg files added here are copied from the GTK4 codebase which
is under the LGPLv2+.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé authored 3 years ago
Daniel P. Berrangé committed 3 years ago
0 | <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"> | |
1 | <path d="M13.98 1.99a1 1 0 0 0-.687.303l-.984.984A8 8 0 0 0 8 2 8 8 0 0 0 .262 8.01a8 8 0 0 0 2.943 4.37l-.912.913a1 1 0 1 0 1.414 1.414l11-11a1 1 0 0 0-.727-1.717zM8 4a4 4 0 0 1 2.611.974l-1.42 1.42A2 2 0 0 0 8 6a2 2 0 0 0-2 2 2 2 0 0 0 .396 1.19l-1.42 1.42A4 4 0 0 1 4 8a4 4 0 0 1 4-4zm7.03 2.209l-3.344 3.343a4 4 0 0 1-2.127 2.127l-2.28 2.28a8 8 0 0 0 .721.04 8 8 0 0 0 7.738-6.01 8 8 0 0 0-.709-1.78zm-7.53.79a.5.5 0 0 1 .5.5.5.5 0 0 1-.5.5.5.5 0 0 1-.5-.5.5.5 0 0 1 .5-.5z" fill="#2e3436"/> | |
2 | </svg>⏎ |
0 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
1 | <svg xmlns:osb="http://www.openswatchbook.org/uri/2009/osb" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="16" viewBox="0 0 16 16" version="1.1" id="svg7384" height="16"> | |
2 | <metadata id="metadata90"> | |
3 | <rdf:RDF> | |
4 | <cc:Work rdf:about=""> | |
5 | <dc:format>image/svg+xml</dc:format> | |
6 | <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> | |
7 | <dc:title>Gnome Symbolic Icon Theme</dc:title> | |
8 | </cc:Work> | |
9 | </rdf:RDF> | |
10 | </metadata> | |
11 | <title id="title9167">Gnome Symbolic Icon Theme</title> | |
12 | <defs id="defs7386"> | |
13 | <linearGradient osb:paint="solid" id="linearGradient7212"> | |
14 | <stop style="stop-color:#000000;stop-opacity:1;" offset="0" id="stop7214"/> | |
15 | </linearGradient> | |
16 | </defs> | |
17 | <g transform="translate(-341.0002,-13.000323)" style="display:inline" id="layer9"/> | |
18 | <g transform="translate(-100,-380.00032)" id="layer1"/> | |
19 | <g transform="translate(-100,-380.00032)" style="display:inline" id="layer10"> | |
20 | <path d="m 108,382 a 8,8 0 0 0 -7.73828,6.00977 A 8,8 0 0 0 108,394 8,8 0 0 0 115.73828,387.99023 8,8 0 0 0 108,382 Z m 0,2 a 4,4 0 0 1 4,4 4,4 0 0 1 -4,4 4,4 0 0 1 -4,-4 4,4 0 0 1 4,-4 z" id="path2314" style="opacity:1;vector-effect:none;fill:#2e3436;fill-opacity:1;stroke:none;stroke-width:1.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;marker-start:none;marker-mid:none;marker-end:none;paint-order:normal"/> | |
21 | <path id="path2318" d="m 110,388.00003 a 2,2 0 0 1 -2,2 2,2 0 0 1 -2,-2 2,2 0 0 1 2,-2 2,2 0 0 1 2,2 z" style="vector-effect:none;fill:#2e3436;fill-opacity:1;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"/> | |
22 | </g> | |
23 | <g transform="translate(-100,-380.00032)" id="g6387"/> | |
24 | <g transform="translate(-100,-380.00032)" id="layer11"/> | |
25 | </svg>⏎ |
129 | 129 | <property name="bottom-attach">2</property> |
130 | 130 | </packing> |
131 | 131 | </child> |
132 | <child> | |
133 | <object class="GtkCheckButton" id="show-password"> | |
134 | <property name="label" translatable="yes">Show password</property> | |
135 | <property name="visible">True</property> | |
136 | <property name="can-focus">True</property> | |
137 | <property name="receives-default">False</property> | |
138 | <property name="draw-indicator">False</property> | |
139 | </object> | |
140 | <packing> | |
141 | <property name="left-attach">1</property> | |
142 | <property name="right-attach">2</property> | |
143 | <property name="top-attach">2</property> | |
144 | <property name="bottom-attach">3</property> | |
145 | </packing> | |
146 | </child> | |
147 | <child> | |
148 | <placeholder/> | |
149 | </child> | |
150 | 132 | </object> |
151 | 133 | <packing> |
152 | 134 | <property name="expand">False</property> |
17 | 17 | <file alias="icons/32x32/virt-viewer.png">../../icons/32x32/virt-viewer.png</file> |
18 | 18 | <file alias="icons/48x48/virt-viewer.png">../../icons/48x48/virt-viewer.png</file> |
19 | 19 | <file alias="icons/256x256/virt-viewer.png">../../icons/256x256/virt-viewer.png</file> |
20 | <file alias="icons/eye-not-looking-symbolic.svg">../../icons/scalable/eye-not-looking-symbolic.svg</file> | |
21 | <file alias="icons/eye-open-negative-filled-symbolic.svg">../../icons/scalable/eye-open-negative-filled-symbolic.svg</file> | |
20 | 22 | </gresource> |
21 | 23 | </gresources> |
33 | 33 | #include "virt-viewer-util.h" |
34 | 34 | |
35 | 35 | static void |
36 | show_password(GtkCheckButton *check_button G_GNUC_UNUSED, | |
37 | GtkEntry *entry) | |
36 | show_password(GtkEntry *entry, | |
37 | GtkEntryIconPosition pos G_GNUC_UNUSED, | |
38 | GdkEvent event G_GNUC_UNUSED) | |
38 | 39 | { |
39 | gtk_entry_set_visibility(entry, !gtk_entry_get_visibility(entry)); | |
40 | gboolean visible = gtk_entry_get_visibility(entry); | |
41 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry), | |
42 | GTK_ENTRY_ICON_SECONDARY, | |
43 | visible ? | |
44 | "eye-not-looking-symbolic" : | |
45 | "eye-open-negative-filled-symbolic"); | |
46 | gtk_entry_set_visibility(entry, !visible); | |
40 | 47 | } |
41 | 48 | |
42 | 49 | /* NOTE: if username is provided, and *username is non-NULL, the user input |
57 | 64 | GtkWidget *promptUsername; |
58 | 65 | GtkWidget *promptPassword; |
59 | 66 | GtkWidget *labelMessage; |
60 | GtkWidget *checkPassword; | |
61 | 67 | int response; |
62 | 68 | char *message; |
63 | 69 | |
70 | 76 | promptUsername = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-username")); |
71 | 77 | credPassword = GTK_WIDGET(gtk_builder_get_object(creds, "cred-password")); |
72 | 78 | promptPassword = GTK_WIDGET(gtk_builder_get_object(creds, "prompt-password")); |
73 | checkPassword = GTK_WIDGET(gtk_builder_get_object(creds, "show-password")); | |
74 | 79 | |
75 | 80 | gtk_widget_set_sensitive(credUsername, username != NULL); |
76 | 81 | if (username && *username) { |
82 | 87 | gtk_widget_set_sensitive(credPassword, password != NULL); |
83 | 88 | gtk_widget_set_sensitive(promptPassword, password != NULL); |
84 | 89 | |
85 | g_signal_connect(checkPassword, "clicked", G_CALLBACK(show_password), credPassword); | |
90 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(credPassword), | |
91 | GTK_ENTRY_ICON_SECONDARY, | |
92 | "eye-not-looking-symbolic"); | |
93 | gtk_entry_set_icon_sensitive(GTK_ENTRY(credPassword), | |
94 | GTK_ENTRY_ICON_SECONDARY, | |
95 | TRUE); | |
96 | gtk_entry_set_icon_activatable(GTK_ENTRY(credPassword), | |
97 | GTK_ENTRY_ICON_SECONDARY, | |
98 | TRUE); | |
99 | gtk_entry_set_icon_tooltip_text(GTK_ENTRY(credPassword), | |
100 | GTK_ENTRY_ICON_SECONDARY, | |
101 | _("Show / hide password text")); | |
102 | ||
103 | g_signal_connect(credPassword, "icon-press", G_CALLBACK(show_password), credPassword); | |
86 | 104 | |
87 | 105 | if (address) { |
88 | 106 | message = g_strdup_printf(_("Authentication is required for the %s connection to:\n\n<b>%s</b>\n\n"), |