]> 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)
1  2 
libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-theme-adium.c

index a8903b476832bd003224255f2eb4c35fba864c1c,ffd12de2b5c4b1da319dea511666c34fdeb3af4a..bdb97be3a5a10bcea1529cdebabdb496a2b8698c
  #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"
@@@ -106,8 -106,6 +106,8 @@@ struct _EmpathyChatPriv 
        guint              update_misspelled_words_id;
        /* Source func ID for save_paned_pos_timeout () */
        guint              save_paned_pos_id;
 +      /* Source func ID for chat_contacts_visible_timeout_cb () */
 +      guint              contacts_visible_id;
  
        GtkWidget         *widget;
        GtkWidget         *hpaned;
@@@ -1014,44 -1012,6 +1014,44 @@@ chat_command_whois (EmpathyChat *chat
                whois_got_contact_cb, NULL, NULL, G_OBJECT (chat));
  }
  
 +static void
 +chat_command_whale (EmpathyChat *chat,
 +                  GStrv        strv)
 +{
 +      EmpathyChatPriv *priv = GET_PRIV (chat);
 +      TpMessage *message;
 +
 +      message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
 +              "\n\n\n"
 +              "•_______________•");
 +      empathy_tp_chat_send (priv->tp_chat, message);
 +      g_object_unref (message);
 +}
 +
 +static void
 +chat_command_babywhale (EmpathyChat *chat,
 +                      GStrv        strv)
 +{
 +      EmpathyChatPriv *priv = GET_PRIV (chat);
 +      TpMessage *message;
 +
 +      message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
 +              "\n"
 +              "•_____•");
 +      empathy_tp_chat_send (priv->tp_chat, message);
 +      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);
@@@ -1106,11 -1066,6 +1106,11 @@@ static ChatCommandItem commands[] = 
        {"help", 1, 2, chat_command_help, NULL,
         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},
  };
  
  static void
@@@ -1119,10 -1074,6 +1119,10 @@@ chat_command_show_help (EmpathyCha
  {
        gchar *str;
  
 +      if (item->help == NULL) {
 +              return;
 +      }
 +
        str = g_strdup_printf (_("Usage: %s"), _(item->help));
        empathy_chat_view_append_event (chat->view, str);
        g_free (str);
@@@ -1143,11 -1094,8 +1143,11 @@@ chat_command_help (EmpathyChat *chat
                                        continue;
                                }
                        }
 -                  empathy_chat_view_append_event (chat->view,
 -                          _(commands[i].help));
 +                      if (commands[i].help == NULL) {
 +                              continue;
 +                      }
 +                      empathy_chat_view_append_event (chat->view,
 +                              _(commands[i].help));
                }
                return;
        }
                                        break;
                                }
                        }
 +                      if (commands[i].help == NULL) {
 +                              break;
 +                      }
                        chat_command_show_help (chat, &commands[i]);
                        return;
                }
@@@ -1451,6 -1396,51 +1451,51 @@@ chat_message_acknowledged_cb (EmpathyTp
        }
  }
  
+ 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,
        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");
        }
@@@ -2650,22 -2639,9 +2694,22 @@@ chat_member_renamed_cb (EmpathyTpChat  
  }
  
  static gboolean
 -chat_reset_size_request (gpointer widget)
 +chat_contacts_visible_timeout_cb (gpointer chat)
  {
 -      gtk_widget_set_size_request (widget, -1, -1);
 +      EmpathyChatPriv *priv = GET_PRIV (chat);
 +
 +      /* Relax the size request */
 +      gtk_widget_set_size_request (priv->vbox_left, -1, -1);
 +
 +      /* Set the position of the slider. This must be done here because
 +       * GtkPaned need to know its size allocation and it will be settled only
 +       * after the gtk_window_resize () tough effect. */
 +      if (priv->contacts_width > 0) {
 +              gtk_paned_set_position (GTK_PANED (priv->hpaned),
 +                                      priv->contacts_width);
 +      }
 +
 +      priv->contacts_visible_id = 0;
  
        return FALSE;
  }
@@@ -2675,6 -2651,7 +2719,6 @@@ chat_update_contacts_visibility (Empath
                         gboolean show)
  {
        EmpathyChatPriv *priv = GET_PRIV (chat);
 -      GtkAllocation allocation;
  
        if (!priv->scrolled_window_contacts) {
                return;
        if (show && priv->contact_list_view == NULL) {
                EmpathyContactListStore *store;
                gint                     min_width;
 +              GtkAllocation            allocation;
  
                /* We are adding the contact list to the chat, we don't want the
                 * chat view to become too small. If the chat view is already
                gtk_widget_get_allocation (priv->vbox_left, &allocation);
                min_width = MIN (allocation.width, 250);
                gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
 -              g_idle_add (chat_reset_size_request, priv->vbox_left);
  
 -              if (priv->contacts_width > 0) {
 -                      gtk_paned_set_position (GTK_PANED (priv->hpaned),
 -                                              priv->contacts_width);
 -              }
 +              /* There is no way to know when the window resize will happen
 +               * since it is WM's decision. Let's hope it won't be longer. */
 +              if (priv->contacts_visible_id != 0)
 +                      g_source_remove (priv->contacts_visible_id);
 +              priv->contacts_visible_id = g_timeout_add (500,
 +                      chat_contacts_visible_timeout_cb, chat);
  
                store = empathy_contact_list_store_new (
                                EMPATHY_CONTACT_LIST (priv->tp_chat));
@@@ -2946,6 -2921,7 +2990,6 @@@ chat_create_ui (EmpathyChat *chat
        GList           *list = NULL;
        gchar           *filename;
        GtkTextBuffer   *buffer;
 -      gint              paned_pos;
        EmpathyThemeManager *theme_mgr;
  
        filename = empathy_file_lookup ("empathy-chat.ui",
                          G_CALLBACK (chat_hpaned_pos_changed_cb),
                          chat);
  
 -        /* Load the paned position */
 -      paned_pos = g_settings_get_int (priv->gsettings_ui,
 -                      EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
 -      if (paned_pos != 0)
 -              gtk_paned_set_position (GTK_PANED(priv->hpaned), paned_pos);
 -
        /* Set widget focus order */
        list = g_list_append (NULL, priv->search_bar);
        list = g_list_append (list, priv->scrolled_window_input);
@@@ -3069,9 -3051,6 +3113,9 @@@ chat_finalize (GObject *object
        if (priv->save_paned_pos_id != 0)
                g_source_remove (priv->save_paned_pos_id);
  
 +      if (priv->contacts_visible_id != 0)
 +              g_source_remove (priv->contacts_visible_id);
 +
        g_object_unref (priv->gsettings_chat);
        g_object_unref (priv->gsettings_ui);
  
@@@ -3240,7 -3219,7 +3284,7 @@@ empathy_chat_class_init (EmpathyChatCla
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
 -                            g_cclosure_marshal_VOID__BOOLEAN,
 +                            g_cclosure_marshal_generic,
                              G_TYPE_NONE,
                              1, G_TYPE_BOOLEAN);
  
                              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);
  
                                  G_SIGNAL_RUN_LAST,
                                  0,
                                  NULL, NULL,
 -                                g_cclosure_marshal_VOID__POINTER,
 +                                g_cclosure_marshal_generic,
                                  G_TYPE_NONE,
                                  1, G_TYPE_STRV);
  
@@@ -3287,7 -3266,7 +3331,7 @@@ account_manager_prepared_cb (GObject *s
        EmpathyChat *chat = user_data;
        GError *error = NULL;
  
 -      if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
 +      if (!tp_proxy_prepare_finish (account_manager, result, &error)) {
                DEBUG ("Failed to prepare the account manager: %s", error->message);
                g_error_free (error);
                return;
@@@ -3316,13 -3295,12 +3360,13 @@@ empathy_chat_init (EmpathyChat *chat
        priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
        priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
  
 -      priv->contacts_width = -1;
 +      priv->contacts_width = g_settings_get_int (priv->gsettings_ui,
 +              EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
        priv->input_history = NULL;
        priv->input_history_current = NULL;
        priv->account_manager = tp_account_manager_dup ();
  
 -      tp_account_manager_prepare_async (priv->account_manager, NULL,
 +      tp_proxy_prepare_async (priv->account_manager, NULL,
                                          account_manager_prepared_cb, chat);
  
        priv->show_contacts = g_settings_get_boolean (priv->gsettings_chat,
index c5d9d209052347c3275986af78c0697ebc233997,a6a697a2976921a36cee535b6148bc653a18552b..9c23d35170804638d4cba5dcadf59ddbe2e637e4
@@@ -541,8 -541,7 +541,8 @@@ theme_adium_append_html (EmpathyThemeAd
                         const gchar       *service_name,
                         const gchar       *message_classes,
                         gint64             timestamp,
 -                       gboolean           is_backlog)
 +                       gboolean           is_backlog,
 +                       gboolean           outgoing)
  {
        EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
        GString     *string;
                         * Incoming/SenderColors.txt it will be used instead of
                         * the default colors.
                         */
 -                      if (contact_id != NULL) {
 +
 +                      /* Ensure we always use the same color when sending messages
 +                       * (bgo #658821) */
 +                      if (outgoing) {
 +                              replace = "inherit";
 +                      } else if (contact_id != NULL) {
                                guint hash = g_str_hash (contact_id);
                                replace = colors[hash % G_N_ELEMENTS (colors)];
                        }
@@@ -693,7 -687,7 +693,7 @@@ theme_adium_append_event_escaped (Empat
        theme_adium_append_html (theme, "appendMessage",
                                 priv->data->status_html, escaped, NULL, NULL, NULL,
                                 NULL, "event",
 -                               empathy_time_get_current (), FALSE);
 +                               empathy_time_get_current (), FALSE, FALSE);
  
        /* There is no last contact */
        if (priv->last_contact) {
@@@ -950,7 -944,7 +950,7 @@@ theme_adium_append_message (EmpathyChat
        theme_adium_append_html (theme, func, html, body_escaped,
                                 avatar_filename, name, contact_id,
                                 service_name, message_classes->str,
 -                               timestamp, is_backlog);
 +                               timestamp, is_backlog, empathy_contact_is_user (sender));
  
        /* Keep the sender of the last displayed message */
        if (priv->last_contact) {
@@@ -981,6 -975,14 +981,14 @@@ theme_adium_append_event (EmpathyChatVi
        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 -1299,7 +1305,7 @@@ theme_adium_iface_init (EmpathyChatView
  {
        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;
@@@ -1654,20 -1657,6 +1663,20 @@@ empathy_theme_adium_set_variant (Empath
        g_object_notify (G_OBJECT (theme), "variant");
  }
  
 +void
 +empathy_theme_adium_show_inspector (EmpathyThemeAdium *theme)
 +{
 +      WebKitWebView      *web_view = WEBKIT_WEB_VIEW (theme);
 +      WebKitWebInspector *inspector;
 +
 +      g_object_set (G_OBJECT (webkit_web_view_get_settings (web_view)),
 +                    "enable-developer-extras", TRUE,
 +                    NULL);
 +
 +      inspector = webkit_web_view_get_inspector (web_view);
 +      webkit_web_inspector_show (inspector);
 +}
 +
  gboolean
  empathy_adium_path_is_valid (const gchar *path)
  {
@@@ -1753,11 -1742,8 +1762,11 @@@ adium_info_dup_path_for_variant (GHashT
                return g_strdup ("main.css");
        }
  
 -      /* Verify the variant exists, fallback to the first one */
        variants = empathy_adium_info_get_available_variants (info);
 +      if (variants->len == 0)
 +              return g_strdup ("main.css");
 +
 +      /* Verify the variant exists, fallback to the first one */
        for (i = 0; i < variants->len; i++) {
                if (!tp_strdiff (variant, g_ptr_array_index (variants, i))) {
                        break;