2010-02-09 12:11:56 +00:00
|
|
|
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2007-08-10 19:53:44 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2010-01-01 23:46:17 +00:00
|
|
|
* Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* 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
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-10 19:53:44 +00:00
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2006-05-18 00:24:59 +00:00
|
|
|
|
|
|
|
#include "conky.h"
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
xmmsc_connection_t *xmms2_conn;
|
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
#define CONN_INIT 0
|
|
|
|
#define CONN_OK 1
|
|
|
|
#define CONN_NO 2
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2007-08-05 04:47:21 +00:00
|
|
|
static void xmms_alloc(struct information *ptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ptr->xmms2.artist == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.artist = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->xmms2.album == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.album = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->xmms2.title == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.title = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->xmms2.genre == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.genre = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->xmms2.comment == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.comment = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->xmms2.url == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.url = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->xmms2.date == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.date = (char*) malloc(text_buffer_size.get(*state));
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2007-08-05 04:47:21 +00:00
|
|
|
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;
|
2008-03-18 00:23:16 +00:00
|
|
|
ptr->xmms2.timesplayed = -1;
|
|
|
|
}
|
|
|
|
|
2009-11-29 20:06:59 +00:00
|
|
|
void free_xmms2(struct text_object *obj)
|
|
|
|
{
|
|
|
|
(void)obj;
|
2009-12-28 20:21:28 +00:00
|
|
|
|
2010-02-24 11:04:28 +00:00
|
|
|
free_and_zero(info.xmms2.artist);
|
|
|
|
free_and_zero(info.xmms2.album);
|
|
|
|
free_and_zero(info.xmms2.title);
|
|
|
|
free_and_zero(info.xmms2.genre);
|
|
|
|
free_and_zero(info.xmms2.comment);
|
|
|
|
free_and_zero(info.xmms2.url);
|
|
|
|
free_and_zero(info.xmms2.date);
|
|
|
|
free_and_zero(info.xmms2.status);
|
|
|
|
free_and_zero(info.xmms2.playlist);
|
2009-11-29 20:06:59 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 00:23:16 +00:00
|
|
|
void connection_lost(void *p)
|
|
|
|
{
|
2010-02-09 12:38:12 +00:00
|
|
|
struct information *ptr = (struct information*) p;
|
2009-11-09 22:21:58 +00:00
|
|
|
ptr->xmms2.conn_state = CONN_NO;
|
2008-03-18 00:23:16 +00:00
|
|
|
|
2009-11-09 22:21:58 +00:00
|
|
|
fprintf(stderr,"XMMS2 connection failed. %s\n", xmmsc_get_last_error(xmms2_conn));
|
2008-03-18 00:23:16 +00:00
|
|
|
|
2009-11-09 22:21:58 +00:00
|
|
|
xmms_alloc(ptr);
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.status, "Disconnected", text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
ptr->xmms2.playlist[0] = '\0';
|
|
|
|
ptr->xmms2.id = 0;
|
2007-08-05 04:47:21 +00:00
|
|
|
}
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
|
|
|
|
int handle_curent_id(xmmsv_t *value, void *p)
|
2007-08-05 04:47:21 +00:00
|
|
|
{
|
2010-02-09 12:38:12 +00:00
|
|
|
struct information *ptr = (struct information*) p;
|
2009-04-28 16:02:24 +00:00
|
|
|
xmmsv_t *val, *infos, *dict_entry;
|
|
|
|
xmmsc_result_t *res;
|
|
|
|
const char *errbuf;
|
|
|
|
int current_id;
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
const char *charval;
|
|
|
|
int intval;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_error(value, &errbuf)) {
|
|
|
|
fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
|
|
|
|
return TRUE;
|
2009-11-09 22:21:58 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_int(value, ¤t_id) && current_id > 0) {
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
res = xmmsc_medialib_get_info(xmms2_conn, current_id);
|
|
|
|
xmmsc_result_wait(res);
|
|
|
|
val = xmmsc_result_get_value(res);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_error(val, &errbuf)) {
|
|
|
|
fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
|
|
|
|
return TRUE;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
xmms_alloc(ptr);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
ptr->xmms2.id = current_id;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
infos = xmmsv_propdict_to_dict(val, NULL);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "artist", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.artist, charval, text_buffer_size.get(*state) - 1);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-12-28 20:21:28 +00:00
|
|
|
if (xmmsv_dict_get(infos, "title", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.title, charval, text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
|
2009-12-28 20:21:28 +00:00
|
|
|
if (xmmsv_dict_get(infos, "album", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.album, charval, text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "genre", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.genre, charval, text_buffer_size.get(*state) - 1);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "comment", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.comment, charval, text_buffer_size.get(*state) - 1);
|
2009-04-28 16:02:24 +00:00
|
|
|
|
|
|
|
if (xmmsv_dict_get(infos, "url", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.url, charval, text_buffer_size.get(*state) - 1);
|
2009-04-28 16:02:24 +00:00
|
|
|
|
|
|
|
if (xmmsv_dict_get(infos, "date", &dict_entry) && xmmsv_get_string(dict_entry, &charval))
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.date, charval, text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "tracknr", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
|
|
|
|
ptr->xmms2.tracknr = intval;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "duration", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
|
|
|
|
ptr->xmms2.duration = intval;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "bitrate", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
|
|
|
|
ptr->xmms2.bitrate = intval / 1000;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "size", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
|
|
|
|
ptr->xmms2.size = (float) intval / 1048576;
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_dict_get(infos, "timesplayed", &dict_entry) && xmmsv_get_int(dict_entry, &intval))
|
|
|
|
ptr->xmms2.timesplayed = intval;
|
2008-03-18 00:23:16 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
|
|
|
|
xmmsv_unref(infos);
|
|
|
|
xmmsc_result_unref(res);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-04-28 16:02:24 +00:00
|
|
|
return TRUE;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
int handle_playtime(xmmsv_t *value, void *p)
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
2010-02-09 12:38:12 +00:00
|
|
|
struct information *ptr = (struct information*) p;
|
2009-04-28 16:02:24 +00:00
|
|
|
int play_time;
|
|
|
|
const char *errbuf;
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_error(value, &errbuf)) {
|
|
|
|
fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
|
|
|
|
return TRUE;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_int(value, &play_time)) {
|
|
|
|
ptr->xmms2.elapsed = play_time;
|
|
|
|
ptr->xmms2.progress = (float) play_time / ptr->xmms2.duration;
|
2010-01-02 19:50:53 +00:00
|
|
|
ptr->xmms2.percent = (int)(ptr->xmms2.progress*100);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-04-06 06:11:53 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
return TRUE;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
int handle_playback_state_change(xmmsv_t *value, void *p)
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
2010-02-09 12:38:12 +00:00
|
|
|
struct information *ptr = (struct information*) p;
|
2009-04-28 16:02:24 +00:00
|
|
|
int pb_state = 0;
|
|
|
|
const char *errbuf;
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_error(value, &errbuf)) {
|
|
|
|
fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
|
|
|
|
return TRUE;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (ptr->xmms2.status == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.status = (char*) malloc(text_buffer_size.get(*state));
|
2009-04-28 16:02:24 +00:00
|
|
|
ptr->xmms2.status[0] = '\0';
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_int(value, &pb_state)) {
|
2009-11-09 22:21:58 +00:00
|
|
|
switch (pb_state) {
|
|
|
|
case XMMS_PLAYBACK_STATUS_PLAY:
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.status, "Playing", text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
break;
|
|
|
|
case XMMS_PLAYBACK_STATUS_PAUSE:
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.status, "Paused", text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
break;
|
|
|
|
case XMMS_PLAYBACK_STATUS_STOP:
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.status, "Stopped", text_buffer_size.get(*state) - 1);
|
2010-06-13 17:10:59 +00:00
|
|
|
ptr->xmms2.elapsed = ptr->xmms2.progress = ptr->xmms2.percent = 0;
|
2009-11-09 22:21:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.status, "Unknown", text_buffer_size.get(*state) - 1);
|
2009-11-09 22:21:58 +00:00
|
|
|
}
|
2009-04-28 16:02:24 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2006-05-18 00:24:59 +00:00
|
|
|
}
|
|
|
|
|
2009-12-28 20:21:28 +00:00
|
|
|
int handle_playlist_loaded(xmmsv_t *value, void *p)
|
2009-04-28 16:02:24 +00:00
|
|
|
{
|
2010-02-09 12:38:12 +00:00
|
|
|
struct information *ptr = (struct information*) p;
|
2009-04-28 16:02:24 +00:00
|
|
|
const char *c, *errbuf;
|
|
|
|
|
|
|
|
if (xmmsv_get_error(value, &errbuf)) {
|
|
|
|
fprintf(stderr,"XMMS2 server error. %s\n", errbuf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-03-18 00:23:16 +00:00
|
|
|
|
|
|
|
if (ptr->xmms2.playlist == NULL) {
|
2010-11-23 17:42:48 +00:00
|
|
|
ptr->xmms2.playlist = (char*) malloc(text_buffer_size.get(*state));
|
2008-03-18 00:23:16 +00:00
|
|
|
ptr->xmms2.playlist[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmmsv_get_string(value, &c)) {
|
2010-11-23 17:42:48 +00:00
|
|
|
strncpy(ptr->xmms2.playlist, c, text_buffer_size.get(*state) - 1);
|
2008-03-18 00:23:16 +00:00
|
|
|
}
|
2009-04-28 16:02:24 +00:00
|
|
|
return TRUE;
|
2008-03-18 00:23:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 17:10:59 +00:00
|
|
|
int update_xmms2(void)
|
2008-02-20 20:30:45 +00:00
|
|
|
{
|
|
|
|
struct information *current_info = &info;
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* initialize connection */
|
2009-04-28 16:02:24 +00:00
|
|
|
if (current_info->xmms2.conn_state == CONN_INIT) {
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmms2_conn == NULL) {
|
2010-01-02 19:50:53 +00:00
|
|
|
xmms2_conn = xmmsc_init(PACKAGE_NAME);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* did init fail? */
|
2009-04-28 16:02:24 +00:00
|
|
|
if (xmms2_conn == NULL) {
|
|
|
|
fprintf(stderr,"XMMS2 init failed. %s\n", xmmsc_get_last_error(xmms2_conn));
|
2010-06-13 17:10:59 +00:00
|
|
|
return 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* init ok but not connected yet.. */
|
2009-04-28 16:02:24 +00:00
|
|
|
current_info->xmms2.conn_state = CONN_NO;
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* clear all values */
|
2009-04-28 16:02:24 +00:00
|
|
|
xmms_alloc(current_info);
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* connect */
|
2009-04-28 16:02:24 +00:00
|
|
|
if (current_info->xmms2.conn_state == CONN_NO) {
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
char *path = getenv("XMMS_PATH");
|
|
|
|
|
2009-04-28 16:02:24 +00:00
|
|
|
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;
|
2010-06-13 17:10:59 +00:00
|
|
|
return 0;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set callbacks */
|
2009-04-28 16:02:24 +00:00
|
|
|
xmmsc_disconnect_callback_set(xmms2_conn, connection_lost, current_info);
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_broadcast_playback_current_id,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_curent_id, current_info);
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_signal_playback_playtime,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_playtime, current_info);
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_broadcast_playback_status,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_playback_state_change, current_info);
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_broadcast_playlist_loaded,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_playlist_loaded, current_info);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2008-03-18 00:23:16 +00:00
|
|
|
/* get playback status, current id and active playlist */
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_playback_current_id,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_curent_id, current_info);
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_playback_status,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_playback_state_change, current_info);
|
2009-12-28 20:21:28 +00:00
|
|
|
XMMS_CALLBACK_SET(xmms2_conn, xmmsc_playlist_current_active,
|
2009-04-28 16:02:24 +00:00
|
|
|
handle_playlist_loaded, current_info);
|
2008-02-20 20:30:45 +00:00
|
|
|
|
|
|
|
/* everything seems to be ok */
|
2009-04-28 16:02:24 +00:00
|
|
|
current_info->xmms2.conn_state = CONN_OK;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2006-05-18 00:24:59 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
/* handle callbacks */
|
2009-04-28 16:02:24 +00:00
|
|
|
if (current_info->xmms2.conn_state == CONN_OK) {
|
|
|
|
|
|
|
|
xmmsc_io_in_handle(xmms2_conn);
|
2009-05-10 17:44:57 +00:00
|
|
|
if (xmmsc_io_want_out(xmms2_conn))
|
2009-04-28 16:02:24 +00:00
|
|
|
xmmsc_io_out_handle(xmms2_conn);
|
2009-05-10 17:44:57 +00:00
|
|
|
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2010-06-13 17:10:59 +00:00
|
|
|
return 0;
|
2009-11-09 22:21:58 +00:00
|
|
|
}
|
2009-04-28 16:02:24 +00:00
|
|
|
|
2009-11-09 22:38:12 +00:00
|
|
|
void print_xmms2_tracknr(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
(void)obj;
|
|
|
|
if (info.xmms2.tracknr != -1) {
|
|
|
|
snprintf(p, p_max_size, "%i", info.xmms2.tracknr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_xmms2_elapsed(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
(void)obj;
|
|
|
|
snprintf(p, p_max_size, "%02d:%02d", info.xmms2.elapsed / 60000,
|
|
|
|
(info.xmms2.elapsed / 1000) % 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_xmms2_duration(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
(void)obj;
|
|
|
|
snprintf(p, p_max_size, "%02d:%02d",
|
|
|
|
info.xmms2.duration / 60000,
|
|
|
|
(info.xmms2.duration / 1000) % 60);
|
|
|
|
}
|
|
|
|
|
2009-12-04 00:31:21 +00:00
|
|
|
double xmms2_barval(struct text_object *obj)
|
2009-11-09 22:38:12 +00:00
|
|
|
{
|
|
|
|
(void)obj;
|
|
|
|
|
2009-12-04 00:31:21 +00:00
|
|
|
return info.xmms2.progress;
|
2009-11-09 22:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_xmms2_smart(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
(void)obj;
|
2011-03-04 18:29:52 +00:00
|
|
|
int artist_len = strlen(info.xmms2.artist);
|
|
|
|
int title_len = strlen(info.xmms2.title);
|
|
|
|
if (artist_len < 2 && title_len < 2) {
|
2009-11-09 22:38:12 +00:00
|
|
|
snprintf(p, p_max_size, "%s", info.xmms2.url);
|
2011-03-04 18:29:52 +00:00
|
|
|
} else if (artist_len < 1) {
|
|
|
|
snprintf(p, p_max_size, "%s", info.xmms2.title);
|
2009-11-09 22:38:12 +00:00
|
|
|
} else {
|
|
|
|
snprintf(p, p_max_size, "%s - %s", info.xmms2.artist,
|
|
|
|
info.xmms2.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define XMMS2_PRINT_GENERATOR(name, fmt) \
|
|
|
|
void print_xmms2_##name(struct text_object *obj, char *p, int p_max_size) \
|
|
|
|
{ \
|
|
|
|
(void)obj; \
|
|
|
|
snprintf(p, p_max_size, fmt, info.xmms2.name); \
|
|
|
|
}
|
2009-04-28 16:02:24 +00:00
|
|
|
|
2009-11-09 22:38:12 +00:00
|
|
|
XMMS2_PRINT_GENERATOR(artist, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(album, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(title, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(genre, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(comment, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(url, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(status, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(date, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(bitrate, "%i")
|
|
|
|
XMMS2_PRINT_GENERATOR(id, "%u")
|
|
|
|
XMMS2_PRINT_GENERATOR(size, "%2.1f")
|
|
|
|
XMMS2_PRINT_GENERATOR(playlist, "%s")
|
|
|
|
XMMS2_PRINT_GENERATOR(timesplayed, "%i")
|
2010-01-02 19:50:53 +00:00
|
|
|
XMMS2_PRINT_GENERATOR(percent, "%i")
|
2009-11-09 22:38:12 +00:00
|
|
|
|
|
|
|
#undef XMMS2_PRINT_GENERATOR
|
2009-11-16 22:47:44 +00:00
|
|
|
|
2010-01-02 19:50:53 +00:00
|
|
|
int if_xmms2_connected(struct text_object *obj)
|
2009-11-16 22:47:44 +00:00
|
|
|
{
|
|
|
|
(void)obj;
|
|
|
|
|
|
|
|
return info.xmms2.conn_state == CONN_OK;
|
|
|
|
}
|