Hi,

It has already been concluded that we want to get rid of a few data resources for GIMP 2.8 and also that this requires a mechanism to support backwards compatibility for scripts that uses the soon-to-be-removed resources.


The attached patch makes resources which have "gimp-obsolete-files" as part of the path considered obsolete and will not be part of any of the traditional resource management. We make the assumption/have the requirement that obsolete resources are not added, removed or changed during a running GIMP session.

To test the patch, do

  $ cd $prefix/share/gimp/2.0/brushes/
  $ mkdir gimp-obsolete-files
  $ mv Circle-* gimp-obsolete-files
  $ mv gimp-obsolete-files/Circle-*19* .

then run GIMP and look at the brushes in the UI. Only the largest Circle* brushes are available. But you can still execute File -> Create -> Logos -> Frosty.. which uses "Circle Fuzzy (11)".

Any comments on the proposed way to deal with obsolete resources?

 / Martin

--

My GIMP Blog:
http://www.chromecode.com/
>From b12d3466e65c67aeb0f5cc5a444040f81dd1df23 Mon Sep 17 00:00:00 2001
From: Martin Nordholts <mart...@src.gnome.org>
Date: Tue, 11 Aug 2009 20:38:12 +0200
Subject: [PATCH] app: Support obsolete data resources

Add support for having obsolete data resources. An obsolete resource
is not shown in the UI or managed in any way, but it will be
considered when plug-ins requests resources. This in order to maintain
backwards compatibility for plug-ins.
---
 app/core/gimpdatafactory.c |   35 ++++++++++++++++++++++++++++++++++-
 app/core/gimpdatafactory.h |    2 ++
 app/pdb/gimppdb-utils.c    |   27 +++++++++++++++++++--------
 3 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c
index dd92dd3..05abbe3 100644
--- a/app/core/gimpdatafactory.c
+++ b/app/core/gimpdatafactory.c
@@ -42,12 +42,19 @@
 
 #define WRITABLE_PATH_KEY "gimp-data-factory-writable-path"
 
+/* Data files that have this string in their path are considered
+ * obsolete and are only kept around for backwards compatibility
+ */
+#define GIMP_OBSOLETE_DATA_DIR_NAME "gimp-obsolete-files"
+
 
 struct _GimpDataFactoryPriv
 {
   Gimp                             *gimp;
   GimpContainer                    *container;
 
+  GimpContainer                    *container_obsolete;
+
   gchar                            *path_property_name;
   gchar                            *writable_property_name;
 
@@ -102,6 +109,7 @@ gimp_data_factory_init (GimpDataFactory *factory)
 
   factory->priv->gimp                   = NULL;
   factory->priv->container              = NULL;
+  factory->priv->container_obsolete     = NULL;
   factory->priv->path_property_name     = NULL;
   factory->priv->writable_property_name = NULL;
   factory->priv->loader_entries         = NULL;
@@ -121,6 +129,12 @@ gimp_data_factory_finalize (GObject *object)
       factory->priv->container = NULL;
     }
 
+  if (factory->priv->container_obsolete)
+    {
+      g_object_unref (factory->priv->container_obsolete);
+      factory->priv->container_obsolete = NULL;
+    }
+
   if (factory->priv->path_property_name)
     {
       g_free (factory->priv->path_property_name);
@@ -145,6 +159,8 @@ gimp_data_factory_get_memsize (GimpObject *object,
 
   memsize += gimp_object_get_memsize (GIMP_OBJECT (factory->priv->container),
                                       gui_size);
+  memsize += gimp_object_get_memsize (GIMP_OBJECT (factory->priv->container_obsolete),
+                                      gui_size);
 
   return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
                                                                   gui_size);
@@ -175,6 +191,9 @@ gimp_data_factory_new (Gimp                             *gimp,
   factory->priv->container              = gimp_list_new (data_type, TRUE);
   gimp_list_set_sort_func (GIMP_LIST (factory->priv->container),
 			   (GCompareFunc) gimp_data_compare);
+  factory->priv->container_obsolete     = gimp_list_new (data_type, TRUE);
+  gimp_list_set_sort_func (GIMP_LIST (factory->priv->container_obsolete),
+			   (GCompareFunc) gimp_data_compare);
 
   factory->priv->path_property_name     = g_strdup (path_property_name);
   factory->priv->writable_property_name = g_strdup (writable_property_name);
@@ -630,6 +649,14 @@ gimp_data_factory_get_container (GimpDataFactory *factory)
   return factory->priv->container;
 }
 
+GimpContainer *
+gimp_data_factory_get_container_obsolete (GimpDataFactory *factory)
+{
+  g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
+
+  return factory->priv->container_obsolete;
+}
+
 Gimp *
 gimp_data_factory_get_gimp (GimpDataFactory *factory)
 {
@@ -783,7 +810,13 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
                 data->mtime = file_data->mtime;
                 data->dirty = FALSE;
 
-                gimp_container_add (factory->priv->container, GIMP_OBJECT (data));
+                if (strstr (file_data->dirname, GIMP_OBSOLETE_DATA_DIR_NAME))
+                  gimp_container_add (factory->priv->container_obsolete,
+                                      GIMP_OBJECT (data));
+                else
+                  gimp_container_add (factory->priv->container,
+                                      GIMP_OBJECT (data));
+
                 g_object_unref (data);
               }
 
diff --git a/app/core/gimpdatafactory.h b/app/core/gimpdatafactory.h
index 9717868..bad6033 100644
--- a/app/core/gimpdatafactory.h
+++ b/app/core/gimpdatafactory.h
@@ -95,6 +95,8 @@ gboolean        gimp_data_factory_data_save_single  (GimpDataFactory  *factory,
                                                      GimpData         *data,
                                                      GError          **error);
 GimpContainer * gimp_data_factory_get_container     (GimpDataFactory  *factory);
+GimpContainer * gimp_data_factory_get_container_obsolete
+                                                    (GimpDataFactory  *factory);
 Gimp          * gimp_data_factory_get_gimp          (GimpDataFactory  *factory);
 gboolean        gimp_data_factory_has_data_new_func (GimpDataFactory  *factory);
 
diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c
index fab4189..4fd5ff0 100644
--- a/app/pdb/gimppdb-utils.c
+++ b/app/pdb/gimppdb-utils.c
@@ -41,6 +41,21 @@
 #include "gimp-intl.h"
 
 
+static GimpObject *
+gimp_pdb_get_data_factory_item (GimpDataFactory *data_factory,
+                                const gchar     *name)
+{
+  GimpObject *gimp_object;
+
+  gimp_object = gimp_container_get_child_by_name (gimp_data_factory_get_container (data_factory), name);
+
+  if (! gimp_object)
+    gimp_object = gimp_container_get_child_by_name (gimp_data_factory_get_container_obsolete (data_factory), name);
+
+  return gimp_object;
+}
+
+
 GimpBrush *
 gimp_pdb_get_brush (Gimp         *gimp,
                     const gchar  *name,
@@ -59,8 +74,7 @@ gimp_pdb_get_brush (Gimp         *gimp,
       return NULL;
     }
 
-  brush = (GimpBrush *)
-    gimp_container_get_child_by_name (gimp_data_factory_get_container (gimp->brush_factory), name);
+  brush = (GimpBrush *) gimp_pdb_get_data_factory_item (gimp->brush_factory, name);
 
   if (! brush)
     {
@@ -120,8 +134,7 @@ gimp_pdb_get_pattern (Gimp         *gimp,
       return NULL;
     }
 
-  pattern = (GimpPattern *)
-    gimp_container_get_child_by_name (gimp_data_factory_get_container (gimp->pattern_factory), name);
+  pattern = (GimpPattern *) gimp_pdb_get_data_factory_item (gimp->pattern_factory, name);
 
   if (! pattern)
     {
@@ -150,8 +163,7 @@ gimp_pdb_get_gradient (Gimp         *gimp,
       return NULL;
     }
 
-  gradient = (GimpGradient *)
-    gimp_container_get_child_by_name (gimp_data_factory_get_container (gimp->gradient_factory), name);
+  gradient = (GimpGradient *) gimp_pdb_get_data_factory_item (gimp->gradient_factory, name);
 
   if (! gradient)
     {
@@ -186,8 +198,7 @@ gimp_pdb_get_palette (Gimp         *gimp,
       return NULL;
     }
 
-  palette = (GimpPalette *)
-    gimp_container_get_child_by_name (gimp_data_factory_get_container (gimp->palette_factory), name);
+  palette = (GimpPalette *) gimp_pdb_get_data_factory_item (gimp->palette_factory, name);
 
   if (! palette)
     {
-- 
1.6.2.5

_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

Reply via email to