[evolution] composer-autosave: Miscellaneous cleanups.



commit 2a69370d81d5adf74450ef19b36d9e7e400ff4d5
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Nov 25 12:40:32 2013 -0500

    composer-autosave: Miscellaneous cleanups.

 modules/composer-autosave/Makefile.am              |   41 ++++---
 modules/composer-autosave/e-autosave-utils.c       |   47 ++++----
 modules/composer-autosave/e-composer-autosave.c    |  114 ++++++++-----------
 modules/composer-autosave/e-composer-autosave.h    |   63 +++++++++++
 modules/composer-autosave/e-composer-registry.c    |  104 ++++++++----------
 modules/composer-autosave/e-composer-registry.h    |   65 +++++++++++
 .../evolution-composer-autosave.c                  |   11 +--
 7 files changed, 275 insertions(+), 170 deletions(-)
---
diff --git a/modules/composer-autosave/Makefile.am b/modules/composer-autosave/Makefile.am
index b8f3057..8bd99b5 100644
--- a/modules/composer-autosave/Makefile.am
+++ b/modules/composer-autosave/Makefile.am
@@ -1,27 +1,34 @@
+NULL =
+
 module_LTLIBRARIES = module-composer-autosave.la
 
 module_composer_autosave_la_CPPFLAGS = \
-       $(AM_CPPFLAGS)                                          \
-       -I$(top_srcdir)                                         \
-       -DG_LOG_DOMAIN=\"evolution-composer-autosave\"          \
-       $(EVOLUTION_DATA_SERVER_CFLAGS)                         \
-       $(GNOME_PLATFORM_CFLAGS)                                \
-       $(GTKHTML_CFLAGS)
+       $(AM_CPPFLAGS) \
+       -I$(top_srcdir) \
+       -DG_LOG_DOMAIN=\"evolution-composer-autosave\" \
+       $(EVOLUTION_DATA_SERVER_CFLAGS) \
+       $(GNOME_PLATFORM_CFLAGS) \
+       $(GTKHTML_CFLAGS) \
+       $(NULL)
 
 module_composer_autosave_la_SOURCES = \
-       evolution-composer-autosave.c                           \
-       e-autosave-utils.c                                      \
-       e-autosave-utils.h                                      \
-       e-composer-autosave.c                                   \
-       e-composer-registry.c
+       evolution-composer-autosave.c \
+       e-autosave-utils.c \
+       e-autosave-utils.h \
+       e-composer-autosave.c \
+       e-composer-autosave.h \
+       e-composer-registry.c \
+       e-composer-registry.h \
+       $(NULL)
 
 module_composer_autosave_la_LIBADD = \
-       $(top_builddir)/shell/libevolution-shell.la             \
-       $(top_builddir)/composer/libevolution-mail-composer.la  \
-       $(top_builddir)/e-util/libevolution-util.la             \
-       $(EVOLUTION_DATA_SERVER_LIBS)                           \
-       $(GNOME_PLATFORM_LIBS)                                  \
-       $(GTKHTML_LIBS)
+       $(top_builddir)/shell/libevolution-shell.la \
+       $(top_builddir)/composer/libevolution-mail-composer.la \
+       $(top_builddir)/e-util/libevolution-util.la \
+       $(EVOLUTION_DATA_SERVER_LIBS) \
+       $(GNOME_PLATFORM_LIBS) \
+       $(GTKHTML_LIBS) \
+       $(NULL)
 
 module_composer_autosave_la_LDFLAGS = \
        -module -avoid-version $(NO_UNDEFINED)
diff --git a/modules/composer-autosave/e-autosave-utils.c b/modules/composer-autosave/e-autosave-utils.c
index 6971ab8..dff074f 100644
--- a/modules/composer-autosave/e-autosave-utils.c
+++ b/modules/composer-autosave/e-autosave-utils.c
@@ -128,16 +128,16 @@ load_snapshot_loaded_cb (GFile *snapshot_file,
        CamelStream *camel_stream;
        gchar *contents = NULL;
        gsize length;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
        context = g_simple_async_result_get_op_res_gpointer (simple);
 
        g_file_load_contents_finish (
-               snapshot_file, result, &contents, &length, NULL, &error);
+               snapshot_file, result, &contents, &length, NULL, &local_error);
 
-       if (error != NULL) {
+       if (local_error != NULL) {
                g_warn_if_fail (contents == NULL);
-               g_simple_async_result_take_error (simple, error);
+               g_simple_async_result_take_error (simple, local_error);
                g_simple_async_result_complete (simple);
                return;
        }
@@ -148,12 +148,12 @@ load_snapshot_loaded_cb (GFile *snapshot_file,
        message = camel_mime_message_new ();
        camel_stream = camel_stream_mem_new_with_buffer (contents, length);
        camel_data_wrapper_construct_from_stream_sync (
-               CAMEL_DATA_WRAPPER (message), camel_stream, NULL, &error);
+               CAMEL_DATA_WRAPPER (message), camel_stream, NULL, &local_error);
        g_object_unref (camel_stream);
        g_free (contents);
 
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
+       if (local_error != NULL) {
+               g_simple_async_result_take_error (simple, local_error);
                g_simple_async_result_complete (simple);
                g_object_unref (message);
                return;
@@ -186,12 +186,12 @@ save_snapshot_splice_cb (GOutputStream *output_stream,
                          GAsyncResult *result,
                          GSimpleAsyncResult *simple)
 {
-       GError *error = NULL;
+       GError *local_error = NULL;
 
-       g_output_stream_splice_finish (output_stream, result, &error);
+       g_output_stream_splice_finish (output_stream, result, &local_error);
 
-       if (error != NULL)
-               g_simple_async_result_take_error (simple, error);
+       if (local_error != NULL)
+               g_simple_async_result_take_error (simple, local_error);
 
        g_simple_async_result_complete (simple);
        g_object_unref (simple);
@@ -207,16 +207,16 @@ save_snapshot_get_message_cb (EMsgComposer *composer,
        GInputStream *input_stream;
        CamelStream *camel_stream;
        GByteArray *buffer;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
        context = g_simple_async_result_get_op_res_gpointer (simple);
 
        message = e_msg_composer_get_message_draft_finish (
-               composer, result, &error);
+               composer, result, &local_error);
 
-       if (error != NULL) {
+       if (local_error != NULL) {
                g_warn_if_fail (message == NULL);
-               g_simple_async_result_take_error (simple, error);
+               g_simple_async_result_take_error (simple, local_error);
                g_simple_async_result_complete (simple);
                g_object_unref (simple);
                return;
@@ -266,17 +266,18 @@ save_snapshot_replace_cb (GFile *snapshot_file,
        GObject *object;
        SaveContext *context;
        GFileOutputStream *output_stream;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
        context = g_simple_async_result_get_op_res_gpointer (simple);
 
        /* Output stream might be NULL, so don't use cast macro. */
-       output_stream = g_file_replace_finish (snapshot_file, result, &error);
+       output_stream = g_file_replace_finish (
+               snapshot_file, result, &local_error);
        context->output_stream = (GOutputStream *) output_stream;
 
-       if (error != NULL) {
+       if (local_error != NULL) {
                g_warn_if_fail (output_stream == NULL);
-               g_simple_async_result_take_error (simple, error);
+               g_simple_async_result_take_error (simple, local_error);
                g_simple_async_result_complete (simple);
                g_object_unref (simple);
                return;
@@ -453,7 +454,7 @@ e_composer_save_snapshot (EMsgComposer *composer,
        GSimpleAsyncResult *simple;
        SaveContext *context;
        GFile *snapshot_file;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
        g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 
@@ -474,11 +475,11 @@ e_composer_save_snapshot (EMsgComposer *composer,
        snapshot_file = e_composer_get_snapshot_file (composer);
 
        if (!G_IS_FILE (snapshot_file))
-               snapshot_file = create_snapshot_file (composer, &error);
+               snapshot_file = create_snapshot_file (composer, &local_error);
 
-       if (error != NULL) {
+       if (local_error != NULL) {
                g_warn_if_fail (snapshot_file == NULL);
-               g_simple_async_result_take_error (simple, error);
+               g_simple_async_result_take_error (simple, local_error);
                g_simple_async_result_complete (simple);
                g_object_unref (simple);
                return;
diff --git a/modules/composer-autosave/e-composer-autosave.c b/modules/composer-autosave/e-composer-autosave.c
index 97c0a3c..2d3518f 100644
--- a/modules/composer-autosave/e-composer-autosave.c
+++ b/modules/composer-autosave/e-composer-autosave.c
@@ -16,31 +16,19 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <libebackend/libebackend.h>
+#include "e-composer-autosave.h"
 
 #include <composer/e-msg-composer.h>
 
 #include "e-autosave-utils.h"
 
-/* Standard GObject macros */
-#define E_TYPE_COMPOSER_AUTOSAVE \
-       (e_composer_autosave_get_type ())
-#define E_COMPOSER_AUTOSAVE(obj) \
-       (G_TYPE_CHECK_INSTANCE_CAST \
-       ((obj), E_TYPE_COMPOSER_AUTOSAVE, EComposerAutosave))
+#define E_COMPOSER_AUTOSAVE_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), E_TYPE_COMPOSER_AUTOSAVE, EComposerAutosavePrivate))
 
 #define AUTOSAVE_INTERVAL      60 /* seconds */
 
-typedef struct _EComposerAutosave EComposerAutosave;
-typedef struct _EComposerAutosaveClass EComposerAutosaveClass;
-
-struct _EComposerAutosave {
-       EExtension parent;
-
+struct _EComposerAutosavePrivate {
        GCancellable *cancellable;
        guint timeout_id;
 
@@ -52,35 +40,32 @@ struct _EComposerAutosave {
        gboolean error_shown;
 };
 
-struct _EComposerAutosaveClass {
-       EExtensionClass parent_class;
-};
-
-/* Forward Declarations */
-GType e_composer_autosave_get_type (void);
-void e_composer_autosave_type_register (GTypeModule *type_module);
-
 G_DEFINE_DYNAMIC_TYPE (
        EComposerAutosave,
        e_composer_autosave,
        E_TYPE_EXTENSION)
 
 static void
-composer_autosave_finished_cb (EMsgComposer *composer,
+composer_autosave_finished_cb (GObject *source_object,
                                GAsyncResult *result,
-                               EComposerAutosave *autosave)
+                               gpointer user_data)
 {
+       EMsgComposer *composer;
+       EComposerAutosave *autosave;
        GFile *snapshot_file;
-       GError *error = NULL;
+       GError *local_error = NULL;
+
+       composer = E_MSG_COMPOSER (source_object);
+       autosave = E_COMPOSER_AUTOSAVE (user_data);
 
        snapshot_file = e_composer_get_snapshot_file (composer);
-       e_composer_save_snapshot_finish (composer, result, &error);
+       e_composer_save_snapshot_finish (composer, result, &local_error);
 
        /* Return silently if we were cancelled. */
-       if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
-               g_error_free (error);
+       if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+               g_error_free (local_error);
 
-       else if (error != NULL) {
+       else if (local_error != NULL) {
                gchar *basename;
 
                if (G_IS_FILE (snapshot_file))
@@ -89,18 +74,18 @@ composer_autosave_finished_cb (EMsgComposer *composer,
                        basename = g_strdup (" ");
 
                /* Only show one error dialog at a time. */
-               if (!autosave->error_shown) {
-                       autosave->error_shown = TRUE;
+               if (!autosave->priv->error_shown) {
+                       autosave->priv->error_shown = TRUE;
                        e_alert_run_dialog_for_args (
                                GTK_WINDOW (composer),
                                "mail-composer:no-autosave",
-                               basename, error->message, NULL);
-                       autosave->error_shown = FALSE;
+                               basename, local_error->message, NULL);
+                       autosave->priv->error_shown = FALSE;
                } else
-                       g_warning ("%s: %s", basename, error->message);
+                       g_warning ("%s: %s", basename, local_error->message);
 
                g_free (basename);
-               g_error_free (error);
+               g_error_free (local_error);
        }
 
        g_object_unref (autosave);
@@ -117,24 +102,23 @@ composer_autosave_timeout_cb (gpointer user_data)
 
        /* User may have reverted or explicitly saved
         * the changes since the timeout was scheduled. */
-       if (autosave->changed) {
+       if (autosave->priv->changed) {
 
                /* Cancel the previous snapshot if it's still in
                 * progress and start a new snapshot operation. */
-               g_cancellable_cancel (autosave->cancellable);
-               g_object_unref (autosave->cancellable);
-               autosave->cancellable = g_cancellable_new ();
+               g_cancellable_cancel (autosave->priv->cancellable);
+               g_object_unref (autosave->priv->cancellable);
+               autosave->priv->cancellable = g_cancellable_new ();
 
                e_composer_save_snapshot (
                        E_MSG_COMPOSER (extensible),
-                       autosave->cancellable,
-                       (GAsyncReadyCallback)
+                       autosave->priv->cancellable,
                        composer_autosave_finished_cb,
                        g_object_ref (autosave));
        }
 
-       autosave->timeout_id = 0;
-       autosave->changed = FALSE;
+       autosave->priv->timeout_id = 0;
+       autosave->priv->changed = FALSE;
 
        return FALSE;
 }
@@ -148,10 +132,10 @@ composer_autosave_changed_cb (EComposerAutosave *autosave)
        extensible = e_extension_get_extensible (E_EXTENSION (autosave));
 
        editor = GTKHTML_EDITOR (extensible);
-       autosave->changed = gtkhtml_editor_get_changed (editor);
+       autosave->priv->changed = gtkhtml_editor_get_changed (editor);
 
-       if (autosave->changed && autosave->timeout_id == 0) {
-               autosave->timeout_id = e_named_timeout_add_seconds (
+       if (autosave->priv->changed && autosave->priv->timeout_id == 0) {
+               autosave->priv->timeout_id = e_named_timeout_add_seconds (
                        AUTOSAVE_INTERVAL,
                        composer_autosave_timeout_cb, autosave);
        }
@@ -160,37 +144,32 @@ composer_autosave_changed_cb (EComposerAutosave *autosave)
 static void
 composer_autosave_dispose (GObject *object)
 {
-       EComposerAutosave *autosave;
-       GObjectClass *parent_class;
+       EComposerAutosavePrivate *priv;
 
-       autosave = E_COMPOSER_AUTOSAVE (object);
+       priv = E_COMPOSER_AUTOSAVE_GET_PRIVATE (object);
 
        /* Cancel any snapshots in progress. */
-       if (autosave->cancellable != NULL) {
-               g_cancellable_cancel (autosave->cancellable);
-               g_object_unref (autosave->cancellable);
-               autosave->cancellable = NULL;
-       }
+       g_cancellable_cancel (priv->cancellable);
 
-       if (autosave->timeout_id > 0) {
-               g_source_remove (autosave->timeout_id);
-               autosave->timeout_id = 0;
+       if (priv->timeout_id > 0) {
+               g_source_remove (priv->timeout_id);
+               priv->timeout_id = 0;
        }
 
+       g_clear_object (&priv->cancellable);
+
        /* Chain up to parent's dispose() method. */
-       parent_class = G_OBJECT_CLASS (e_composer_autosave_parent_class);
-       parent_class->dispose (object);
+       G_OBJECT_CLASS (e_composer_autosave_parent_class)->dispose (object);
 }
 
 static void
 composer_autosave_constructed (GObject *object)
 {
        EExtensible *extensible;
-       GObjectClass *parent_class;
 
        /* Chain up to parent's constructed() method. */
-       parent_class = G_OBJECT_CLASS (e_composer_autosave_parent_class);
-       parent_class->constructed (object);
+       G_OBJECT_CLASS (e_composer_autosave_parent_class)->
+               constructed (object);
 
        extensible = e_extension_get_extensible (E_EXTENSION (object));
 
@@ -205,6 +184,8 @@ e_composer_autosave_class_init (EComposerAutosaveClass *class)
        GObjectClass *object_class;
        EExtensionClass *extension_class;
 
+       g_type_class_add_private (class, sizeof (EComposerAutosavePrivate));
+
        object_class = G_OBJECT_CLASS (class);
        object_class->dispose = composer_autosave_dispose;
        object_class->constructed = composer_autosave_constructed;
@@ -221,7 +202,8 @@ e_composer_autosave_class_finalize (EComposerAutosaveClass *class)
 static void
 e_composer_autosave_init (EComposerAutosave *autosave)
 {
-       autosave->cancellable = g_cancellable_new ();
+       autosave->priv = E_COMPOSER_AUTOSAVE_GET_PRIVATE (autosave);
+       autosave->priv->cancellable = g_cancellable_new ();
 }
 
 void
diff --git a/modules/composer-autosave/e-composer-autosave.h b/modules/composer-autosave/e-composer-autosave.h
new file mode 100644
index 0000000..2c5d7e7
--- /dev/null
+++ b/modules/composer-autosave/e-composer-autosave.h
@@ -0,0 +1,63 @@
+/*
+ * e-composer-autosave.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_COMPOSER_AUTOSAVE_H
+#define E_COMPOSER_AUTOSAVE_H
+
+#include <libebackend/libebackend.h>
+
+/* Standard GObject macros */
+#define E_TYPE_COMPOSER_AUTOSAVE \
+       (e_composer_autosave_get_type ())
+#define E_COMPOSER_AUTOSAVE(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), E_TYPE_COMPOSER_AUTOSAVE, EComposerAutosave))
+#define E_COMPOSER_AUTOSAVE_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), E_TYPE_COMPOSER_AUTOSAVE, EComposerAutosaveClass))
+#define E_IS_COMPOSER_AUTOSAVE(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), E_TYPE_COMPOSER_AUTOSAVE))
+#define E_IS_COMPOSER_AUTOSAVE_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), E_TYPE_COMPOSER_AUTOSAVE))
+#define E_COMPOSER_AUTOSAVE_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), E_TYPE_COMPOSER_AUTOSAVE, EComposerAutosaveClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EComposerAutosave EComposerAutosave;
+typedef struct _EComposerAutosaveClass EComposerAutosaveClass;
+typedef struct _EComposerAutosavePrivate EComposerAutosavePrivate;
+
+struct _EComposerAutosave {
+       EExtension parent;
+       EComposerAutosavePrivate *priv;
+};
+
+struct _EComposerAutosaveClass {
+       EExtensionClass parent_class;
+};
+
+GType          e_composer_autosave_get_type    (void) G_GNUC_CONST;
+void           e_composer_autosave_type_register
+                                               (GTypeModule *type_module);
+
+#endif /* E_COMPOSER_AUTOSAVE_H */
+
diff --git a/modules/composer-autosave/e-composer-registry.c b/modules/composer-autosave/e-composer-registry.c
index bd4bb93..b8bb3c5 100644
--- a/modules/composer-autosave/e-composer-registry.c
+++ b/modules/composer-autosave/e-composer-registry.c
@@ -16,10 +16,9 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "e-composer-registry.h"
 
+#include <config.h>
 #include <glib/gstdio.h>
 #include <libebackend/libebackend.h>
 
@@ -29,52 +28,41 @@
 
 #include "e-autosave-utils.h"
 
-/* Standard GObject macros */
-#define E_TYPE_COMPOSER_REGISTRY \
-       (e_composer_registry_get_type ())
-#define E_COMPOSER_REGISTRY(obj) \
-       (G_TYPE_CHECK_INSTANCE_CAST \
-       ((obj), E_TYPE_COMPOSER_REGISTRY, EComposerRegistry))
-
-typedef struct _EComposerRegistry EComposerRegistry;
-typedef struct _EComposerRegistryClass EComposerRegistryClass;
+#define E_COMPOSER_REGISTRY_GET_PRIVATE(obj) \
+       (G_TYPE_INSTANCE_GET_PRIVATE \
+       ((obj), E_TYPE_COMPOSER_REGISTRY, EComposerRegistryPrivate))
 
-struct _EComposerRegistry {
-       EExtension parent;
+struct _EComposerRegistryPrivate {
        GQueue composers;
        gboolean orphans_restored;
 };
 
-struct _EComposerRegistryClass {
-       EExtensionClass parent_class;
-};
-
-/* Forward Declarations */
-GType e_composer_registry_get_type (void);
-void e_composer_registry_type_register (GTypeModule *type_module);
-
 G_DEFINE_DYNAMIC_TYPE (
        EComposerRegistry,
        e_composer_registry,
        E_TYPE_EXTENSION)
 
 static void
-composer_registry_recovered_cb (EShell *shell,
+composer_registry_recovered_cb (GObject *source_object,
                                 GAsyncResult *result,
-                                EComposerRegistry *registry)
+                                gpointer user_data)
 {
        EMsgComposer *composer;
-       GError *error = NULL;
+       EComposerRegistry *registry;
+       GError *local_error = NULL;
+
+       registry = E_COMPOSER_REGISTRY (user_data);
 
-       composer = e_composer_load_snapshot_finish (shell, result, &error);
+       composer = e_composer_load_snapshot_finish (
+               E_SHELL (source_object), result, &local_error);
 
-       if (error != NULL) {
+       if (local_error != NULL) {
                /* FIXME Show an alert dialog here explaining
                 *       why we could not recover the message.
                 *       Will need a new error XML entry. */
                g_warn_if_fail (composer == NULL);
-               g_warning ("%s", error->message);
-               g_error_free (error);
+               g_warning ("%s", local_error->message);
+               g_error_free (local_error);
                goto exit;
        }
 
@@ -86,27 +74,26 @@ exit:
        g_object_unref (registry);
 }
 
-static gboolean
-composer_registry_map_event_cb (GtkWindow *parent,
-                                GdkEvent *event,
-                                EComposerRegistry *registry)
+static void
+composer_registry_restore_orphans (EComposerRegistry *registry,
+                                   GtkWindow *parent)
 {
        EExtensible *extensible;
        GList *orphans;
        gint response;
-       GError *error = NULL;
+       GError *local_error = NULL;
 
        extensible = e_extension_get_extensible (E_EXTENSION (registry));
 
        /* Look for orphaned auto-save files. */
        orphans = e_composer_find_orphans (
-               &registry->composers, &error);
+               &registry->priv->composers, &local_error);
        if (orphans == NULL) {
-               if (error != NULL) {
-                       g_warning ("%s", error->message);
-                       g_error_free (error);
+               if (local_error != NULL) {
+                       g_warning ("%s", local_error->message);
+                       g_error_free (local_error);
                }
-               goto exit;
+               return;
        }
 
        /* Ask if the user wants to recover the orphaned files. */
@@ -120,7 +107,7 @@ composer_registry_map_event_cb (GtkWindow *parent,
                if (response == GTK_RESPONSE_YES)
                        e_composer_load_snapshot (
                                E_SHELL (extensible),
-                               file, NULL, (GAsyncReadyCallback)
+                               file, NULL,
                                composer_registry_recovered_cb,
                                g_object_ref (registry));
                else
@@ -130,9 +117,15 @@ composer_registry_map_event_cb (GtkWindow *parent,
 
                orphans = g_list_delete_link (orphans, orphans);
        }
+}
 
-exit:
-       registry->orphans_restored = TRUE;
+static gboolean
+composer_registry_map_event_cb (GtkWindow *parent,
+                                GdkEvent *event,
+                                EComposerRegistry *registry)
+{
+       composer_registry_restore_orphans (registry, parent);
+       registry->priv->orphans_restored = TRUE;
 
        return FALSE;
 }
@@ -142,7 +135,7 @@ composer_registry_notify_cb (EComposerRegistry *registry,
                              GObject *where_the_object_was)
 {
        /* Remove the finalized composer from the registry. */
-       g_queue_remove (&registry->composers, where_the_object_was);
+       g_queue_remove (&registry->priv->composers, where_the_object_was);
 
        g_object_unref (registry);
 }
@@ -154,15 +147,15 @@ composer_registry_window_added_cb (GtkApplication *application,
 {
        /* Offer to restore any orphaned auto-save files from the
         * previous session once the first EShellWindow is mapped. */
-       if (E_IS_SHELL_WINDOW (window) && !registry->orphans_restored)
+       if (E_IS_SHELL_WINDOW (window) && !registry->priv->orphans_restored) {
                g_signal_connect (
                        window, "map-event",
                        G_CALLBACK (composer_registry_map_event_cb),
                        registry);
 
        /* Track the new composer window. */
-       else if (E_IS_MSG_COMPOSER (window)) {
-               g_queue_push_tail (&registry->composers, window);
+       } else if (E_IS_MSG_COMPOSER (window)) {
+               g_queue_push_tail (&registry->priv->composers, window);
                g_object_weak_ref (
                        G_OBJECT (window), (GWeakNotify)
                        composer_registry_notify_cb,
@@ -173,28 +166,25 @@ composer_registry_window_added_cb (GtkApplication *application,
 static void
 composer_registry_finalize (GObject *object)
 {
-       GObjectClass *parent_class;
-       EComposerRegistry *registry;
+       EComposerRegistryPrivate *priv;
 
-       registry = E_COMPOSER_REGISTRY (object);
+       priv = E_COMPOSER_REGISTRY_GET_PRIVATE (object);
 
        /* All composers should have been finalized by now. */
-       g_warn_if_fail (g_queue_is_empty (&registry->composers));
+       g_warn_if_fail (g_queue_is_empty (&priv->composers));
 
        /* Chain up to parent's finalize() method. */
-       parent_class = G_OBJECT_CLASS (e_composer_registry_parent_class);
-       parent_class->finalize (object);
+       G_OBJECT_CLASS (e_composer_registry_parent_class)->finalize (object);
 }
 
 static void
 composer_registry_constructed (GObject *object)
 {
        EExtensible *extensible;
-       GObjectClass *parent_class;
 
        /* Chain up to parent's constructed() method. */
-       parent_class = G_OBJECT_CLASS (e_composer_registry_parent_class);
-       parent_class->constructed (object);
+       G_OBJECT_CLASS (e_composer_registry_parent_class)->
+               constructed (object);
 
        extensible = e_extension_get_extensible (E_EXTENSION (object));
 
@@ -211,6 +201,8 @@ e_composer_registry_class_init (EComposerRegistryClass *class)
        GObjectClass *object_class;
        EExtensionClass *extension_class;
 
+       g_type_class_add_private (class, sizeof (EComposerRegistryPrivate));
+
        object_class = G_OBJECT_CLASS (class);
        object_class->finalize = composer_registry_finalize;
        object_class->constructed = composer_registry_constructed;
@@ -227,7 +219,7 @@ e_composer_registry_class_finalize (EComposerRegistryClass *class)
 static void
 e_composer_registry_init (EComposerRegistry *registry)
 {
-       g_queue_init (&registry->composers);
+       registry->priv = E_COMPOSER_REGISTRY_GET_PRIVATE (registry);
 }
 
 void
diff --git a/modules/composer-autosave/e-composer-registry.h b/modules/composer-autosave/e-composer-registry.h
new file mode 100644
index 0000000..c082d38
--- /dev/null
+++ b/modules/composer-autosave/e-composer-registry.h
@@ -0,0 +1,65 @@
+/*
+ * e-composer-registry.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_COMPOSER_REGISTRY_H
+#define E_COMPOSER_REGISTRY_H
+
+#include <libebackend/libebackend.h>
+
+/* Standard GObject macros */
+#define E_TYPE_COMPOSER_REGISTRY \
+       (e_composer_registry_get_type ())
+#define E_COMPOSER_REGISTRY(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST \
+       ((obj), E_TYPE_COMPOSER_REGISTRY, EComposerRegistry))
+#define E_COMPOSER_REGISTRY_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_CAST \
+       ((cls), E_TYPE_COMPOSER_REGISTRY, EComposerRegistryClass))
+#define E_IS_COMPOSER_REGISTRY(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE \
+       ((obj), E_TYPE_COMPOSER_REGISTRY))
+#define E_IS_COMPOSER_REGISTRY_CLASS(cls) \
+       (G_TYPE_CHECK_CLASS_TYPE \
+       ((cls), E_TYPE_COMPOSER_REGISTRY))
+#define E_COMPOSER_REGISTRY_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS \
+       ((obj), E_TYPE_COMPOSER_REGISTRY, EComposerRegistryClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EComposerRegistry EComposerRegistry;
+typedef struct _EComposerRegistryClass EComposerRegistryClass;
+typedef struct _EComposerRegistryPrivate EComposerRegistryPrivate;
+
+struct _EComposerRegistry {
+       EExtension parent;
+       EComposerRegistryPrivate *priv;
+};
+
+struct _EComposerRegistryClass {
+       EExtensionClass parent_class;
+};
+
+GType          e_composer_registry_get_type    (void) G_GNUC_CONST;
+void           e_composer_registry_type_register
+                                               (GTypeModule *type_module);
+
+G_END_DECLS
+
+#endif /* E_COMPOSER_REGISTRY_H */
+
diff --git a/modules/composer-autosave/evolution-composer-autosave.c 
b/modules/composer-autosave/evolution-composer-autosave.c
index 323fed7..97fb68c 100644
--- a/modules/composer-autosave/evolution-composer-autosave.c
+++ b/modules/composer-autosave/evolution-composer-autosave.c
@@ -16,21 +16,16 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include <gmodule.h>
 #include <glib-object.h>
 
+#include "e-composer-autosave.h"
+#include "e-composer-registry.h"
+
 /* Module Entry Points */
 void e_module_load (GTypeModule *type_module);
 void e_module_unload (GTypeModule *type_module);
 
-/* Forward Declarations */
-void e_composer_autosave_type_register (GTypeModule *type_module);
-void e_composer_registry_type_register (GTypeModule *type_module);
-
 G_MODULE_EXPORT void
 e_module_load (GTypeModule *type_module)
 {


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