[evolution] Prefer gtk_clipboard_wait_for_targets() over gtk_clipboard_request_targets()



commit 1cce2f80d0edc485b946f262502b0dcde784954d
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 4 10:51:37 2017 +0200

    Prefer gtk_clipboard_wait_for_targets() over gtk_clipboard_request_targets()
    
    The later seems to be unreliable, returning no targets when pasting
    into the composer, while the former returns the targets reliably.
    Hard to tell what failed for the later, but as long as the other one
    works, then prefer it over the other.

 src/composer/e-msg-composer.c               |   18 ++++++++----
 src/e-util/e-focus-tracker.c                |   12 ++++----
 src/modules/webkit-editor/e-webkit-editor.c |   39 +++++++++++---------------
 3 files changed, 35 insertions(+), 34 deletions(-)
---
diff --git a/src/composer/e-msg-composer.c b/src/composer/e-msg-composer.c
index 70179cf..9b7a0c1 100644
--- a/src/composer/e-msg-composer.c
+++ b/src/composer/e-msg-composer.c
@@ -1791,14 +1791,17 @@ msg_composer_paste_primary_clipboard_cb (EContentEditor *cnt_editor,
                                          EMsgComposer *composer)
 {
        GtkClipboard *clipboard;
+       GdkAtom *targets = NULL;
+       gint n_targets;
 
        clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
 
        composer->priv->last_signal_was_paste_primary = TRUE;
 
-       gtk_clipboard_request_targets (
-               clipboard, (GtkClipboardTargetsReceivedFunc)
-               msg_composer_paste_clipboard_targets_cb, composer);
+       if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
+               msg_composer_paste_clipboard_targets_cb (clipboard, targets, n_targets, composer);
+               g_free (targets);
+       }
 
        return TRUE;
 }
@@ -1808,14 +1811,17 @@ msg_composer_paste_clipboard_cb (EContentEditor *cnt_editor,
                                  EMsgComposer *composer)
 {
        GtkClipboard *clipboard;
+       GdkAtom *targets = NULL;
+       gint n_targets;
 
        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
        composer->priv->last_signal_was_paste_primary = FALSE;
 
-       gtk_clipboard_request_targets (
-               clipboard, (GtkClipboardTargetsReceivedFunc)
-               msg_composer_paste_clipboard_targets_cb, composer);
+       if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
+               msg_composer_paste_clipboard_targets_cb (clipboard, targets, n_targets, composer);
+               g_free (targets);
+       }
 
        return TRUE;
 }
diff --git a/src/e-util/e-focus-tracker.c b/src/e-util/e-focus-tracker.c
index c4390e3..613f95e 100644
--- a/src/e-util/e-focus-tracker.c
+++ b/src/e-util/e-focus-tracker.c
@@ -370,8 +370,6 @@ focus_tracker_targets_received_cb (GtkClipboard *clipboard,
                focus_tracker_editor_update_actions (
                        focus_tracker, E_CONTENT_EDITOR (focus),
                        targets, n_targets);
-
-       g_object_unref (focus_tracker);
 }
 
 static void
@@ -1084,6 +1082,8 @@ void
 e_focus_tracker_update_actions (EFocusTracker *focus_tracker)
 {
        GtkClipboard *clipboard;
+       GdkAtom *targets = NULL;
+       gint n_targets;
 
        g_return_if_fail (E_IS_FOCUS_TRACKER (focus_tracker));
 
@@ -1091,10 +1091,10 @@ e_focus_tracker_update_actions (EFocusTracker *focus_tracker)
 
        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
-       gtk_clipboard_request_targets (
-               clipboard, (GtkClipboardTargetsReceivedFunc)
-               focus_tracker_targets_received_cb,
-               g_object_ref (focus_tracker));
+       if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
+               focus_tracker_targets_received_cb (clipboard, targets, n_targets, focus_tracker);
+               g_free (targets);
+       }
 }
 
 void
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 4ec4583..8a6c35c 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -5735,25 +5735,15 @@ webkit_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
                                           gint n_targets,
                                           gpointer user_data)
 {
-       GWeakRef *weak_ref = user_data;
-       EWebKitEditor *wk_editor;
+       EWebKitEditor *wk_editor = user_data;
        gchar *content = NULL;
        gboolean is_html = FALSE;
 
-       g_return_if_fail (weak_ref != NULL);
-
-       wk_editor = g_weak_ref_get (weak_ref);
-
-       e_weak_ref_free (weak_ref);
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
 
-       if (!wk_editor)
+       if (targets == NULL || n_targets < 0)
                return;
 
-       if (targets == NULL || n_targets < 0) {
-               g_clear_object (&wk_editor);
-               return;
-       }
-
        /* If view doesn't have focus, focus it */
        if (!gtk_widget_has_focus (GTK_WIDGET (wk_editor)))
                gtk_widget_grab_focus (GTK_WIDGET (wk_editor));
@@ -5791,7 +5781,6 @@ webkit_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
 
                webkit_editor_insert_image (E_CONTENT_EDITOR (wk_editor), uri);
 
-               g_clear_object (&wk_editor);
                g_free (content);
                g_free (uri);
 
@@ -5805,7 +5794,6 @@ webkit_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
         * when pasting content from outside the editor view. */
 
        if (!content || !*content) {
-               g_clear_object (&wk_editor);
                g_free (content);
                return;
        }
@@ -5822,7 +5810,6 @@ webkit_editor_paste_clipboard_targets_cb (GtkClipboard *clipboard,
                        E_CONTENT_EDITOR_INSERT_TEXT_PLAIN |
                        E_CONTENT_EDITOR_INSERT_CONVERT);
 
-       g_clear_object (&wk_editor);
        g_free (content);
 }
 
@@ -5831,6 +5818,8 @@ webkit_editor_paste_primary (EContentEditor *editor)
 {
 
        GtkClipboard *clipboard;
+       GdkAtom *targets = NULL;
+       gint n_targets;
        EWebKitEditor *wk_editor;
 
        wk_editor = E_WEBKIT_EDITOR (editor);
@@ -5843,24 +5832,30 @@ webkit_editor_paste_primary (EContentEditor *editor)
 
        clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
 
-       gtk_clipboard_request_targets (
-               clipboard, (GtkClipboardTargetsReceivedFunc)
-               webkit_editor_paste_clipboard_targets_cb, e_weak_ref_new (wk_editor));
+       if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
+               webkit_editor_paste_clipboard_targets_cb (clipboard, targets, n_targets, wk_editor);
+               g_free (targets);
+       }
 }
 
 static void
 webkit_editor_paste (EContentEditor *editor)
 {
        GtkClipboard *clipboard;
+       GdkAtom *targets = NULL;
+       gint n_targets;
        EWebKitEditor *wk_editor;
 
        wk_editor = E_WEBKIT_EDITOR (editor);
 
+       wk_editor->priv->pasting_primary_clipboard = FALSE;
+
        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
-       gtk_clipboard_request_targets (
-               clipboard, (GtkClipboardTargetsReceivedFunc)
-               webkit_editor_paste_clipboard_targets_cb, e_weak_ref_new (wk_editor));
+       if (gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets)) {
+               webkit_editor_paste_clipboard_targets_cb (clipboard, targets, n_targets, wk_editor);
+               g_free (targets);
+       }
 }
 
 static void


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