Commit 56530b1c authored by Stepan Salenikovich's avatar Stepan Salenikovich Committed by Alexandre Viau

fix account migration wizard

This fixes a couple of issues and potential crashes:
- the account state changes signal was not being disconnected before
  calling reload on the account which causes a state change and so the
  handler was being called twice
- when migating multiple accounts, the wizard view would not be
  destoryed immediately when calling gtk_container_remove() and so it
  was possible to have 2 views in the GtkStack with the same name

This also removes the weak ptr reference to the migration view. It is
not necessary since the only time the view is destroyed is when we
explicitly do so in the handle_account_migrations() function.

Tuleap: #1121
Change-Id: I448db725193f7c566378298f52f5bad818dbd492
parent 61d05b39
......@@ -95,6 +95,15 @@ static guint account_migration_view_signals[LAST_SIGNAL] = { 0 };
static void
account_migration_view_dispose(GObject *object)
{
auto priv = ACCOUNT_MIGRATION_VIEW_GET_PRIVATE(object);
// make sure to disconnect from all signals when disposing of view
QObject::disconnect(priv->state_changed);
if (priv->timeout_tag) {
g_source_remove(priv->timeout_tag);
priv->timeout_tag = 0;
}
G_OBJECT_CLASS(account_migration_view_parent_class)->dispose(object);
}
......@@ -155,7 +164,9 @@ static gboolean
migration_timeout(AccountMigrationView *view)
{
AccountMigrationViewPrivate *priv = ACCOUNT_MIGRATION_VIEW_GET_PRIVATE(view);
g_warning("timeout reached while migrating account %s", priv->account->id().constData());
QObject::disconnect(priv->state_changed);
priv->timeout_tag = 0;
gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_migration), priv->error_view);
return G_SOURCE_REMOVE;
}
......@@ -163,7 +174,6 @@ migration_timeout(AccountMigrationView *view)
static void
button_error_view_ok_clicked(G_GNUC_UNUSED GtkButton* button, AccountMigrationView *view)
{
AccountMigrationViewPrivate *priv = ACCOUNT_MIGRATION_VIEW_GET_PRIVATE(view);
g_signal_emit(G_OBJECT(view), account_migration_view_signals[ACCOUNT_MIGRATION_FAILED], 0);
}
......@@ -199,12 +209,15 @@ migrate_account_clicked(G_GNUC_UNUSED GtkButton* button, AccountMigrationView *v
case Account::RegistrationState::TRYING:
case Account::RegistrationState::UNREGISTERED:
{
// disconnect before calling reload, since that will cause and account state change
QObject::disconnect(priv->state_changed); // only want to emit once
g_source_remove(priv->timeout_tag); // We didn't timeout
priv->timeout_tag = 0;
// Make sure that the account is ready to be displayed.
priv->account << Account::EditAction::RELOAD;
AccountMigrationViewPrivate *priv = ACCOUNT_MIGRATION_VIEW_GET_PRIVATE(view);
QObject::disconnect(priv->state_changed); // only want to emit once
g_source_remove(priv->timeout_tag); // We didn't timeout
g_signal_emit(G_OBJECT(view), account_migration_view_signals[ACCOUNT_MIGRATION_COMPLETED], 0);
break;
}
......
......@@ -1013,17 +1013,16 @@ handle_account_migrations(RingMainWindow *win)
/* If there is an existing migration view, remove it */
if (priv->account_migration_view)
{
gtk_container_remove(GTK_CONTAINER(priv->stack_main_view), priv->account_migration_view);
gtk_widget_destroy(priv->account_migration_view);
priv->account_migration_view = nullptr;
}
QList<Account*> accounts = AccountModel::instance().accountsToMigrate();
if (!accounts.isEmpty())
{
Account* account = accounts.first();
g_debug("Migrating account: %s", account->id().constData());
priv->account_migration_view = account_migration_view_new(account);
g_object_add_weak_pointer(G_OBJECT(priv->account_migration_view), (gpointer *)&priv->account_migration_view);
g_signal_connect_swapped(priv->account_migration_view, "account-migration-completed", G_CALLBACK(handle_account_migrations), win);
g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed", G_CALLBACK(handle_account_migrations), win);
......
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