1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al.
11 * All rights reserved.
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <bmp/dbus.hh>
28 #include <dbus/dbus-glib.h>
35 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
36 (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
38 static DBusGConnection *bus;
39 static DBusGProxy *remote_object;
40 static int connected = 0;
41 static char *unknown = "unknown";
46 struct information *current_info = &info;
52 dbus_g_type_specialized_init();
54 bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
56 ERR("BMPx error 1: %s\n", error->message);
60 remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
61 BMP_DBUS_PATH, BMP_DBUS_INTERFACE);
63 ERR("BMPx error 2: %s\n", error->message);
71 if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
72 G_TYPE_INVALID, G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
74 ERR("BMPx error 3: %s\n", error->message);
78 if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
79 G_TYPE_INT, current_track, G_TYPE_INVALID,
80 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
82 if (current_info->bmpx.title) {
83 free(current_info->bmpx.title);
84 current_info->bmpx.title = 0;
86 if (current_info->bmpx.artist) {
87 free(current_info->bmpx.artist);
88 current_info->bmpx.artist = 0;
90 if (current_info->bmpx.album) {
91 free(current_info->bmpx.album);
92 current_info->bmpx.album = 0;
94 current_info->bmpx.title =
95 g_value_dup_string(g_hash_table_lookup(metadata, "title"));
96 current_info->bmpx.artist =
97 g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
98 current_info->bmpx.album =
99 g_value_dup_string(g_hash_table_lookup(metadata, "album"));
100 current_info->bmpx.bitrate =
101 g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
102 current_info->bmpx.track =
103 g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
104 current_info->bmpx.uri =
105 g_value_get_string(g_hash_table_lookup(metadata, "location"));
107 ERR("BMPx error 4: %s\n", error->message);
111 g_hash_table_destroy(metadata);
117 if (current_info->bmpx.title) {
118 g_free(current_info->bmpx.title);
119 current_info->bmpx.title = 0;
121 if (current_info->bmpx.artist) {
122 g_free(current_info->bmpx.artist);
123 current_info->bmpx.artist = 0;
125 if (current_info->bmpx.album) {
126 g_free(current_info->bmpx.album);
127 current_info->bmpx.album = 0;
129 current_info->bmpx.title = unknown;
130 current_info->bmpx.artist = unknown;
131 current_info->bmpx.album = unknown;
132 current_info->bmpx.bitrate = 0;
133 current_info->bmpx.track = 0;