[calls] account-row: Use delayed state changes for GtkSwitch



commit 41479eea09601c63f109ebb0f68773294d8f936e
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date:   Thu May 19 20:06:23 2022 +0200

    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 cc64eec4..7c1db4f5 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 (user_data));
 
-  g_assert (CALLS_IS_ACCOUNT_ROW (self));
+  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 9be9fa6d..156d5ed0 100644
--- a/src/ui/account-row.ui
+++ b/src/ui/account-row.ui
@@ -21,7 +21,7 @@
         <property name="valign">center</property>
         <property name="visible">True</property>
         <property name="active">False</property>
-        <signal name="notify::active" handler="on_online_switched" swapped="yes"/>
+        <signal name="state-set" handler="on_online_switched" swapped="no"/>
       </object>
     </child>
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]