[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/base/konq-plugins/babelfish
From: Laurent Montel <montel () kde ! org>
Date: 2008-04-07 22:16:18
Message-ID: 1207606578.862624.5787.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 794575 by mlaurent:
Now it can work with webkitkde
M +23 -1 CMakeLists.txt
A config-babelfish.h.cmake
M +49 -16 plugin_babelfish.cpp
--- trunk/extragear/base/konq-plugins/babelfish/CMakeLists.txt #794574:794575
@@ -1,9 +1,25 @@
+include(MacroOptionalDependPackage)
+MACRO_OPTIONAL_DEPEND_PACKAGE(WebKitKde "webkitkde")
+if(DEPEND_PACKAGE_WebKitKde)
+ macro_optional_find_package(WebKitKde QUIET)
+else(DEPEND_PACKAGE_WebKitKde)
+ set(WEBKITKDE_FOUND FALSE)
+endif(DEPEND_PACKAGE_WebKitKde)
+
+macro_bool_to_01(WEBKITKDE_FOUND HAVE_WEBKITKDE)
+
+configure_file(config-babelfish.h.cmake \
${CMAKE_CURRENT_BINARY_DIR}/config-babelfish.h ) +
########### next target ###############
+if( WEBKITKDE_FOUND )
+ include_directories(${WEBKITKDE_INCLUDE_DIR})
+endif(WEBKITKDE_FOUND)
+
set(babelfishplugin_PART_SRCS plugin_babelfish.cpp )
kde4_add_plugin(babelfishplugin WITH_PREFIX ${babelfishplugin_PART_SRCS})
@@ -11,7 +27,11 @@
target_link_libraries(babelfishplugin ${KDE4_KHTML_LIBS} )
+if( WEBKITKDE_FOUND)
+ target_link_libraries(babelfishplugin ${WEBKITKDE_LIBRARIES} \
${QT_QTWEBKIT_LIBRARY} ) +endif(WEBKITKDE_FOUND)
+
install(TARGETS babelfishplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
@@ -19,6 +39,8 @@
install( FILES plugin_babelfish.rc plugin_babelfish.desktop DESTINATION \
${DATA_INSTALL_DIR}/khtml/kpartplugins ) install( FILES translaterc DESTINATION \
${CONFIG_INSTALL_DIR} )
-
+if(WEBKITKDE_FOUND)
+ install( FILES plugin_babelfish.rc plugin_babelfish.desktop DESTINATION \
${DATA_INSTALL_DIR}/webkitpart/kpartplugins ) +endif(WEBKITKDE_FOUND)
kde4_install_icons( ${ICON_INSTALL_DIR} )
--- trunk/extragear/base/konq-plugins/babelfish/plugin_babelfish.cpp #794574:794575
@@ -3,6 +3,8 @@
Original code: plugin code, connecting to Babelfish and support for selected \
text Copyright (C) 2003 Rand2342 <rand2342@yahoo.com>
Submenus, KConfig file and support for other translation engines
+ Copyright (C) 2008 Montel Laurent <montel@kde.org>
+ Add webkitkde support
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -20,6 +22,11 @@
*/
#include "plugin_babelfish.h"
+#include "config-babelfish.h"
+
+#include <kparts/part.h>
+#include <kparts/browserextension.h>
+
#include <kactionmenu.h>
#include <kaction.h>
#include <kactioncollection.h>
@@ -31,8 +38,14 @@
#include <kgenericfactory.h>
#include <kaboutdata.h>
#include <kicon.h>
-#include <khtml_part.h>
+#include <KConfigGroup>
+#include <KHTMLPart>
+#ifdef HAVE_WEBKITKDE
+#include <webkitpart.h>
+#include <webkitview.h>
+#endif
+
typedef KGenericFactory<PluginBabelFish> BabelFishFactory;
static const KAboutData aboutdata("babelfish", 0, ki18n("Translate Web Page") , \
"1.0" ); K_EXPORT_COMPONENT_FACTORY( libbabelfishplugin, BabelFishFactory( \
&aboutdata ) ) @@ -161,7 +174,7 @@
m_menu->setEnabled( true );
// TODO: we could also support plain text viewers...
- if ( parent && parent->inherits( "KHTMLPart" ) )
+ if ( parent )
{
KParts::ReadOnlyPart* part = static_cast<KParts::ReadOnlyPart *>(parent);
connect( part, SIGNAL(started(KIO::Job*)), this,
@@ -176,7 +189,7 @@
void PluginBabelFish::slotStarted( KIO::Job* )
{
- if ( parent()->inherits("KHTMLPart") &&
+ if ( ( parent()->inherits("KHTMLPart")||parent()->inherits("WebKitPart") ) &&
// Babelfish wants http URLs only. No https.
static_cast<KParts::ReadOnlyPart *>(parent())->url().protocol().toLower() == \
"http" ) {
@@ -195,7 +208,7 @@
return;
// The parent is assumed to be a KHTMLPart
- if ( !parent()->inherits("KHTMLPart") )
+ if ( !parent()->inherits("KHTMLPart")&& !parent()->inherits("WebKitPart") )
{
QString title = i18n( "Cannot Translate Source" );
QString text = i18n( "Only web pages can be translated using "
@@ -211,24 +224,44 @@
QString engine = grp.readEntry( sender()->objectName(), QString("babelfish") );
// Get URL
- KHTMLPart *part = dynamic_cast<KHTMLPart *>(parent());
- if ( !part )
+ KParts::BrowserExtension * ext = KParts::BrowserExtension::childObject(parent());
+ if ( !ext )
return;
// we check if we have text selected. if so, we translate that. If
// not, we translate the url
QString totrans;
- if ( part->hasSelection() )
+
+
+ KHTMLPart *part = dynamic_cast<KHTMLPart *>(parent());
+ bool hasSelection = false;
+ QString selection;
+ KUrl url;
+ if ( part )
{
+ hasSelection = part->hasSelection();
+ selection = part->selectedText();
+ url = part->url();
+ }
+ else
+ {
+#ifdef HAVE_WEBKITKDE
+ WebKitPart *part = dynamic_cast<WebKitPart *>(parent());
+ hasSelection = !part->view()->selectedText().isEmpty();
+ selection = part->view()->selectedText();
+ url = KUrl( part->view()->url() );
+#endif
+ }
+ if ( hasSelection )
+ {
if( engine == "reverso" || engine == "tsail" )
{
- KMessageBox::sorry( 0L, i18n( "Translation Error" ),
- i18n( "Only full webpages can be translated for this language pair." ) \
); + KMessageBox::sorry( 0L,
+ i18n( "Only full webpages can be translated for this language pair." \
),i18n( "Translation Error" ) ); return;
}
- totrans = KUrl::encode_string( part->selectedText() );
+ totrans = KUrl::encode_string( selection );
} else {
- KUrl url = part->url();
// Check syntax
if ( !url.isValid() )
{
@@ -276,7 +309,7 @@
query += "Portuguese/English";
else // Should be en_fr
query += "English/French";
- if ( part->hasSelection() )
+ if ( hasSelection )
{
result = KUrl( "http://ets.freetranslation.com" );
query += "&mode=html&template=results_en-us.htm&srctext=";
@@ -289,7 +322,7 @@
// Does only English -> Thai
result = KUrl( "http://c3po.links.nectec.or.th/cgi-bin/Parsitcgi.exe" );
query = "mode=test&inputtype=";
- if ( part->hasSelection() )
+ if ( hasSelection )
query += "text&TxtEng=";
else
query += "html&inputurl=";
@@ -334,7 +367,7 @@
result = KUrl( "http://trans.voila.fr/voila" );
query = "systran_id=Voila-fr&systran_lp=";
query += sender()->objectName();
- if ( part->hasSelection() )
+ if ( hasSelection )
query += "&systran_charset=utf-8&systran_text=";
else
query += "&systran_url=";
@@ -344,7 +377,7 @@
result = KUrl( "http://babelfish.altavista.com/babelfish/tr" );
query = "lp=";
query += sender()->objectName();
- if ( part->hasSelection() )
+ if ( hasSelection )
query += "&text=";
else
query += "&url=";
@@ -354,7 +387,7 @@
result.setQuery( query );
// Connect to the fish
- emit part->browserExtension()->openUrlRequest( result );
+ emit ext->openUrlRequest( result );
}
#include <plugin_babelfish.moc>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic