[calls/wip/ui-manage-accounts: 10/26] account: Include uuid in account-state-changed signal




commit 0b099a68da78918d07f9b050d07b6144501442e3
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Fri Jun 25 18:00:44 2021 +0200

    account: Include uuid in account-state-changed signal
    
    And use it in CallsSipOrigin

 plugins/sip/calls-sip-origin.c | 59 ++++++++++++++++++++++++------------------
 src/calls-account.c            |  2 +-
 2 files changed, 35 insertions(+), 26 deletions(-)
---
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index 5053996a..c6c8d6e8 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -368,6 +368,23 @@ on_credentials_updated (CallsSipOrigin *self)
     update_nua (self);
 }
 
+static void
+change_state (CallsSipOrigin    *self,
+              CallsAccountState  state)
+{
+  const char *uuid;
+
+  g_assert (CALLS_IS_SIP_ORIGIN (self));
+
+  if (state == self->state)
+    return;
+
+  self->state = state;
+  uuid = calls_credentials_get_uuid (self->credentials);
+
+  g_signal_emit_by_name (self, "account-state-changed", uuid, state);
+}
+
 
 static void
 sip_authenticate (CallsSipOrigin *self,
@@ -456,22 +473,20 @@ sip_r_register (int              status,
 
   if (status == 200) {
     g_debug ("REGISTER successful");
-    origin->state = CALLS_ACCOUNT_ONLINE;
+    change_state (origin, CALLS_ACCOUNT_ONLINE);
 
   } else if (status == 401 || status == 407) {
     sip_authenticate (origin, nh, sip);
-    origin->state = CALLS_ACCOUNT_AUTHENTICATING;
+    change_state (origin, CALLS_ACCOUNT_AUTHENTICATING);
 
   } else if (status == 403) {
     g_warning ("wrong credentials?");
-    origin->state = CALLS_ACCOUNT_AUTHENTICATION_FAILURE;
+    change_state (origin, CALLS_ACCOUNT_AUTHENTICATION_FAILURE);
 
   } else if (status == 904) {
     g_warning ("unmatched challenge");
-    origin->state = CALLS_ACCOUNT_AUTHENTICATION_FAILURE;
+    change_state (origin, CALLS_ACCOUNT_AUTHENTICATION_FAILURE);
   }
-
-  g_object_notify_by_pspec (G_OBJECT (origin), props[PROP_ACC_STATE]);
 }
 
 
@@ -489,14 +504,12 @@ sip_r_unregister (int              status,
 
   if (status == 200) {
     g_debug ("Unregistering successful");
-    origin->state = CALLS_ACCOUNT_OFFLINE;
+    change_state (origin, CALLS_ACCOUNT_OFFLINE);
 
   } else {
     g_warning ("Unregisterung unsuccessful: %03d %s", status, phrase);
-    origin->state = CALLS_ACCOUNT_UNKNOWN_ERROR;
+    change_state (origin, CALLS_ACCOUNT_UNKNOWN_ERROR);
   }
-
-  g_object_notify_by_pspec (G_OBJECT (origin), props[PROP_ACC_STATE]);
 }
 
 
@@ -984,8 +997,8 @@ init_sip_account (CallsSipOrigin *self,
                  "init_sip_account ()"
                  "Try again when account is setup");
 
-    self->state = CALLS_ACCOUNT_NO_CREDENTIALS;
-    goto err;
+    change_state (self, CALLS_ACCOUNT_NO_CREDENTIALS);
+    return FALSE;
   }
 
   // setup_nua() and setup_sip_handles() only after account data has been set
@@ -994,8 +1007,8 @@ init_sip_account (CallsSipOrigin *self,
     g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                  "Failed setting up nua context");
 
-    self->state = CALLS_ACCOUNT_NULL;
-    goto err;
+    change_state (self, CALLS_ACCOUNT_NULL);
+    return FALSE;
   }
 
   self->oper = setup_sip_handles (self);
@@ -1003,15 +1016,16 @@ init_sip_account (CallsSipOrigin *self,
     g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                  "Failed setting operation handles");
 
-    self->state = CALLS_ACCOUNT_NULL;
-    goto err;
+    change_state (self, CALLS_ACCOUNT_NULL);
+    return FALSE;
   }
 
   /* In the case of a direct connection we're immediately good to go */
-  if (self->use_direct_connection)
-    self->state = CALLS_ACCOUNT_ONLINE;
-  else {
-    self->state = CALLS_ACCOUNT_OFFLINE;
+  if (self->use_direct_connection) {
+    change_state (self, CALLS_ACCOUNT_ONLINE);
+
+  } else {
+    change_state (self, CALLS_ACCOUNT_OFFLINE);
 
     g_object_get (self->credentials, "auto-connect", &auto_connect, NULL);
     /* try to go online */
@@ -1019,12 +1033,7 @@ init_sip_account (CallsSipOrigin *self,
       go_online (CALLS_ACCOUNT (self), TRUE);
   }
 
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACC_STATE]);
   return TRUE;
-
- err:
-  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACC_STATE]);
-  return FALSE;
 }
 
 
diff --git a/src/calls-account.c b/src/calls-account.c
index 216413cc..07954edb 100644
--- a/src/calls-account.c
+++ b/src/calls-account.c
@@ -53,7 +53,7 @@ calls_account_default_init (CallsAccountInterface *iface)
                   G_SIGNAL_RUN_LAST,
                   0, NULL, NULL, NULL,
                   G_TYPE_NONE,
-                  2, CALLS_TYPE_ACCOUNT_STATE, CALLS_TYPE_ACCOUNT_STATE);
+                  2, G_TYPE_STRING, CALLS_TYPE_ACCOUNT_STATE);
 
   g_object_interface_install_property (iface,
     g_param_spec_object ("account-credentials",


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