2006-03-16 16:20:30 +00:00
|
|
|
/*
|
|
|
|
* bmpx.c
|
2005-12-30 09:44:40 +00:00
|
|
|
* BMPx client
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2006-05-12 12:41:18 +00:00
|
|
|
#include <bmp/dbus.h>
|
2006-03-16 16:20:30 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
|
2005-12-30 09:44:40 +00:00
|
|
|
#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-05 10:01:46 +00:00
|
|
|
static char *unknown = "unknown";
|
2005-12-30 09:44:40 +00:00
|
|
|
|
|
|
|
void update_bmpx()
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
struct information *current_info = &info;
|
2006-05-12 12:41:18 +00:00
|
|
|
gint current_track;
|
2005-12-30 09:44:40 +00:00
|
|
|
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,
|
2006-05-12 12:41:18 +00:00
|
|
|
BMP_DBUS_PATH,
|
2005-12-30 09:44:40 +00:00
|
|
|
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) {
|
2006-05-12 12:41:18 +00:00
|
|
|
if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
|
2005-12-30 09:44:40 +00:00
|
|
|
G_TYPE_INVALID,
|
2006-05-12 12:41:18 +00:00
|
|
|
G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
|
2005-12-30 09:44:40 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2006-05-12 12:41:18 +00:00
|
|
|
if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
|
|
|
|
G_TYPE_INT,
|
|
|
|
current_track,
|
2005-12-30 09:44:40 +00:00
|
|
|
G_TYPE_INVALID,
|
|
|
|
DBUS_TYPE_G_STRING_VALUE_HASHTABLE,
|
|
|
|
&metadata,
|
|
|
|
G_TYPE_INVALID)) {
|
2006-01-06 23:56:12 +00:00
|
|
|
if (current_info->bmpx.title) {
|
|
|
|
free(current_info->bmpx.title);
|
|
|
|
current_info->bmpx.title = 0;
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.artist) {
|
|
|
|
free(current_info->bmpx.artist);
|
|
|
|
current_info->bmpx.artist = 0;
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.album) {
|
|
|
|
free(current_info->bmpx.album);
|
|
|
|
current_info->bmpx.album = 0;
|
|
|
|
}
|
|
|
|
current_info->bmpx.title = g_value_dup_string(g_hash_table_lookup(metadata, "title"));
|
|
|
|
current_info->bmpx.artist = g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
|
|
|
|
current_info->bmpx.album = g_value_dup_string(g_hash_table_lookup(metadata, "album"));
|
2005-12-30 09:44:40 +00:00
|
|
|
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"));
|
2006-05-12 12:41:18 +00:00
|
|
|
current_info->bmpx.uri = g_value_get_string(g_hash_table_lookup(metadata, "location"));
|
2005-12-30 09:44:40 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_destroy(metadata);
|
|
|
|
} else {
|
2006-01-02 03:39:51 +00:00
|
|
|
fail:
|
2006-01-05 10:01:46 +00:00
|
|
|
if (error)
|
|
|
|
g_error_free(error);
|
2006-01-06 23:56:12 +00:00
|
|
|
if (current_info->bmpx.title) {
|
2006-01-12 01:22:14 +00:00
|
|
|
g_free(current_info->bmpx.title);
|
2006-01-06 23:56:12 +00:00
|
|
|
current_info->bmpx.title = 0;
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.artist) {
|
2006-01-12 01:22:14 +00:00
|
|
|
g_free(current_info->bmpx.artist);
|
2006-01-06 23:56:12 +00:00
|
|
|
current_info->bmpx.artist = 0;
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.album) {
|
2006-01-12 01:22:14 +00:00
|
|
|
g_free(current_info->bmpx.album);
|
2006-01-06 23:56:12 +00:00
|
|
|
current_info->bmpx.album = 0;
|
|
|
|
}
|
2006-01-07 17:28:51 +00:00
|
|
|
current_info->bmpx.title = unknown;
|
2006-01-02 03:39:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|