libkonq Library API Documentation

konq_sound.cc

00001 /* This file is part of the KDE Project 00002 Copyright (c) 2001 Malte Starostik <malte@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00016 Boston, MA 02111-1307, USA. 00017 */ 00018 00019 // $Id: konq_sound.cc,v 1.17 2003/07/26 10:41:28 mueller Exp $ 00020 00021 #include <kartsdispatcher.h> 00022 #include <kdebug.h> 00023 #include <kplayobjectfactory.h> 00024 #include <soundserver.h> 00025 00026 #include "konq_sound.h" 00027 00028 using namespace std; 00029 00030 class KonqSoundPlayerImpl : public KonqSoundPlayer 00031 { 00032 public: 00033 KonqSoundPlayerImpl(); 00034 virtual ~KonqSoundPlayerImpl(); 00035 00036 virtual const QStringList &mimeTypes(); 00037 virtual void play(const QString &fileName); 00038 virtual void stop(); 00039 00040 private: 00041 QStringList m_mimeTypes; 00042 00043 KArtsDispatcher m_dispatcher; 00044 Arts::SoundServerV2 m_soundServer; 00045 KDE::PlayObjectFactory *m_factory; 00046 KDE::PlayObject *m_player; 00047 }; 00048 00049 KonqSoundPlayerImpl::KonqSoundPlayerImpl() 00050 : m_player(0) 00051 { 00052 m_soundServer = Arts::Reference("global:Arts_SoundServerV2"); 00053 m_factory = new KDE::PlayObjectFactory(m_soundServer); 00054 } 00055 00056 KonqSoundPlayerImpl::~KonqSoundPlayerImpl() 00057 { 00058 delete m_player; 00059 delete m_factory; 00060 } 00061 00062 const QStringList &KonqSoundPlayerImpl::mimeTypes() 00063 { 00064 if (m_mimeTypes.isEmpty()) 00065 { 00066 Arts::TraderQuery query; 00067 vector<Arts::TraderOffer> *offers = query.query(); 00068 00069 for (vector<Arts::TraderOffer>::iterator it = offers->begin(); 00070 it != offers->end(); ++it) 00071 { 00072 vector<string> *prop = (*it).getProperty("MimeType"); 00073 for (vector<string>::iterator mt = prop->begin(); 00074 mt != prop->end(); ++mt) 00075 if ((*mt).length()) // && (*mt).find("video/") == string::npos) 00076 m_mimeTypes << (*mt).c_str(); 00077 delete prop; 00078 } 00079 delete offers; 00080 } 00081 return m_mimeTypes; 00082 } 00083 00084 void KonqSoundPlayerImpl::play(const QString &fileName) 00085 { 00086 if (m_soundServer.isNull()) 00087 return; 00088 00089 delete m_player; 00090 if ((m_player = m_factory->createPlayObject(fileName, true))) 00091 { 00092 if (m_player->isNull()) 00093 stop(); 00094 else 00095 m_player->play(); 00096 } 00097 } 00098 00099 void KonqSoundPlayerImpl::stop() 00100 { 00101 delete m_player; 00102 m_player = 0; 00103 } 00104 00105 class KonqSoundFactory : public KLibFactory 00106 { 00107 public: 00108 KonqSoundFactory(QObject *parent = 0, const char *name = 0) 00109 : KLibFactory(parent, name) {}; 00110 virtual ~KonqSoundFactory() {}; 00111 00112 protected: 00113 virtual QObject *createObject(QObject * = 0, const char * = 0, 00114 const char *className = "QObject", const QStringList &args = QStringList()); 00115 }; 00116 00117 QObject *KonqSoundFactory::createObject(QObject *, const char *, 00118 const char *className, const QStringList &) 00119 { 00120 if (qstrcmp(className, "KonqSoundPlayer") == 0) 00121 return new KonqSoundPlayerImpl(); 00122 return 0; 00123 } 00124 00125 extern "C" 00126 { 00127 KLibFactory *init_konq_sound() 00128 { 00129 return new KonqSoundFactory(); 00130 } 00131 } 00132 00133 // vim: ts=4 sw=4 noet
KDE Logo
This file is part of the documentation for libkonq Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Sep 16 15:59:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003