• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

KNotify

  • sources
  • kde-4.14
  • kde-runtime
  • knotify
notifybyktts.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 by Olivier Goffart <ogoffart at kde.org>
3  Copyright (C) 2009 by Laurent Montel <montel@kde.org>
4 
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  */
21 #include "notifybyktts.h"
22 #include <QtDBus/QtDBus>
23 #include <QHash>
24 #include <ktoolinvocation.h>
25 #include <kmessagebox.h>
26 #include <kmacroexpander.h>
27 #include <klocale.h>
28 #include <knotifyconfig.h>
29 
30 NotifyByKTTS::NotifyByKTTS(QObject *parent) : KNotifyPlugin(parent),m_kspeech(0), tryToStartKttsd( false )
31 {
32 }
33 
34 
35 NotifyByKTTS::~NotifyByKTTS()
36 {
37 }
38 
39 void NotifyByKTTS::setupKttsd()
40 {
41  m_kspeech = new org::kde::KSpeech("org.kde.kttsd", "/KSpeech", QDBusConnection::sessionBus());
42  m_kspeech->setParent(this);
43  m_kspeech->setApplicationName("KNotify");
44 
45  QDBusServiceWatcher *watcher = new QDBusServiceWatcher(this);
46  watcher->setConnection(QDBusConnection::sessionBus());
47  watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
48  watcher->addWatchedService("org.kde.kttsd");
49  connect(watcher, SIGNAL(serviceUnregistered( const QString & ) ), this, SLOT( removeSpeech() ));
50 }
51 
52 void NotifyByKTTS::notify( int id, KNotifyConfig * config )
53 {
54  if( !m_kspeech)
55  {
56  if ( tryToStartKttsd ) //don't try to restart it all the time.
57  return;
58  // If KTTSD not running, start it.
59  if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
60  {
61  QString error;
62  if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error))
63  {
64  KMessageBox::error(0, i18n( "Starting Jovie Text-to-Speech Service Failed"), error );
65  tryToStartKttsd = true;
66  return;
67  }
68  }
69  setupKttsd();
70  }
71 
72  QString say = config->readEntry( "KTTS" );
73 
74  if (!say.isEmpty()) {
75  QHash<QChar,QString> subst;
76  subst.insert( 'e', config->eventid );
77  subst.insert( 'a', config->appname );
78  subst.insert( 's', config->text );
79  subst.insert( 'w', QString::number( (quintptr)config->winId ));
80  subst.insert( 'i', QString::number( id ));
81  subst.insert( 'm', config->text );
82  say = KMacroExpander::expandMacrosShellQuote( say, subst );
83  }
84 
85  if ( say.isEmpty() )
86  say = config->text; // fallback
87 
88  m_kspeech->setApplicationName(config->appname);
89  m_kspeech->call(QDBus::NoBlock, "say", say, 0);
90 
91  finished(id);
92 }
93 
94 void NotifyByKTTS::removeSpeech()
95 {
96  tryToStartKttsd = false;
97 
98  delete m_kspeech;
99  m_kspeech = 0;
100 }
101 
102 #include "notifybyktts.moc"
QHash::insert
iterator insert(const Key &key, const T &value)
NotifyByKTTS::~NotifyByKTTS
virtual ~NotifyByKTTS()
Definition: notifybyktts.cpp:35
KNotifyConfig::readEntry
QString readEntry(const QString &entry, bool path=false)
Definition: knotifyconfig.cpp:80
NotifyByKTTS::notify
virtual void notify(int id, KNotifyConfig *config)
This function is called when the notification is sent.
Definition: notifybyktts.cpp:52
KNotifyPlugin
abstract class for KNotify actions
Definition: knotifyplugin.h:44
QDBusConnection::sessionBus
QDBusConnection sessionBus()
knotifyconfig.h
KNotifyConfig::text
QString text
the text of the notification
Definition: knotifyconfig.h:85
QString::number
QString number(int n, int base)
QDBusServiceWatcher::setConnection
void setConnection(const QDBusConnection &connection)
QHash
KNotifyConfig::eventid
QString eventid
the name of the notification
Definition: knotifyconfig.h:120
QObject
notifybyktts.h
QString::isEmpty
bool isEmpty() const
QString
NotifyByKTTS::NotifyByKTTS
NotifyByKTTS(QObject *parent=0l)
Definition: notifybyktts.cpp:30
QStringList
KNotifyPlugin::finished
void finished(int id)
the presentation is finished.
KNotifyConfig::winId
WId winId
The windowsID of the window that initiated the notification (it is a window in the client) ...
Definition: knotifyconfig.h:100
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QDBusServiceWatcher::setWatchMode
void setWatchMode(QFlags< QDBusServiceWatcher::WatchModeFlag > mode)
KNotifyConfig::appname
QString appname
the name of the application that triggered the notification
Definition: knotifyconfig.h:109
KNotifyConfig
Represent the configuration for an event.
Definition: knotifyconfig.h:60
QDBusServiceWatcher::addWatchedService
void addWatchedService(const QString &newService)
QDBusServiceWatcher
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:23 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNotify

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

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal