arts Library API Documentation

kplayobjectfactory.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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 00020 */ 00021 00022 #include <kio/kmimetype.h> 00023 #include "kplayobject.h" 00024 #include "artskde.h" 00025 #include "kplayobjectfactory.h" 00026 #include "kplayobjectfactory_p.h" 00027 #include "kplayobjectcreator.h" 00028 #include "kioinputstream_impl.h" 00029 #include "kartsdispatcher.h" 00030 #include "kartsserver.h" 00031 00032 #include <qfile.h> 00033 #include <kdebug.h> 00034 #include "kaudiomanagerplay.h" 00035 #include <flowsystem.h> 00036 00037 using namespace std; 00038 00039 KPlayObjectFactory::KPlayObjectFactory(Arts::SoundServerV2 server) 00040 { 00041 m_server = server; 00042 m_allowStreaming = true; 00043 m_stream = false; 00044 } 00045 00046 KPlayObjectFactory::KPlayObjectFactory(KArtsServer* server) 00047 { 00048 m_server = server->server(); 00049 m_allowStreaming = true; 00050 m_stream = false; 00051 } 00052 00053 KPlayObjectFactory::~KPlayObjectFactory() 00054 { 00055 } 00056 00057 KPlayObject *KPlayObjectFactory::createPlayObject(const KURL& url, bool createBUS) 00058 { 00059 KMimeType::Ptr mimetype = KMimeType::findByURL(url); 00060 return createPlayObject(url, mimetype->name(), createBUS); 00061 } 00062 00063 KPlayObject *KPlayObjectFactory::createPlayObject(const KURL& url, const QString &mimetype, bool createBUS) 00064 { 00065 if(!m_server.isNull()) 00066 { 00067 if(mimetype == "application/octet-stream" && m_allowStreaming) 00068 { 00069 Arts::KIOInputStream instream; 00070 instream.openURL(url.url().latin1()); 00071 00072 m_stream = true; 00073 00074 // TODO: what else than hardcoding audio/x-mp3 ? 00075 return new KPlayObject(m_server.createPlayObjectForStream(instream, string("audio/x-mp3"), createBUS), true); 00076 } 00077 else 00078 return new KPlayObject(m_server.createPlayObjectForURL(string(QFile::encodeName(url.path())), string(mimetype.latin1()), createBUS), false); 00079 } 00080 else 00081 return new KPlayObject(); 00082 } 00083 00084 00085 00086 // 00087 00088 KDE::PlayObjectFactory::PlayObjectFactory(Arts::SoundServerV2 server) 00089 { 00090 d = new PrivateData; 00091 d->server = server; 00092 d->amanPlay = 0; 00093 d->helper = 0; 00094 d->allowStreaming = true; 00095 d->isStream = false; 00096 } 00097 00098 KDE::PlayObjectFactory::PlayObjectFactory(KArtsServer* server) 00099 { 00100 d = new PrivateData; 00101 d->server = server->server(); 00102 d->amanPlay = 0; 00103 d->helper = 0; 00104 d->allowStreaming = true; 00105 d->isStream = false; 00106 } 00107 00108 KDE::PlayObjectFactory::~PlayObjectFactory() 00109 { 00110 delete d->helper; 00111 delete d; 00112 } 00113 00114 void KDE::PlayObjectFactory::setAudioManagerPlay( KAudioManagerPlay * amanPlay ) 00115 { 00116 d->amanPlay = amanPlay; 00117 if( ! d->helper ) 00118 d->helper = new POFHelper; 00119 } 00120 00121 KDE::PlayObject *KDE::PlayObjectFactory::createPlayObject(const KURL& url, bool createBUS) 00122 { 00123 KMimeType::Ptr mimetype = KMimeType::findByURL(url); 00124 return createPlayObject(url, mimetype->name(), createBUS); 00125 } 00126 00127 KDE::PlayObject *KDE::PlayObjectFactory::createPlayObject(const KURL& url, const QString &mimetype, bool createBUS) 00128 { 00129 // return a NULL playobject if the server is NULL 00130 if ( d->server.isNull() || url.isEmpty() ) 00131 return new KDE::PlayObject(); 00132 00133 // if the program wants to use it's own Synth_AMAN_PLAY we don't need a 00134 // bus 00135 if( d->amanPlay && createBUS ) 00136 { 00137 kdWarning( 400 ) << "KDE::PlayObjectFactory was instructed to use a Synth_AMAN_PLAY for output but the program also asked for a Synth_BUS_UPLINK" << endl; 00138 createBUS = false; 00139 } 00140 00141 // decide if it's a local file. mpeglib provides cdda reading and decoding, so we prefer that over kio_audiocd 00142 if ( url.isLocalFile() || !d->allowStreaming || (url.protocol() == "audiocd" && mimetype == "application/x-cda" && mimeTypes().contains( "application/x-cda" ) ) ) 00143 { 00144 // we rely on the delivered mimetype if it's a local file 00145 d->playObj = new KDE::PlayObject( d->server.createPlayObjectForURL( string( QFile::encodeName( url.path() ) ), string( mimetype.latin1() ), createBUS ), false ); 00146 } 00147 else 00148 { 00149 // if non-local, let the KPlayObject figure out the mimetype itself 00150 // this invokes asynchronous creation automatically 00151 d->playObj = new KDE::PlayObject( d->server, url, true, createBUS ); 00152 } 00153 00154 if( d->playObj->isNull() ) 00155 { 00156 delete d->playObj; 00157 d->playObj = 0; 00158 return new KDE::PlayObject(); // return a NULL playobject 00159 } 00160 00161 if( d->amanPlay ) 00162 { 00163 d->helper->po = d->playObj; 00164 d->helper->ap = d->amanPlay; 00165 if( d->playObj->object().isNull() && d->amanPlay ) 00166 QObject::connect( d->playObj, SIGNAL( playObjectCreated() ), d->helper, SLOT( connectAmanPlay() ) ); 00167 else 00168 d->helper->connectAmanPlay(); 00169 } 00170 00171 return d->playObj; 00172 } 00173 00174 QStringList KDE::PlayObjectFactory::mimeTypes(void) 00175 { 00176 KArtsDispatcher dispatcher; // we need such a thing, otherwise we crash 00177 Arts::TraderQuery query; 00178 vector<Arts::TraderOffer> *offers = query.query(); 00179 00180 QStringList results; 00181 for(vector<Arts::TraderOffer>::iterator offer = offers->begin(); 00182 offer != offers->end(); ++offer) 00183 { 00184 vector<string> *mimetypes = (*offer).getProperty("MimeType"); 00185 00186 for(vector<string>::iterator mimetype = mimetypes->begin(); 00187 mimetype != mimetypes->end(); ++mimetype) 00188 { 00189 QString name = QString::fromLocal8Bit((*mimetype).c_str()).stripWhiteSpace(); 00190 if(KMimeType::mimeType(name)) 00191 results.append(name); 00192 } 00193 00194 delete mimetypes; 00195 } 00196 delete offers; 00197 00198 // clean out duplicates 00199 results.sort(); 00200 for(QStringList::iterator result = results.begin(); result != results.end(); ) 00201 { 00202 QStringList::iterator previous = result; 00203 ++result; 00204 if(result != results.end() && *result == *previous) 00205 { 00206 results.remove(result); 00207 result = previous; 00208 } 00209 } 00210 00211 return results; 00212 } 00213 00214 /* ### KDE4 00215 void KDE::PlayObjectFactory::connectAmanPlay() 00216 { 00217 kdDebug( 400 ) << k_funcinfo << endl; 00218 if( d->playObj->object().isNull() ) 00219 return; 00220 00221 d->amanPlay->start(); 00222 d->playObj->object()._node()->start(); 00223 Arts::connect( d->playObj->object(), "left" , d->amanPlay->amanPlay(), "left" ); 00224 Arts::connect( d->playObj->object(), "right", d->amanPlay->amanPlay(), "right" ); 00225 } 00226 */ 00227 00228 void KDE::POFHelper::connectAmanPlay() 00229 { 00230 kdDebug( 400 ) << k_funcinfo << endl; 00231 if( po->object().isNull() ) 00232 return; 00233 00234 ap->start(); 00235 po->object()._node()->start(); 00236 Arts::connect( po->object(), "left" , ap->amanPlay(), "left" ); 00237 Arts::connect( po->object(), "right", ap->amanPlay(), "right" ); 00238 } 00239 00240 #include "kplayobjectfactory_p.moc" 00241 00242 // vim: sw=4 ts=4 noet
KDE Logo
This file is part of the documentation for arts Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Aug 30 22:55:01 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003