diff --git a/src/newaccountsettingsview.cpp b/src/newaccountsettingsview.cpp index 3716d8a1d510e4948bc72325a82f74990ab7dc7d..33bb3b303f265055987cedd83ae6120c2862295f 100644 --- a/src/newaccountsettingsview.cpp +++ b/src/newaccountsettingsview.cpp @@ -190,14 +190,9 @@ struct _NewAccountSettingsViewPrivate GtkWidget* button_add_device_cancel; GtkWidget* entry_password_export_label; GtkWidget* entry_password_export; - - /* generating account spinner */ - GtkWidget* vbox_generating_pin_spinner; - - /* export on ring error */ - GtkWidget* export_on_ring_error; - GtkWidget* label_export_on_ring_error; - GtkWidget* button_export_on_ring_error_ok; + GtkWidget* exporting_infos; + GtkWidget* exporting_spinner; + GtkWidget* exporting_label; QMetaObject::Connection new_device_added_connection; QMetaObject::Connection device_updated_connection; @@ -366,14 +361,9 @@ new_account_settings_view_class_init(NewAccountSettingsViewClass *klass) gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, button_add_device_cancel); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, entry_password_export_label); gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, entry_password_export); - - // generating pin spinner - gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, vbox_generating_pin_spinner); - - // export on ring error - gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, export_on_ring_error); - gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, label_export_on_ring_error); - gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, button_export_on_ring_error_ok); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, exporting_infos); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, exporting_spinner); + gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, exporting_label); // generated_pin view gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS(klass), NewAccountSettingsView, generated_pin); @@ -410,25 +400,6 @@ show_generated_pin_view(NewAccountSettingsView* view) gtk_stack_set_visible_child(GTK_STACK(priv->stack_account), priv->generated_pin); } -static void -show_generating_pin_spinner(NewAccountSettingsView* view) -{ - g_return_if_fail(IS_NEW_ACCOUNT_SETTINGS_VIEW(view)); - auto* priv = NEW_ACCOUNT_SETTINGS_VIEW_GET_PRIVATE(view); - gtk_widget_show(priv->vbox_generating_pin_spinner); - gtk_stack_set_visible_child(GTK_STACK(priv->stack_account), priv->vbox_generating_pin_spinner); -} - -static void -show_export_on_ring_error(NewAccountSettingsView* view) -{ - g_return_if_fail(IS_NEW_ACCOUNT_SETTINGS_VIEW(view)); - auto* priv = NEW_ACCOUNT_SETTINGS_VIEW_GET_PRIVATE(view); - gtk_widget_show(priv->export_on_ring_error); - gtk_stack_set_visible_child(GTK_STACK(priv->stack_account), priv->export_on_ring_error); -} - - // Edit general // TODO(sblin) expliquer le return false @@ -1721,6 +1692,7 @@ show_add_device_view(NewAccountSettingsView* view) gtk_widget_hide(priv->entry_password_export); gtk_widget_hide(priv->entry_password_export_label); } + gtk_widget_hide(priv->exporting_infos); } @@ -1736,6 +1708,9 @@ export_on_the_ring_clicked(G_GNUC_UNUSED GtkButton *button, NewAccountSettingsVi passwordStr = password; } gtk_entry_set_text(GTK_ENTRY(priv->entry_password_export), ""); + gtk_label_set_text(GTK_LABEL(priv->exporting_label), _("Exporting account…")); + gtk_widget_show_all(priv->exporting_infos); + gtk_widget_set_sensitive(priv->button_export_on_the_ring, FALSE); priv->export_on_ring_ended = QObject::connect( (*priv->accountInfo_)->accountModel, @@ -1743,6 +1718,7 @@ export_on_the_ring_clicked(G_GNUC_UNUSED GtkButton *button, NewAccountSettingsVi [=] (const std::string& accountID, lrc::api::account::ExportOnRingStatus status, const std::string& pin) { if (accountID != (*priv->accountInfo_)->id) return; QObject::disconnect(priv->export_on_ring_ended); + gtk_widget_set_sensitive(priv->button_export_on_the_ring, TRUE); switch (status) { case lrc::api::account::ExportOnRingStatus::SUCCESS: @@ -1756,33 +1732,39 @@ export_on_the_ring_clicked(G_GNUC_UNUSED GtkButton *button, NewAccountSettingsVi } case lrc::api::account::ExportOnRingStatus::WRONG_PASSWORD: { - gtk_label_set_text(GTK_LABEL(priv->label_export_on_ring_error), _("Bad password")); - show_export_on_ring_error(view); + gtk_widget_hide(priv->exporting_spinner); + gchar* text = g_markup_printf_escaped("<b>%s</b>", _("Bad password")); + gtk_label_set_markup(GTK_LABEL(priv->exporting_label), text); + gtk_widget_show(priv->exporting_label); break; } case lrc::api::account::ExportOnRingStatus::NETWORK_ERROR: { - gtk_label_set_text(GTK_LABEL(priv->label_export_on_ring_error), _("Network error, try again")); - show_export_on_ring_error(view); + gtk_widget_hide(priv->exporting_spinner); + gchar* text = g_markup_printf_escaped("<b>%s</b>", _("Network error, try again")); + gtk_label_set_markup(GTK_LABEL(priv->exporting_label), text); + gtk_widget_show(priv->exporting_label); break; } default: { - gtk_label_set_text(GTK_LABEL(priv->label_export_on_ring_error), _("Unknown error")); - show_export_on_ring_error(view); + gtk_widget_hide(priv->exporting_spinner); + gchar* text = g_markup_printf_escaped("<b>%s</b>", _("Unknown error")); + gtk_label_set_markup(GTK_LABEL(priv->exporting_label), text); + gtk_widget_show(priv->exporting_label); break; } } } ); - show_generating_pin_spinner(view); if (!(*priv->accountInfo_)->accountModel->exportOnRing((*priv->accountInfo_)->id, passwordStr)) { QObject::disconnect(priv->export_on_ring_ended); - gtk_label_set_text(GTK_LABEL(priv->label_export_on_ring_error), _("Could not initiate export to the Jami, try again")); - g_debug("Could not initiate exportOnRing operation"); - show_export_on_ring_error(view); + gtk_widget_hide(priv->exporting_spinner); + gtk_label_set_text(GTK_LABEL(priv->exporting_label), _("Could not initiate export to the Jami, try again")); + gtk_widget_show(priv->exporting_label); + gtk_widget_set_sensitive(priv->button_export_on_the_ring, TRUE); } } @@ -1978,7 +1960,6 @@ build_settings_view(NewAccountSettingsView* view) g_signal_connect_swapped(priv->button_add_device_cancel, "clicked", G_CALLBACK(show_general_settings), view); g_signal_connect(priv->button_export_on_the_ring, "clicked", G_CALLBACK(export_on_the_ring_clicked), view); g_signal_connect_swapped(priv->button_generated_pin_ok, "clicked", G_CALLBACK(show_general_settings), view); - g_signal_connect_swapped(priv->button_export_on_ring_error_ok, "clicked", G_CALLBACK(show_general_settings), view); } diff --git a/ui/newaccountsettingsview.ui b/ui/newaccountsettingsview.ui index 6d08a17b4bb305b316196150fd136722eaea7a12..a3db4848c3e8dc3736724a9b34124d8d493780f0 100644 --- a/ui/newaccountsettingsview.ui +++ b/ui/newaccountsettingsview.ui @@ -171,6 +171,28 @@ </packing> </child> <!-- End of password entry row --> + <child> + <object class="GtkBox" id="exporting_infos"> + <property name="visible">False</property> + <property name="orientation">horizontal</property> + <property name="spacing">15</property> + <property name="halign">center</property> + <child> + <object class="GtkSpinner" id="exporting_spinner"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="active">True</property> + <property name="height_request">24</property> + </object> + </child> + <child> + <object class="GtkLabel" id="exporting_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + </child> + </object> + </child> <!-- Cancel and export on ring buttons --> <child> <object class="GtkButtonBox" id="buttonbox_confirm"> @@ -195,32 +217,6 @@ </object> </child> <!-- End add device view --> - <!-- Generating pin spinner --> - <child> - <object class="GtkBox" id="vbox_generating_pin_spinner"> - <property name="visible">False</property> - <property name="valign">center</property> - <property name="border_width">10</property> - <property name="orientation">vertical</property> - <property name="spacing">15</property> - <child> - <object class="GtkLabel"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Exporting account on the Jami…</property> - </object> - </child> - <child> - <object class="GtkSpinner"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="active">True</property> - <property name="height_request">50</property> - </object> - </child> - </object> - </child> - <!-- End Generating account spinner --> <!-- Generated pin view --> <child> <object class="GtkBox" id="generated_pin"> @@ -269,29 +265,6 @@ </object> </child> <!-- End Generated pin view --> - <!-- Export on Jami error --> - <child> - <object class="GtkBox" id="export_on_ring_error"> - <property name="visible">False</property> - <property name="orientation">vertical</property> - <property name="spacing">15</property> - <property name="valign">center</property> - <child> - <object class="GtkLabel" id="label_export_on_ring_error"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="use_markup">True</property> - </object> - </child> - <child> - <object class="GtkButton" id="button_export_on_ring_error_ok"> - <property name="visible">True</property> - <property name="label" translatable="yes">OK</property> - </object> - </child> - </object> - </child> - <!-- End export on Jami error --> <child> <!-- General settings --> <object class="GtkBox" id="general_settings_box">