2019-03-13 22:53:13 +00:00
|
|
|
/* 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>
|
|
|
|
|
2019-05-31 02:52:13 +00:00
|
|
|
|
2019-03-13 22:53:13 +00:00
|
|
|
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));
|
2019-05-31 02:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
button_pressed (GtkButton *widget,
|
|
|
|
GtkWidget *window)
|
|
|
|
{
|
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2019-03-13 22:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_password_entry (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *header;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2019-03-13 22:53:13 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
|
|
|
header = gtk_header_bar_new ();
|
|
|
|
gtk_header_bar_set_show_title_buttons (GTK_HEADER_BAR (header), FALSE);
|
|
|
|
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
2020-04-30 23:04:08 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Choose a Password");
|
2019-03-13 22:53:13 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
|
|
|
gtk_window_set_deletable (GTK_WINDOW (window), FALSE);
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2019-03-13 22:53:13 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (box, 18);
|
|
|
|
gtk_widget_set_margin_end (box, 18);
|
|
|
|
gtk_widget_set_margin_top (box, 18);
|
|
|
|
gtk_widget_set_margin_bottom (box, 18);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2019-03-13 22:53:13 +00:00
|
|
|
|
|
|
|
entry = gtk_password_entry_new ();
|
2019-03-14 22:53:28 +00:00
|
|
|
gtk_password_entry_set_show_peek_icon (GTK_PASSWORD_ENTRY (entry), TRUE);
|
2019-03-13 22:53:13 +00:00
|
|
|
g_object_set (entry,
|
|
|
|
"placeholder-text", "Password",
|
|
|
|
"activates-default", TRUE,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (entry, "notify::text", G_CALLBACK (update_button), NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), entry);
|
2019-03-13 22:53:13 +00:00
|
|
|
|
|
|
|
entry2 = gtk_password_entry_new ();
|
2019-03-14 22:53:28 +00:00
|
|
|
gtk_password_entry_set_show_peek_icon (GTK_PASSWORD_ENTRY (entry2), TRUE);
|
2019-03-13 22:53:13 +00:00
|
|
|
g_object_set (entry2,
|
|
|
|
"placeholder-text", "Confirm",
|
|
|
|
"activates-default", TRUE,
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (entry2, "notify::text", G_CALLBACK (update_button), NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), entry2);
|
2019-03-13 22:53:13 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_mnemonic ("_Done");
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (button, "suggested-action");
|
2019-05-31 02:52:13 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (button_pressed), window);
|
2019-03-13 22:53:13 +00:00
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
|
|
|
|
|
2019-04-28 19:15:11 +00:00
|
|
|
gtk_window_set_default_widget (GTK_WINDOW (window), button);
|
2019-03-13 22:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
gtk_widget_show (window);
|
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2019-03-13 22:53:13 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|