1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Any original torsmo code is licensed under the BSD license
8 * All code written since the fork of torsmo is licensed under the GPL
10 * Please see COPYING for details
12 * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
14 * All rights reserved.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 #include <bmp/dbus.hh>
35 #include <dbus/dbus-glib.h>
37 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
38 (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
40 static DBusGConnection *bus;
41 static DBusGProxy *remote_object;
42 static int connected = 0;
43 static char *unknown = "unknown";
45 void fail(GError *error, struct information *);
50 struct information *current_info = &info;
56 dbus_g_type_specialized_init();
58 bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
60 NORM_ERR("BMPx error 1: %s\n", error->message);
61 fail(error, current_info);
65 remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
66 BMP_DBUS_PATH__BMP, BMP_DBUS_INTERFACE__BMP);
68 NORM_ERR("BMPx error 2: %s\n", error->message);
69 fail(error, current_info);
77 if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
78 G_TYPE_INVALID, G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
80 NORM_ERR("BMPx error 3: %s\n", error->message);
81 fail(error, current_info);
85 if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
86 G_TYPE_INT, current_track, G_TYPE_INVALID,
87 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
89 if (current_info->bmpx.title) {
90 free(current_info->bmpx.title);
91 current_info->bmpx.title = 0;
93 if (current_info->bmpx.artist) {
94 free(current_info->bmpx.artist);
95 current_info->bmpx.artist = 0;
97 if (current_info->bmpx.album) {
98 free(current_info->bmpx.album);
99 current_info->bmpx.album = 0;
101 current_info->bmpx.title =
102 g_value_dup_string(g_hash_table_lookup(metadata, "title"));
103 current_info->bmpx.artist =
104 g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
105 current_info->bmpx.album =
106 g_value_dup_string(g_hash_table_lookup(metadata, "album"));
107 current_info->bmpx.bitrate =
108 g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
109 current_info->bmpx.track =
110 g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
111 current_info->bmpx.uri =
112 g_value_get_string(g_hash_table_lookup(metadata, "location"));
114 NORM_ERR("BMPx error 4: %s\n", error->message);
115 fail(error, current_info);
119 g_hash_table_destroy(metadata);
121 fail(error, current_info);
125 void fail(GError *error, struct information *current_info)
130 if (current_info->bmpx.title) {
131 g_free(current_info->bmpx.title);
132 current_info->bmpx.title = 0;
134 if (current_info->bmpx.artist) {
135 g_free(current_info->bmpx.artist);
136 current_info->bmpx.artist = 0;
138 if (current_info->bmpx.album) {
139 g_free(current_info->bmpx.album);
140 current_info->bmpx.album = 0;
142 current_info->bmpx.title = unknown;
143 current_info->bmpx.artist = unknown;
144 current_info->bmpx.album = unknown;
145 current_info->bmpx.bitrate = 0;
146 current_info->bmpx.track = 0;