#include <telepathy-glib/dbus.h>
#include <telepathy-glib/util.h>
+#include <pango/pango.h>
+#include <gdk/gdk.h>
+#include <libempathy/empathy-gsettings.h>
#include <libempathy/empathy-time.h>
#include <libempathy/empathy-utils.h>
#include "empathy-theme-adium.h"
#include "empathy-smiley-manager.h"
-#include "empathy-conf.h"
#include "empathy-ui-utils.h"
#include "empathy-plist.h"
+#include "empathy-string-parser.h"
+#include "empathy-images.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
#include <libempathy/empathy-debug.h>
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyThemeAdium)
+#define BORING_DPI_DEFAULT 96
+
/* "Join" consecutive messages with timestamps within five minutes */
#define MESSAGE_JOIN_PERIOD 5*60
gboolean last_is_backlog;
gboolean page_loaded;
GList *message_queue;
- gchar *hovered_uri;
- guint notify_enable_webkit_developer_tools_id;
GtkWidget *inspector_window;
+ GSettings *gsettings_chat;
} EmpathyThemeAdiumPriv;
struct _EmpathyAdiumData {
- guint ref_count;
+ gint ref_count;
gchar *path;
gchar *basedir;
gchar *default_avatar_filename;
static void
theme_adium_update_enable_webkit_developer_tools (EmpathyThemeAdium *theme)
{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
WebKitWebView *web_view = WEBKIT_WEB_VIEW (theme);
gboolean enable_webkit_developer_tools;
- if (!empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
- &enable_webkit_developer_tools)) {
- return;
- }
+ enable_webkit_developer_tools = g_settings_get_boolean (
+ priv->gsettings_chat,
+ EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS);
g_object_set (G_OBJECT (webkit_web_view_get_settings (web_view)),
"enable-developer-extras",
}
static void
-theme_adium_notify_enable_webkit_developer_tools_cb (EmpathyConf *conf,
+theme_adium_notify_enable_webkit_developer_tools_cb (GSettings *gsettings,
const gchar *key,
gpointer user_data)
{
return TRUE;
}
-static void
-theme_adium_hovering_over_link_cb (EmpathyThemeAdium *theme,
- gchar *title,
- gchar *uri,
- gpointer user_data)
-{
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
-
- if (tp_strdiff (uri, priv->hovered_uri)) {
- g_free (priv->hovered_uri);
- priv->hovered_uri = g_strdup (uri);
- }
-}
-
static void
theme_adium_copy_address_cb (GtkMenuItem *menuitem,
gpointer user_data)
{
- EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (user_data);
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ 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, priv->hovered_uri, -1);
+ gtk_clipboard_set_text (clipboard, uri, -1);
clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
- gtk_clipboard_set_text (clipboard, priv->hovered_uri, -1);
+ gtk_clipboard_set_text (clipboard, uri, -1);
+
+ g_free (uri);
}
static void
theme_adium_open_address_cb (GtkMenuItem *menuitem,
gpointer user_data)
{
- EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (user_data);
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
-
- empathy_url_show (GTK_WIDGET (menuitem), priv->hovered_uri);
-}
-
-static void
-theme_adium_populate_popup_cb (WebKitWebView *view,
- GtkMenu *menu,
- gpointer user_data)
-{
- EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
- GtkWidget *item;
- GList *items;
- GtkWidget *icon;
- gchar *stock_id;
- gboolean is_link = FALSE;
- gboolean developer_tools_enabled;
-
- /* FIXME: WebKitGTK+'s context menu API clearly needs an
- * overhaul. There is currently no way to know what is being
- * clicked, to decide what features to provide. You either
- * take what it gives you as a menu, or use hacks to figure
- * out what to display. */
- items = gtk_container_get_children (GTK_CONTAINER (menu));
- item = GTK_WIDGET (g_list_nth_data (items, 0));
- g_list_free (items);
-
- if (GTK_IS_IMAGE_MENU_ITEM (item)) {
- icon = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (item));
- gtk_image_get_stock (GTK_IMAGE (icon), &stock_id, NULL);
-
- if ((!strcmp (stock_id, GTK_STOCK_OPEN)) && priv->hovered_uri)
- is_link = TRUE;
- }
-
- /* Remove default menu items */
- g_object_get (G_OBJECT (webkit_web_view_get_settings (view)),
- "enable-developer-extras", &developer_tools_enabled, NULL);
- if (!developer_tools_enabled)
- gtk_container_foreach (GTK_CONTAINER (menu),
- (GtkCallback) gtk_widget_destroy, NULL);
-
- /* 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);
- gtk_widget_show (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);
- gtk_widget_show (item);
-
- g_signal_connect_swapped (item, "activate",
- G_CALLBACK (webkit_web_view_copy_clipboard),
- view);
- }
+ WebKitHitTestResult *hit_test_result = WEBKIT_HIT_TEST_RESULT (user_data);
+ gchar *uri;
- /* Clear menu item */
- item = gtk_separator_menu_item_new ();
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
+ g_object_get (G_OBJECT (hit_test_result), "link-uri", &uri, NULL);
- item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLEAR, NULL);
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
+ empathy_url_show (GTK_WIDGET (menuitem), uri);
- 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 (!is_link)
- return;
-
- /* Separator */
- item = gtk_separator_menu_item_new ();
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (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),
- view);
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (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),
- view);
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
+ g_free (uri);
}
-static gchar *
-theme_adium_parse_body (EmpathyThemeAdium *theme,
- const gchar *text)
+static void
+theme_adium_match_newline (const gchar *text,
+ gssize len,
+ EmpathyStringReplace replace_func,
+ EmpathyStringParser *sub_parsers,
+ gpointer user_data)
{
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
- gboolean use_smileys = FALSE;
- GSList *smileys, *l;
- GString *string;
- gint i;
- GRegex *uri_regex;
- GMatchInfo *match_info;
- gboolean match;
- gchar *ret = NULL;
- gint prev;
-
- empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
- &use_smileys);
-
- /* Add <a href></a> arround links */
- uri_regex = empathy_uri_regex_dup_singleton ();
- match = g_regex_match (uri_regex, text, 0, &match_info);
- if (match) {
- gint last = 0;
- gint s = 0, e = 0;
-
- string = g_string_sized_new (strlen (text));
- do {
- gchar *real_url;
-
- g_match_info_fetch_pos (match_info, 0, &s, &e);
-
- if (s > last) {
- /* Append the text between last link (or the
- * start of the message) and this link */
- g_string_append_len (string, text + last, s - last);
- }
-
- /* Append the link inside <a href=""></a> tag */
- real_url = empathy_make_absolute_url (text + s);
-
- g_string_append (string, "<a href=\"");
- g_string_append (string, real_url);
- g_string_append (string, "\">");
- g_string_append_len (string, text + s, e - s);
- g_string_append (string, "</a>");
-
- g_free (real_url);
- last = e;
- } while (g_match_info_next (match_info, NULL));
-
- if (e < strlen (text)) {
- /* Append the text after the last link */
- g_string_append_len (string, text + e, strlen (text) - e);
- }
+ GString *string = user_data;
+ gint i;
+ gint prev = 0;
- g_free (ret);
- text = ret = g_string_free (string, FALSE);
- } else if (use_smileys) {
- /* Replace smileys by a <img/> tag */
- string = g_string_sized_new (strlen (text));
- smileys = empathy_smiley_manager_parse (priv->smiley_manager, text);
- for (l = smileys; l; l = l->next) {
- EmpathySmiley *smiley;
-
- smiley = l->data;
- if (smiley->path) {
- g_string_append_printf (string,
- "<abbr title='%s'><img src=\"%s\"/ alt=\"%s\"/></abbr>",
- smiley->str, smiley->path, smiley->str);
- } else {
- gchar *str;
-
- str = g_markup_escape_text (smiley->str, -1);
- g_string_append (string, str);
- g_free (str);
- }
- empathy_smiley_free (smiley);
- }
- g_slist_free (smileys);
-
- g_free (ret);
- text = ret = g_string_free (string, FALSE);
+ if (len < 0) {
+ len = G_MAXSSIZE;
}
- g_match_info_free (match_info);
- g_regex_unref (uri_regex);
-
/* Replace \n by <br/> */
- string = NULL;
- prev = 0;
- for (i = 0; text[i] != '\0'; i++) {
+ for (i = 0; i < len && text[i] != '\0'; i++) {
if (text[i] == '\n') {
- if (!string ) {
- string = g_string_sized_new (strlen (text));
- }
- g_string_append_len (string, text + prev, i - prev);
+ empathy_string_parser_substr (text + prev,
+ i - prev, sub_parsers,
+ user_data);
g_string_append (string, "<br/>");
prev = i + 1;
}
}
- if (string) {
- g_string_append (string, text + prev);
- g_free (ret);
- text = ret = g_string_free (string, FALSE);
- }
+ empathy_string_parser_substr (text + prev, i - prev,
+ sub_parsers, user_data);
+}
- return ret;
+static void
+theme_adium_replace_smiley (const gchar *text,
+ gssize len,
+ gpointer match_data,
+ gpointer user_data)
+{
+ EmpathySmileyHit *hit = match_data;
+ GString *string = user_data;
+
+ /* Replace smiley by a <img/> tag */
+ g_string_append_printf (string,
+ "<img src=\"%s\" alt=\"%.*s\" title=\"%.*s\"/>",
+ hit->path, (int)len, text, (int)len, text);
+}
+
+static EmpathyStringParser string_parsers[] = {
+ {empathy_string_match_link, empathy_string_replace_link},
+ {theme_adium_match_newline, NULL},
+ {empathy_string_match_all, empathy_string_replace_escaped},
+ {NULL, NULL}
+};
+
+static EmpathyStringParser string_parsers_with_smiley[] = {
+ {empathy_string_match_link, empathy_string_replace_link},
+ {empathy_string_match_smiley, theme_adium_replace_smiley},
+ {theme_adium_match_newline, NULL},
+ {empathy_string_match_all, empathy_string_replace_escaped},
+ {NULL, NULL}
+};
+
+static gchar *
+theme_adium_parse_body (EmpathyThemeAdium *self,
+ const gchar *text)
+{
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (self);
+ EmpathyStringParser *parsers;
+ GString *string;
+
+ /* Check if we have to parse smileys */
+ if (g_settings_get_boolean (priv->gsettings_chat,
+ EMPATHY_PREFS_CHAT_SHOW_SMILEYS))
+ parsers = string_parsers_with_smiley;
+ else
+ parsers = string_parsers;
+
+ /* Parse text and construct string with links and smileys replaced
+ * by html tags. Also escape text to make sure html code is
+ * displayed verbatim. */
+ string = g_string_sized_new (strlen (text));
+ empathy_string_parser_substr (text, -1, parsers, string);
+
+ /* Wrap body in order to make tabs and multiple spaces displayed
+ * properly. See bug #625745. */
+ g_string_prepend (string, "<div style=\"display: inline; "
+ "white-space: pre-wrap\"'>");
+ g_string_append (string, "</div>");
+
+ return g_string_free (string, FALSE);
}
static void
const gchar *contact_id,
const gchar *service_name,
const gchar *message_classes,
- time_t timestamp)
+ time_t timestamp,
+ gboolean is_backlog)
{
GString *string;
const gchar *cur = NULL;
cur++;
}
- dup_replace = empathy_time_to_string_local (timestamp,
- format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
+ if (is_backlog) {
+ dup_replace = empathy_time_to_string_local (timestamp,
+ format ? format : EMPATHY_TIME_DATE_FORMAT_DISPLAY_SHORT);
+ } else {
+ dup_replace = empathy_time_to_string_local (timestamp,
+ format ? format : EMPATHY_TIME_FORMAT_DISPLAY_SHORT);
+ }
replace = dup_replace;
g_free (format);
} else {
g_free (script);
}
+static void
+theme_adium_append_event_escaped (EmpathyChatView *view,
+ const gchar *escaped)
+{
+ EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
+ EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+
+ if (priv->data->status_html) {
+ theme_adium_append_html (theme, "appendMessage",
+ priv->data->status_html,
+ priv->data->status_len,
+ escaped, NULL, NULL, NULL, NULL,
+ "event", empathy_time_get_current (), FALSE);
+ }
+
+ /* There is no last contact */
+ if (priv->last_contact) {
+ g_object_unref (priv->last_contact);
+ priv->last_contact = NULL;
+ }
+}
+
static void
theme_adium_append_message (EmpathyChatView *view,
EmpathyMessage *msg)
EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
EmpathyContact *sender;
- EmpathyAccount *account;
- gchar *dup_body = NULL;
+ TpAccount *account;
+ gchar *body_escaped;
const gchar *body;
const gchar *name;
const gchar *contact_id;
const gchar *func;
const gchar *service_name;
GString *message_classes = NULL;
- gboolean is_backlog;
+ gboolean is_backlog;
+ gboolean consecutive;
if (!priv->page_loaded) {
priv->message_queue = g_list_prepend (priv->message_queue,
sender = empathy_message_get_sender (msg);
account = empathy_contact_get_account (sender);
service_name = empathy_protocol_name_to_display_name
- (empathy_account_get_protocol (account));
+ (tp_account_get_protocol (account));
+ if (service_name == NULL)
+ service_name = tp_account_get_protocol (account);
timestamp = empathy_message_get_timestamp (msg);
body = empathy_message_get_body (msg);
- dup_body = theme_adium_parse_body (theme, body);
- if (dup_body) {
- body = dup_body;
- }
- name = empathy_contact_get_name (sender);
+ body_escaped = theme_adium_parse_body (theme, body);
+ name = empathy_contact_get_alias (sender);
contact_id = empathy_contact_get_id (sender);
/* If this is a /me, append an event */
if (empathy_message_get_tptype (msg) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) {
gchar *str;
- str = g_strdup_printf ("%s %s", name, body);
- empathy_chat_view_append_event (view, str);
+ str = g_strdup_printf ("%s %s", name, body_escaped);
+ theme_adium_append_event_escaped (view, str);
+
g_free (str);
- g_free (dup_body);
+ g_free (body_escaped);
return;
}
if (!avatar_filename) {
if (!priv->data->default_avatar_filename) {
priv->data->default_avatar_filename =
- empathy_filename_from_icon_name ("stock_person",
+ empathy_filename_from_icon_name (EMPATHY_IMAGE_AVATAR_DEFAULT,
GTK_ICON_SIZE_DIALOG);
}
avatar_filename = priv->data->default_avatar_filename;
}
}
+ /* We want to join this message with the last one if
+ * - senders are the same contact,
+ * - last message was recieved recently,
+ * - last message and this message both are/aren't backlog, and
+ * - DisableCombineConsecutive is not set in theme's settings */
is_backlog = empathy_message_is_backlog (msg);
+ consecutive = empathy_contact_equal (priv->last_contact, sender) &&
+ (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) &&
+ (is_backlog == priv->last_is_backlog) &&
+ !tp_asv_get_boolean (priv->data->info,
+ "DisableCombineConsecutive", NULL);
- /* Get the right html/func to add the message */
- func = "appendMessage";
-
+ /* Define message classes */
message_classes = g_string_new ("message");
-
- /* eventually append the "history" class */
if (is_backlog) {
g_string_append (message_classes, " history");
}
-
- /* check the sender of the message and append the appropriate class */
+ if (consecutive) {
+ g_string_append (message_classes, " consecutive");
+ }
if (empathy_contact_is_user (sender)) {
g_string_append (message_classes, " outgoing");
- }
- else {
+ } else {
g_string_append (message_classes, " incoming");
}
- /*
- * To mimick Adium's behavior, we only want to join messages
- * sent by the same contact within a 5 minute time frame.
- */
- if (empathy_contact_equal (priv->last_contact, sender) &&
- (timestamp - priv->last_timestamp < MESSAGE_JOIN_PERIOD) &&
- (is_backlog == priv->last_is_backlog)) {
- /* the messages can be appended */
+ /* Define javascript function to use */
+ if (consecutive) {
func = "appendNextMessage";
- g_string_append (message_classes, " consecutive");
+ } else {
+ func = "appendMessage";
+ }
- /* check who is the sender of the message to use the correct html file */
- if (empathy_contact_is_user (sender)) {
- /* check if this is a backlog message and use NextContext.html */
+ /* Outgoing */
+ if (empathy_contact_is_user (sender)) {
+ if (consecutive) {
if (is_backlog) {
html = priv->data->out_nextcontext_html;
len = priv->data->out_nextcontext_len;
}
- /*
- * html is null if this is not a backlog message or
- * if we have to fallback (NextContext.html missing).
- * use NextContent.html
- */
+ /* Not backlog, or fallback if NextContext.html
+ * is missing */
if (html == NULL) {
html = priv->data->out_nextcontent_html;
len = priv->data->out_nextcontent_len;
}
}
- else {
+
+ /* Not consecutive, or fallback if NextContext.html and/or
+ * NextContent.html are missing */
+ if (html == NULL) {
if (is_backlog) {
- html = priv->data->in_nextcontext_html;
- len = priv->data->in_nextcontext_len;
+ html = priv->data->out_context_html;
+ len = priv->data->out_context_len;
}
if (html == NULL) {
- html = priv->data->in_nextcontent_html;
- len = priv->data->in_nextcontent_len;
+ html = priv->data->out_content_html;
+ len = priv->data->out_content_len;
}
}
}
- /*
- * we have html == NULL here if:
- * 1. the message didn't have to be appended because
- * the sender was different or the timestamp was too far
- * 2. NextContent.html file does not exist, so we must
- * not forget to fallback to the correct Content.html
- */
+ /* Incoming, or fallback if outgoing files are missing */
if (html == NULL) {
- if (empathy_contact_is_user (sender)) {
+ if (consecutive) {
if (is_backlog) {
- html = priv->data->out_context_html;
- len = priv->data->out_context_len;
+ html = priv->data->in_nextcontext_html;
+ len = priv->data->in_nextcontext_len;
}
+ /* Note backlog, or fallback if NextContext.html
+ * is missing */
if (html == NULL) {
- html = priv->data->out_content_html;
- len = priv->data->out_content_len;
+ html = priv->data->in_nextcontent_html;
+ len = priv->data->in_nextcontent_len;
}
}
- else {
+
+ /* Not consecutive, or fallback if NextContext.html and/or
+ * NextContent.html are missing */
+ if (html == NULL) {
if (is_backlog) {
html = priv->data->in_context_html;
len = priv->data->in_context_len;
}
}
- theme_adium_append_html (theme, func, html, len, body, avatar_filename,
- name, contact_id, service_name, message_classes->str,
- timestamp);
+ if (html != NULL) {
+ theme_adium_append_html (theme, func, html, len, body_escaped,
+ avatar_filename, name, contact_id,
+ service_name, message_classes->str,
+ timestamp, is_backlog);
+ } else {
+ DEBUG ("Couldn't find HTML file for this message");
+ }
/* Keep the sender of the last displayed message */
if (priv->last_contact) {
priv->last_timestamp = timestamp;
priv->last_is_backlog = is_backlog;
- g_free (dup_body);
+ g_free (body_escaped);
g_string_free (message_classes, TRUE);
}
theme_adium_append_event (EmpathyChatView *view,
const gchar *str)
{
- EmpathyThemeAdium *theme = EMPATHY_THEME_ADIUM (view);
- EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+ gchar *str_escaped;
- if (priv->data->status_html) {
- theme_adium_append_html (theme, "appendMessage",
- priv->data->status_html,
- priv->data->status_len,
- str, NULL, NULL, NULL, NULL, "event",
- empathy_time_get_current ());
- }
-
- /* There is no last contact */
- if (priv->last_contact) {
- g_object_unref (priv->last_contact);
- priv->last_contact = NULL;
- }
+ str_escaped = g_markup_escape_text (str, -1);
+ theme_adium_append_event_escaped (view, str_escaped);
+ g_free (str_escaped);
}
static void
static gboolean
theme_adium_find_previous (EmpathyChatView *view,
const gchar *search_criteria,
- gboolean new_search)
+ gboolean new_search,
+ gboolean match_case)
{
+ /* FIXME: Doesn't respect new_search */
return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
- search_criteria, FALSE,
+ search_criteria, match_case,
FALSE, TRUE);
}
static gboolean
theme_adium_find_next (EmpathyChatView *view,
const gchar *search_criteria,
- gboolean new_search)
+ gboolean new_search,
+ gboolean match_case)
{
+ /* FIXME: Doesn't respect new_search */
return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
- search_criteria, FALSE,
+ search_criteria, match_case,
TRUE, TRUE);
}
static void
theme_adium_find_abilities (EmpathyChatView *view,
const gchar *search_criteria,
+ gboolean match_case,
gboolean *can_do_previous,
gboolean *can_do_next)
{
static void
theme_adium_highlight (EmpathyChatView *view,
- const gchar *text)
+ const gchar *text,
+ gboolean match_case)
{
webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
- text, FALSE, 0);
+ text, match_case, 0);
webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
TRUE);
}
webkit_web_view_copy_clipboard (WEBKIT_WEB_VIEW (view));
}
+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 = gtk_menu_new ();
+
+ /* 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);
+ g_object_ref_sink (menu);
+ g_object_unref (menu);
+}
+
+static gboolean
+theme_adium_button_press_event (GtkWidget *widget, GdkEventButton *event)
+{
+ if (event->button == 3) {
+ gboolean developer_tools_enabled;
+
+ g_object_get (G_OBJECT (webkit_web_view_get_settings (WEBKIT_WEB_VIEW (widget))),
+ "enable-developer-extras", &developer_tools_enabled, NULL);
+
+ /* We currently have no way to add an inspector menu
+ * 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);
+ return TRUE;
+ }
+ }
+
+ return GTK_WIDGET_CLASS (empathy_theme_adium_parent_class)->button_press_event (widget, event);
+}
+
static void
theme_adium_iface_init (EmpathyChatViewIface *iface)
{
EmpathyThemeAdiumPriv *priv = GET_PRIV (object);
empathy_adium_data_unref (priv->data);
- g_free (priv->hovered_uri);
-
- empathy_conf_notify_remove (empathy_conf_get (),
- priv->notify_enable_webkit_developer_tools_id);
+ g_object_unref (priv->gsettings_chat);
G_OBJECT_CLASS (empathy_theme_adium_parent_class)->finalize (object);
}
return NULL;
}
+static PangoFontDescription *
+theme_adium_get_default_font (void)
+{
+ GSettings *gsettings;
+ PangoFontDescription *pango_fd;
+ gchar *font_family;
+
+ gsettings = g_settings_new (EMPATHY_PREFS_DESKTOP_INTERFACE_SCHEMA);
+
+ font_family = g_settings_get_string (gsettings,
+ EMPATHY_PREFS_DESKTOP_INTERFACE_DOCUMENT_FONT_NAME);
+
+ if (font_family == NULL)
+ return NULL;
+
+ pango_fd = pango_font_description_from_string (font_family);
+ g_free (font_family);
+ g_object_unref (gsettings);
+ return pango_fd;
+}
+
+static void
+theme_adium_set_webkit_font (WebKitWebSettings *w_settings,
+ const gchar *name,
+ gint size)
+{
+ g_object_set (w_settings, "default-font-family", name, NULL);
+ g_object_set (w_settings, "default-font-size", size, NULL);
+}
+
+static void
+theme_adium_set_default_font (WebKitWebSettings *w_settings)
+{
+ PangoFontDescription *default_font_desc;
+ GdkScreen *current_screen;
+ gdouble dpi = 0;
+ gint pango_font_size = 0;
+
+ default_font_desc = theme_adium_get_default_font ();
+ if (default_font_desc == NULL)
+ return ;
+ pango_font_size = pango_font_description_get_size (default_font_desc)
+ / PANGO_SCALE ;
+ if (pango_font_description_get_size_is_absolute (default_font_desc)) {
+ current_screen = gdk_screen_get_default ();
+ if (current_screen != NULL) {
+ dpi = gdk_screen_get_resolution (current_screen);
+ } else {
+ dpi = BORING_DPI_DEFAULT;
+ }
+ pango_font_size = (gint) (pango_font_size / (dpi / 72));
+ }
+ theme_adium_set_webkit_font (w_settings,
+ pango_font_description_get_family (default_font_desc),
+ pango_font_size);
+ pango_font_description_free (default_font_desc);
+}
+
static void
theme_adium_constructed (GObject *object)
{
font_family = tp_asv_get_string (priv->data->info, "DefaultFontFamily");
font_size = tp_asv_get_int32 (priv->data->info, "DefaultFontSize", NULL);
webkit_settings = webkit_web_view_get_settings (webkit_view);
- if (font_family) {
- g_object_set (webkit_settings,
- "default-font-family", font_family,
- NULL);
- }
- if (font_size) {
- g_object_set (webkit_settings,
- "default-font-size", font_size,
- NULL);
+
+ if (font_family && font_size) {
+ theme_adium_set_webkit_font (webkit_settings, font_family, font_size);
+ } else {
+ theme_adium_set_default_font (webkit_settings);
}
/* Setup webkit inspector */
empathy_theme_adium_class_init (EmpathyThemeAdiumClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = theme_adium_finalize;
object_class->dispose = theme_adium_dispose;
object_class->get_property = theme_adium_get_property;
object_class->set_property = theme_adium_set_property;
+ widget_class->button_press_event = theme_adium_button_press_event;
+
g_object_class_install_property (object_class,
PROP_ADIUM_DATA,
g_param_spec_boxed ("adium-data",
g_signal_connect (theme, "navigation-policy-decision-requested",
G_CALLBACK (theme_adium_navigation_policy_decision_requested_cb),
NULL);
- g_signal_connect (theme, "populate-popup",
- G_CALLBACK (theme_adium_populate_popup_cb),
- NULL);
- g_signal_connect (theme, "hovering-over-link",
- G_CALLBACK (theme_adium_hovering_over_link_cb),
- NULL);
- priv->notify_enable_webkit_developer_tools_id =
- empathy_conf_notify_add (empathy_conf_get (),
- EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
- theme_adium_notify_enable_webkit_developer_tools_cb,
- theme);
+ priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
+ g_signal_connect (priv->gsettings_chat,
+ "changed::" EMPATHY_PREFS_CHAT_WEBKIT_DEVELOPER_TOOLS,
+ G_CALLBACK (theme_adium_notify_enable_webkit_developer_tools_cb),
+ theme);
theme_adium_update_enable_webkit_developer_tools (theme);
}