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-2008 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/>.
31 #include <bmp/dbus.hh>
32 #include <dbus/dbus-glib.h>
34 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
35 (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
37 static DBusGConnection *bus;
38 static DBusGProxy *remote_object;
39 static int connected = 0;
40 static char *unknown = "unknown";
42 void fail(GError *error);
47 struct information *current_info = &info;
53 dbus_g_type_specialized_init();
55 bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
57 ERR("BMPx error 1: %s\n", error->message);
62 remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
63 BMP_DBUS_PATH, BMP_DBUS_INTERFACE);
65 ERR("BMPx error 2: %s\n", error->message);
74 if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
75 G_TYPE_INVALID, G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
77 ERR("BMPx error 3: %s\n", error->message);
82 if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
83 G_TYPE_INT, current_track, G_TYPE_INVALID,
84 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
86 if (current_info->bmpx.title) {
87 free(current_info->bmpx.title);
88 current_info->bmpx.title = 0;
90 if (current_info->bmpx.artist) {
91 free(current_info->bmpx.artist);
92 current_info->bmpx.artist = 0;
94 if (current_info->bmpx.album) {
95 free(current_info->bmpx.album);
96 current_info->bmpx.album = 0;
98 current_info->bmpx.title =
99 g_value_dup_string(g_hash_table_lookup(metadata, "title"));
100 current_info->bmpx.artist =
101 g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
102 current_info->bmpx.album =
103 g_value_dup_string(g_hash_table_lookup(metadata, "album"));
104 current_info->bmpx.bitrate =
105 g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
106 current_info->bmpx.track =
107 g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
108 current_info->bmpx.uri =
109 g_value_get_string(g_hash_table_lookup(metadata, "location"));
111 ERR("BMPx error 4: %s\n", error->message);
116 g_hash_table_destroy(metadata);
122 void fail(GError *error)
127 if (current_info->bmpx.title) {
128 g_free(current_info->bmpx.title);
129 current_info->bmpx.title = 0;
131 if (current_info->bmpx.artist) {
132 g_free(current_info->bmpx.artist);
133 current_info->bmpx.artist = 0;
135 if (current_info->bmpx.album) {
136 g_free(current_info->bmpx.album);
137 current_info->bmpx.album = 0;
139 current_info->bmpx.title = unknown;
140 current_info->bmpx.artist = unknown;
141 current_info->bmpx.album = unknown;
142 current_info->bmpx.bitrate = 0;
143 current_info->bmpx.track = 0;