]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-adium.c
individual_view_drag_end: remove the auto scroll
[empathy.git] / libempathy-gtk / empathy-theme-adium.c
index e5227f506a7e7da23f2193d1fc8f21462a8fb10b..98df46b79a9de43ee019f56544b9a46e0a461e33 100644 (file)
@@ -132,13 +132,15 @@ typedef struct {
        guint type;
        EmpathyMessage *msg;
        char *str;
+       gboolean should_highlight;
 } QueuedItem;
 
 static QueuedItem *
 queue_item (GQueue *queue,
            guint type,
            EmpathyMessage *msg,
-           const char *str)
+           const char *str,
+           gboolean should_highlight)
 {
        QueuedItem *item = g_slice_new0 (QueuedItem);
 
@@ -146,6 +148,7 @@ queue_item (GQueue *queue,
        if (msg != NULL)
                item->msg = g_object_ref (msg);
        item->str = g_strdup (str);
+       item->should_highlight = should_highlight;
 
        g_queue_push_tail (queue, item);
 
@@ -212,39 +215,6 @@ theme_adium_navigation_policy_decision_requested_cb (WebKitWebView             *
        return TRUE;
 }
 
-static void
-theme_adium_copy_address_cb (GtkMenuItem *menuitem,
-                            gpointer     user_data)
-{
-       WebKitHitTestResult   *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
-       gchar                 *uri;
-       GtkClipboard          *clipboard;
-
-       g_object_get (G_OBJECT (hit_test_result), "link-uri", &uri, NULL);
-
-       clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
-       gtk_clipboard_set_text (clipboard, uri, -1);
-
-       clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
-       gtk_clipboard_set_text (clipboard, uri, -1);
-
-       g_free (uri);
-}
-
-static void
-theme_adium_open_address_cb (GtkMenuItem *menuitem,
-                            gpointer     user_data)
-{
-       WebKitHitTestResult   *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
-       gchar                 *uri;
-
-       g_object_get (G_OBJECT (hit_test_result), "link-uri", &uri, NULL);
-
-       empathy_url_show (GTK_WIDGET (menuitem), uri);
-
-       g_free (uri);
-}
-
 /* Replace each %@ in format with string passed in args */
 static gchar *
 string_with_format (const gchar *format,
@@ -574,7 +544,8 @@ theme_adium_append_html (EmpathyThemeAdium *theme,
                         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;
@@ -604,7 +575,12 @@ theme_adium_append_html (EmpathyThemeAdium *theme,
                         * 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)];
                        }
@@ -720,7 +696,7 @@ theme_adium_append_event_escaped (EmpathyChatView *view,
        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) {
@@ -802,14 +778,15 @@ theme_adium_remove_all_focus_marks (EmpathyThemeAdium *theme)
 
 static void
 theme_adium_append_message (EmpathyChatView *view,
-                           EmpathyMessage  *msg)
+                           EmpathyMessage  *msg,
+                           gboolean         should_highlight)
 {
        EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
        EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
        EmpathyContact        *sender;
        TpMessage             *tp_msg;
        TpAccount             *account;
-       gchar                 *body_escaped;
+       gchar                 *body_escaped, *name_escaped;
        const gchar           *name;
        const gchar           *contact_id;
        EmpathyAvatar         *avatar;
@@ -824,7 +801,7 @@ theme_adium_append_message (EmpathyChatView *view,
        gboolean               action;
 
        if (priv->pages_loading != 0) {
-               queue_item (&priv->message_queue, QUEUED_MESSAGE, msg, NULL);
+               queue_item (&priv->message_queue, QUEUED_MESSAGE, msg, NULL, should_highlight);
                return;
        }
 
@@ -843,6 +820,8 @@ theme_adium_append_message (EmpathyChatView *view,
        contact_id = empathy_contact_get_id (sender);
        action = (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
 
+       name_escaped = g_markup_escape_text (name, -1);
+
        /* If this is a /me probably */
        if (action) {
                gchar *str;
@@ -850,7 +829,7 @@ theme_adium_append_message (EmpathyChatView *view,
                if (priv->data->version >= 4 || !priv->data->custom_template) {
                        str = g_strdup_printf ("<span class='actionMessageUserName'>%s</span>"
                                               "<span class='actionMessageBody'>%s</span>",
-                                              name, body_escaped);
+                                              name_escaped, body_escaped);
                } else {
                        str = g_strdup_printf ("*%s*", body_escaped);
                }
@@ -911,7 +890,7 @@ theme_adium_append_message (EmpathyChatView *view,
        } else {
                g_string_append (message_classes, " incoming");
        }
-       if (empathy_message_should_highlight (msg)) {
+       if (should_highlight) {
                g_string_append (message_classes, " mention");
        }
        if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_AUTO_REPLY) {
@@ -975,9 +954,9 @@ theme_adium_append_message (EmpathyChatView *view,
        }
 
        theme_adium_append_html (theme, func, html, body_escaped,
-                                avatar_filename, name, contact_id,
+                                avatar_filename, name_escaped, 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) {
@@ -988,6 +967,7 @@ theme_adium_append_message (EmpathyChatView *view,
        priv->last_is_backlog = is_backlog;
 
        g_free (body_escaped);
+       g_free (name_escaped);
        g_string_free (message_classes, TRUE);
 }
 
@@ -999,7 +979,7 @@ theme_adium_append_event (EmpathyChatView *view,
        gchar *str_escaped;
 
        if (priv->pages_loading != 0) {
-               queue_item (&priv->message_queue, QUEUED_EVENT, NULL, str);
+               queue_item (&priv->message_queue, QUEUED_EVENT, NULL, str, FALSE);
                return;
        }
 
@@ -1008,6 +988,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)
@@ -1021,7 +1009,7 @@ theme_adium_edit_message (EmpathyChatView *view,
        GError *error = NULL;
 
        if (priv->pages_loading != 0) {
-               queue_item (&priv->message_queue, QUEUED_EDIT, message, NULL);
+               queue_item (&priv->message_queue, QUEUED_EDIT, message, NULL, FALSE);
                return;
        }
 
@@ -1296,90 +1284,6 @@ theme_adium_message_acknowledged (EmpathyChatView *view,
        theme_adium_remove_mark_from_message (self, id);
 }
 
-static void
-theme_adium_context_menu_selection_done_cb (GtkMenuShell *menu, gpointer user_data)
-{
-       WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
-
-       g_object_unref (hit_test_result);
-}
-
-static void
-theme_adium_context_menu_for_event (EmpathyThemeAdium *theme, GdkEventButton *event)
-{
-       WebKitWebView              *view = WEBKIT_WEB_VIEW (theme);
-       WebKitHitTestResult        *hit_test_result;
-       WebKitHitTestResultContext  context;
-       GtkWidget                  *menu;
-       GtkWidget                  *item;
-
-       hit_test_result = webkit_web_view_get_hit_test_result (view, event);
-       g_object_get (G_OBJECT (hit_test_result), "context", &context, NULL);
-
-       /* The menu */
-       menu = empathy_context_menu_new (GTK_WIDGET (view));
-
-       /* Select all item */
-       item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
-       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-
-       g_signal_connect_swapped (item, "activate",
-                                 G_CALLBACK (webkit_web_view_select_all),
-                                 view);
-
-       /* Copy menu item */
-       if (webkit_web_view_can_copy_clipboard (view)) {
-               item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
-               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-
-               g_signal_connect_swapped (item, "activate",
-                                         G_CALLBACK (webkit_web_view_copy_clipboard),
-                                         view);
-       }
-
-       /* Clear menu item */
-       item = gtk_separator_menu_item_new ();
-       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-
-       item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
-       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-
-       g_signal_connect_swapped (item, "activate",
-                                 G_CALLBACK (empathy_chat_view_clear),
-                                 view);
-
-       /* We will only add the following menu items if we are
-        * right-clicking a link */
-       if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
-               /* Separator */
-               item = gtk_separator_menu_item_new ();
-               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-
-               /* Copy Link Address menu item */
-               item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Address"));
-               g_signal_connect (item, "activate",
-                                 G_CALLBACK (theme_adium_copy_address_cb),
-                                 hit_test_result);
-               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-
-               /* Open Link menu item */
-               item = gtk_menu_item_new_with_mnemonic (_("_Open Link"));
-               g_signal_connect (item, "activate",
-                                 G_CALLBACK (theme_adium_open_address_cb),
-                                 hit_test_result);
-               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-       }
-
-       g_signal_connect (GTK_MENU_SHELL (menu), "selection-done",
-                         G_CALLBACK (theme_adium_context_menu_selection_done_cb),
-                         hit_test_result);
-
-       /* Display the menu */
-       gtk_widget_show_all (menu);
-       gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
-                       event->button, event->time);
-}
-
 static gboolean
 theme_adium_button_press_event (GtkWidget *widget, GdkEventButton *event)
 {
@@ -1393,7 +1297,9 @@ theme_adium_button_press_event (GtkWidget *widget, GdkEventButton *event)
                 * item ourselves, so we disable our customized menu
                 * if the developer extras are enabled. */
                if (!developer_tools_enabled) {
-                       theme_adium_context_menu_for_event (EMPATHY_THEME_ADIUM (widget), event);
+                       empathy_webkit_context_menu_for_event (
+                               WEBKIT_WEB_VIEW (widget), event,
+                               EMPATHY_WEBKIT_MENU_CLEAR);
                        return TRUE;
                }
        }
@@ -1406,6 +1312,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;
@@ -1442,7 +1349,8 @@ theme_adium_load_finished_cb (WebKitWebView  *view,
                switch (item->type)
                {
                        case QUEUED_MESSAGE:
-                               theme_adium_append_message (chat_view, item->msg);
+                               theme_adium_append_message (chat_view, item->msg,
+                                       item->should_highlight);
                                break;
 
                        case QUEUED_EDIT:
@@ -1763,6 +1671,20 @@ empathy_theme_adium_set_variant (EmpathyThemeAdium *theme,
        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)
 {
@@ -1848,8 +1770,11 @@ adium_info_dup_path_for_variant (GHashTable *info,
                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;
@@ -2024,8 +1949,16 @@ empathy_adium_data_new_with_info (const gchar *path, GHashTable *info)
        /* template -> empathy's template */
        data->custom_template = (template_html != NULL);
        if (template_html == NULL) {
+               GError *error = NULL;
+
                tmp = empathy_file_lookup ("Template.html", "data");
-               g_file_get_contents (tmp, &template_html, NULL, NULL);
+
+               if (!g_file_get_contents (tmp, &template_html, NULL, &error)) {
+                       g_warning ("couldn't load Empathy's default theme "
+                               "template: %s", error->message);
+                       g_return_val_if_reached (data);
+               }
+
                g_free (tmp);
        }