1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/***************************************************************************
* Copyright (C) 2003 by Hans Karlsson *
* karlsson.h@home.se *
* *
* 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 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "xmmssensor.h"
#ifdef HAVE_XMMS
#include <xmmsctrl.h>
#endif // HAVE_XMMS
XMMSSensor::XMMSSensor( int interval, const QString &encoding )
: Sensor( interval )
{
if( !encoding.isEmpty() )
{
codec = QTextCodec::codecForName( encoding.ascii() );
if ( codec == 0)
codec = QTextCodec::codecForLocale();
}
else
codec = QTextCodec::codecForLocale();
}
XMMSSensor::~XMMSSensor()
{}
void XMMSSensor::update()
{
QString format;
SensorParams *sp;
Meter *meter;
QObjectListIt it( *objList );
#ifdef HAVE_XMMS
int pos;
QString title;
int songLength = 0;
int currentTime = 0;
bool isPlaying = false;
bool isRunning = xmms_remote_is_running(0);
if( isRunning )
{
isPlaying = xmms_remote_is_playing(0);
pos = xmms_remote_get_playlist_pos(0);
qDebug("unicode start");
title = codec->toUnicode( QCString( xmms_remote_get_playlist_title( 0, pos ) ) );
qDebug("unicode end");
if( title.isEmpty() )
title = "XMMS";
qDebug("Title: %s", title.ascii());
songLength = xmms_remote_get_playlist_time( 0, pos );
currentTime = xmms_remote_get_output_time( 0 );
}
#endif // HAVE_XMMS
while (it != 0)
{
sp = (SensorParams*)(*it);
meter = sp->getMeter();
#ifdef HAVE_XMMS
if( isRunning )
{
format = sp->getParam("FORMAT");
if (format.length() == 0 )
{
format = "%title %time / %length";
}
if( format == "%ms" )
{
meter->setMax( songLength );
meter->setValue( currentTime );
}
else
if ( format == "%full" )
{
meter->setValue( 1 );
}
else
{
format.replace( QRegExp("%title", false), title );
format.replace( QRegExp("%length", false), QTime( 0,0,0 ).
addMSecs( songLength )
.toString( "h:mm:ss" ) );
format.replace( QRegExp("%time", false), QTime( 0,0,0 ).
addMSecs( currentTime )
.toString( "h:mm:ss" ) );
if( isPlaying )
{
format.replace( QRegExp("%remain", false), QTime( 0,0,0 ).
addMSecs( songLength )
.addMSecs(-currentTime )
.toString( "h:mm:ss" ) );
}
else
{
format.replace( QRegExp("%remain", false), QTime( 0,0,0 ).toString("h:mm:ss" ) );
}
meter->setValue(format);
}
}
else
#endif // HAVE_XMMS
{
meter->setValue("");
}
++it;
}
}
void XMMSSensor::setMaxValue( SensorParams *sp)
{
Meter *meter;
meter = sp->getMeter();
QString f;
f = sp->getParam("FORMAT");
if ( f == "%full" )
meter->setMax( 1 );
}
#include "xmmssensor.moc"
|