[balsa/wip/gtk4: 248/351] mailbox maildir: Declare it final



commit b42dd3aa6f8dc227543c13dcd2d023c49b34632b
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Mar 25 18:52:33 2018 -0400

    mailbox maildir: Declare it final
    
    Use G_DECLARE_FINAL_TYPE for LibBalsaMailboxMaildir and make it
    private.

 libbalsa/mailbox_maildir.c |   62 +++++++++++++++----------------------------
 libbalsa/mailbox_maildir.h |   35 ++++--------------------
 2 files changed, 28 insertions(+), 69 deletions(-)
---
diff --git a/libbalsa/mailbox_maildir.c b/libbalsa/mailbox_maildir.c
index 97f7524..5de5471 100644
--- a/libbalsa/mailbox_maildir.c
+++ b/libbalsa/mailbox_maildir.c
@@ -54,12 +54,6 @@ struct message_info {
     ((((orig_flags) ^ (flags)) & LIBBALSA_MESSAGE_FLAGS_REAL) != 0)
 #define FLAGS_CHANGED(msg_info) \
     FLAGS_REALLY_DIFFER(msg_info->orig_flags, msg_info->local_info.flags)
-  
-
-static LibBalsaMailboxLocalClass *parent_class = NULL;
-
-static void libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass *klass);
-static void libbalsa_mailbox_maildir_init(LibBalsaMailboxMaildir * mailbox);
 
 /* Object class method */
 static void libbalsa_mailbox_maildir_finalize(GObject * object);
@@ -107,32 +101,23 @@ static void free_message_info(struct message_info *msg_info);
 static int libbalsa_mailbox_maildir_open_temp (const gchar *dest_path,
                                          char **name_used);
 
-GType
-libbalsa_mailbox_maildir_get_type(void)
-{
-    static GType mailbox_type = 0;
-
-    if (!mailbox_type) {
-       static const GTypeInfo mailbox_info = {
-           sizeof(LibBalsaMailboxMaildirClass),
-            NULL,               /* base_init */
-            NULL,               /* base_finalize */
-           (GClassInitFunc) libbalsa_mailbox_maildir_class_init,
-            NULL,               /* class_finalize */
-            NULL,               /* class_data */
-           sizeof(LibBalsaMailboxMaildir),
-            0,                  /* n_preallocs */
-           (GInstanceInitFunc) libbalsa_mailbox_maildir_init
-       };
-
-       mailbox_type =
-           g_type_register_static(LIBBALSA_TYPE_MAILBOX_LOCAL,
-                                  "LibBalsaMailboxMaildir",
-                                   &mailbox_info, 0);
-    }
+struct _LibBalsaMailboxMaildir {
+    LibBalsaMailboxLocal parent;
 
-    return mailbox_type;
-}
+    GHashTable* messages_info;
+    GPtrArray* msgno_2_msg_info;
+    gchar *curdir;
+    gchar *newdir;
+    gchar *tmpdir;
+};
+
+struct _LibBalsaMailboxMaildirClass {
+    LibBalsaMailboxLocalClass klass;
+};
+
+G_DEFINE_TYPE(LibBalsaMailboxMaildir,
+              libbalsa_mailbox_maildir,
+              LIBBALSA_TYPE_MAILBOX_LOCAL)
 
 static void
 libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass * klass)
@@ -145,8 +130,6 @@ libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass * klass)
     libbalsa_mailbox_class = LIBBALSA_MAILBOX_CLASS(klass);
     libbalsa_mailbox_local_class = LIBBALSA_MAILBOX_LOCAL_CLASS(klass);
 
-    parent_class = g_type_class_peek_parent(klass);
-
     object_class->finalize = libbalsa_mailbox_maildir_finalize;
 
     libbalsa_mailbox_class->load_config =
@@ -286,8 +269,7 @@ libbalsa_mailbox_maildir_finalize(GObject * object)
     g_free(mdir->tmpdir);
     mdir->tmpdir = NULL;
 
-    if (G_OBJECT_CLASS(parent_class)->finalize)
-       G_OBJECT_CLASS(parent_class)->finalize(object);
+    G_OBJECT_CLASS(libbalsa_mailbox_maildir_parent_class)->finalize(object);
 }
 
 static void
@@ -301,7 +283,7 @@ libbalsa_mailbox_maildir_load_config(LibBalsaMailbox * mailbox,
     lbm_maildir_set_subdirs(mdir, path);
     g_free(path);
 
-    LIBBALSA_MAILBOX_CLASS(parent_class)->load_config(mailbox, prefix);
+    LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->load_config(mailbox, prefix);
 }
 
 static GMimeStream *
@@ -343,7 +325,7 @@ lbm_maildir_remove_files(LibBalsaMailboxLocal *mailbox)
                             _("Could not remove %s:\n%s"),
                             path, strerror(errno));
     }
-    LIBBALSA_MAILBOX_LOCAL_CLASS(parent_class)->remove_files(mailbox);
+    LIBBALSA_MAILBOX_LOCAL_CLASS(libbalsa_mailbox_maildir_parent_class)->remove_files(mailbox);
 }
 
 static LibBalsaMessageFlag parse_filename(const gchar *subdir,
@@ -633,8 +615,8 @@ libbalsa_mailbox_maildir_close_mailbox(LibBalsaMailbox * mailbox,
     if (mdir->msgno_2_msg_info->len != len)
         libbalsa_mailbox_changed(mailbox);
 
-    if (LIBBALSA_MAILBOX_CLASS(parent_class)->close_mailbox)
-        LIBBALSA_MAILBOX_CLASS(parent_class)->close_mailbox(mailbox,
+    if (LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->close_mailbox)
+        LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->close_mailbox(mailbox,
                                                             expunge);
 
     /* Now it's safe to free the message info. */
@@ -852,7 +834,7 @@ libbalsa_mailbox_maildir_fetch_message_structure(LibBalsaMailbox * mailbox,
                                                    msg_info->filename);
     }
 
-    return LIBBALSA_MAILBOX_CLASS(parent_class)->
+    return LIBBALSA_MAILBOX_CLASS(libbalsa_mailbox_maildir_parent_class)->
         fetch_message_structure(mailbox, message, flags);
 }
 
diff --git a/libbalsa/mailbox_maildir.h b/libbalsa/mailbox_maildir.h
index 675cf9c..ef6ad42 100644
--- a/libbalsa/mailbox_maildir.h
+++ b/libbalsa/mailbox_maildir.h
@@ -21,37 +21,14 @@
 #ifndef __LIBBALSA_MAILBOX_MAILDIR_H__
 #define __LIBBALSA_MAILBOX_MAILDIR_H__
 
-#define LIBBALSA_TYPE_MAILBOX_MAILDIR \
-    (libbalsa_mailbox_maildir_get_type())
-#define LIBBALSA_MAILBOX_MAILDIR(obj) \
-    (G_TYPE_CHECK_INSTANCE_CAST ((obj), LIBBALSA_TYPE_MAILBOX_MAILDIR, \
-                                 LibBalsaMailboxMaildir))
-#define LIBBALSA_MAILBOX_MAILDIR_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_CAST ((klass), LIBBALSA_TYPE_MAILBOX_MAILDIR, \
-                              LibBalsaMailboxMaildirClass))
-#define LIBBALSA_IS_MAILBOX_MAILDIR(obj) \
-    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIBBALSA_TYPE_MAILBOX_MAILDIR))
-#define LIBBALSA_IS_MAILBOX_MAILDIR_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_TYPE ((klass), LIBBALSA_TYPE_MAILBOX_MAILDIR))
+#define LIBBALSA_TYPE_MAILBOX_MAILDIR libbalsa_mailbox_maildir_get_type()
 
-typedef struct _LibBalsaMailboxMaildir LibBalsaMailboxMaildir;
-typedef struct _LibBalsaMailboxMaildirClass LibBalsaMailboxMaildirClass;
+G_DECLARE_FINAL_TYPE(LibBalsaMailboxMaildir,
+                     libbalsa_mailbox_maildir,
+                     LIBBALSA,
+                     MAILBOX_MAILDIR,
+                     LibBalsaMailboxLocal)
 
-struct _LibBalsaMailboxMaildir {
-    LibBalsaMailboxLocal parent;
-
-    GHashTable* messages_info;
-    GPtrArray* msgno_2_msg_info;
-    gchar *curdir;
-    gchar *newdir;
-    gchar *tmpdir;
-};
-
-struct _LibBalsaMailboxMaildirClass {
-    LibBalsaMailboxLocalClass klass;
-};
-
-GType libbalsa_mailbox_maildir_get_type(void);
 LibBalsaMailbox *libbalsa_mailbox_maildir_new(const gchar * path,
                                               gboolean      create);
 


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