summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-09-26 20:22:00 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2011-09-28 11:32:20 +0100
commitfd8b6fe898130d6de44501e83629f188a3f3391a (patch)
tree7a9650813cec469c35b97a2e34e064c15dd57be7
parent4ae0e4fc7cf2d4ffffec1efe8858b95202995333 (diff)
downloadtelepathy-mission-control-fd8b6fe898130d6de44501e83629f188a3f3391a.tar.gz
Account: add would_like_to_connect method.
This consolidates logic previously duplicated between two code paths.
-rw-r--r--src/mcd-account.c63
-rw-r--r--src/mcd-account.h1
-rw-r--r--src/mcd-master.c8
3 files changed, 45 insertions, 27 deletions
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 818701e9..e6672bea 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -238,27 +238,8 @@ _mcd_account_maybe_autoconnect (McdAccount *account)
g_return_if_fail (MCD_IS_ACCOUNT (account));
priv = account->priv;
- if (!priv->enabled)
- {
- DEBUG ("%s not Enabled", priv->unique_name);
- return;
- }
-
- if (!mcd_account_is_valid (account))
+ if (!mcd_account_would_like_to_connect (account))
{
- DEBUG ("%s not Valid", priv->unique_name);
- return;
- }
-
- if (priv->conn_status != TP_CONNECTION_STATUS_DISCONNECTED)
- {
- DEBUG ("%s already connecting/connected", priv->unique_name);
- return;
- }
-
- if (!priv->connect_automatically)
- {
- DEBUG ("%s does not ConnectAutomatically", priv->unique_name);
return;
}
@@ -3403,6 +3384,48 @@ mcd_account_get_connect_automatically (McdAccount *account)
return priv->connect_automatically;
}
+/*
+ * mcd_account_would_like_to_connect:
+ * @account: an account
+ *
+ * Returns: %TRUE if @account is not currently in the process of trying to
+ * connect, but would like to be, in a perfect world.
+ */
+gboolean
+mcd_account_would_like_to_connect (McdAccount *account)
+{
+ McdAccountPrivate *priv;
+
+ g_return_val_if_fail (MCD_IS_ACCOUNT (account), FALSE);
+ priv = account->priv;
+
+ if (!priv->enabled)
+ {
+ DEBUG ("%s not Enabled", priv->unique_name);
+ return FALSE;
+ }
+
+ if (!mcd_account_is_valid (account))
+ {
+ DEBUG ("%s not Valid", priv->unique_name);
+ return FALSE;
+ }
+
+ if (priv->conn_status != TP_CONNECTION_STATUS_DISCONNECTED)
+ {
+ DEBUG ("%s already connecting/connected", priv->unique_name);
+ return FALSE;
+ }
+
+ if (!priv->connect_automatically)
+ {
+ DEBUG ("%s does not ConnectAutomatically", priv->unique_name);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* TODO: remove when the relative members will become public */
void
mcd_account_get_automatic_presence (McdAccount *account,
diff --git a/src/mcd-account.h b/src/mcd-account.h
index 49b019c4..2480440e 100644
--- a/src/mcd-account.h
+++ b/src/mcd-account.h
@@ -119,6 +119,7 @@ void mcd_account_get_requested_presence (McdAccount *account,
const gchar **message);
gboolean mcd_account_get_connect_automatically (McdAccount *account);
+gboolean mcd_account_would_like_to_connect (McdAccount *account);
void mcd_account_get_automatic_presence (McdAccount *account,
TpConnectionPresenceType *presence,
const gchar **status,
diff --git a/src/mcd-master.c b/src/mcd-master.c
index e6b379a1..5ea3384e 100644
--- a/src/mcd-master.c
+++ b/src/mcd-master.c
@@ -145,13 +145,7 @@ mcd_master_transport_connected (McdMaster *master, McdTransportPlugin *plugin,
McdAccount *account = MCD_ACCOUNT (v);
GHashTable *conditions;
- /* get all enabled accounts, which have the "ConnectAutomatically"
- * flag set and that are not connected */
- if (!mcd_account_is_valid (account) ||
- !mcd_account_is_enabled (account) ||
- !mcd_account_get_connect_automatically (account) ||
- mcd_account_get_connection_status (account) ==
- TP_CONNECTION_STATUS_CONNECTED)
+ if (!mcd_account_would_like_to_connect (account))
continue;
DEBUG ("account %s would like to connect",