]> git.0d.be Git - empathy.git/commitdiff
Merge remote-tracking branch 'pochu/error-dialog'
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Fri, 14 Oct 2011 04:31:16 +0000 (15:31 +1100)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>
Fri, 14 Oct 2011 04:32:13 +0000 (15:32 +1100)
libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-individual-menu.c
libempathy-gtk/empathy-new-message-dialog.c
libempathy/empathy-auth-factory.c
libempathy/empathy-request-util.c
libempathy/empathy-request-util.h
src/empathy-chat-manager.c
src/empathy-chat-window.c

index bdb97be3a5a10bcea1529cdebabdb496a2b8698c..b1d469f3f2c8d7ae3ccad16077d1598ff16b5c1c 100644 (file)
@@ -277,11 +277,13 @@ account_reconnected (EmpathyChat *chat,
                        if (priv->sms_channel)
                                empathy_sms_contact_id (
                                        account, priv->id,
-                                       TP_USER_ACTION_TIME_NOT_USER_ACTION);
+                                       TP_USER_ACTION_TIME_NOT_USER_ACTION,
+                                       NULL, NULL);
                        else
                                empathy_chat_with_contact_id (
                                        account, priv->id,
-                                       TP_USER_ACTION_TIME_NOT_USER_ACTION);
+                                       TP_USER_ACTION_TIME_NOT_USER_ACTION,
+                                       NULL, NULL);
                        break;
                case TP_HANDLE_TYPE_ROOM:
                        empathy_join_muc (account, priv->id,
index 77cbc57d5427eb11550dbe5574cda0c15c9cac77..2209e1538915861cf476bdda6c256f5782b72d6b 100644 (file)
@@ -786,7 +786,8 @@ empathy_individual_sms_menu_item_activated (GtkMenuItem *item,
   empathy_sms_contact_id (
       empathy_contact_get_account (contact),
       empathy_contact_get_id (contact),
-      empathy_get_current_action_time ());
+      empathy_get_current_action_time (),
+      NULL, NULL);
 }
 
 GtkWidget *
index 1c4bbaad50d2aa9d6e2ed795916a0510f79d6e72..027ef872101074d02aa69ff8105db1cb4e835a26 100644 (file)
@@ -63,6 +63,82 @@ enum
   EMP_NEW_MESSAGE_SMS,
 };
 
+static const gchar *
+get_error_display_message (GError *error)
+{
+  if (error->domain != TP_ERROR)
+    goto out;
+
+  switch (error->code)
+    {
+      case TP_ERROR_NETWORK_ERROR:
+        return _("Network error");
+      case TP_ERROR_OFFLINE:
+        return _("The contact is offline");
+      case TP_ERROR_INVALID_HANDLE:
+        return _("The specified contact is either invalid or unknown");
+      case TP_ERROR_NOT_CAPABLE:
+        return _("The contact does not support this kind of conversation");
+      case TP_ERROR_NOT_IMPLEMENTED:
+        return _("The requested functionality is not implemented "
+                 "for this protocol");
+      case TP_ERROR_INVALID_ARGUMENT:
+        /* Not very user friendly to say 'invalid arguments' */
+        break;
+      case TP_ERROR_NOT_AVAILABLE:
+        return _("Could not start a conversation with the given contact");
+      case TP_ERROR_CHANNEL_BANNED:
+        return _("You are banned from this channel");
+      case TP_ERROR_CHANNEL_FULL:
+        return _("This channel is full");
+      case TP_ERROR_CHANNEL_INVITE_ONLY:
+        return _("You must be invited to join this channel");
+      case TP_ERROR_DISCONNECTED:
+        return _("Can't proceed while disconnected");
+      case TP_ERROR_PERMISSION_DENIED:
+        return _("Permission denied");
+      default:
+        DEBUG ("Unhandled error code: %d", error->code);
+    }
+
+out:
+  return _("There was an error starting the conversation");
+}
+
+static void
+show_chat_error (GError *error,
+    GtkWindow *parent)
+{
+  GtkWidget *dialog;
+
+  dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
+      GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+      "%s",
+      get_error_display_message (error));
+
+  g_signal_connect_swapped (dialog, "response",
+      G_CALLBACK (gtk_widget_destroy),
+      dialog);
+
+  gtk_widget_show (dialog);
+}
+
+static void
+ensure_text_channel_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  GError *error = NULL;
+
+  if (!tp_account_channel_request_ensure_channel_finish (
+        TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
+    {
+      DEBUG ("Failed to ensure text channel: %s", error->message);
+      show_chat_error (error, user_data);
+      g_error_free (error);
+    }
+}
+
 static void
 empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
 {
@@ -80,12 +156,16 @@ empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
     {
       case EMP_NEW_MESSAGE_TEXT:
         empathy_chat_with_contact_id (account, contact_id,
-            empathy_get_current_action_time ());
+            empathy_get_current_action_time (),
+            ensure_text_channel_cb,
+            gtk_widget_get_parent_window (GTK_WIDGET (dialog)));
         break;
 
       case EMP_NEW_MESSAGE_SMS:
         empathy_sms_contact_id (account, contact_id,
-            empathy_get_current_action_time ());
+            empathy_get_current_action_time (),
+            ensure_text_channel_cb,
+            gtk_widget_get_parent_window (GTK_WIDGET (dialog)));
         break;
 
       default:
index 4eb5134ddf5b44dee2c24cc4ae18b90d6a04c983..6368b1d7d914852506f49e444d351a7810d6d3c3 100644 (file)
@@ -20,9 +20,7 @@
 
 #include "empathy-auth-factory.h"
 
-#include <telepathy-glib/interfaces.h>
-#include <telepathy-glib/simple-handler.h>
-#include <telepathy-glib/util.h>
+#include <telepathy-glib/telepathy-glib.h>
 
 #define DEBUG_FLAG EMPATHY_DEBUG_TLS
 #include "empathy-debug.h"
index 409fdf54a7447cc5b3ea1a5570a75be0ab9ad2b9..6b53dab9a7583329f5eb789f446d42130c2e61b1 100644 (file)
@@ -40,7 +40,7 @@ empathy_chat_with_contact (EmpathyContact *contact,
 {
   empathy_chat_with_contact_id (
       empathy_contact_get_account (contact), empathy_contact_get_id (contact),
-      timestamp);
+      timestamp, NULL, NULL);
 }
 
 static void
@@ -63,7 +63,9 @@ create_text_channel (TpAccount *account,
     TpHandleType target_handle_type,
     const gchar *target_id,
     gboolean sms_channel,
-    gint64 timestamp)
+    gint64 timestamp,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
 {
   GHashTable *request;
   TpAccountChannelRequest *req;
@@ -83,19 +85,23 @@ create_text_channel (TpAccount *account,
   tp_account_channel_request_set_delegate_to_preferred_handler (req, TRUE);
 
   tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_BUS_NAME,
-      NULL, ensure_text_channel_cb, NULL);
+      NULL, callback ? callback : ensure_text_channel_cb, user_data);
 
   g_hash_table_unref (request);
   g_object_unref (req);
 }
 
+/* @callback is optional, but if it's provided, it should call the right
+ * _finish() func that we call in ensure_text_channel_cb() */
 void
 empathy_chat_with_contact_id (TpAccount *account,
     const gchar *contact_id,
-    gint64 timestamp)
+    gint64 timestamp,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
 {
   create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
-      contact_id, FALSE, timestamp);
+      contact_id, FALSE, timestamp, callback, user_data);
 }
 
 void
@@ -104,14 +110,18 @@ empathy_join_muc (TpAccount *account,
     gint64 timestamp)
 {
   create_text_channel (account, TP_HANDLE_TYPE_ROOM,
-      room_name, FALSE, timestamp);
+      room_name, FALSE, timestamp, NULL, NULL);
 }
 
+/* @callback is optional, but if it's provided, it should call the right
+ * _finish() func that we call in ensure_text_channel_cb() */
 void
 empathy_sms_contact_id (TpAccount *account,
     const gchar *contact_id,
-    gint64 timestamp)
+    gint64 timestamp,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
 {
   create_text_channel (account, TP_HANDLE_TYPE_CONTACT,
-      contact_id, TRUE, timestamp);
+      contact_id, TRUE, timestamp, callback, user_data);
 }
index 70a607e73c41d35614805d7140d19ec221868376..6781b72d40b4ac2351f5a4fa08ce0da0cdefe005 100644 (file)
@@ -45,9 +45,11 @@ G_BEGIN_DECLS
 /* Requesting 1 to 1 text channels */
 void empathy_chat_with_contact_id (TpAccount *account,
   const gchar *contact_id,
-  gint64 timestamp);
+  gint64 timestamp,
+  GAsyncReadyCallback callback,
+  gpointer user_data);
 
-void  empathy_chat_with_contact (EmpathyContact *contact,
+void empathy_chat_with_contact (EmpathyContact *contact,
   gint64 timestamp);
 
 /* Request a muc channel */
@@ -58,7 +60,9 @@ void empathy_join_muc (TpAccount *account,
 /* Request a sms channel */
 void empathy_sms_contact_id (TpAccount *account,
   const gchar *contact_id,
-  gint64 timestamp);
+  gint64 timestamp,
+  GAsyncReadyCallback callback,
+  gpointer user_data);
 
 G_END_DECLS
 
index 7f37cc5c4633f60d60382d5ffeb4db45a4be259a..a52585736d51426183b0d0f64d0ce553ecee5336 100644 (file)
@@ -448,9 +448,11 @@ empathy_chat_manager_undo_closed_chat (EmpathyChatManager *self,
   if (data->room)
     empathy_join_muc (data->account, data->id, timestamp);
   else if (data->sms)
-    empathy_sms_contact_id (data->account, data->id, timestamp);
+    empathy_sms_contact_id (data->account, data->id, timestamp,
+        NULL, NULL);
   else
-    empathy_chat_with_contact_id (data->account, data->id, timestamp);
+    empathy_chat_with_contact_id (data->account, data->id, timestamp,
+        NULL, NULL);
 
   g_signal_emit (self, signals[CLOSED_CHATS_CHANGED], 0,
       g_queue_get_length (priv->closed_queue));
index 44f3dcce39d761ef9177a3ed130168ce83d792d1..46f76466b2d838b9ea945a7e9b98a72572453138 100644 (file)
@@ -1865,7 +1865,9 @@ chat_window_drag_data_received (GtkWidget        *widget,
 
                if (!chat) {
                        empathy_chat_with_contact_id (
-                               account, contact_id, empathy_get_current_action_time ());
+                               account, contact_id,
+                               empathy_get_current_action_time (),
+                               NULL, NULL);
 
                        g_strfreev (strv);
                        return;