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

arts

  • arts
  • knotify
knotify.cpp
1 /*
2  Copyright (c) 1997 Christian Esken (esken@kde.org)
3  2000 Charles Samuels (charles@kde.org)
4  2000 Stefan Schimanski (1Stein@gmx.de)
5  2000 Matthias Ettrich (ettrich@kde.org)
6  2000 Waldo Bastian <bastian@kde.org>
7  2000-2003 Carsten Pfeiffer <pfeiffer@kde.org>
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2, or (at your option)
12  any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 // C headers
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 
29 #include <config.h>
30 #ifndef WITHOUT_ARTS
31 // aRts headers
32 #include <connect.h>
33 #include <dispatcher.h>
34 #include <flowsystem.h>
35 #include <qiomanager.h>
36 #include <soundserver.h>
37 #endif
38 
39 // QT headers
40 #include <tqfile.h>
41 #include <tqfileinfo.h>
42 #include <tqstringlist.h>
43 #include <tqtextstream.h>
44 
45 // KDE headers
46 #include <dcopclient.h>
47 #include <kaboutdata.h>
48 #ifndef WITHOUT_ARTS
49 #include <kartsdispatcher.h>
50 #include <kartsserver.h>
51 #endif
52 #include <kcmdlineargs.h>
53 #include <kconfig.h>
54 #include <kdebug.h>
55 #include <kglobal.h>
56 #include <klocale.h>
57 #include <kmessagebox.h>
58 #include <kpassivepopup.h>
59 #include <kiconloader.h>
60 #include <kmacroexpander.h>
61 #ifndef WITHOUT_ARTS
62 #include <kplayobjectfactory.h>
63 #include <kaudiomanagerplay.h>
64 #endif
65 #include <kprocess.h>
66 #include <kstandarddirs.h>
67 #include <kuniqueapplication.h>
68 #include <kwin.h>
69 
70 #include "knotify.h"
71 #include "knotify.moc"
72 
73 class KNotifyPrivate
74 {
75 public:
76  KConfig* globalEvents;
77  KConfig* globalConfig;
78  TQMap<TQString, KConfig*> events;
79  TQMap<TQString, KConfig*> configs;
80  TQString externalPlayer;
81  KProcess *externalPlayerProc;
82 
83 #ifndef WITHOUT_ARTS
84  TQPtrList<KDE::PlayObject> playObjects;
85  TQMap<KDE::PlayObject*,int> playObjectEventMap;
86  KAudioManagerPlay *audioManager;
87 #endif
88  int externalPlayerEventId;
89 
90  bool useExternal;
91  bool useArts;
92  int volume;
93  TQTimer *playTimer;
94  bool inStartup;
95  TQString startupEvents;
96 };
97 
98 // Yes, it's ugly to put this here, but this facilitates the cautious startup
99 // procedure.
100 #ifndef WITHOUT_ARTS
101 KArtsServer *soundServer = 0;
102 #endif
103 
104 extern "C"{
105 
106 KDE_EXPORT int kdemain(int argc, char **argv)
107 {
108  KAboutData aboutdata("knotify", I18N_NOOP("KNotify"),
109  "3.0", I18N_NOOP("KDE Notification Server"),
110  KAboutData::License_GPL, "(C) 1997-2003, KDE Developers");
111  aboutdata.addAuthor("Carsten Pfeiffer",I18N_NOOP("Current Maintainer"),"pfeiffer@kde.org");
112  aboutdata.addAuthor("Christian Esken",0,"esken@kde.org");
113  aboutdata.addAuthor("Stefan Westerfeld",I18N_NOOP("Sound support"),"stefan@space.twc.de");
114  aboutdata.addAuthor("Charles Samuels",I18N_NOOP("Previous Maintainer"),"charles@kde.org");
115 
116  KCmdLineArgs::init( argc, argv, &aboutdata );
117  KUniqueApplication::addCmdLineOptions();
118 
119 
120  // initialize application
121  if ( !KUniqueApplication::start() ) {
122  kdDebug() << "Running knotify found" << endl;
123  return 0;
124  }
125 
126  KUniqueApplication app;
127  app.disableSessionManagement();
128 
129  // KNotify is started on KDE startup and on demand (using
130  // KNotifClient::startDaemon()) whenever a KNotify event occurs. Especially
131  // KWin may fire many events (e.g. when a window pops up). When we have
132  // problems with aRts or the installation, we might get an infinite loop
133  // of knotify crashing, popping up the crashhandler window and kwin firing
134  // another event, starting knotify again...
135  // We try to prevent this by tracking our startup and offer options to
136  // abort this.
137 
138 #ifndef WITHOUT_ARTS
139  KConfigGroup config( KGlobal::config(), "StartProgress" );
140  KConfig artsKCMConfig( "kcmartsrc" );
141  artsKCMConfig.setGroup( "Arts" );
142  bool useArts = artsKCMConfig.readBoolEntry( "StartServer", true );
143  if (useArts)
144  useArts = config.readBoolEntry( "Use Arts", useArts );
145  bool ok = config.readBoolEntry( "Arts Init", true );
146 
147  if ( useArts && !ok )
148  {
149  if ( KMessageBox::questionYesNo(
150  0L,
151  i18n("During the previous startup, KNotify crashed while creating "
152  "Arts::Dispatcher. Do you want to try again or disable "
153  "aRts sound output?\n\n"
154  "If you choose to disable aRts output now, you can re-enable "
155  "it later or select an alternate sound player "
156  "in the System Notifications control panel."),
157  i18n("KNotify Problem"),
158  i18n("&Try Again"),
159  i18n("D&isable aRts Output"),
160  "KNotifyStartProgress",
161  0 /* don't call KNotify :) */
162  )
163  == KMessageBox::No )
164  {
165  useArts = false;
166  }
167  }
168 
169  // when ArtsDispatcher crashes, we know it the next start.
170  config.writeEntry( "Arts Init", false );
171  config.writeEntry( "Use Arts", useArts );
172  config.sync();
173 
174  KArtsDispatcher *dispatcher = 0;
175  if ( useArts )
176  {
177  dispatcher = new KArtsDispatcher;
178  soundServer = new KArtsServer;
179  }
180 
181  // ok, seemed to work.
182  config.writeEntry("Arts Init", useArts );
183  config.sync();
184 
185  ok = config.readBoolEntry( "KNotify Init", true );
186  if ( useArts && !ok )
187  {
188  if ( KMessageBox::questionYesNo(
189  0L,
190  i18n("During the previous startup, KNotify crashed while instantiating "
191  "KNotify. Do you want to try again or disable "
192  "aRts sound output?\n\n"
193  "If you choose to disable aRts output now, you can re-enable "
194  "it later or select an alternate sound player "
195  "in the System Notifications control panel."),
196  i18n("KNotify Problem"),
197  i18n("&Try Again"),
198  i18n("D&isable aRts Output"),
199  "KNotifyStartProgress",
200  0 /* don't call KNotify :) */
201  )
202  == KMessageBox::No )
203  {
204  useArts = false;
205  delete soundServer;
206  soundServer = 0L;
207  delete dispatcher;
208  dispatcher = 0L;
209  }
210  }
211 
212  // when KNotify instantiation crashes, we know it the next start.
213  config.writeEntry( "KNotify Init", false );
214  config.writeEntry( "Use Arts", useArts );
215  config.sync();
216 
217  // start notify service
218  KNotify *notify = new KNotify( useArts );
219 
220  config.writeEntry( "KNotify Init", true );
221  config.sync();
222 
223 #else
224 
225  // start notify service, without aRts
226  KNotify *notify = new KNotify( false );
227 
228 #endif
229 
230  app.dcopClient()->setDefaultObject( "Notify" );
231  app.dcopClient()->setDaemonMode( true );
232  // kdDebug() << "knotify starting" << endl;
233 
234  int ret = app.exec();
235  delete notify;
236 #ifndef WITHOUT_ARTS
237  delete soundServer;
238  delete dispatcher;
239 #endif
240  return ret;
241 }
242 }// end extern "C"
243 
244 KNotify::KNotify( bool useArts )
245  : TQObject(), DCOPObject("Notify")
246 {
247  d = new KNotifyPrivate;
248  d->globalEvents = new KConfig("knotify/eventsrc", true, false, "data");
249  d->globalConfig = new KConfig("knotify.eventsrc", true, false);
250  d->externalPlayerProc = 0;
251  d->useArts = useArts;
252  d->inStartup = true;
253 #ifndef WITHOUT_ARTS
254  d->playObjects.setAutoDelete(true);
255  d->audioManager = 0;
256  if( useArts )
257  {
258  connect( soundServer, TQT_SIGNAL( restartedServer() ), this, TQT_SLOT( restartedArtsd() ) );
259  restartedArtsd(); //started allready need to initialize d->audioManager
260  }
261 #endif
262 
263  d->volume = 100;
264 
265  d->playTimer = 0;
266 
267  loadConfig();
268 }
269 
270 KNotify::~KNotify()
271 {
272  reconfigure();
273 
274 #ifndef WITHOUT_ARTS
275  d->playObjects.clear();
276 
277  delete d->globalEvents;
278  delete d->globalConfig;
279  delete d->externalPlayerProc;
280  delete d->audioManager;
281 #endif
282  delete d;
283 }
284 
285 
286 void KNotify::loadConfig() {
287  // load external player settings
288  KConfig *kc = KGlobal::config();
289  kc->setGroup("Misc");
290  d->useExternal = kc->readBoolEntry( "Use external player", false );
291  d->externalPlayer = kc->readPathEntry("External player");
292 
293  // try to locate a suitable player if none is configured
294  if ( d->externalPlayer.isEmpty() ) {
295  TQStringList players;
296  players << "wavplay" << "aplay" << "auplay";
297  TQStringList::Iterator it = players.begin();
298  while ( d->externalPlayer.isEmpty() && it != players.end() ) {
299  d->externalPlayer = KStandardDirs::findExe( *it );
300  ++it;
301  }
302  }
303 
304  // load default volume
305  d->volume = kc->readNumEntry( "Volume", 100 );
306 }
307 
308 
309 void KNotify::reconfigure()
310 {
311  kapp->config()->reparseConfiguration();
312  loadConfig();
313 
314  // clear loaded config files
315  d->globalConfig->reparseConfiguration();
316  for ( TQMapIterator<TQString,KConfig*> it = d->configs.begin(); it != d->configs.end(); ++it )
317  delete it.data();
318  d->configs.clear();
319 }
320 
321 
322 void KNotify::notify(const TQString &event, const TQString &fromApp,
323  const TQString &text, TQString sound, TQString file,
324  int present, int level)
325 {
326  notify( event, fromApp, text, sound, file, present, level, 0, 1 );
327 }
328 
329 void KNotify::notify(const TQString &event, const TQString &fromApp,
330  const TQString &text, TQString sound, TQString file,
331  int present, int level, int winId)
332 {
333  notify( event, fromApp, text, sound, file, present, level, winId, 1 );
334 }
335 
336 void KNotify::notify(const TQString &event, const TQString &fromApp,
337  const TQString &text, TQString sound, TQString file,
338  int present, int level, int winId, int eventId )
339 {
340  // kdDebug() << "event=" << event << " fromApp=" << fromApp << " text=" << text << " sound=" << sound <<
341  // " file=" << file << " present=" << present << " level=" << level << " winId=" << winId << " eventId=" << eventId << endl;
342  if( d->inStartup ) {
343  d->startupEvents += "(" + event + ":" + fromApp + ")";
344  }
345 
346  TQString commandline;
347  KConfig *eventsFile = NULL;
348  KConfig *configFile = NULL;
349 
350  // check for valid events
351  if ( !event.isEmpty() ) {
352 
353  // get config file
354  if ( d->events.contains( fromApp ) ) {
355  eventsFile = d->events[fromApp];
356  } else {
357  eventsFile=new KConfig(locate("data", fromApp+"/eventsrc"),true,false);
358  d->events.insert( fromApp, eventsFile );
359  }
360  if ( d->configs.contains( fromApp) ) {
361  configFile = d->configs[fromApp];
362  } else {
363  configFile=new KConfig(fromApp+".eventsrc",true,false);
364  d->configs.insert( fromApp, configFile );
365  }
366 
367  if ( !eventsFile->hasGroup( event ) && isGlobal(event) )
368  {
369  eventsFile = d->globalEvents;
370  configFile = d->globalConfig;
371  }
372 
373  eventsFile->setGroup( event );
374  configFile->setGroup( event );
375 
376  // get event presentation
377  if ( present==-1 )
378  present = configFile->readNumEntry( "presentation", -1 );
379  if ( present==-1 )
380  present = eventsFile->readNumEntry( "default_presentation", 0 );
381 
382  // get sound file name
383  if( present & KNotifyClient::Sound ) {
384  TQString theSound = configFile->readPathEntry( "soundfile" );
385  if ( theSound.isEmpty() )
386  theSound = eventsFile->readPathEntry( "default_sound" );
387  if ( !theSound.isEmpty() )
388  sound = theSound;
389  }
390 
391  // get log file name
392  if( present & KNotifyClient::Logfile ) {
393  TQString theFile = configFile->readPathEntry( "logfile" );
394  if ( theFile.isEmpty() )
395  theFile = eventsFile->readPathEntry( "default_logfile" );
396  if ( !theFile.isEmpty() )
397  file = theFile;
398  }
399 
400  // get default event level
401  if( present & KNotifyClient::Messagebox )
402  level = eventsFile->readNumEntry( "level", 0 );
403 
404  // get command line
405  if (present & KNotifyClient::Execute ) {
406  commandline = configFile->readPathEntry( "commandline" );
407  if ( commandline.isEmpty() )
408  commandline = eventsFile->readPathEntry( "default_commandline" );
409  }
410  }
411 
412  // emit event
413  if ( present & KNotifyClient::Sound ) // && TQFile(sound).isReadable()
414  notifyBySound( sound, fromApp, eventId );
415 
416  if ( present & KNotifyClient::Execute )
417  notifyByExecute( commandline, event, fromApp, text, winId, eventId );
418 
419  if ( present & KNotifyClient::Logfile ) // && TQFile(file).isWritable()
420  notifyByLogfile( text, file );
421 
422  if ( present & KNotifyClient::Stderr )
423  notifyByStderr( text );
424 
425  if ( present & KNotifyClient::Taskbar )
426  notifyByTaskbar( checkWinId( fromApp, winId ));
427 
428  if ( present & KNotifyClient::PassivePopup )
429  notifyByPassivePopup( text, fromApp, eventsFile, checkWinId( fromApp, winId ));
430  else if ( present & KNotifyClient::Messagebox )
431  notifyByMessagebox( text, level, checkWinId( fromApp, winId ));
432 
433  TQByteArray qbd;
434  TQDataStream ds(qbd, IO_WriteOnly);
435  ds << event << fromApp << text << sound << file << present << level
436  << winId << eventId;
437  emitDCOPSignal("notifySignal(TQString,TQString,TQString,TQString,TQString,int,int,int,int)", qbd);
438 
439 }
440 
441 
442 bool KNotify::notifyBySound( const TQString &sound, const TQString &appname, int eventId )
443 {
444  if (sound.isEmpty()) {
445  soundFinished( eventId, NoSoundFile );
446  return false;
447  }
448 
449  bool external = d->useExternal && !d->externalPlayer.isEmpty();
450  // get file name
451  TQString soundFile(sound);
452  if ( TQFileInfo(sound).isRelative() )
453  {
454  TQString search = TQString("%1/sounds/%2").arg(appname).arg(sound);
455  soundFile = KGlobal::instance()->dirs()->findResource("data", search);
456  if ( soundFile.isEmpty() )
457  soundFile = locate( "sound", sound );
458  }
459  if ( soundFile.isEmpty() || isPlaying( soundFile ) )
460  {
461  soundFinished( eventId, soundFile.isEmpty() ? NoSoundFile : FileAlreadyPlaying );
462  return false;
463  }
464 
465 
466  // kdDebug() << "KNotify::notifyBySound - trying to play file " << soundFile << endl;
467 
468  if (!external) {
469  //If we disabled using aRts, just return,
470  //(If we don't, we'll blow up accessing the null soundServer)
471  if (!d->useArts)
472  {
473  soundFinished( eventId, NoSoundSupport );
474  return false;
475  }
476 
477 #ifndef WITHOUT_ARTS
478  // play sound finally
479  while( d->playObjects.count()>5 )
480  abortFirstPlayObject();
481 
482  KDE::PlayObjectFactory factory(soundServer->server());
483  if( d->audioManager )
484  factory.setAudioManagerPlay( d->audioManager );
485  KURL soundURL;
486  soundURL.setPath(soundFile);
487  KDE::PlayObject *playObject = factory.createPlayObject(soundURL, false);
488 
489  if (playObject->isNull())
490  {
491  soundFinished( eventId, NoSoundSupport );
492  delete playObject;
493  return false;
494  }
495 
496  if ( d->volume != 100 )
497  {
498  // It works to access the playObject immediately because we don't allow
499  // non-file URLs for sounds.
500  Arts::StereoVolumeControl volumeControl = Arts::DynamicCast(soundServer->server().createObject("Arts::StereoVolumeControl"));
501  Arts::PlayObject player = playObject->object();
502  Arts::Synth_AMAN_PLAY ap = d->audioManager->amanPlay();
503  if( ! volumeControl.isNull() && ! player.isNull() && ! ap.isNull() )
504  {
505  volumeControl.scaleFactor( d->volume/100.0 );
506 
507  ap.stop();
508  Arts::disconnect( player, "left", ap, "left" );
509  Arts::disconnect( player, "right", ap, "right" );
510 
511  ap.start();
512  volumeControl.start();
513 
514  Arts::connect(player,"left",volumeControl,"inleft");
515  Arts::connect(player,"right",volumeControl,"inright");
516 
517  Arts::connect(volumeControl,"outleft",ap,"left");
518  Arts::connect(volumeControl,"outright",ap,"right");
519 
520  player._addChild( volumeControl, "volume" );
521  }
522  }
523 
524  playObject->play();
525  d->playObjects.append( playObject );
526  d->playObjectEventMap.insert( playObject, eventId );
527 
528  if ( !d->playTimer )
529  {
530  d->playTimer = new TQTimer( this );
531  connect( d->playTimer, TQT_SIGNAL( timeout() ), TQT_SLOT( playTimeout() ) );
532  }
533  if ( !d->playTimer->isActive() )
534  d->playTimer->start( 1000 );
535 #endif
536  return true;
537 
538  } else if(!d->externalPlayer.isEmpty()) {
539  // use an external player to play the sound
540  KProcess *proc = d->externalPlayerProc;
541  if (!proc)
542  {
543  proc = d->externalPlayerProc = new KProcess;
544  connect( proc, TQT_SIGNAL( processExited( KProcess * )),
545  TQT_SLOT( slotPlayerProcessExited( KProcess * )));
546  }
547  if (proc->isRunning())
548  {
549  soundFinished( eventId, PlayerBusy );
550  return false; // Skip
551  }
552  proc->clearArguments();
553  (*proc) << d->externalPlayer << TQFile::encodeName( soundFile ).data();
554  d->externalPlayerEventId = eventId;
555  proc->start(KProcess::NotifyOnExit);
556  return true;
557  }
558 
559  soundFinished( eventId, Unknown );
560  return false;
561 }
562 
563 bool KNotify::notifyByMessagebox(const TQString &text, int level, WId winId)
564 {
565  // ignore empty messages
566  if ( text.isEmpty() )
567  return false;
568 
569  // display message box for specified event level
570  switch( level ) {
571  default:
572  case KNotifyClient::Notification:
573  KMessageBox::informationWId( winId, text, i18n("Notification"), 0, false );
574  break;
575  case KNotifyClient::Warning:
576  KMessageBox::sorryWId( winId, text, i18n("Warning"), false );
577  break;
578  case KNotifyClient::Error:
579  KMessageBox::errorWId( winId, text, i18n("Error"), false );
580  break;
581  case KNotifyClient::Catastrophe:
582  KMessageBox::errorWId( winId, text, i18n("Catastrophe!"), false );
583  break;
584  }
585 
586  return true;
587 }
588 
589 bool KNotify::notifyByPassivePopup( const TQString &text,
590  const TQString &appName,
591  KConfig* eventsFile,
592  WId senderWinId )
593 {
594  KIconLoader iconLoader( appName );
595  if ( eventsFile != NULL ) {
596  KConfigGroup config( eventsFile, "!Global!" );
597  TQString iconName = config.readEntry( "IconName", appName );
598  TQPixmap icon = iconLoader.loadIcon( iconName, KIcon::Small );
599  TQString title = config.readEntry( "Comment", appName );
600  KPassivePopup::message(title, text, icon, senderWinId);
601  } else
602  kdError() << "No events for app " << appName << "defined!" <<endl;
603 
604  return true;
605 }
606 
607 bool KNotify::notifyByExecute(const TQString &command, const TQString& event,
608  const TQString& fromApp, const TQString& text,
609  int winId, int eventId) {
610  if (!command.isEmpty()) {
611  // kdDebug() << "executing command '" << command << "'" << endl;
612  TQMap<TQChar,TQString> subst;
613  subst.insert( 'e', event );
614  subst.insert( 'a', fromApp );
615  subst.insert( 's', text );
616  subst.insert( 'w', TQString::number( winId ));
617  subst.insert( 'i', TQString::number( eventId ));
618  TQString execLine = KMacroExpander::expandMacrosShellQuote( command, subst );
619  if ( execLine.isEmpty() )
620  execLine = command; // fallback
621 
622  KProcess p;
623  p.setUseShell(true);
624  p << execLine;
625  p.start(KProcess::DontCare);
626  return true;
627  }
628  return false;
629 }
630 
631 
632 bool KNotify::notifyByLogfile(const TQString &text, const TQString &file)
633 {
634  // ignore empty messages
635  if ( text.isEmpty() )
636  return true;
637 
638  // open file in append mode
639  TQFile logFile(file);
640  if ( !logFile.open(IO_WriteOnly | IO_Append) )
641  return false;
642 
643  // append msg
644  TQTextStream strm( &logFile );
645  strm << "- KNotify " << TQDateTime::currentDateTime().toString() << ": ";
646  strm << text << endl;
647 
648  // close file
649  logFile.close();
650  return true;
651 }
652 
653 bool KNotify::notifyByStderr(const TQString &text)
654 {
655  // ignore empty messages
656  if ( text.isEmpty() )
657  return true;
658 
659  // open stderr for output
660  TQTextStream strm( stderr, IO_WriteOnly );
661 
662  // output msg
663  strm << "KNotify " << TQDateTime::currentDateTime().toString() << ": ";
664  strm << text << endl;
665 
666  return true;
667 }
668 
669 bool KNotify::notifyByTaskbar( WId win )
670 {
671  if( win == 0 )
672  return false;
673  KWin::demandAttention( win );
674  return true;
675 }
676 
677 bool KNotify::isGlobal(const TQString &eventname)
678 {
679  return d->globalEvents->hasGroup( eventname );
680 }
681 
682 void KNotify::setVolume( int volume )
683 {
684  if ( volume<0 ) volume=0;
685  if ( volume>=100 ) volume=100;
686  d->volume = volume;
687 }
688 
689 void KNotify::playTimeout()
690 {
691 #ifndef WITHOUT_ARTS
692  for ( TQPtrListIterator< KDE::PlayObject > it(d->playObjects); *it;)
693  {
694  TQPtrListIterator< KDE::PlayObject > current = it;
695  ++it;
696  if ( (*current)->state() != Arts::posPlaying )
697  {
698  TQMap<KDE::PlayObject*,int>::Iterator eit = d->playObjectEventMap.find( *current );
699  if ( eit != d->playObjectEventMap.end() )
700  {
701  soundFinished( *eit, PlayedOK );
702  d->playObjectEventMap.remove( eit );
703  }
704  d->playObjects.remove( current );
705  }
706  }
707  if ( !d->playObjects.count() )
708  d->playTimer->stop();
709 #endif
710 }
711 
712 bool KNotify::isPlaying( const TQString& soundFile ) const
713 {
714 #ifndef WITHOUT_ARTS
715  for ( TQPtrListIterator< KDE::PlayObject > it(d->playObjects); *it; ++it)
716  {
717  if ( (*it)->mediaName() == soundFile )
718  return true;
719  }
720 #endif
721  return false;
722 }
723 
724 void KNotify::slotPlayerProcessExited( KProcess *proc )
725 {
726  soundFinished( d->externalPlayerEventId,
727  (proc->normalExit() && proc->exitStatus() == 0) ? PlayedOK : Unknown );
728 }
729 
730 void KNotify::abortFirstPlayObject()
731 {
732 #ifndef WITHOUT_ARTS
733  TQMap<KDE::PlayObject*,int>::Iterator it = d->playObjectEventMap.find( d->playObjects.getFirst() );
734  if ( it != d->playObjectEventMap.end() )
735  {
736  soundFinished( it.data(), Aborted );
737  d->playObjectEventMap.remove( it );
738  }
739  d->playObjects.removeFirst();
740 #endif
741 }
742 
743 void KNotify::soundFinished( int eventId, PlayingFinishedStatus reason )
744 {
745  TQByteArray data;
746  TQDataStream stream( data, IO_WriteOnly );
747  stream << eventId << (int) reason;
748 
749  DCOPClient::mainClient()->emitDCOPSignal( "KNotify", "playingFinished(int,int)", data );
750 }
751 
752 WId KNotify::checkWinId( const TQString &appName, WId senderWinId )
753 {
754  if ( senderWinId == 0 )
755  {
756  TQCString senderId = kapp->dcopClient()->senderId();
757  TQCString compare = (appName + "-mainwindow").latin1();
758  int len = compare.length();
759  // kdDebug() << "notifyByPassivePopup: appName=" << appName << " sender=" << senderId << endl;
760 
761  QCStringList objs = kapp->dcopClient()->remoteObjects( senderId );
762  for (QCStringList::ConstIterator it = objs.begin(); it != objs.end(); ++it ) {
763  TQCString obj( *it );
764  if ( obj.left(len) == compare) {
765  // kdDebug( ) << "found " << obj << endl;
766  TQCString replyType;
767  TQByteArray data, replyData;
768 
769  if ( kapp->dcopClient()->call(senderId, obj, "getWinID()", data, replyType, replyData) ) {
770  TQDataStream answer(replyData, IO_ReadOnly);
771  if (replyType == "int") {
772  answer >> senderWinId;
773  // kdDebug() << "SUCCESS, found getWinID(): type='" << TQString(replyType)
774  // << "' senderWinId=" << senderWinId << endl;
775  }
776  }
777  }
778  }
779  }
780  return senderWinId;
781 }
782 
783 void KNotify::restartedArtsd()
784 {
785 #ifndef WITHOUT_ARTS
786  delete d->audioManager;
787  d->audioManager = new KAudioManagerPlay( soundServer );
788  d->audioManager->setTitle( i18n( "Trinity System Notifications" ) );
789  d->audioManager->setAutoRestoreID( "KNotify Aman Play" );
790 #endif
791 }
792 
793 void KNotify::sessionReady()
794 {
795  if( d->inStartup && !d->startupEvents.isEmpty())
796  kdDebug() << "There were knotify events while startup:" << d->startupEvents << endl;
797  d->inStartup = false;
798 }
799 
800 // vim: sw=4 sts=4 ts=8 et
KURL
KUniqueApplication::start
static bool start()
KProcess
locate
TQString locate(const char *type, const TQString &filename, const KInstance *instance=KGlobal::instance())
KMessageBox::questionYesNo
static int questionYesNo(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
KProcess::NotifyOnExit
NotifyOnExit
KProcess::clearArguments
void clearArguments()
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
KIcon::Small
Small
KMessageBox::informationWId
static void informationWId(WId parent_id, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
KProcess::setUseShell
void setUseShell(bool useShell, const char *shell=0)
kdError
kdbgstream kdError(int area=0)
KNotifyClient::Execute
Execute
KPassivePopup::message
static KPassivePopup * message(const TQString &text, TQWidget *parent, const char *name=0)
KStandardDirs::findResource
TQString findResource(const char *type, const TQString &filename) const
KStandardDirs::findExe
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
KProcess::start
virtual bool start(RunMode runmode=NotifyOnExit, Communication comm=NoCommunication)
kdDebug
kdbgstream kdDebug(int area=0)
KApplication::disableSessionManagement
void disableSessionManagement()
klocale.h
KDE::PlayObject::object
Arts::PlayObject object()
Returns the internal Arts::PlayObject.
Definition: kplayobject.cc:284
KConfigBase::setGroup
void setGroup(const TQString &group)
KWin::demandAttention
static void demandAttention(WId win, bool set=true)
KConfigBase::readPathEntry
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
KConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
KNotifyClient::PassivePopup
PassivePopup
KDE::PlayObject
This class acts as a general interface to the KDE multimedia framework.
Definition: kplayobject.h:188
KURL::setPath
void setPath(const TQString &path)
I18N_NOOP
#define I18N_NOOP(x)
KProcess::isRunning
bool isRunning() const
KAboutData
KProcess::exitStatus
int exitStatus() const
KAudioManagerPlay
KDE Wrapper for Arts::Synth_AMAN_PLAY.
Definition: kaudiomanagerplay.h:38
KGlobal::instance
static KInstance * instance()
KProcess::DontCare
DontCare
KMessageBox::errorWId
static void errorWId(WId parent_id, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
KMessageBox::sorryWId
static void sorryWId(WId parent_id, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
KConfigGroup
KUniqueApplication::addCmdLineOptions
static void addCmdLineOptions()
KConfig
KProcess::normalExit
bool normalExit() const
KCmdLineArgs::init
static void init(int _argc, char **_argv, const char *_appname, const char *programName, const char *_description, const char *_version, bool noKApp=false)
KNotifyClient::Taskbar
Taskbar
KDE::PlayObject::isNull
bool isNull()
return true if this != 0.
Definition: kplayobject.cc:289
KConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
KInstance::dirs
KStandardDirs * dirs() const
KApplication::dcopClient
static DCOPClient * dcopClient()
KAudioRecordStream::data
void data(TQByteArray &data)
Data from the aRts server has arrived.
KDE::PlayObjectFactory::setAudioManagerPlay
void setAudioManagerPlay(KAudioManagerPlay *amanplay)
If this is set the PlayObject doesn&#39;t create a Synth_BUS_UPLINK at all but always uses the Synth_AMAN...
Definition: kplayobjectfactory.cc:123
KDE::PlayObject::play
void play()
causes the PlayObject to start the play back.
Definition: kplayobject.cc:173
KUniqueApplication
endl
kndbgstream & endl(kndbgstream &s)
KDE::PlayObjectFactory
This class implements a factory to create KDE::PlayObjects for a given URL and mimetype.
Definition: kplayobjectfactory.h:79
KConfigBase::hasGroup
bool hasGroup(const TQString &group) const
KGlobal::config
static KConfig * config()
KMacroExpander::expandMacrosShellQuote
TQString expandMacrosShellQuote(const TQString &str, const TQMap< TQChar, TQString > &map, TQChar c= '%')
KIconLoader

arts

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

arts

Skip menu "arts"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for arts by doxygen 1.8.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |