2005-12-30 09:44:40 +00:00
|
|
|
/** bmpx.c
|
|
|
|
* BMPx client
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
#include <bmpx/dbus.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "conky.h"
|
|
|
|
|
|
|
|
#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
|
|
|
|
|
|
|
|
static DBusGConnection *bus;
|
|
|
|
static DBusGProxy *remote_object;
|
|
|
|
static int connected = 0;
|
2006-01-02 03:39:51 +00:00
|
|
|
char unknown[8];
|
2005-12-30 09:44:40 +00:00
|
|
|
|
|
|
|
void update_bmpx()
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
struct information *current_info = &info;
|
|
|
|
gchar *uri;
|
|
|
|
GHashTable *metadata;
|
|
|
|
|
|
|
|
if (connected == 0) {
|
|
|
|
g_type_init();
|
|
|
|
dbus_g_type_specialized_init();
|
|
|
|
|
|
|
|
bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
|
|
|
|
if (bus == NULL) {
|
2006-01-02 03:39:51 +00:00
|
|
|
ERR("BMPx error 1: %s\n", error->message);
|
2005-12-30 12:57:28 +00:00
|
|
|
goto fail;
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remote_object = dbus_g_proxy_new_for_name(bus,
|
|
|
|
BMP_DBUS_SERVICE,
|
|
|
|
BMP_DBUS_PATH_SYSTEMCONTROL,
|
|
|
|
BMP_DBUS_INTERFACE);
|
|
|
|
if (!remote_object) {
|
2006-01-02 03:39:51 +00:00
|
|
|
ERR("BMPx error 2: %s\n", error->message);
|
2005-12-30 09:44:40 +00:00
|
|
|
goto fail;
|
2005-12-30 12:57:28 +00:00
|
|
|
}
|
2005-12-30 09:44:40 +00:00
|
|
|
|
2005-12-30 12:57:28 +00:00
|
|
|
connected = 1;
|
|
|
|
}
|
|
|
|
|
2005-12-30 09:44:40 +00:00
|
|
|
if (connected == 1) {
|
|
|
|
if (dbus_g_proxy_call(remote_object, "GetCurrentUri", &error,
|
|
|
|
G_TYPE_INVALID,
|
|
|
|
G_TYPE_STRING, &uri, G_TYPE_INVALID)) {
|
|
|
|
current_info->bmpx.uri = uri;
|
|
|
|
} else {
|
2006-01-02 03:39:51 +00:00
|
|
|
ERR("BMPx error 3: %s\n", error->message);
|
2005-12-30 09:44:40 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dbus_g_proxy_call(remote_object, "GetMetadataForUri", &error,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
uri,
|
|
|
|
G_TYPE_INVALID,
|
|
|
|
DBUS_TYPE_G_STRING_VALUE_HASHTABLE,
|
|
|
|
&metadata,
|
|
|
|
G_TYPE_INVALID)) {
|
2006-01-02 03:39:51 +00:00
|
|
|
current_info->bmpx.title = g_value_get_string(g_hash_table_lookup(metadata, "title"));
|
2005-12-30 09:44:40 +00:00
|
|
|
current_info->bmpx.artist = g_value_get_string(g_hash_table_lookup(metadata, "artist"));
|
|
|
|
current_info->bmpx.album = g_value_get_string(g_hash_table_lookup(metadata, "album"));
|
|
|
|
current_info->bmpx.bitrate = g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
|
|
|
|
current_info->bmpx.track = g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
|
|
|
|
} else {
|
2006-01-02 03:39:51 +00:00
|
|
|
ERR("BMPx error 4: %s\n", error->message);
|
2005-12-30 09:44:40 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri)
|
|
|
|
free(uri);
|
|
|
|
g_hash_table_destroy(metadata);
|
|
|
|
} else {
|
2006-01-02 03:39:51 +00:00
|
|
|
fail:
|
|
|
|
strcpy(unknown, "Unknown");
|
|
|
|
current_info->bmpx.title = unknown;
|
|
|
|
current_info->bmpx.artist = unknown;
|
|
|
|
current_info->bmpx.album = unknown;
|
2005-12-30 09:44:40 +00:00
|
|
|
current_info->bmpx.bitrate = 0;
|
|
|
|
current_info->bmpx.track = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-01-02 03:39:51 +00:00
|
|
|
|