konq_sound.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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())
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
This file is part of the documentation for libkonq Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 5 04:41:09 2004 by
doxygen 1.3.6-20040222 written by
Dimitri van Heesch, © 1997-2003