[gnome-control-center] user-accounts: port to GtkLevelBar
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] user-accounts: port to GtkLevelBar
- Date: Mon, 16 Jul 2012 10:31:59 +0000 (UTC)
commit dfe03a1173f2c1d5cae8db948bfd57a0e193ecf4
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jun 11 09:57:31 2012 -0400
user-accounts: port to GtkLevelBar
This also adds another out parameter to pw_strength(), which is a discrete
indication of the password strength (to be used with GtkLevelBar). The
advantage of having such a parameter back from pw_strength() is that we
can make sure the fill value and the hint string change at the same
time, for better consistency.
https://bugzilla.gnome.org/show_bug.cgi?id=679984
panels/user-accounts/data/password-dialog.ui | 8 ++++++-
panels/user-accounts/pw-utils.c | 30 +++++++++++++++++--------
panels/user-accounts/pw-utils.h | 3 +-
panels/user-accounts/um-password-dialog.c | 9 +++----
panels/user-accounts/um-user-panel.c | 2 -
5 files changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/panels/user-accounts/data/password-dialog.ui b/panels/user-accounts/data/password-dialog.ui
index fc98708..b6f60a8 100644
--- a/panels/user-accounts/data/password-dialog.ui
+++ b/panels/user-accounts/data/password-dialog.ui
@@ -228,8 +228,14 @@
<property name="top_padding">6</property>
<property name="bottom_padding">6</property>
<child>
- <object class="CcStrengthBar" id="strength-indicator">
+ <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>
diff --git a/panels/user-accounts/pw-utils.c b/panels/user-accounts/pw-utils.c
index 8d2fde0..6f089cc 100644
--- a/panels/user-accounts/pw-utils.c
+++ b/panels/user-accounts/pw-utils.c
@@ -79,10 +79,11 @@ pw_strength (const gchar *password,
const gchar *old_password,
const gchar *username,
const gchar **hint,
- const gchar **long_hint)
+ const gchar **long_hint,
+ gint *strength_level)
{
- gint rv;
- gdouble strength;
+ gint rv, level = 0;
+ gdouble strength = 0.0;
void *auxerror;
rv = pwquality_check (get_pwq (),
@@ -92,26 +93,35 @@ pw_strength (const gchar *password,
if (rv == PWQ_ERROR_MIN_LENGTH) {
*hint = C_("Password strength", "Too short");
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
- return 0.0;
+ goto out;
}
else if (rv < 0) {
*hint = C_("Password strength", "Not good enough");
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
- return 0.0;
+ goto out;
}
strength = CLAMP (0.01 * rv, 0.0, 1.0);
- if (strength < 0.50)
+ if (strength < 0.50) {
+ level = 1;
*hint = C_("Password strength", "Weak");
- else if (strength < 0.75)
+ } else if (strength < 0.75) {
+ level = 2;
*hint = C_("Password strength", "Fair");
- else if (strength < 0.90)
+ } else if (strength < 0.90) {
+ level = 3;
*hint = C_("Password strength", "Good");
- else
+ } else {
+ level = 4;
*hint = C_("Password strength", "Strong");
+ }
*long_hint = NULL;
- return strength;
+ out:
+ if (strength_level)
+ *strength_level = level;
+
+ return strength;
}
diff --git a/panels/user-accounts/pw-utils.h b/panels/user-accounts/pw-utils.h
index a88ae34..cacb506 100644
--- a/panels/user-accounts/pw-utils.h
+++ b/panels/user-accounts/pw-utils.h
@@ -27,4 +27,5 @@ gdouble pw_strength (const gchar *password,
const gchar *old_password,
const gchar *username,
const gchar **hint,
- const gchar **long_hints);
+ const gchar **long_hints,
+ gint *strength_level);
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index 8660594..b2a9a66 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -32,7 +32,6 @@
#include "um-password-dialog.h"
#include "um-user-manager.h"
-#include "cc-strength-bar.h"
#include "um-utils.h"
#include "run-passwd.h"
#include "pw-utils.h"
@@ -316,7 +315,7 @@ update_password_strength (UmPasswordDialog *um)
const gchar *password;
const gchar *old_password;
const gchar *username;
- gdouble strength;
+ gint strength_level;
const gchar *hint;
const gchar *long_hint;
@@ -324,10 +323,10 @@ update_password_strength (UmPasswordDialog *um)
old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
username = um_user_get_user_name (um->user);
- strength = pw_strength (password, old_password, username,
- &hint, &long_hint);
+ pw_strength (password, old_password, username,
+ &hint, &long_hint, &strength_level);
- cc_strength_bar_set_fraction (CC_STRENGTH_BAR (um->strength_indicator), strength);
+ 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);
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 3612608..2eb6c14 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -42,7 +42,6 @@
#include "um-user.h"
#include "um-user-manager.h"
-#include "cc-strength-bar.h"
#include "um-editable-button.h"
#include "um-editable-combo.h"
@@ -1258,7 +1257,6 @@ um_user_panel_init (UmUserPanel *self)
d = self->priv = UM_USER_PANEL_PRIVATE (self);
/* register types that the builder might need */
- type = cc_strength_bar_get_type ();
type = um_editable_button_get_type ();
type = cc_editable_entry_get_type ();
type = um_editable_combo_get_type ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]