diff options
author | Dan Vrátil <dvratil@redhat.com> | 2012-05-03 16:14:37 +0800 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2012-05-03 16:14:37 +0800 |
commit | 96f9d7a159ebec6ff456f53cedb4beb338b8b3f6 (patch) | |
tree | f3fa2def0afcbf49d684086f47756650fc77fc48 /addressbook | |
parent | b91c6da187f51f6e2956f5d89b193f7004449360 (diff) | |
download | gsoc2013-evolution-96f9d7a159ebec6ff456f53cedb4beb338b8b3f6.tar.gz gsoc2013-evolution-96f9d7a159ebec6ff456f53cedb4beb338b8b3f6.tar.zst gsoc2013-evolution-96f9d7a159ebec6ff456f53cedb4beb338b8b3f6.zip |
Bug #674997 - Collapsing contact lists broken in Contacts preview
Diffstat (limited to 'addressbook')
-rw-r--r-- | addressbook/gui/widgets/eab-contact-display.c | 21 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-contact-formatter.c | 88 | ||||
-rw-r--r-- | addressbook/gui/widgets/eab-contact-formatter.h | 2 |
3 files changed, 100 insertions, 11 deletions
diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index 2486fd72f1..9d4e4eda89 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -36,6 +36,8 @@ #include "e-util/e-file-request.h" #include "e-util/e-stock-request.h" +#include <webkit/webkit.h> + #ifdef WITH_CONTACT_MAPS #include "widgets/misc/e-contact-map.h" #endif @@ -400,6 +402,23 @@ contact_display_object_requested (WebKitWebView *web_view, #endif static void +contact_display_load_status_changed (WebKitWebView *web_view, + GParamSpec *pspec, + gpointer user_data) +{ + WebKitLoadStatus load_status; + WebKitDOMDocument *document; + + + load_status = webkit_web_view_get_load_status (web_view); + if (load_status != WEBKIT_LOAD_FINISHED) + return; + + document = webkit_web_view_get_dom_document (web_view); + eab_contact_formatter_bind_dom (document); +} + +static void contact_display_update_actions (EWebView *web_view) { GtkActionGroup *action_group; @@ -515,6 +534,8 @@ eab_contact_display_init (EABContactDisplay *display) g_signal_connect (web_view, "create-plugin-widget", G_CALLBACK (contact_display_object_requested), display); #endif + g_signal_connect (web_view, "notify::load-status", + G_CALLBACK (contact_display_load_status_changed), NULL); e_web_view_install_request_handler (E_WEB_VIEW (display), E_TYPE_FILE_REQUEST); e_web_view_install_request_handler (E_WEB_VIEW (display), E_TYPE_STOCK_REQUEST); diff --git a/addressbook/gui/widgets/eab-contact-formatter.c b/addressbook/gui/widgets/eab-contact-formatter.c index 0c594b9993..16430bf87a 100644 --- a/addressbook/gui/widgets/eab-contact-formatter.c +++ b/addressbook/gui/widgets/eab-contact-formatter.c @@ -422,8 +422,11 @@ render_title_block (EABContactFormatter *formatter, photo->data.inlined.mime_type, photo_data); } else if (photo && photo->type == E_CONTACT_PHOTO_TYPE_URI && photo->data.uri && *photo->data.uri) { + gboolean is_local = g_str_has_prefix (photo->data.uri, "file://"); + g_string_append_printf ( - buffer, "<img border=\"1\" src=\"%s\">", photo->data.uri); + buffer, "<img border=\"1\" src=\"%s%s\">", + is_local ? "evo-" : "", photo->data.uri); } if (photo) @@ -478,11 +481,11 @@ render_contact_list_row (EABContactFormatter *formatter, if (e_destination_is_evolution_list (destination)) { g_string_append_printf ( buffer, - "<td width=" IMAGE_COL_WIDTH " valign=\"top\">" - "<img src=\"%s/minus.png\" " - "onClick=\"collapse_list(this, %s);\" " - "class=\"navigable\">" - "</td><td width=\"100%%\">%s", + "<td width=" IMAGE_COL_WIDTH " valign=\"top\" align=\"left\">" + "<img src=\"evo-file://%s/minus.png\" " + "id=\"%s\" " + "class=\"navigable _evo_collapse_button\">" + "</td><td width=\"100%%\" align=\"left\">%s", evolution_imagesdir, e_destination_get_contact_uid (destination), name ? name : email_addr); @@ -491,7 +494,7 @@ render_contact_list_row (EABContactFormatter *formatter, const GList *dest, *dests; g_string_append_printf ( buffer, - "<br><table cellspacing=\"1\" id=\"%s\">", + "<br><table cellspacing=\"1\" id=\"list-%s\">", e_destination_get_contact_uid (destination)); dests = e_destination_list_get_root_dests (destination); @@ -875,12 +878,14 @@ render_compact (EABContactFormatter *formatter, } if (photo->type == E_CONTACT_PHOTO_TYPE_URI && - photo->data.uri && *photo->data.uri) + photo->data.uri && *photo->data.uri) { + gboolean is_local = g_str_has_prefix (photo->data.uri, "file://"); g_string_append_printf ( buffer, - "<img width=\"%d\" height=\"%d\" src=\"%s\">", - calced_width, calced_height, photo->data.uri); - else { + "<img width=\"%d\" height=\"%d\" src=\"%s%s\">", + calced_width, calced_height, + is_local ? "evo-" : "", photo->data.uri); + } else { gchar *photo_data; photo_data = g_base64_encode ( @@ -1253,3 +1258,64 @@ eab_contact_formatter_format_contact_async (EABContactFormatter *formatter, result, do_start_async_formatter, G_PRIORITY_DEFAULT, cancellable); } + +static void +collapse_contacts_list (WebKitDOMEventTarget *event_target, + WebKitDOMEvent *event, + gpointer user_data) +{ + WebKitDOMDocument *document; + WebKitDOMElement *list; + gchar *id, *list_id; + gchar *imagesdir, *src; + gboolean hidden; + + document = user_data; + id = webkit_dom_html_element_get_id (WEBKIT_DOM_HTML_ELEMENT (event_target)); + + list_id = g_strconcat ("list-", id, NULL); + list = webkit_dom_document_get_element_by_id (document, list_id); + g_free (id); + g_free (list_id); + + if (!list) + return; + + imagesdir = g_filename_to_uri (EVOLUTION_IMAGESDIR, NULL, NULL); + hidden = webkit_dom_html_element_get_hidden (WEBKIT_DOM_HTML_ELEMENT (list)); + + if (hidden) { + src = g_strdup_printf ("evo-file://%s/minus.png", imagesdir); + } else { + src = g_strdup_printf ("evo-file://%s/plus.png", imagesdir); + } + + webkit_dom_html_element_set_hidden ( + WEBKIT_DOM_HTML_ELEMENT (list), !hidden); + webkit_dom_html_image_element_set_src ( + WEBKIT_DOM_HTML_IMAGE_ELEMENT (event_target), src); + + g_free (src); + g_free (imagesdir); +} + +void +eab_contact_formatter_bind_dom (WebKitDOMDocument* document) +{ + WebKitDOMNodeList *nodes; + gulong i, length; + + nodes = webkit_dom_document_get_elements_by_class_name ( + document, "_evo_collapse_button"); + + length = webkit_dom_node_list_get_length (nodes); + for (i = 0; i < length; i++) { + + WebKitDOMNode *node; + + node = webkit_dom_node_list_item (nodes, i); + webkit_dom_event_target_add_event_listener ( + WEBKIT_DOM_EVENT_TARGET (node), "click", + G_CALLBACK (collapse_contacts_list), FALSE, document); + } +} diff --git a/addressbook/gui/widgets/eab-contact-formatter.h b/addressbook/gui/widgets/eab-contact-formatter.h index 4a0e95fd2b..690d74321b 100644 --- a/addressbook/gui/widgets/eab-contact-formatter.h +++ b/addressbook/gui/widgets/eab-contact-formatter.h @@ -84,6 +84,8 @@ void eab_contact_formatter_format_contact_async GAsyncReadyCallback callback, gpointer user_data); +void eab_contact_formatter_bind_dom (WebKitDOMDocument *document); + G_END_DECLS #endif |