Commit 8cc8a810 authored by Laurent Montel's avatar Laurent Montel 😁

Allow to test jquery

parent 3147a9cc
......@@ -645,5 +645,11 @@ QList<QAction *> Viewer::interceptorUrlActions(const WebEngineViewer::WebHitTest
return d->interceptorUrlActions(result);
}
void Viewer::runJavaScript(const QString &code)
{
Q_D(Viewer);
d->mViewer->page()->runJavaScript(code);
}
}
......@@ -327,6 +327,7 @@ public:
QList<QAction *> viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features);
QList<QAction *> interceptorUrlActions(const WebEngineViewer::WebHitTestResult &result) const;
void runJavaScript(const QString &code);
Q_SIGNALS:
void moveMessageToTrash();
void executeMailAction(MessageViewer::Viewer::MailAction type);
......
......@@ -27,14 +27,21 @@
#include <QPushButton>
#include <QMessageBox>
#include <QTextEdit>
#include <QFile>
#include <MessageViewer/Viewer>
TestJQuerySupportMailWebEngine::TestJQuerySupportMailWebEngine(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
//true => use JQuery
pageView = new WebEngineViewer::WebEngineView(true, this);
vboxLayout->addWidget(pageView);
viewer = new MessageViewer::Viewer(0);
vboxLayout->addWidget(viewer);
viewer->setMessage(readAndParseMail(QStringLiteral("encapsulated-with-attachment.mbox"))/*KMime::Message::Ptr(msg)*/);
viewer->setPluginName(QStringLiteral("longheaderstyleplugin"));
mEditor = new QTextEdit(this);
mEditor->setAcceptRichText(false);
......@@ -44,8 +51,6 @@ TestJQuerySupportMailWebEngine::TestJQuerySupportMailWebEngine(QWidget *parent)
QPushButton *executeQuery = new QPushButton(QStringLiteral("Execute Query"), this);
connect(executeQuery, &QPushButton::clicked, this, &TestJQuerySupportMailWebEngine::slotExecuteQuery);
vboxLayout->addWidget(executeQuery);
pageView->load(QUrl(QStringLiteral("http://www.kde.org")));
}
TestJQuerySupportMailWebEngine::~TestJQuerySupportMailWebEngine()
......@@ -53,11 +58,25 @@ TestJQuerySupportMailWebEngine::~TestJQuerySupportMailWebEngine()
}
KMime::Message::Ptr TestJQuerySupportMailWebEngine::readAndParseMail(const QString &mailFile)
{
QFile file(QLatin1String(MAIL_DATA_DIR) + QLatin1Char('/') + mailFile);
file.open(QIODevice::ReadOnly);
QByteArray ba = file.readAll();
qDebug() << ba;
const QByteArray data = ba;
Q_ASSERT(!data.isEmpty());
KMime::Message::Ptr msg(new KMime::Message);
msg->setContent(data);
msg->parse();
return msg;
}
void TestJQuerySupportMailWebEngine::slotExecuteQuery()
{
const QString code = mEditor->toPlainText();
if (!code.isEmpty()) {
pageView->page()->runJavaScript(code);
viewer->runJavaScript(code);
}
}
......
......@@ -21,11 +21,12 @@
#define TestJQuerySupportMailWebEngine_H
#include <QWidget>
#include <qwebengineview.h>
namespace WebEngineViewer
#include <KMime/Message>
namespace MessageViewer
{
class WebEngineView;
class Viewer;
}
class QTextEdit;
class TestJQuerySupportMailWebEngine : public QWidget
{
......@@ -38,7 +39,8 @@ private Q_SLOTS:
void slotExecuteQuery();
private:
WebEngineViewer::WebEngineView *pageView;
KMime::Message::Ptr readAndParseMail(const QString &mailFile);
MessageViewer::Viewer *viewer;
QTextEdit *mEditor;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment