[calls/wip/ui-manage-accounts: 3/26] account-provider: Add credentials-type property and adapt




commit bdaac8baee61b5787f81d8404a05dfc06d23473f
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Tue Jun 29 10:22:33 2021 +0200

    account-provider: Add credentials-type property and adapt
    
    This will make it easier for the account management backend to match
    CallsCredentials to the correct CallsAccountProvider.

 plugins/sip/calls-sip-provider.c |  9 ++++++++-
 src/calls-account-provider.c     | 29 +++++++++++++++++++++++++++++
 src/calls-account-provider.h     | 13 +++++++------
 3 files changed, 44 insertions(+), 7 deletions(-)
---
diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c
index 5520c771..c4ab5a1c 100644
--- a/plugins/sip/calls-sip-provider.c
+++ b/plugins/sip/calls-sip-provider.c
@@ -59,6 +59,7 @@ static const char * const supported_protocols[] = {
 enum {
   PROP_0,
   PROP_SIP_STATE,
+  PROP_PROVIDER_TYPE,
   PROP_LAST_PROP,
 };
 static GParamSpec *props[PROP_LAST_PROP];
@@ -266,6 +267,10 @@ calls_sip_provider_get_property (GObject      *object,
     g_value_set_enum (value, self->sip_state);
     break;
 
+  case PROP_PROVIDER_TYPE:
+    g_value_set_enum (value, CALLS_CREDENTIALS_TYPE_SIP);
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     break;
@@ -343,8 +348,10 @@ calls_sip_provider_class_init (CallsSipProviderClass *klass)
                        SIP_TYPE_ENGINE_STATE,
                        SIP_ENGINE_NULL,
                        G_PARAM_READABLE);
+  g_object_class_install_property (object_class, PROP_SIP_STATE, props[PROP_SIP_STATE]);
 
-  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
+  g_object_class_override_property (object_class, PROP_PROVIDER_TYPE, "credentials-type");
+  props[PROP_PROVIDER_TYPE] = g_object_class_find_property (object_class, "credentials-type");
 }
 
 
diff --git a/src/calls-account-provider.c b/src/calls-account-provider.c
index 606d83cf..9d8dac22 100644
--- a/src/calls-account-provider.c
+++ b/src/calls-account-provider.c
@@ -25,6 +25,7 @@
 #define G_LOG_DOMAIN "CallsAccountProvider"
 
 #include "calls-account-provider.h"
+#include "enum-types.h"
 
 /**
  * SECTION:account-provider
@@ -42,6 +43,13 @@ G_DEFINE_INTERFACE (CallsAccountProvider, calls_account_provider, CALLS_TYPE_PRO
 static void
 calls_account_provider_default_init (CallsAccountProviderInterface *iface)
 {
+  g_object_interface_install_property (iface,
+    g_param_spec_enum ("credentials-type",
+                       "Credentials type",
+                       "The type of credentials for this account provider",
+                       CALLS_TYPE_CREDENTIALS_TYPE,
+                       CALLS_CREDENTIALS_TYPE_NULL,
+                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 }
 
 /**
@@ -116,3 +124,24 @@ calls_account_provider_get_account (CallsAccountProvider *self,
 
   return iface->get_account (self, credentials);
 }
+
+
+/**
+ * calls_account_provider_get_credentials_type:
+ * @self: A #CallsAccountProvider
+ *
+ * Get the #CallsCredentialsType this #CallsAccountProvider can consume
+ *
+ * Returns: The #CallsCredentialsType of @self
+ */
+CallsCredentialsType
+calls_account_provider_get_credentials_type (CallsAccountProvider *self)
+{
+  CallsCredentialsType type;
+
+  g_return_val_if_fail (CALLS_ACCOUNT_PROVIDER (self), CALLS_CREDENTIALS_TYPE_NULL);
+
+  g_object_get (self, "credentials-type", &type, NULL);
+
+  return type;
+}
diff --git a/src/calls-account-provider.h b/src/calls-account-provider.h
index 7bd8bbff..89f06ab1 100644
--- a/src/calls-account-provider.h
+++ b/src/calls-account-provider.h
@@ -48,11 +48,12 @@ struct _CallsAccountProviderInterface
                                                                CallsCredentials     *credentials);
 };
 
-gboolean               calls_account_provider_add_account     (CallsAccountProvider *self,
-                                                               CallsCredentials     *credentials);
-gboolean               calls_account_provider_remove_account  (CallsAccountProvider *self,
-                                                               CallsCredentials     *credentials);
-CallsAccount          *calls_account_provider_get_account     (CallsAccountProvider *self,
-                                                               CallsCredentials     *credentials);
+gboolean             calls_account_provider_add_account          (CallsAccountProvider *self,
+                                                                  CallsCredentials     *credentials);
+gboolean             calls_account_provider_remove_account       (CallsAccountProvider *self,
+                                                                  CallsCredentials     *credentials);
+CallsAccount        *calls_account_provider_get_account          (CallsAccountProvider *self,
+                                                                  CallsCredentials     *credentials);
+CallsCredentialsType calls_account_provider_get_credentials_type (CallsAccountProvider *self);
 
 G_END_DECLS


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