Add BMPx (http://beep-media-player.org/) support. Bugs and memleaks are here
authorRoman Bogorodskiy <mirrorbox@users.sourceforge.net>
Fri, 30 Dec 2005 09:44:40 +0000 (09:44 +0000)
committerRoman Bogorodskiy <mirrorbox@users.sourceforge.net>
Fri, 30 Dec 2005 09:44:40 +0000 (09:44 +0000)
for sure, will deal with it a bit later.

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@452 7f574dfc-610e-0410-a909-a81674777703

AUTHORS
ChangeLog
configure.in
src/Makefile.am
src/bmpx.c [new file with mode: 0644]
src/common.c
src/conky.c
src/conky.h

diff --git a/AUTHORS b/AUTHORS
index 919e018..42b5c6a 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -134,6 +134,7 @@ Rui Paulo <rpaulo at netbsd-pt dot org>
 
 Roman Bogorodskiy <novel at clublife dot ru>
   FreeBSD support
+  BMPx support
 
 Szymon Boniecki
   Reads current LC_TIME
index 9a15923..43ec59b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 # $Id$
 
+2005-12-30
+       * Added BMPx (http://beep-media-player.org/) support
+
 2005-12-14
        * Fixed issues with execi stuff
 
index d10f139..c5e5f5e 100644 (file)
@@ -79,6 +79,23 @@ if test $dah = "yes"; then
 fi
 
 dnl
+dnl BMPx
+dnl
+
+want_bmpx=no
+AC_ARG_ENABLE(bmpx,
+             [ --enable-bmpx           enable if you want BMPx support [[default=no]]],
+             [want_bmpx="$enableval"])
+
+AM_CONDITIONAL(BUILD_BMPX, test x$want_bmpx = xyes)
+if test x$want_bmpx = xyes; then
+       PKG_CHECK_MODULES([DBUS], [dbus-1 >= 0.35 dbus-glib-1 >= 0.35])
+       CFLAGS="$CFLAGS $DBUS_CFLAGS"
+       LIBS="$LIBS $DBUS_LIBS"
+       AC_DEFINE(BMPX, 1, [Define if you want BMPx support])
+fi
+
+dnl
 dnl Seti@Home
 dnl
 
index 40c1b19..f623dc6 100644 (file)
@@ -1,5 +1,9 @@
 bin_PROGRAMS = conky
 
+if BUILD_BMPX
+bmpx = bmpx.c
+endif
+
 if BUILD_SETI
 seti = seti.c
 endif
@@ -38,7 +42,7 @@ if BUILD_X11
 x11 = x11.c
 endif
 
-conky_SOURCES = common.c fs.c $(linux) mail.c mixer.c $(seti) $(mpd) $(solaris) $(freebsd) $(netbsd) $(port_monitors) conky.c conky.h $(x11) $(mldonkey) remoted.c remoted.h remotec.c remotec.h
+conky_SOURCES = common.c fs.c $(linux) mail.c mixer.c $(seti) $(mpd) $(solaris) $(freebsd) $(netbsd) $(port_monitors) conky.c conky.h $(x11) $(mldonkey) remoted.c remoted.h remotec.c remotec.h $(bmpx)
 
 AM_LDFLAGS = $(X11_LIBS) $(XFT_LIBS) $(CAIRO_LIBS) $(PTHREAD_LIBS) -lm
 
diff --git a/src/bmpx.c b/src/bmpx.c
new file mode 100644 (file)
index 0000000..de245ef
--- /dev/null
@@ -0,0 +1,86 @@
+/** bmpx.c
+ * BMPx client
+ *
+ * $Id$
+ */
+
+#include <dbus/dbus-glib.h>
+#include <bmpx/dbus.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "conky.h"
+
+#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
+
+static DBusGConnection *bus;
+static DBusGProxy *remote_object;
+static int connected = 0;
+
+void update_bmpx()
+{
+       GError *error = NULL;
+       struct information *current_info = &info;
+       gchar *uri;
+       GHashTable *metadata;
+       
+       if (connected == 0) {
+               g_type_init();
+               dbus_g_type_specialized_init();
+               
+               bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+               if (bus == NULL) {
+                       ERR("%s\n", error->message);
+               }
+               
+               remote_object = dbus_g_proxy_new_for_name(bus,
+                       BMP_DBUS_SERVICE,
+                       BMP_DBUS_PATH_SYSTEMCONTROL,
+                       BMP_DBUS_INTERFACE);
+               if (!remote_object) {
+                       ERR("%s\n", error->message);
+                       goto fail;
+               } else
+                       connected = 1;
+       }
+
+       if (connected == 1) {
+               if (dbus_g_proxy_call(remote_object, "GetCurrentUri", &error,
+                                       G_TYPE_INVALID,
+                                       G_TYPE_STRING, &uri, G_TYPE_INVALID)) {
+                       current_info->bmpx.uri = uri;
+               } else {
+                       ERR("%s\n", error->message);
+                       goto fail;
+               }
+       
+               if (dbus_g_proxy_call(remote_object, "GetMetadataForUri", &error,
+                               G_TYPE_STRING,
+                               uri,
+                               G_TYPE_INVALID,
+                               DBUS_TYPE_G_STRING_VALUE_HASHTABLE,
+                               &metadata,
+                               G_TYPE_INVALID)) {
+                       current_info->bmpx.title= g_value_get_string(g_hash_table_lookup(metadata, "title"));
+                       current_info->bmpx.artist = g_value_get_string(g_hash_table_lookup(metadata, "artist"));
+                       current_info->bmpx.album = g_value_get_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"));
+               } else {
+                       ERR("%s\n", error->message);
+                       goto fail;
+               }
+               
+               if (uri)
+                       free(uri);
+               g_hash_table_destroy(metadata);
+       } else {
+fail:
+               current_info->bmpx.title = strdup("Unknown");
+               current_info->bmpx.artist = strdup("Unknown");
+               current_info->bmpx.album = strdup("Unknown");
+               current_info->bmpx.bitrate = 0;
+               current_info->bmpx.track = 0;
+       }
+}
index f73348d..a1e18c2 100644 (file)
@@ -226,7 +226,11 @@ void update_stuff()
        if (NEED(INFO_MPD))
                update_mpd();
 #endif
-
+#ifdef BMPX
+       if (NEED(INFO_BMPX))
+               update_bmpx();
+#endif
+       
        if (NEED(INFO_LOADAVG))
                update_load_average();
 
index f658839..cdff7dc 100644 (file)
@@ -891,6 +891,14 @@ enum text_object_type {
        OBJ_mpd_track,
        OBJ_mpd_percent,
 #endif
+#ifdef BMPX
+       OBJ_bmpx_title,
+       OBJ_bmpx_artist,
+       OBJ_bmpx_album,
+       OBJ_bmpx_track,
+       OBJ_bmpx_uri,
+       OBJ_bmpx_bitrate,
+#endif
 #ifdef TCP_PORT_MONITOR
        OBJ_tcp_portmon,
 #endif
@@ -1068,6 +1076,14 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
                case OBJ_mpd_status:
                case OBJ_mpd_host:
 #endif
+#ifdef BMPX
+               case OBJ_bmpx_title:
+               case OBJ_bmpx_artist:
+               case OBJ_bmpx_album:
+               case OBJ_bmpx_track:
+               case OBJ_bmpx_uri:
+               case OBJ_bmpx_bitrate:
+#endif
                case OBJ_pre_exec:
                case OBJ_battery:
                        free(objs[i].data.s);
@@ -1777,6 +1793,20 @@ int a = stippled_borders, b = 1;
         (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
        END
 #endif
+#ifdef BMPX
+       OBJ(bmpx_title, INFO_BMPX)
+       END
+       OBJ(bmpx_artist, INFO_BMPX)
+       END
+       OBJ(bmpx_album, INFO_BMPX)
+       END
+       OBJ(bmpx_track, INFO_BMPX)
+       END
+       OBJ(bmpx_uri, INFO_BMPX)
+       END
+       OBJ(bmpx_bitrate, INFO_BMPX)
+       END
+#endif
 #ifdef TCP_PORT_MONITOR
        OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR) 
                int argc, port_begin, port_end, item, connection_index;
@@ -3032,6 +3062,26 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
                                               255.0f));
                        }
 #endif
+#ifdef BMPX
+                       OBJ(bmpx_title) {
+                               snprintf(p, p_max_size, "%s", cur->bmpx.title);
+                       }
+                       OBJ(bmpx_artist) {
+                               snprintf(p, p_max_size, "%s", cur->bmpx.artist);
+                       }
+                       OBJ(bmpx_album) {
+                               snprintf(p, p_max_size, "%s", cur->bmpx.album);
+                       }
+                       OBJ(bmpx_uri) {
+                               snprintf(p, p_max_size, "%s", cur->bmpx.uri);
+                       }
+                       OBJ(bmpx_track) {
+                                snprintf(p, p_max_size, "%i", cur->bmpx.track);
+                       }
+                       OBJ(bmpx_bitrate) {
+                               snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
+                       }
+#endif
                        OBJ(top) {
                                if (obj->data.top.type == TOP_NAME
                                    && obj->data.top.num >= 0
index 3ca7713..a9d39fe 100644 (file)
@@ -56,8 +56,12 @@ fprintf(stderr, "Conky: " s "\n", ##varargs)
 #define CRIT_ERR(s, varargs...) \
 { fprintf(stderr, "Conky: " s "\n", ##varargs);  exit(EXIT_FAILURE); }
 
+#ifndef MIN
 #define MIN(a,b) (a>b ? b : a)
+#endif
+#ifndef MAX
 #define MAX(a,b) (a<b ? b : a)
+#endif
 
 struct i8k_struct {
        char *version;
@@ -118,6 +122,17 @@ struct mpd_s {
 };
 #endif
 
+#ifdef BMPX
+struct bmpx_s {
+       char *title;
+       char *artist;
+       char *album;
+       char *uri;
+       int bitrate;
+       int track;
+};
+#endif
+
 #ifdef TCP_PORT_MONITOR
 #include "libtcp-portmon.h"
 #define MIN_PORT_MONITORS_DEFAULT 16
@@ -155,6 +170,9 @@ enum {
 #ifdef TCP_PORT_MONITOR
         INFO_TCP_PORT_MONITOR = 22,
 #endif
+#ifdef BMPX
+       INFO_BMPX = 23,
+#endif
 };
 
 
@@ -198,6 +216,9 @@ struct information {
        struct mpd_s mpd;
        mpd_Connection *conn;
 #endif
+#ifdef BMPX
+       struct bmpx_s bmpx;
+#endif
        struct process *cpu[10];
        struct process *memu[10];
        struct process *first_process;