[gimp/gtk3-port] libgimpmodule: move all GimpModuleDB members to private



commit 36b4fa31d0bf99b61c80862cdba9132ade9a32e0
Author: Michael Natterer <mitch gimp org>
Date:   Sat May 5 20:41:02 2018 +0200

    libgimpmodule: move all GimpModuleDB members to private

 app/dialogs/module-dialog.c  |    3 +-
 libgimpmodule/gimpmoduledb.c |  116 +++++++++++++++++++++++++++++-------------
 libgimpmodule/gimpmoduledb.h |    9 +---
 3 files changed, 84 insertions(+), 44 deletions(-)
---
diff --git a/app/dialogs/module-dialog.c b/app/dialogs/module-dialog.c
index 4d5ae5b..b121bee 100644
--- a/app/dialogs/module-dialog.c
+++ b/app/dialogs/module-dialog.c
@@ -176,7 +176,8 @@ module_dialog_new (Gimp *gimp)
 
   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
 
-  g_list_foreach (gimp->module_db->modules, make_list_item, private);
+  g_list_foreach (gimp_module_db_get_modules (gimp->module_db),
+                  make_list_item, private);
 
   rend = gtk_cell_renderer_toggle_new ();
 
diff --git a/libgimpmodule/gimpmoduledb.c b/libgimpmodule/gimpmoduledb.c
index 62c2a54..b1e3b4e 100644
--- a/libgimpmodule/gimpmoduledb.c
+++ b/libgimpmodule/gimpmoduledb.c
@@ -49,10 +49,20 @@ enum
   LAST_SIGNAL
 };
 
-
 #define DUMP_DB FALSE
 
 
+struct _GimpModuleDBPrivate
+{
+  GList    *modules;
+
+  gchar    *load_inhibit;
+  gboolean  verbose;
+};
+
+#define GET_PRIVATE(obj) (((GimpModuleDB *) (obj))->priv)
+
+
 static void         gimp_module_db_finalize            (GObject      *object);
 
 static void         gimp_module_db_load_directory      (GimpModuleDB *db,
@@ -120,41 +130,43 @@ gimp_module_db_class_init (GimpModuleDBClass *klass)
 
   klass->add             = NULL;
   klass->remove          = NULL;
+
+  g_type_class_add_private (klass, sizeof (GimpModuleDBPrivate));
 }
 
 static void
 gimp_module_db_init (GimpModuleDB *db)
 {
-  db->modules      = NULL;
-  db->load_inhibit = NULL;
-  db->verbose      = FALSE;
+  db->priv = G_TYPE_INSTANCE_GET_PRIVATE (db,
+                                          GIMP_TYPE_MODULE_DB,
+                                          GimpModuleDBPrivate);
+
+  db->priv->modules      = NULL;
+  db->priv->load_inhibit = NULL;
+  db->priv->verbose      = FALSE;
 }
 
 static void
 gimp_module_db_finalize (GObject *object)
 {
-  GimpModuleDB *db = GIMP_MODULE_DB (object);
+  GimpModuleDBPrivate *priv = GET_PRIVATE (object);
 
-  if (db->modules)
+  if (priv->modules)
     {
       GList *list;
 
-      for (list = db->modules; list; list = g_list_next (list))
+      for (list = priv->modules; list; list = g_list_next (list))
         {
           g_signal_handlers_disconnect_by_func (list->data,
                                                 gimp_module_db_module_modified,
-                                                db);
+                                                object);
         }
 
-      g_list_free (db->modules);
-      db->modules = NULL;
+      g_list_free (priv->modules);
+      priv->modules = NULL;
     }
 
-  if (db->load_inhibit)
-    {
-      g_free (db->load_inhibit);
-      db->load_inhibit = NULL;
-    }
+  g_clear_pointer (&priv->load_inhibit, g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -175,11 +187,30 @@ gimp_module_db_new (gboolean verbose)
 
   db = g_object_new (GIMP_TYPE_MODULE_DB, NULL);
 
-  db->verbose = verbose ? TRUE : FALSE;
+  db->priv->verbose = verbose ? TRUE : FALSE;
 
   return db;
 }
 
+/**
+ * gimp_module_db_get_modules:
+ * @db: A #GimpModuleDB.
+ *
+ * Returns a #GList of the modules kept by @db. The list must not be
+ * modified or freed.
+ *
+ * Return value: a #GList of #GimpModule instances.
+ *
+ * Since: 3.0
+ **/
+GList *
+gimp_module_db_get_modules (GimpModuleDB *db)
+{
+  g_return_val_if_fail (GIMP_IS_MODULE_DB (db), NULL);
+
+  return GET_PRIVATE (db)->modules;
+}
+
 static gboolean
 is_in_inhibit_list (const gchar *filename,
                     const gchar *inhibit_list)
@@ -229,16 +260,19 @@ void
 gimp_module_db_set_load_inhibit (GimpModuleDB *db,
                                  const gchar  *load_inhibit)
 {
-  GList *list;
+  GimpModuleDBPrivate *priv;
+  GList               *list;
 
   g_return_if_fail (GIMP_IS_MODULE_DB (db));
 
-  if (db->load_inhibit)
-    g_free (db->load_inhibit);
+  priv = GET_PRIVATE (db);
+
+  if (priv->load_inhibit)
+    g_free (priv->load_inhibit);
 
-  db->load_inhibit = g_strdup (load_inhibit);
+  priv->load_inhibit = g_strdup (load_inhibit);
 
-  for (list = db->modules; list; list = g_list_next (list))
+  for (list = priv->modules; list; list = g_list_next (list))
     {
       GimpModule *module = list->data;
 
@@ -262,7 +296,7 @@ gimp_module_db_get_load_inhibit (GimpModuleDB *db)
 {
   g_return_val_if_fail (GIMP_IS_MODULE_DB (db), NULL);
 
-  return db->load_inhibit;
+  return GET_PRIVATE (db)->load_inhibit;
 }
 
 /**
@@ -279,9 +313,13 @@ void
 gimp_module_db_load (GimpModuleDB *db,
                      const gchar  *module_path)
 {
+  GimpModuleDBPrivate *priv;
+
   g_return_if_fail (GIMP_IS_MODULE_DB (db));
   g_return_if_fail (module_path != NULL);
 
+  priv = GET_PRIVATE (db);
+
   if (g_module_supported ())
     {
       GList *path;
@@ -298,7 +336,7 @@ gimp_module_db_load (GimpModuleDB *db,
     }
 
   if (DUMP_DB)
-    g_list_foreach (db->modules, gimp_module_db_module_dump_func, NULL);
+    g_list_foreach (priv->modules, gimp_module_db_module_dump_func, NULL);
 }
 
 /**
@@ -318,13 +356,16 @@ void
 gimp_module_db_refresh (GimpModuleDB *db,
                         const gchar  *module_path)
 {
-  GList *kill_list = NULL;
+  GimpModuleDBPrivate *priv;
+  GList               *kill_list = NULL;
 
   g_return_if_fail (GIMP_IS_MODULE_DB (db));
   g_return_if_fail (module_path != NULL);
 
+  priv = GET_PRIVATE (db);
+
   /* remove modules we don't have on disk anymore */
-  g_list_foreach (db->modules,
+  g_list_foreach (priv->modules,
                   gimp_module_db_module_on_disk_func,
                   &kill_list);
   g_list_foreach (kill_list,
@@ -378,9 +419,10 @@ static void
 gimp_module_db_load_module (GimpModuleDB *db,
                             GFile        *file)
 {
-  GimpModule *module;
-  gchar      *path;
-  gboolean    load_inhibit;
+  GimpModuleDBPrivate *priv = GET_PRIVATE (db);
+  GimpModule          *module;
+  gchar               *path;
+  gboolean             load_inhibit;
 
   if (! gimp_file_has_extension (file, "." G_MODULE_SUFFIX))
     return;
@@ -394,11 +436,11 @@ gimp_module_db_load_module (GimpModuleDB *db,
       return;
     }
 
-  load_inhibit = is_in_inhibit_list (path, db->load_inhibit);
+  load_inhibit = is_in_inhibit_list (path, priv->load_inhibit);
 
   module = gimp_module_new (path,
                             load_inhibit,
-                            db->verbose);
+                            priv->verbose);
 
   g_free (path);
 
@@ -406,7 +448,7 @@ gimp_module_db_load_module (GimpModuleDB *db,
                     G_CALLBACK (gimp_module_db_module_modified),
                     db);
 
-  db->modules = g_list_append (db->modules, module);
+  priv->modules = g_list_append (priv->modules, module);
 
   g_signal_emit (db, db_signals[ADD], 0, module);
 }
@@ -415,9 +457,10 @@ static GimpModule *
 gimp_module_db_module_find_by_path (GimpModuleDB *db,
                                     const char   *fullpath)
 {
-  GList *list;
+  GimpModuleDBPrivate *priv = GET_PRIVATE (db);
+  GList               *list;
 
-  for (list = db->modules; list; list = g_list_next (list))
+  for (list = priv->modules; list; list = g_list_next (list))
     {
       GimpModule *module = list->data;
 
@@ -488,14 +531,15 @@ static void
 gimp_module_db_module_remove_func (gpointer data,
                                    gpointer user_data)
 {
-  GimpModule   *module = data;
-  GimpModuleDB *db     = user_data;
+  GimpModule          *module = data;
+  GimpModuleDB        *db     = user_data;
+  GimpModuleDBPrivate *priv   = GET_PRIVATE (db);
 
   g_signal_handlers_disconnect_by_func (module,
                                         gimp_module_db_module_modified,
                                         db);
 
-  db->modules = g_list_remove (db->modules, module);
+  priv->modules = g_list_remove (priv->modules, module);
 
   g_signal_emit (db, db_signals[REMOVE], 0, module);
 }
diff --git a/libgimpmodule/gimpmoduledb.h b/libgimpmodule/gimpmoduledb.h
index 959427f..5654363 100644
--- a/libgimpmodule/gimpmoduledb.h
+++ b/libgimpmodule/gimpmoduledb.h
@@ -42,13 +42,6 @@ struct _GimpModuleDB
   GObject              parent_instance;
 
   GimpModuleDBPrivate *priv;
-
-  /* FIXME MOVE TO PRIVATE */
-  /*< private >*/
-  GList    *modules;
-
-  gchar    *load_inhibit;
-  gboolean  verbose;
 };
 
 struct _GimpModuleDBClass
@@ -77,6 +70,8 @@ struct _GimpModuleDBClass
 GType          gimp_module_db_get_type         (void) G_GNUC_CONST;
 GimpModuleDB * gimp_module_db_new              (gboolean      verbose);
 
+GList        * gimp_module_db_get_modules      (GimpModuleDB *db);
+
 void           gimp_module_db_set_load_inhibit (GimpModuleDB *db,
                                                 const gchar  *load_inhibit);
 const gchar  * gimp_module_db_get_load_inhibit (GimpModuleDB *db);


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