2011-03-02 16:57:41 +01:00
|
|
|
#include "testplugin.h"
|
2012-02-19 16:01:51 +01:00
|
|
|
#include "qupzilla.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
PluginSpec TestPlugin::pluginSpec()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-02-19 16:01:51 +01:00
|
|
|
PluginSpec spec;
|
|
|
|
spec.name = tr("Example Plugin");
|
|
|
|
spec.info = tr("Example minimal plugin");
|
|
|
|
spec.description = tr("Very simple minimal plugin example");
|
|
|
|
spec.version = "0.0.1";
|
|
|
|
spec.author = "David Rosca <nowrep@gmail.com>";
|
|
|
|
spec.icon = QIcon(":qupzilla.png");
|
|
|
|
spec.hasSettings = true;
|
|
|
|
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlugin::init(const QString &sPath)
|
|
|
|
{
|
|
|
|
qDebug() << __FUNCTION__ << "called";
|
|
|
|
|
|
|
|
// This function is called right after plugin is loaded
|
|
|
|
// it will be called even if we return false from testPlugin()
|
|
|
|
// so it is recommended not to call any QupZilla function here
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
settingsPath = sPath;
|
2012-02-19 16:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlugin::unload()
|
|
|
|
{
|
2011-03-02 16:57:41 +01:00
|
|
|
qDebug() << __FUNCTION__ << "called";
|
2012-02-19 16:01:51 +01:00
|
|
|
|
|
|
|
// This function will be called when unloading plugin
|
|
|
|
// it will be also called if we return false from testPlugin()
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TestPlugin::testPlugin()
|
|
|
|
{
|
2011-03-03 22:52:15 +01:00
|
|
|
//This function is called right after init()
|
2011-03-02 16:57:41 +01:00
|
|
|
//There should be some testing if plugin is loaded correctly
|
|
|
|
//If this function returns false, plugin is automatically unloaded
|
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
return (QupZilla::VERSION == "1.1.8");
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
QTranslator* TestPlugin::getTranslator(const QString &locale)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
QTranslator* translator = new QTranslator();
|
2011-12-16 19:07:36 +01:00
|
|
|
translator->load(":/" + locale);
|
2011-03-02 16:57:41 +01:00
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
void TestPlugin::showSettings(QWidget *parent)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-02-19 16:01:51 +01:00
|
|
|
QDialog* dialog = new QDialog(parent);
|
|
|
|
QPushButton* b = new QPushButton("Example Plugin v0.0.1");
|
|
|
|
|
|
|
|
QHBoxLayout* l = new QHBoxLayout(dialog);
|
|
|
|
l->addWidget(b);
|
|
|
|
dialog->setLayout(l);
|
|
|
|
|
|
|
|
dialog->resize(200, 200);
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->setWindowTitle("Example Plugin Settings");
|
|
|
|
dialog->setWindowIcon(QIcon(":/qupzilla.png"));
|
|
|
|
|
|
|
|
dialog->show();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-19 16:01:51 +01:00
|
|
|
void TestPlugin::populateWebViewMenu(QMenu* menu, QWebView* view, const QWebHitTestResult &r)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(view)
|
|
|
|
QString title;
|
2011-12-16 19:07:36 +01:00
|
|
|
if (!r.imageUrl().isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
title += " on image";
|
2011-12-16 19:07:36 +01:00
|
|
|
}
|
|
|
|
if (!r.linkUrl().isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
title += " on link";
|
2011-12-16 19:07:36 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
QWebElement element = r.element();
|
2011-12-16 19:07:36 +01:00
|
|
|
if (!element.isNull() && (element.tagName().toLower() == "input" || element.tagName().toLower() == "textarea")) {
|
|
|
|
title += " on input";
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
menu->addAction(tr("My first plugin action") + title, this, SLOT(actionSlot()));
|
|
|
|
}
|
|
|
|
|
2011-12-16 19:07:36 +01:00
|
|
|
void TestPlugin::populateHelpMenu(QMenu* menu)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
menu->addAction(tr("My first plugin action"), this, SLOT(actionSlot()));
|
|
|
|
}
|
|
|
|
|
2011-12-16 19:07:36 +01:00
|
|
|
void TestPlugin::populateToolsMenu(QMenu* menu)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
menu->addAction(tr("My first plugin action"), this, SLOT(actionSlot()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestPlugin::actionSlot()
|
|
|
|
{
|
|
|
|
QMessageBox::information(0, tr("Hello"), tr("First plugin action works :-)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Export plugin macro
|
|
|
|
Q_EXPORT_PLUGIN2(ExamplePlugin, TestPlugin)
|