[gtk] gtk-demo: Add a password entry demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] gtk-demo: Add a password entry demo
- Date: Thu, 14 Mar 2019 22:56:16 +0000 (UTC)
commit f5e112fd2d802df6d2c60325dbf138f0c0241616
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Mar 13 18:53:13 2019 -0400
gtk-demo: Add a password entry demo
demos/gtk-demo/demo.gresource.xml | 1 +
demos/gtk-demo/meson.build | 1 +
demos/gtk-demo/password_entry.c | 87 +++++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+)
---
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 0a49548a48..fa0c245c87 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -189,6 +189,7 @@
<file>paintable_animated.c</file>
<file>paintable_mediastream.c</file>
<file>panes.c</file>
+ <file>password_entry.c</file>
<file>pickers.c</file>
<file>pixbufs.c</file>
<file>popover.c</file>
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index 83d0176250..e331001abb 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -47,6 +47,7 @@ demos = files([
'paintable_animated.c',
'paintable_mediastream.c',
'panes.c',
+ 'password_entry.c',
'pickers.c',
'pixbufs.c',
'popover.c',
diff --git a/demos/gtk-demo/password_entry.c b/demos/gtk-demo/password_entry.c
new file mode 100644
index 0000000000..d190d685ad
--- /dev/null
+++ b/demos/gtk-demo/password_entry.c
@@ -0,0 +1,87 @@
+/* Entry/Password Entry
+ *
+ * GtkPasswordEntry provides common functionality of
+ * entries that are used to enter passwords and other
+ * secrets.
+ *
+ * It will display a warning if CapsLock is on, and it
+ * can optionally provide a way to see the text.
+ */
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+static GtkWidget *entry;
+static GtkWidget *entry2;
+static GtkWidget *button;
+
+static void
+update_button (GObject *object,
+ GParamSpec *pspec,
+ gpointer data)
+{
+ const char *text = gtk_editable_get_text (GTK_EDITABLE (entry));
+ const char *text2 = gtk_editable_get_text (GTK_EDITABLE (entry2));
+
+ gtk_widget_set_sensitive (button,
+ text[0] != '\0' && g_str_equal (text, text2));
+}
+
+GtkWidget *
+do_password_entry (GtkWidget *do_widget)
+{
+ static GtkWidget *window = NULL;
+ GtkWidget *box;
+ GtkWidget *header;
+
+ if (!window)
+ {
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_display (GTK_WINDOW (window),
+ gtk_widget_get_display (do_widget));
+ header = gtk_header_bar_new ();
+ gtk_header_bar_set_title (GTK_HEADER_BAR (header), "Choose a Password");
+ gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
+ gtk_window_set_titlebar (GTK_WINDOW (window), header);
+ gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
+ gtk_window_set_deletable (GTK_WINDOW (window), FALSE);
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ g_object_set (box, "margin", 18, NULL);
+ gtk_container_add (GTK_CONTAINER (window), box);
+
+ entry = gtk_password_entry_new ();
+ g_object_set (entry,
+ "placeholder-text", "Password",
+ "activates-default", TRUE,
+ NULL);
+ g_signal_connect (entry, "notify::text", G_CALLBACK (update_button), NULL);
+ gtk_container_add (GTK_CONTAINER (box), entry);
+
+ entry2 = gtk_password_entry_new ();
+ g_object_set (entry2,
+ "placeholder-text", "Confirm",
+ "activates-default", TRUE,
+ NULL);
+ g_signal_connect (entry2, "notify::text", G_CALLBACK (update_button), NULL);
+ gtk_container_add (GTK_CONTAINER (box), entry2);
+
+ button = gtk_button_new_with_mnemonic ("_Done");
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
+ g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
+ gtk_widget_set_sensitive (button, FALSE);
+ gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
+
+ gtk_widget_set_can_default (button, TRUE);
+ gtk_window_set_default (GTK_WINDOW (window), button);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ gtk_widget_show (window);
+ else
+ gtk_widget_destroy (window);
+
+ return window;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]