2010-02-09 12:11:56 +00:00
|
|
|
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2005-12-30 09:44:40 +00:00
|
|
|
*
|
2007-08-10 19:53:44 +00:00
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
2010-01-01 23:46:17 +00:00
|
|
|
* Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-10 19:53:44 +00:00
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2005-12-30 09:44:40 +00:00
|
|
|
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "conky.h"
|
|
|
|
#include "logging.h"
|
|
|
|
|
2007-08-05 04:47:21 +00:00
|
|
|
#include <bmp/dbus.hh>
|
2006-03-16 16:20:30 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
|
|
|
|
(dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
|
2005-12-30 09:44:40 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2008-04-10 22:45:45 +00:00
|
|
|
void fail(GError *error);
|
|
|
|
|
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;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-12-30 09:44:40 +00:00
|
|
|
if (connected == 0) {
|
|
|
|
g_type_init();
|
|
|
|
dbus_g_type_specialized_init();
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-12-30 09:44:40 +00:00
|
|
|
bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
|
|
|
|
if (bus == NULL) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("BMPx error 1: %s\n", error->message);
|
2008-04-10 22:45:45 +00:00
|
|
|
fail(error);
|
|
|
|
return;
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
|
2008-04-10 22:45:45 +00:00
|
|
|
BMP_DBUS_PATH, BMP_DBUS_INTERFACE);
|
2005-12-30 09:44:40 +00:00
|
|
|
if (!remote_object) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("BMPx error 2: %s\n", error->message);
|
2008-04-10 22:45:45 +00:00
|
|
|
fail(error);
|
|
|
|
return;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-12-30 09:44:40 +00:00
|
|
|
|
2005-12-30 12:57:28 +00:00
|
|
|
connected = 1;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2008-04-10 22:45:45 +00:00
|
|
|
G_TYPE_INVALID, G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
|
2005-12-30 09:44:40 +00:00
|
|
|
} else {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("BMPx error 3: %s\n", error->message);
|
2008-04-10 22:45:45 +00:00
|
|
|
fail(error);
|
|
|
|
return;
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2006-05-12 12:41:18 +00:00
|
|
|
if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
|
2008-04-10 22:45:45 +00:00
|
|
|
G_TYPE_INT, current_track, G_TYPE_INVALID,
|
|
|
|
DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
|
|
|
|
G_TYPE_INVALID)) {
|
2010-02-22 21:03:14 +00:00
|
|
|
free_and_zero(current_info->bmpx.title);
|
|
|
|
free_and_zero(current_info->bmpx.artist);
|
|
|
|
free_and_zero(current_info->bmpx.album);
|
2008-02-20 20:30:45 +00:00
|
|
|
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"));
|
|
|
|
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"));
|
|
|
|
current_info->bmpx.uri =
|
|
|
|
g_value_get_string(g_hash_table_lookup(metadata, "location"));
|
2005-12-30 09:44:40 +00:00
|
|
|
} else {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("BMPx error 4: %s\n", error->message);
|
2008-04-10 22:45:45 +00:00
|
|
|
fail(error);
|
|
|
|
return;
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2005-12-30 09:44:40 +00:00
|
|
|
g_hash_table_destroy(metadata);
|
|
|
|
} else {
|
2008-04-10 22:45:45 +00:00
|
|
|
fail(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fail(GError *error)
|
|
|
|
{
|
|
|
|
if (error) {
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.title) {
|
|
|
|
g_free(current_info->bmpx.title);
|
|
|
|
current_info->bmpx.title = 0;
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.artist) {
|
|
|
|
g_free(current_info->bmpx.artist);
|
|
|
|
current_info->bmpx.artist = 0;
|
|
|
|
}
|
|
|
|
if (current_info->bmpx.album) {
|
|
|
|
g_free(current_info->bmpx.album);
|
|
|
|
current_info->bmpx.album = 0;
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
2008-04-10 22:45:45 +00:00
|
|
|
current_info->bmpx.title = unknown;
|
|
|
|
current_info->bmpx.artist = unknown;
|
|
|
|
current_info->bmpx.album = unknown;
|
|
|
|
current_info->bmpx.bitrate = 0;
|
|
|
|
current_info->bmpx.track = 0;
|
2005-12-30 09:44:40 +00:00
|
|
|
}
|
2009-11-08 18:27:01 +00:00
|
|
|
|
|
|
|
#define BMPX_PRINT_GENERATOR(name, fmt) \
|
|
|
|
void print_bmpx_##name(struct text_object *obj, char *p, int p_max_size) \
|
|
|
|
{ \
|
|
|
|
(void)obj; \
|
|
|
|
snprintf(p, p_max_size, fmt, info.bmpx.name); \
|
|
|
|
}
|
|
|
|
|
|
|
|
BMPX_PRINT_GENERATOR(title, "%s")
|
|
|
|
BMPX_PRINT_GENERATOR(artist, "%s")
|
|
|
|
BMPX_PRINT_GENERATOR(album, "%s")
|
|
|
|
BMPX_PRINT_GENERATOR(uri, "%s")
|
|
|
|
BMPX_PRINT_GENERATOR(track, "%i")
|
|
|
|
BMPX_PRINT_GENERATOR(bitrate, "%i")
|
|
|
|
|
|
|
|
#undef BMPX_PRINT_GENERATOR
|
|
|
|
|