From 41479eea09601c63f109ebb0f68773294d8f936e Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Thu, 19 May 2022 20:06:23 +0200 Subject: [PATCH] account-row: Use delayed state changes for GtkSwitch When trying to go online/offline we're always waiting for confirmation from the stack (even if it's a timeout) so the delayed pattern is a good choice. --- src/calls-account-row.c | 24 +++++++++++++++++++----- src/ui/account-row.ui | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/calls-account-row.c b/src/calls-account-row.c index cc64eec..7c1db4f 100644 --- a/src/calls-account-row.c +++ b/src/calls-account-row.c @@ -74,7 +74,12 @@ on_account_state_changed (CallsAccountRow *self) { CallsAccountState state = calls_account_get_state (self->account); + g_debug ("Account (%s) state changed: %s", + calls_origin_get_name (CALLS_ORIGIN (self->account)), + calls_account_state_to_string (state)); + gtk_switch_set_active (self->online_switch, state == CALLS_ACCOUNT_STATE_ONLINE); + gtk_switch_set_state (self->online_switch, state == CALLS_ACCOUNT_STATE_ONLINE); } static void @@ -88,15 +93,24 @@ on_edit_clicked (CallsAccountRow *self) } -static void -on_online_switched (CallsAccountRow *self) +static gboolean +on_online_switched (GtkSwitch *widget, + gboolean online, + gpointer user_data) { - gboolean online; + CallsAccountRow *self; - g_assert (CALLS_IS_ACCOUNT_ROW (self)); + g_assert (CALLS_IS_ACCOUNT_ROW (user_data)); + + self = CALLS_ACCOUNT_ROW (user_data); + + g_debug ("Trying to go %sline with account %s", + online ? "on" : "off", + calls_origin_get_name (CALLS_ORIGIN (self->account))); - online = gtk_switch_get_active (self->online_switch); calls_account_go_online (self->account, online); + + return TRUE; } diff --git a/src/ui/account-row.ui b/src/ui/account-row.ui index 9be9fa6..156d5ed 100644 --- a/src/ui/account-row.ui +++ b/src/ui/account-row.ui @@ -21,7 +21,7 @@ center True False - +