gnome-python-desktop r493 - in branches/gnome-2-22: . totem



Author: gjc
Date: Fri Aug 22 21:47:16 2008
New Revision: 493
URL: http://svn.gnome.org/viewvc/gnome-python-desktop?rev=493&view=rev

Log:
	* totem/plparsermodule.c (fill_py_dict, _metadata_from_gvalue),
	(_metadata_to_gvalue, initplparser): Register PyObject <->
	TOTEM_TYPE_PL_PARSER_METADATA conversion functions with pygobject.
	Closes #Bug 503343.



Modified:
   branches/gnome-2-22/ChangeLog
   branches/gnome-2-22/totem/plparsermodule.c

Modified: branches/gnome-2-22/totem/plparsermodule.c
==============================================================================
--- branches/gnome-2-22/totem/plparsermodule.c	(original)
+++ branches/gnome-2-22/totem/plparsermodule.c	Fri Aug 22 21:47:16 2008
@@ -18,14 +18,80 @@
 
    Author: Tiago Cogumbreiro <cogumbreiro users sf net>
  */
-
-#include <pygobject.h>
+#define PY_SSIZE_T_CLEAN
 #include <Python.h>
+#include <pygobject.h>
+#include "totem-pl-parser.h"
+
+
+#if PY_VERSION_HEX < 0x02050000
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+typedef inquiry lenfunc;
+typedef intargfunc ssizeargfunc;
+typedef intobjargproc ssizeobjargproc;
+#endif
+
 
 void pyplparser_register_classes(PyObject *d);
 void pyplparser_add_constants(PyObject *module, const gchar *strip_prefix);
 extern PyMethodDef pyplparser_functions[];
 
+
+#ifdef TOTEM_TYPE_PL_PARSER_METADATA
+
+static void fill_py_dict (gpointer key,
+                          gpointer value,
+                          gpointer user_data)
+{
+    PyObject *val = PyString_FromString((char *) value);
+    PyDict_SetItemString((PyObject*) user_data, (char*) key, val);
+    Py_DECREF(val);
+}
+
+static PyObject *
+_metadata_from_gvalue(const GValue *value)
+{
+    GHashTable *hash_table;
+    PyObject *py_dict;
+    
+    hash_table = (GHashTable *) g_value_get_boxed(value);
+    py_dict = PyDict_New();
+    g_hash_table_foreach(hash_table, fill_py_dict, py_dict);
+    
+    return py_dict;
+}
+
+static int
+_metadata_to_gvalue(GValue *gvalue, PyObject *obj)
+{
+    GHashTable *hash_table;
+    PyObject *key, *value;
+    Py_ssize_t pos = 0;
+
+    if (!PyDict_Check(obj))
+        return -1;
+
+    hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+    while (PyDict_Next(obj, &pos, &key, &value)) {
+          /* do something interesting with the values... */
+        if (!PyString_Check(key) || !PyString_Check(value)) {
+            g_hash_table_unref(hash_table);
+            return -1;
+        }
+        g_hash_table_insert(hash_table, g_strdup(PyString_AsString(key)),
+                            g_strdup(PyString_AsString(value)));
+    }
+
+    g_value_take_boxed(gvalue, hash_table);
+    return 0;
+}
+
+#endif
+
+
 DL_EXPORT(void)
 initplparser(void)
 {
@@ -43,4 +109,11 @@
     pyplparser_register_classes(d);
     pyplparser_add_constants(m, "TOTEM_PL_");
 
+      /* Bug  #503343 */
+#ifdef TOTEM_TYPE_PL_PARSER_METADATA
+    pyg_register_gtype_custom(TOTEM_TYPE_PL_PARSER_METADATA,
+			      _metadata_from_gvalue,
+			      _metadata_to_gvalue);
+#endif
+
 }



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