]> git.0d.be Git - empathy.git/commitdiff
new-message-dialog: filter out CM which doesn't support 1-1 chat
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 16 Dec 2009 12:04:49 +0000 (12:04 +0000)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 17 Dec 2009 10:38:50 +0000 (10:38 +0000)
libempathy-gtk/empathy-new-message-dialog.c

index ca20b40054e11e919f819ca5065a6048ee07853f..3b60b63d5dc1116f7e27da748ad236d57314cf9e 100644 (file)
@@ -26,6 +26,8 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 
+#include <telepathy-glib/interfaces.h>
+
 #include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-contact-manager.h>
 #include <libempathy/empathy-dispatcher.h>
@@ -63,6 +65,38 @@ empathy_new_message_dialog_got_response (EmpathyContactSelectorDialog *dialog,
   empathy_dispatcher_chat_with_contact_id (connection, contact_id, NULL, NULL);
 }
 
+static gboolean
+empathy_new_message_account_filter (EmpathyContactSelectorDialog *dialog,
+    TpAccount *account)
+{
+  TpConnection *connection;
+  EmpathyDispatcher *dispatcher;
+  GList *classes;
+
+  if (tp_account_get_connection_status (account, NULL) !=
+      TP_CONNECTION_STATUS_CONNECTED)
+    return FALSE;
+
+  /* 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;
+
+  g_list_free (classes);
+  return TRUE;
+}
+
 static GObject *
 empathy_new_message_dialog_constructor (GType type,
     guint n_props,
@@ -123,6 +157,7 @@ empathy_new_message_dialog_class_init (
   object_class->constructor = empathy_new_message_dialog_constructor;
 
   dialog_class->got_response = empathy_new_message_dialog_got_response;
+  dialog_class->account_filter = empathy_new_message_account_filter;
 }
 
 /**