-/*
-* xmms2.c: xmms2 stuff for Conky
-*
-*
-*/
+/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
+ *
+ * Conky, a system monitor, based on torsmo
+ *
+ * Any original torsmo code is licensed under the BSD license
+ *
+ * All code written since the fork of torsmo is licensed under the GPL
+ *
+ * Please see COPYING for details
+ *
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
+ * (see AUTHORS)
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
#include "conky.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <xmmsclient/xmmsclient.h>
-#define CONN_INIT 0
-#define CONN_OK 1
-#define CONN_NO 2
-
-/* callbacks */
-
-void connection_lost( void *ptr ) {
- ((struct information *)ptr)->xmms2_conn_state = CONN_NO;
-
- if ( ((struct information *)ptr)->xmms2.status == NULL )
- ((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.status, "xmms2 not responding", TEXT_BUFFER_SIZE - 1 );
-
-
- if ( ((struct information *)ptr)->xmms2.artist == NULL )
- ((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.artist, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.album == NULL )
- ((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.album, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.title == NULL )
- ((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.title, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.genre == NULL )
- ((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.genre, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.comment == NULL )
- ((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.decoder == NULL )
- ((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.transport == NULL )
- ((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.url == NULL )
- ((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( ((struct information *)ptr)->xmms2.date == NULL )
- ((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
- strncpy( ((struct information *)ptr)->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
-
- ((struct information *)ptr)->xmms2.tracknr = 0;
- ((struct information *)ptr)->xmms2.id = 0;
- ((struct information *)ptr)->xmms2.bitrate = 0;
- ((struct information *)ptr)->xmms2.duration = 0;
- ((struct information *)ptr)->xmms2.elapsed = 0;
- ((struct information *)ptr)->xmms2.size = 0;
- ((struct information *)ptr)->xmms2.progress = 0;
+xmmsc_connection_t *xmms2_conn;
+
+#define CONN_INIT 0
+#define CONN_OK 1
+#define CONN_NO 2
+
+static void xmms_alloc(struct information *ptr)
+{
+
+ if (ptr->xmms2.artist == NULL) {
+ ptr->xmms2.artist = malloc(text_buffer_size);
+ }
+
+ if (ptr->xmms2.album == NULL) {
+ ptr->xmms2.album = malloc(text_buffer_size);
+ }
+
+ if (ptr->xmms2.title == NULL) {
+ ptr->xmms2.title = malloc(text_buffer_size);
+ }
+
+ if (ptr->xmms2.genre == NULL) {
+ ptr->xmms2.genre = malloc(text_buffer_size);
+ }
+
+ if (ptr->xmms2.comment == NULL) {
+ ptr->xmms2.comment = malloc(text_buffer_size);
+ }
+
+ if (ptr->xmms2.url == NULL) {
+ ptr->xmms2.url = malloc(text_buffer_size);
+ }
+
+ if (ptr->xmms2.date == NULL) {
+ ptr->xmms2.date = malloc(text_buffer_size);
+ }
+
+ ptr->xmms2.artist[0] = '\0';
+ ptr->xmms2.album[0] = '\0';
+ ptr->xmms2.title[0] = '\0';
+ ptr->xmms2.genre[0] = '\0';
+ ptr->xmms2.comment[0] = '\0';
+ ptr->xmms2.url[0] = '\0';
+ ptr->xmms2.date[0] = '\0';
+
+ ptr->xmms2.tracknr = 0;
+ ptr->xmms2.id = 0;
+ ptr->xmms2.bitrate = 0;
+ ptr->xmms2.duration = 0;
+ ptr->xmms2.elapsed = 0;
+ ptr->xmms2.size = 0;
+ ptr->xmms2.progress = 0;
+ ptr->xmms2.timesplayed = -1;
}
-void handle_curent_id( xmmsc_result_t *res, void *ptr ) {
-
- uint current_id;
-
- if ( xmmsc_result_get_uint( res, ¤t_id ) ) {
+void connection_lost(void *p)
+{
+ struct information *ptr = p;
+ ptr->xmms2.conn_state = CONN_NO;
- xmmsc_result_t *res2;
- res2 = xmmsc_medialib_get_info( ((struct information *)ptr)->xmms2_conn, current_id );
- xmmsc_result_wait( res2 );
+ fprintf(stderr,"XMMS2 connection failed. %s\n", xmmsc_get_last_error(xmms2_conn));
+ xmms_alloc(ptr);
+ strncpy(ptr->xmms2.status, "Disocnnected", text_buffer_size - 1);
+ ptr->xmms2.playlist[0] = '\0';
+ ptr->xmms2.id = 0;
+}
- if ( ((struct information *)ptr)->xmms2.artist == NULL )
- ((struct information *)ptr)->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
-
- if ( ((struct information *)ptr)->xmms2.album == NULL )
- ((struct information *)ptr)->xmms2.album = malloc( TEXT_BUFFER_SIZE );
-
- if ( ((struct information *)ptr)->xmms2.title == NULL )
- ((struct information *)ptr)->xmms2.title = malloc( TEXT_BUFFER_SIZE );
- if ( ((struct information *)ptr)->xmms2.genre == NULL )
- ((struct information *)ptr)->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
+int handle_curent_id(xmmsv_t *value, void *p)
+{
+ struct information *ptr = p;
+ xmmsv_t *val, *infos, *dict_entry;
+ xmmsc_result_t *res;
+ const char *errbuf;
+ int current_id;
- if ( ((struct information *)ptr)->xmms2.comment == NULL )
- ((struct information *)ptr)->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
+ const char *charval;
+ int intval;
- if ( ((struct information *)ptr)->xmms2.decoder == NULL )
- ((struct information *)ptr)->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
- if ( ((struct information *)ptr)->xmms2.transport == NULL )
- ((struct information *)ptr)->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
+ if (xmmsv_get_error(value, &errbuf)) {
+ fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
+ return TRUE;
+ }
- if ( ((struct information *)ptr)->xmms2.url == NULL )
- ((struct information *)ptr)->xmms2.url = malloc( TEXT_BUFFER_SIZE );
+ if (xmmsv_get_int(value, ¤t_id) && current_id > 0) {
- if ( ((struct information *)ptr)->xmms2.date == NULL )
- ((struct information *)ptr)->xmms2.date = malloc( TEXT_BUFFER_SIZE );
+ res = xmmsc_medialib_get_info(xmms2_conn, current_id);
+ xmmsc_result_wait(res);
+ val = xmmsc_result_get_value(res);
+ if (xmmsv_get_error(val, &errbuf)) {
+ fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
+ return TRUE;
+ }
- ((struct information *)ptr)->xmms2.id = current_id;
+ xmms_alloc(ptr);
- char *temp;
- xmmsc_result_get_dict_entry_string( res2, "artist", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.artist, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.artist, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
+ ptr->xmms2.id = current_id;
- xmmsc_result_get_dict_entry_string( res2, "title", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.title, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.title, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
+ infos = xmmsv_propdict_to_dict(val, NULL);
- xmmsc_result_get_dict_entry_string( res2, "album", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.album, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.album, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
+ if (xmmsv_dict_get(infos, "artist", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.artist, charval, text_buffer_size - 1);
+ if (xmmsv_dict_get(infos, "title", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.title, charval, text_buffer_size - 1);
- xmmsc_result_get_dict_entry_string( res2, "genre", &temp );
- if ( temp != NULL ) {
+ if (xmmsv_dict_get(infos, "album", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.album, charval, text_buffer_size - 1);
- strncpy( ((struct information *)ptr)->xmms2.genre, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.genre, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
+ if (xmmsv_dict_get(infos, "genre", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.genre, charval, text_buffer_size - 1);
+ if (xmmsv_dict_get(infos, "comment", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.comment, charval, text_buffer_size - 1);
- xmmsc_result_get_dict_entry_string( res2, "comment", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.comment, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
- }
+ if (xmmsv_dict_get(infos, "url", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.url, charval, text_buffer_size - 1);
+ if (xmmsv_dict_get(infos, "date", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
+ strncpy(ptr->xmms2.date, charval, text_buffer_size - 1);
- xmmsc_result_get_dict_entry_string( res2, "decoder", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.decoder, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.decoder, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
- xmmsc_result_get_dict_entry_string( res2, "transport", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.transport, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.transport, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
+ if (xmmsv_dict_get(infos, "tracknr", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
+ ptr->xmms2.tracknr = intval;
+ if (xmmsv_dict_get(infos, "duration", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
+ ptr->xmms2.duration = intval;
- xmmsc_result_get_dict_entry_string( res2, "url", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.url, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.url, "[Unknown]", TEXT_BUFFER_SIZE - 1 );
- }
+ if (xmmsv_dict_get(infos, "bitrate", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
+ ptr->xmms2.bitrate = intval / 1000;
+ if (xmmsv_dict_get(infos, "size", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
+ ptr->xmms2.size = (float) intval / 1048576;
- xmmsc_result_get_dict_entry_string( res2, "date", &temp );
- if ( temp != NULL ) {
- strncpy( ((struct information *)ptr)->xmms2.date, temp, TEXT_BUFFER_SIZE - 1 );
- } else {
- strncpy( ((struct information *)ptr)->xmms2.date, "????", TEXT_BUFFER_SIZE - 1 );
- }
+ if (xmmsv_dict_get(infos, "timesplayed", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
+ ptr->xmms2.timesplayed = intval;
- int itemp;
- xmmsc_result_get_dict_entry_int( res2, "tracknr", &itemp );
- ((struct information *)ptr)->xmms2.tracknr = itemp;
+ xmmsv_unref(infos);
+ xmmsc_result_unref(res);
+ }
+ return TRUE;
+}
- xmmsc_result_get_dict_entry_int( res2, "duration", &itemp );
- ((struct information *)ptr)->xmms2.duration = itemp;
+int handle_playtime(xmmsv_t *value, void *p)
+{
+ struct information *ptr = p;
+ int play_time;
+ const char *errbuf;
- xmmsc_result_get_dict_entry_int( res2, "bitrate", &itemp );
- ((struct information *)ptr)->xmms2.bitrate = itemp / 1000;
+ if (xmmsv_get_error(value, &errbuf)) {
+ fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
+ return TRUE;
+ }
- xmmsc_result_get_dict_entry_int( res2, "size", &itemp );
- ((struct information *)ptr)->xmms2.size = (float)itemp / 1048576;
+ if (xmmsv_get_int(value, &play_time)) {
+ ptr->xmms2.elapsed = play_time;
+ ptr->xmms2.progress = (float) play_time / ptr->xmms2.duration;
+ }
- xmmsc_result_unref( res2 );
- }
+ return TRUE;
}
-void handle_playtime( xmmsc_result_t *res, void *ptr ) {
- xmmsc_result_t * res2;
- uint play_time;
-
- if ( xmmsc_result_iserror( res ) )
- return;
-
- if ( !xmmsc_result_get_uint( res, &play_time ) )
- return;
-
- res2 = xmmsc_result_restart( res );
- xmmsc_result_unref( res2 );
+int handle_playback_state_change(xmmsv_t *value, void *p)
+{
+ struct information *ptr = p;
+ int pb_state = 0;
+ const char *errbuf;
+
+ if (xmmsv_get_error(value, &errbuf)) {
+ fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
+ return TRUE;
+ }
+
+ if (ptr->xmms2.status == NULL) {
+ ptr->xmms2.status = malloc(text_buffer_size);
+ ptr->xmms2.status[0] = '\0';
+ }
+
+ if (xmmsv_get_int(value, &pb_state)) {
+ switch (pb_state) {
+ case XMMS_PLAYBACK_STATUS_PLAY:
+ strncpy(ptr->xmms2.status, "Playing", text_buffer_size - 1);
+ break;
+ case XMMS_PLAYBACK_STATUS_PAUSE:
+ strncpy(ptr->xmms2.status, "Paused", text_buffer_size - 1);
+ break;
+ case XMMS_PLAYBACK_STATUS_STOP:
+ strncpy(ptr->xmms2.status, "Stopped", text_buffer_size - 1);
+ ptr->xmms2.elapsed = ptr->xmms2.progress = ptr->xmms2.percent = 0;
+ break;
+ default:
+ strncpy(ptr->xmms2.status, "Unknown", text_buffer_size - 1);
+ }
+ }
+ return TRUE;
+}
- ((struct information *)ptr)->xmms2.elapsed = play_time;
- ((struct information *)ptr)->xmms2.progress = (float) play_time / ((struct information *)ptr)->xmms2.duration;
+int handle_playlist_loaded(xmmsv_t *value, void *p)
+{
+ struct information *ptr = p;
+ const char *c, *errbuf;
+
+ if (xmmsv_get_error(value, &errbuf)) {
+ fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
+ return TRUE;
+ }
+
+ if (ptr->xmms2.playlist == NULL) {
+ ptr->xmms2.playlist = malloc(text_buffer_size);
+ ptr->xmms2.playlist[0] = '\0';
+ }
+
+ if (xmmsv_get_string(value, &c)) {
+ strncpy(ptr->xmms2.playlist, c, text_buffer_size - 1);
+ }
+ return TRUE;
}
-void handle_playback_state_change( xmmsc_result_t *res, void *ptr ) {
- uint pb_state = 0;
- if ( xmmsc_result_iserror( res ) )
- return;
-
- if ( !xmmsc_result_get_uint( res, &pb_state ) )
- return;
-
- if ( ((struct information *)ptr)->xmms2.status == NULL )
- ((struct information *)ptr)->xmms2.status = malloc( TEXT_BUFFER_SIZE );
-
- switch (pb_state) {
- case XMMS_PLAYBACK_STATUS_PLAY:
- strncpy( ((struct information *)ptr)->xmms2.status,
- "Playing", TEXT_BUFFER_SIZE - 1 );
- break;
- case XMMS_PLAYBACK_STATUS_PAUSE:
- strncpy( ((struct information *)ptr)->xmms2.status,
- "Paused", TEXT_BUFFER_SIZE - 1 );
- break;
- case XMMS_PLAYBACK_STATUS_STOP:
- strncpy( ((struct information *)ptr)->xmms2.status,
- "Stopped", TEXT_BUFFER_SIZE - 1 );
- break;
- default:
- strncpy( ((struct information *)ptr)->xmms2.status,
- "Unknown", TEXT_BUFFER_SIZE - 1 );
- }
+int update_xmms2(void)
+{
+ struct information *current_info = &info;
+
+ /* initialize connection */
+ if (current_info->xmms2.conn_state == CONN_INIT) {
+
+ if (xmms2_conn == NULL) {
+ xmms2_conn = xmmsc_init(PACKAGE);
+ }
+
+ /* did init fail? */
+ if (xmms2_conn == NULL) {
+ fprintf(stderr,"XMMS2 init failed. %s\n", xmmsc_get_last_error(xmms2_conn));
+ return 0;
+ }
+
+ /* init ok but not connected yet.. */
+ current_info->xmms2.conn_state = CONN_NO;
+
+ /* clear all values */
+ xmms_alloc(current_info);
+ }
+
+ /* connect */
+ if (current_info->xmms2.conn_state == CONN_NO) {
+
+ char *path = getenv("XMMS_PATH");
+
+ if (!xmmsc_connect(xmms2_conn, path)) {
+ fprintf(stderr,"XMMS2 connection failed. %s\n", xmmsc_get_last_error(xmms2_conn));
+ current_info->xmms2.conn_state = CONN_NO;
+ return 0;
+ }
+
+ /* set callbacks */
+ xmmsc_disconnect_callback_set(xmms2_conn, connection_lost, current_info);
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_broadcast_playback_current_id,
+ handle_curent_id, current_info);
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_signal_playback_playtime,
+ handle_playtime, current_info);
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_broadcast_playback_status,
+ handle_playback_state_change, current_info);
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_broadcast_playlist_loaded,
+ handle_playlist_loaded, current_info);
+
+ /* get playback status, current id and active playlist */
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_playback_current_id,
+ handle_curent_id, current_info);
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_playback_status,
+ handle_playback_state_change, current_info);
+ XMMS_CALLBACK_SET(xmms2_conn, xmmsc_playlist_current_active,
+ handle_playlist_loaded, current_info);
+
+ /* everything seems to be ok */
+ current_info->xmms2.conn_state = CONN_OK;
+ }
+
+ /* handle callbacks */
+ if (current_info->xmms2.conn_state == CONN_OK) {
+
+ xmmsc_io_in_handle(xmms2_conn);
+ if (xmmsc_io_want_out(xmms2_conn))
+ xmmsc_io_out_handle(xmms2_conn);
+
+ }
+ return 0;
}
-void update_xmms2() {
- struct information * current_info = &info;
-
- /* initialize connection */
- if ( current_info->xmms2_conn_state == CONN_INIT ) {
-
- if ( current_info->xmms2_conn == NULL ) {
- current_info->xmms2_conn = xmmsc_init( "conky" );
- }
-
- /* did init fail? */
- if ( current_info->xmms2_conn == NULL ) {
- fprintf(stderr,"Conky: xmms2 init failed. %s\n", xmmsc_get_last_error ( current_info->xmms2_conn ));
- fflush(stderr);
- return;
- }
-
- /* init ok but not connected yet.. */
- current_info->xmms2_conn_state = CONN_NO;
-
- /* clear all values */
- if ( current_info->xmms2.artist == NULL )
- current_info->xmms2.artist = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.artist, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.album == NULL )
- current_info->xmms2.album = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.album, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.title == NULL )
- current_info->xmms2.title = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.title, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.genre == NULL )
- current_info->xmms2.genre = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.genre, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.comment == NULL )
- current_info->xmms2.comment = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.comment, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.decoder == NULL )
- current_info->xmms2.decoder = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.decoder, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.transport == NULL )
- current_info->xmms2.transport = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.transport, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.url == NULL )
- current_info->xmms2.url = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.url, "", TEXT_BUFFER_SIZE - 1 );
-
- if ( current_info->xmms2.date == NULL )
- current_info->xmms2.date = malloc( TEXT_BUFFER_SIZE );
- strncpy( current_info->xmms2.date, "", TEXT_BUFFER_SIZE - 1 );
-
-
- current_info->xmms2.tracknr = 0;
- current_info->xmms2.id = 0;
- current_info->xmms2.bitrate = 0;
- current_info->xmms2.duration = 0;
- current_info->xmms2.elapsed = 0;
- current_info->xmms2.size = 0;
- current_info->xmms2.progress = 0;
-
- /* fprintf(stderr,"Conky: xmms2 init ok.\n");
- fflush(stderr); */
- }
-
- /* connect */
- if ( current_info->xmms2_conn_state == CONN_NO ) {
-
- char *path = getenv ( "XMMS_PATH" );
- if ( !xmmsc_connect( current_info->xmms2_conn, path ) ) {
- fprintf(stderr,"Conky: xmms2 connection failed. %s\n",
- xmmsc_get_last_error ( current_info->xmms2_conn ));
- fflush(stderr);
- current_info->xmms2_conn_state = CONN_NO;
- return;
- }
-
- /* set callbacks */
- xmmsc_disconnect_callback_set( current_info->xmms2_conn, connection_lost, current_info );
- XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_playback_current_id, handle_curent_id, current_info );
- XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_broadcast_playback_current_id, handle_curent_id, current_info );
- XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_signal_playback_playtime, handle_playtime, current_info );
- XMMS_CALLBACK_SET( current_info->xmms2_conn, xmmsc_broadcast_playback_status, handle_playback_state_change, current_info );
-
- /* get playback status, it wont be broadcasted untill it chages */
- xmmsc_result_t * res = xmmsc_playback_status( current_info->xmms2_conn );
- xmmsc_result_wait ( res );
- unsigned int pb_state;
-
- if ( current_info->xmms2.status == NULL )
- current_info->xmms2.status = malloc( TEXT_BUFFER_SIZE );
-
- xmmsc_result_get_uint( res, &pb_state );
- switch (pb_state) {
- case XMMS_PLAYBACK_STATUS_PLAY:
- strncpy( current_info->xmms2.status,
- "Playing", TEXT_BUFFER_SIZE - 1 );
- break;
- case XMMS_PLAYBACK_STATUS_PAUSE:
- strncpy( current_info->xmms2.status,
- "Paused", TEXT_BUFFER_SIZE - 1 );
- break;
- case XMMS_PLAYBACK_STATUS_STOP:
- strncpy( current_info->xmms2.status,
- "Stopped", TEXT_BUFFER_SIZE - 1 );
- break;
- default:
- strncpy( current_info->xmms2.status,
- "Unknown", TEXT_BUFFER_SIZE - 1 );
- }
- xmmsc_result_unref ( res );
-
- /* everything seems to be ok */
- current_info->xmms2_conn_state = CONN_OK;
-
- /* fprintf(stderr,"Conky: xmms2 connected.\n");
- fflush(stderr); */
- }
-
-
- /* handle callbacks */
- if ( current_info->xmms2_conn_state == CONN_OK ) {
- struct timeval tmout;
- tmout.tv_sec = 0;
- tmout.tv_usec = 100;
-
- select( current_info->xmms2_fd + 1, ¤t_info->xmms2_fdset, NULL, NULL, &tmout );
-
- xmmsc_io_in_handle(current_info->xmms2_conn);
- if (xmmsc_io_want_out(current_info->xmms2_conn)) {
- xmmsc_io_out_handle(current_info->xmms2_conn);
- }
- }
-}