aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-new-message-dialog.c
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2010-11-11 01:23:39 +0800
committerVitaly Minko <vitaly.minko@gmail.com>2010-11-11 01:23:39 +0800
commit18d649cbfd8eda7678957a3d2a76b9bb8681a981 (patch)
treec3798b5507f8bf2102d3bd6c94922a21e40c17a8 /libempathy-gtk/empathy-new-message-dialog.c
parentc6cd722328a112e8f4b015ca57ffe8dc72f50cd8 (diff)
downloadgsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.tar
gsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.tar.gz
gsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.tar.bz2
gsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.tar.lz
gsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.tar.xz
gsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.tar.zst
gsoc2013-empathy-18d649cbfd8eda7678957a3d2a76b9bb8681a981.zip
Make AccountChooser filters asynchronous to let them handle newly connected accounts properly (#633481).
Diffstat (limited to 'libempathy-gtk/empathy-new-message-dialog.c')
-rw-r--r--libempathy-gtk/empathy-new-message-dialog.c85
1 files changed, 67 insertions, 18 deletions
diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c
index a17481437..8249b8693 100644
--- a/libempathy-gtk/empathy-new-message-dialog.c
+++ b/libempathy-gtk/empathy-new-message-dialog.c
@@ -42,6 +42,11 @@
#include "empathy-new-message-dialog.h"
#include "empathy-account-chooser.h"
+typedef struct {
+ EmpathyAccountChooserFilterResultCallback callback;
+ gpointer user_data;
+} FilterCallbackData;
+
static EmpathyNewMessageDialog *dialog_singleton = NULL;
G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog,
@@ -77,36 +82,80 @@ out:
gtk_widget_destroy (GTK_WIDGET (dialog));
}
-static gboolean
+static void
+conn_prepared_cb (GObject *conn,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ FilterCallbackData *data = user_data;
+ GError *myerr = NULL;
+ TpCapabilities *caps;
+ GPtrArray *classes;
+ guint i;
+
+ if (!tp_proxy_prepare_finish (conn, result, &myerr))
+ goto out;
+
+ caps = tp_connection_get_capabilities (TP_CONNECTION (conn));
+ classes = tp_capabilities_get_channel_classes (caps);
+
+ for (i = 0; i < classes->len; i++)
+ {
+ GHashTable *fixed;
+ GStrv allowed;
+ const gchar *chan_type;
+
+ tp_value_array_unpack (g_ptr_array_index (classes, i), 2,
+ &fixed, &allowed);
+
+ chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE);
+
+ if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
+ continue;
+
+ if (tp_asv_get_uint32 (fixed, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) !=
+ TP_HANDLE_TYPE_CONTACT)
+ continue;
+
+ data->callback (TRUE, data->user_data);
+ g_slice_free (FilterCallbackData, data);
+ return;
+ }
+
+out:
+ data->callback (FALSE, data->user_data);
+ g_slice_free (FilterCallbackData, data);
+}
+
+static void
empathy_new_message_account_filter (EmpathyContactSelectorDialog *dialog,
+ EmpathyAccountChooserFilterResultCallback callback,
+ gpointer callback_data,
TpAccount *account)
{
TpConnection *connection;
- EmpathyDispatcher *dispatcher;
- GList *classes;
+ FilterCallbackData *cb_data;
+ GQuark features[] = { TP_CONNECTION_FEATURE_CAPABILITIES, 0 };
if (tp_account_get_connection_status (account, NULL) !=
TP_CONNECTION_STATUS_CONNECTED)
- return FALSE;
+ {
+ callback (FALSE, callback_data);
+ return;
+ }
/* check if CM supports 1-1 text chat */
connection = tp_account_get_connection (account);
if (connection == NULL)
- return FALSE;
-
- dispatcher = empathy_dispatcher_dup_singleton ();
-
- classes = empathy_dispatcher_find_requestable_channel_classes
- (dispatcher, connection, TP_IFACE_CHANNEL_TYPE_TEXT,
- TP_HANDLE_TYPE_CONTACT, NULL);
-
- g_object_unref (dispatcher);
-
- if (classes == NULL)
- return FALSE;
+ {
+ callback (FALSE, callback_data);
+ return;
+ }
- g_list_free (classes);
- return TRUE;
+ cb_data = g_slice_new0 (FilterCallbackData);
+ cb_data->callback = callback;
+ cb_data->user_data = callback_data;
+ tp_proxy_prepare_async (connection, features, conn_prepared_cb, cb_data);
}
static GObject *