summaryrefslogtreecommitdiffstats
path: root/arts/kde/kplayobjectcreator.cc
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /arts/kde/kplayobjectcreator.cc
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'arts/kde/kplayobjectcreator.cc')
-rw-r--r--arts/kde/kplayobjectcreator.cc104
1 files changed, 104 insertions, 0 deletions
diff --git a/arts/kde/kplayobjectcreator.cc b/arts/kde/kplayobjectcreator.cc
new file mode 100644
index 000000000..26b4308ab
--- /dev/null
+++ b/arts/kde/kplayobjectcreator.cc
@@ -0,0 +1,104 @@
+ /*
+
+ Copyright (C) 2002 Matthias Welwarsky <mwelwarsky@web.de>
+
+ 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 <kio/kmimetype.h>
+#include "artskde.h"
+#include "kplayobjectcreator.h"
+#include "kplayobjectcreator.moc"
+#include "kioinputstream_impl.h"
+
+#include <qfile.h>
+
+#include <kdebug.h>
+
+KDE::PlayObjectCreator::PlayObjectCreator(Arts::SoundServerV2 server)
+{
+ m_server = server;
+}
+
+KDE::PlayObjectCreator::~PlayObjectCreator()
+{
+}
+
+bool KDE::PlayObjectCreator::create(const KURL& url, bool createBUS, const QObject* receiver, const char* slot)
+{
+ // no need to go any further, and I hate deep indentation
+ if (m_server.isNull() || url.isEmpty() )
+ return false;
+
+ connect( this, SIGNAL( playObjectCreated( Arts::PlayObject ) ),
+ receiver, slot );
+
+ // check if the URL is a local file
+ if (!url.isLocalFile())
+ {
+ m_createBUS = createBUS;
+
+ // This is the RightWay(tm) according to stw
+ Arts::KIOInputStream_impl* instream_impl = new Arts::KIOInputStream_impl();
+ m_instream = Arts::KIOInputStream::_from_base(instream_impl);
+
+ // signal will be called once the ioslave knows the mime-type of the stream
+ connect(instream_impl, SIGNAL(mimeTypeFound(const QString &)),
+ this, SLOT(slotMimeType(const QString &)));
+
+ // GO!
+ m_instream.openURL(url.url().latin1());
+ m_instream.streamStart();
+
+ return true;
+ }
+ kdDebug( 400 ) << "stream is local file: " << url.url() << endl;
+
+ // usual stuff if we have a local file
+ KMimeType::Ptr mimetype = KMimeType::findByURL(url);
+ emit playObjectCreated (
+ m_server.createPlayObjectForURL(std::string(QFile::encodeName(url.path())),
+ std::string(mimetype->name().latin1()),
+ createBUS)
+ );
+ return true;
+}
+
+void KDE::PlayObjectCreator::slotMimeType(const QString& mimetype)
+{
+
+ kdDebug( 400 ) << "slotMimeType called: " << mimetype << endl;
+
+ QString mimetype_copy = mimetype;
+
+ if ( mimetype_copy == "application/octet-stream" )
+ mimetype_copy = QString("audio/x-mp3");
+
+ if (mimetype_copy == "application/x-zerosize")
+ emit playObjectCreated(Arts::PlayObject::null());
+
+ playObject = m_server.createPlayObjectForStream(
+ m_instream,
+ std::string( mimetype_copy.latin1() ),
+ m_createBUS );
+ if ( playObject.isNull() ) {
+ m_instream.streamEnd();
+ emit playObjectCreated( Arts::PlayObject::null() );
+ return;
+ }
+ emit playObjectCreated( playObject );
+}