[gnome-initial-setup/wip/port-to-gtk4: 15/23] password: Port to GTK4
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/wip/port-to-gtk4: 15/23] password: Port to GTK4
- Date: Mon, 25 Jul 2022 15:52:56 +0000 (UTC)
commit 2ffca880057469df79185cbafe0c03aec1a8a264
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Thu Jul 7 15:08:22 2022 -0300
password: Port to GTK4
Fixes https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/81
gnome-initial-setup/gnome-initial-setup.c | 4 +-
gnome-initial-setup/meson.build | 2 +-
gnome-initial-setup/pages/meson.build | 2 +-
.../pages/password/gis-password-page.c | 71 ++++--
.../pages/password/gis-password-page.ui | 282 +++++++++------------
5 files changed, 174 insertions(+), 187 deletions(-)
---
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index 816e3163..e5684eb8 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -39,7 +39,7 @@
#include "pages/goa/gis-goa-page.h"
#include "pages/account/gis-account-pages.h"
//#include "pages/parental-controls/gis-parental-controls-page.h"
-//#include "pages/password/gis-password-page.h"
+#include "pages/password/gis-password-page.h"
#include "pages/summary/gis-summary-page.h"
#define VENDOR_PAGES_GROUP "pages"
@@ -71,7 +71,7 @@ static PageData page_table[] = {
PAGE (software, TRUE),
PAGE (goa, FALSE),
PAGE (account, TRUE),
- //PAGE (password, TRUE),
+ PAGE (password, TRUE),
#ifdef HAVE_PARENTAL_CONTROLS
//PAGE (parental_controls, TRUE),
//PAGE (parent_password, TRUE),
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index a7a0d2a5..6bd8d8aa 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -66,7 +66,7 @@ dependencies = [
dependency ('json-glib-1.0'),
dependency ('krb5'),
dependency ('libsecret-1', version: '>= 0.18.8'),
- #dependency ('pwquality'),
+ dependency ('pwquality'),
dependency ('rest-1.0'),
dependency ('webkit2gtk-5.0'),
ibus_dep,
diff --git a/gnome-initial-setup/pages/meson.build b/gnome-initial-setup/pages/meson.build
index f657b945..63e33d0c 100644
--- a/gnome-initial-setup/pages/meson.build
+++ b/gnome-initial-setup/pages/meson.build
@@ -6,7 +6,7 @@ pages = [
'timezone',
'privacy',
'goa',
- #'password',
+ 'password',
'software',
'summary',
'welcome',
diff --git a/gnome-initial-setup/pages/password/gis-password-page.c
b/gnome-initial-setup/pages/password/gis-password-page.c
index d7a62cdf..269cf940 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.c
+++ b/gnome-initial-setup/pages/password/gis-password-page.c
@@ -30,7 +30,6 @@
#include "gis-keyring.h"
#include "pw-utils.h"
-#include "../account/um-utils.h"
#include <glib/gi18n.h>
#include <gio/gio.h>
@@ -65,6 +64,18 @@ typedef enum
static GParamSpec *obj_props[PROP_PARENT_MODE + 1];
+static void
+clear_password_validation_error (GtkWidget *entry)
+{
+ gtk_widget_remove_css_class (entry, "error");
+}
+
+static void
+set_password_validation_error (GtkWidget *entry)
+{
+ gtk_widget_add_css_class (entry, "error");
+}
+
static void
update_header (GisPasswordPage *page)
{
@@ -172,7 +183,7 @@ gis_password_page_save_data (GisPage *gis_page,
return TRUE;
}
- password = gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
+ password = gtk_editable_get_text (GTK_EDITABLE (priv->password_entry));
if (strlen (password) == 0)
act_user_set_password_mode (act_user, ACT_USER_PASSWORD_MODE_NONE);
@@ -210,8 +221,8 @@ validate (GisPasswordPage *page)
g_clear_handle_id (&priv->timeout_id, g_source_remove);
- password = gtk_entry_get_text (GTK_ENTRY (priv->password_entry));
- verify = gtk_entry_get_text (GTK_ENTRY (priv->confirm_entry));
+ password = gtk_editable_get_text (GTK_EDITABLE (priv->password_entry));
+ verify = gtk_editable_get_text (GTK_EDITABLE (priv->confirm_entry));
pw_strength (password, NULL, priv->username, &hint, &strength_level);
gtk_level_bar_set_value (GTK_LEVEL_BAR (priv->password_strength), strength_level);
@@ -221,21 +232,17 @@ validate (GisPasswordPage *page)
priv->valid_confirm = FALSE;
priv->valid_password = (strlen (password) && strength_level > 1);
- if (priv->valid_password) {
- set_entry_validation_checkmark (GTK_ENTRY (priv->password_entry));
- clear_entry_validation_error (GTK_ENTRY (priv->password_entry));
- } else {
- set_entry_validation_error (GTK_ENTRY (priv->password_entry), _("This is a weak password."));
- }
+ if (priv->valid_password)
+ clear_password_validation_error (priv->password_entry);
+ else
+ set_password_validation_error (priv->password_entry);
if (strlen (password) > 0 && strlen (verify) > 0) {
priv->valid_confirm = (strcmp (password, verify) == 0);
- if (!priv->valid_confirm) {
+ if (!priv->valid_confirm)
gtk_label_set_label (GTK_LABEL (priv->confirm_explanation), _("The passwords do not match."));
- }
- else {
- set_entry_validation_checkmark (GTK_ENTRY (priv->confirm_entry));
- }
+ else
+ clear_password_validation_error (priv->password_entry);
}
/*
@@ -265,8 +272,8 @@ password_changed (GtkWidget *w,
{
GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
- clear_entry_validation_error (GTK_ENTRY (w));
- clear_entry_validation_error (GTK_ENTRY (priv->confirm_entry));
+ clear_password_validation_error (w);
+ clear_password_validation_error (priv->confirm_entry);
priv->valid_password = FALSE;
update_page_validation (page);
@@ -283,7 +290,7 @@ confirm_changed (GtkWidget *w,
{
GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
- clear_entry_validation_error (GTK_ENTRY (w));
+ clear_password_validation_error (w);
priv->valid_confirm = FALSE;
update_page_validation (page);
@@ -304,8 +311,8 @@ username_changed (GObject *obj, GParamSpec *pspec, GisPasswordPage *page)
else
gtk_widget_hide (GTK_WIDGET (page));
- clear_entry_validation_error (GTK_ENTRY (priv->password_entry));
- clear_entry_validation_error (GTK_ENTRY (priv->confirm_entry));
+ clear_password_validation_error (priv->password_entry);
+ clear_password_validation_error (priv->confirm_entry);
validate (page);
}
@@ -327,6 +334,18 @@ confirm (GisPasswordPage *page)
gis_assistant_next_page (gis_driver_get_assistant (GIS_PAGE (page)->driver));
}
+static void
+track_focus_out (GisPasswordPage *page,
+ GtkWidget *widget)
+{
+ GtkEventController *focus_controller;
+
+ focus_controller = gtk_event_controller_focus_new ();
+ gtk_widget_add_controller (widget, focus_controller);
+
+ g_signal_connect_swapped (focus_controller, "leave", G_CALLBACK (on_focusout), page);
+}
+
static void
gis_password_page_constructed (GObject *object)
{
@@ -337,17 +356,15 @@ gis_password_page_constructed (GObject *object)
g_signal_connect (priv->password_entry, "notify::text",
G_CALLBACK (password_changed), page);
- g_signal_connect_swapped (priv->password_entry, "focus-out-event",
- G_CALLBACK (on_focusout), page);
g_signal_connect_swapped (priv->password_entry, "activate",
G_CALLBACK (confirm), page);
+ track_focus_out (page, priv->password_entry);
g_signal_connect (priv->confirm_entry, "notify::text",
G_CALLBACK (confirm_changed), page);
- g_signal_connect_swapped (priv->confirm_entry, "focus-out-event",
- G_CALLBACK (on_focusout), page);
g_signal_connect_swapped (priv->confirm_entry, "activate",
G_CALLBACK (confirm), page);
+ track_focus_out (page, priv->confirm_entry);
g_signal_connect (GIS_PAGE (page)->driver, "notify::username",
G_CALLBACK (username_changed), page);
@@ -474,9 +491,9 @@ gis_password_page_init (GisPasswordPage *page)
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (provider, "/org/gnome/initial-setup/gis-password-page.css");
- gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
- GTK_STYLE_PROVIDER (provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ gtk_style_context_add_provider_for_display (gdk_display_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
gtk_widget_init_template (GTK_WIDGET (page));
diff --git a/gnome-initial-setup/pages/password/gis-password-page.ui
b/gnome-initial-setup/pages/password/gis-password-page.ui
index b21010c4..7345e006 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.ui
+++ b/gnome-initial-setup/pages/password/gis-password-page.ui
@@ -1,173 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.0 -->
<template class="GisPasswordPage" parent="GisPage">
+
<child>
- <object class="GtkBox" id="page">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">fill</property>
- <property name="orientation">vertical</property>
+ <object class="AdwPreferencesPage">
+
<child>
- <object class="GisPageHeader" id="header">
- <property name="visible">True</property>
- <property name="margin_top">24</property>
- <!-- title and subtitle are set in code, so are not set here -->
- <property name="icon_name">dialog-password-symbolic</property>
- <property name="show_icon" bind-source="GisPasswordPage" bind-property="small-screen"
bind-flags="invert-boolean|sync-create"/>
- </object>
- </child>
- <child>
- <object class="GtkGrid" id="secrets">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="column_spacing">12</property>
- <property name="row_spacing">6</property>
- <property name="margin_top">40</property>
- <child>
- <object class="GtkLabel" id="password_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_Password</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">password_entry</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
+ <object class="AdwPreferencesGroup">
<child>
- <object class="GtkEntry" id="password_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="visibility">False</property>
- <property name="invisible_char">●</property>
- <property name="invisible_char_set">True</property>
+ <object class="GisPageHeader" id="header">
+ <property name="margin_top">24</property>
+ <!-- title and subtitle are set in code, so are not set here -->
+ <property name="icon_name">dialog-password-symbolic</property>
+ <property name="show_icon" bind-source="GisPasswordPage" bind-property="small-screen"
bind-flags="invert-boolean|sync-create"/>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="confirm_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">end</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_Confirm</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">confirm_entry</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="confirm_entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="visibility">False</property>
- <property name="invisible_char">●</property>
- <property name="invisible_char_set">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLevelBar" id="password_strength">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">fill</property>
- <property name="valign">center</property>
- <property name="max-value">5</property>
- <property name="mode">discrete</property>
- <offsets>
- <offset name="strength-weak" value="1"/>
- <offset name="strength-low" value="2"/>
- <offset name="strength-medium" value="3"/>
- <offset name="strength-good" value="4"/>
- <offset name="strength-high" value="5"/>
- </offsets>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="password_explanation">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0</property>
- <property name="label" translatable="yes"></property>
- <property name="width-chars">35</property>
- <property name="max-width-chars">35</property>
- <property name="height-request">50</property>
- <property name="wrap">True</property>
- <property name="hexpand">True</property>
- <property name="wrap_mode">word-char</property>
- <style>
- <class name="dim-label"/>
- </style>
- <attributes>
- <attribute name="scale" value="0.8"/>
- </attributes>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ </object>
+ </child>
+
+ <child>
+ <object class="AdwPreferencesGroup">
<child>
- <object class="GtkLabel" id="confirm_explanation">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="yalign">0</property>
- <property name="label" translatable="yes"></property>
- <property name="width-chars">35</property>
- <property name="max-width-chars">35</property>
- <property name="wrap">True</property>
- <property name="hexpand">True</property>
- <property name="wrap_mode">word-char</property>
- <style>
- <class name="dim-label"/>
- </style>
- <attributes>
- <attribute name="scale" value="0.8"/>
- </attributes>
+ <object class="GtkGrid" id="secrets">
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
+ <property name="margin_top">40</property>
+ <child>
+ <object class="GtkLabel" id="password_label">
+ <property name="halign">end</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Password</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">password_entry</property>
+ <layout>
+ <property name="column">0</property>
+ <property name="row">0</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkPasswordEntry" id="password_entry">
+ <layout>
+ <property name="column">1</property>
+ <property name="row">0</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="confirm_label">
+ <property name="halign">end</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_Confirm</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">confirm_entry</property>
+ <layout>
+ <property name="column">0</property>
+ <property name="row">3</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkPasswordEntry" id="confirm_entry">
+ <layout>
+ <property name="column">1</property>
+ <property name="row">3</property>
+ </layout>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLevelBar" id="password_strength">
+ <property name="halign">fill</property>
+ <property name="valign">center</property>
+ <property name="max-value">5</property>
+ <property name="mode">discrete</property>
+ <layout>
+ <property name="column">1</property>
+ <property name="row">1</property>
+ </layout>
+ <offsets>
+ <offset name="strength-weak" value="1"/>
+ <offset name="strength-low" value="2"/>
+ <offset name="strength-medium" value="3"/>
+ <offset name="strength-good" value="4"/>
+ <offset name="strength-high" value="5"/>
+ </offsets>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="password_explanation">
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ <property name="label" translatable="yes"></property>
+ <property name="width-chars">35</property>
+ <property name="max-width-chars">35</property>
+ <property name="height-request">50</property>
+ <property name="wrap">True</property>
+ <property name="hexpand">True</property>
+ <property name="wrap_mode">word-char</property>
+ <layout>
+ <property name="column">1</property>
+ <property name="row">2</property>
+ </layout>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ <attributes>
+ <attribute name="scale" value="0.8"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="confirm_explanation">
+ <property name="xalign">0</property>
+ <property name="yalign">0</property>
+ <property name="label" translatable="yes"></property>
+ <property name="width-chars">35</property>
+ <property name="max-width-chars">35</property>
+ <property name="wrap">True</property>
+ <property name="hexpand">True</property>
+ <property name="wrap_mode">word-char</property>
+ <layout>
+ <property name="column">1</property>
+ <property name="row">4</property>
+ </layout>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ <attributes>
+ <attribute name="scale" value="0.8"/>
+ </attributes>
+ </object>
+ </child>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
</object>
</child>
+
</object>
</child>
+
</template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]