[evolution/wip-webkit2] PreferPlain - Do dbus calls asynchronously



commit 46152071cc9418111e23159f2cfa5e09447c69e6
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Nov 19 15:09:04 2013 +0100

    PreferPlain - Do dbus calls asynchronously

 .../e-mail-display-popup-prefer-plain.c            |  177 +++++++++++--------
 .../module-prefer-plain-web-extension.c            |    6 +-
 2 files changed, 106 insertions(+), 77 deletions(-)
---
diff --git a/modules/prefer-plain/e-mail-display-popup-prefer-plain.c 
b/modules/prefer-plain/e-mail-display-popup-prefer-plain.c
index bbcd6e8..7ad8f61 100644
--- a/modules/prefer-plain/e-mail-display-popup-prefer-plain.c
+++ b/modules/prefer-plain/e-mail-display-popup-prefer-plain.c
@@ -149,32 +149,23 @@ mail_display_popup_prefer_plain_watch_web_extension (EMailDisplayPopupPreferPlai
 }
 
 static void
-toggle_part (GtkAction *action,
-             EMailDisplayPopupExtension *extension)
+toggle_part_get_document_uri_cb (GDBusProxy *web_extension,
+                                 GAsyncResult *result,
+                                 EMailDisplayPopupExtension *extension)
 {
        EMailDisplayPopupPreferPlain *pp_extension = (EMailDisplayPopupPreferPlain *) extension;
-       GVariant *result;
        SoupURI *soup_uri;
        GHashTable *query;
-       const gchar *document_uri;
        gchar *uri;
+       GVariant *result_variant;
 
-       if (!pp_extension->web_extension)
-               return;
+       result_variant = g_dbus_proxy_call_finish (web_extension, result, NULL);
+       if (result_variant) {
+               const gchar *document_uri;
 
-       /* Get URI from saved document */
-       result = g_dbus_proxy_call_sync (
-                       pp_extension->web_extension,
-                       "GetDocumentURI",
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result) {
-               g_variant_get (result, "(&s)", &document_uri);
+               g_variant_get (result_variant, "(&s)", &document_uri);
                soup_uri = soup_uri_new (document_uri);
-               g_variant_unref (result);
+               g_variant_unref (result_variant);
        }
 
        if (!soup_uri || !soup_uri->query) {
@@ -201,21 +192,40 @@ toggle_part (GtkAction *action,
        uri = soup_uri_to_string (soup_uri, FALSE);
        soup_uri_free (soup_uri);
 
-       /* Get frame's window and from the window the actual <iframe> element */
-       result = g_dbus_proxy_call_sync (
-                       pp_extension->web_extension,
-                       "ChangeIFrameSource",
-                       g_variant_new ("(s)", uri),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result)
-               g_variant_unref (result);
+       g_dbus_proxy_call (
+               pp_extension->web_extension,
+               "ChangeIFrameSource",
+               g_variant_new ("(s)", uri),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
 
        g_free (uri);
 }
 
+static void
+toggle_part (GtkAction *action,
+             EMailDisplayPopupExtension *extension)
+{
+       EMailDisplayPopupPreferPlain *pp_extension = (EMailDisplayPopupPreferPlain *) extension;
+
+       if (!pp_extension->web_extension)
+               return;
+
+       /* Get URI from saved document */
+       g_dbus_proxy_call (
+               pp_extension->web_extension,
+               "GetDocumentURI",
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               (GAsyncReadyCallback) toggle_part_get_document_uri_cb,
+               extension);
+}
+
 GtkActionEntry entries[] = {
 
        { "show-plain-text-part",
@@ -301,12 +311,13 @@ create_group (EMailDisplayPopupExtension *extension)
 }
 
 static void
-mail_display_popup_prefer_plain_update_actions (EMailDisplayPopupExtension *extension)
+get_document_uri_cb (GDBusProxy *web_extension,
+                     GAsyncResult *result,
+                     EMailDisplayPopupExtension *extension)
 {
        EMailDisplay *display;
        GtkAction *action;
        gchar *part_id, *pos, *prefix;
-       const gchar *document_uri;
        SoupURI *soup_uri;
        GHashTable *query;
        EMailPartList *part_list;
@@ -315,58 +326,20 @@ mail_display_popup_prefer_plain_update_actions (EMailDisplayPopupExtension *exte
        EMailDisplayPopupPreferPlain *pp_extension;
        GQueue queue = G_QUEUE_INIT;
        GList *head, *link;
-       GVariant *result;
-       gint32 x, y;
-       GdkDeviceManager *device_manager;
-       GdkDevice *pointer;
+       GVariant *result_variant;
 
        display = E_MAIL_DISPLAY (e_extension_get_extensible (
                        E_EXTENSION (extension)));
 
        pp_extension = E_MAIL_DISPLAY_POPUP_PREFER_PLAIN (extension);
 
-       if (!pp_extension->action_group)
-               pp_extension->action_group = create_group (extension);
-
-       /* In WK2 you can't get the node on what WebKitHitTest was performed,
-        * we have to use other way */
-       device_manager = gdk_display_get_device_manager (
-               gtk_widget_get_display (GTK_WIDGET(display)));
-       pointer = gdk_device_manager_get_client_pointer (device_manager);
-       gdk_window_get_device_position (
-               gtk_widget_get_window (GTK_WIDGET (display)), pointer, &x, &y, NULL);
-
-       if (!pp_extension->web_extension)
-                       return;
-
-       result = g_dbus_proxy_call_sync (
-                       pp_extension->web_extension,
-                       "SaveDocumentFromPoint",
-                       g_variant_new (
-                               "(tii)",
-                               webkit_web_view_get_page_id (
-                                       WEBKIT_WEB_VIEW (display)),
-                               x, y),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result)
-               g_variant_unref (result);
+       result_variant = g_dbus_proxy_call_finish (web_extension, result, NULL);
+       if (result_variant) {
+               const gchar *document_uri;
 
-       /* Get URI from saved document */
-       result = g_dbus_proxy_call_sync (
-                       pp_extension->web_extension,
-                       "GetDocumentURI",
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result) {
-               g_variant_get (result, "(&s)", &document_uri);
+               g_variant_get (result_variant, "(&s)", &document_uri);
                soup_uri = soup_uri_new (document_uri);
-               g_variant_unref (result);
+               g_variant_unref (result_variant);
        }
 
        if (!soup_uri || !soup_uri->query) {
@@ -470,6 +443,60 @@ mail_display_popup_prefer_plain_update_actions (EMailDisplayPopupExtension *exte
        soup_uri_free (soup_uri);
 }
 
+static void
+mail_display_popup_prefer_plain_update_actions (EMailDisplayPopupExtension *extension)
+{
+       EMailDisplay *display;
+       EMailDisplayPopupPreferPlain *pp_extension;
+       gint32 x, y;
+       GdkDeviceManager *device_manager;
+       GdkDevice *pointer;
+
+       display = E_MAIL_DISPLAY (e_extension_get_extensible (
+                       E_EXTENSION (extension)));
+
+       pp_extension = E_MAIL_DISPLAY_POPUP_PREFER_PLAIN (extension);
+
+       if (!pp_extension->action_group)
+               pp_extension->action_group = create_group (extension);
+
+       /* In WK2 you can't get the node on what WebKitHitTest was performed,
+        * we have to use other way */
+       device_manager = gdk_display_get_device_manager (
+               gtk_widget_get_display (GTK_WIDGET(display)));
+       pointer = gdk_device_manager_get_client_pointer (device_manager);
+       gdk_window_get_device_position (
+               gtk_widget_get_window (GTK_WIDGET (display)), pointer, &x, &y, NULL);
+
+       if (!pp_extension->web_extension)
+                       return;
+
+       g_dbus_proxy_call (
+               pp_extension->web_extension,
+               "SaveDocumentFromPoint",
+               g_variant_new (
+                       "(tii)",
+                       webkit_web_view_get_page_id (
+                               WEBKIT_WEB_VIEW (display)),
+                       x, y),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
+
+       /* Get URI from saved document */
+       g_dbus_proxy_call (
+               pp_extension->web_extension,
+               "GetDocumentURI",
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               (GAsyncReadyCallback) get_document_uri_cb,
+               extension);
+}
+
 void
 e_mail_display_popup_prefer_plain_type_register (GTypeModule *type_module)
 {
diff --git a/modules/prefer-plain/web-extension/module-prefer-plain-web-extension.c 
b/modules/prefer-plain/web-extension/module-prefer-plain-web-extension.c
index 29f969c..2b1e668 100644
--- a/modules/prefer-plain/web-extension/module-prefer-plain-web-extension.c
+++ b/modules/prefer-plain/web-extension/module-prefer-plain-web-extension.c
@@ -94,7 +94,6 @@ handle_method_call (GDBusConnection *connection,
                g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "SaveDocumentFromPoint") == 0) {
                gint32 x = 0, y = 0;
-               WebKitDOMElement *active_element;
 
                g_variant_get (parameters, "(tii)", &page_id, &x, &y);
                web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
@@ -108,7 +107,10 @@ handle_method_call (GDBusConnection *connection,
        } else if (g_strcmp0 (method_name, "GetDocumentURI") == 0) {
                gchar *document_uri;
 
-               document_uri = webkit_dom_document_get_document_uri (document_saved);
+               if (document_saved)
+                       document_uri = webkit_dom_document_get_document_uri (document_saved);
+               else
+                       document_uri = g_strdup ("");
 
                g_dbus_method_invocation_return_value (
                        invocation, g_variant_new ("(s)", document_uri));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]