19 #include <kartsdispatcher.h>
21 #include <kplayobjectfactory.h>
22 #include <soundserver.h>
24 #include "konq_sound.h"
28 class KonqSoundPlayerImpl :
public KonqSoundPlayer
31 KonqSoundPlayerImpl();
32 virtual ~KonqSoundPlayerImpl();
34 virtual const TQStringList &mimeTypes();
35 virtual void play(
const TQString &fileName);
37 virtual bool isPlaying();
40 TQStringList m_mimeTypes;
42 KArtsDispatcher m_dispatcher;
43 Arts::SoundServerV2 m_soundServer;
44 KDE::PlayObjectFactory *m_factory;
45 KDE::PlayObject *m_player;
48 KonqSoundPlayerImpl::KonqSoundPlayerImpl()
51 m_soundServer = Arts::Reference(
"global:Arts_SoundServerV2");
52 m_factory =
new KDE::PlayObjectFactory(m_soundServer);
55 KonqSoundPlayerImpl::~KonqSoundPlayerImpl()
61 const TQStringList &KonqSoundPlayerImpl::mimeTypes()
63 if (m_mimeTypes.isEmpty())
65 Arts::TraderQuery query;
66 vector<Arts::TraderOffer> *offers = query.query();
68 for (vector<Arts::TraderOffer>::iterator it = offers->begin();
69 it != offers->end(); ++it)
71 vector<string> *prop = (*it).getProperty(
"MimeType");
72 for (vector<string>::iterator mt = prop->begin();
73 mt != prop->end(); ++mt)
75 m_mimeTypes << (*mt).c_str();
83 void KonqSoundPlayerImpl::play(
const TQString &fileName)
85 if (m_soundServer.isNull())
89 if ((m_player = m_factory->createPlayObject(fileName,
true)))
91 if (m_player->isNull())
98 void KonqSoundPlayerImpl::stop()
104 bool KonqSoundPlayerImpl::isPlaying()
106 return m_player ? (m_player->state() == Arts::posPlaying) :
false;
109 class KonqSoundFactory :
public KLibFactory
112 KonqSoundFactory(TQObject *parent = 0,
const char *name = 0)
113 : KLibFactory(parent, name) {};
114 virtual ~KonqSoundFactory() {};
117 virtual TQObject *createObject(TQObject * = 0,
const char * = 0,
118 const char *className =
"TQObject",
const TQStringList &args = TQStringList());
121 TQObject *KonqSoundFactory::createObject(TQObject *,
const char *,
122 const char *className,
const TQStringList &)
124 if (qstrcmp(className,
"KonqSoundPlayer") == 0)
125 return new KonqSoundPlayerImpl();
131 TDE_EXPORT KLibFactory *init_konq_sound()
133 return new KonqSoundFactory();