From f407f84d8afcd0563e6faff06a393c79912c0103 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 5 Mar 2008 02:13:09 +0000 Subject: [PATCH] move in an own class (out of the page view) all the TTS related code svn path=/trunk/KDE/kdegraphics/okular/; revision=782420 --- CMakeLists.txt | 1 + ui/pageview.cpp | 46 ++++++++++------------------- ui/tts.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ ui/tts.h | 32 ++++++++++++++++++++ 4 files changed, 126 insertions(+), 31 deletions(-) create mode 100644 ui/tts.cpp create mode 100644 ui/tts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bd9f401c5..e2b113819 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 133231e13..bbf68e7c3 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -29,10 +29,6 @@ #include #include #include -#include -#include -#include -#include #include #include @@ -44,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -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 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 ); } } } diff --git a/ui/tts.cpp b/ui/tts.cpp new file mode 100644 index 000000000..76e155796 --- /dev/null +++ b/ui/tts.cpp @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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 +#include +#include +#include + +#include +#include + +#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 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" diff --git a/ui/tts.h b/ui/tts.h new file mode 100644 index 000000000..52e3060e1 --- /dev/null +++ b/ui/tts.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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 + +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