mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 02:45:38 +00:00
move in an own class (out of the page view) all the TTS related code
svn path=/trunk/KDE/kdegraphics/okular/; revision=782420
This commit is contained in:
parent
822fd2488d
commit
f407f84d8a
|
@ -140,6 +140,7 @@ set(okularpart_SRCS
|
|||
ui/toc.cpp
|
||||
ui/tocmodel.cpp
|
||||
ui/toolaction.cpp
|
||||
ui/tts.cpp
|
||||
)
|
||||
|
||||
kde4_add_ui_files(okularpart_SRCS
|
||||
|
|
|
@ -29,10 +29,6 @@
|
|||
#include <qtooltip.h>
|
||||
#include <qapplication.h>
|
||||
#include <qclipboard.h>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusConnectionInterface>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QtDBus/QDBusReply>
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kstandardaction.h>
|
||||
|
@ -44,7 +40,6 @@
|
|||
#include <kglobalsettings.h>
|
||||
#include <kselectaction.h>
|
||||
#include <ktoggleaction.h>
|
||||
#include <ktoolinvocation.h>
|
||||
#include <kdebug.h>
|
||||
#include <kmessagebox.h>
|
||||
#include <kicon.h>
|
||||
|
@ -63,6 +58,7 @@
|
|||
#include "annotationpopup.h"
|
||||
#include "pageviewannotator.h"
|
||||
#include "toolaction.h"
|
||||
#include "tts.h"
|
||||
#include "core/action.h"
|
||||
#include "core/document.h"
|
||||
#include "core/form.h"
|
||||
|
@ -82,6 +78,7 @@ public:
|
|||
PageViewPrivate( PageView *qq );
|
||||
|
||||
FormWidgetsController* formWidgetsController();
|
||||
OkularTTS* tts();
|
||||
QString selectedText() const;
|
||||
|
||||
// the document, pageviewItems and the 'visible cache'
|
||||
|
@ -128,6 +125,7 @@ public:
|
|||
PageViewMessage * messageWindow; // in pageviewutils.h
|
||||
bool m_formsVisible;
|
||||
FormWidgetsController *formsWidgetController;
|
||||
OkularTTS * m_tts;
|
||||
|
||||
// drag scroll
|
||||
QPoint dragScrollVector;
|
||||
|
@ -176,6 +174,16 @@ FormWidgetsController* PageViewPrivate::formWidgetsController()
|
|||
return formsWidgetController;
|
||||
}
|
||||
|
||||
OkularTTS* PageViewPrivate::tts()
|
||||
{
|
||||
if ( !m_tts )
|
||||
{
|
||||
m_tts = new OkularTTS( messageWindow, q );
|
||||
}
|
||||
|
||||
return m_tts;
|
||||
}
|
||||
|
||||
|
||||
class PageViewWidget : public QWidget
|
||||
{
|
||||
|
@ -296,6 +304,7 @@ PageView::PageView( QWidget *parent, Okular::Document *document )
|
|||
d->messageWindow = new PageViewMessage(this);
|
||||
d->m_formsVisible = false;
|
||||
d->formsWidgetController = 0;
|
||||
d->m_tts = 0;
|
||||
d->aRotateClockwise = 0;
|
||||
d->aRotateCounterClockwise = 0;
|
||||
d->aRotateOriginal = 0;
|
||||
|
@ -1873,32 +1882,7 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e )
|
|||
else if ( choice == speakText )
|
||||
{
|
||||
// [2] speech selection using KTTSD
|
||||
// Albert says is this ever necessary?
|
||||
// we already attached on Part constructor
|
||||
// If KTTSD not running, start it.
|
||||
QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd");
|
||||
bool kttsdactive = false;
|
||||
if ( reply.isValid() )
|
||||
kttsdactive = reply.value();
|
||||
if ( !kttsdactive )
|
||||
{
|
||||
QString error;
|
||||
if (KToolInvocation::startServiceByDesktopName("kttsd", QStringList(), &error))
|
||||
{
|
||||
d->messageWindow->display( i18n("Starting KTTSD Failed: %1", error) );
|
||||
}
|
||||
else
|
||||
{
|
||||
kttsdactive = true;
|
||||
}
|
||||
}
|
||||
if ( kttsdactive )
|
||||
{
|
||||
// creating the connection to the kspeech interface
|
||||
QDBusInterface kspeech("org.kde.kttsd", "/KSpeech", "org.kde.KSpeech");
|
||||
kspeech.call("setApplicationName", "okular");
|
||||
kspeech.call("say", selectedText, 0);
|
||||
}
|
||||
d->tts()->say( selectedText );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
78
ui/tts.cpp
Normal file
78
ui/tts.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#include "tts.h"
|
||||
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusConnectionInterface>
|
||||
#include <QtDBus/QDBusInterface>
|
||||
#include <QtDBus/QDBusReply>
|
||||
|
||||
#include <klocale.h>
|
||||
#include <ktoolinvocation.h>
|
||||
|
||||
#include "pageviewutils.h"
|
||||
|
||||
/* Private storage. */
|
||||
class OkularTTS::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
{
|
||||
}
|
||||
|
||||
PageViewMessage *messageWindow;
|
||||
};
|
||||
|
||||
|
||||
OkularTTS::OkularTTS( PageViewMessage *messageWindow, QObject *parent )
|
||||
: QObject( parent ), d( new Private )
|
||||
{
|
||||
d->messageWindow = messageWindow;
|
||||
}
|
||||
|
||||
OkularTTS::~OkularTTS()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void OkularTTS::say( const QString &text )
|
||||
{
|
||||
if ( text.isEmpty() )
|
||||
return;
|
||||
|
||||
// Albert says is this ever necessary?
|
||||
// we already attached on Part constructor
|
||||
// If KTTSD not running, start it.
|
||||
QDBusReply<bool> reply = QDBusConnection::sessionBus().interface()->isServiceRegistered( "org.kde.kttsd" );
|
||||
bool kttsdactive = false;
|
||||
if ( reply.isValid() )
|
||||
kttsdactive = reply.value();
|
||||
if ( !kttsdactive )
|
||||
{
|
||||
QString error;
|
||||
if ( KToolInvocation::startServiceByDesktopName( "kttsd", QStringList(), &error ) )
|
||||
{
|
||||
d->messageWindow->display( i18n( "Starting KTTSD Failed: %1", error ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
kttsdactive = true;
|
||||
}
|
||||
}
|
||||
if ( kttsdactive )
|
||||
{
|
||||
// creating the connection to the kspeech interface
|
||||
QDBusInterface kspeech( "org.kde.kttsd", "/KSpeech", "org.kde.KSpeech" );
|
||||
kspeech.call( "setApplicationName", "Okular" );
|
||||
kspeech.call( "say", text, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#include "tts.moc"
|
32
ui/tts.h
Normal file
32
ui/tts.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _TTS_H_
|
||||
#define _TTS_H_
|
||||
|
||||
#include <qobject.h>
|
||||
|
||||
class PageViewMessage;
|
||||
|
||||
class OkularTTS : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OkularTTS( PageViewMessage *messageWindow, QObject *parent = 0 );
|
||||
~OkularTTS();
|
||||
|
||||
void say( const QString &text );
|
||||
|
||||
private:
|
||||
// private storage
|
||||
class Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue