[gimp] Implemented better signal handling for property-changed events.



commit 3705c85e1e448c979ef1f5b6e93344a01f980bf9
Author: Roman Joost <romanofski gimp org>
Date:   Sat Sep 26 20:49:04 2009 +1000

    Implemented better signal handling for property-changed events.
    
    The XMPModel listens now on the row-changed event and checks if the row
    belong to a property or schema change. If a property change occured a
    detailed property-changed signal is emitted. A detailed schema-changed
    signal is currently not emitted, because not implemented.

 plug-ins/metadata/xmp-model.c |   79 +++++++++++++++++++++++++++++++++-------
 plug-ins/metadata/xmp-model.h |    5 ++-
 plug-ins/metadata/xmpdump.c   |    6 +--
 3 files changed, 70 insertions(+), 20 deletions(-)
---
diff --git a/plug-ins/metadata/xmp-model.c b/plug-ins/metadata/xmp-model.c
index f5719d6..f8de017 100644
--- a/plug-ins/metadata/xmp-model.c
+++ b/plug-ins/metadata/xmp-model.c
@@ -31,6 +31,19 @@
 #include "xmp-parse.h"
 #include "xmp-model.h"
 
+/* Used for converting row-changed events into property-changed and
+ * schema-changed events.*/
+#define XMP_MODEL_SCHEMA    0
+#define XMP_MODEL_PROPERTY  1
+
+/* local function declarations */
+static void         tree_model_row_changed  (GtkTreeModel    *model,
+                                             GtkTreePath     *path,
+                                             GtkTreeIter     *iter,
+                                             gpointer         user_data);
+
+static XMPSchema *  find_xmp_schema_by_iter (XMPModel       *xmp_model,
+                                             GtkTreeIter    *iter);
 
 enum
 {
@@ -90,6 +103,10 @@ xmp_model_init (XMPModel *xmp_model)
   xmp_model->custom_schemas     = NULL;
   xmp_model->custom_properties  = NULL;
   xmp_model->cached_schema      = NULL;
+
+  g_signal_connect (GTK_TREE_MODEL (xmp_model), "row-changed",
+                    G_CALLBACK (tree_model_row_changed),
+                    NULL);
 }
 
 static void
@@ -168,10 +185,53 @@ xmp_model_is_empty (XMPModel *xmp_model)
                                          &iter);
 }
 
+/* translate a row-changed event into a property-changed or
+ * schema-changed event with the detail.
+ */
+static void
+tree_model_row_changed (GtkTreeModel    *model,
+                        GtkTreePath     *path,
+                        GtkTreeIter     *iter,
+                        gpointer         user_data)
+{
+  gint       depth;
+  XMPSchema *schema;
+
+  /* 1. check which iter depth the change was: 0 for schema 1 for
+   * property? */
+  depth = gtk_tree_store_iter_depth (GTK_TREE_STORE (model), iter);
+  if (depth == XMP_MODEL_SCHEMA)
+  {
+    /* 2. If a schema has changed, emit a schema changed signal */
+  }
+
+  if (depth == XMP_MODEL_PROPERTY)
+  {
+    schema = find_xmp_schema_by_iter (XMP_MODEL (model), iter);
+    xmp_model_property_changed (XMP_MODEL (model), schema, iter);
+  }
+}
+
+static XMPSchema *
+find_xmp_schema_by_iter (XMPModel       *xmp_model,
+                         GtkTreeIter    *child)
+{
+  GtkTreeIter  parent;
+  XMPSchema   *schema;
+
+  if (! gtk_tree_model_iter_parent (GTK_TREE_MODEL (xmp_model), &parent, child))
+    return NULL;
+
+  gtk_tree_model_get (GTK_TREE_MODEL (xmp_model), &parent,
+                      COL_XMP_TYPE_XREF, &schema,
+                      -1);
+  return schema;
+}
+
 /* check if the given schema_uri matches a known schema; else return NULL */
 static XMPSchema *
-find_xmp_schema (XMPModel    *xmp_model,
-                 const gchar *schema_uri)
+find_xmp_schema_by_uri (XMPModel    *xmp_model,
+                        const gchar *schema_uri)
 {
   int          i;
   GSList      *list;
@@ -392,9 +452,7 @@ parse_start_schema (XMPParseContext     *context,
   XMPSchema   *schema;
 
   g_return_val_if_fail (xmp_model != NULL, NULL);
-
-  schema = find_xmp_schema (xmp_model, ns_uri);
-
+  schema = find_xmp_schema_by_uri (xmp_model, ns_uri);
   if (schema == NULL)
     {
       /* add schema to custom_schemas */
@@ -521,7 +579,6 @@ parse_set_property (XMPParseContext     *context,
                           COL_XMP_WEIGHT, PANGO_WEIGHT_NORMAL,
                           COL_XMP_WEIGHT_SET, FALSE,
                           -1);
-      xmp_model_property_changed (xmp_model, schema, &child_iter);
       break;
 
     case XMP_PTYPE_RESOURCE:
@@ -859,9 +916,7 @@ xmp_model_get_scalar_property (XMPModel    *xmp_model,
   g_return_val_if_fail (xmp_model != NULL, NULL);
   g_return_val_if_fail (schema_name != NULL, NULL);
   g_return_val_if_fail (property_name != NULL, NULL);
-
-  schema = find_xmp_schema (xmp_model, schema_name);
-
+  schema = find_xmp_schema_by_uri (xmp_model, schema_name);
   if (! schema)
     schema = find_xmp_schema_prefix (xmp_model, schema_name);
 
@@ -930,9 +985,7 @@ xmp_model_set_scalar_property (XMPModel    *xmp_model,
   g_return_val_if_fail (schema_name != NULL, FALSE);
   g_return_val_if_fail (property_name != NULL, FALSE);
   g_return_val_if_fail (property_value != NULL, FALSE);
-
-  schema = find_xmp_schema (xmp_model, schema_name);
-
+  schema = find_xmp_schema_by_uri (xmp_model, schema_name);
   if (! schema)
     schema = find_xmp_schema_prefix (xmp_model, schema_name);
 
@@ -981,8 +1034,6 @@ xmp_model_set_scalar_property (XMPModel    *xmp_model,
                       COL_XMP_WEIGHT, PANGO_WEIGHT_NORMAL,
                       COL_XMP_WEIGHT_SET, FALSE,
                       -1);
-  xmp_model_property_changed (xmp_model, schema, &child_iter);
-
   return TRUE;
 }
 
diff --git a/plug-ins/metadata/xmp-model.h b/plug-ins/metadata/xmp-model.h
index 7c4dab3..98fe0f4 100644
--- a/plug-ins/metadata/xmp-model.h
+++ b/plug-ins/metadata/xmp-model.h
@@ -25,8 +25,8 @@ G_BEGIN_DECLS
 #include <glib-object.h>
 
 #define GIMP_TYPE_XMP_MODEL             (xmp_model_get_type ())
-#define XMP_MODEL(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_XMP_MODEL, XMPModel))
-#define XMP_MODEL_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_XMP_MODEL, XMPModelClass))
+#define XMP_MODEL(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_XMP_MODEL, XMPModel))
+#define XMP_MODEL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_XMP_MODEL, XMPModelClass))
 #define GIMP_IS_XMP_MODEL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_XMP_MODEL))
 #define GIMP_IS_XMP_MODEL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_XMP_MODEL))
 #define GIMP_XMP_MODEL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_XMP_MODEL, XMPModelClass))
@@ -114,6 +114,7 @@ gboolean      xmp_model_set_scalar_property (XMPModel    *xmp_model,
                                              const gchar *property_name,
                                              const gchar *property_value);
 
+
 /* Signals */
 void          xmp_model_property_changed    (XMPModel     *xmp_model,
                                              XMPSchema    *schema,
diff --git a/plug-ins/metadata/xmpdump.c b/plug-ins/metadata/xmpdump.c
index be350d2..241b94a 100644
--- a/plug-ins/metadata/xmpdump.c
+++ b/plug-ins/metadata/xmpdump.c
@@ -122,7 +122,7 @@ scan_file (const gchar *filename)
   gsize              length;
   GError            *error;
   XMPParseContext   *context;
-  // XMPModel          *xmp_model = xmp_model_new ();
+  XMPModel          *xmp_model = xmp_model_new ();
 
   g_print ("\nFile: %s\n", filename);
   error = NULL;
@@ -143,16 +143,14 @@ scan_file (const gchar *filename)
 
   /*
    * used for testing the XMPModel
-   *
+   */
   g_signal_connect (xmp_model, "property-changed::xmpMM:DocumentID",
                     G_CALLBACK (property_changed), NULL);
 
   if (! xmp_model_parse_file (xmp_model, filename, &error))
     {
-      xmp_model_free (xmp_model);
       return 1;
     }
-  */
 
   if (! xmp_parse_context_parse (context, contents, length, NULL))
     {



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