| # arts Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kplayobjectcreator.cc

    00001     /*
    00002
    00003     Copyright (C) 2002 Matthias Welwarsky <mwelwarsky@web.de>
    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., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    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     // no need to go any further, and I hate deep indentation
    00044     if (m_server.isNull() || url.isEmpty() )
    00045         return false;
    00046
    00047     connect( this, SIGNAL( playObjectCreated( Arts::PlayObject ) ),
    00048             receiver, slot );
    00049
    00050     // check if the URL is a local file
    00051     if (!url.isLocalFile())
    00052     {
    00053         m_createBUS = createBUS;
    00054
    00055         // This is the RightWay(tm) according to stw
    00056         Arts::KIOInputStream_impl* instream_impl = new Arts::KIOInputStream_impl();
    00057         m_instream = Arts::KIOInputStream::_from_base(instream_impl);
    00058
    00059         // signal will be called once the ioslave knows the mime-type of the stream
    00060         connect(instream_impl, SIGNAL(mimeTypeFound(const QString &)),
    00061                  this, SLOT(slotMimeType(const QString &)));
    00062
    00063         // GO!
    00064         m_instream.openURL(url.url().latin1());
    00065         m_instream.streamStart();
    00066
    00067         return true;
    00068     }
    00069     kdDebug( 400 ) << "stream is local file: " << url.url() << endl;
    00070
    00071     // usual stuff if we have a local file
    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( 400 ) << "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.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:27:55 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003