[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/apps/konqueror/kttsplugin
From: David Faure <faure () kde ! org>
Date: 2010-09-27 11:49:15
Message-ID: 20100927114915.48FF5AC857 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1180213 by dfaure:
Port to KParts::TextExtension, so that this doesn't have to link both khtml and \
webkit anymore. You need kdelibs trunk (>= last Friday).
M +3 -28 CMakeLists.txt
D config-kttsplugin.h.cmake
M +12 -72 khtmlkttsd.cpp
--- trunk/KDE/kdebase/apps/konqueror/kttsplugin/CMakeLists.txt #1180212:1180213
@@ -1,45 +1,20 @@
+########### khtmlkttsdplugin ###############
-
-
-########### next target ###############
-
include(MacroOptionalDependPackage)
-MACRO_OPTIONAL_DEPEND_PACKAGE(KWebKitPart "kwebkitpart")
-if(DEPEND_PACKAGE_KWebKitPart)
- macro_optional_find_package(KWebKitPart QUIET)
-else(DEPEND_PACKAGE_KWebKitPart)
- set(KWEBKITPART_FOUND FALSE)
-endif(DEPEND_PACKAGE_KWebKitPart)
-
-if(KWEBKITPART_FOUND)
- set(HAVE_KWEBKITPART true)
- include_directories(${KWEBKITPART_INCLUDE_DIR})
-endif(KWEBKITPART_FOUND)
-
-
-configure_file(config-kttsplugin.h.cmake \
${CMAKE_CURRENT_BINARY_DIR}/config-kttsplugin.h )
-
-
set(khtmlkttsdplugin_PART_SRCS khtmlkttsd.cpp )
qt4_add_dbus_interfaces(khtmlkttsdplugin_PART_SRCS \
${KDE4_DBUS_INTERFACES_DIR}/org.kde.KSpeech.xml)
kde4_add_plugin(khtmlkttsdplugin ${khtmlkttsdplugin_PART_SRCS})
-target_link_libraries(khtmlkttsdplugin ${KDE4_KHTML_LIBS} )
+target_link_libraries(khtmlkttsdplugin ${KDE4_KPARTS_LIBS} )
-if(KWEBKITPART_FOUND)
- target_link_libraries(khtmlkttsdplugin ${KWEBKITPART_LIBRARIES} \
${KDE4_KDEWEBKIT_LIBS} ${QT_QTWEBKIT_LIBRARY} )
-endif(KWEBKITPART_FOUND)
-
-
install(TARGETS khtmlkttsdplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES khtmlkttsd.rc khtmlkttsd.desktop DESTINATION \
${DATA_INSTALL_DIR}/khtml/kpartplugins )
-if(KWEBKITPART_FOUND)
install( FILES khtmlkttsd.rc khtmlkttsd.desktop DESTINATION \
${DATA_INSTALL_DIR}/kwebkitpart/kpartplugins )
-endif(KWEBKITPART_FOUND)
+
--- trunk/KDE/kdebase/apps/konqueror/kttsplugin/khtmlkttsd.cpp #1180212:1180213
@@ -19,33 +19,24 @@
#include "kspeechinterface.h"
// KDE
-#include <dom/dom_string.h>
-#include <dom/html_document.h>
-#include <dom/html_element.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <kdebug.h>
-#include <khtml_part.h> // this plugin applies to a khtml part
-#include <config-kttsplugin.h>
#include <kicon.h>
#include <klocale.h>
#include <kmessagebox.h>
+#include <kparts/part.h>
+#include <kparts/textextension.h>
#include <kpluginfactory.h>
#include <kservicetypetrader.h>
#include <kspeech.h>
#include <ktoolinvocation.h>
-#ifdef HAVE_KWEBKITPART
-#include <kwebkitpart.h>
-#include <QWebFrame>
-#include <QWebView>
-#endif
-
-
KHTMLPluginKTTSD::KHTMLPluginKTTSD( QObject* parent, const QVariantList& )
: Plugin( parent )
{
- if (qobject_cast<KHTMLPart*>(parent)) { // should always be true, but let's make \
sure + KParts::TextExtension* textExt = \
KParts::TextExtension::childObject(parent); + if (textExt && \
qobject_cast<KParts::ReadOnlyPart *>(parent)) { QAction *action = \
actionCollection()->addAction( "tools_kttsd" ); action->setIcon( KIcon("text-speak") \
); action->setText( i18n("&Speak Text") );
@@ -59,7 +50,7 @@
void KHTMLPluginKTTSD::slotReadOut()
{
- // The parent is assumed to be a KHTMLPart (checked in constructor)
+ // The parent is a KParts::ReadOnlyPart (checked in constructor)
KParts::ReadOnlyPart* part = static_cast<KParts::ReadOnlyPart *>(parent());
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kttsd"))
@@ -80,70 +71,19 @@
else
{
supportsXhtml = reply.value() & KSpeech::tcCanParseHtml;
- }
-
- QString query;
- bool hasSelection = false;
- KHTMLPart *compPart = dynamic_cast<KHTMLPart *>(part);
- if ( compPart )
- {
if (supportsXhtml)
- {
kDebug() << "KTTS claims to support rich speak (XHTML to SSML).";
- if (hasSelection)
- query = compPart->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();
- compPart->selectAll();
- query = compPart->selectedTextAsHTML();
- // Restore no selection.
- compPart->setSelection(compPart->document().createRange());
}
+
+ KParts::TextExtension* textExt = KParts::TextExtension::childObject(parent());
+ QString query;
+ const KParts::TextExtension::Format format = supportsXhtml ? \
KParts::TextExtension::HTML : KParts::TextExtension::PlainText; + if \
(textExt->hasSelection()) { + query = textExt->selectedText(format);
} else {
- if (hasSelection)
- query = compPart->selectedText();
- else
- query = compPart->htmlDocument().body().innerText().string();
+ query = textExt->completeText(format);
}
- }
-#ifdef HAVE_KWEBKITPART
- else
- {
- KWebKitPart *webkitPart = dynamic_cast<KWebKitPart *>(part);
- if ( webkitPart )
- {
- if (supportsXhtml)
- {
- kDebug() << "KTTS claims to support rich speak (XHTML to SSML).";
- if (hasSelection)
- query = webkitPart->view()->page()->currentFrame()->toHtml();
- 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();
-#if 0
- webkitPart->selectAll();
- query = webkitPart->view()->page()->currentFrame()->toHtml();
- // Restore no selection.
- webkitPart->setSelection(webkitPart->document().createRange());
-#endif
- }
- } else {
- if (hasSelection)
- query = webkitPart->view()->selectedText();
- else
- query = webkitPart->view()->page()->currentFrame()->toHtml();
- }
- }
- }
-#endif
// kDebug() << "query =" << query;
reply = kttsd.say(query, KSpeech::soNone);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic