1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 * Conky, a system monitor, based on torsmo
5 * Any original torsmo code is licensed under the BSD license
7 * All code written since the fork of torsmo is licensed under the GPL
9 * Please see COPYING for details
11 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
13 * All rights reserved.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 * vim: ts=4 sw=4 noet ai cindent syntax=c
35 #include <bmp/dbus.hh>
36 #include <dbus/dbus-glib.h>
38 #define DBUS_TYPE_G_STRING_VALUE_HASHTABLE \
39 (dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
41 static DBusGConnection *bus;
42 static DBusGProxy *remote_object;
43 static int connected = 0;
44 static char *unknown = "unknown";
46 void fail(GError *error);
51 struct information *current_info = &info;
57 dbus_g_type_specialized_init();
59 bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
61 NORM_ERR("BMPx error 1: %s\n", error->message);
66 remote_object = dbus_g_proxy_new_for_name(bus, BMP_DBUS_SERVICE,
67 BMP_DBUS_PATH, BMP_DBUS_INTERFACE);
69 NORM_ERR("BMPx error 2: %s\n", error->message);
78 if (dbus_g_proxy_call(remote_object, "GetCurrentTrack", &error,
79 G_TYPE_INVALID, G_TYPE_INT, ¤t_track, G_TYPE_INVALID)) {
81 NORM_ERR("BMPx error 3: %s\n", error->message);
86 if (dbus_g_proxy_call(remote_object, "GetMetadataForListItem", &error,
87 G_TYPE_INT, current_track, G_TYPE_INVALID,
88 DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &metadata,
90 if (current_info->bmpx.title) {
91 free(current_info->bmpx.title);
92 current_info->bmpx.title = 0;
94 if (current_info->bmpx.artist) {
95 free(current_info->bmpx.artist);
96 current_info->bmpx.artist = 0;
98 if (current_info->bmpx.album) {
99 free(current_info->bmpx.album);
100 current_info->bmpx.album = 0;
102 current_info->bmpx.title =
103 g_value_dup_string(g_hash_table_lookup(metadata, "title"));
104 current_info->bmpx.artist =
105 g_value_dup_string(g_hash_table_lookup(metadata, "artist"));
106 current_info->bmpx.album =
107 g_value_dup_string(g_hash_table_lookup(metadata, "album"));
108 current_info->bmpx.bitrate =
109 g_value_get_int(g_hash_table_lookup(metadata, "bitrate"));
110 current_info->bmpx.track =
111 g_value_get_int(g_hash_table_lookup(metadata, "track-number"));
112 current_info->bmpx.uri =
113 g_value_get_string(g_hash_table_lookup(metadata, "location"));
115 NORM_ERR("BMPx error 4: %s\n", error->message);
120 g_hash_table_destroy(metadata);
126 void fail(GError *error)
131 if (current_info->bmpx.title) {
132 g_free(current_info->bmpx.title);
133 current_info->bmpx.title = 0;
135 if (current_info->bmpx.artist) {
136 g_free(current_info->bmpx.artist);
137 current_info->bmpx.artist = 0;
139 if (current_info->bmpx.album) {
140 g_free(current_info->bmpx.album);
141 current_info->bmpx.album = 0;
143 current_info->bmpx.title = unknown;
144 current_info->bmpx.artist = unknown;
145 current_info->bmpx.album = unknown;
146 current_info->bmpx.bitrate = 0;
147 current_info->bmpx.track = 0;