summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-05-24 16:28:03 +0100
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-05-26 10:55:31 +0100
commit0db0042b4183d6bcc3e5b2dc646eb0f769440f65 (patch)
tree85717f742dbbd8604a8f818fd5f74692f6a48e7d
parentdafe457f2620b7daea7435efa6a9066d53058896 (diff)
downloadempathy-0db0042b4183d6bcc3e5b2dc646eb0f769440f65.tar.gz
NewMessageDialog: show an error if starting the channel fails
-rw-r--r--libempathy-gtk/empathy-new-message-dialog.c79
1 files changed, 77 insertions, 2 deletions
diff --git a/libempathy-gtk/empathy-new-message-dialog.c b/libempathy-gtk/empathy-new-message-dialog.c
index 2dc5793b4..9b0101d22 100644
--- a/libempathy-gtk/empathy-new-message-dialog.c
+++ b/libempathy-gtk/empathy-new-message-dialog.c
@@ -68,6 +68,81 @@ 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)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (NULL, 0,
+ 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);
+ g_error_free (error);
+ }
+}
+
static void
empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
{
@@ -86,13 +161,13 @@ empathy_new_message_dialog_response (GtkDialog *dialog, int response_id)
case EMP_NEW_MESSAGE_TEXT:
empathy_dispatcher_chat_with_contact_id (account, contact_id,
gtk_get_current_event_time (),
- NULL, NULL);
+ ensure_text_channel_cb, NULL);
break;
case EMP_NEW_MESSAGE_SMS:
empathy_dispatcher_sms_contact_id (account, contact_id,
gtk_get_current_event_time (),
- NULL, NULL);
+ ensure_text_channel_cb, NULL);
break;
default: