• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

akregator

  • sources
  • kde-4.12
  • kdepim
  • akregator
  • src
speechclient.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org>
5  Copyright (C) 2009 Laurent Montel <montel@kde.org>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of Qt, and distribute the resulting executable,
23  without including the source code for Qt in the source distribution.
24 */
25 
26 #include "speechclient.h"
27 #include <kstandarddirs.h>
28 #include "article.h"
29 #include "utils.h"
30 
31 #include <kcharsets.h>
32 #include <klocale.h>
33 #include <kdebug.h>
34 #include <ktoolinvocation.h>
35 #include <kservicetypetrader.h>
36 
37 #include "kspeechinterface.h"
38 #include <QString>
39 #include <kspeech.h>
40 namespace Akregator
41 {
42 
43 class SpeechClient::SpeechClientPrivate
44 {
45  public:
46 
47  bool isTextSpeechInstalled;
48  QList<uint> pendingJobs;
49 };
50 
51 SpeechClient* SpeechClient::m_self = 0;
52 
53 SpeechClient* SpeechClient::self()
54 {
55  static SpeechClient sself;
56  if (!m_self)
57  m_self = &sself;
58  return m_self;
59 }
60 
61 
62 SpeechClient::SpeechClient() : QObject(), m_kspeech( 0 ), d(new SpeechClientPrivate)
63 {
64  d->isTextSpeechInstalled = false;
65  setupSpeechSystem();
66 }
67 
68 SpeechClient::~SpeechClient()
69 {
70  delete d;
71  d = 0;
72 }
73 
74 void SpeechClient::slotSpeak(const QString& text, const QString& /*language*/)
75 {
76  if ( !d->isTextSpeechInstalled )
77  setupSpeechSystem();
78  if ( text.isEmpty())
79  return;
80  uint jobNum = m_kspeech->say(text,0);
81  d->pendingJobs.append(jobNum);
82  if (d->pendingJobs.count() == 1)
83  {
84  emit signalJobsStarted();
85  emit signalActivated(true);
86  }
87 }
88 
89 void SpeechClient::slotSpeak(const Article& article)
90 {
91  if (!isTextToSpeechInstalled() || article.isNull())
92  return;
93 
94  QString speakMe;
95  speakMe += KCharsets::resolveEntities(Utils::stripTags((article).title()))
96  + ". . . . "
97  + KCharsets::resolveEntities(Utils::stripTags((article).description()));
98  slotSpeak(speakMe, "en");
99 }
100 
101 void SpeechClient::slotSpeak(const QList<Article>& articles)
102 {
103  qDebug()<<" SpeechClient::slotSpeak(const Articlessssssssssss& article) :"<<articles.isEmpty()<<" isTextToSpeechInstalled :"<<isTextToSpeechInstalled();
104 
105  if (!isTextToSpeechInstalled() || articles.isEmpty())
106  return;
107 
108  QString speakMe;
109 
110  for (QList<Article>::ConstIterator it = articles.begin(); it != articles.end(); ++it)
111  {
112  if (!speakMe.isEmpty())
113  speakMe += ". . . . . . " + i18n("Next Article: ");
114  speakMe += KCharsets::resolveEntities(Utils::stripTags((*it).title()))
115  + ". . . . "
116  + KCharsets::resolveEntities(Utils::stripTags((*it).description()));
117  }
118 
119  SpeechClient::self()->slotSpeak(speakMe, "en");
120 }
121 
122 void SpeechClient::slotAbortJobs()
123 {
124  if (!d->pendingJobs.isEmpty())
125  {
126  for (QList<uint>::ConstIterator it = d->pendingJobs.constBegin(); it != d->pendingJobs.constEnd(); ++it)
127  {
128  //removeText(*it);
129  }
130 
131  d->pendingJobs.clear();
132  emit signalJobsDone();
133  emit signalActivated(false);
134  }
135 }
136 
137 void SpeechClient::textRemoved(const QString &/*appId*/, int jobNum, int state )
138 {
139  if ( state == KSpeech::jsFinished || state == KSpeech::jsDeleted )
140  if (d->pendingJobs.contains(jobNum))
141  {
142  d->pendingJobs.removeAll(jobNum);
143  if (d->pendingJobs.isEmpty())
144  {
145  emit signalJobsDone();
146  emit signalActivated(false);
147  }
148  }
149 }
150 
151 bool SpeechClient::isTextToSpeechInstalled() const
152 {
153  return d->isTextSpeechInstalled;
154 }
155 
156 void SpeechClient::setupSpeechSystem()
157 {
158  if ( KStandardDirs::findExe( "kttsd" ).isEmpty() )
159  {
160  kDebug() <<"KTTSD not installed, disable support";
161  d->isTextSpeechInstalled = false;
162  }
163  else
164  {
165  if ( QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd") )
166  {
167  d->isTextSpeechInstalled = true;
168  }
169  else
170  {
171  QString error;
172 
173  if (KToolInvocation::startServiceByDesktopName("kttsd", QString(), &error) != 0)
174  {
175  kDebug() <<"Starting KTTSD failed with message" << error;
176  d->isTextSpeechInstalled = false;
177  }
178  else
179  {
180  d->isTextSpeechInstalled = true;
181  }
182  }
183  if (d->isTextSpeechInstalled)
184  {
185  if ( !m_kspeech )
186  {
187  m_kspeech = new org::kde::KSpeech("org.kde.kttsd", "/KSpeech", QDBusConnection::sessionBus());
188  m_kspeech->setParent(this);
189  m_kspeech->setApplicationName("Akregator Speech Text");
190  connect(m_kspeech, SIGNAL(jobStateChanged(QString,int,int)),
191  this, SLOT(textRemoved(QString,int,int)));
192  connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceUnregistered(QString)), this, SLOT(slotServiceUnregistered(QString)) );
193  connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), this, SLOT(slotServiceOwnerChanged(QString,QString,QString)) );
194 
195  }
196  }
197  }
198 }
199 
200 void SpeechClient::slotServiceUnregistered( const QString &service )
201 {
202  if ( service == QLatin1String( "org.kde.kttsd" ) )
203  {
204  removeSpeech();
205  }
206 
207 }
208 
209 void SpeechClient::slotServiceOwnerChanged( const QString &service, const QString &, const QString &newOwner )
210 {
211  if ( service == QLatin1String( "org.kde.kttsd" ) && newOwner.isEmpty() )
212  {
213  removeSpeech();
214  }
215 }
216 
217 void SpeechClient::removeSpeech()
218 {
219  d->isTextSpeechInstalled = false;
220  disconnect( QDBusConnection::sessionBus().interface(), 0, this, 0 );
221 
222  delete m_kspeech;
223  m_kspeech = 0;
224 
225 }
226 
227 } // namespace Akregator
228 
229 #include "speechclient.moc"
Akregator::SpeechClient::signalActivated
void signalActivated(bool)
Akregator::Utils::stripTags
static QString stripTags(const QString &str)
removes HTML/XML tags (everything between < and >) from a string.
Definition: utils.cpp:31
Akregator::SpeechClient::removeSpeech
void removeSpeech()
Definition: speechclient.cpp:217
Akregator::SpeechClient::signalJobsDone
void signalJobsDone()
emitted when all jobs were finished or aborted and no further jobs are queued
speechclient.h
Akregator::SpeechClient::SpeechClient
SpeechClient()
Definition: speechclient.cpp:62
uint
unsigned int uint
Definition: article.h:39
Akregator::SpeechClient::self
static SpeechClient * self()
Definition: speechclient.cpp:53
Akregator::SpeechClient::setupSpeechSystem
void setupSpeechSystem()
Definition: speechclient.cpp:156
QObject
utils.h
Akregator::Article::isNull
bool isNull() const
Definition: article.cpp:253
Akregator::SpeechClient::~SpeechClient
~SpeechClient()
Definition: speechclient.cpp:68
Akregator::SpeechClient::slotAbortJobs
void slotAbortJobs()
Definition: speechclient.cpp:122
article.h
Akregator::SpeechClient
Definition: speechclient.h:39
Akregator::SpeechClient::isTextToSpeechInstalled
bool isTextToSpeechInstalled() const
Definition: speechclient.cpp:151
Akregator::Article
A proxy class for Syndication::ItemPtr with some additional methods to assist sorting.
Definition: article.h:61
Akregator::SpeechClient::textRemoved
void textRemoved(const QString &appId, int jobNum, int state)
Definition: speechclient.cpp:137
Akregator::SpeechClient::signalJobsStarted
void signalJobsStarted()
emitted when the job queue was empty before and the first job was just queued
Akregator::SpeechClient::slotSpeak
void slotSpeak(const QString &text, const QString &language)
Definition: speechclient.cpp:74
QList< uint >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

Skip menu "akregator"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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