[calls] account: Add address property



commit a638b644022e2b72a9c51297b050f06a40db4936
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Sun Jul 4 00:24:30 2021 +0200

    account: Add address property

 plugins/sip/calls-sip-origin.c | 23 ++++++++++++++++++++++-
 src/calls-account.c            | 29 +++++++++++++++++++++++++++++
 src/calls-account.h            |  2 ++
 3 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/plugins/sip/calls-sip-origin.c b/plugins/sip/calls-sip-origin.c
index a105b6f7..83801b7d 100644
--- a/plugins/sip/calls-sip-origin.c
+++ b/plugins/sip/calls-sip-origin.c
@@ -70,6 +70,7 @@ enum {
   PROP_ACC_LOCAL_PORT,
   PROP_SIP_CONTEXT,
   PROP_ACC_STATE,
+  PROP_ACC_ADDRESS,
   PROP_CALLS,
   PROP_COUNTRY_CODE,
   PROP_LAST_PROP,
@@ -873,7 +874,6 @@ go_online (CallsAccount *account,
   CallsSipOrigin *self;
 
   g_assert (CALLS_IS_ACCOUNT (account));
-  g_assert (CALLS_IS_ORIGIN (account));
   g_assert (CALLS_IS_SIP_ORIGIN (account));
 
   self = CALLS_SIP_ORIGIN (account);
@@ -901,6 +901,19 @@ go_online (CallsAccount *account,
   }
 }
 
+static const char *
+get_address (CallsAccount *account)
+{
+  CallsSipOrigin *self;
+
+  g_assert (CALLS_IS_ACCOUNT (account));
+  g_assert (CALLS_IS_SIP_ORIGIN (account));
+
+  self = CALLS_SIP_ORIGIN (account);
+
+  return self->address;
+}
+
 
 static void
 setup_account_for_direct_connection (CallsSipOrigin *self)
@@ -1141,6 +1154,10 @@ calls_sip_origin_get_property (GObject      *object,
     g_value_set_enum (value, self->state);
     break;
 
+  case PROP_ACC_ADDRESS:
+    g_value_set_string (value, get_address (CALLS_ACCOUNT (self)));
+    break;
+
   case PROP_COUNTRY_CODE:
     g_value_set_string (value, NULL);
     break;
@@ -1314,6 +1331,9 @@ calls_sip_origin_class_init (CallsSipOriginClass *klass)
   g_object_class_override_property (object_class, PROP_ACC_STATE, "account-state");
   props[PROP_ACC_STATE] = g_object_class_find_property (object_class, "account-state");
 
+  g_object_class_override_property (object_class, PROP_ACC_ADDRESS, "address");
+  props[PROP_ACC_ADDRESS] = g_object_class_find_property (object_class, "address");
+
 #define IMPLEMENTS(ID, NAME) \
   g_object_class_override_property (object_class, ID, NAME);    \
   props[ID] = g_object_class_find_property(object_class, NAME);
@@ -1343,6 +1363,7 @@ static void
 calls_sip_origin_accounts_interface_init (CallsAccountInterface *iface)
 {
   iface->go_online = go_online;
+  iface->get_address = get_address;
 }
 
 
diff --git a/src/calls-account.c b/src/calls-account.c
index cebf7e3e..3a6365c1 100644
--- a/src/calls-account.c
+++ b/src/calls-account.c
@@ -48,6 +48,15 @@ calls_account_default_init (CallsAccountInterface *iface)
                        G_PARAM_READABLE |
                        G_PARAM_STATIC_STRINGS |
                        G_PARAM_EXPLICIT_NOTIFY));
+
+  g_object_interface_install_property (iface,
+    g_param_spec_string ("address",
+                         "Address",
+                         "The address of this account",
+                         NULL,
+                         G_PARAM_READABLE |
+                         G_PARAM_STATIC_STRINGS |
+                         G_PARAM_EXPLICIT_NOTIFY));
 }
 
 /**
@@ -88,3 +97,23 @@ calls_account_get_state (CallsAccount *self)
 
   return state;
 }
+
+/**
+ * calls_account_get_address:
+ * @self: A #CallsAccount
+ *
+ * Returns: The address under which this account can be reached.
+ * For example: alice example org for SIP and XMPP/Jingle or @alice:example.org for Matrix
+ */
+const char *
+calls_account_get_address (CallsAccount *self)
+{
+  CallsAccountInterface *iface;
+
+  g_return_val_if_fail (CALLS_IS_ACCOUNT (self), NULL);
+
+  iface = CALLS_ACCOUNT_GET_IFACE (self);
+  g_return_val_if_fail (iface->get_address, NULL);
+
+  return iface->get_address (self);
+}
diff --git a/src/calls-account.h b/src/calls-account.h
index b3501150..7dcf815b 100644
--- a/src/calls-account.h
+++ b/src/calls-account.h
@@ -42,6 +42,7 @@ struct _CallsAccountInterface
 
   void               (*go_online)                           (CallsAccount *self,
                                                              gboolean      online);
+  const char        *(*get_address)                         (CallsAccount *self);
 };
 /**
  * CallsAccountState:
@@ -69,6 +70,7 @@ typedef enum {
 
 void                   calls_account_go_online          (CallsAccount *self,
                                                          gboolean      online);
+const char            *calls_account_get_address        (CallsAccount *self);
 CallsAccountState      calls_account_get_state          (CallsAccount *self);
 
 G_END_DECLS


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