• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_sound.cpp
1 /* This file is part of the KDE Project
2  Copyright (c) 2001 Malte Starostik <malte@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include <kartsdispatcher.h>
20 #include <kdebug.h>
21 #include <kplayobjectfactory.h>
22 #include <soundserver.h>
23 
24 #include "konq_sound.h"
25 
26 using namespace std;
27 
28 class KonqSoundPlayerImpl : public KonqSoundPlayer
29 {
30 public:
31  KonqSoundPlayerImpl();
32  virtual ~KonqSoundPlayerImpl();
33 
34  virtual const TQStringList &mimeTypes();
35  virtual void play(const TQString &fileName);
36  virtual void stop();
37  virtual bool isPlaying();
38 
39 private:
40  TQStringList m_mimeTypes;
41 
42  KArtsDispatcher m_dispatcher;
43  Arts::SoundServerV2 m_soundServer;
44  KDE::PlayObjectFactory *m_factory;
45  KDE::PlayObject *m_player;
46 };
47 
48 KonqSoundPlayerImpl::KonqSoundPlayerImpl()
49  : m_player(0)
50 {
51  m_soundServer = Arts::Reference("global:Arts_SoundServerV2");
52  m_factory = new KDE::PlayObjectFactory(m_soundServer);
53 }
54 
55 KonqSoundPlayerImpl::~KonqSoundPlayerImpl()
56 {
57  delete m_player;
58  delete m_factory;
59 }
60 
61 const TQStringList &KonqSoundPlayerImpl::mimeTypes()
62 {
63  if (m_mimeTypes.isEmpty())
64  {
65  Arts::TraderQuery query;
66  vector<Arts::TraderOffer> *offers = query.query();
67 
68  for (vector<Arts::TraderOffer>::iterator it = offers->begin();
69  it != offers->end(); ++it)
70  {
71  vector<string> *prop = (*it).getProperty("MimeType");
72  for (vector<string>::iterator mt = prop->begin();
73  mt != prop->end(); ++mt)
74  if ((*mt).length()) // && (*mt).find("video/") == string::npos)
75  m_mimeTypes << (*mt).c_str();
76  delete prop;
77  }
78  delete offers;
79  }
80  return m_mimeTypes;
81 }
82 
83 void KonqSoundPlayerImpl::play(const TQString &fileName)
84 {
85  if (m_soundServer.isNull())
86  return;
87 
88  delete m_player;
89  if ((m_player = m_factory->createPlayObject(fileName, true)))
90  {
91  if (m_player->isNull())
92  stop();
93  else
94  m_player->play();
95  }
96 }
97 
98 void KonqSoundPlayerImpl::stop()
99 {
100  delete m_player;
101  m_player = 0;
102 }
103 
104 bool KonqSoundPlayerImpl::isPlaying()
105 {
106  return m_player ? (m_player->state() == Arts::posPlaying) : false;
107 }
108 
109 class KonqSoundFactory : public KLibFactory
110 {
111 public:
112  KonqSoundFactory(TQObject *parent = 0, const char *name = 0)
113  : KLibFactory(parent, name) {};
114  virtual ~KonqSoundFactory() {};
115 
116 protected:
117  virtual TQObject *createObject(TQObject * = 0, const char * = 0,
118  const char *className = TQOBJECT_OBJECT_NAME_STRING, const TQStringList &args = TQStringList());
119 };
120 
121 TQObject *KonqSoundFactory::createObject(TQObject *, const char *,
122  const char *className, const TQStringList &)
123 {
124  if (qstrcmp(className, "KonqSoundPlayer") == 0)
125  return TQT_TQOBJECT(new KonqSoundPlayerImpl());
126  return 0;
127 }
128 
129 extern "C"
130 {
131  KDE_EXPORT KLibFactory *init_konq_sound()
132  {
133  return new KonqSoundFactory();
134  }
135 }

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.