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

arts

  • arts
  • kde
kplayobjectfactory.cpp
1  /*
2 
3  Copyright (C) 2001 Nikolas Zimmermann <wildfox@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 
20  */
21 
22 #include <tdeio/kmimetype.h>
23 #include "kplayobject.h"
24 #include "artskde.h"
25 #include "kplayobjectfactory.h"
26 #include "kplayobjectfactory_p.h"
27 #include "kplayobjectcreator.h"
28 #include "kioinputstream_impl.h"
29 #include "kartsdispatcher.h"
30 #include "kartsserver.h"
31 
32 #include <tqfile.h>
33 #include <kdebug.h>
34 #include "kaudiomanagerplay.h"
35 #include <flowsystem.h>
36 #include <tdeio/netaccess.h>
37 
38 using namespace std;
39 
40 KPlayObjectFactory::KPlayObjectFactory(Arts::SoundServerV2 server)
41 {
42  m_server = server;
43  m_allowStreaming = true;
44  m_stream = false;
45 }
46 
47 KPlayObjectFactory::KPlayObjectFactory(KArtsServer* server)
48 {
49  m_server = server->server();
50  m_allowStreaming = true;
51  m_stream = false;
52 }
53 
54 KPlayObjectFactory::~KPlayObjectFactory()
55 {
56 }
57 
58 KPlayObject *KPlayObjectFactory::createPlayObject(const KURL& url, bool createBUS)
59 {
60  KMimeType::Ptr mimetype = KMimeType::findByURL(url);
61  return createPlayObject(url, mimetype->name(), createBUS);
62 }
63 
64 
65 KPlayObject *KPlayObjectFactory::createPlayObject(const KURL& _url, const TQString &mimetype, bool createBUS)
66 {
67  // WHY DOES BROKEN TDEIO_MEDIA GIVE WRONG URLS?
68  // I hate it
69  // I hate it
70  // It sucks
71  // tdeio_media please die
72  KURL url = TDEIO::NetAccess::mostLocalURL(_url, 0);
73 
74  if(!m_server.isNull())
75  {
76  if(mimetype == "application/octet-stream" && m_allowStreaming)
77  {
78  Arts::TDEIOInputStream instream;
79  instream.openURL(url.url().latin1());
80 
81  m_stream = true;
82 
83  // TODO: what else than hardcoding audio/x-mp3 ?
84  return new KPlayObject(m_server.createPlayObjectForStream(instream, string("audio/x-mp3"), createBUS), true);
85  }
86  else
87  return new KPlayObject(m_server.createPlayObjectForURL(string(TQFile::encodeName(url.path())), string(mimetype.latin1()), createBUS), false);
88  }
89  else
90  return new KPlayObject();
91 }
92 
93 
94 
95 //
96 
97 KDE::PlayObjectFactory::PlayObjectFactory(Arts::SoundServerV2 server)
98 {
99  d = new PrivateData;
100  d->server = server;
101  d->amanPlay = 0;
102  d->helper = 0;
103  d->allowStreaming = true;
104  d->isStream = false;
105 }
106 
107 KDE::PlayObjectFactory::PlayObjectFactory(KArtsServer* server)
108 {
109  d = new PrivateData;
110  d->server = server->server();
111  d->amanPlay = 0;
112  d->helper = 0;
113  d->allowStreaming = true;
114  d->isStream = false;
115 }
116 
117 KDE::PlayObjectFactory::~PlayObjectFactory()
118 {
119  delete d->helper;
120  delete d;
121 }
122 
123 void KDE::PlayObjectFactory::setAudioManagerPlay( KAudioManagerPlay * amanPlay )
124 {
125  d->amanPlay = amanPlay;
126  if( ! d->helper )
127  d->helper = new POFHelper;
128 }
129 
130 KDE::PlayObject *KDE::PlayObjectFactory::createPlayObject(const KURL& url, bool createBUS)
131 {
132  KMimeType::Ptr mimetype = KMimeType::findByURL(url);
133  return createPlayObject(url, mimetype->name(), createBUS);
134 }
135 
136 KDE::PlayObject *KDE::PlayObjectFactory::createPlayObject(const KURL& _url, const TQString &mimetype, bool createBUS)
137 {
138  // WHY DOES BROKEN TDEIO_MEDIA GIVE WRONG URLS?
139  // I hate it
140  // I hate it
141  // It sucks
142  // tdeio_media please die
143  KURL url = TDEIO::NetAccess::mostLocalURL(_url, 0);
144 
145  // return a NULL playobject if the server is NULL
146  if ( d->server.isNull() || url.isEmpty() )
147  return new KDE::PlayObject();
148 
149  // if the program wants to use it's own Synth_AMAN_PLAY we don't need a
150  // bus
151  if( d->amanPlay && createBUS )
152  {
153  kdWarning( 400 ) << "KDE::PlayObjectFactory was instructed to use a Synth_AMAN_PLAY for output but the program also asked for a Synth_BUS_UPLINK" << endl;
154  createBUS = false;
155  }
156 
157  // decide if it's a local file. mpeglib provides cdda reading and decoding, so we prefer that over tdeio_audiocd
158  if ( url.isLocalFile() || !d->allowStreaming || (url.protocol() == "audiocd" && mimetype == "application/x-cda" && mimeTypes().contains( "application/x-cda" ) ) )
159  {
160  // we rely on the delivered mimetype if it's a local file
161  d->playObj = new KDE::PlayObject( d->server.createPlayObjectForURL( string( TQFile::encodeName( url.path() ) ), string( mimetype.latin1() ), createBUS ), false );
162  }
163  else
164  {
165  // if non-local, let the KPlayObject figure out the mimetype itself
166  // this invokes asynchronous creation automatically
167  d->playObj = new KDE::PlayObject( d->server, url, true, createBUS );
168  }
169 
170  if( d->playObj->isNull() )
171  {
172  delete d->playObj;
173  d->playObj = 0;
174  return new KDE::PlayObject(); // return a NULL playobject
175  }
176 
177  if( d->amanPlay )
178  {
179  d->helper->po = d->playObj;
180  d->helper->ap = d->amanPlay;
181  if( d->playObj->object().isNull() && d->amanPlay )
182  TQObject::connect( d->playObj, TQT_SIGNAL( playObjectCreated() ), d->helper, TQT_SLOT( connectAmanPlay() ) );
183  else
184  d->helper->connectAmanPlay();
185  }
186 
187  return d->playObj;
188 }
189 
190 TQStringList KDE::PlayObjectFactory::mimeTypes(void)
191 {
192  KArtsDispatcher dispatcher; // we need such a thing, otherwise we crash
193  Arts::TraderQuery query;
194  vector<Arts::TraderOffer> *offers = query.query();
195 
196  TQStringList results;
197  for(vector<Arts::TraderOffer>::iterator offer = offers->begin();
198  offer != offers->end(); ++offer)
199  {
200  vector<string> *mimetypes = (*offer).getProperty("MimeType");
201 
202  for(vector<string>::iterator mimetype = mimetypes->begin();
203  mimetype != mimetypes->end(); ++mimetype)
204  {
205  TQString name = TQString(TQString::fromLocal8Bit((*mimetype).c_str())).stripWhiteSpace();
206  if(KMimeType::mimeType(name))
207  results.append(name);
208  }
209 
210  delete mimetypes;
211  }
212  delete offers;
213 
214  // clean out duplicates
215  results.sort();
216  for(TQStringList::iterator result = results.begin(); result != results.end(); )
217  {
218  TQStringList::iterator previous = result;
219  ++result;
220  if(result != results.end() && *result == *previous)
221  {
222  results.remove(result);
223  result = previous;
224  }
225  }
226 
227  return results;
228 }
229 
230 /* ### KDE4
231 void KDE::PlayObjectFactory::connectAmanPlay()
232 {
233  kdDebug( 400 ) << k_funcinfo << endl;
234  if( d->playObj->object().isNull() )
235  return;
236 
237  d->amanPlay->start();
238  d->playObj->object()._node()->start();
239  Arts::connect( d->playObj->object(), "left" , d->amanPlay->amanPlay(), "left" );
240  Arts::connect( d->playObj->object(), "right", d->amanPlay->amanPlay(), "right" );
241 }
242 */
243 
244 void KDE::POFHelper::connectAmanPlay()
245 {
246  kdDebug( 400 ) << k_funcinfo << endl;
247  if( po->object().isNull() )
248  return;
249 
250  ap->start();
251  po->object()._node()->start();
252  Arts::connect( po->object(), "left" , ap->amanPlay(), "left" );
253  Arts::connect( po->object(), "right", ap->amanPlay(), "right" );
254 }
255 
256 #include "kplayobjectfactory_p.moc"
KURL
KArtsServer
KArtsServer is a wrapper to conveniently get a reference to a SoundServer, and restart artsd when nec...
Definition: kartsserver.h:37
KArtsServer::server
Arts::SoundServerV2 server(void)
Get a verified reference to the SoundServerV2, (re)starting artsd using the kcontrol-specified settin...
Definition: kartsserver.cpp:47
KArtsDispatcher
KArtsDispatcher ensures that an instance of Arts::Dispatcher using an Arts::QIOManager exists...
Definition: kartsdispatcher.h:64
KURL::protocol
TQString protocol() const
std
kdDebug
kdbgstream kdDebug(int area=0)
KURL::isEmpty
bool isEmpty() const
KDE::PlayObject
This class acts as a general interface to the KDE multimedia framework.
Definition: kplayobject.h:188
KURL::isLocalFile
bool isLocalFile() const
kdWarning
kdbgstream kdWarning(int area=0)
KAudioManagerPlay
KDE Wrapper for Arts::Synth_AMAN_PLAY.
Definition: kaudiomanagerplay.h:38
KDE::PlayObjectFactory::createPlayObject
KDE::PlayObject * createPlayObject(const KURL &url, bool createBUS)
Creates a KDE::PlayObject to play back the file or stream url points to.
Definition: kplayobjectfactory.cpp:130
KDE::PlayObjectFactory::PlayObjectFactory
PlayObjectFactory(Arts::SoundServerV2 server)
Creates a KDE::PlayObjectFactory.
Definition: kplayobjectfactory.cpp:97
KDE::PlayObjectFactory::setAudioManagerPlay
void setAudioManagerPlay(KAudioManagerPlay *amanplay)
If this is set the PlayObject doesn't create a Synth_BUS_UPLINK at all but always uses the Synth_AMAN...
Definition: kplayobjectfactory.cpp:123
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
KURL::path
TQString path() const
KDE::PlayObjectFactory::mimeTypes
static TQStringList mimeTypes(void)
Return the mimetypes that are playable.
Definition: kplayobjectfactory.cpp:190
endl
kndbgstream & endl(kndbgstream &s)

arts

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

arts

Skip menu "arts"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for arts by doxygen 1.8.8
This website is maintained by Timothy Pearson.