Commit f9a551d8 authored by Stepan Salenikovich's avatar Stepan Salenikovich

Display Ring username after account creation

The Account settings view was being created during account creation
but before registration and the username box was not being updated
once the registration completed. We now connect to the signal
earlier and update the username box accordingly once registration is
complete, even if registration was not initiated from the username
box widget.

Change-Id: I619cbf065d2b2eb6df8399cac0b537d8219eabca
Tuleap: #1177
parent a8ad047e
......@@ -57,6 +57,7 @@ struct _UsernameRegistrationBoxPrivate
QMetaObject::Connection registered_name_found;
QString* username_waiting_for_lookup_result;
gint lookup_timeout;
gulong entry_changed;
gboolean use_blockchain;
gboolean show_register_button;
......@@ -304,59 +305,8 @@ button_register_username_clicked(G_GNUC_UNUSED GtkButton* button, UsernameRegist
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Registering username..."));
priv->name_registration_ended = QObject::connect(
priv->account,
&Account::nameRegistrationEnded,
[=] (NameDirectory::RegisterNameStatus status, G_GNUC_UNUSED const QString& name) {
gtk_spinner_stop(GTK_SPINNER(priv->spinner));
gtk_widget_hide(priv->spinner);
gtk_widget_set_sensitive(priv->entry_username, TRUE);
switch(status)
{
case NameDirectory::RegisterNameStatus::SUCCESS:
{
gtk_label_set_text(GTK_LABEL(priv->label_status), NULL);
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
g_object_set(G_OBJECT(priv->entry_username), "editable", FALSE, NULL);
gtk_widget_hide(priv->button_register_username);
g_signal_emit(G_OBJECT(view), username_registration_box_signals[USERNAME_REGISTRATION_COMPLETED], 0);
break;
}
case NameDirectory::RegisterNameStatus::INVALID_NAME:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Invalid username"));
gtk_widget_show(priv->icon_username_availability);
break;
}
case NameDirectory::RegisterNameStatus::WRONG_PASSWORD:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Bad password"));
gtk_widget_show(priv->icon_username_availability);
break;
}
case NameDirectory::RegisterNameStatus::ALREADY_TAKEN:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Username already taken"));
gtk_widget_show(priv->icon_username_availability);
break;
}
case NameDirectory::RegisterNameStatus::NETWORK_ERROR:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Network error"));
gtk_widget_show(priv->icon_username_availability);
break;
}
}
}
);
if (!priv->account->registerName(password, username))
{
if (!priv->account->registerName(password, username))
{
gtk_spinner_stop(GTK_SPINNER(priv->spinner));
gtk_widget_hide(priv->spinner);
gtk_widget_set_sensitive(priv->entry_username, TRUE);
......@@ -364,7 +314,7 @@ button_register_username_clicked(G_GNUC_UNUSED GtkButton* button, UsernameRegist
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Count not initiate name registration, try again."));
gtk_widget_show(priv->icon_username_availability);
}
}
break;
}
case GTK_RESPONSE_CANCEL:
......@@ -394,7 +344,7 @@ build_view(UsernameRegistrationBox *view, gboolean register_button)
{
//Make the entry editable
g_object_set(G_OBJECT(priv->entry_username), "editable", TRUE, NULL);
g_signal_connect_swapped(priv->entry_username, "changed", G_CALLBACK(entry_username_changed), view);
priv->entry_changed = g_signal_connect_swapped(priv->entry_username, "changed", G_CALLBACK(entry_username_changed), view);
//Show the status icon
gtk_widget_show(priv->icon_username_availability);
......@@ -410,8 +360,66 @@ build_view(UsernameRegistrationBox *view, gboolean register_button)
//Show the status label
gtk_widget_show(priv->label_status);
}
if (priv->account) {
priv->name_registration_ended = QObject::connect(
priv->account,
&Account::nameRegistrationEnded,
[=] (NameDirectory::RegisterNameStatus status, G_GNUC_UNUSED const QString& name) {
gtk_spinner_stop(GTK_SPINNER(priv->spinner));
gtk_widget_hide(priv->spinner);
gtk_widget_set_sensitive(priv->entry_username, TRUE);
switch(status)
{
case NameDirectory::RegisterNameStatus::SUCCESS:
{
// update the entry to what was registered, just to be sure
// don't do more lookups
if (priv->entry_changed != 0) {
g_signal_handler_disconnect(priv->entry_username, priv->entry_changed);
priv->entry_changed = 0;
}
gtk_entry_set_text(GTK_ENTRY(priv->entry_username), name.toUtf8().constData());
gtk_label_set_text(GTK_LABEL(priv->label_status), NULL);
g_object_set(G_OBJECT(priv->entry_username), "editable", FALSE, NULL);
gtk_widget_hide(priv->button_register_username);
g_signal_emit(G_OBJECT(view), username_registration_box_signals[USERNAME_REGISTRATION_COMPLETED], 0);
break;
}
case NameDirectory::RegisterNameStatus::INVALID_NAME:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Invalid username"));
gtk_widget_show(priv->icon_username_availability);
break;
}
case NameDirectory::RegisterNameStatus::WRONG_PASSWORD:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Bad password"));
gtk_widget_show(priv->icon_username_availability);
break;
}
case NameDirectory::RegisterNameStatus::ALREADY_TAKEN:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Username already taken"));
gtk_widget_show(priv->icon_username_availability);
break;
}
case NameDirectory::RegisterNameStatus::NETWORK_ERROR:
{
gtk_widget_set_sensitive(priv->button_register_username, TRUE);
gtk_label_set_text(GTK_LABEL(priv->label_status), _("Network error"));
gtk_widget_show(priv->icon_username_availability);
break;
}
}
}
);
}
}
}
GtkWidget *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment