[gnome-control-center] user-accounts: Password dialog redesign
- From: Thomas Wood <thos src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: Password dialog redesign
- Date: Tue, 11 Jun 2013 14:29:24 +0000 (UTC)
commit d134890b8b8785792eda1b30793915f435729333
Author: Ondrej Holy <oholy redhat com>
Date: Fri Mar 1 13:38:56 2013 +0100
user-accounts: Password dialog redesign
https://bugzilla.gnome.org/show_bug.cgi?id=695450
panels/user-accounts/data/password-dialog.ui | 412 +++++++---------------
panels/user-accounts/um-password-dialog.c | 468 ++++++++++----------------
panels/user-accounts/um-password-dialog.h | 2 -
panels/user-accounts/um-user-panel.c | 1 -
4 files changed, 305 insertions(+), 578 deletions(-)
---
diff --git a/panels/user-accounts/data/password-dialog.ui b/panels/user-accounts/data/password-dialog.ui
index 65c05de..71d7ac5 100644
--- a/panels/user-accounts/data/password-dialog.ui
+++ b/panels/user-accounts/data/password-dialog.ui
@@ -1,40 +1,10 @@
<?xml version="1.0"?>
<interface>
- <!-- interface-requires gtk+ 3.8 -->
+ <!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkListStore" id="action-model">
- <columns>
- <!-- column-name gchararray -->
- <column type="gchararray"/>
- <!-- column-name gint -->
- <column type="gint"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">Set a password now</col>
- <col id="1">0</col>
- </row>
- <row>
- <col id="0" translatable="yes">Choose password at next login</col>
- <col id="1">1</col>
- </row>
- <row>
- <col id="0" translatable="yes">Log in without a password</col>
- <col id="1">2</col>
- </row>
- <row>
- <col id="0" translatable="yes">Disable this account</col>
- <col id="1">3</col>
- </row>
- <row>
- <col id="0" translatable="yes">Enable this account</col>
- <col id="1">4</col>
- </row>
- </data>
- </object>
<object class="GtkDialog" id="dialog">
- <property name="border_width">5</property>
- <property name="title"> </property>
+ <property name="border_width">6</property>
+ <property name="title">Change Password</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
@@ -45,178 +15,152 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
- <property name="spacing">12</property>
+ <property name="spacing">6</property>
<child>
- <object class="GtkVBox" id="vbox7">
+ <object class="GtkBox" id="vbox7">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
- <property name="spacing">16</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
<child>
- <object class="GtkTable" id="table4">
+ <object class="GtkGrid" id="table4">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="n_rows">7</property>
- <property name="n_columns">2</property>
- <property name="column_spacing">10</property>
+ <property name="column_spacing">6</property>
<property name="row_spacing">6</property>
- <child>
- <placeholder/>
- </child>
+ <property name="hexpand">True</property>
<child>
<object class="GtkEntry" id="verify-entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="visibility">False</property>
+ <property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
<property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="password-hint">
+ <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="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.83"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="password-normal-verify-label">
<property name="visible">True</property>
<property name="xalign">1</property>
- <property name="label" translatable="yes">C_onfirm password</property>
+ <property name="label" translatable="yes">C_onfirm New Password</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">verify-entry</property>
+ <property name="margin_left">25</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
+ <property name="left_attach">0</property>
<property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
- <property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbox17">
+ <object class="GtkLabel" id="password-normal-password-label">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkLabel" id="password-normal-password-label">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_New password</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">password-entry</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label35">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">_New Password</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">password-entry</property>
+ <property name="margin_left">25</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
</object>
<packing>
+ <property name="left_attach">0</property>
<property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
- <property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbox16">
+ <object class="GtkEntry" id="password-entry">
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="visibility">False</property>
+ <property name="hexpand">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box13">
<property name="orientation">vertical</property>
- <property name="spacing">6</property>
+ <property name="visible">True</property>
<child>
- <object class="GtkHBox" id="hbox1">
+ <object class="GtkLevelBar" id="strength-indicator">
<property name="visible">True</property>
- <property name="spacing">6</property>
- <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="secondary-icon-name">system-run-symbolic</property>
- <property name="secondary-icon-tooltip-text" translatable="yes">Generate a
password</property>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
+ <property name="mode">discrete</property>
+ <property name="max-value">4</property>
+ <offsets>
+ <offset name="low" value="1"/>
+ <offset name="high" value="3"/>
+ </offsets>
</object>
<packing>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox13">
+ <object class="GtkLabel" id="strength-indicator-label">
<property name="visible">True</property>
- <property name="spacing">9</property>
- <child>
- <object class="GtkAlignment" id="alignment1">
- <property name="visible">True</property>
- <property name="top_padding">6</property>
- <property name="bottom_padding">6</property>
- <child>
- <object class="GtkLevelBar" id="strength-indicator">
- <property name="visible">True</property>
- <property name="mode">discrete</property>
- <property name="max-value">4</property>
- <offsets>
- <offset name="low" value="1"/>
- <offset name="high" value="3"/>
- </offsets>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="strength-indicator-label">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label"></property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes"></property>
+ <attributes>
+ <attribute name="scale" value="0.83"/>
+ </attributes>
</object>
<packing>
- <property name="position">1</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
+ <property name="left_attach">2</property>
<property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="old-password-label">
<property name="visible">True</property>
<property name="xalign">1</property>
- <property name="label" translatable="yes">Current _password</property>
+ <property name="label" translatable="yes">Current _Password</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">old-password-entry</property>
+ <property name="margin_left">25</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
+ <property name="left_attach">0</property>
<property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
</packing>
</child>
<child>
@@ -224,117 +168,78 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="visibility">False</property>
+ <property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="right_attach">2</property>
<property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="action-label">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">_Action</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">action-combo</property>
- <style>
- <class name="dim-label"/>
- </style>
- </object>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
</packing>
</child>
<child>
- <object class="GtkComboBox" id="action-combo">
- <property name="visible">True</property>
- <property name="model">action-model</property>
- <child>
- <object class="GtkCellRendererText" id="renderer"/>
- <attributes>
- <attribute name="text">0</attribute>
- </attributes>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkHBox" id="hbox3">
+ <object class="GtkBox" id="action-radio-box">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
- <object class="GtkLabel" id="blablalabel23">
+ <object class="GtkRadioButton" id="action-login-radio">
+ <property name="label" translatable="yes">Allow user to set a password when they
next login</property>
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkImage" id="user-icon">
+ <object class="GtkRadioButton" id="action-now-radio">
+ <property name="label" translatable="yes">Set a password now</property>
<property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">action-login-radio</property>
</object>
<packing>
- <property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
- <property name="x_options">GTK_FILL</property>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">3</property>
</packing>
</child>
<child>
- <object class="GtkVBox" id="vbox6">
+ <object class="GtkBox" id="box18">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
<child>
- <object class="GtkLabel" id="label8">
+ <object class="GtkImage" id="old-password-checkmark">
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Changing password for</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-apply</property>
+ <property name="halign">start</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
- <object class="GtkLabel" id="user-name">
+ <object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="ellipsize">end</property>
- <property name="max_width_chars">30</property>
- <attributes>
- <attribute name="weight" value="bold"/>
- <attribute name="scale" value="1.200000"/>
- </attributes>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkSpinner" id="old-password-spinner">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ </object>
+ </child>
</object>
<packing>
<property name="position">1</property>
@@ -342,29 +247,10 @@
</child>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="show-password-checkbutton">
- <property name="label" translatable="yes">_Show password</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">6</property>
- <property name="bottom_attach">7</property>
+ <property name="left_attach">2</property>
+ <property name="top_attach">3</property>
</packing>
</child>
- <child>
- <placeholder/>
- </child>
</object>
<packing>
<property name="position">0</property>
@@ -380,71 +266,36 @@
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
- <property name="layout_style">edge</property>
+ <property name="layout_style">end</property>
<child>
- <object class="GtkAlignment" id="alignment2">
+ <object class="GtkButton" id="ok-button">
+ <property name="label" translatable="yes">Ch_ange</property>
<property name="visible">True</property>
- <property name="xalign">0</property>
- <child>
- <object class="GtkLabel" id="password-normal-strength-hints-label">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="label" translatable="yes">How to choose a strong password</property>
- <property name="use_markup">True</property>
- <property name="track_visited_links">False</property>
- </object>
- </child>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">0</property>
- <property name="secondary">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
- <object class="GtkHButtonBox" id="hbuttonbox1">
+ <object class="GtkButton" id="cancel-button">
+ <property name="label">gtk-cancel</property>
<property name="visible">True</property>
- <property name="spacing">6</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="ok-button">
- <property name="label" translatable="yes">Ch_ange</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="cancel-button">
- <property name="label">gtk-cancel</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
- <property name="secondary">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
</packing>
</child>
</object>
@@ -457,5 +308,4 @@
</object>
</child>
</object>
- <object class="GtkSizeGroup" id="sizegroup"/>
</interface>
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index 62efdb0..03b895f 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -36,37 +36,35 @@
#include "run-passwd.h"
#include "pw-utils.h"
+#define PASSWORD_CHECK_TIMEOUT 500
+
struct _UmPasswordDialog {
GtkWidget *dialog;
- GtkWidget *user_icon;
- GtkWidget *user_name;
- GtkWidget *action_label;
- GtkWidget *action_combo;
+ GtkWidget *action_radio_box;
+ GtkWidget *action_now_radio;
+ GtkWidget *action_login_radio;
GtkWidget *password_entry;
GtkWidget *verify_entry;
+ gint password_entry_timeout_id;
GtkWidget *strength_indicator;
GtkWidget *strength_indicator_label;
- GtkWidget *show_password_button;
GtkWidget *ok_button;
+ GtkWidget *password_hint;
ActUser *user;
+ ActUserPasswordMode password_mode;
GtkWidget *old_password_label;
GtkWidget *old_password_entry;
+ GtkWidget *old_password_checkmark;
+ GtkWidget *old_password_spinner;
gboolean old_password_ok;
+ gint old_password_entry_timeout_id;
PasswdHandler *passwd_handler;
};
-typedef enum {
- UM_PASSWORD_DIALOG_MODE_NORMAL = 0,
- UM_PASSWORD_DIALOG_MODE_SET_AT_LOGIN,
- UM_PASSWORD_DIALOG_MODE_NO_PASSWORD,
- UM_PASSWORD_DIALOG_MODE_LOCK_ACCOUNT,
- UM_PASSWORD_DIALOG_MODE_UNLOCK_ACCOUNT
-} UmPasswordDialogMode;
-
-static int
+static gint
update_password_strength (UmPasswordDialog *um)
{
const gchar *password;
@@ -75,6 +73,12 @@ update_password_strength (UmPasswordDialog *um)
gint strength_level;
const gchar *hint;
const gchar *long_hint;
+ const gchar *verify;
+ const gchar *strength_hint;
+
+ if (um->user == NULL) {
+ return 0;
+ }
password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
@@ -83,53 +87,22 @@ update_password_strength (UmPasswordDialog *um)
pw_strength (password, old_password, username,
&hint, &long_hint, &strength_level);
- gtk_level_bar_set_value (GTK_LEVEL_BAR (um->strength_indicator), strength_level);
- gtk_label_set_label (GTK_LABEL (um->strength_indicator_label), hint);
- gtk_widget_set_tooltip_text (um->strength_indicator, long_hint);
- gtk_widget_set_tooltip_text (um->strength_indicator_label, long_hint);
-
- return strength_level;
-}
-
-static void
-generate_one_password (GtkWidget *widget,
- UmPasswordDialog *um)
-{
- gchar *pwd;
-
- pwd = pw_generate ();
-
- gtk_entry_set_text (GTK_ENTRY (um->password_entry), pwd);
- gtk_entry_set_text (GTK_ENTRY (um->verify_entry), "");
-
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->show_password_button),
- TRUE);
-
- g_free (pwd);
-}
+ if (strlen (password) == 0) {
+ strength_hint = "";
+ } else {
+ strength_hint = hint;
+ }
-static void
-activate_icon (GtkEntry *entry,
- GtkEntryIconPosition pos,
- GdkEventButton *event,
- UmPasswordDialog *um)
-{
- generate_one_password (GTK_WIDGET (entry), um);
-}
+ gtk_level_bar_set_value (GTK_LEVEL_BAR (um->strength_indicator), strength_level);
+ gtk_label_set_label (GTK_LABEL (um->strength_indicator_label), strength_hint);
+ gtk_label_set_label (GTK_LABEL (um->password_hint), long_hint);
-static void
-populate_menu (GtkEntry *entry,
- GtkMenu *menu,
- UmPasswordDialog *um)
-{
- GtkWidget *item;
+ verify = gtk_entry_get_text (GTK_ENTRY (um->verify_entry));
+ if (strlen (verify) == 0) {
+ gtk_widget_set_sensitive (um->verify_entry, strength_level > 0);
+ }
- item = gtk_menu_item_new_with_mnemonic (_("_Generate a password"));
- g_signal_connect (item, "activate",
- G_CALLBACK (generate_one_password), um);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ return strength_level;
}
static void
@@ -214,21 +187,12 @@ static void
accept_password_dialog (GtkButton *button,
UmPasswordDialog *um)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
- gint mode;
- const gchar *hint;
const gchar *password;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (um->action_combo));
- gtk_combo_box_get_active_iter (GTK_COMBO_BOX (um->action_combo), &iter);
- gtk_tree_model_get (model, &iter, 1, &mode, -1);
-
password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
- hint = NULL;
- switch (mode) {
- case UM_PASSWORD_DIALOG_MODE_NORMAL:
+ switch (um->password_mode) {
+ case ACT_USER_PASSWORD_MODE_REGULAR:
if (act_user_get_uid (um->user) == getuid ()) {
GdkDisplay *display;
GdkCursor *cursor;
@@ -248,27 +212,14 @@ accept_password_dialog (GtkButton *button,
return;
}
- act_user_set_password (um->user, password, hint);
+ act_user_set_password (um->user, password, "");
break;
- case UM_PASSWORD_DIALOG_MODE_SET_AT_LOGIN:
- act_user_set_password_mode (um->user, ACT_USER_PASSWORD_MODE_SET_AT_LOGIN);
+ case ACT_USER_PASSWORD_MODE_SET_AT_LOGIN:
+ act_user_set_password_mode (um->user, um->password_mode);
act_user_set_automatic_login (um->user, FALSE);
break;
- case UM_PASSWORD_DIALOG_MODE_NO_PASSWORD:
- act_user_set_password_mode (um->user, ACT_USER_PASSWORD_MODE_NONE);
- break;
-
- case UM_PASSWORD_DIALOG_MODE_LOCK_ACCOUNT:
- act_user_set_locked (um->user, TRUE);
- act_user_set_automatic_login (um->user, FALSE);
- break;
-
- case UM_PASSWORD_DIALOG_MODE_UNLOCK_ACCOUNT:
- act_user_set_locked (um->user, FALSE);
- break;
-
default:
g_assert_not_reached ();
}
@@ -280,96 +231,53 @@ static void
update_sensitivity (UmPasswordDialog *um)
{
const gchar *password, *verify;
- const gchar *old_password;
- const gchar *tooltip;
gboolean can_change;
- int strength_level;
+ int strength;
password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
verify = gtk_entry_get_text (GTK_ENTRY (um->verify_entry));
- old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
-
- /* Don't update the password strength if we didn't enter anything */
- if (password && *password == '\0' &&
- verify && *verify == '\0' &&
- old_password && *old_password == '\0')
- return;
- strength_level = update_password_strength (um);
-
- if (strength_level < 1) {
- can_change = FALSE;
- if (password[0] == '\0') {
- tooltip = _("You need to enter a new password");
- }
- else {
- tooltip = _("The new password is not strong enough");
- }
- }
- else if (strcmp (password, verify) != 0) {
- can_change = FALSE;
- if (verify[0] == '\0') {
- tooltip = _("You need to confirm the password");
- }
- else {
- tooltip = _("The passwords do not match");
- }
- }
- else if (!um->old_password_ok) {
- can_change = FALSE;
- if (old_password[0] == '\0') {
- tooltip = _("You need to enter your current password");
- }
- else {
- tooltip = _("The current password is not correct");
- }
+ if (um->password_mode == ACT_USER_PASSWORD_MODE_REGULAR) {
+ strength = update_password_strength (um);
+ can_change = strength > 0 && strcmp (password, verify) == 0 &&
+ (um->old_password_ok || !gtk_widget_get_visible (um->old_password_entry));
}
else {
can_change = TRUE;
- tooltip = NULL;
}
gtk_widget_set_sensitive (um->ok_button, can_change);
- gtk_widget_set_tooltip_text (um->ok_button, tooltip);
}
static void
-action_changed (GtkComboBox *combo,
- UmPasswordDialog *um)
+mode_change (UmPasswordDialog *um,
+ ActUserPasswordMode mode)
{
- gint active;
+ gboolean active;
- active = gtk_combo_box_get_active (combo);
- if (active == 0) {
- gtk_widget_set_sensitive (um->password_entry, TRUE);
- gtk_entry_set_icon_sensitive (GTK_ENTRY (um->password_entry), GTK_ENTRY_ICON_SECONDARY,
TRUE);
- gtk_widget_set_sensitive (um->verify_entry, TRUE);
- gtk_widget_set_sensitive (um->old_password_entry, TRUE);
- gtk_widget_set_sensitive (um->strength_indicator_label, TRUE);
- gtk_widget_set_sensitive (um->show_password_button, TRUE);
+ active = (mode == ACT_USER_PASSWORD_MODE_REGULAR);
+ gtk_widget_set_sensitive (um->password_entry, active);
+ gtk_widget_set_sensitive (um->verify_entry, active);
+ gtk_widget_set_sensitive (um->old_password_entry, active);
+ gtk_widget_set_sensitive (um->strength_indicator_label, active);
+ gtk_widget_set_sensitive (um->password_hint, active);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->action_now_radio), active);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->action_login_radio), !active);
- update_sensitivity (um);
- }
- else {
- gtk_widget_set_sensitive (um->password_entry, FALSE);
- gtk_entry_set_icon_sensitive (GTK_ENTRY (um->password_entry), GTK_ENTRY_ICON_SECONDARY,
FALSE);
- gtk_widget_set_sensitive (um->verify_entry, FALSE);
- gtk_widget_set_sensitive (um->old_password_entry, FALSE);
- gtk_widget_set_sensitive (um->strength_indicator_label, FALSE);
- gtk_widget_set_sensitive (um->show_password_button, FALSE);
- gtk_widget_set_sensitive (um->ok_button, TRUE);
- }
+ um->password_mode = mode;
+ update_sensitivity (um);
}
static void
-show_password_toggled (GtkToggleButton *button,
- UmPasswordDialog *um)
+action_changed (GtkRadioButton *radio,
+ UmPasswordDialog *um)
{
- gboolean active;
+ gint active;
+ ActUserPasswordMode mode;
- active = gtk_toggle_button_get_active (button);
- gtk_entry_set_visibility (GTK_ENTRY (um->password_entry), active);
- gtk_entry_set_visibility (GTK_ENTRY (um->verify_entry), active);
+ active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio));
+ mode = active ? ACT_USER_PASSWORD_MODE_REGULAR : ACT_USER_PASSWORD_MODE_SET_AT_LOGIN;
+ mode_change (um, mode);
}
static void
@@ -383,6 +291,8 @@ update_password_match (UmPasswordDialog *um)
if (strlen (password) > 0 && strlen (verify) > 0) {
if (strcmp (password, verify) != 0) {
+ gtk_label_set_label (GTK_LABEL (um->password_hint),
+ _("The passwords do not match."));
set_entry_validation_error (GTK_ENTRY (um->verify_entry),
_("Passwords do not match"));
}
@@ -392,49 +302,71 @@ update_password_match (UmPasswordDialog *um)
}
}
-static void
-password_entry_changed (GtkEntry *entry,
- GParamSpec *pspec,
- UmPasswordDialog *um)
+static gboolean
+password_entry_timeout (UmPasswordDialog *um)
{
update_password_strength (um);
update_sensitivity (um);
update_password_match (um);
-}
-static gboolean
-password_entry_focus_out (GtkWidget *entry,
- GdkEventFocus *event,
- UmPasswordDialog *um)
-{
- update_password_match (um);
+ um->password_entry_timeout_id = 0;
+
return FALSE;
}
static void
-verify_entry_changed (GtkEntry *entry,
+password_entry_changed (GtkEntry *entry,
GParamSpec *pspec,
UmPasswordDialog *um)
{
+ if (um->password_entry_timeout_id != 0) {
+ g_source_remove (um->password_entry_timeout_id);
+ um->password_entry_timeout_id = 0;
+ }
+
clear_entry_validation_error (GTK_ENTRY (entry));
- update_password_strength (um);
- update_sensitivity (um);
+
+ um->password_entry_timeout_id = g_timeout_add (PASSWORD_CHECK_TIMEOUT,
+ (GSourceFunc) password_entry_timeout,
+ um);
}
static gboolean
-verify_entry_focus_out (GtkWidget *entry,
+password_entry_focus_out (GtkWidget *entry,
GdkEventFocus *event,
UmPasswordDialog *um)
{
- update_password_match (um);
+ if (um->password_entry_timeout_id != 0) {
+ g_source_remove (um->password_entry_timeout_id);
+ um->password_entry_timeout_id = 0;
+ }
+
+ password_entry_timeout (um);
+
return FALSE;
}
static void
+begin_action (UmPasswordDialog *um)
+{
+ gtk_widget_show (um->old_password_spinner);
+ gtk_spinner_start (GTK_SPINNER (um->old_password_spinner));
+}
+
+static void
+finish_action (UmPasswordDialog *um)
+{
+ gtk_widget_hide (um->old_password_spinner);
+ gtk_spinner_stop (GTK_SPINNER (um->old_password_spinner));
+}
+
+static void
auth_cb (PasswdHandler *handler,
GError *error,
UmPasswordDialog *um)
{
+ finish_action (um);
+
if (error) {
um->old_password_ok = FALSE;
set_entry_validation_error (GTK_ENTRY (um->old_password_entry),
@@ -443,64 +375,73 @@ auth_cb (PasswdHandler *handler,
else {
um->old_password_ok = TRUE;
clear_entry_validation_error (GTK_ENTRY (um->old_password_entry));
+ gtk_widget_show (um->old_password_checkmark);
}
update_sensitivity (um);
}
static gboolean
-old_password_entry_focus_out (GtkWidget *entry,
- GdkEventFocus *event,
- UmPasswordDialog *um)
+old_password_entry_timeout (UmPasswordDialog *um)
{
const char *text;
- text = gtk_entry_get_text (GTK_ENTRY (entry));
- if (strlen (text) > 0) {
- passwd_authenticate (um->passwd_handler, text,
- (PasswdCallback)auth_cb, um);
+ text = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
+ if (strlen (text) > 0 && !um->old_password_ok) {
+ begin_action (um);
+ passwd_authenticate (um->passwd_handler, text, (PasswdCallback)auth_cb, um);
}
+ um->old_password_entry_timeout_id = 0;
+
return FALSE;
}
-static void
-old_password_entry_activate (GtkWidget *entry,
- UmPasswordDialog *um)
+static gboolean
+old_password_entry_focus_out (GtkWidget *entry,
+ GdkEventFocus *event,
+ UmPasswordDialog *um)
{
- const char *text;
-
- text = gtk_entry_get_text (GTK_ENTRY (entry));
- if (strlen (text) > 0) {
- passwd_authenticate (um->passwd_handler, text,
- (PasswdCallback)auth_cb, um);
+ if (um->old_password_entry_timeout_id != 0) {
+ g_source_remove (um->old_password_entry_timeout_id);
+ um->old_password_entry_timeout_id = 0;
}
-}
+ old_password_entry_timeout (um);
+
+ return FALSE;
+}
static void
old_password_entry_changed (GtkEntry *entry,
GParamSpec *pspec,
UmPasswordDialog *um)
{
+ if (um->old_password_entry_timeout_id != 0) {
+ g_source_remove (um->old_password_entry_timeout_id);
+ um->old_password_entry_timeout_id = 0;
+ }
+
+ gtk_widget_hide (um->old_password_checkmark);
clear_entry_validation_error (GTK_ENTRY (entry));
um->old_password_ok = FALSE;
update_sensitivity (um);
+
+ um->old_password_entry_timeout_id = g_timeout_add (PASSWORD_CHECK_TIMEOUT,
+ (GSourceFunc) old_password_entry_timeout,
+ um);
}
-void
-um_password_dialog_set_privileged (UmPasswordDialog *um,
- gboolean privileged)
+static void
+hint_allocate (GtkWidget *label,
+ GtkAllocation *allocation,
+ UmPasswordDialog *um)
{
- if (privileged) {
- gtk_widget_set_visible (um->action_label, TRUE);
- gtk_widget_set_visible (um->action_combo, TRUE);
- }
- else {
- gtk_combo_box_set_active (GTK_COMBO_BOX (um->action_combo), 0);
- gtk_widget_set_visible (um->action_label, FALSE);
- gtk_widget_set_visible (um->action_combo, FALSE);
- }
+ gint height;
+
+ /* Allocate enought space for hint and don't change */
+ height = gtk_widget_get_allocated_height (um->strength_indicator_label);
+ gtk_widget_set_size_request (label, allocation->width, height * 3);
}
UmPasswordDialog *
@@ -510,8 +451,6 @@ um_password_dialog_new (void)
GError *error;
UmPasswordDialog *um;
GtkWidget *widget;
- const char *old_label;
- char *label;
gint len;
builder = gtk_builder_new ();
@@ -527,20 +466,17 @@ um_password_dialog_new (void)
um = g_new0 (UmPasswordDialog, 1);
- um->action_label = (GtkWidget *) gtk_builder_get_object (builder, "action-label");
- widget = (GtkWidget *) gtk_builder_get_object (builder, "action-combo");
- g_signal_connect (widget, "changed",
- G_CALLBACK (action_changed), um);
- um->action_combo = widget;
+ um->action_radio_box = (GtkWidget *) gtk_builder_get_object (builder, "action-radio-box");
+ widget = (GtkWidget *) gtk_builder_get_object (builder, "action-now-radio");
+ g_signal_connect (widget, "toggled", G_CALLBACK (action_changed), um);
+ um->action_now_radio = widget;
+ um->action_login_radio = (GtkWidget *) gtk_builder_get_object (builder, "action-login-radio");
widget = (GtkWidget *) gtk_builder_get_object (builder, "dialog");
g_signal_connect (widget, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
um->dialog = widget;
- um->user_icon = (GtkWidget *) gtk_builder_get_object (builder, "user-icon");
- um->user_name = (GtkWidget *) gtk_builder_get_object (builder, "user-name");
-
widget = (GtkWidget *) gtk_builder_get_object (builder, "cancel-button");
g_signal_connect (widget, "clicked",
G_CALLBACK (cancel_password_dialog), um);
@@ -551,31 +487,12 @@ um_password_dialog_new (void)
gtk_widget_grab_default (widget);
um->ok_button = widget;
- widget = (GtkWidget *) gtk_builder_get_object (builder, "password-normal-strength-hints-label");
- old_label = gtk_label_get_label (GTK_LABEL (widget));
- label = g_strdup_printf ("<a href=\"%s\">%s</a>",
- "help:gnome-help/user-goodpassword",
- old_label);
- gtk_label_set_markup (GTK_LABEL (widget), label);
- g_free (label);
-
- widget = (GtkWidget *) gtk_builder_get_object (builder, "show-password-checkbutton");
- g_signal_connect (widget, "toggled",
- G_CALLBACK (show_password_toggled), um);
- um->show_password_button = widget;
-
widget = (GtkWidget *) gtk_builder_get_object (builder, "password-entry");
g_signal_connect (widget, "notify::text",
G_CALLBACK (password_entry_changed), um);
g_signal_connect_after (widget, "focus-out-event",
G_CALLBACK (password_entry_focus_out), um);
gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
-
- g_signal_connect (widget, "icon-press",
- G_CALLBACK (activate_icon), um);
- g_signal_connect (widget, "populate-popup",
- G_CALLBACK (populate_menu), um);
-
um->password_entry = widget;
widget = (GtkWidget *) gtk_builder_get_object (builder, "old-password-entry");
@@ -583,32 +500,30 @@ um_password_dialog_new (void)
G_CALLBACK (old_password_entry_focus_out), um);
g_signal_connect (widget, "notify::text",
G_CALLBACK (old_password_entry_changed), um);
- g_signal_connect (widget, "activate",
- G_CALLBACK (old_password_entry_activate), um);
um->old_password_entry = widget;
um->old_password_label = (GtkWidget *) gtk_builder_get_object (builder, "old-password-label");
+ um->old_password_spinner = (GtkWidget *) gtk_builder_get_object (builder, "old-password-spinner");
+ um->old_password_checkmark = (GtkWidget *) gtk_builder_get_object (builder,
"old-password-checkmark");
+ um->old_password_entry_timeout_id = 0;
widget = (GtkWidget *) gtk_builder_get_object (builder, "verify-entry");
g_signal_connect (widget, "notify::text",
- G_CALLBACK (verify_entry_changed), um);
+ G_CALLBACK (password_entry_changed), um);
g_signal_connect_after (widget, "focus-out-event",
- G_CALLBACK (verify_entry_focus_out), um);
+ G_CALLBACK (password_entry_focus_out), um);
um->verify_entry = widget;
-
- len = 0;
- len = MAX (len, strlen (C_("Password strength", "Too short")));
- len = MAX (len, strlen (C_("Password strength", "Weak")));
- len = MAX (len, strlen (C_("Password strength", "Fair")));
- len = MAX (len, strlen (C_("Password strength", "Good")));
- len = MAX (len, strlen (C_("Password strength", "Strong")));
- len += 2;
+ um->password_entry_timeout_id = 0;
widget = (GtkWidget *) gtk_builder_get_object (builder, "strength-indicator-label");
+ len = pw_strenght_hint_get_width_chars ();
gtk_label_set_width_chars (GTK_LABEL (widget), len);
+ um->strength_indicator_label = widget;
um->strength_indicator = (GtkWidget *) gtk_builder_get_object (builder, "strength-indicator");
- um->strength_indicator_label = (GtkWidget *) gtk_builder_get_object (builder,
"strength-indicator-label");
+ widget = (GtkWidget *)gtk_builder_get_object (builder, "password-hint");
+ g_signal_connect (widget, "size-allocate", G_CALLBACK (hint_allocate), um);
+ um->password_hint = widget;
g_object_unref (builder);
@@ -620,50 +535,28 @@ um_password_dialog_free (UmPasswordDialog *um)
{
gtk_widget_destroy (um->dialog);
- if (um->user)
- g_object_unref (um->user);
+ g_clear_object (&um->user);
if (um->passwd_handler)
passwd_destroy (um->passwd_handler);
- g_free (um);
-}
-
-static gboolean
-visible_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- UmPasswordDialog *um)
-{
- if (um->user) {
- gint mode;
- gboolean locked = act_user_get_locked (um->user);
-
- gtk_tree_model_get (model, iter, 1, &mode, -1);
-
- /* We don't allow the current user to disable their own account,
- * as this can lead to them being 'locked out'.
- */
- if (mode == UM_PASSWORD_DIALOG_MODE_LOCK_ACCOUNT &&
- (locked || act_user_get_uid (um->user) == getuid ()
- || would_demote_only_admin (um->user)))
- return FALSE;
-
- if (mode == UM_PASSWORD_DIALOG_MODE_UNLOCK_ACCOUNT && !locked)
- return FALSE;
-
- return TRUE;
+ if (um->old_password_entry_timeout_id != 0) {
+ g_source_remove (um->old_password_entry_timeout_id);
+ um->old_password_entry_timeout_id = 0;
+ }
+
+ if (um->password_entry_timeout_id != 0) {
+ g_source_remove (um->password_entry_timeout_id);
+ um->password_entry_timeout_id = 0;
}
- return TRUE;
+ g_free (um);
}
void
um_password_dialog_set_user (UmPasswordDialog *um,
ActUser *user)
{
- GdkPixbuf *pixbuf;
- GtkTreeModel *model;
-
if (um->user) {
g_object_unref (um->user);
um->user = NULL;
@@ -671,24 +564,23 @@ um_password_dialog_set_user (UmPasswordDialog *um,
if (user) {
um->user = g_object_ref (user);
- pixbuf = render_user_icon (user, UM_ICON_STYLE_NONE, 48);
- gtk_image_set_from_pixbuf (GTK_IMAGE (um->user_icon), pixbuf);
- g_object_unref (pixbuf);
-
- gtk_label_set_label (GTK_LABEL (um->user_name),
- act_user_get_real_name (user));
-
gtk_entry_set_text (GTK_ENTRY (um->password_entry), "");
gtk_entry_set_text (GTK_ENTRY (um->verify_entry), "");
gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), "");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->show_password_button), FALSE);
- if (act_user_get_uid (um->user) == getuid () &&
- act_user_get_password_mode (um->user) == ACT_USER_PASSWORD_MODE_REGULAR) {
+ gtk_widget_hide (um->old_password_checkmark);
+ gtk_widget_hide (um->old_password_spinner);
+
+ if (act_user_get_uid (um->user) == getuid ()) {
+ mode_change (um, ACT_USER_PASSWORD_MODE_REGULAR);
+ gtk_widget_hide (um->action_radio_box);
gtk_widget_show (um->old_password_label);
gtk_widget_show (um->old_password_entry);
um->old_password_ok = FALSE;
}
else {
+ mode_change (um, ACT_USER_PASSWORD_MODE_SET_AT_LOGIN);
+ gtk_widget_show (um->action_radio_box);
+
gtk_widget_hide (um->old_password_label);
gtk_widget_hide (um->old_password_entry);
um->old_password_ok = TRUE;
@@ -699,18 +591,6 @@ um_password_dialog_set_user (UmPasswordDialog *um,
um->passwd_handler = passwd_init ();
}
}
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (um->action_combo));
- if (!GTK_IS_TREE_MODEL_FILTER (model)) {
- model = gtk_tree_model_filter_new (model, NULL);
- gtk_combo_box_set_model (GTK_COMBO_BOX (um->action_combo), model);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
- (GtkTreeModelFilterVisibleFunc) visible_func,
- um, NULL);
- }
-
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
- gtk_combo_box_set_active (GTK_COMBO_BOX (um->action_combo), 0);
}
void
diff --git a/panels/user-accounts/um-password-dialog.h b/panels/user-accounts/um-password-dialog.h
index c6a5974..ef8e45c 100644
--- a/panels/user-accounts/um-password-dialog.h
+++ b/panels/user-accounts/um-password-dialog.h
@@ -33,8 +33,6 @@ UmPasswordDialog *um_password_dialog_new (void);
void um_password_dialog_free (UmPasswordDialog *dialog);
void um_password_dialog_set_user (UmPasswordDialog *dialog,
ActUser *user);
-void um_password_dialog_set_privileged (UmPasswordDialog *dialog,
- gboolean privileged);
void um_password_dialog_show (UmPasswordDialog *dialog,
GtkWindow *parent);
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 99b448c..0f08f2b 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -1173,7 +1173,6 @@ on_permission_changed (GPermission *permission,
}
um_password_dialog_set_user (d->password_dialog, user);
- um_password_dialog_set_privileged (d->password_dialog, is_authorized);
g_object_unref (user);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]