7#include "templateextracthtmlelementfrommail.h"
8#include "templateparser_debug.h"
9#include "templatewebenginepage.h"
10#include <QWebEngineScript>
12template<
typename Arg,
typename R,
typename C>
13struct InvokeWrapperFunction {
15 void (C::*memberFun)(Arg);
16 void operator()(Arg result)
18 (receiver->*memberFun)(result);
22template<
typename Arg,
typename R,
typename C>
23InvokeWrapperFunction<Arg, R, C> invokeFunction(R *receiver,
void (C::*memberFun)(Arg))
25 InvokeWrapperFunction<Arg, R, C> wrapper = {receiver, memberFun};
29using namespace TemplateParser;
31TemplateExtractHtmlElementFromMail::TemplateExtractHtmlElementFromMail(
QObject *parent)
33 , mPage(new TemplateWebEnginePage(this))
35 connect(mPage, &TemplateWebEnginePage::loadFinished,
this, &TemplateExtractHtmlElementFromMail::slotLoadFinished);
38TemplateExtractHtmlElementFromMail::~TemplateExtractHtmlElementFromMail() =
default;
40void TemplateExtractHtmlElementFromMail::clear()
43 mHeaderElement.
clear();
47void TemplateExtractHtmlElementFromMail::setHtmlContent(
const QString &html)
54QString extractHeaderBodyScript()
56 const QString source = QStringLiteral(
59 " body: document.getElementsByTagName('body')[0].innerHTML,"
60 " header: document.getElementsByTagName('head')[0].innerHTML"
67void TemplateExtractHtmlElementFromMail::slotLoadFinished(
bool success)
70 mPage->runJavaScript(extractHeaderBodyScript(),
71 (QWebEngineScript::UserWorld + 2),
72 invokeFunction(
this, &TemplateExtractHtmlElementFromMail::handleHtmlInfo));
74 Q_EMIT loadContentDone(
false);
78void TemplateExtractHtmlElementFromMail::handleHtmlInfo(
const QVariant &result)
81 const QVariantMap
map = result.
toMap();
82 mBodyElement =
map.value(QStringLiteral(
"body")).toString();
83 mHeaderElement =
map.value(QStringLiteral(
"header")).toString();
84 Q_EMIT loadContentDone(
true);
86 qCWarning(TEMPLATEPARSER_LOG) <<
"Impossible to get value";
87 Q_EMIT loadContentDone(
false);
91QString TemplateExtractHtmlElementFromMail::htmlElement()
const
96QString TemplateExtractHtmlElementFromMail::headerElement()
const
98 return mHeaderElement;
101QString TemplateExtractHtmlElementFromMail::bodyElement()
const
106#include "moc_templateextracthtmlelementfrommail.cpp"
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid() const const
QMap< QString, QVariant > toMap() const const