user-accounts: Don't modify pre-filled username

If user type custom username, don't modify it automatically when
changing fullname.

https://bugzilla.gnome.org/show_bug.cgi?id=778555
This commit is contained in:
Ondrej Holy 2017-02-14 09:13:00 +01:00 committed by Bastien Nocera
parent 2f1af82a4e
commit 9440035560

View file

@ -79,6 +79,7 @@ struct _UmAccountDialog {
/* Local user account widgets */ /* Local user account widgets */
GtkWidget *local_username; GtkWidget *local_username;
GtkWidget *local_username_entry; GtkWidget *local_username_entry;
gboolean has_custom_username;
GtkWidget *local_name; GtkWidget *local_name;
gint local_name_timeout_id; gint local_name_timeout_id;
GtkWidget *local_username_hint; GtkWidget *local_username_hint;
@ -368,13 +369,21 @@ on_username_changed (GtkComboBoxText *combo,
{ {
UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data); UmAccountDialog *self = UM_ACCOUNT_DIALOG (user_data);
GtkWidget *entry; GtkWidget *entry;
const gchar *username;
entry = gtk_bin_get_child (GTK_BIN (self->local_username));
username = gtk_entry_get_text (GTK_ENTRY (entry));
if (*username == '\0')
self->has_custom_username = FALSE;
else if (gtk_widget_has_focus (entry) ||
gtk_combo_box_get_active (GTK_COMBO_BOX (self->local_username)) > 0)
self->has_custom_username = TRUE;
if (self->local_username_timeout_id != 0) { if (self->local_username_timeout_id != 0) {
g_source_remove (self->local_username_timeout_id); g_source_remove (self->local_username_timeout_id);
self->local_username_timeout_id = 0; self->local_username_timeout_id = 0;
} }
entry = gtk_bin_get_child (GTK_BIN (self->local_username));
clear_entry_validation_error (GTK_ENTRY (entry)); clear_entry_validation_error (GTK_ENTRY (entry));
gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE); gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE);
@ -421,12 +430,13 @@ on_name_changed (GtkEditable *editable,
gtk_list_store_clear (GTK_LIST_STORE (model)); gtk_list_store_clear (GTK_LIST_STORE (model));
name = gtk_entry_get_text (GTK_ENTRY (editable)); name = gtk_entry_get_text (GTK_ENTRY (editable));
if (strlen (name) == 0) { if ((name == NULL || strlen (name) == 0) && !self->has_custom_username) {
entry = gtk_bin_get_child (GTK_BIN (self->local_username)); entry = gtk_bin_get_child (GTK_BIN (self->local_username));
gtk_entry_set_text (GTK_ENTRY (entry), ""); gtk_entry_set_text (GTK_ENTRY (entry), "");
} else { } else if (name != NULL && strlen (name) != 0) {
generate_username_choices (name, GTK_LIST_STORE (model)); generate_username_choices (name, GTK_LIST_STORE (model));
gtk_combo_box_set_active (GTK_COMBO_BOX (self->local_username), 0); if (!self->has_custom_username)
gtk_combo_box_set_active (GTK_COMBO_BOX (self->local_username), 0);
} }
clear_entry_validation_error (GTK_ENTRY (editable)); clear_entry_validation_error (GTK_ENTRY (editable));
@ -587,6 +597,7 @@ local_prepare (UmAccountDialog *self)
model = gtk_combo_box_get_model (GTK_COMBO_BOX (self->local_username)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (self->local_username));
gtk_list_store_clear (GTK_LIST_STORE (model)); gtk_list_store_clear (GTK_LIST_STORE (model));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->account_type_standard), TRUE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->account_type_standard), TRUE);
self->has_custom_username = FALSE;
} }
static gboolean static gboolean