[balsa/wip/gtk4: 247/351] mailbox local: Declare it derivable



commit 9f0f7d7e424cf3dd29c251e17f8900ae07d86e6f
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Mar 25 14:48:53 2018 -0400

    mailbox local: Declare it derivable
    
    Use G_DECLARE_DERIVABLE_TYPE for LibBalsaMailboxLocal and make it
    private. No additional getters or setters needed.

 libbalsa/mailbox_local.c |  261 +++++++++++++++++++++++++---------------------
 libbalsa/mailbox_local.h |   43 +-------
 2 files changed, 148 insertions(+), 156 deletions(-)
---
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 194e59a..624cfad 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -36,11 +36,23 @@
 #include "misc.h"
 #include <glib/gi18n.h>
 
+typedef struct _LibBalsaMailboxLocalPrivate LibBalsaMailboxLocalPrivate;
+struct _LibBalsaMailboxLocalPrivate {
+    guint sync_id;  /* id of the idle mailbox sync job  */
+    guint sync_time; /* estimated time of sync job execution (in seconds),
+                      * used to  throttle frequency of large mbox syncing. */
+    guint sync_cnt; /* we do not want to rely on the time of last sync since
+                     * some sync can be faster than others. Instead, we
+                     * average the syncing time for mailbox. */
+    guint thread_id;    /* id of the idle mailbox thread job */
+    guint save_tree_id; /* id of the idle mailbox save-tree job */
+    guint load_messages_id; /* id of the idle load-messages job */
+    guint msgno;            /* where to start loading messages */
+    GPtrArray *threading_info;
+    LibBalsaMailboxLocalPool message_pool[LBML_POOL_SIZE];
+    guint pool_seqno;
+};
 
-static LibBalsaMailboxClass *parent_class = NULL;
-
-static void libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass *klass);
-static void libbalsa_mailbox_local_init(LibBalsaMailboxLocal * mailbox);
 static void libbalsa_mailbox_local_dispose(GObject * object);
 static void libbalsa_mailbox_local_finalize(GObject * object);
 
@@ -111,32 +123,8 @@ static void libbalsa_mailbox_local_test_can_reach(LibBalsaMailbox          * mai
 /* LibBalsaMailboxLocal class method: */
 static void lbm_local_real_remove_files(LibBalsaMailboxLocal * local);
 
-GType
-libbalsa_mailbox_local_get_type(void)
-{
-    static GType mailbox_type = 0;
-
-    if (!mailbox_type) {
-       static const GTypeInfo mailbox_info = {
-           sizeof(LibBalsaMailboxLocalClass),
-            NULL,               /* base_init */
-            NULL,               /* base_finalize */
-           (GClassInitFunc) libbalsa_mailbox_local_class_init,
-            NULL,               /* class_finalize */
-            NULL,               /* class_data */
-           sizeof(LibBalsaMailboxLocal),
-            0,                  /* n_preallocs */
-           (GInstanceInitFunc) libbalsa_mailbox_local_init
-       };
-
-       mailbox_type =
-           g_type_register_static(LIBBALSA_TYPE_MAILBOX,
-                                  "LibBalsaMailboxLocal",
-                                   &mailbox_info, 0);
-    }
-
-    return mailbox_type;
-}
+G_DEFINE_TYPE_WITH_PRIVATE(LibBalsaMailboxLocal, libbalsa_mailbox_local,
+                           LIBBALSA_TYPE_MAILBOX)
 
 static void
 libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
@@ -147,8 +135,6 @@ libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
     object_class = G_OBJECT_CLASS(klass);
     libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
 
-    parent_class = g_type_class_peek_parent(klass);
-
     object_class->dispose  = libbalsa_mailbox_local_dispose;
     object_class->finalize = libbalsa_mailbox_local_finalize;
 
@@ -194,13 +180,16 @@ libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
 }
 
 static void
-libbalsa_mailbox_local_init(LibBalsaMailboxLocal * mailbox)
+libbalsa_mailbox_local_init(LibBalsaMailboxLocal * local)
 {
-    mailbox->sync_id   = 0;
-    mailbox->sync_time = 0;
-    mailbox->sync_cnt  = 0;
-    mailbox->thread_id = 0;
-    mailbox->save_tree_id = 0;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
+
+    priv->sync_id   = 0;
+    priv->sync_time = 0;
+    priv->sync_cnt  = 0;
+    priv->thread_id = 0;
+    priv->save_tree_id = 0;
 }
 
 LibBalsaMailbox *
@@ -302,14 +291,16 @@ static void
 lbml_add_message_to_pool(LibBalsaMailboxLocal * local,
                          LibBalsaMessage * message)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMailboxLocalPool *item, *oldest;
 
-    ++local->pool_seqno;
+    ++priv->pool_seqno;
 
-    for (item = oldest = &local->message_pool[0];
-         item < &local->message_pool[LBML_POOL_SIZE]; item++) {
+    for (item = oldest = &priv->message_pool[0];
+         item < &priv->message_pool[LBML_POOL_SIZE]; item++) {
         if (item->message == message) {
-            item->pool_seqno = local->pool_seqno;
+            item->pool_seqno = priv->pool_seqno;
             return;
         }
         if (item->pool_seqno < oldest->pool_seqno)
@@ -317,7 +308,7 @@ lbml_add_message_to_pool(LibBalsaMailboxLocal * local,
     }
 
     g_set_object(&oldest->message, message);
-    oldest->pool_seqno = local->pool_seqno;
+    oldest->pool_seqno = priv->pool_seqno;
 }
 
 static void
@@ -405,36 +396,36 @@ lbm_local_free_info(LibBalsaMailboxLocalInfo * info)
 static void
 libbalsa_mailbox_local_dispose(GObject * object)
 {
-    LibBalsaMailboxLocal *ml;
+    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) object;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(object));
 
-    ml = LIBBALSA_MAILBOX_LOCAL(object);
+    libbalsa_clear_source_id(&priv->sync_id);
+    libbalsa_clear_source_id(&priv->thread_id);
+    libbalsa_clear_source_id(&priv->save_tree_id);
+    libbalsa_clear_source_id(&priv->load_messages_id);
 
-    libbalsa_clear_source_id(&ml->sync_id);
-    libbalsa_clear_source_id(&ml->thread_id);
-    libbalsa_clear_source_id(&ml->save_tree_id);
-    libbalsa_clear_source_id(&ml->load_messages_id);
-
-    G_OBJECT_CLASS(parent_class)->dispose(object);
+    G_OBJECT_CLASS(libbalsa_mailbox_local_parent_class)->dispose(object);
 }
 
 static void
 libbalsa_mailbox_local_finalize(GObject * object)
 {
-    LibBalsaMailboxLocal *ml;
+    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) object;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(object));
 
-    ml = LIBBALSA_MAILBOX_LOCAL(object);
-
-    if (ml->threading_info != NULL) {
-       /* The memory owned by ml->threading_info was freed on closing,
+    if (priv->threading_info != NULL) {
+       /* The memory owned by priv->threading_info was freed on closing,
         * so we free only the array itself. */
-       g_ptr_array_free(ml->threading_info, TRUE);
+       g_ptr_array_free(priv->threading_info, TRUE);
     }
 
-    G_OBJECT_CLASS(parent_class)->finalize(object);
+    G_OBJECT_CLASS(libbalsa_mailbox_local_parent_class)->finalize(object);
 }
 
 
@@ -458,8 +449,8 @@ libbalsa_mailbox_local_save_config(LibBalsaMailbox * mailbox,
 
     libbalsa_conf_set_string("Path", libbalsa_mailbox_local_get_path(local));
 
-    if (LIBBALSA_MAILBOX_CLASS(parent_class)->save_config)
-       LIBBALSA_MAILBOX_CLASS(parent_class)->save_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->save_config)
+       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->save_config(mailbox, prefix);
 }
 
 static void
@@ -478,8 +469,8 @@ libbalsa_mailbox_local_load_config(LibBalsaMailbox * mailbox,
     g_free(url);
     g_free(path);
 
-    if (LIBBALSA_MAILBOX_CLASS(parent_class)->load_config)
-       LIBBALSA_MAILBOX_CLASS(parent_class)->load_config(mailbox, prefix);
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->load_config)
+       LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->load_config(mailbox, prefix);
 }
 
 /*
@@ -735,13 +726,15 @@ lbm_local_restore_tree(LibBalsaMailboxLocal * local, guint * total)
 static void
 lbm_local_save_tree_real(LibBalsaMailboxLocal * local)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(local);
 
     libbalsa_lock_mailbox(mailbox);
 
     if (MAILBOX_OPEN(mailbox) && libbalsa_mailbox_get_msg_tree_changed(mailbox))
         lbm_local_save_tree(local);
-    local->save_tree_id = 0;
+    priv->save_tree_id = 0;
 
     libbalsa_unlock_mailbox(mailbox);
 }
@@ -757,9 +750,12 @@ lbm_local_save_tree_idle(LibBalsaMailboxLocal * local)
 static void
 lbm_local_queue_save_tree(LibBalsaMailboxLocal * local)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
+
     libbalsa_lock_mailbox((LibBalsaMailbox *) local);
-    if (!local->save_tree_id)
-        local->save_tree_id =
+    if (!priv->save_tree_id)
+        priv->save_tree_id =
             g_idle_add((GSourceFunc) lbm_local_save_tree_idle, local);
     libbalsa_unlock_mailbox((LibBalsaMailbox *) local);
 }
@@ -773,49 +769,51 @@ libbalsa_mailbox_local_close_mailbox(LibBalsaMailbox * mailbox,
                                      gboolean expunge)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     guint i;
     LibBalsaMailboxLocalPool *item;
 
-    libbalsa_clear_source_id(&local->sync_id);
+    libbalsa_clear_source_id(&priv->sync_id);
 
     /* Restore the persistent view before saving the tree. */
     libbalsa_mailbox_set_view_filter(mailbox,
                                      libbalsa_mailbox_get_view_filter(mailbox, TRUE),
                                      TRUE);
 
-    if (local->thread_id) {
+    if (priv->thread_id) {
         /* Rethread immediately. */
         LibBalsaMailboxThreadingType cur_type =
             libbalsa_mailbox_get_threading_type(mailbox);
 
-        libbalsa_clear_source_id(&local->thread_id);
+        libbalsa_clear_source_id(&priv->thread_id);
         libbalsa_mailbox_set_threading(mailbox, cur_type);
     }
 
         /* Save immediately. */
-    libbalsa_clear_source_id(&local->save_tree_id);
+    libbalsa_clear_source_id(&priv->save_tree_id);
     lbm_local_save_tree(local);
 
-    if (local->threading_info) {
-       /* Free the memory owned by local->threading_info, but neither
+    if (priv->threading_info) {
+       /* Free the memory owned by priv->threading_info, but neither
         * free nor truncate the array. */
-        for (i = local->threading_info->len; i > 0;) {
+        for (i = priv->threading_info->len; i > 0;) {
             gpointer *entry =
-                &g_ptr_array_index(local->threading_info, --i);
+                &g_ptr_array_index(priv->threading_info, --i);
             lbm_local_free_info(*entry);
             *entry = NULL;
         }
     }
 
-    for (item = &local->message_pool[0];
-         item < &local->message_pool[LBML_POOL_SIZE]; item++) {
+    for (item = &priv->message_pool[0];
+         item < &priv->message_pool[LBML_POOL_SIZE]; item++) {
         g_clear_object(&item->message);
         item->pool_seqno = 0;
     }
-    local->pool_seqno = 0;
+    priv->pool_seqno = 0;
 
-    if (LIBBALSA_MAILBOX_CLASS(parent_class)->close_mailbox)
-        LIBBALSA_MAILBOX_CLASS(parent_class)->close_mailbox(mailbox,
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->close_mailbox)
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->close_mailbox(mailbox,
                                                             expunge);
 }
 
@@ -850,14 +848,16 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
                    LibBalsaCondition *cond)
 {
     LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMessage *message = NULL;
     gboolean match = FALSE;
     gboolean is_refed = FALSE;
     LibBalsaMailboxIndexEntry *entry =
         libbalsa_mailbox_get_index_entry(mailbox, msgno);
     LibBalsaMailboxLocalInfo *info =
-        msgno <= local->threading_info->len ?
-        g_ptr_array_index(local->threading_info, msgno - 1) : NULL;
+        msgno <= priv->threading_info->len ?
+        g_ptr_array_index(priv->threading_info, msgno - 1) : NULL;
 
     /* We may be able to match the msgno from info cached in entry or
      * info; if those are NULL, we'll need to fetch the message, so we
@@ -868,7 +868,7 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
             return FALSE;
         libbalsa_mailbox_local_cache_message(local, msgno, message);
         entry = libbalsa_mailbox_get_index_entry(mailbox, msgno);
-        info  = g_ptr_array_index(local->threading_info, msgno - 1);
+        info  = g_ptr_array_index(priv->threading_info, msgno - 1);
     }
 
     if (entry->idle_pending)
@@ -1025,6 +1025,8 @@ libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
                                      guint msgno,
                                      LibBalsaMessage * message)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     gpointer *entry;
     LibBalsaMailboxLocalInfo *info;
 
@@ -1034,12 +1036,12 @@ libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
     libbalsa_mailbox_cache_message(LIBBALSA_MAILBOX(local), msgno,
                                    message);
 
-    if (!local->threading_info)
+    if (!priv->threading_info)
         return;
 
-    while (local->threading_info->len < msgno)
-        g_ptr_array_add(local->threading_info, NULL);
-    entry = &g_ptr_array_index(local->threading_info, msgno - 1);
+    while (priv->threading_info->len < msgno)
+        g_ptr_array_add(priv->threading_info, NULL);
+    entry = &g_ptr_array_index(priv->threading_info, msgno - 1);
 
     if (*entry)
         return;
@@ -1060,18 +1062,19 @@ libbalsa_mailbox_local_cache_message(LibBalsaMailboxLocal * local,
 static gboolean
 lbml_load_messages_idle_cb(LibBalsaMailbox * mailbox)
 {
+    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     guint msgno;
     guint new_messages;
-    LibBalsaMailboxLocal *local;
     guint lastno;
     GNode *lastn;
     LibBalsaMailboxLocalMessageInfo *(*get_info) (LibBalsaMailboxLocal *, guint);
 
-    local = (LibBalsaMailboxLocal *) mailbox;
     g_assert(LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local) != NULL);
 
     libbalsa_lock_mailbox(mailbox);
-    local->load_messages_id = 0;
+    priv->load_messages_id = 0;
 
     if (!libbalsa_mailbox_get_msg_tree(mailbox)) {
        /* Mailbox is closed, or no view has been created. */
@@ -1080,7 +1083,7 @@ lbml_load_messages_idle_cb(LibBalsaMailbox * mailbox)
     }
 
     lastno = libbalsa_mailbox_total_messages(mailbox);
-    msgno = local->msgno;
+    msgno = priv->msgno;
     new_messages = lastno - msgno;
     lastn = g_node_last_child(libbalsa_mailbox_get_msg_tree(mailbox));
     get_info = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->get_info;
@@ -1109,15 +1112,16 @@ void
 libbalsa_mailbox_local_load_messages(LibBalsaMailbox *mailbox,
                                      guint msgno)
 {
-    LibBalsaMailboxLocal *local;
+    LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
 
     g_return_if_fail(LIBBALSA_IS_MAILBOX_LOCAL(mailbox));
 
-    local = (LibBalsaMailboxLocal *) mailbox;
     libbalsa_lock_mailbox(mailbox);
-    if (!local->load_messages_id) {
-        local->msgno = msgno;
-        local->load_messages_id =
+    if (!priv->load_messages_id) {
+        priv->msgno = msgno;
+        priv->load_messages_id =
             g_idle_add((GSourceFunc) lbml_load_messages_idle_cb, mailbox);
     }
     libbalsa_unlock_mailbox(mailbox);
@@ -1134,8 +1138,11 @@ static void lbml_threading_simple(LibBalsaMailbox * mailbox,
 void 
 libbalsa_mailbox_local_set_threading_info(LibBalsaMailboxLocal * local)
 {
-    if (!local->threading_info)
-        local->threading_info = g_ptr_array_new();
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
+
+    if (!priv->threading_info)
+        priv->threading_info = g_ptr_array_new();
 }
 
 static void
@@ -1231,13 +1238,15 @@ libbalsa_mailbox_local_msgno_removed(LibBalsaMailbox * mailbox,
                                     guint msgno)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
 
     /* local might not have a threading-info array, and even if it does,
      * it might not be populated; we check both. */
-    if (local->threading_info && msgno <= local->threading_info->len) {
-       lbm_local_free_info(g_ptr_array_index(local->threading_info,
+    if (priv->threading_info && msgno <= priv->threading_info->len) {
+       lbm_local_free_info(g_ptr_array_index(priv->threading_info,
                                              msgno - 1));
-       g_ptr_array_remove_index(local->threading_info, msgno - 1);
+       g_ptr_array_remove_index(priv->threading_info, msgno - 1);
     }
 
     libbalsa_mailbox_msgno_removed(mailbox, msgno);
@@ -1291,10 +1300,12 @@ lbm_local_update_view_filter(LibBalsaMailbox * mailbox,
 static gboolean
 lbm_local_prepare_msgno(LibBalsaMailboxLocal * local, guint msgno)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMessage *message;
 
-    if (msgno <= local->threading_info->len
-        && g_ptr_array_index(local->threading_info, msgno - 1))
+    if (msgno <= priv->threading_info->len
+        && g_ptr_array_index(priv->threading_info, msgno - 1))
         return FALSE;
 
     message =
@@ -1312,6 +1323,8 @@ lbm_local_prepare_msgno(LibBalsaMailboxLocal * local, guint msgno)
 static gboolean
 lbm_local_thread_idle(LibBalsaMailboxLocal * local)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(local);
 
     libbalsa_lock_mailbox(mailbox);
@@ -1322,7 +1335,7 @@ lbm_local_thread_idle(LibBalsaMailboxLocal * local)
 
         libbalsa_mailbox_set_threading(mailbox, cur_type);
     }
-    local->thread_id = 0;
+    priv->thread_id = 0;
 
     libbalsa_unlock_mailbox(mailbox);
     g_object_unref(local);
@@ -1337,6 +1350,8 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
                                          guint start)
 {
     LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     guint msgno;
     gboolean need_thread = FALSE;
     gchar *text;
@@ -1368,13 +1383,13 @@ libbalsa_mailbox_local_prepare_threading(LibBalsaMailbox * mailbox,
 
     libbalsa_progress_set_text(&progress, NULL, 0);
 
-    if (retval && need_thread && !local->thread_id) {
+    if (retval && need_thread && !priv->thread_id) {
         if (libbalsa_mailbox_get_threading_type(mailbox) !=
             LB_MAILBOX_THREADING_FLAT
             || libbalsa_mailbox_get_sort_field(mailbox) !=
             LB_MAILBOX_SORT_NO) {
             g_object_ref(local);
-            local->thread_id =
+            priv->thread_id =
                 g_idle_add((GSourceFunc) lbm_local_thread_idle, local);
         }
     }
@@ -1542,14 +1557,16 @@ lbml_threading_jwz(LibBalsaMailbox * mailbox)
 static LibBalsaMailboxLocalInfo *
 lbml_get_info(GNode * node, ThreadingInfo * ti)
 {
+    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(ti->mailbox);
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     guint msgno = GPOINTER_TO_UINT(node->data);
     LibBalsaMailboxLocalInfo *info;
-    LibBalsaMailboxLocal *local = LIBBALSA_MAILBOX_LOCAL(ti->mailbox);
 
-    if (msgno == 0 || msgno > local->threading_info->len)
+    if (msgno == 0 || msgno > priv->threading_info->len)
         return NULL;
 
-    info = g_ptr_array_index(local->threading_info, msgno - 1);
+    info = g_ptr_array_index(priv->threading_info, msgno - 1);
 
     return info;
 }
@@ -2157,20 +2174,22 @@ libbalsa_mailbox_local_get_message_stream(LibBalsaMailbox * mailbox,
 static void
 lbm_local_sync_real(LibBalsaMailboxLocal * local)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     LibBalsaMailbox *mailbox = (LibBalsaMailbox*)local;
     time_t tstart;
 
     time(&tstart);
     libbalsa_lock_mailbox(mailbox);
-    if (local->sync_id &&                       /* request still pending */
+    if (priv->sync_id &&                       /* request still pending */
         MAILBOX_OPEN(mailbox) &&                   /* mailbox still open */
         !libbalsa_mailbox_sync_storage(mailbox, FALSE))   /* cannot sync */
        libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                             _("Failed to sync mailbox ā€œ%sā€"),
                             libbalsa_mailbox_get_name(mailbox));
-    local->sync_id = 0;
-    local->sync_time += time(NULL)-tstart;
-    local->sync_cnt++;
+    priv->sync_id = 0;
+    priv->sync_time += time(NULL)-tstart;
+    priv->sync_cnt++;
     libbalsa_unlock_mailbox(mailbox);
     g_object_unref(local);
 }
@@ -2190,6 +2209,8 @@ lbm_local_sync_idle(LibBalsaMailboxLocal * local)
 static void
 lbm_local_sync_queue(LibBalsaMailboxLocal * local)
 {
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     guint schedule_delay;
 
     /* The optimal behavior here would be to keep rescheduling
@@ -2198,15 +2219,15 @@ lbm_local_sync_queue(LibBalsaMailboxLocal * local)
     * another queue request is filed but it is too late for removal of
     * the sync thread. And we get two sync threads executing one after
     * another, etc. So it is better to do sync bit too often... */
-    if (local->sync_id) 
+    if (priv->sync_id) 
         return;
     g_object_ref(local);
     /* queue sync job so that the delay is at least five times longer
      * than the syncing time. Otherwise large mailbox owners will be
      * annnoyed. */
     schedule_delay =
-        local->sync_cnt ? (local->sync_time * 5000) / local->sync_cnt : 0;
-    local->sync_id = g_timeout_add_full(G_PRIORITY_LOW, schedule_delay,
+        priv->sync_cnt ? (priv->sync_time * 5000) / priv->sync_cnt : 0;
+    priv->sync_id = g_timeout_add_full(G_PRIORITY_LOW, schedule_delay,
                                         (GSourceFunc)lbm_local_sync_idle,
                                         local, NULL);
 }
@@ -2214,9 +2235,9 @@ lbm_local_sync_queue(LibBalsaMailboxLocal * local)
 static void
 lbm_local_sort(LibBalsaMailbox * mailbox, GArray *sort_array)
 {
-    g_assert(LIBBALSA_MAILBOX_CLASS(parent_class) != NULL);
+    g_assert(LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class) != NULL);
 
-    LIBBALSA_MAILBOX_CLASS(parent_class)->sort(mailbox, sort_array);
+    LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_local_parent_class)->sort(mailbox, sort_array);
     lbm_local_queue_save_tree(LIBBALSA_MAILBOX_LOCAL(mailbox));
 }
 
@@ -2337,11 +2358,13 @@ static GArray *
 libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox * mailbox)
 {
     LibBalsaMailboxLocal *local = (LibBalsaMailboxLocal *) mailbox;
+    LibBalsaMailboxLocalPrivate *priv =
+        libbalsa_mailbox_local_get_instance_private(local);
     GHashTable *table;
     guint i;
     GArray *msgnos;
 
-    if (!local->threading_info)
+    if (!priv->threading_info)
         return NULL;
 
     /* We need all the message-ids. */
@@ -2351,7 +2374,7 @@ libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox * mailbox)
     table = g_hash_table_new(g_str_hash, g_str_equal);
     msgnos = g_array_new(FALSE, FALSE, sizeof(guint));
 
-    for (i = 0; i < local->threading_info->len; i++) {
+    for (i = 0; i < priv->threading_info->len; i++) {
         LibBalsaMailboxLocalInfo *info;
         gpointer tmp;
         guint master, msgno = i + 1;
@@ -2360,7 +2383,7 @@ libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox * mailbox)
             (mailbox, msgno, LIBBALSA_MESSAGE_FLAG_DELETED, 0))
             continue;
 
-        info = g_ptr_array_index(local->threading_info, i);
+        info = g_ptr_array_index(priv->threading_info, i);
         if (!info || !info->message_id)
             continue;
 
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index 2caad75..a411e15 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -23,26 +23,13 @@
 
 #include "libbalsa.h"
 
-#define LIBBALSA_TYPE_MAILBOX_LOCAL \
-    (libbalsa_mailbox_local_get_type())
-#define LIBBALSA_MAILBOX_LOCAL(obj) \
-    (G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBBALSA_TYPE_MAILBOX_LOCAL, \
-                                 LibBalsaMailboxLocal))
-#define LIBBALSA_MAILBOX_LOCAL_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_CAST ((klass), LIBBALSA_TYPE_MAILBOX_LOCAL, \
-                              LibBalsaMailboxLocalClass))
-#define LIBBALSA_IS_MAILBOX_LOCAL(obj) \
-    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBBALSA_TYPE_MAILBOX_LOCAL))
-#define LIBBALSA_IS_MAILBOX_LOCAL_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_TYPE ((klass), LIBBALSA_TYPE_MAILBOX_LOCAL))
-#define LIBBALSA_MAILBOX_LOCAL_GET_CLASS(mailbox) \
-    (G_TYPE_INSTANCE_GET_CLASS ((mailbox), LIBBALSA_TYPE_MAILBOX_LOCAL, \
-                               LibBalsaMailboxLocalClass))
+#define LIBBALSA_TYPE_MAILBOX_LOCAL libbalsa_mailbox_local_get_type()
 
-GType libbalsa_mailbox_local_get_type(void);
-
-typedef struct _LibBalsaMailboxLocal LibBalsaMailboxLocal;
-typedef struct _LibBalsaMailboxLocalClass LibBalsaMailboxLocalClass;
+G_DECLARE_DERIVABLE_TYPE(LibBalsaMailboxLocal,
+                         libbalsa_mailbox_local,
+                         LIBBALSA,
+                         MAILBOX_LOCAL,
+                         LibBalsaMailbox)
 
 struct _LibBalsaMailboxLocalPool {
     LibBalsaMessage * message;
@@ -58,24 +45,6 @@ struct _LibBalsaMailboxLocalMessageInfo {
 };
 typedef struct _LibBalsaMailboxLocalMessageInfo LibBalsaMailboxLocalMessageInfo;
 
-struct _LibBalsaMailboxLocal {
-    LibBalsaMailbox mailbox;
-
-    guint sync_id;  /* id of the idle mailbox sync job  */
-    guint sync_time; /* estimated time of sync job execution (in seconds),
-                      * used to  throttle frequency of large mbox syncing. */
-    guint sync_cnt; /* we do not want to rely on the time of last sync since
-                     * some sync can be faster than others. Instead, we
-                     * average the syncing time for mailbox. */
-    guint thread_id;    /* id of the idle mailbox thread job */
-    guint save_tree_id; /* id of the idle mailbox save-tree job */
-    guint load_messages_id; /* id of the idle load-messages job */
-    guint msgno;            /* where to start loading messages */
-    GPtrArray *threading_info;
-    LibBalsaMailboxLocalPool message_pool[LBML_POOL_SIZE];
-    guint pool_seqno;
-};
-
 typedef gboolean LibBalsaMailboxLocalAddMessageFunc(LibBalsaMailboxLocal *
                                                     local,
                                                     GMimeStream * stream,


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