• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
noatunsensor.cpp
1/***************************************************************************
2 * Copyright (C) 2003 by Hans Karlsson *
3 * karlsson.h@home.se *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10#include "noatunsensor.h"
11
12NoatunSensor::NoatunSensor( int interval, DCOPClient *c)
13 : Sensor( interval )
14{
15 client = c;
16 noatunID = "noatun";
17}
18
19
20NoatunSensor::~NoatunSensor()
21{}
22
23
24void NoatunSensor::update()
25{
26 TQString format;
27 SensorParams *sp;
28 Meter *meter;
29 TQObjectListIt it( *objList );
30
31 TQString title;
32 int songLength = 0;
33 int currentTime = 0;
34
35 bool running = isRunning();
36
37 if( running )
38 {
39 title = getTitle();
40
41 if( title.isEmpty() )
42 title = "Noatun";
43 currentTime = getTime();
44 if( currentTime == -1 )
45 currentTime = 0;
46
47 songLength = getLength();
48 if( songLength == -1 )
49 songLength = 0;
50 }
51
52
53 while (it != 0)
54 {
55 sp = (SensorParams*)(*it);
56 meter = sp->getMeter();
57
58 if( running )
59 {
60
61 format = sp->getParam("FORMAT");
62 if (format.length() == 0 )
63 {
64 format = "%title %time / %length";
65 }
66
67 if( format.lower() == "%ms" )
68 {
69 meter->setMax( songLength );
70 meter->setValue( currentTime );
71 }
72 else
73 if ( format.lower() == "%full" )
74 {
75 meter->setValue( 1 );
76 }
77 else
78
79 {
80 format.replace( TQRegExp("%title", false), title );
81 format.replace( TQRegExp("%id", false), noatunID );
82
83 format.replace( TQRegExp("%length", false), TQTime( 0,0,0 ).
84 addMSecs( songLength )
85 .toString( "h:mm:ss" ) );
86
87 format.replace( TQRegExp("%time", false), TQTime( 0,0,0 ).
88 addMSecs( currentTime )
89 .toString( "h:mm:ss" ) );
90 format.replace( TQRegExp("%remain", false), TQTime( 0,0,0 ).
91 addMSecs( songLength )
92 .addMSecs(-currentTime )
93 .toString( "h:mm:ss" ) );
94
95 meter->setValue(format);
96 }
97 }
98 else
99
100 {
101 meter->setValue("");
102 }
103 ++it;
104
105
106 }
107
108}
109
110bool NoatunSensor::isRunning()
111{
112 TQRegExp rx("(noatun)|(noatun-\\d+)");
113 QCStringList list = client->registeredApplications();
114 TQValueList<TQCString>::iterator it;
115 it = list.begin();
116 bool foundNoatun = false;
117 noatunID = "noatun";
118 while( foundNoatun == false && it != list.end() )
119 {
120 if( rx.search( *it ) != -1 )
121 {
122 foundNoatun = true;
123 noatunID = *it;
124 }
125 ++it;
126 }
127 return ( client->isApplicationRegistered ( noatunID ) );
128}
129
130
131TQString NoatunSensor::getTitle()
132{
133 TQByteArray data, replyData;
134 TQCString replyType;
135 TQString result;
136 TQDataStream arg(data, IO_WriteOnly);
137 arg << 5;
138 if (!client->call( noatunID, "Noatun", "title()",
139 data, replyType, replyData))
140 {
141 result = "";
142 tqDebug("there was some error using DCOP.");
143 }
144 else
145 {
146 TQDataStream reply(replyData, IO_ReadOnly);
147 if (replyType == "TQString")
148 {
149 reply >> result;
150 result.replace( TQRegExp("_")," " );
151 result.replace( TQRegExp(".mp3$"),"" );
152
153 }
154 else
155 {
156 result = "";
157 tqDebug("title returned an unexpected type of reply!");
158 }
159 }
160 return result;
161}
162
163
164int NoatunSensor::getTime()
165{
166 TQByteArray data, replyData;
167 TQCString replyType;
168 int result;
169 TQDataStream arg(data, IO_WriteOnly);
170 arg << 5;
171 if (!client->call( noatunID, "Noatun", "position()",
172 data, replyType, replyData))
173 {
174 result = 0;
175 tqDebug("there was some error using DCOP.");
176 }
177 else
178 {
179 TQDataStream reply(replyData, IO_ReadOnly);
180 if (replyType == "int")
181 {
182 reply >> result;
183 }
184 else
185 {
186 result = 0;
187 tqDebug("title returned an unexpected type of reply!");
188 }
189 }
190 return result;
191}
192
193
194int NoatunSensor::getLength()
195{
196 TQByteArray data, replyData;
197 TQCString replyType;
198 int result;
199 TQDataStream arg(data, IO_WriteOnly);
200 arg << 5;
201 if (!client->call( noatunID, "Noatun", "length()",
202 data, replyType, replyData))
203 {
204 result = 0;
205 tqDebug("there was some error using DCOP.");
206 }
207 else
208 {
209 TQDataStream reply(replyData, IO_ReadOnly);
210 if (replyType == "int")
211 {
212 reply >> result;
213 }
214 else
215 {
216 result = 0;
217 tqDebug("title returned an unexpected type of reply!");
218 }
219 }
220 return result;
221}
222
223
224void NoatunSensor::setMaxValue( SensorParams *sp)
225{
226 Meter *meter;
227 meter = sp->getMeter();
228 TQString f;
229 f = sp->getParam("FORMAT");
230
231 if ( f == "%full" )
232 meter->setMax( 1 );
233
234}
SensorParams
Hans Karlsson.
Definition: sensorparams.h:32

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.