Commit 964ded9a authored by Laurent Montel's avatar Laurent Montel 😁

Use mailwebenginescript

parent 0304dd06
......@@ -19,6 +19,7 @@
#include "mailwebenginepage.h"
#include "webengine/webengineaccesskey/webengineaccesskey.h"
#include "webengine/webenginescript.h"
#include "mailwebenginescript.h"
#include "messageviewer/messageviewersettings.h"
#include "loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.h"
#include "cidreferencesurlinterceptor/cidreferencesurlinterceptor.h"
......@@ -251,7 +252,7 @@ void MailWebEngineView::injectAttachments(const boost::function<QString()> &dela
if (html.isEmpty()) {
return;
}
page()->runJavaScript(MessageViewer::WebEngineScript::injectAttachments(html, QStringLiteral("attachmentInjectionPoint")));
page()->runJavaScript(MessageViewer::MailWebEngineScript::injectAttachments(html, QStringLiteral("attachmentInjectionPoint")));
}
void MailWebEngineView::toggleFullAddressList(const QString &field, const boost::function<QString()> &delayedHtml, bool doShow)
......@@ -262,7 +263,7 @@ void MailWebEngineView::toggleFullAddressList(const QString &field, const boost:
}
qDebug() << "void MailWebEngineView::toggleFullAddressList(const QString &field, const boost::function<QString()> &delayedHtml, bool doShow)" << html << " fields " << field;
page()->runJavaScript(MessageViewer::WebEngineScript::replaceInnerHtml(field, html, doShow), invoke(this, &MailWebEngineView::updateToggleFullAddressList));
page()->runJavaScript(MessageViewer::MailWebEngineScript::replaceInnerHtml(field, html, doShow), invoke(this, &MailWebEngineView::updateToggleFullAddressList));
}
void MailWebEngineView::updateToggleFullAddressList(const QVariant &result)
......@@ -275,7 +276,7 @@ void MailWebEngineView::updateToggleFullAddressList(const QVariant &result)
qDebug() << "map !!!! " << map;
const bool show = map.value(QStringLiteral("show")).toBool();
const QString field = map.value(QStringLiteral("field")).toString();
page()->runJavaScript(MessageViewer::WebEngineScript::updateToggleFullAddressList(field, show));
page()->runJavaScript(MessageViewer::MailWebEngineScript::updateToggleFullAddressList(field, show));
}
}
}
......
......@@ -189,65 +189,3 @@ QString WebEngineScript::scrollToRelativePosition(int pos)
const QString source = QString::fromLatin1("window.scrollTo(window.scrollX, %1); [window.scrollX, window.scrollY];").arg(pos);
return source;
}
QString WebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr)
{
const QString source = QString::fromLatin1("var element = document.getElementById('%1'); "
"if (element) { "
" element.innerHTML += '%2';"
"}").arg(elementStr).arg(delayedHtml);
qDebug() << "QString WebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
QString WebEngineScript::replaceInnerHtml(const QString &field, const QString &html, bool doShow)
{
const QString replaceInnerHtmlStr = QLatin1String("iconFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1("(function() {"
"var doShow = %3;"
"var field = \'%4\';"
"var out = [];"
"var element = document.getElementById('%1'); "
"if (element) { "
" element.innerHTML = '%2';"
" out.push({"
" field: field,"
" doShow: doShow"
" });"
"}"
"return out;"
"})()").arg(replaceInnerHtmlStr).arg(html).arg(doShow).arg(field);
qDebug() << "QString WebEngineScript::replaceInnerHtml(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
QString WebEngineScript::updateToggleFullAddressList(const QString &field, bool doShow)
{
const QString dotsFullStr = QLatin1String("dotsFull") + field + QLatin1String("AddressList");
const QString hiddenFullStr = QLatin1String("hiddenFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1(" %1;"
" %2;")
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(dotsFullStr, !doShow))
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(hiddenFullStr, doShow));
qDebug() << "QString WebEngineScript::updateToggleFullAddressList(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
QString WebEngineScript::toggleFullAddressList(const QString &field, const QString &html, bool doShow)
{
const QString replaceInnerHtmlStr = QLatin1String("iconFull") + field + QLatin1String("AddressList");
const QString dotsFullStr = QLatin1String("dotsFull") + field + QLatin1String("AddressList");
const QString hiddenFullStr = QLatin1String("hiddenFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1("var element = document.getElementById('%1'); "
"if (element) { "
" element.innerHTML = '%2';"
" %3;"
" %4;"
"}").arg(replaceInnerHtmlStr).arg(html)
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(dotsFullStr, !doShow))
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(hiddenFullStr, doShow));
qDebug() << "QString WebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
......@@ -38,10 +38,6 @@ MESSAGEVIEWER_EXPORT QString scrollUp(int pixel);
MESSAGEVIEWER_EXPORT QString scrollPercentage(int percent);
MESSAGEVIEWER_EXPORT QString scrollToRelativePosition(int pos);
MESSAGEVIEWER_EXPORT QString removeStyleToElement(const QString &element);
MESSAGEVIEWER_EXPORT QString injectAttachments(const QString &delayedHtml, const QString &element);
MESSAGEVIEWER_EXPORT QString toggleFullAddressList(const QString &field, const QString &html, bool doShow);
MESSAGEVIEWER_EXPORT QString replaceInnerHtml(const QString &field, const QString &html, bool doShow);
MESSAGEVIEWER_EXPORT QString updateToggleFullAddressList(const QString &field, bool doShow);
}
}
#endif // WEBENGINESCRIPT_H
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