[calls/wip/ui-manage-accounts: 5/26] credentials: Add account property and use it in CallsAccountProvider
- From: Evangelos Ribeiro Tzaras <devrtz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [calls/wip/ui-manage-accounts: 5/26] credentials: Add account property and use it in CallsAccountProvider
- Date: Fri, 16 Jul 2021 12:16:33 +0000 (UTC)
commit 69edcfa85e09bf62313175f5fa17bd186141eb26
Author: Evangelos Ribeiro Tzaras <evangelos tzaras puri sm>
Date: Tue Jun 29 11:08:48 2021 +0200
credentials: Add account property and use it in CallsAccountProvider
src/calls-account-provider.c | 15 +++++++++++++--
src/calls-credentials.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/calls-credentials.h | 5 +++++
3 files changed, 61 insertions(+), 2 deletions(-)
---
diff --git a/src/calls-account-provider.c b/src/calls-account-provider.c
index 856a82ff..9a0d7972 100644
--- a/src/calls-account-provider.c
+++ b/src/calls-account-provider.c
@@ -66,6 +66,7 @@ calls_account_provider_add_account (CallsAccountProvider *self,
CallsCredentials *credentials)
{
CallsAccountProviderInterface *iface;
+ CallsAccount *account;
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (self), FALSE);
@@ -74,7 +75,13 @@ 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);
+ account = iface->add_account (self, credentials);
+
+ if (account) {
+ calls_credentials_set_account (credentials, account);
+ return TRUE;
+ }
+ return FALSE;
}
/**
@@ -99,7 +106,11 @@ calls_account_provider_remove_account (CallsAccountProvider *self,
g_debug ("Trying to remove account from %s", calls_credentials_get_name (credentials));
- return iface->remove_account (self, credentials);
+ if (iface->remove_account (self, credentials)) {
+ calls_credentials_set_account (credentials, NULL);
+ return TRUE;
+ }
+ return FALSE;
}
/**
diff --git a/src/calls-credentials.c b/src/calls-credentials.c
index 1ccdb612..202ad9ee 100644
--- a/src/calls-credentials.c
+++ b/src/calls-credentials.c
@@ -46,6 +46,7 @@ enum {
PROP_ACC_PROTOCOL,
PROP_ACC_AUTO_CONNECT,
PROP_CREDENTIALS_TYPE,
+ PROP_ACCOUNT,
PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];
@@ -72,6 +73,9 @@ struct _CallsCredentials
CallsCredentialsType credentials_type;
gboolean auto_connect;
+
+ /* The account these credentials are currently used for */
+ CallsAccount *account;
};
@@ -150,6 +154,10 @@ calls_credentials_set_property (GObject *object,
self->credentials_type = g_value_get_enum (value);
break;
+ case PROP_ACCOUNT:
+ calls_credentials_set_account (self, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -202,6 +210,10 @@ calls_credentials_get_property (GObject *object,
g_value_set_enum (value, calls_credentials_get_credentials_type (self));
break;
+ case PROP_ACCOUNT:
+ g_value_set_object (value, calls_credentials_get_account (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -220,6 +232,7 @@ calls_credentials_finalize (GObject *object)
g_free (self->user);
g_free (self->password);
g_free (self->transport_protocol);
+ g_free (self->account);
G_OBJECT_CLASS (calls_credentials_parent_class)->finalize (object);
}
@@ -298,6 +311,13 @@ calls_credentials_class_init (CallsCredentialsClass *klass)
CALLS_CREDENTIALS_TYPE_NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ props[PROP_ACCOUNT] =
+ g_param_spec_object ("account",
+ "Account",
+ "The account these credentials are currently used for",
+ CALLS_TYPE_ACCOUNT,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
signals[SIGNAL_ACCOUNT_UPDATED] =
@@ -448,3 +468,26 @@ calls_credentials_get_credentials_type (CallsCredentials *self)
return self->credentials_type;
}
+
+
+void
+calls_credentials_set_account (CallsCredentials *self,
+ CallsAccount *account)
+{
+ g_return_if_fail (CALLS_IS_CREDENTIALS (self));
+
+ g_clear_object (&self->account);
+ if (account)
+ self->account = g_object_ref (account);
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACCOUNT]);
+}
+
+
+CallsAccount *
+calls_credentials_get_account (CallsCredentials *self)
+{
+ g_return_val_if_fail (CALLS_IS_CREDENTIALS (self), NULL);
+
+ return self->account;
+}
diff --git a/src/calls-credentials.h b/src/calls-credentials.h
index 7dd88305..378016eb 100644
--- a/src/calls-credentials.h
+++ b/src/calls-credentials.h
@@ -24,6 +24,8 @@
#pragma once
+#include "calls-account.h"
+
#include <glib-object.h>
G_BEGIN_DECLS
@@ -54,6 +56,9 @@ void calls_credentials_set_name (CallsCredenti
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);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]