[gimp] app: move the GimpAsyncSet and the waiting code to GimpDataFactory
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: move the GimpAsyncSet and the waiting code to GimpDataFactory
- Date: Sun, 3 Jun 2018 20:29:12 +0000 (UTC)
commit c563659ed8c1a5faac97195893f2a62d9d388aa9
Author: Michael Natterer <mitch gimp org>
Date: Sun Jun 3 22:28:00 2018 +0200
app: move the GimpAsyncSet and the waiting code to GimpDataFactory
it's potentially useful for all data factories.
app/core/gimpdatafactory.c | 49 ++++++++++++++++-----------
app/core/gimpdatafactory.h | 3 --
app/text/gimpfontfactory.c | 83 ++++++++--------------------------------------
3 files changed, 44 insertions(+), 91 deletions(-)
---
diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c
index 3baaaca111..7cd0b5970d 100644
--- a/app/core/gimpdatafactory.c
+++ b/app/core/gimpdatafactory.c
@@ -34,10 +34,14 @@
#include "gimp.h"
#include "gimp-utils.h"
+#include "gimpasyncset.h"
+#include "gimpcancelable.h"
#include "gimpcontext.h"
#include "gimpdata.h"
#include "gimpdatafactory.h"
#include "gimplist.h"
+#include "gimpuncancelablewaitable.h"
+#include "gimpwaitable.h"
#include "gimp-intl.h"
@@ -74,6 +78,8 @@ struct _GimpDataFactoryPrivate
gchar *path_property_name;
gchar *writable_property_name;
+ GimpAsyncSet *async_set;
+
const GimpDataFactoryLoaderEntry *loader_entries;
gint n_loader_entries;
@@ -105,9 +111,6 @@ static void gimp_data_factory_real_data_refresh (GimpDataFactory *fa
GimpContext *context);
static void gimp_data_factory_real_data_save (GimpDataFactory *factory);
static void gimp_data_factory_real_data_free (GimpDataFactory *factory);
-static GimpAsyncSet *
- gimp_data_factory_real_get_async_set (GimpDataFactory *factory);
-static gboolean gimp_data_factory_real_data_wait (GimpDataFactory *factory);
static GimpData * gimp_data_factory_real_data_new (GimpDataFactory *factory,
GimpContext *context,
const gchar *name);
@@ -170,8 +173,6 @@ gimp_data_factory_class_init (GimpDataFactoryClass *klass)
klass->data_refresh = gimp_data_factory_real_data_refresh;
klass->data_save = gimp_data_factory_real_data_save;
klass->data_free = gimp_data_factory_real_data_free;
- klass->get_async_set = gimp_data_factory_real_get_async_set;
- klass->data_wait = gimp_data_factory_real_data_wait;
klass->data_new = gimp_data_factory_real_data_new;
klass->data_duplicate = gimp_data_factory_real_data_duplicate;
klass->data_delete = gimp_data_factory_real_data_delete;
@@ -211,6 +212,8 @@ gimp_data_factory_init (GimpDataFactory *factory)
factory->priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
GIMP_TYPE_DATA_FACTORY,
GimpDataFactoryPrivate);
+
+ factory->priv->async_set = gimp_async_set_new ();
}
static void
@@ -301,6 +304,13 @@ gimp_data_factory_finalize (GObject *object)
{
GimpDataFactoryPrivate *priv = GET_PRIVATE (object);
+ if (priv->async_set)
+ {
+ gimp_cancelable_cancel (GIMP_CANCELABLE (priv->async_set));
+
+ g_clear_object (&priv->async_set);
+ }
+
g_clear_object (&priv->container);
g_clear_object (&priv->container_obsolete);
@@ -513,18 +523,6 @@ gimp_data_factory_real_data_free (GimpDataFactory *factory)
gimp_container_thaw (factory->priv->container);
}
-static GimpAsyncSet *
-gimp_data_factory_real_get_async_set (GimpDataFactory *factory)
-{
- return NULL;
-}
-
-static gboolean
-gimp_data_factory_real_data_wait (GimpDataFactory *factory)
-{
- return TRUE;
-}
-
static GimpData *
gimp_data_factory_real_data_new (GimpDataFactory *factory,
GimpContext *context,
@@ -726,15 +724,28 @@ gimp_data_factory_get_async_set (GimpDataFactory *factory)
{
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
- return GIMP_DATA_FACTORY_GET_CLASS (factory)->get_async_set (factory);
+ return factory->priv->async_set;
}
gboolean
gimp_data_factory_data_wait (GimpDataFactory *factory)
{
+ GimpDataFactoryPrivate *priv;
+ GimpWaitable *waitable;
+
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), FALSE);
- return GIMP_DATA_FACTORY_GET_CLASS (factory)->data_wait (factory);
+ priv = GET_PRIVATE (factory);
+
+ /* don't allow cancellation for now */
+ waitable = gimp_uncancelable_waitable_new (GIMP_WAITABLE (priv->async_set));
+
+ gimp_wait (priv->gimp, waitable,
+ _("Loading fonts (this may take a while...)"));
+
+ g_object_unref (waitable);
+
+ return TRUE;
}
GimpData *
diff --git a/app/core/gimpdatafactory.h b/app/core/gimpdatafactory.h
index 397ac14554..e80b9f8d64 100644
--- a/app/core/gimpdatafactory.h
+++ b/app/core/gimpdatafactory.h
@@ -74,9 +74,6 @@ struct _GimpDataFactoryClass
void (* data_save) (GimpDataFactory *factory);
void (* data_free) (GimpDataFactory *factory);
- GimpAsyncSet * (* get_async_set) (GimpDataFactory *factory);
- gboolean (* data_wait) (GimpDataFactory *factory);
-
GimpData * (* data_new) (GimpDataFactory *factory,
GimpContext *context,
const gchar *name);
diff --git a/app/text/gimpfontfactory.c b/app/text/gimpfontfactory.c
index 20e20d6f4c..3d729567fe 100644
--- a/app/text/gimpfontfactory.c
+++ b/app/text/gimpfontfactory.c
@@ -37,10 +37,7 @@
#include "core/gimp-parallel.h"
#include "core/gimpasync.h"
#include "core/gimpasyncset.h"
-#include "core/gimpcancelable.h"
#include "core/gimpcontainer.h"
-#include "core/gimpuncancelablewaitable.h"
-#include "core/gimpwaitable.h"
#include "gimpfont.h"
#include "gimpfontfactory.h"
@@ -62,23 +59,18 @@
struct _GimpFontFactoryPrivate
{
- GimpAsyncSet *async_set;
+ gpointer foo; /* can't have an empty struct */
};
#define GET_PRIVATE(obj) (((GimpFontFactory *) (obj))->priv)
-static void gimp_font_factory_finalize (GObject *object);
-
static void gimp_font_factory_data_init (GimpDataFactory *factory,
GimpContext *context,
gboolean no_data);
static void gimp_font_factory_data_refresh (GimpDataFactory *factory,
GimpContext *context);
static void gimp_font_factory_data_save (GimpDataFactory *factory);
-static GimpAsyncSet *
- gimp_font_factory_get_async_set (GimpDataFactory *factory);
-static gboolean gimp_font_factory_data_wait (GimpDataFactory *factory);
static GimpData * gimp_font_factory_data_new (GimpDataFactory *factory,
GimpContext *context,
const gchar *name);
@@ -113,16 +105,11 @@ G_DEFINE_TYPE (GimpFontFactory, gimp_font_factory, GIMP_TYPE_DATA_FACTORY)
static void
gimp_font_factory_class_init (GimpFontFactoryClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpDataFactoryClass *factory_class = GIMP_DATA_FACTORY_CLASS (klass);
- object_class->finalize = gimp_font_factory_finalize;
-
factory_class->data_init = gimp_font_factory_data_init;
factory_class->data_refresh = gimp_font_factory_data_refresh;
factory_class->data_save = gimp_font_factory_data_save;
- factory_class->get_async_set = gimp_font_factory_get_async_set;
- factory_class->data_wait = gimp_font_factory_data_wait;
factory_class->data_new = gimp_font_factory_data_new;
factory_class->data_duplicate = gimp_font_factory_data_duplicate;
factory_class->data_delete = gimp_font_factory_data_delete;
@@ -136,23 +123,6 @@ gimp_font_factory_init (GimpFontFactory *factory)
factory->priv = G_TYPE_INSTANCE_GET_PRIVATE (factory,
GIMP_TYPE_FONT_FACTORY,
GimpFontFactoryPrivate);
-
- factory->priv->async_set = gimp_async_set_new ();
-}
-
-static void
-gimp_font_factory_finalize (GObject *object)
-{
- GimpFontFactoryPrivate *priv = GET_PRIVATE (object);
-
- if (priv->async_set)
- {
- gimp_cancelable_cancel (GIMP_CANCELABLE (priv->async_set));
-
- g_clear_object (&priv->async_set);
- }
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
@@ -196,8 +166,6 @@ gimp_font_factory_data_refresh (GimpDataFactory *factory,
static void
gimp_font_factory_data_save (GimpDataFactory *factory)
{
- GimpFontFactoryPrivate *priv = GET_PRIVATE (factory);
-
/* this is not "saving" but this functions is called at the right
* time at exit to reset the config
*/
@@ -205,38 +173,13 @@ gimp_font_factory_data_save (GimpDataFactory *factory)
/* if font loading is in progress in another thread, do nothing. calling
* FcInitReinitialize() while loading takes place is unsafe.
*/
- if (! gimp_async_set_is_empty (priv->async_set))
+ if (! gimp_async_set_is_empty (gimp_data_factory_get_async_set (factory)))
return;
/* Reinit the library with defaults. */
FcInitReinitialize ();
}
-static GimpAsyncSet *
-gimp_font_factory_get_async_set (GimpDataFactory *factory)
-{
- GimpFontFactoryPrivate *priv = GET_PRIVATE (factory);
-
- return priv->async_set;
-}
-
-static gboolean
-gimp_font_factory_data_wait (GimpDataFactory *factory)
-{
- GimpFontFactoryPrivate *priv = GET_PRIVATE (factory);
- GimpWaitable *waitable;
-
- /* don't allow cancellation for now */
- waitable = gimp_uncancelable_waitable_new (GIMP_WAITABLE (priv->async_set));
-
- gimp_wait (gimp_data_factory_get_gimp (factory), waitable,
- _("Loading fonts (this may take a while...)"));
-
- g_object_unref (waitable);
-
- return TRUE;
-}
-
static GimpData *
gimp_font_factory_data_new (GimpDataFactory *factory,
GimpContext *context,
@@ -341,15 +284,17 @@ static void
gimp_font_factory_load (GimpFontFactory *factory,
GError **error)
{
- GimpFontFactoryPrivate *priv = GET_PRIVATE (factory);
- GimpContainer *container;
- Gimp *gimp;
- FcConfig *config;
- GFile *fonts_conf;
- GList *path;
- GimpAsync *async;
-
- if (! gimp_async_set_is_empty (priv->async_set))
+ GimpContainer *container;
+ Gimp *gimp;
+ GimpAsyncSet *async_set;
+ FcConfig *config;
+ GFile *fonts_conf;
+ GList *path;
+ GimpAsync *async;
+
+ async_set = gimp_data_factory_get_async_set (GIMP_DATA_FACTORY (factory));
+
+ if (! gimp_async_set_is_empty (async_set))
{
/* font loading is already in progress */
return;
@@ -397,7 +342,7 @@ gimp_font_factory_load (GimpFontFactory *factory,
(GimpAsyncCallback) gimp_font_factory_load_async_callback,
factory);
- gimp_async_set_add (priv->async_set, async);
+ gimp_async_set_add (async_set, async);
g_object_unref (async);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]