[calls/wip/ui-manage-accounts: 11/26] credentials: Require a name and adapt to changes




commit 04d57529f7da03c0fdc1b7e80f32ee477653e583
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Wed Jun 30 12:52:18 2021 +0200

    credentials: Require a name and adapt to changes

 plugins/sip/calls-sip-provider.c |  2 +-
 src/calls-credentials.c          |  6 +++++-
 src/calls-credentials.h          | 31 ++++++++++++++++---------------
 tests/test-account.c             |  8 ++++----
 tests/test-manager.c             |  8 ++++----
 tests/test-sip.c                 | 14 ++++++++------
 6 files changed, 38 insertions(+), 31 deletions(-)
---
diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c
index cabdbaa3..6b6af7f7 100644
--- a/plugins/sip/calls-sip-provider.c
+++ b/plugins/sip/calls-sip-provider.c
@@ -107,7 +107,7 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
 
   for (gsize i = 0; groups[i] != NULL; i++) {
     g_autoptr (CallsCredentials) credentials =
-      calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
+      calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP, groups[i]);
 
     gint local_port = 0;
     gboolean direct_connection =
diff --git a/src/calls-credentials.c b/src/calls-credentials.c
index 1c321c04..4de88db4 100644
--- a/src/calls-credentials.c
+++ b/src/calls-credentials.c
@@ -341,10 +341,14 @@ calls_credentials_init (CallsCredentials *self)
 
 
 CallsCredentials *
-calls_credentials_new (CallsCredentialsType credentials_type)
+calls_credentials_new (CallsCredentialsType  credentials_type,
+                       const char           *name)
 {
+  g_return_val_if_fail (name, NULL);
+
   return g_object_new (CALLS_TYPE_CREDENTIALS,
                        "credentials-type", credentials_type,
+                       "name", name,
                        NULL);
 }
 
diff --git a/src/calls-credentials.h b/src/calls-credentials.h
index 4c9e3d76..d23c2467 100644
--- a/src/calls-credentials.h
+++ b/src/calls-credentials.h
@@ -48,21 +48,22 @@ typedef enum {
 } CallsCredentialsType;
 
 
-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);
-void                    calls_credentials_set_account             (CallsCredentials *self,
-                                                                   CallsAccount     *account);
-CallsAccount           *calls_credentials_get_account             (CallsCredentials *self);
-gboolean                calls_credentials_update_from_credentials (CallsCredentials *self,
-                                                                   CallsCredentials *other);
-gboolean                calls_credentials_is_ready                (CallsCredentials *self);
-const char             *calls_credentials_get_uuid                (CallsCredentials *self);
+CallsCredentials       *calls_credentials_new                     (CallsCredentialsType  credentials_type,
+                                                                   const char           *name);
+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);
+void                    calls_credentials_set_account             (CallsCredentials     *self,
+                                                                   CallsAccount         *account);
+CallsAccount           *calls_credentials_get_account             (CallsCredentials     *self);
+gboolean                calls_credentials_update_from_credentials (CallsCredentials     *self,
+                                                                   CallsCredentials     *other);
+gboolean                calls_credentials_is_ready                (CallsCredentials     *self);
+const char             *calls_credentials_get_uuid                (CallsCredentials     *self);
 
 G_END_DECLS
 
diff --git a/tests/test-account.c b/tests/test-account.c
index 40350ebb..1470f050 100644
--- a/tests/test-account.c
+++ b/tests/test-account.c
@@ -19,8 +19,10 @@
 static void
 test_account_basic (void)
 {
-  CallsCredentials *alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
-  CallsCredentials *bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP);
+  CallsCredentials *alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                                                   "Alice");
+  CallsCredentials *bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                                                 "Bob");
   CallsSipProvider *sip =
     CALLS_SIP_PROVIDER (calls_provider_load_plugin ("sip"));
   CallsAccountProvider *acc_provider;
@@ -32,13 +34,11 @@ test_account_basic (void)
   origins = calls_provider_get_origins (CALLS_PROVIDER (sip));
 
   g_object_set (alice,
-                "name", "Alice",
                 "user", "alice",
                 "host", "example.org",
                 "password", "password123",
                 NULL);
   g_object_set (bob,
-                "name", "Bob",
                 "user", "bob",
                 "host", "example.org",
                 "password", "password123",
diff --git a/tests/test-manager.c b/tests/test-manager.c
index d4f5f573..017013e7 100644
--- a/tests/test-manager.c
+++ b/tests/test-manager.c
@@ -172,9 +172,9 @@ 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 (CALLS_CREDENTIALS_TYPE_SIP);
+  alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                                 "Alice");
   g_object_set (alice,
-                "name", "Alice",
                 "user", "alice",
                 "host", "example.org",
                 "password", "password123",
@@ -191,9 +191,9 @@ 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 (CALLS_CREDENTIALS_TYPE_SIP);
+  bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                               "Bob");
   g_object_set (bob,
-                "name", "Bob",
                 "user", "bob",
                 "host", "example.org",
                 "password", "password123",
diff --git a/tests/test-sip.c b/tests/test-sip.c
index afc21962..589c11d5 100644
--- a/tests/test-sip.c
+++ b/tests/test-sip.c
@@ -362,22 +362,24 @@ setup_sip_origins (SipFixture   *fixture,
                    gconstpointer user_data)
 {
   GListModel *origins;
-  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);
+  CallsCredentials *alice = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                                                   "Alice");
+  CallsCredentials *bob = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                                                 "Bob");
+  CallsCredentials *offline = calls_credentials_new (CALLS_CREDENTIALS_TYPE_SIP,
+                                                     "Offline");
 
   setup_sip_provider (fixture, user_data);
 
-  g_object_set (alice, "name", "Alice", "user", "alice", NULL);
+  g_object_set (alice, "user", "alice", NULL);
 
   calls_sip_provider_add_origin (fixture->provider, alice, 5060, TRUE);
 
-  g_object_set (bob, "name", "Bob", "user", "bob", NULL);
+  g_object_set (bob, "user", "bob", NULL);
 
   calls_sip_provider_add_origin (fixture->provider, bob, 5061, TRUE);
 
   g_object_set (offline,
-                "name", "Offline",
                 "user", "someuser",
                 "host", "sip.imaginary-host.org",
                 "password", "password123",


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