[calls/wip/ui-manage-accounts: 2/26] credentials: Add credentials-type construct-only property and adapt




commit c96e311d4569a1ecc11816251aa189f643f87ac1
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Tue Jun 29 10:17:47 2021 +0200

    credentials: Add credentials-type construct-only property and adapt
    
    This will help the account management backend to match up CallsCredentials
    to the correct CallsAccountProvider.

 plugins/sip/calls-sip-provider.c |  4 +++-
 src/calls-credentials.c          | 37 +++++++++++++++++++++++++++++++++++--
 src/calls-credentials.h          | 16 +++++++++++++++-
 src/meson.build                  |  1 +
 tests/test-account.c             |  4 ++--
 tests/test-manager.c             |  4 ++--
 tests/test-sip.c                 |  6 +++---
 7 files changed, 61 insertions(+), 11 deletions(-)
---
diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c
index 096c1643..5520c771 100644
--- a/plugins/sip/calls-sip-provider.c
+++ b/plugins/sip/calls-sip-provider.c
@@ -105,7 +105,9 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
   groups = g_key_file_get_groups (key_file, NULL);
 
   for (gsize i = 0; groups[i] != NULL; i++) {
-    g_autoptr (CallsCredentials) credentials = calls_credentials_new ();
+    g_autoptr (CallsCredentials) credentials =
+      calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
+
     gint local_port = 0;
     gboolean direct_connection =
       g_key_file_get_boolean (key_file, groups[i], "Direct", NULL);
diff --git a/src/calls-credentials.c b/src/calls-credentials.c
index 504c6f7a..1ccdb612 100644
--- a/src/calls-credentials.c
+++ b/src/calls-credentials.c
@@ -25,6 +25,7 @@
 #define G_LOG_DOMAIN "CallsCredentials"
 
 #include "calls-credentials.h"
+#include "enum-types.h"
 
 /**
  * SECTION:Credentials
@@ -44,6 +45,7 @@ enum {
   PROP_ACC_PORT,
   PROP_ACC_PROTOCOL,
   PROP_ACC_AUTO_CONNECT,
+  PROP_CREDENTIALS_TYPE,
   PROP_LAST_PROP,
 };
 static GParamSpec *props[PROP_LAST_PROP];
@@ -67,6 +69,7 @@ struct _CallsCredentials
   char *password;
   gint port;
   char *transport_protocol;
+  CallsCredentialsType credentials_type;
 
   gboolean auto_connect;
 };
@@ -143,6 +146,10 @@ calls_credentials_set_property (GObject      *object,
     self->auto_connect = g_value_get_boolean (value);
     break;
 
+  case PROP_CREDENTIALS_TYPE:
+    self->credentials_type = g_value_get_enum (value);
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     break;
@@ -191,6 +198,10 @@ calls_credentials_get_property (GObject    *object,
     g_value_set_boolean (value, self->auto_connect);
     break;
 
+  case PROP_CREDENTIALS_TYPE:
+    g_value_set_enum (value, calls_credentials_get_credentials_type (self));
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     break;
@@ -279,6 +290,14 @@ calls_credentials_class_init (CallsCredentialsClass *klass)
                           TRUE,
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
+  props[PROP_CREDENTIALS_TYPE] =
+    g_param_spec_enum ("credentials-type",
+                       "Credentials type",
+                       "The type of service these credentials are used for",
+                       CALLS_TYPE_CREDENTIALS_TYPE,
+                       CALLS_CREDENTIALS_TYPE_NULL,
+                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
 
   signals[SIGNAL_ACCOUNT_UPDATED] =
@@ -298,9 +317,11 @@ calls_credentials_init (CallsCredentials *self)
 
 
 CallsCredentials *
-calls_credentials_new (void)
+calls_credentials_new (CallsCredentialsType credentials_type)
 {
-  return g_object_new (CALLS_TYPE_CREDENTIALS, NULL);
+  return g_object_new (CALLS_TYPE_CREDENTIALS,
+                       "credentials-type", credentials_type,
+                       NULL);
 }
 
 /**
@@ -324,6 +345,7 @@ calls_credentials_update_from_keyfile (CallsCredentials *self,
   char *protocol = NULL;
   char *display_name = NULL;
   gint port = 0;
+  CallsCredentialsType credentials_type = CALLS_CREDENTIALS_TYPE_NULL;
   gboolean auto_connect = TRUE;
 
   g_return_val_if_fail (CALLS_IS_CREDENTIALS (self), FALSE);
@@ -341,6 +363,7 @@ calls_credentials_update_from_keyfile (CallsCredentials *self,
   protocol = g_key_file_get_string (key_file, name, "Protocol", NULL);
   port = g_key_file_get_integer (key_file, name, "Port", NULL);
   display_name = g_key_file_get_string (key_file, name, "DisplayName", NULL);
+  credentials_type = g_key_file_get_integer (key_file, name, "CredentialsType", NULL);
 
   if (g_key_file_has_key (key_file, name, "AutoConnect", NULL))
     auto_connect = g_key_file_get_boolean (key_file, name, "AutoConnect", NULL);
@@ -382,6 +405,7 @@ calls_credentials_update_from_keyfile (CallsCredentials *self,
 
   self->port = port;
   self->auto_connect = auto_connect;
+  self->credentials_type = credentials_type;
 
   g_debug ("Updated credentials with name %s", name);
 
@@ -415,3 +439,12 @@ calls_credentials_set_name (CallsCredentials *self,
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]);
 }
+
+
+CallsCredentialsType
+calls_credentials_get_credentials_type (CallsCredentials *self)
+{
+  g_return_val_if_fail (CALLS_IS_CREDENTIALS (self), CALLS_CREDENTIALS_TYPE_NULL);
+
+  return self->credentials_type;
+}
diff --git a/src/calls-credentials.h b/src/calls-credentials.h
index d110fa66..7dd88305 100644
--- a/src/calls-credentials.h
+++ b/src/calls-credentials.h
@@ -31,15 +31,29 @@ G_BEGIN_DECLS
 #define CALLS_TYPE_CREDENTIALS (calls_credentials_get_type ())
 
 G_DECLARE_FINAL_TYPE (CallsCredentials, calls_credentials, CALLS, CREDENTIALS, GObject);
+/**
+ * CallsCredentialsType:
+ * @CALLS_CREDENTIALS_TYPE_NULL: Not initialized (this is an error)
+ * @CALLS_CREDENTIALS_TYPE_SIP: Credentials for SIP
+ * @CALLS_CREDENTIALS_TYPE_MATRIX: Credentials for Matrix (not implemented)
+ * @CALLS_CREDENTIALS_TYPE_XMPP: Credentials for XMPP/Jingle (not implemented)
+ */
+typedef enum {
+  CALLS_CREDENTIALS_TYPE_NULL = 0,
+  CALLS_CREDENTIALS_TYPE_SIP,
+  CALLS_CREDENTIALS_TYPE_MATRIX,
+  CALLS_CREDENTIALS_TYPE_XMPP,
+} CallsCredentialsType;
 
 
-CallsCredentials       *calls_credentials_new                     (void);
+CallsCredentials       *calls_credentials_new                     (CallsCredentialsType credentials_type);
 gboolean                calls_credentials_update_from_keyfile     (CallsCredentials *self,
                                                                    GKeyFile         *key_file,
                                                                    const char       *name);
 void                    calls_credentials_set_name                (CallsCredentials *self,
                                                                    const char       *name);
 const char             *calls_credentials_get_name                (CallsCredentials *self);
+CallsCredentialsType    calls_credentials_get_credentials_type    (CallsCredentials *self);
 
 G_END_DECLS
 
diff --git a/src/meson.build b/src/meson.build
index 972f9cc6..39a8141c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -70,6 +70,7 @@ calls_enum_headers = files(['calls-call.h',
                             'calls-ussd.h',
                             'calls-manager.h',
                             'calls-account.h',
+                            'calls-credentials.h',
                             ])
 calls_enum_sources = gnome.mkenums_simple('enum-types',
                                           sources : calls_enum_headers)
diff --git a/tests/test-account.c b/tests/test-account.c
index 4ece23ab..0680e381 100644
--- a/tests/test-account.c
+++ b/tests/test-account.c
@@ -19,8 +19,8 @@
 static void
 test_account_basic (void)
 {
-  CallsCredentials *alice = calls_credentials_new ();
-  CallsCredentials *bob = calls_credentials_new ();
+  CallsCredentials *alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
+  CallsCredentials *bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
   CallsSipProvider *sip =
     CALLS_SIP_PROVIDER (calls_provider_load_plugin ("sip"));
   CallsAccountProvider *acc_provider;
diff --git a/tests/test-manager.c b/tests/test-manager.c
index 4185db1c..d4f5f573 100644
--- a/tests/test-manager.c
+++ b/tests/test-manager.c
@@ -172,7 +172,7 @@ test_calls_manager_multiple_providers_mm_sip (void)
   g_assert_cmpuint (calls_manager_get_state (manager), ==, CALLS_MANAGER_STATE_NO_ORIGIN);
 
   /* Add Alice SIP account */
-  alice = calls_credentials_new ();
+  alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
   g_object_set (alice,
                 "name", "Alice",
                 "user", "alice",
@@ -191,7 +191,7 @@ test_calls_manager_multiple_providers_mm_sip (void)
    * starting with a simple "default" mechanism for now
    * needs https://source.puri.sm/Librem5/calls/-/issues/259 first though
    */
-  bob = calls_credentials_new ();
+  bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
   g_object_set (bob,
                 "name", "Bob",
                 "user", "bob",
diff --git a/tests/test-sip.c b/tests/test-sip.c
index d33b8a5e..afc21962 100644
--- a/tests/test-sip.c
+++ b/tests/test-sip.c
@@ -362,9 +362,9 @@ setup_sip_origins (SipFixture   *fixture,
                    gconstpointer user_data)
 {
   GListModel *origins;
-  CallsCredentials *alice = calls_credentials_new ();
-  CallsCredentials *bob = calls_credentials_new ();
-  CallsCredentials *offline = calls_credentials_new ();
+  CallsCredentials *alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
+  CallsCredentials *bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
+  CallsCredentials *offline = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
 
   setup_sip_provider (fixture, user_data);
 


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