Amarok query support for drivel



Hi all

The attached patch adds support for querying Amarok, the KDE music
player, for the current playing song.

It makes it pretty trivial to query other players that expose DCOP
interfaces too.

Ok to commit?

Cheers
Grahame

-- 
Grahame Bowland                       Email: grahame bowland uwa edu au
University Communications Services    Phone: +61 8 6488 1175
The University of Western Australia     Fax: +61 8 6488 1109
                                     CRICOS: 00126G
? changes.patch
? depcomp
? install-sh
? missing
Index: configure.ac
===================================================================
RCS file: /cvs/gnome/drivel/configure.ac,v
retrieving revision 1.57
diff -p -u -r1.57 configure.ac
--- configure.ac	9 Jul 2005 03:11:42 -0000	1.57
+++ configure.ac	6 Aug 2005 18:08:29 -0000
@@ -158,6 +158,19 @@ if test x$SCROLLKEEPER_CONFIG = xno; the
 fi
 
 dnl
+dnl Check for dcop
+dnl
+
+AC_PATH_PROG(DCOP_PROGRAM, dcop, no)
+if test x$DCOP_PROGRAM = xno; then
+  AC_MSG_WARN(Couldn't find dcop, query of dcop music players disabled)
+  HAVE_DCOP=no
+else
+  AC_DEFINE_UNQUOTED(DCOP_PROGRAM, "$DCOP_PROGRAM", "definition of DCOP_PROGRAM")
+  HAVE_DCOP=yes
+fi
+
+dnl
 dnl Check for libcurl.
 dnl
 
@@ -214,6 +227,7 @@ drivel-$VERSION:
 	Compiler:			${CC}
 	Using gtkspell:			$HAVE_GTKSPELL
 	Rhythmbox interface:		$HAVE_RHYTHMBOX
+	DCOP interface:			$HAVE_DCOP
 	Update MIME database:		$HAVE_NEW_MIME
 	Update desktop database:	$HAVE_NEW_DESKTOP
 "
Index: src/query_music_players.c
===================================================================
RCS file: /cvs/gnome/drivel/src/query_music_players.c,v
retrieving revision 1.8
diff -p -u -r1.8 query_music_players.c
--- src/query_music_players.c	11 Jan 2005 00:21:18 -0000	1.8
+++ src/query_music_players.c	6 Aug 2005 18:08:29 -0000
@@ -52,6 +52,9 @@ static gboolean
 rhythmbox_init (gpointer **ptr);
 static gchar
 *rhythmbox_query (gpointer *ptr);
+
+static gchar
+*amarok_query (gpointer *ptr);
 /* ---- end definitions ---- */
 
 void
@@ -87,6 +90,10 @@ query_music_players (GtkListStore *playi
 		add_music_entry (playing, rhythmbox_query (ptr), pixbuf, &entries, FALSE);
 	}
 #endif
+#ifdef DCOP_PROGRAM
+	pixbuf = NULL;
+	add_music_entry (playing, amarok_query (ptr), pixbuf, &entries, FALSE);
+#endif
 	if (entries)
 		add_music_entry (playing, g_strdup (""), NULL, NULL, TRUE);
 	else
@@ -299,3 +306,44 @@ static gchar
 		return NULL;
 }
 #endif
+
+#ifdef DCOP_PROGRAM
+#include <stdio.h>
+
+#define DCOP_BUF_SIZE		1024
+
+static gchar
+*dcop_query (gchar *command)
+{
+	FILE *pipe;
+	gchar *cmd, *p;
+	char buf[DCOP_BUF_SIZE];
+	
+	cmd = g_strdup_printf("%s %s", DCOP_PROGRAM, command);
+	pipe = popen(cmd, "r");
+	if (!pipe)
+		return NULL;
+	memset(buf, 0, DCOP_BUF_SIZE);
+	fread(buf, DCOP_BUF_SIZE-1, 1, pipe);
+	pclose(pipe);
+	g_free(cmd);
+
+	p = buf;
+	while (*p) {
+		if (*p == '\n') {
+			*p = '\0';
+			break;
+		}
+		p++;
+	}
+
+	return g_strdup(buf);
+}
+
+static gchar
+*amarok_query (gpointer *ptr)
+{
+	return dcop_query("amarok player nowPlaying");
+}
+#endif
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]