[evolution/wip/mcrha/webkit-jsc-api] Correct calls of e_content_editor_get_content()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Correct calls of e_content_editor_get_content()
- Date: Wed, 22 Apr 2020 15:40:55 +0000 (UTC)
commit 832e1efc97d0144e8a4bf3dc77e3443362e9bbc9
Author: Milan Crha <mcrha redhat com>
Date: Wed Apr 22 17:43:52 2020 +0200
Correct calls of e_content_editor_get_content()
src/e-util/e-mail-signature-editor.c | 82 ++++++++++++++-------------
src/plugins/external-editor/external-editor.c | 27 ++++++---
2 files changed, 63 insertions(+), 46 deletions(-)
---
diff --git a/src/e-util/e-mail-signature-editor.c b/src/e-util/e-mail-signature-editor.c
index ad56b0c01a..a2fa5d1149 100644
--- a/src/e-util/e-mail-signature-editor.c
+++ b/src/e-util/e-mail-signature-editor.c
@@ -229,16 +229,56 @@ action_close_cb (GtkAction *action,
gtk_widget_destroy (GTK_WIDGET (window));
}
+static void
+mail_signature_editor_commit_ready_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EMailSignatureEditor *editor;
+ GError *error = NULL;
+
+ g_return_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (source_object));
+
+ editor = E_MAIL_SIGNATURE_EDITOR (source_object);
+
+ e_mail_signature_editor_commit_finish (editor, result, &error);
+
+ /* Ignore cancellations. */
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ g_error_free (error);
+
+ } else if (error != NULL) {
+ e_alert_submit (
+ E_ALERT_SINK (e_mail_signature_editor_get_editor (editor)),
+ "widgets:no-save-signature",
+ error->message, NULL);
+ g_error_free (error);
+
+ /* Only destroy the editor if the save was successful. */
+ } else {
+ ESourceRegistry *registry;
+ ESource *source;
+
+ registry = e_mail_signature_editor_get_registry (editor);
+ source = e_mail_signature_editor_get_source (editor);
+
+ /* Only make sure that the 'source-changed' is called,
+ * thus the preview of the signature is updated on save.
+ * It is not called when only signature body is changed
+ * (and ESource properties are left unchanged). */
+ g_signal_emit_by_name (registry, "source-changed", source);
+
+ gtk_widget_destroy (GTK_WIDGET (editor));
+ }
+}
+
static void
action_save_and_close_cb (GtkAction *action,
EMailSignatureEditor *editor)
{
GtkEntry *entry;
- EAsyncClosure *closure;
- GAsyncResult *result;
ESource *source;
gchar *display_name;
- GError *error = NULL;
entry = GTK_ENTRY (editor->priv->entry);
source = e_mail_signature_editor_get_source (editor);
@@ -267,43 +307,9 @@ action_save_and_close_cb (GtkAction *action,
editor->priv->cancellable = g_cancellable_new ();
- closure = e_async_closure_new ();
-
e_mail_signature_editor_commit (
editor, editor->priv->cancellable,
- e_async_closure_callback, closure);
-
- result = e_async_closure_wait (closure);
-
- e_mail_signature_editor_commit_finish (editor, result, &error);
-
- e_async_closure_free (closure);
-
- /* Ignore cancellations. */
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
-
- } else if (error != NULL) {
- e_alert_submit (
- E_ALERT_SINK (e_mail_signature_editor_get_editor (editor)),
- "widgets:no-save-signature",
- error->message, NULL);
- g_error_free (error);
-
- /* Only destroy the editor if the save was successful. */
- } else {
- ESourceRegistry *registry;
-
- registry = e_mail_signature_editor_get_registry (editor);
-
- /* Only make sure that the 'source-changed' is called,
- * thus the preview of the signature is updated on save.
- * It is not called when only signature body is changed
- * (and ESource properties are left unchanged). */
- g_signal_emit_by_name (registry, "source-changed", source);
-
- gtk_widget_destroy (GTK_WIDGET (editor));
- }
+ mail_signature_editor_commit_ready_cb, NULL);
}
static GtkActionEntry entries[] = {
diff --git a/src/plugins/external-editor/external-editor.c b/src/plugins/external-editor/external-editor.c
index cdc2671a52..518bd6d2d1 100644
--- a/src/plugins/external-editor/external-editor.c
+++ b/src/plugins/external-editor/external-editor.c
@@ -198,9 +198,23 @@ enable_composer_idle (gpointer user_data)
struct ExternalEditorData {
EMsgComposer *composer;
gchar *content;
+ GDestroyNotify content_destroy_notify;
guint cursor_position, cursor_offset;
};
+static void
+external_editor_data_free (gpointer ptr)
+{
+ struct ExternalEditorData *eed = ptr;
+
+ if (eed) {
+ g_clear_object (&eed->composer);
+ if (eed->content_destroy_notify)
+ eed->content_destroy_notify (eed->content);
+ g_slice_free (struct ExternalEditorData, eed);
+ }
+}
+
/* needed because the new thread needs to call g_idle_add () */
static gboolean
update_composer_text (gpointer user_data)
@@ -221,9 +235,7 @@ update_composer_text (gpointer user_data)
e_content_editor_set_changed (cnt_editor, TRUE);
- g_clear_object (&eed->composer);
- g_free (eed->content);
- g_slice_free (struct ExternalEditorData, eed);
+ external_editor_data_free (eed);
return FALSE;
}
@@ -384,7 +396,8 @@ external_editor_thread (gpointer user_data)
eed2 = g_slice_new0 (struct ExternalEditorData);
eed2->composer = g_object_ref (eed->composer);
- eed2->content = camel_text_to_html (buf, CAMEL_MIME_FILTER_TOHTML_PRE, 0);
+ eed2->content = camel_text_to_html (buf, CAMEL_MIME_FILTER_TOHTML_PRE, 0);
+ eed2->content_destroy_notify = g_free;
g_idle_add ((GSourceFunc) update_composer_text, eed2);
@@ -402,9 +415,7 @@ finished:
external_editor_running = FALSE;
g_mutex_unlock (&external_editor_running_lock);
- g_clear_object (&eed->composer);
- g_free (eed->content);
- g_slice_free (struct ExternalEditorData, eed);
+ external_editor_data_free (eed);
return NULL;
}
@@ -430,7 +441,7 @@ launch_editor_content_ready_cb (GObject *source_object,
if (!content_hash)
g_warning ("%s: Faild to get content: %s", G_STRFUNC, error ? error->message : "Unknown
error");
- eed->content = content_hash ? e_content_editor_util_get_content_data (content_hash,
E_CONTENT_EDITOR_GET_TO_SEND_PLAIN) : NULL;
+ eed->content = content_hash ? e_content_editor_util_steal_content_data (content_hash,
E_CONTENT_EDITOR_GET_TO_SEND_PLAIN, &(eed->content_destroy_notify)) : NULL;
editor_thread = g_thread_new (NULL, external_editor_thread, eed);
g_thread_unref (editor_thread);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]