diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-05-18 14:04:26 +0800 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2011-05-25 09:01:59 +0800 |
commit | 3c402461dd7eb5776f81ecd6d31b6f663315bc26 (patch) | |
tree | aa92341f792f92c15b9e2e99b35de0f8e87ee563 /libempathy-gtk | |
parent | 72d86515da906e3c867eff6abd309a8a03a38534 (diff) | |
download | gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.tar gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.tar.gz gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.tar.bz2 gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.tar.lz gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.tar.xz gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.tar.zst gsoc2013-empathy-3c402461dd7eb5776f81ecd6d31b6f663315bc26.zip |
[theme-adium] implement edit_message()
This is done via DOM manipulation, we find the id for the <span> tag we
wrapped the message in in the previous commit. We then replace the innerHTML
with the new message.
This requires a version of WebKitGtk 1.3.x, but I'm not precisely sure what. I
used WebKitGtk 1.4.0, but natty only has 1.3.13, so we'll try setting that as
the dep.
Need to somehow mark a message as edited. Could set a class on it, but that
requires support in the theme. Need inspiration here.
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-theme-adium.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 712c2fbc5..05758ed9d 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -643,6 +643,63 @@ theme_adium_append_event (EmpathyChatView *view, } static void +theme_adium_edit_message (EmpathyChatView *view, + EmpathyMessage *message) +{ + EmpathyThemeAdiumPriv *priv = GET_PRIV (view); + WebKitDOMDocument *doc; + WebKitDOMElement *span; + gchar *id, *parsed_body; + GError *error = NULL; + + if (priv->pages_loading != 0) { + priv->message_queue = g_list_prepend (priv->message_queue, + g_object_ref (message)); + return; + } + + id = g_strdup_printf ("message-token-%s", + empathy_message_get_supersedes (message)); + /* we don't pass a token here, because doing so will return another + * <span> element, and we don't want nested <span> elements */ + parsed_body = theme_adium_parse_body ( + empathy_message_get_body (message), NULL); + + /* find the element */ + doc = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view)); + span = webkit_dom_document_get_element_by_id (doc, id); + + if (span == NULL) { + DEBUG ("Failed to find id '%s'", id); + goto except; + } + + if (!WEBKIT_DOM_IS_HTML_ELEMENT (span)) { + DEBUG ("Not a HTML element"); + goto except; + } + + /* update the HTML */ + webkit_dom_html_element_set_inner_html (WEBKIT_DOM_HTML_ELEMENT (span), + parsed_body, &error); + + if (error != NULL) { + DEBUG ("Error setting new inner-HTML: %s", error->message); + g_error_free (error); + } + + goto finally; + +except: + DEBUG ("Could not find message to edit with: %s", + empathy_message_get_body (message)); + +finally: + g_free (id); + g_free (parsed_body); +} + +static void theme_adium_scroll (EmpathyChatView *view, gboolean allow_scrolling) { @@ -852,6 +909,7 @@ theme_adium_iface_init (EmpathyChatViewIface *iface) { iface->append_message = theme_adium_append_message; iface->append_event = theme_adium_append_event; + iface->edit_message = theme_adium_edit_message; iface->scroll = theme_adium_scroll; iface->scroll_down = theme_adium_scroll_down; iface->get_has_selection = theme_adium_get_has_selection; @@ -882,7 +940,11 @@ theme_adium_load_finished_cb (WebKitWebView *view, while (priv->message_queue) { EmpathyMessage *message = priv->message_queue->data; - theme_adium_append_message (chat_view, message); + if (empathy_message_is_edit (message)) + theme_adium_edit_message (chat_view, message); + else + theme_adium_append_message (chat_view, message); + priv->message_queue = g_list_remove (priv->message_queue, message); g_object_unref (message); } |