]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-chat.c
Merge remote-tracking branch 'pochu/error-dialog'
[empathy.git] / libempathy-gtk / empathy-chat.c
index 570d73b691f2ad711d93e5324289af6e0411300c..b1d469f3f2c8d7ae3ccad16077d1598ff16b5c1c 100644 (file)
 #include "empathy-contact-list-store.h"
 #include "empathy-contact-list-view.h"
 #include "empathy-contact-menu.h"
-#include "empathy-gtk-marshal.h"
 #include "empathy-input-text-view.h"
 #include "empathy-search-bar.h"
 #include "empathy-theme-manager.h"
+#include "empathy-theme-adium.h"
 #include "empathy-smiley-manager.h"
 #include "empathy-ui-utils.h"
 #include "empathy-string-parser.h"
@@ -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,
@@ -1042,6 +1044,16 @@ chat_command_babywhale (EmpathyChat *chat,
        g_object_unref (message);
 }
 
+static void
+chat_command_inspector (EmpathyChat *chat,
+                   GStrv        strv)
+{
+       if (EMPATHY_IS_THEME_ADIUM (chat->view)) {
+               empathy_theme_adium_show_inspector (
+                       EMPATHY_THEME_ADIUM (chat->view));
+       }
+}
+
 static void chat_command_help (EmpathyChat *chat, GStrv strv);
 
 typedef void (*ChatCommandFunc) (EmpathyChat *chat, GStrv strv);
@@ -1097,6 +1109,8 @@ static ChatCommandItem commands[] = {
         N_("/help [<command>]: show all supported commands. "
            "If <command> is defined, show its usage.")},
 
+       {"inspector", 1, 1, chat_command_inspector, NULL, NULL},
+
        {"whale", 1, 1, chat_command_whale, NULL, NULL},
        {"babywhale", 1, 1, chat_command_babywhale, NULL, NULL},
 };
@@ -1439,6 +1453,51 @@ chat_message_acknowledged_cb (EmpathyTpChat  *tp_chat,
        }
 }
 
+static void
+append_balance_error (EmpathyChat *chat,
+                     const gchar *message_body)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       TpConnection *conn = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
+       const gchar *uri = tp_connection_get_balance_uri (conn);
+       const gchar *error = _("insufficient balance to send message");
+       gchar *str, *str_markup = NULL;
+
+       if (message_body != NULL) {
+               str = g_strdup_printf (_("Error sending message '%s': %s"), message_body, error);
+       } else {
+               str = g_strdup_printf (_("Error sending message: %s"), error);
+       }
+
+       if (!tp_str_empty (uri)) {
+               /* translators: error used when user doesn't have enough credit on his
+                * account to send the message. */
+               gchar *markup_error = g_strdup_printf (_("insufficient balance to send message."
+                                                        " <a href='%s'>Top up</a>."), uri);
+
+               if (message_body != NULL) {
+                       gchar *escaped_body = g_markup_escape_text (message_body, -1);
+
+                       str_markup = g_strdup_printf (_("Error sending message '%s': %s"),
+                               escaped_body, markup_error);
+
+                       g_free (escaped_body);
+               } else {
+                       str_markup = g_strdup_printf (_("Error sending message: %s"), markup_error);
+               }
+
+               g_free (markup_error);
+       }
+
+       if (str_markup != NULL)
+               empathy_chat_view_append_event_markup (chat->view, str_markup, str);
+       else
+               empathy_chat_view_append_event (chat->view, str);
+
+       g_free (str);
+       g_free (str_markup);
+}
+
 static void
 chat_send_error_cb (EmpathyTpChat          *tp_chat,
                    const gchar            *message_body,
@@ -1450,9 +1509,8 @@ chat_send_error_cb (EmpathyTpChat          *tp_chat,
        gchar       *str;
 
        if (!tp_strdiff (dbus_error, TP_ERROR_STR_INSUFFICIENT_BALANCE)) {
-               /* translators: error used when user doesn't have enough credit on his
-                * account to send the message. */
-               error = _("insufficient balance to send message");
+               append_balance_error (chat, message_body);
+               return;
        } else if (!tp_strdiff (dbus_error, TP_ERROR_STR_NOT_CAPABLE)) {
                error = _("not capable");
        }
@@ -3228,7 +3286,7 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             g_cclosure_marshal_VOID__BOOLEAN,
+                             g_cclosure_marshal_generic,
                              G_TYPE_NONE,
                              1, G_TYPE_BOOLEAN);
 
@@ -3238,7 +3296,7 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             _empathy_gtk_marshal_VOID__OBJECT_BOOLEAN,
+                             g_cclosure_marshal_generic,
                              G_TYPE_NONE,
                              2, EMPATHY_TYPE_MESSAGE, G_TYPE_BOOLEAN);
 
@@ -3248,7 +3306,7 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                                  G_SIGNAL_RUN_LAST,
                                  0,
                                  NULL, NULL,
-                                 g_cclosure_marshal_VOID__POINTER,
+                                 g_cclosure_marshal_generic,
                                  G_TYPE_NONE,
                                  1, G_TYPE_STRV);