kplayobjectcreator.cc
00001     
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include <kio/kmimetype.h>
00023 #include "artskde.h"
00024 #include "kplayobjectcreator.h"
00025 #include "kplayobjectcreator.moc"
00026 #include "kioinputstream_impl.h"
00027 
00028 #include <qfile.h>
00029 
00030 #include <kdebug.h>
00031 
00032 KDE::PlayObjectCreator::PlayObjectCreator(Arts::SoundServerV2 server)
00033 {
00034     m_server = server;
00035 }
00036 
00037 KDE::PlayObjectCreator::~PlayObjectCreator()
00038 {
00039 }
00040 
00041 bool KDE::PlayObjectCreator::create(const KURL& url, bool createBUS, const QObject* receiver, const char* slot)
00042 {
00043     
00044     if (m_server.isNull() || url.isEmpty() )
00045         return false;
00046 
00047     connect( this, SIGNAL( playObjectCreated( Arts::PlayObject ) ),
00048             receiver, slot );
00049 
00050     
00051     if (!url.isLocalFile())
00052     {
00053         m_createBUS = createBUS;
00054 
00055         
00056         Arts::KIOInputStream_impl* instream_impl = new Arts::KIOInputStream_impl();
00057         m_instream = Arts::KIOInputStream::_from_base(instream_impl);
00058 
00059         
00060         connect(instream_impl, SIGNAL(mimeTypeFound(const QString &)),
00061                  this, SLOT(slotMimeType(const QString &)));
00062 
00063         
00064         m_instream.openURL(url.url().latin1());
00065         m_instream.streamStart();
00066 
00067         return true;
00068     }
00069     kdDebug() << "stream is local file: " << url.url() << endl;
00070 
00071     
00072     KMimeType::Ptr mimetype = KMimeType::findByURL(url);
00073     emit playObjectCreated (
00074         m_server.createPlayObjectForURL(std::string(QFile::encodeName(url.path())), 
00075                          std::string(mimetype->name().latin1()), 
00076                          createBUS)
00077         );
00078     return true;
00079 }
00080 
00081 void KDE::PlayObjectCreator::slotMimeType(const QString& mimetype)
00082 {
00083 
00084     kdDebug() << "slotMimeType called: " << mimetype << endl;
00085 
00086     QString mimetype_copy = mimetype;
00087 
00088     if ( mimetype_copy == "application/octet-stream" )
00089         mimetype_copy = QString("audio/x-mp3");
00090 
00091     if (mimetype_copy == "application/x-zerosize")
00092         emit playObjectCreated(Arts::PlayObject::null());
00093 
00094     playObject = m_server.createPlayObjectForStream( 
00095                     m_instream,
00096                     std::string( mimetype_copy.latin1() ),
00097                     m_createBUS );
00098     if ( playObject.isNull() ) {
00099         m_instream.streamEnd();
00100         emit playObjectCreated( Arts::PlayObject::null() );
00101         return;
00102     }
00103     emit playObjectCreated( playObject );
00104 }
 
This file is part of the documentation for arts Library Version 3.2.0.