[gegl/pippin/property-keys: 1/11] Add key/value property-key meta-data store for paramspecs



commit 9bde8c376208975a5702bacc9b0fe16c393d3c36
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu May 15 00:41:26 2014 +0200

    Add key/value property-key meta-data store for paramspecs
    
    This provides storage infrastructure for additional contextual ui rendering
    data. Permitting to use customized, widgets - adapted interactions as well as
    linking properties to each other.
    
    No name-space or schema; though some common practice will arise from
    interactions between existing ops and GIMP.

 gegl/gegl-operations-util.h                   |   34 +++++-
 gegl/gegl-plugin.h                            |    1 +
 gegl/operation/Makefile.am                    |    2 +
 gegl/operation/gegl-operation-property-keys.c |  174 +++++++++++++++++++++++++
 gegl/operation/gegl-operation-property-keys.h |   42 ++++++
 5 files changed, 252 insertions(+), 1 deletions(-)
---
diff --git a/gegl/gegl-operations-util.h b/gegl/gegl-operations-util.h
index e2d734d..27e4635 100644
--- a/gegl/gegl-operations-util.h
+++ b/gegl/gegl-operations-util.h
@@ -77,6 +77,38 @@ gboolean       gegl_has_operation           (const gchar *operation_type);
 GParamSpec** gegl_operation_list_properties (const gchar   *operation_type,
                                              guint         *n_properties_p);
 
+
+/**
+ * gegl_operation_get_property_key:
+ * @operation_type: the name of the operation type we want to query to property keys for.
+ * @property_name: the property to query a key for.
+ * @property_key_name: the property mata data key to query
+ *
+ * Return value: NULL or a string with the meta-data value for the operation
+ * key.
+ */
+const gchar *
+gegl_operation_get_property_key (const gchar *operation_type,
+                                 const gchar *property_name,
+                                 const gchar *property_key_name);
+
+/**
+ * gegl_operation_list_property_keys:
+ * @operation_type: the name of the operation type we want to query to property keys for.
+ * @property_name: the property to query a key for.
+ * @n_keys: (out caller-allocates): return location for number of property
+ * keys.
+ *
+ * Return value: (transfer container) (array length=n_keys): An allocated NULL terminated array of 
property-key names. The list should be freed with g_free after use.
+ */
+gchar **
+gegl_operation_list_property_keys (const gchar *operation_type,
+                                   const gchar *property_name,
+                                   guint       *n_keys);
+
+
+
+
 G_END_DECLS
 
-#endif /* __GEGL_OPERATIONS_UTIL_H__ */
\ No newline at end of file
+#endif /* __GEGL_OPERATIONS_UTIL_H__ */
diff --git a/gegl/gegl-plugin.h b/gegl/gegl-plugin.h
index b5f955c..2c334d3 100644
--- a/gegl/gegl-plugin.h
+++ b/gegl/gegl-plugin.h
@@ -77,6 +77,7 @@ GType gegl_module_register_type (GTypeModule     *module,
 #include <operation/gegl-operation-sink.h>
 #include <operation/gegl-operation-meta.h>
 #include <operation/gegl-extension-handler.h>
+#include <operation/gegl-operation-property-keys.h>
 
 G_END_DECLS
 
diff --git a/gegl/operation/Makefile.am b/gegl/operation/Makefile.am
index 6482d92..e9eb1a6 100644
--- a/gegl/operation/Makefile.am
+++ b/gegl/operation/Makefile.am
@@ -32,6 +32,7 @@ liboperation_public_HEADERS = \
        gegl-operation-point-composer3.h \
        gegl-operation-point-filter.h    \
        gegl-operation-point-render.h    \
+       gegl-operation-property-keys.h \
        gegl-operation-sink.h            \
        gegl-operation-source.h          \
        gegl-operation-temporal.h
@@ -49,6 +50,7 @@ liboperation_sources = \
        gegl-operation-point-composer3.c        \
        gegl-operation-point-filter.c           \
        gegl-operation-point-render.c           \
+       gegl-operation-property-keys.c \
        gegl-operation-sink.c                   \
        gegl-operation-source.c                 \
        gegl-operation-temporal.c               \
diff --git a/gegl/operation/gegl-operation-property-keys.c b/gegl/operation/gegl-operation-property-keys.c
new file mode 100644
index 0000000..62a042b
--- /dev/null
+++ b/gegl/operation/gegl-operation-property-keys.c
@@ -0,0 +1,174 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Øyvind Kolås
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <string.h>
+
+#include "gegl.h"
+#include "gegl-operation.h"
+#include "gegl-operations.h"
+#include "gegl-operation-property-keys.h"
+
+static GHashTable *
+gegl_param_spec_get_property_key_ht (GParamSpec  *pspec,
+                                     gboolean     create)
+{
+  GHashTable *ret = NULL;
+  if (pspec)
+    {
+      GQuark quark = g_quark_from_static_string ("gegl-property-keys");
+      ret = g_param_spec_get_qdata (pspec, quark);
+      if (!ret && create)
+      {
+        ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+        g_param_spec_set_qdata_full (pspec, quark, ret, 
+                                     (GDestroyNotify)g_hash_table_unref);
+      }
+    }
+  return ret;
+}
+
+const gchar *
+gegl_param_spec_get_property_key (GParamSpec  *pspec,
+                                  const gchar *key_name)
+{
+  GHashTable *ht;
+  ht = gegl_param_spec_get_property_key_ht (pspec, FALSE);
+  if (ht)
+    return g_hash_table_lookup (ht, key_name);
+  return NULL;
+}
+
+const gchar *
+gegl_param_spec_set_property_key (GParamSpec  *pspec,
+                                  const gchar *key_name,
+                                  const gchar *value)
+{
+  GHashTable *ht;
+  ht = gegl_param_spec_get_property_key_ht (pspec, TRUE);
+  if (ht)
+    g_hash_table_insert (ht, g_strdup (key_name), g_strdup (value));
+  return NULL;
+}
+
+static GHashTable *
+gegl_operation_class_get_property_key_ht (GeglOperationClass *operation_class,
+                                          const gchar        *property_name,
+                                          gboolean            create)
+{
+  GParamSpec *pspec;
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (operation_class),
+                                        property_name);
+  if (pspec)
+    return gegl_param_spec_get_property_key_ht (pspec, create);
+  return NULL;
+}
+
+gchar **
+gegl_operation_list_property_keys (const gchar *operation_name,
+                                   const gchar *property_name,
+                                   guint       *n_keys)
+{
+  GType         type;
+  GObjectClass *klass;
+  GHashTable   *ht = NULL;
+  GList        *list, *l;
+  gchar       **ret;
+  int count;
+  int i;
+  type = gegl_operation_gtype_from_name (operation_name);
+  if (!type)
+    {
+      if (n_keys)
+        *n_keys = 0;
+      return NULL;
+    }
+  klass  = g_type_class_ref (type);
+  ht = gegl_operation_class_get_property_key_ht (GEGL_OPERATION_CLASS (klass),
+                                                 property_name, FALSE);
+  if (!ht)
+  {
+    count = 0;
+    ret = g_malloc0 (sizeof (gpointer));;
+  }
+  else
+  {
+    count = g_hash_table_size (ht);
+    ret = g_malloc0 (sizeof (gpointer) * (count + 1));
+    list = g_hash_table_get_keys (ht);
+    for (i = 0, l = list; l; l = l->next)
+      {
+        ret[i] = l->data;
+      }
+    g_list_free (list);
+  }
+  if (n_keys)
+    *n_keys = count;
+  g_type_class_unref (klass);
+  return ret;
+}
+
+void
+gegl_operation_class_set_property_key (GeglOperationClass *operation_class,
+                                       const gchar        *property_name,
+                                       const gchar        *key_name,
+                                       const gchar        *value)
+{
+  GParamSpec *pspec;
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (operation_class),
+                                        property_name);
+  if (pspec)
+    gegl_param_spec_set_property_key (pspec, key_name, value);
+}
+
+
+const gchar *
+gegl_operation_class_get_property_key (GeglOperationClass *operation_class,
+                                       const gchar        *property_name,
+                                       const gchar        *key_name)
+{
+  GParamSpec *pspec;
+  pspec = g_object_class_find_property (G_OBJECT_CLASS (operation_class),
+                                        property_name);
+  if (pspec)
+    return gegl_param_spec_get_property_key (pspec, key_name);
+  return NULL;
+}
+
+const gchar *
+gegl_operation_get_property_key (const gchar *operation_name,
+                                 const gchar *property_name,
+                                 const gchar *property_key_name)
+{
+  GType         type;
+  GObjectClass *klass;
+  const gchar  *ret = NULL;
+  type = gegl_operation_gtype_from_name (operation_name);
+  if (!type)
+    {
+      return NULL;
+    }
+  klass  = g_type_class_ref (type);
+  ret = gegl_operation_class_get_property_key (GEGL_OPERATION_CLASS (klass), 
+                                               property_name, 
+                                               property_key_name);
+  g_type_class_unref (klass);
+  return ret;
+}
diff --git a/gegl/operation/gegl-operation-property-keys.h b/gegl/operation/gegl-operation-property-keys.h
new file mode 100644
index 0000000..dc8432e
--- /dev/null
+++ b/gegl/operation/gegl-operation-property-keys.h
@@ -0,0 +1,42 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2014 Øyvind Kolås
+ */
+
+#ifndef __GEGL_OPERATION_PROPERTY_KEYS_H__
+#define __GEGL_OPERATION_PROPERTY_KEYS_H__
+
+#include <glib-object.h>
+
+const gchar *gegl_param_spec_get_property_key (GParamSpec  *pspec,
+                                               const gchar *key_name);
+
+const gchar *gegl_param_spec_set_property_key (GParamSpec  *pspec,
+                                               const gchar *key_name,
+                                               const gchar *value);
+
+void       gegl_operation_class_set_property_key
+                                            (GeglOperationClass *klass,
+                                             const gchar        *property_name,
+                                             const gchar        *key_name,
+                                             const gchar        *value);
+
+const gchar *
+gegl_operation_class_get_property_key (GeglOperationClass *operation_class,
+                                       const gchar        *property_name,
+                                       const gchar        *key_name);
+
+#endif


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