Commit 19803027 authored by Laurent Montel's avatar Laurent Montel 😁

Merge remote-tracking branch 'origin/Applications/17.04'

parents bfa31bb2 9ddb2772
......@@ -41,6 +41,7 @@
#include "job/attachmenteditjob.h"
#include "job/modifymessagedisplayformatjob.h"
#include "config-messageviewer.h"
#include "webengine/mailwebenginescript.h"
#include "viewerplugins/viewerplugintoolmanager.h"
#include <WebEngineViewer/WebEnginePrintMessageBox>
#include <KContacts/VCardConverter>
......@@ -900,6 +901,11 @@ void ViewerPrivate::displayMessage()
connect(mViewer, &MailWebEngineView::loadStarted, this, &ViewerPrivate::slotLoadStarted, Qt::UniqueConnection);
connect(mViewer, &MailWebEngineView::loadFinished, this, &ViewerPrivate::executeCustomScriptsAfterLoading, Qt::UniqueConnection);
connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotMessageRendered, Qt::UniqueConnection);
const QString html = attachmentInjectionHtml();
const QString js = html.isEmpty() ? QString() : MessageViewer::MailWebEngineScript::injectAttachments(html, QStringLiteral("attachmentInjectionPoint"));
mViewer->addScript(js, QStringLiteral("attachment_injection"), QWebEngineScript::DocumentReady);
htmlWriter()->flush();
}
......@@ -1862,11 +1868,6 @@ QString ViewerPrivate::renderAttachments(KMime::Content *node, const QColor &bgC
if (child) {
QString subHtml = renderAttachments(child, nextColor(bgColor));
if (!subHtml.isEmpty()) {
QString visibility;
if (!mShowAttachmentQuicklist) {
visibility = QStringLiteral("display:none;");
}
QString margin;
if (node != mMessage.data() || headerStylePlugin()->hasMargin()) {
margin = QStringLiteral("padding:2px; margin:2px; ");
......@@ -1875,8 +1876,8 @@ QString ViewerPrivate::renderAttachments(KMime::Content *node, const QColor &bgC
const QByteArray mediaTypeLower = node->contentType()->mediaType().toLower();
const bool result = (mediaTypeLower == "message" || mediaTypeLower == "multipart" || node == mMessage.data());
if (result)
html += QStringLiteral("<div id=\"attachmentid\" style=\"background:%1; %2"
"vertical-align:middle; float:%3; %4\">").arg(bgColor.name()).arg(margin).arg(align).arg(visibility);
html += QStringLiteral("<div style=\"background:%1; %2"
"vertical-align:middle; float:%3;\">").arg(bgColor.name()).arg(margin).arg(align);
html += subHtml;
if (result) {
html += QLatin1String("</div>");
......@@ -2388,6 +2389,9 @@ QString ViewerPrivate::attachmentInjectionHtml()
return QString();
}
const QString listVisibility = !mShowAttachmentQuicklist ? QStringLiteral("style=\"display:none;\"") : QString();
html = QStringLiteral("<div id=\"attachmentlist\" %1>").arg(listVisibility) + html + QStringLiteral("</div>");
const QString urlHandleShow = QStringLiteral("kmail:showAttachmentQuicklist");
const QString imgSrcShow = QStringLiteral("quicklistClosed.png");
const QString urlHandleHide = QStringLiteral("kmail:hideAttachmentQuicklist");
......@@ -2426,7 +2430,6 @@ void ViewerPrivate::executeCustomScriptsAfterLoading()
// inject attachments in header view
// we have to do that after the otp has run so we also see encrypted parts
mViewer->injectAttachments(bind(&ViewerPrivate::attachmentInjectionHtml, this));
toggleFullAddressList();
mViewer->scrollToRelativePosition(mViewer->relativePosition());
mViewer->clearRelativePosition();
......
......@@ -22,16 +22,21 @@
#include <QDebug>
using namespace MessageViewer;
static QString checkJQuery(const char *scriptName)
{
return QStringLiteral("if (!qt) { console.warn(\"%1 executed too early, 'qt' variable unknown\"); };").arg(QString::fromLatin1(scriptName));
}
QString MailWebEngineScript::createShowHideAddressScript(const QString &field, bool hide)
{
QString source;
QString source = checkJQuery("createShowHideAddressScript");
if (hide) {
source = QString::fromLatin1("qt.jQuery('#kmail%1show').hide();"
source += QString::fromLatin1("qt.jQuery(\"#kmail%1show\").hide();"
"qt.jQuery(\"#kmail%1hide\").show();"
"qt.jQuery(\"#dotsFull%1AddressList\").hide();"
"qt.jQuery(\"#hiddenFull%1AddressList\").show();").arg(field);
} else {
source = QString::fromLatin1("qt.jQuery(\"#kmail%1hide\").hide();"
source += QString::fromLatin1("qt.jQuery(\"#kmail%1hide\").hide();"
"qt.jQuery(\"#kmail%1show\").show();"
"qt.jQuery(\"#dotsFull%1AddressList\").show();"
"qt.jQuery(\"#hiddenFull%1AddressList\").hide();").arg(field);
......@@ -51,29 +56,31 @@ QString MailWebEngineScript::manageShowHideCcAddress(bool hide)
QString MailWebEngineScript::manageShowHideAttachments(bool hide)
{
QString source;
QString source = checkJQuery("manageShowHideAttachments");
if (hide) {
source = QString::fromLatin1("qt.jQuery(\"#kmailhideattachment\").hide();"
source += QString::fromLatin1("qt.jQuery(\"#kmailhideattachment\").hide();"
"qt.jQuery(\"#kmailshowattachment\").show();"
"qt.jQuery(\"#attachmentid\").show();");
"if (!qt.jQuery(\"#attachmentlist\")) { console.warn('attachmentlist not found'); } else { qt.jQuery(\"#attachmentlist\").show(); }");
} else {
source = QString::fromLatin1("qt.jQuery('#kmailshowattachment').hide();"
source += QString::fromLatin1("qt.jQuery('#kmailshowattachment').hide();"
"qt.jQuery(\"#kmailhideattachment\").show();"
"qt.jQuery(\"#attachmentid\").hide();");
"if (!qt.jQuery(\"#attachmentlist\")) { console.warn('attachmentlist not found'); } else { qt.jQuery(\"#attachmentlist\").hide(); }");
}
return source;
}
QString MailWebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr)
{
const QString source = QString::fromLatin1("qt.jQuery('#%1').append('%2')").arg(elementStr, delayedHtml);
const QString source = checkJQuery("injectAttachments") + QString::fromLatin1(
"if (!document.getElementById('%1')) { console.warn('NOT FOUND: %1'); };"
"qt.jQuery('#%1').append('%2')").arg(elementStr, delayedHtml);
return source;
}
QString MailWebEngineScript::replaceInnerHtml(const QString &field, const QString &html)
{
const QString replaceInnerHtmlStr = QLatin1String("iconFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1("qt.jQuery('#%1').append('%2')").arg(replaceInnerHtmlStr, html);
const QString source = checkJQuery("replaceInnerHtml") + QString::fromLatin1("qt.jQuery('#%1').append('%2')").arg(replaceInnerHtmlStr, html);
return source;
}
......@@ -373,15 +373,6 @@ void MailWebEngineView::executeHideShowAttachmentsScripts(bool hide)
runJavaScriptInWordId(source);
}
void MailWebEngineView::injectAttachments(const boost::function<QString()> &delayedHtml)
{
const QString html = delayedHtml();
if (html.isEmpty()) {
return;
}
runJavaScriptInWordId(MessageViewer::MailWebEngineScript::injectAttachments(html, QStringLiteral("attachmentInjectionPoint")));
}
void MailWebEngineView::toggleFullAddressList(const QString &field, const boost::function<QString()> &delayedHtml)
{
const QString html = delayedHtml();
......
......@@ -55,7 +55,6 @@ public:
void scrollToAnchor(const QString &anchor);
void scrollPageDown(int percent);
void scrollPageUp(int percent);
void injectAttachments(const boost::function<QString()> &delayedHtml);
void scrollToRelativePosition(qreal pos);
......
qt.jQuery('#kmailshowattachment').click(function(){
qt.jQuery('#kmailshowattachment').hide();
qt.jQuery("#kmailhideattachment").show();
qt.jQuery("#attachmentid").hide()}
qt.jQuery("#attachmentlist").hide()}
);
qt.jQuery('#kmailhideattachment').click(function(){
qt.jQuery("#kmailhideattachment").hide();
qt.jQuery("#kmailshowattachment").show();
qt.jQuery("#attachmentid").show()}
qt.jQuery("#attachmentlist").show()}
);
......@@ -98,7 +98,7 @@ bool WebEnginePage::acceptNavigationRequest(const QUrl &url, NavigationType type
void WebEngineViewer::WebEnginePage::javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level, const QString &message, int lineNumber, const QString &sourceID)
{
Q_UNUSED(level);
Q_UNUSED(lineNumber);
Q_UNUSED(sourceID);
qDebug() << lineNumber << ":" << message;
Q_EMIT showConsoleMessage(message);
}
......@@ -179,13 +179,9 @@ QString WebEngineScript::scrollToRelativePosition(qreal pos)
QString WebEngineScript::isScrolledToBottom()
{
return QString::fromLatin1("(function() { "
"var isAtBottom = 0;"
"if (qt.jQuery(window).scrollTop() + qt.jQuery(window).height() == qt.jQuery(document).height())"
"{ "
" isAtBottom = 1;"
"} else {"
" isAtBottom = 0;"
"}"
"var docElement = document.documentElement;"
"var viewportHeight = docElement.clientHeight;"
"var isAtBottom = document.body.scrollTop + viewportHeight >= document.body.scrollHeight;"
"return Boolean(isAtBottom); "
"}());");
}
......@@ -76,12 +76,10 @@ WebEngineManageScript *WebEngineView::webEngineManagerScript() const
void WebEngineView::initializeJQueryScript()
{
QFile file;
file.setFileName(QStringLiteral(":/data/jquery.min.js"));
QFile file(QStringLiteral(":/data/jquery.min.js"));
file.open(QIODevice::ReadOnly);
QString jquery = QString::fromUtf8(file.readAll());
jquery.append(QStringLiteral("\nvar qt = { 'jQuery': jQuery.noConflict(true) };"));
file.close();
d->mManagerScript->addScript(page()->profile(), jquery, QStringLiteral("jquery"), QWebEngineScript::DocumentCreation);
}
......
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