From b7857a6aa8c39cfc51cb322efec513d3528cad11 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 30 Jan 2014 15:13:15 +0000 Subject: [PATCH 3/9] mcd_account_dup_protocol: factor out Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71093 --- src/mcd-account.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/mcd-account.c b/src/mcd-account.c index 8e6cf5e..6af1741 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -3519,6 +3519,39 @@ mcd_account_is_valid (McdAccount *account) return priv->invalid_reason == NULL; } +/* + * mcd_account_dup_protocol: + * @self: the account + * + * Returns: (transfer full): the account's connection manager's protocol, + * possibly %NULL if "not valid" + */ +static TpProtocol * +mcd_account_dup_protocol (McdAccount *self) +{ + TpProtocol *protocol; + + if (!self->priv->manager && !load_manager (self)) + { + DEBUG ("unable to load manager for account %s", + self->priv->unique_name); + return NULL; + } + + protocol = _mcd_manager_dup_protocol (self->priv->manager, + self->priv->protocol_name); + + if (G_UNLIKELY (protocol == NULL)) + { + DEBUG ("unable to get protocol for %s account %s", + self->priv->protocol_name, + self->priv->unique_name); + return NULL; + } + + return protocol; +} + /** * mcd_account_is_enabled: * @account: the #McdAccount. @@ -3559,7 +3592,6 @@ mcd_account_get_object_path (McdAccount *account) GHashTable * _mcd_account_dup_parameters (McdAccount *account) { - McdAccountPrivate *priv; TpProtocol *protocol; GList *protocol_params; GList *iter; @@ -3567,8 +3599,6 @@ _mcd_account_dup_parameters (McdAccount *account) g_return_val_if_fail (MCD_IS_ACCOUNT (account), NULL); - priv = account->priv; - DEBUG ("called"); /* FIXME: this is ridiculous. MC stores the parameters for the account, so @@ -3578,21 +3608,8 @@ _mcd_account_dup_parameters (McdAccount *account) * needs the CM (or .manager file) to be around to tell it whether "true" * is a string or a boolean… */ - if (!priv->manager && !load_manager (account)) - { - DEBUG ("unable to load manager for account %s", priv->unique_name); - return NULL; - } - - protocol = _mcd_manager_dup_protocol (priv->manager, - priv->protocol_name); - if (G_UNLIKELY (protocol == NULL)) - { - DEBUG ("unable to get protocol for %s account %s", priv->protocol_name, - priv->unique_name); - return NULL; - } + protocol = mcd_account_dup_protocol (account); params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, -- 1.9.rc1