File: khtmltts.cpp

package info (click to toggle)
konqueror 4%3A25.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 61,852 kB
  • sloc: cpp: 59,368; python: 943; xml: 682; javascript: 186; sh: 165; makefile: 10
file content (58 lines) | stat: -rw-r--r-- 1,593 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
    SPDX-FileCopyrightText: 2002 George Russell <george.russell@clara.net>
    SPDX-FileCopyrightText: 2003-2004 Olaf Schmidt <ojschmidt@kde.org>
    SPDX-FileCopyrightText: 2015 Jeremy Whiting <jpwhiting@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

// Own
#include "khtmltts.h"
#include "textextension.h"

// Qt
#include <QAction>
#include <QIcon>
#include <QTextToSpeech>

// KDE
#include <KActionCollection>
#include <KLocalizedString>
#include <KParts/ReadOnlyPart>
#include <kpluginfactory.h>

KHTMLPluginTTS::KHTMLPluginTTS(QObject *parent, const QVariantList &)
    : KonqParts::Plugin(parent)
{
    TextExtension *textExt = TextExtension::childObject(parent);
    if (textExt && qobject_cast<KParts::ReadOnlyPart *>(parent)) {
        m_tts = std::unique_ptr<QTextToSpeech>(new QTextToSpeech);

        QAction *action = actionCollection()->addAction(QStringLiteral("tools_tts"));
        action->setIcon(QIcon::fromTheme(QStringLiteral("text-speak")));
        action->setText(i18n("&Speak Text"));
        connect(action, SIGNAL(triggered(bool)), SLOT(slotReadOut()));
    }
}

KHTMLPluginTTS::~KHTMLPluginTTS()
{
}

void KHTMLPluginTTS::slotReadOut()
{
    TextExtension *textExt = TextExtension::childObject(parent());
    QString query;
    const TextExtension::Format format = TextExtension::PlainText;
    if (textExt->hasSelection()) {
        query = textExt->selectedText(format);
    } else {
        query = textExt->completeText(format);
    }

    m_tts->say(query);
}

K_PLUGIN_CLASS_WITH_JSON(KHTMLPluginTTS, "khtmltts.json")

#include "khtmltts.moc"