summaryrefslogtreecommitdiffstats
path: root/arts/kde/kplayobject.cpp
blob: a9b3a8a364e09f33e5d1ba40306e670ebbbb2f28 (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
	/*

	Copyright (C) 2001 Nikolas Zimmermann <[email protected]>

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Library General Public
	License as published by the Free Software Foundation; either
	version 2 of the License, or (at your option) any later version.
  
	This library 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
	Library General Public License for more details.

	You should have received a copy of the GNU Library General Public License
	along with this library; see the file COPYING.LIB.  If not, write to
	the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
	Boston, MA 02110-1301, USA.

	*/

#include "kplayobject.h"
#include "kplayobject.moc"
#include "kplayobjectcreator.h"
#include <kdebug.h>

KPlayObject::KPlayObject() : TQObject()
{
	m_playObject = Arts::PlayObject::null();
	m_isStream = false;
}

KPlayObject::KPlayObject(Arts::PlayObject playobject, bool isStream) : TQObject()
{
	m_playObject = playobject;
	m_isStream = isStream;
}

KPlayObject::~KPlayObject()
{
}

void KPlayObject::play()
{
	object().play();
}

void KPlayObject::seek(Arts::poTime newTime)
{
	if(!m_isStream)
		object().seek(newTime);
	else
		kdDebug( 400 ) << "Seeking in a Stream? huh?" << endl;
}

void KPlayObject::pause()
{
	object().pause();
}

void KPlayObject::halt()
{
	object().halt();
}

TQString KPlayObject::description()
{
	return TQString::fromLatin1(object().description().c_str());
}

Arts::poTime KPlayObject::currentTime()
{
	return object().currentTime();
}

Arts::poTime KPlayObject::overallTime()
{
	return object().overallTime();
}

Arts::poCapabilities KPlayObject::capabilities()
{
	return object().capabilities();
}

TQString KPlayObject::mediaName()
{
	return TQString::fromLatin1(object().mediaName().c_str());
}

Arts::poState KPlayObject::state()
{
	return object().state();
}

Arts::PlayObject KPlayObject::object()
{
	return m_playObject;
}

bool KPlayObject::isNull()
{
	if( !this )
		return true;
	return object().isNull();
}

void KPlayObject::setObject(Arts::PlayObject playObject)
{
	m_playObject = playObject;
}

bool KPlayObject::stream()
{
	return m_isStream;
}

struct KDE::PlayObject::PrivateData
{
	PrivateData() : creator( 0 ), 
			isProxy( false ),
			internalState( Arts::posIdle ) {}
	~PrivateData() {
		delete creator;
	}
	Arts::SoundServerV2 server;
	KDE::PlayObjectCreator* creator;
	bool createBUS;
	bool isProxy;
	Arts::poState internalState;
	KURL url;
};

KDE::PlayObject::PlayObject() : TQObject()
{
	m_playObject = Arts::PlayObject::null();
	m_isStream = false;
	d = new PrivateData;
}

KDE::PlayObject::PlayObject(Arts::PlayObject playobject, bool isStream) : TQObject()
{
	m_playObject = playobject;
	m_isStream = isStream;
	d = new PrivateData;

	//very funny! you can't connect to signals before creating
	//the object - so nobody will ever receive this signal (mkretz)
	//
	//emit playObjectCreated();
}

KDE::PlayObject::PlayObject( Arts::SoundServerV2 server, const KURL& url, bool isStream, bool createBUS ) : TQObject()
{
	kdDebug( 400 ) << "KDE::PlayObject: created as proxy for URL " << url.url()<< endl;

	m_playObject = Arts::PlayObject::null();
	m_isStream = isStream;
	d = new PrivateData;
	d->server = server;
	d->url = url;
	d->createBUS = createBUS;
	d->isProxy = true;
}

KDE::PlayObject::~PlayObject()
{
	kdDebug( 400 ) << "KDE::PlayObject: destroyed" << endl;

	delete d;
}

void KDE::PlayObject::play()
{
	kdDebug( 400 ) << "KDE::PlayObject::play()" << endl;

	if ( object().isNull() ) {
		if ( m_isStream ) {
			if ( d->creator )
				delete d->creator;
			d->creator = new KDE::PlayObjectCreator( d->server );
			d->creator->create( d->url, d->createBUS, this, TQ_SLOT( attachPlayObject( Arts::PlayObject ) ) );
			kdDebug( 400 ) << "KDE::PlayObject::play(): creator called" << endl;
			d->internalState = Arts::posPlaying;
		}
		return;
	}
	object().play();
}

void KDE::PlayObject::attachPlayObject( Arts::PlayObject playObject )
{
	kdDebug( 400 ) << "KDE::PlayObject::attachPlayObject()" << endl;

	m_playObject = playObject;
	emit playObjectCreated();
	if ( object().isNull() )
		return;
	switch ( d->internalState ) {
	case Arts::posIdle:
		object().halt();
		break;
	case Arts::posPaused:
		object().pause();
		break;
	case Arts::posPlaying:
		object().play ();
		break;
	}
}

void KDE::PlayObject::seek(Arts::poTime newTime)
{
	if ( object().isNull() )
		return;
	if(!m_isStream)
		object().seek(newTime);
	else
		kdDebug( 400 ) << "Seeking in a Stream? huh?" << endl;
}

void KDE::PlayObject::pause()
{
	if ( !object().isNull() )
		object().pause();
	d->internalState = Arts::posPaused;
}

void KDE::PlayObject::halt()
{
	kdDebug( 400 ) << "KDE::PlayObject::halt()" << endl;
	if ( !object().isNull() )
		object().halt();
	else if ( d->creator ) {
		delete d->creator;
		d->creator = 0;
		kdDebug( 400 ) << "KDE::PlayObject::halt(): creator destroyed" << endl;
	}
	d->internalState = Arts::posIdle;
}

TQString KDE::PlayObject::description()
{
	if ( object().isNull() )
		return TQString();
	return TQString::fromLatin1(object().description().c_str());
}

Arts::poTime KDE::PlayObject::currentTime()
{
	if ( object().isNull() )
		return Arts::poTime( 0, 0, -1, "" );
	return object().currentTime();
}

Arts::poTime KDE::PlayObject::overallTime()
{
	if ( object().isNull() )
		return Arts::poTime( 0, 0, -1, "" );
	return object().overallTime();
}

Arts::poCapabilities KDE::PlayObject::capabilities()
{
	if ( object().isNull() )
		return static_cast<Arts::poCapabilities>( 0 );
	return object().capabilities();
}

TQString KDE::PlayObject::mediaName()
{
	if ( object().isNull() )
		return TQString();
	return TQString::fromLatin1(object().mediaName().c_str());
}

Arts::poState KDE::PlayObject::state()
{
	if ( object().isNull() )
		return d->internalState;
	return object().state();
}

Arts::PlayObject KDE::PlayObject::object()
{
	return m_playObject;
}

bool KDE::PlayObject::isNull()
{
	if ( !this )
		return true;
	if ( d->isProxy )
		return false;
	return object().isNull();
}

bool KDE::PlayObject::stream()
{
	return m_isStream;
}