summaryrefslogtreecommitdiffstats
path: root/konqueror/kttsplugin
diff options
context:
space:
mode:
Diffstat (limited to 'konqueror/kttsplugin')
-rw-r--r--konqueror/kttsplugin/Makefile.am16
-rw-r--r--konqueror/kttsplugin/khtmlkttsd.cpp138
-rw-r--r--konqueror/kttsplugin/khtmlkttsd.desktop75
-rw-r--r--konqueror/kttsplugin/khtmlkttsd.h46
-rw-r--r--konqueror/kttsplugin/khtmlkttsd.rc13
5 files changed, 288 insertions, 0 deletions
diff --git a/konqueror/kttsplugin/Makefile.am b/konqueror/kttsplugin/Makefile.am
new file mode 100644
index 000000000..580a18dcd
--- /dev/null
+++ b/konqueror/kttsplugin/Makefile.am
@@ -0,0 +1,16 @@
+INCLUDES = $(all_includes)
+METASOURCES = AUTO
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = libkhtmlkttsdplugin.la
+
+libkhtmlkttsdplugin_la_SOURCES = khtmlkttsd.cpp
+libkhtmlkttsdplugin_la_LIBADD = $(LIB_KHTML)
+libkhtmlkttsdplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+
+pluginsdir = $(kde_datadir)/khtml/kpartplugins
+plugins_DATA = khtmlkttsd.rc khtmlkttsd.desktop
+
+messages: rc.cpp
+ $(EXTRACTRC) *.rc > rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/khtmlkttsd.pot
diff --git a/konqueror/kttsplugin/khtmlkttsd.cpp b/konqueror/kttsplugin/khtmlkttsd.cpp
new file mode 100644
index 000000000..cda947223
--- /dev/null
+++ b/konqueror/kttsplugin/khtmlkttsd.cpp
@@ -0,0 +1,138 @@
+/***************************************************************************
+ Copyright:
+ (C) 2002 by George Russell <george.russell@clara.net>
+ (C) 2003-2004 by Olaf Schmidt <ojschmidt@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 <khtml_part.h> // this plugin applies to a khtml part
+#include <dom/html_document.h>
+#include <dom/html_element.h>
+#include <dom/dom_string.h>
+#include <kdebug.h>
+#include "khtmlkttsd.h"
+#include <kaction.h>
+#include <kgenericfactory.h>
+#include <kiconloader.h>
+#include <qmessagebox.h>
+#include <klocale.h>
+#include <qstring.h>
+#include <qtimer.h>
+#include <kspeech.h>
+#include <qbuffer.h>
+
+#include <kapplication.h>
+#include <dcopclient.h>
+#include <ktrader.h>
+
+KHTMLPluginKTTSD::KHTMLPluginKTTSD( QObject* parent, const char* name, const QStringList& )
+ : Plugin( parent, name )
+{
+ // If KTTSD is not installed, hide action.
+ KTrader::OfferList offers = KTrader::self()->query("DCOP/Text-to-Speech", "Name == 'KTTSD'");
+ if (offers.count() > 0)
+ {
+ (void) new KAction( i18n("&Speak Text"),
+ "kttsd", 0,
+ this, SLOT(slotReadOut()),
+ actionCollection(), "tools_kttsd" );
+ }
+ else
+ kdDebug() << "KHTMLPLuginKTTSD::KHTMLPluginKTTSD: KTrader did not find KTTSD." << endl;
+}
+
+KHTMLPluginKTTSD::~KHTMLPluginKTTSD()
+{
+}
+
+void KHTMLPluginKTTSD::slotReadOut()
+{
+ // The parent is assumed to be a KHTMLPart
+ if ( !parent()->inherits("KHTMLPart") )
+ QMessageBox::warning( 0, i18n( "Cannot Read source" ),
+ i18n( "You cannot read anything except web pages with\n"
+ "this plugin, sorry." ));
+ else
+ {
+ // If KTTSD not running, start it.
+ DCOPClient *client = kapp->dcopClient();
+ if (!client->isApplicationRegistered("kttsd"))
+ {
+ QString error;
+ if (kapp->startServiceByDesktopName("kttsd", QStringList(), &error))
+ QMessageBox::warning(0, i18n( "Starting KTTSD Failed"), error );
+ }
+
+ // Find out if KTTSD supports xhtml (rich speak).
+ QByteArray data;
+ QBuffer dataBuf(data);
+ QDataStream arg;
+ dataBuf.open(IO_WriteOnly);
+ arg.setDevice(&dataBuf);
+ arg << "" << KSpeech::mtHtml;
+ QCString replyType;
+ QByteArray replyData;
+ bool supportsXhtml = false;
+ if ( !client->call("kttsd", "KSpeech", "supportsMarkup(QString,uint)",
+ data, replyType, replyData, true) )
+ QMessageBox::warning( 0, i18n( "DCOP Call Failed" ),
+ i18n( "The DCOP call supportsMarkup failed." ));
+ else
+ {
+ QDataStream reply(replyData, IO_ReadOnly);
+ reply >> supportsXhtml;
+ }
+
+ KHTMLPart *part = (KHTMLPart *) parent();
+
+ QString query;
+ if (supportsXhtml)
+ {
+ kdDebug() << "KTTS claims to support rich speak (XHTML to SSML)." << endl;
+ if (part->hasSelection())
+ query = part->selectedTextAsHTML();
+ else
+ {
+ // TODO: Fooling around with the selection probably has unwanted
+ // side effects, but until a method is supplied to get valid xhtml
+ // from entire document..
+ // query = part->document().toString().string();
+ part->selectAll();
+ query = part->selectedTextAsHTML();
+ // Restore no selection.
+ part->setSelection(part->document().createRange());
+ }
+ } else {
+ if (part->hasSelection())
+ query = part->selectedText();
+ else
+ query = part->htmlDocument().body().innerText().string();
+ }
+ // kdDebug() << "KHTMLPluginKTTSD::slotReadOut: query = " << query << endl;
+
+ dataBuf.at(0); // reset data
+ arg << query << "";
+ if ( !client->call("kttsd", "KSpeech", "setText(QString,QString)",
+ data, replyType, replyData, true) )
+ QMessageBox::warning( 0, i18n( "DCOP Call Failed" ),
+ i18n( "The DCOP call setText failed." ));
+ dataBuf.at(0);
+ arg << 0;
+ if ( !client->call("kttsd", "KSpeech", "startText(uint)",
+ data, replyType, replyData, true) )
+ QMessageBox::warning( 0, i18n( "DCOP Call Failed" ),
+ i18n( "The DCOP call startText failed." ));
+ }
+}
+
+K_EXPORT_COMPONENT_FACTORY( libkhtmlkttsdplugin, KGenericFactory<KHTMLPluginKTTSD>("khtmlkttsd") )
+
+#include "khtmlkttsd.moc"
diff --git a/konqueror/kttsplugin/khtmlkttsd.desktop b/konqueror/kttsplugin/khtmlkttsd.desktop
new file mode 100644
index 000000000..96bfcafeb
--- /dev/null
+++ b/konqueror/kttsplugin/khtmlkttsd.desktop
@@ -0,0 +1,75 @@
+[Desktop Entry]
+X-KDE-Library=libkhtmlkttsdplugin
+X-KDE-PluginInfo-Author=Olaf Schmidt
+X-KDE-PluginInfo-Email=ojschmidt@kde.org
+X-KDE-PluginInfo-Name=khtmlkttsdplugin
+X-KDE-PluginInfo-Version=3.4
+X-KDE-PluginInfo-Website=
+X-KDE-PluginInfo-Category=Tools
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+X-KDE-ParentApp=konqueror
+Name=Text-to-Speech Plugin
+Name[ar]=برنامج مساعد تحويل لفظ النص
+Name[be]=Утулка галасавога ўзнаўлення тэксту
+Name[bg]=Приставка за синтез на глас
+Name[bn]=লেখা-থেকে-বলা প্লাগ-ইন
+Name[bs]=Dodatak za izgovaranje teksta
+Name[ca]=Endollable de text a veu
+Name[cs]=Modul text-na-řeč
+Name[csb]=Plugins czëtôrza tekstu
+Name[da]=Tekst-til-tale plugin
+Name[de]=Sprachausgabe-Plugin
+Name[el]=Πρόσθετο κείμενο σε ομιλία
+Name[eo]=Teksto-Paroligilo Kromaĵo
+Name[es]=Complemento de Texto-a-Voz
+Name[et]=Teksti kõneks muutmise plugin
+Name[eu]=Testu-ahotserako plugina
+Name[fa]=وصلۀ متن به سخن
+Name[fi]=Teksti puheeksi -liitännäinen
+Name[fr]=Module de synthèse vocale
+Name[fy]=Tekst-ta-spraak-plugin
+Name[ga]=Breiseán Téacs-go-Caint
+Name[gl]=Plugin de Texto-a-Fala
+Name[he]=תוסף טקסט אל דיבור
+Name[hr]=Pretvaranje teksta u govor
+Name[hu]=Szövegfelolvasó modul
+Name[is]=Texti-í-tal íforrit
+Name[it]=Plugin lettura del testo (text-to-speech)
+Name[ja]=テキスト読み上げプラグイン
+Name[ka]=ტექსტის გახმოვანების მოდული
+Name[kk]=Дыбыстап оқу модулі
+Name[km]=កម្មវិធី​ជំនួយ​ខាង​ក្នុង អត្ថបទ-ទៅ​ជា-សម្ដី
+Name[ko]=Text-to-Speech
+Name[lt]=Teksto vertimo kalba priedas
+Name[mk]=Приклучок за текст-во-говор
+Name[ms]=Plugin Teks-ke-Tutur
+Name[nb]=Programtillegg for tekst-til-tale
+Name[nds]=Vörleser-Plugin
+Name[ne]=पाठलाई वाक्यमा प्लगइन
+Name[nl]=Tekst-tot-spraak-plugin
+Name[nn]=Programtillegg for tekst-til-tale
+Name[pa]=ਪਾਠ ਤੋਂ ਬੋਲੀ ਪਲੱਗਇਨ
+Name[pl]=Wtyczka odczytywania tekstu
+Name[pt]='Plugin' de Texto-para-Fala
+Name[pt_BR]=Plug-in de Conversão de Fala
+Name[ro]=Modul vorbire text
+Name[ru]=Зачитывание текста
+Name[rw]=Icomeka Umwandiko-ku-Imvugo
+Name[sk]=Modul text-na-reč
+Name[sl]=Vstavek za pretvorbo besedila v govor
+Name[sr]=Прикључак за текст-у-говор
+Name[sr@Latn]=Priključak za tekst-u-govor
+Name[sv]=Text till tal-insticksprogram
+Name[ta]=உரையில் இருந்து பேச்சு சொருகுப்பொருள்
+Name[th]=ปลั๊กอิน เปลี่ยนตัวหนังสือเป็นเสียง
+Name[tr]=Metinden-Sese Eklentisi
+Name[tt]=Yazma-Uquçı Östämä
+Name[uk]=Втулок синтезу мовлення з тексту
+Name[vi]=Trình bổ sung Chuyển Văn bản thành Tiếng nói
+Name[wa]=Tchôke-divins tecse viè parole
+Name[zh_CN]=文本到语音插件
+Name[zh_TW]=文字轉換語音外掛程式
+Icon=kttsd
+
diff --git a/konqueror/kttsplugin/khtmlkttsd.h b/konqueror/kttsplugin/khtmlkttsd.h
new file mode 100644
index 000000000..aa1608498
--- /dev/null
+++ b/konqueror/kttsplugin/khtmlkttsd.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ Copyright:
+ (C) 2002 by George Russell <george.russell@clara.net>
+ (C) 2003-2004 by Olaf Schmidt <ojschmidt@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 KHTMLKTTSD_H
+#define KHTMLKTTSD_H
+
+#include <kparts/plugin.h>
+
+class KURL;
+class KInstance;
+
+/**
+ * KHTML KParts Plugin
+ */
+class KHTMLPluginKTTSD : public KParts::Plugin
+{
+ Q_OBJECT
+public:
+
+ /**
+ * Construct a new KParts plugin.
+ */
+ KHTMLPluginKTTSD( QObject* parent, const char* name, const QStringList& );
+
+ /**
+ * Destructor.
+ */
+ virtual ~KHTMLPluginKTTSD();
+public slots:
+ void slotReadOut();
+};
+
+#endif
diff --git a/konqueror/kttsplugin/khtmlkttsd.rc b/konqueror/kttsplugin/khtmlkttsd.rc
new file mode 100644
index 000000000..388aec9e7
--- /dev/null
+++ b/konqueror/kttsplugin/khtmlkttsd.rc
@@ -0,0 +1,13 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="khtmlkttsdplugin" library="libkhtmlkttsdplugin" version="2" >
+ <MenuBar>
+ <Menu name="tools">
+ <Text>&amp;Tools</Text>
+ <Action name="tools_kttsd"/>
+ </Menu>
+ </MenuBar>
+ <ToolBar name="Speech Toolbar" hidden="true">
+ <Action name="tools_kttsd"/>
+ </ToolBar>
+</kpartgui>
+