[empathy/gnome-2-34] only try reconnecting accounts if needed (#642358)
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy/gnome-2-34] only try reconnecting accounts if needed (#642358)
- Date: Wed, 16 Feb 2011 10:28:46 +0000 (UTC)
commit a98b91f97661f7a94ef44f957f1edbfebf680fc2
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Tue Feb 15 11:20:59 2011 +0100
only try reconnecting accounts if needed (#642358)
libempathy-gtk/empathy-account-widget.c | 17 ++++++++++++++---
libempathy/empathy-account-settings.c | 16 +++++++++++++++-
libempathy/empathy-account-settings.h | 1 +
src/empathy-account-assistant.c | 2 +-
4 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c
index 7d71f3a..63bf927 100644
--- a/libempathy-gtk/empathy-account-widget.c
+++ b/libempathy-gtk/empathy-account-widget.c
@@ -766,8 +766,10 @@ account_widget_applied_cb (GObject *source_object,
EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source_object);
EmpathyAccountWidget *widget = EMPATHY_ACCOUNT_WIDGET (user_data);
EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
+ gboolean reconnect_required;
- empathy_account_settings_apply_finish (settings, res, &error);
+ empathy_account_settings_apply_finish (settings, res, &reconnect_required,
+ &error);
if (error != NULL)
{
@@ -804,10 +806,19 @@ account_widget_applied_cb (GObject *source_object,
GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
#endif /* HAVE_MEEGO */
- if (tp_account_is_enabled (account) && enabled_checked)
+ /* If the account was offline, we always want to try reconnecting,
+ * to give it a chance to connect if the previous params were wrong.
+ * tp_account_reconnect_async() won't do anything if the requested
+ * presence is offline anyway. */
+ if (tp_account_get_connection_status (account, NULL) ==
+ TP_CONNECTION_STATUS_DISCONNECTED)
+ reconnect_required = TRUE;
+
+ if (reconnect_required && tp_account_is_enabled (account)
+ && enabled_checked)
{
/* After having applied changes to a user account, we
- * automatically reconnect it. This is done so the new
+ * reconnect it if needed. This is done so the new
* information entered by the user is validated on the server. */
tp_account_reconnect_async (account, NULL, NULL);
}
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 2ee1a39..12bde7b 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -1363,9 +1363,10 @@ empathy_account_settings_account_updated (GObject *source,
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
GSimpleAsyncResult *r;
GError *error = NULL;
+ GStrv reconnect_required;
if (!tp_account_update_parameters_finish (TP_ACCOUNT (source),
- result, NULL, &error))
+ result, &reconnect_required, &error))
{
g_simple_async_result_set_from_error (priv->apply_result, error);
g_error_free (error);
@@ -1390,6 +1391,9 @@ empathy_account_settings_account_updated (GObject *source,
return;
}
+ g_simple_async_result_set_op_res_gboolean (priv->apply_result,
+ g_strv_length (reconnect_required) > 0);
+
out:
empathy_account_settings_discard_changes (settings);
@@ -1398,6 +1402,7 @@ out:
g_simple_async_result_complete (r);
g_object_unref (r);
+ g_strfreev (reconnect_required);
}
static void
@@ -1526,6 +1531,10 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
priv->apply_result = g_simple_async_result_new (G_OBJECT (settings),
callback, user_data, empathy_account_settings_apply_finish);
+ /* We'll have to reconnect only if we change none DBus_Property on an
+ * existing account. */
+ g_simple_async_result_set_op_res_gboolean (priv->apply_result, FALSE);
+
if (priv->account == NULL)
{
tp_account_manager_prepare_async (priv->account_manager, NULL,
@@ -1542,6 +1551,7 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
gboolean
empathy_account_settings_apply_finish (EmpathyAccountSettings *settings,
GAsyncResult *result,
+ gboolean *reconnect_required,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
@@ -1551,6 +1561,10 @@ empathy_account_settings_apply_finish (EmpathyAccountSettings *settings,
g_return_val_if_fail (g_simple_async_result_is_valid (result,
G_OBJECT (settings), empathy_account_settings_apply_finish), FALSE);
+ if (reconnect_required != NULL)
+ *reconnect_required = g_simple_async_result_get_op_res_gboolean (
+ G_SIMPLE_ASYNC_RESULT (result));
+
return TRUE;
}
diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h
index d92a595..3a2264e 100644
--- a/libempathy/empathy-account-settings.h
+++ b/libempathy/empathy-account-settings.h
@@ -170,6 +170,7 @@ void empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
gboolean empathy_account_settings_apply_finish (
EmpathyAccountSettings *settings,
GAsyncResult *result,
+ gboolean *reconnect_required,
GError **error);
gboolean empathy_account_settings_is_valid (EmpathyAccountSettings *settings);
diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c
index a8245c6..dee2d31 100644
--- a/src/empathy-account-assistant.c
+++ b/src/empathy-account-assistant.c
@@ -319,7 +319,7 @@ account_assistant_apply_account_cb (GObject *source,
EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
TpAccount *account;
- empathy_account_settings_apply_finish (settings, result, &error);
+ empathy_account_settings_apply_finish (settings, result, NULL, &error);
priv->is_creating = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]