]> git.0d.be Git - empathy.git/commitdiff
Merge branch: 'Add top-up link to chat text when there is insufficient credit'
authorDanielle Madeley <danielle.madeley@collabora.co.uk>
Fri, 14 Oct 2011 04:21:17 +0000 (15:21 +1100)
committerDanielle Madeley <danielle.madeley@collabora.co.uk>
Fri, 14 Oct 2011 04:21:35 +0000 (15:21 +1100)
libempathy-gtk/empathy-chat-view.c
libempathy-gtk/empathy-chat-view.h
libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-theme-adium.c

index 49c384489e6d79ada3bbd169e70e2d3be51e874a..088b1208478139975fcabc2e1b3aa2edd4518b02 100644 (file)
@@ -83,6 +83,22 @@ empathy_chat_view_append_event (EmpathyChatView *view,
        }
 }
 
+void
+empathy_chat_view_append_event_markup (EmpathyChatView *view,
+                                      const gchar     *markup_text,
+                                      const gchar     *fallback_text)
+{
+       g_return_if_fail (EMPATHY_IS_CHAT_VIEW (view));
+
+       if (EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event_markup) {
+               EMPATHY_TYPE_CHAT_VIEW_GET_IFACE (view)->append_event_markup (view,
+                                                                             markup_text,
+                                                                             fallback_text);
+       } else {
+               empathy_chat_view_append_event (view, fallback_text);
+       }
+}
+
 void
 empathy_chat_view_edit_message (EmpathyChatView *view,
                                EmpathyMessage  *message)
index 1fa44450ab30fec559a5fa2f5cdd3a4ae04798ee..bc9e9176105921abb18bfbe722635e3d71ace512 100644 (file)
@@ -46,6 +46,9 @@ struct _EmpathyChatViewIface {
                                                  EmpathyMessage  *msg);
        void             (*append_event)         (EmpathyChatView *view,
                                                  const gchar     *str);
+       void             (*append_event_markup)  (EmpathyChatView *view,
+                                                 const gchar     *markup_text,
+                                                 const gchar     *fallback_text);
        void             (*edit_message)         (EmpathyChatView *view,
                                                  EmpathyMessage  *message);
        void             (*scroll)               (EmpathyChatView *view,
@@ -81,6 +84,9 @@ void             empathy_chat_view_append_message       (EmpathyChatView *view,
                                                         EmpathyMessage  *msg);
 void             empathy_chat_view_append_event         (EmpathyChatView *view,
                                                         const gchar     *str);
+void             empathy_chat_view_append_event_markup  (EmpathyChatView *view,
+                                                        const gchar     *markup_text,
+                                                        const gchar     *fallback_text);
 void             empathy_chat_view_edit_message         (EmpathyChatView *view,
                                                         EmpathyMessage  *message);
 void             empathy_chat_view_scroll               (EmpathyChatView *view,
index a8903b476832bd003224255f2eb4c35fba864c1c..bdb97be3a5a10bcea1529cdebabdb496a2b8698c 100644 (file)
@@ -1451,6 +1451,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,
@@ -1462,9 +1507,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");
        }
index c5d9d209052347c3275986af78c0697ebc233997..9c23d35170804638d4cba5dcadf59ddbe2e637e4 100644 (file)
@@ -981,6 +981,14 @@ theme_adium_append_event (EmpathyChatView *view,
        g_free (str_escaped);
 }
 
+static void
+theme_adium_append_event_markup (EmpathyChatView *view,
+                                const gchar     *markup_text,
+                                const gchar     *fallback_text)
+{
+       theme_adium_append_event_escaped (view, markup_text);
+}
+
 static void
 theme_adium_edit_message (EmpathyChatView *view,
                          EmpathyMessage  *message)
@@ -1297,6 +1305,7 @@ theme_adium_iface_init (EmpathyChatViewIface *iface)
 {
        iface->append_message = theme_adium_append_message;
        iface->append_event = theme_adium_append_event;
+       iface->append_event_markup = theme_adium_append_event_markup;
        iface->edit_message = theme_adium_edit_message;
        iface->scroll = theme_adium_scroll;
        iface->scroll_down = theme_adium_scroll_down;