]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-new-message-dialog.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / empathy-new-message-dialog.c
index 3b60b63d5dc1116f7e27da748ad236d57314cf9e..4747dfbb92762c1de26fda9d2192b9a28eb0a34e 100644 (file)
 #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,
@@ -58,43 +63,76 @@ G_DEFINE_TYPE(EmpathyNewMessageDialog, empathy_new_message_dialog,
  */
 
 static void
-empathy_new_message_dialog_got_response (EmpathyContactSelectorDialog *dialog,
-    TpConnection *connection,
-    const gchar *contact_id)
+empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
 {
-  empathy_dispatcher_chat_with_contact_id (connection, contact_id, NULL, NULL);
+  TpAccount *account;
+  const gchar *contact_id;
+
+  if (response_id != GTK_RESPONSE_ACCEPT) goto out;
+
+  contact_id = empathy_contact_selector_dialog_get_selected (
+      EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL, &account);
+
+  if (EMP_STR_EMPTY (contact_id) || account == NULL) goto out;
+
+  empathy_dispatcher_chat_with_contact_id (account, contact_id,
+      gtk_get_current_event_time ());
+
+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;
+
+  if (!tp_proxy_prepare_finish (conn, result, &myerr))
+    {
+      data->callback (FALSE, data->user_data);
+      g_slice_free (FilterCallbackData, data);
+    }
+
+  caps = tp_connection_get_capabilities (TP_CONNECTION (conn));
+  data->callback (tp_capabilities_supports_text_chats (caps),
+      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 *
@@ -151,13 +189,15 @@ empathy_new_message_dialog_class_init (
   EmpathyNewMessageDialogClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
-  EmpathyContactSelectorDialogClass *dialog_class = \
+  GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (class);
+  EmpathyContactSelectorDialogClass *selector_dialog_class = \
     EMPATHY_CONTACT_SELECTOR_DIALOG_CLASS (class);
 
   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;
+  dialog_class->response = empathy_new_message_dialog_response;
+
+  selector_dialog_class->account_filter = empathy_new_message_account_filter;
 }
 
 /**