[evolution/wip-webkit2] VCardInline - Fix functionality when you have more than one vcard in email
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip-webkit2] VCardInline - Fix functionality when you have more than one vcard in email
- Date: Mon, 18 Nov 2013 09:08:54 +0000 (UTC)
commit 6845f61e5d2e790c1e6b90c376d51ecd45dc7e72
Author: Tomas Popela <tpopela redhat com>
Date: Mon Nov 18 10:01:39 2013 +0100
VCardInline - Fix functionality when you have more than one vcard in email
e-util/e-dom-utils.c | 55 +++++++++++++++++--------
e-util/e-dom-utils.h | 3 +-
modules/vcard-inline/e-mail-formatter-vcard.c | 2 +
modules/vcard-inline/e-mail-part-vcard.c | 21 +++++++--
web-extensions/evolution-web-extension.c | 19 +++++----
5 files changed, 68 insertions(+), 32 deletions(-)
---
diff --git a/e-util/e-dom-utils.c b/e-util/e-dom-utils.c
index 675a835..dd39c55 100644
--- a/e-util/e-dom-utils.c
+++ b/e-util/e-dom-utils.c
@@ -897,23 +897,28 @@ display_mode_toggle_button_cb (WebKitDOMElement *button,
GDBusConnection *connection)
{
GError *error = NULL;
+ gchar *element_id;
+#if WEBKIT_CHECK_VERSION(2,2,0) /* XXX should really be (2,1,something) */
+ element_id = webkit_dom_element_get_id (button);
+#else
+ element_id = webkit_dom_html_element_get_id (WEBKIT_DOM_HTML_ELEMENT (button));
+#endif
g_dbus_connection_emit_signal (
connection,
NULL,
EVOLUTION_WEB_EXTENSION_OBJECT_PATH,
EVOLUTION_WEB_EXTENSION_INTERFACE,
"VCardInlineDisplayModeToggled",
- g_variant_new (
- "(s)",
- webkit_dom_html_button_element_get_value (
- WEBKIT_DOM_HTML_BUTTON_ELEMENT (button))),
+ g_variant_new ("(s)", element_id),
&error);
if (error) {
g_warning ("Error emitting signal DisplayModeToggled: %s\n", error->message);
g_error_free (error);
}
+
+ g_free (element_id);
}
static void
@@ -922,6 +927,10 @@ save_vcard_button_cb (WebKitDOMElement *button,
GDBusConnection *connection)
{
GError *error = NULL;
+ gchar *button_value;
+
+ button_value = webkit_dom_html_button_element_get_value (
+ WEBKIT_DOM_HTML_BUTTON_ELEMENT (button));
g_dbus_connection_emit_signal (
connection,
@@ -929,16 +938,15 @@ save_vcard_button_cb (WebKitDOMElement *button,
EVOLUTION_WEB_EXTENSION_OBJECT_PATH,
EVOLUTION_WEB_EXTENSION_INTERFACE,
"VCardInlineSaveButtonPressed",
- g_variant_new (
- "(s)",
- webkit_dom_html_button_element_get_value (
- WEBKIT_DOM_HTML_BUTTON_ELEMENT (button))),
+ g_variant_new ("(s)", button_value),
&error);
if (error) {
g_warning ("Error emitting signal SaveVCardButtonPressed: %s\n", error->message);
g_error_free (error);
}
+
+ g_free (button_value);
}
void
@@ -948,6 +956,7 @@ e_dom_utils_module_vcard_inline_bind_dom (WebKitDOMDocument *document,
{
WebKitDOMElement *element;
WebKitDOMDocument *element_document;
+ gchar *selector;
element = e_dom_utils_find_element_by_id (document, element_id);
if (!element)
@@ -956,33 +965,37 @@ e_dom_utils_module_vcard_inline_bind_dom (WebKitDOMDocument *document,
element_document = webkit_dom_node_get_owner_document (
WEBKIT_DOM_NODE (element));
+ selector = g_strconcat ("button[id='", element_id, "']", NULL);
e_dom_utils_bind_dom (
element_document,
- ".org-gnome-vcard-display-mode-button",
+ selector,
"click",
display_mode_toggle_button_cb,
connection);
+ g_free (selector);
+ selector = g_strconcat ("button[value='", element_id, "']", NULL);
e_dom_utils_bind_dom (
element_document,
- ".org-gnome-vcard-save-button",
+ selector,
"click",
save_vcard_button_cb,
connection);
+ g_free (selector);
e_dom_utils_eab_contact_formatter_bind_dom (element_document);
}
void
e_dom_utils_module_vcard_inline_update_button (WebKitDOMDocument *document,
- const gchar *button_value,
+ const gchar *button_id,
const gchar *html_label,
const gchar *access_key)
{
WebKitDOMElement *element;
gchar *selector;
- selector = g_strconcat ("button[value=", button_value, "]", NULL);
+ selector = g_strconcat ("button[id='", button_id, "']", NULL);
element = e_dom_utils_find_element_by_selector (document, selector);
g_free (selector);
@@ -1000,16 +1013,24 @@ e_dom_utils_module_vcard_inline_update_button (WebKitDOMDocument *document,
void
e_dom_utils_module_vcard_inline_set_iframe_src (WebKitDOMDocument *document,
+ const gchar *button_id,
const gchar *src)
{
- WebKitDOMElement *element;
+ WebKitDOMElement *element, *parent, *iframe;
+ gchar *selector;
- element = e_dom_utils_find_element_by_selector (
- document, "iframe[name$=org-gnome-vcard-display]");
+ selector = g_strconcat ("button[id='", button_id, "']", NULL);
+ element = e_dom_utils_find_element_by_selector (document, selector);
+ g_free (selector);
- if (!element)
+ parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (element));
+ if (!parent)
+ return;
+
+ iframe = webkit_dom_element_query_selector (parent, "iframe", NULL);
+ if (!iframe)
return;
webkit_dom_html_iframe_element_set_src (
- WEBKIT_DOM_HTML_IFRAME_ELEMENT (element), src);
+ WEBKIT_DOM_HTML_IFRAME_ELEMENT (iframe), src);
}
diff --git a/e-util/e-dom-utils.h b/e-util/e-dom-utils.h
index fda8526..26cb3e1 100644
--- a/e-util/e-dom-utils.h
+++ b/e-util/e-dom-utils.h
@@ -89,11 +89,12 @@ void e_dom_utils_module_vcard_inline_bind_dom
GDBusConnection *connection);
void e_dom_utils_module_vcard_inline_update_button
(WebKitDOMDocument *document,
- const gchar *button_value,
+ const gchar *button_id,
const gchar *html_label,
const gchar *access_key);
void e_dom_utils_module_vcard_inline_set_iframe_src
(WebKitDOMDocument *document,
+ const gchar *button_id,
const gchar *src);
G_END_DECLS
diff --git a/modules/vcard-inline/e-mail-formatter-vcard.c b/modules/vcard-inline/e-mail-formatter-vcard.c
index 75c1d2e..f8b98f7 100644
--- a/modules/vcard-inline/e-mail-formatter-vcard.c
+++ b/modules/vcard-inline/e-mail-formatter-vcard.c
@@ -143,9 +143,11 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
str = g_strdup_printf (
"<button type=\"button\" "
"name=\"set-display-mode\" "
+ "id=\"%s\" "
"class=\"org-gnome-vcard-display-mode-button\" "
"value=\"%d\" "
"accesskey=\"%s\">%s</button>",
+ e_mail_part_get_id (part),
mode, access_key, html_label);
camel_stream_write_string (stream, str, cancellable, NULL);
g_free (str);
diff --git a/modules/vcard-inline/e-mail-part-vcard.c b/modules/vcard-inline/e-mail-part-vcard.c
index 8e9a46b..e7d0154 100644
--- a/modules/vcard-inline/e-mail-part-vcard.c
+++ b/modules/vcard-inline/e-mail-part-vcard.c
@@ -105,12 +105,19 @@ save_vcard_cb (GDBusConnection *connection,
ESourceRegistry *registry;
ESourceSelector *selector;
GSList *contact_list;
- const gchar *extension_name;
+ const gchar *extension_name, *button_value, *part_id;
GtkWidget *dialog;
if (g_strcmp0 (signal_name, "VCardInlineSaveButtonPressed") != 0)
return;
+ g_variant_get (parameters, "(&s)", &button_value);
+
+ part_id = e_mail_part_get_id (E_MAIL_PART (vcard_part));
+
+ if (!strstr (part_id, button_value))
+ return;
+
shell = e_shell_get_default ();
registry = e_shell_get_registry (shell);
extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
@@ -158,7 +165,7 @@ display_mode_toggle_cb (GDBusConnection *connection,
gchar *html_label;
gchar *access_key;
const gchar *part_id;
- const gchar *button_value;
+ const gchar *button_id;
if (g_strcmp0 (signal_name, "VCardInlineDisplayModeToggled") != 0)
return;
@@ -166,10 +173,13 @@ display_mode_toggle_cb (GDBusConnection *connection,
if (!vcard_part->priv->web_extension)
return;
- g_variant_get (parameters, "(&s)", &button_value);
+ g_variant_get (parameters, "(&s)", &button_id);
part_id = e_mail_part_get_id (E_MAIL_PART (vcard_part));
+ if (!strstr (part_id, button_id))
+ return;
+
mode = eab_contact_formatter_get_display_mode (vcard_part->formatter);
if (mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) {
mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT;
@@ -189,7 +199,7 @@ display_mode_toggle_cb (GDBusConnection *connection,
g_variant_new (
"(tsss)",
vcard_part->priv->page_id,
- button_value,
+ button_id,
html_label,
access_key),
G_DBUS_CALL_FLAGS_NONE,
@@ -214,8 +224,9 @@ display_mode_toggle_cb (GDBusConnection *connection,
vcard_part->priv->web_extension,
"VCardInlineSetIFrameSrc",
g_variant_new (
- "(ts)",
+ "(tss)",
vcard_part->priv->page_id,
+ button_id,
uri),
G_DBUS_CALL_FLAGS_NONE,
-1,
diff --git a/web-extensions/evolution-web-extension.c b/web-extensions/evolution-web-extension.c
index 694a3f7..5153c05 100644
--- a/web-extensions/evolution-web-extension.c
+++ b/web-extensions/evolution-web-extension.c
@@ -83,10 +83,10 @@ static const char introspection_xml[] =
" <arg type='s' name='element_id' direction='in'/>"
" </method>"
" <signal name='VCardInlineDisplayModeToggled'>"
-" <arg type='s' name='button_class' direction='out'/>"
+" <arg type='s' name='button_id' direction='out'/>"
" </signal>"
" <signal name='VCardInlineSaveButtonPressed'>"
-" <arg type='s' name='button_class' direction='out'/>"
+" <arg type='s' name='button_value' direction='out'/>"
" </signal>"
" <method name='VCardInlineBindDOM'>"
" <arg type='t' name='page_id' direction='in'/>"
@@ -94,12 +94,13 @@ static const char introspection_xml[] =
" </method>"
" <method name='VCardInlineUpdateButton'>"
" <arg type='t' name='page_id' direction='in'/>"
-" <arg type='s' name='button_value' direction='in'/>"
+" <arg type='s' name='button_id' direction='in'/>"
" <arg type='s' name='html_label' direction='in'/>"
" <arg type='s' name='access_key' direction='in'/>"
" </method>"
" <method name='VCardInlineSetIFrameSrc'>"
" <arg type='t' name='page_id' direction='in'/>"
+" <arg type='s' name='button_id' direction='in'/>"
" <arg type='s' name='src' direction='in'/>"
" </method>"
" </interface>"
@@ -357,12 +358,12 @@ handle_method_call (GDBusConnection *connection,
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "VCardInlineUpdateButton") == 0) {
- const gchar *button_value, *html_label, *access_key;
+ const gchar *button_id, *html_label, *access_key;
g_variant_get (
parameters,
"(t&s&s&s)",
- &page_id, &button_value, &html_label, &access_key);
+ &page_id, &button_id, &html_label, &access_key);
web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
if (!web_page)
@@ -370,19 +371,19 @@ handle_method_call (GDBusConnection *connection,
document = webkit_web_page_get_dom_document (web_page);
e_dom_utils_module_vcard_inline_update_button (
- document, button_value, html_label, access_key);
+ document, button_id, html_label, access_key);
g_dbus_method_invocation_return_value (invocation, NULL);
} else if (g_strcmp0 (method_name, "VCardInlineSetIFrameSrc") == 0) {
- const gchar *src;
+ const gchar *src, *button_id;
- g_variant_get (parameters, "(t&s)", &page_id, &src);
+ g_variant_get (parameters, "(t&s&s)", &page_id, &button_id, &src);
web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
if (!web_page)
return;
document = webkit_web_page_get_dom_document (web_page);
- e_dom_utils_module_vcard_inline_set_iframe_src (document, src);
+ e_dom_utils_module_vcard_inline_set_iframe_src (document, button_id, src);
g_dbus_method_invocation_return_value (invocation, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]