[empathy: 1/2] - Added a utility function (empathy_account_reconnect_async) to easily
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [empathy: 1/2] - Added a utility function (empathy_account_reconnect_async) to easily
- Date: Thu, 27 Aug 2009 13:41:52 +0000 (UTC)
commit 8dba3957946252b622ba9c09e209f007d5961199
Author: Jonathan Tellier <jonathan tellier gmail com>
Date: Tue Aug 25 15:57:41 2009 -0400
- Added a utility function (empathy_account_reconnect_async) to easily
reconnect an account.
- When we apply changes to an account, instead of disconnecting and
reconnecting it, we use the new empathy_account_reconnect_async
function.
libempathy-gtk/empathy-account-widget.c | 63 +++++++++++++------------------
libempathy/empathy-account.c | 43 +++++++++++++++++++++
libempathy/empathy-account.h | 7 +++
3 files changed, 76 insertions(+), 37 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c
index 0927d10..5863d49 100644
--- a/libempathy-gtk/empathy-account-widget.c
+++ b/libempathy-gtk/empathy-account-widget.c
@@ -66,13 +66,6 @@ typedef struct {
* modify it. When we are creating an account, this member is set to TRUE */
gboolean creating_account;
- /* After having applied changes to a user account, we automatically
- * disconnect him. Once he's disconnected, he will be reconnected,
- * depending on the value of this member which should be set to the checked
- * state of the "Enabled" checkbox. This is done so the new information
- * entered by the user is validated on the server. */
- gboolean re_enable_accound;
-
gboolean dispose_run;
} EmpathyAccountWidgetPriv;
@@ -623,32 +616,35 @@ account_widget_applied_cb (GObject *source_object,
account = empathy_account_settings_get_account (priv->settings);
- if (priv->creating_account)
- {
- /* By default, when an account is created, we enable it. */
- empathy_account_set_enabled_async (account, TRUE,
- account_widget_account_enabled_cb, widget);
- }
- else if (account != NULL && priv->enabled_checkbox != NULL)
+ if (account != NULL)
{
- gboolean enabled_checked;
-
- enabled_checked = gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
-
- if (empathy_account_is_enabled (account))
+ if (priv->creating_account)
{
- /* We want to disable the account (and possibly re-enable it) to make
- * sure that the new settings are effective */
- priv->re_enable_accound = enabled_checked;
- empathy_account_set_enabled_async (account, FALSE, NULL, NULL);
+ /* By default, when an account is created, we enable it. */
+ empathy_account_set_enabled_async (account, TRUE,
+ account_widget_account_enabled_cb, widget);
}
- else
+ else if (priv->enabled_checkbox != NULL)
{
- /* The account is already disable so we just enable it according
- * to the value of the "Enabled" checkbox */
- empathy_account_set_enabled_async (account, enabled_checked,
- NULL, NULL);
+ gboolean enabled_checked;
+
+ enabled_checked = gtk_toggle_button_get_active (
+ GTK_TOGGLE_BUTTON (priv->enabled_checkbox));
+
+ if (empathy_account_is_enabled (account) && enabled_checked)
+ {
+ /* After having applied changes to a user account, we
+ * automatically reconnect it. This is done so the new
+ * information entered by the user is validated on the server. */
+ empathy_account_reconnect_async (account, NULL, NULL);
+ }
+ else
+ {
+ /* The account is disabled so we enable it according to the value
+ * of the "Enabled" checkbox */
+ empathy_account_set_enabled_async (account, enabled_checked,
+ NULL, NULL);
+ }
}
}
@@ -1023,14 +1019,7 @@ empathy_account_widget_enabled_cb (EmpathyAccount *account,
EmpathyAccountWidgetPriv *priv = GET_PRIV (widget);
gboolean enabled = empathy_account_is_enabled (account);
- if (!enabled && priv->re_enable_accound)
- {
- /* The account has been disabled because we were applying changes.
- * However, the user wants the account to be enabled so let's re-enable
- * it */
- empathy_account_set_enabled_async (account, TRUE, NULL, NULL);
- }
- else if (priv->enabled_checkbox != NULL)
+ if (priv->enabled_checkbox != NULL)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->enabled_checkbox),
enabled);
diff --git a/libempathy/empathy-account.c b/libempathy/empathy-account.c
index 7733f35..b508f39 100644
--- a/libempathy/empathy-account.c
+++ b/libempathy/empathy-account.c
@@ -978,6 +978,49 @@ empathy_account_set_enabled_async (EmpathyAccount *account,
}
static void
+account_reconnected_cb (TpAccount *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ GSimpleAsyncResult *result = user_data;
+
+ if (error != NULL)
+ g_simple_async_result_set_from_error (result, (GError *) error);
+
+ g_simple_async_result_complete (result);
+ g_object_unref (result);
+}
+
+gboolean
+empathy_account_reconnect_finish (EmpathyAccount *account,
+ GAsyncResult *result,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+ error) ||
+ !g_simple_async_result_is_valid (result, G_OBJECT (account),
+ empathy_account_reconnect_finish))
+ return FALSE;
+
+ return TRUE;
+}
+
+void
+empathy_account_reconnect_async (EmpathyAccount *account,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ EmpathyAccountPriv *priv = GET_PRIV (account);
+
+ GSimpleAsyncResult *result = g_simple_async_result_new (G_OBJECT (account),
+ callback, user_data, empathy_account_reconnect_finish);
+
+ tp_cli_account_call_reconnect (priv->account,
+ -1, account_reconnected_cb, result, NULL, G_OBJECT (account));
+}
+
+static void
empathy_account_requested_presence_cb (TpProxy *proxy,
const GError *error,
gpointer user_data,
diff --git a/libempathy/empathy-account.h b/libempathy/empathy-account.h
index f88ac43..8a22335 100644
--- a/libempathy/empathy-account.h
+++ b/libempathy/empathy-account.h
@@ -72,6 +72,13 @@ void empathy_account_set_enabled_async (EmpathyAccount *account,
gboolean empathy_account_set_enabled_finish (EmpathyAccount *account,
GAsyncResult *result, GError **error);
+void empathy_account_reconnect_async (EmpathyAccount *account,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean empathy_account_reconnect_finish (EmpathyAccount *account,
+ GAsyncResult *result,
+ GError **error);
+
gboolean empathy_account_is_enabled (EmpathyAccount *account);
gboolean empathy_account_is_valid (EmpathyAccount *account);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]