<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Fujitaka Daidouji</b> <span dir="ltr"><<a href="mailto:fujitaka.daidouji@gmail.com">fujitaka.daidouji@gmail.com</a>></span><br>
Date: Wed, Apr 15, 2009 at 7:04 PM<br>Subject: Re: dbus-glib on debian lenny.<br>To: Simon McVittie <<a href="mailto:simon.mcvittie@collabora.co.uk">simon.mcvittie@collabora.co.uk</a>><br><br><br>Thanks. Well. I managed to get my code alittle more functional. Made a xchat version, and a c version for debuging the code. But I have two values I can't find the field type for. Your code <br>
<div class="im"><br> /* the result of this function is only suitable for debug output */<br>
gchar *tmp = g_strdup_value_contents (val);<br>
<br>
printf ("%s -> unhandled type %s with value %s",<br>
key, G_VALUE_TYPE_NAME (value), tmp);<br>
g_free (tmp);<br>
}<br></div>It works, but prints NULL for the second %s.<br>The two fields I am tring to get the type of is filesize and length.<br>Running you code outputs.<br><br>file-size -> unahndled type (null) with value 17578504. I have tried to guess the type such as int uint long etc... No Luck so I ended up using ti.fs = g_strdup_value_contents (val);<br>
But using that. It won't let me do any math on it. I want to take that number it outputs which is ofcourse a filesize number and divide it by 1048576 for a value of 16.764168. Then I can do a sprintf("%1.2f, "var here") on it to make out put 16.76 then take on MB. I am not sure how to go about getting the field type. hmm I even tried looking in the banshee-1 source code which is C#. I must be missing something here. x.x Maby you have an answer.<br>
<br>///////////////////////////////////////////////////////////////////////////////////////////////////<div class="im"><br>#include <stdio.h><br>#include <dbus/dbus-glib.h><br>#include <string.h><br><br>
<br><br></div>const gchar *mt1a;<br>
<br>struct TrackInfo {<br> const gchar *album;<br> const gchar *artist;<br> const gchar *name;<br> const gchar *mt;<br> const gchar *length;<br> const gchar *br;<br> const gchar *fs;<br> };<br>struct TrackInfo ti;<br><br>
<br>static void get_value (GHashTable *table, gpointer k, gpointer data)<br>{<br> //gpointer v;<br> const GValue *value;<br> const gchar *key = k;<br> const GValue *val = g_hash_table_lookup(table, key);<div class="im">
<br> if (G_VALUE_HOLDS_STRING (val))<br>
{<br></div> if (key == "album") <br> {<br> ti.album = g_value_get_string (val);<br> printf("Album: %s\n", ti.album);<br> }<br> if (key == "artist") <br> {<br> ti.artist = g_value_get_string (val);<br>
printf("Artist: %s\n", ti.artist);<br> }<br> if (key == "name") <br> {<br> <a href="http://ti.name" target="_blank">ti.name</a> = g_value_get_string (val);<br> printf("Track Title: %s\n", <a href="http://ti.name" target="_blank">ti.name</a>);<br>
}<br> if (key == "mime-type") <br> {<br> <a href="http://ti.mt" target="_blank">ti.mt</a> = g_value_get_string (val);<br> char *mt1;<br> mt1=strrchr(<a href="http://ti.mt" target="_blank">ti.mt</a>,'/');<br>
if (mt1) mt1++; else mt1=<a href="http://ti.mt" target="_blank">ti.mt</a>;<br>
mt1a=mt1;<br> printf("Mime-Type: %s\n", mt1);<br> }<br> }<br> if (G_VALUE_HOLDS_INT (val))<br> {<br> if (key == "bit-rate") <br> {<br> <a href="http://ti.br" target="_blank">ti.br</a> = g_value_get_int (val);<br>
printf("Bit-Rate: %u\n", <a href="http://ti.br" target="_blank">ti.br</a>);<br> }<br><br>}<br> if (key == "length") <br> {<br> ti.length = g_strdup_value_contents (val);<br> printf("Length: %s\n", ti.length);<br>
}<br> if (key == "file-size") <br> {<br> ti.fs = g_strdup_value_contents (val);<br> printf("File-Size: %s\n", ti.fs);<div class="im"><br> }<br>}<br><br>static void print_hash_value (gpointer k, gpointer v, gpointer data)<br>
{<br> const gchar *key = k;<br> const GValue *val = v;<br></div> const GValue *value;<div class="im"><br><br><br> if (G_VALUE_HOLDS_STRING (val))<br> {<br> printf ("%s -> %s\n", key, g_value_get_string (val));<br>
}<br>
else if (G_VALUE_HOLDS_UINT (val))<br> {<br> printf ("%s -> %u\n", key, g_value_get_uint (val));<br> }<br></div> else if (G_VALUE_HOLDS_INT (val))<br> {<br> printf ("%s -> %u\n", key, g_value_get_int (val));<div class="im">
<br>
}<br> /* ... insert any more types you might need here ... */<br> else<br> {<br> /* the result of this function is only suitable for debug output */<br> gchar *tmp = g_strdup_value_contents (val);<br><br>
</div>
printf ("%s -> unhandled type %s with value %s\n",<br> key, G_VALUE_TYPE (value), tmp);<br> g_free (tmp);<br> }<br>}<br><br><div class="im"><br>int main (int argc, char **argv)<br>{<br>
DBusGConnection *connection;<br>
GError *error;<br> DBusGProxy *proxy;<br> GHashTable* table;<br><br></div><div class="im"> g_type_init ();<br><br> error = NULL;<br> connection = dbus_g_bus_get (DBUS_BUS_SESSION,<br> &error);<br>
if (connection == NULL)<br>
{<br> g_printerr ("Failed to open connection to bus: %s\n",<br> error->message);<br> g_error_free (error);<br> exit (1);<br> }<br><br> /* Create a proxy object for the "bus driver" (name "org.bansheeproject.Banshee") */<br>
<br> proxy = dbus_g_proxy_new_for_name (connection,<br> "org.bansheeproject.Banshee",<br> "/org/bansheeproject/Banshee/PlayerEngine",<br> "org.bansheeproject.Banshee.PlayerEngine");<br>
<br> /* Call GetCurrentTrack method, wait for reply */<br> error = NULL;<br> <br> if (!dbus_g_proxy_call (proxy, "GetCurrentTrack", &error, G_TYPE_INVALID,<br> dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &table,<br>
G_TYPE_INVALID))<br> {<br> <br> g_printerr ("Error: %s\n", error->message);<br> g_error_free (error);<br> exit (1);<br> }<br><br> /* Print the results */<br>
</div>
get_value(table,"album", NULL);<br>get_value(table,"artist", NULL);<br>get_value(table,"name", NULL);<br>get_value(table,"length", NULL);<br>get_value(table,"bit-rate", NULL);<br>
get_value(table,"file-size", NULL);<br>get_value(table,"mime-type", NULL);<br>//printf("Album: %s Artist: %s Title: %s [%s|%u Kbps|%s]\n", ti.album, ti.artist, <a href="http://ti.name" target="_blank">ti.name</a>, ti.length, <a href="http://ti.br" target="_blank">ti.br</a>, mt1a);<br>
//g_hash_table_foreach (table, print_hash_value, NULL);<div class="im"><br>//banshee_hash_str(table, "album", ti->album);<br><br> g_object_unref (proxy);<br><br> return 0;<br>}<br></div>////////////////////////////////////////////////////////////////////////////////<div>
<div></div><div class="h5"><br>
<br><div class="gmail_quote">On Wed, Apr 15, 2009 at 6:24 AM, Simon McVittie <span dir="ltr"><<a href="mailto:simon.mcvittie@collabora.co.uk" target="_blank">simon.mcvittie@collabora.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>On Tue, 14 Apr 2009 at 20:43:01 -0500, Fujitaka Daidouji wrote:<br>
> static void print_hash_value (gpointer key, gpointer val, gpointer data)<br>
> {<br>
> printf ("%s -> %s\n", (char *) key, (char *) val);<br>
> }<br>
<br>
</div>No, val points to a GValue, not a string. Try something like this:<br>
<br>
static void print_hash_value (gpointer k, gpointer v, gpointer data)<br>
{<br>
const gchar *key = k;<br>
const GValue *val = v;<br>
<br>
if (G_VALUE_HOLDS_STRING (val))<br>
{<br>
printf ("%s -> %s\n", key, g_value_get_string (val));<br>
}<br>
else if (G_VALUE_HOLDS_UINT (val))<br>
{<br>
printf ("%s -> %u\n", key, g_value_get_uint (val));<br>
}<br>
/* ... insert any more types you might need here ... */<br>
else<br>
{<br>
/* the result of this function is only suitable for debug output */<br>
gchar *tmp = g_strdup_value_contents (val);<br>
<br>
printf ("%s -> unhandled type %s with value %s",<br>
key, G_VALUE_TYPE_NAME (value), tmp);<br>
g_free (tmp);<br>
}<br>
}<br>
_______________________________________________<br>
dbus mailing list<br>
<a href="mailto:dbus@lists.freedesktop.org" target="_blank">dbus@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/dbus" target="_blank">http://lists.freedesktop.org/mailman/listinfo/dbus</a><br>
</blockquote></div><br>
</div></div></div><br>