kplayobject.cc

00001     /*
00002 
00003     Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009   
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 
00020     */
00021 
00022 #include "kplayobject.h"
00023 #include "kplayobject.moc"
00024 #include "kplayobjectcreator.h"
00025 #include <kdebug.h>
00026 
00027 KPlayObject::KPlayObject() : QObject()
00028 {
00029     m_playObject = Arts::PlayObject::null();
00030     m_isStream = false;
00031 }
00032 
00033 KPlayObject::KPlayObject(Arts::PlayObject playobject, bool isStream) : QObject()
00034 {
00035     m_playObject = playobject;
00036     m_isStream = isStream;
00037 }
00038 
00039 KPlayObject::~KPlayObject()
00040 {
00041 }
00042 
00043 void KPlayObject::play()
00044 {
00045     object().play();
00046 }
00047 
00048 void KPlayObject::seek(Arts::poTime newTime)
00049 {
00050     if(!m_isStream)
00051         object().seek(newTime);
00052     else
00053         kdDebug( 400 ) << "Seeking in a Stream? huh?" << endl;
00054 }
00055 
00056 void KPlayObject::pause()
00057 {
00058     object().pause();
00059 }
00060 
00061 void KPlayObject::halt()
00062 {
00063     object().halt();
00064 }
00065 
00066 QString KPlayObject::description()
00067 {
00068     return QString::fromLatin1(object().description().c_str());
00069 }
00070 
00071 Arts::poTime KPlayObject::currentTime()
00072 {
00073     return object().currentTime();
00074 }
00075 
00076 Arts::poTime KPlayObject::overallTime()
00077 {
00078     return object().overallTime();
00079 }
00080 
00081 Arts::poCapabilities KPlayObject::capabilities()
00082 {
00083     return object().capabilities();
00084 }
00085 
00086 QString KPlayObject::mediaName()
00087 {
00088     return QString::fromLatin1(object().mediaName().c_str());
00089 }
00090 
00091 Arts::poState KPlayObject::state()
00092 {
00093     return object().state();
00094 }
00095 
00096 Arts::PlayObject KPlayObject::object()
00097 {
00098     return m_playObject;
00099 }
00100 
00101 bool KPlayObject::isNull()
00102 {
00103     if( !this )
00104         return true;
00105     return object().isNull();
00106 }
00107 
00108 void KPlayObject::setObject(Arts::PlayObject playObject)
00109 {
00110     m_playObject = playObject;
00111 }
00112 
00113 bool KPlayObject::stream()
00114 {
00115     return m_isStream;
00116 }
00117 
00118 struct KDE::PlayObject::PrivateData
00119 {
00120     PrivateData() : creator( 0 ), 
00121             isProxy( false ),
00122             internalState( Arts::posIdle ) {}
00123     ~PrivateData() {
00124         delete creator;
00125     }
00126     Arts::SoundServerV2 server;
00127     KDE::PlayObjectCreator* creator;
00128     bool createBUS;
00129     bool isProxy;
00130     Arts::poState internalState;
00131     KURL url;
00132 };
00133 
00134 KDE::PlayObject::PlayObject() : QObject()
00135 {
00136     m_playObject = Arts::PlayObject::null();
00137     m_isStream = false;
00138     d = new PrivateData;
00139 }
00140 
00141 KDE::PlayObject::PlayObject(Arts::PlayObject playobject, bool isStream) : QObject()
00142 {
00143     m_playObject = playobject;
00144     m_isStream = isStream;
00145     d = new PrivateData;
00146 
00147     //very funny! you can't connect to signals before creating
00148     //the object - so nobody will ever receive this signal (mkretz)
00149     //
00150     //emit playObjectCreated();
00151 }
00152 
00153 KDE::PlayObject::PlayObject( Arts::SoundServerV2 server, const KURL& url, bool isStream, bool createBUS ) : QObject()
00154 {
00155     kdDebug( 400 ) << "KDE::PlayObject: created as proxy for URL " << url.url()<< endl;
00156 
00157     m_playObject = Arts::PlayObject::null();
00158     m_isStream = isStream;
00159     d = new PrivateData;
00160     d->server = server;
00161     d->url = url;
00162     d->createBUS = createBUS;
00163     d->isProxy = true;
00164 }
00165 
00166 KDE::PlayObject::~PlayObject()
00167 {
00168     kdDebug( 400 ) << "KDE::PlayObject: destroyed" << endl;
00169 
00170     delete d;
00171 }
00172 
00173 void KDE::PlayObject::play()
00174 {
00175     kdDebug( 400 ) << "KDE::PlayObject::play()" << endl;
00176 
00177     if ( object().isNull() ) {
00178         if ( m_isStream ) {
00179             if ( d->creator )
00180                 delete d->creator;
00181             d->creator = new KDE::PlayObjectCreator( d->server );
00182             d->creator->create( d->url, d->createBUS, this, SLOT( attachPlayObject( Arts::PlayObject ) ) );
00183             kdDebug( 400 ) << "KDE::PlayObject::play(): creator called" << endl;
00184             d->internalState = Arts::posPlaying;
00185         }
00186         return;
00187     }
00188     object().play();
00189 }
00190 
00191 void KDE::PlayObject::attachPlayObject( Arts::PlayObject playObject )
00192 {
00193     kdDebug( 400 ) << "KDE::PlayObject::attachPlayObject()" << endl;
00194 
00195     m_playObject = playObject;
00196     emit playObjectCreated();
00197     if ( object().isNull() )
00198         return;
00199     switch ( d->internalState ) {
00200     case Arts::posIdle:
00201         object().halt();
00202         break;
00203     case Arts::posPaused:
00204         object().pause();
00205         break;
00206     case Arts::posPlaying:
00207         object().play ();
00208         break;
00209     }
00210 }
00211 
00212 void KDE::PlayObject::seek(Arts::poTime newTime)
00213 {
00214     if ( object().isNull() )
00215         return;
00216     if(!m_isStream)
00217         object().seek(newTime);
00218     else
00219         kdDebug( 400 ) << "Seeking in a Stream? huh?" << endl;
00220 }
00221 
00222 void KDE::PlayObject::pause()
00223 {
00224     if ( !object().isNull() )
00225         object().pause();
00226     d->internalState = Arts::posPaused;
00227 }
00228 
00229 void KDE::PlayObject::halt()
00230 {
00231     kdDebug( 400 ) << "KDE::PlayObject::halt()" << endl;
00232     if ( !object().isNull() )
00233         object().halt();
00234     else if ( d->creator ) {
00235         delete d->creator;
00236         d->creator = 0;
00237         kdDebug( 400 ) << "KDE::PlayObject::halt(): creator destroyed" << endl;
00238     }
00239     d->internalState = Arts::posIdle;
00240 }
00241 
00242 QString KDE::PlayObject::description()
00243 {
00244     if ( object().isNull() )
00245         return QString();
00246     return QString::fromLatin1(object().description().c_str());
00247 }
00248 
00249 Arts::poTime KDE::PlayObject::currentTime()
00250 {
00251     if ( object().isNull() )
00252         return Arts::poTime( 0, 0, -1, "" );
00253     return object().currentTime();
00254 }
00255 
00256 Arts::poTime KDE::PlayObject::overallTime()
00257 {
00258     if ( object().isNull() )
00259         return Arts::poTime( 0, 0, -1, "" );
00260     return object().overallTime();
00261 }
00262 
00263 Arts::poCapabilities KDE::PlayObject::capabilities()
00264 {
00265     if ( object().isNull() )
00266         return static_cast<Arts::poCapabilities>( 0 );
00267     return object().capabilities();
00268 }
00269 
00270 QString KDE::PlayObject::mediaName()
00271 {
00272     if ( object().isNull() )
00273         return QString();
00274     return QString::fromLatin1(object().mediaName().c_str());
00275 }
00276 
00277 Arts::poState KDE::PlayObject::state()
00278 {
00279     if ( object().isNull() )
00280         return d->internalState;
00281     return object().state();
00282 }
00283 
00284 Arts::PlayObject KDE::PlayObject::object()
00285 {
00286     return m_playObject;
00287 }
00288 
00289 bool KDE::PlayObject::isNull()
00290 {
00291     if ( !this )
00292         return true;
00293     if ( d->isProxy )
00294         return false;
00295     return object().isNull();
00296 }
00297 
00298 bool KDE::PlayObject::stream()
00299 {
00300     return m_isStream;
00301 }
00302 
00303 // vim: sw=4 ts=4 noet
KDE Home | KDE Accessibility Home | Description of Access Keys