diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /languages/cpp/app_templates/kpartplugin/plugin_app.cpp | |
download | tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'languages/cpp/app_templates/kpartplugin/plugin_app.cpp')
-rw-r--r-- | languages/cpp/app_templates/kpartplugin/plugin_app.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/languages/cpp/app_templates/kpartplugin/plugin_app.cpp b/languages/cpp/app_templates/kpartplugin/plugin_app.cpp new file mode 100644 index 00000000..a9ee55a3 --- /dev/null +++ b/languages/cpp/app_templates/kpartplugin/plugin_app.cpp @@ -0,0 +1,109 @@ + +#include "plugin_%{APPNAMELC}.h" + +#include <khtml_part.h> +#include <kaction.h> +#include <kinstance.h> +#include <kmessagebox.h> +#include <klocale.h> +#include <kglobal.h> + +Plugin%{APPNAME}::Plugin%{APPNAME}( QObject* parent, const char* name ) + : Plugin( parent, name ) +{ + // Instantiate all of your actions here. These will appear in + // Konqueror's menu and toolbars. + (void) new KAction( i18n("&Plugin Action"), "%{APPNAMELC}", 0, + this, SLOT(slotAction()), + actionCollection(), "plugin_action" ); +} + +Plugin%{APPNAME}::~Plugin%{APPNAME}() +{ +} + +void Plugin%{APPNAME}::slotAction() +{ + // This plugin assumes KHTMLPart. If your plugin can handle more + // than this or a different Part than this, simply delete or + // change the following block. + if ( !parent()->inherits("KHTMLPart") ) + { + QString title( i18n( "Cannot Translate Source" ) ); + QString text( i18n( "You cannot translate anything except web pages " + "with this plugin." ) ); + + KMessageBox::sorry( 0, text, title ); + return; + } + + // Get a handle on our parent so we may get the necessary data for + // processing + KHTMLPart *part = dynamic_cast<KHTMLPart *>(parent()); + + // This plugin only uses the URL. You may use whatever data you + // need. + KURL url( part->url() ); + + // This is a standard check to make sure we are dealing with a + // valid URL + if ( !url.isValid() ) + { + QString title( i18n( "Malformed URL" ) ); + QString text( i18n( "The URL you entered is not valid, please " + "correct it and try again" ) ); + + KMessageBox::sorry( 0, text, title ); + return; + } + +// The following block is very plugin specific. In this example, we +// translate the current page with AltaVista's BabelFish. You will +// definitely want to change this. +// BEGIN + KURL work( "http://babel.altavista.com/translate.dyn" ); + + QString query( "urltext=" ); + query += KURL::encode_string( url.url() ); + work.setQuery( query ); +// END + + // Finally, execute the request + part->openURL( work ); +} + +%{APPNAME}Factory::%{APPNAME}Factory() + : KLibFactory() +{ +} + +%{APPNAME}Factory::~%{APPNAME}Factory() +{ + delete s_instance; + s_instance = 0; +} + +QObject* %{APPNAME}Factory::createObject( QObject* parent, const char* name, const char*, const QStringList & ) +{ + return new Plugin%{APPNAME}( parent, name ); +} + +KInstance *%{APPNAME}Factory::instance() +{ + if ( !s_instance ) + s_instance = new KInstance( "%{APPNAMELC}" ); + return s_instance; +} + +extern "C" +{ + void* init_lib%{APPNAMELC}plugin() + { + KGlobal::locale()->insertCatalogue("%{APPNAMELC}"); + return new %{APPNAME}Factory; + } +} + +KInstance* %{APPNAME}Factory::s_instance = 0L; + +#include "plugin_%{APPNAMELC}.moc" |