GNOME Bugzilla – Bug 412210
RhythmDB's metadata gathering isn't usable from python
Last modified: 2007-02-27 10:36:25 UTC
Python can't connect to the metadata gathering signal of RhythmDB, because it uses a hash table parameter in the callback, and they don't carry enough information to use from Python (types etc).
Created attachment 83384 [details] [review] patch This patch adds a String-GValue map class, which is implemented using a GHashTable, and bound to Python. The use of GHashTable in the signal is replaces with the new class, and it can be seen to work with the following fragment, runnable from the python console: shell.props.db.connect('entry-extra-metadata-gather', lambda db, e, m: m.set('xxx', 'yyy')) map = shell.props.db.entry_gather_metadata(shell.props.shell_player.get_playing_entry()) map.size() map.get('xxx') I've also changed rb_value_free() to use gslices instead of malloc/free, and changed the metadata-dbus code accordingly.
The new files are missing from the patch, but what I can see of it looks good. It'd be nice if we could make the string-gvalue map look like a python dict, but maybe that's more trouble than it's worth.
Created attachment 83422 [details] [review] move along, nothing to see here New files added to patch, while no-one was watching.
Looks sensible enough, and it seems to work.
Created attachment 83435 [details] [review] test case in the art display plugin As a test case I hacked the art display plugin. It seems to work perfectly, as I can retrieve the metadata from the map in the python console, but on each call to the attached callback there's a warning in the console: Traceback (most recent call last):
+ Trace 114202
metadata.set('coverArt-uri', self.art_widget.current_uri)
Can't say what's wrong, though, and it may be just me.
Nevermind, I forgot to check if current_uri is not null. Your patch works pretty well!
In particular, the TypeError occurs because we don't know what to map None to. There are three possible types it could be G_TYPE_POINTER, G_TYPE_BOXED and G_TYPE_OBJECT. I've committed the patch to trunk, with a small change that makes it use a more meaningful error message when you try to store None. I'm leaving the bug open, because I want to allow you to do "metadata['cover-art-uri'] = foo" as well.
RBStringValueMap now supports Python's map protocol, so indexing like that works :)
Last commit (r4868) breaks build: gcc -DHAVE_CONFIG_H -I. -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/bindings/python -I../.. -I/home/alex/src/remote-cvs/gnome.org/rhythmbox -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/lib -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/metadata -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/player -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/rhythmdb -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/widgets -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/sources -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/iradio -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/podcast -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/plugins -I/home/alex/src/remote-cvs/gnome.org/rhythmbox/shell -DORBIT2=1 -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/libgnomeui-2.0 -I/usr/include/libgnome-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/libart-2.0 -I/usr/include/gconf/2 -I/usr/include/libbonoboui-2.0 -I/usr/include/gnome-vfs-2.0 -I/usr/lib/gnome-vfs-2.0/include -I/usr/include/gnome-keyring-1 -I/usr/include/orbit-2.0 -I/usr/include/libbonobo-2.0 -I/usr/include/bonobo-activation-2.0 -I/usr/include/libxml2 -I/usr/include/libglade-2.0 -I/usr/include/gnome-vfs-module-2.0 -pthread -I/usr/include/gstreamer-0.10 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2 -Wcomment -Wformat -Wnonnull -Wimplicit-int -Wimplicit -Wmain -Wmissing-braces -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused-function -Wunused-label -Wunused-value -Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wcast-align -Wall -Werror -std=gnu89 -I/usr/include/pygtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/python2.4 -Wno-error -g -O2 -MT rb_la-rhythmdb.lo -MD -MP -MF .deps/rb_la-rhythmdb.Tpo -c rhythmdb.c -fPIC -DPIC -o .libs/rb_la-rhythmdb.o rhythmdb.override: In function '_wrap_rhythmdb_entry_type__get_can_sync_metadata': rhythmdb.override:479: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override:480: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override:483: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override:484: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override: In function '_wrap_rhythmdb_entry_type__set_can_sync_metadata': rhythmdb.override:515: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override:519: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override: In function '_wrap_rhythmdb_entry_get': rhythmdb.override:110: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override: In function '_wrap_rhythmdb_entry_set': rhythmdb.override:145: warning: dereferencing type-punned pointer will break strict-aliasing rules rhythmdb.override: At top level: rhythmdb.override:734: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_wrap_rb_string_value_map_mp_length' rhythmdb.override:798: error: '_wrap_rb_string_value_map_mp_length' undeclared here (not in a function) make[4]: *** [rb_la-rhythmdb.lo] Error 1
Fixed again in SVN.