[rhythmbox] rhythmdb: add boxed type and python bindings for RhythmDBEntryChange



commit cde5b4d64c31f0cbe976c5a1cf57705c7657f2b3
Author: Jonathan Matthew <jonathan d14n org>
Date:   Tue Apr 6 22:51:46 2010 +1000

    rhythmdb: add boxed type and python bindings for RhythmDBEntryChange
    
    First step in making the RhythmDB entry-changed signal useful in python.

 bindings/python/rhythmdb.defs     |   11 +++++++
 bindings/python/rhythmdb.override |   38 +++++++++++++++++++++++++
 rhythmdb/rhythmdb.c               |   56 +++++++++++++++++++++++++++++--------
 rhythmdb/rhythmdb.h               |    3 ++
 4 files changed, 96 insertions(+), 12 deletions(-)
---
diff --git a/bindings/python/rhythmdb.defs b/bindings/python/rhythmdb.defs
index 6ef0066..cdb7f46 100644
--- a/bindings/python/rhythmdb.defs
+++ b/bindings/python/rhythmdb.defs
@@ -20,6 +20,17 @@
   (gtype-id "RHYTHMDB_TYPE_ENTRY")
 )
 
+(define-boxed EntryChange
+  (in-module "RhythmDB")
+  (c-name "RhythmDBEntryChange")
+  (gtype-id "RHYTHMDB_TYPE_ENTRY_CHANGE")
+  (fields
+    '("RhythmDBPropType" "prop" (access read))
+    '("GValue" "old" (access read))
+    '("GValue" "new" (access read))
+  )
+)
+
 (define-boxed EntryType
   (in-module "RhythmDB")
   (c-name "RhythmDBEntryType_")
diff --git a/bindings/python/rhythmdb.override b/bindings/python/rhythmdb.override
index a73c027..d0e624b 100644
--- a/bindings/python/rhythmdb.override
+++ b/bindings/python/rhythmdb.override
@@ -1247,3 +1247,41 @@ _wrap_rb_string_value_map_set (PyGObject *self, PyObject *args, PyObject *kwargs
 	Py_RETURN_NONE;
 }
 
+%%
+override-attr  RhythmDBEntryChange.old
+
+static PyObject *
+_wrap_rhythmdb_entry_change__get_old(PyGBoxed *self, void *closure)
+{
+    RhythmDBEntryChange *c;
+
+    if (pyg_boxed_check(self, RHYTHMDB_TYPE_ENTRY_CHANGE))
+	    c = pyg_boxed_get(self, RhythmDBEntryChange);
+    else {
+	    char *s = g_strdup_printf ("self should be a RhythmDBEntryChange, is a %s", g_type_name (pyg_type_from_object ((PyObject*)self)));
+	    PyErr_SetString(PyExc_TypeError, s);
+	    g_free (s);
+	    return NULL;
+    }
+    return pyg_value_as_pyobject(&c->old, TRUE);
+}
+
+%%
+override-attr  RhythmDBEntryChange.new
+
+static PyObject *
+_wrap_rhythmdb_entry_change__get_new(PyGBoxed *self, void *closure)
+{
+    RhythmDBEntryChange *c;
+
+    if (pyg_boxed_check(self, RHYTHMDB_TYPE_ENTRY_CHANGE))
+	    c = pyg_boxed_get(self, RhythmDBEntryChange);
+    else {
+	    char *s = g_strdup_printf ("self should be a RhythmDBEntryChange, is a %s", g_type_name (pyg_type_from_object ((PyObject*)self)));
+	    PyErr_SetString(PyExc_TypeError, s);
+	    g_free (s);
+	    return NULL;
+    }
+    return pyg_value_as_pyobject(&c->new, TRUE);
+}
+
diff --git a/rhythmdb/rhythmdb.c b/rhythmdb/rhythmdb.c
index 9e26209..6f110cb 100644
--- a/rhythmdb/rhythmdb.c
+++ b/rhythmdb/rhythmdb.c
@@ -1283,14 +1283,33 @@ rhythmdb_read_leave (RhythmDB *db)
 }
 
 static void
+rhythmdb_entry_change_free (RhythmDBEntryChange *change)
+{
+	g_value_unset (&change->old);
+	g_value_unset (&change->new);
+	g_slice_free (RhythmDBEntryChange, change);
+}
+
+static RhythmDBEntryChange *
+rhythmdb_entry_change_copy (RhythmDBEntryChange *change)
+{
+	RhythmDBEntryChange *c = g_slice_new0 (RhythmDBEntryChange);
+
+	c->prop = change->prop;
+	g_value_init (&c->old, G_VALUE_TYPE (&change->old));
+	g_value_init (&c->new, G_VALUE_TYPE (&change->new));
+	g_value_copy (&change->old, &c->old);
+	g_value_copy (&change->new, &c->new);
+	return c;
+}
+
+static void
 free_entry_changes (GSList *entry_changes)
 {
 	GSList *t;
 	for (t = entry_changes; t; t = t->next) {
 		RhythmDBEntryChange *change = t->data;
-		g_value_unset (&change->old);
-		g_value_unset (&change->new);
-		g_slice_free (RhythmDBEntryChange, change);
+		rhythmdb_entry_change_free (change);
 	}
 	g_slist_free (entry_changes);
 }
@@ -1302,15 +1321,7 @@ copy_entry_changes (GSList *entry_changes)
 	GSList *t;
 	for (t = entry_changes; t; t = t->next) {
 		RhythmDBEntryChange *change = t->data;
-		RhythmDBEntryChange *c = g_slice_new0 (RhythmDBEntryChange);
-
-		c->prop = change->prop;
-		g_value_init (&c->old, G_VALUE_TYPE (&change->old));
-		g_value_init (&c->new, G_VALUE_TYPE (&change->new));
-		g_value_copy (&change->old, &c->old);
-		g_value_copy (&change->new, &c->new);
-
-		r = g_slist_prepend (r, c);
+		r = g_slist_prepend (r, rhythmdb_entry_change_copy (change));
 	}
 
 	return g_slist_reverse (r);
@@ -5699,6 +5710,27 @@ rhythmdb_entry_get_type (void)
 }
 
 /**
+ * rhythmdb_entry_change_get_type:
+ *
+ * Returns the #GType for #RhythmDBEntryChange.  #RhythmDBEntryChange is stored as a
+ * boxed value.  Copying the value copies the full change, including old and new values.
+ *
+ * Return value: entry change value type
+ */
+GType
+rhythmdb_entry_change_get_type (void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY (type == 0)) {
+		type = g_boxed_type_register_static ("RhythmDBEntryChange",
+						     (GBoxedCopyFunc)rhythmdb_entry_change_copy,
+						     (GBoxedFreeFunc)rhythmdb_entry_change_free);
+	}
+	return type;
+}
+
+/**
  * rhythmdb_entry_type_get_type:
  *
  * Returns the #GType for #RhythmDBEntryType.  #RhythmDBEntryType is stored as a boxed
diff --git a/rhythmdb/rhythmdb.h b/rhythmdb/rhythmdb.h
index 4d4039c..d7dc1e6 100644
--- a/rhythmdb/rhythmdb.h
+++ b/rhythmdb/rhythmdb.h
@@ -248,6 +248,9 @@ typedef struct {
 	RhythmDBQuery *subquery;
 } RhythmDBQueryData;
 
+GType rhythmdb_entry_change_get_type (void);
+#define RHYTHMDB_TYPE_ENTRY_CHANGE (rhythmdb_entry_change_get_type ())
+
 typedef struct {
 	RhythmDBPropType prop;
 	GValue old;



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