[calls/wip/ui-manage-accounts: 4/26] account-provider: Simplify interface and adapt to changes




commit 1a62c1f4bd5c77f7cfcb80be7219eed16e19ec1c
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date:   Tue Jun 29 10:44:07 2021 +0200

    account-provider: Simplify interface and adapt to changes

 plugins/sip/calls-sip-provider.c | 25 ++-----------------------
 src/calls-account-provider.c     | 26 +-------------------------
 src/calls-account-provider.h     |  6 +-----
 tests/test-account.c             | 28 ++++------------------------
 4 files changed, 8 insertions(+), 77 deletions(-)
---
diff --git a/plugins/sip/calls-sip-provider.c b/plugins/sip/calls-sip-provider.c
index c4ab5a1c..cabdbaa3 100644
--- a/plugins/sip/calls-sip-provider.c
+++ b/plugins/sip/calls-sip-provider.c
@@ -360,7 +360,7 @@ calls_sip_provider_message_source_interface_init (CallsMessageSourceInterface *i
 {
 }
 
-static gboolean
+static CallsAccount*
 add_account (CallsAccountProvider *acc_provider,
              CallsCredentials     *credentials)
 {
@@ -374,7 +374,7 @@ add_account (CallsAccountProvider *acc_provider,
 
   g_object_ref (acc_provider);
 
-  return !!calls_sip_provider_add_origin (self, credentials, 0, FALSE);
+  return CALLS_ACCOUNT (calls_sip_provider_add_origin (self, credentials, 0, FALSE));
 }
 
 static gboolean
@@ -407,32 +407,11 @@ remove_account (CallsAccountProvider *acc_provider,
   return TRUE;
 }
 
-static CallsAccount *
-get_account (CallsAccountProvider *acc_provider,
-             CallsCredentials     *credentials)
-{
-  CallsSipProvider *self;
-  CallsSipOrigin *origin;
-
-  g_assert (CALLS_IS_ACCOUNT_PROVIDER (acc_provider));
-  g_assert (CALLS_IS_SIP_PROVIDER (acc_provider));
-  g_assert (CALLS_IS_CREDENTIALS (credentials));
-
-  self = CALLS_SIP_PROVIDER (acc_provider);
-
-  origin = g_hash_table_lookup (self->credentials, credentials);
-  if (origin)
-    return CALLS_ACCOUNT (origin);
-  else
-    return NULL;
-}
-
 static void
 calls_sip_provider_account_provider_interface_init (CallsAccountProviderInterface *iface)
 {
   iface->add_account = add_account;
   iface->remove_account = remove_account;
-  iface->get_account = get_account;
 }
 
 static void
diff --git a/src/calls-account-provider.c b/src/calls-account-provider.c
index 9d8dac22..856a82ff 100644
--- a/src/calls-account-provider.c
+++ b/src/calls-account-provider.c
@@ -74,7 +74,7 @@ calls_account_provider_add_account (CallsAccountProvider *self,
 
   g_debug ("Trying to add account for %s", calls_credentials_get_name (credentials));
 
-  return iface->add_account (self, credentials);
+  return !!iface->add_account (self, credentials);
 }
 
 /**
@@ -102,30 +102,6 @@ calls_account_provider_remove_account (CallsAccountProvider *self,
   return iface->remove_account (self, credentials);
 }
 
-/**
- * calls_account_provider_get_account:
- * @self: A #CallsAccountProvider
- * @credentials: A #CallsCredentials
- *
- * Get the account which is using #CallsCredentials
- */
-CallsAccount *
-calls_account_provider_get_account (CallsAccountProvider *self,
-                                    CallsCredentials     *credentials)
-{
-  CallsAccountProviderInterface *iface;
-
-  g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (self), NULL);
-
-  iface = CALLS_ACCOUNT_PROVIDER_GET_IFACE (self);
-  g_return_val_if_fail (iface->get_account != NULL, NULL);
-
-  g_debug ("Trying to get account from %s", calls_credentials_get_name (credentials));
-
-  return iface->get_account (self, credentials);
-}
-
-
 /**
  * calls_account_provider_get_credentials_type:
  * @self: A #CallsAccountProvider
diff --git a/src/calls-account-provider.h b/src/calls-account-provider.h
index 89f06ab1..0510779d 100644
--- a/src/calls-account-provider.h
+++ b/src/calls-account-provider.h
@@ -40,20 +40,16 @@ struct _CallsAccountProviderInterface
 {
   GTypeInterface parent_iface;
 
-  gboolean           (*add_account)                           (CallsAccountProvider *self,
+  CallsAccount      *(*add_account)                           (CallsAccountProvider *self,
                                                                CallsCredentials     *credentials);
   gboolean           (*remove_account)                        (CallsAccountProvider *self,
                                                                CallsCredentials     *credentials);
-  CallsAccount      *(*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
diff --git a/tests/test-account.c b/tests/test-account.c
index 0680e381..40350ebb 100644
--- a/tests/test-account.c
+++ b/tests/test-account.c
@@ -25,12 +25,12 @@ test_account_basic (void)
     CALLS_SIP_PROVIDER (calls_provider_load_plugin ("sip"));
   CallsAccountProvider *acc_provider;
   GListModel *origins;
-  CallsOrigin *origin_alice;
-  CallsOrigin *origin_bob;
 
   g_assert_true (CALLS_IS_ACCOUNT_PROVIDER (sip));
   acc_provider = CALLS_ACCOUNT_PROVIDER (sip);
 
+  origins = calls_provider_get_origins (CALLS_PROVIDER (sip));
+
   g_object_set (alice,
                 "name", "Alice",
                 "user", "alice",
@@ -44,33 +44,13 @@ test_account_basic (void)
                 "password", "password123",
                 NULL);
 
+  g_assert_cmpint (g_list_model_get_n_items (origins), ==, 0);
+
   /* Add credentials */
   g_assert_true (calls_account_provider_add_account (acc_provider, alice));
   g_assert_true (calls_account_provider_add_account (acc_provider, bob));
 
-  /* Are the returned accounts of the correct types? */
-  g_assert_true (CALLS_IS_ACCOUNT (calls_account_provider_get_account (acc_provider, alice)));
-  g_assert_true (CALLS_IS_ORIGIN (calls_account_provider_get_account (acc_provider, alice)));
-
-  g_assert_true (CALLS_IS_ACCOUNT (calls_account_provider_get_account (acc_provider, bob)));
-  g_assert_true (CALLS_IS_ORIGIN (calls_account_provider_get_account (acc_provider, bob)));
-
-  /* Are we getting the correct corresponding origins back? */
-  origins = calls_provider_get_origins (CALLS_PROVIDER (sip));
-
   g_assert_cmpint (g_list_model_get_n_items (origins), ==, 2);
-
-  origin_alice = g_list_model_get_item (origins, 0);
-  origin_bob = g_list_model_get_item (origins, 1);
-
-  g_assert_true (origin_alice ==
-                 CALLS_ORIGIN (calls_account_provider_get_account (acc_provider, alice)));
-  g_assert_true (origin_bob ==
-                 CALLS_ORIGIN (calls_account_provider_get_account (acc_provider, bob)));
-
-  g_object_unref (origin_alice);
-  g_object_unref (origin_bob);
-
   /* Try adding credentials a second time */
   g_assert_false (calls_account_provider_add_account (acc_provider, alice));
 


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