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

Start to implement qtwebengine support

parent 2d9c32cb
......@@ -120,8 +120,14 @@
#include "viewer/urlhandlermanager.h"
#include "messageviewer/messageviewerutil.h"
#include "widgets/vcardviewer.h"
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
#include "findbar/findbarwebengineview.h"
#include "viewer/webengine/mailwebengineview.h"
#else
#include "viewer/webview/mailwebview.h"
#include "findbar/findbarwebview.h"
#endif
#include "header/headerstylemenumanager.h"
#include <MimeTreeParser/BodyPart>
......@@ -159,8 +165,8 @@ ViewerPrivate::ViewerPrivate(Viewer *aParent, QWidget *mainWindow,
KActionCollection *actionCollection)
: QObject(aParent),
mNodeHelper(new MimeTreeParser::NodeHelper),
mViewer(0),
mFindBar(0),
mViewer(Q_NULLPTR),
mFindBar(Q_NULLPTR),
mAttachmentStrategy(0),
mUpdateReaderWinTimer(0),
mResizeTimer(0),
......@@ -835,9 +841,14 @@ void ViewerPrivate::displayMessage()
mColorBar->update();
htmlWriter()->queue(QStringLiteral("</body></html>"));
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::injectAttachments, Qt::UniqueConnection);
connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotMessageRendered, Qt::UniqueConnection);
#else
connect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::injectAttachments, Qt::UniqueConnection);
connect(mPartHtmlWriter, SIGNAL(finished()), this, SLOT(toggleFullAddressList()), Qt::UniqueConnection);
connect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotMessageRendered, Qt::UniqueConnection);
#endif
connect(mPartHtmlWriter, SIGNAL(finished()), this, SLOT(toggleFullAddressList()), Qt::UniqueConnection);
htmlWriter()->flush();
}
......@@ -1025,7 +1036,11 @@ void ViewerPrivate::initHtmlWidget()
mViewer->installEventFilter(this);
if (!htmlWriter()) {
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
mPartHtmlWriter = new WebEnginePartHtmlWriter(mViewer, 0);
#else
mPartHtmlWriter = new WebKitPartHtmlWriter(mViewer, 0);
#endif
#ifdef MESSAGEVIEWER_READER_HTML_DEBUG
mHtmlWriter = new TeeHtmlWriter(new FileHtmlWriter(QString()),
mPartHtmlWriter);
......@@ -1033,7 +1048,17 @@ void ViewerPrivate::initHtmlWidget()
mHtmlWriter = mPartHtmlWriter;
#endif
}
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
//TODO
connect(mViewer, &MailWebEngineView::linkHovered,
this, &ViewerPrivate::slotUrlOn);
connect(mViewer, &MailWebEngineView::linkClicked,
this, &ViewerPrivate::slotUrlOpen, Qt::QueuedConnection);
connect(mViewer, &MailWebEngineView::popupMenu,
this, &ViewerPrivate::slotUrlPopup);
connect(mViewer, &MailWebEngineView::messageMayBeAScam, this, &ViewerPrivate::slotMessageMayBeAScam);
connect(mScamDetectionWarning, &ScamDetectionWarningWidget::showDetails, mViewer, &MailWebEngineView::slotShowDetails);
#else
connect(mViewer, &MailWebView::linkHovered,
this, &ViewerPrivate::slotUrlOn);
connect(mViewer, &QWebView::linkClicked,
......@@ -1042,6 +1067,7 @@ void ViewerPrivate::initHtmlWidget()
this, &ViewerPrivate::slotUrlPopup);
connect(mViewer, &MailWebView::messageMayBeAScam, this, &ViewerPrivate::slotMessageMayBeAScam);
connect(mScamDetectionWarning, &ScamDetectionWarningWidget::showDetails, mViewer, &MailWebView::slotShowDetails);
#endif
connect(mScamDetectionWarning, &ScamDetectionWarningWidget::moveMessageToTrash, this, &ViewerPrivate::moveMessageToTrash);
connect(mScamDetectionWarning, &ScamDetectionWarningWidget::messageIsNotAScam, this, &ViewerPrivate::slotMessageIsNotAScam);
connect(mScamDetectionWarning, &ScamDetectionWarningWidget::addToWhiteList, this, &ViewerPrivate::slotAddToWhiteList);
......@@ -1133,11 +1159,15 @@ void ViewerPrivate::readConfig()
adjustLayout();
readGlobalOverrideCodec();
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
mViewer->settings()->setFontSize(QWebEngineSettings::MinimumFontSize, MessageViewer::MessageViewerSettings::self()->minimumFontSize());
mViewer->settings()->setFontSize(QWebEngineSettings::MinimumLogicalFontSize, MessageViewer::MessageViewerSettings::self()->minimumFontSize());
mViewer->settings()->setAttribute(QWebEngineSettings::PrintElementBackgrounds, MessageViewer::MessageViewerSettings::self()->printBackgroundColorImages());
#else
mViewer->settings()->setFontSize(QWebSettings::MinimumFontSize, MessageViewer::MessageViewerSettings::self()->minimumFontSize());
mViewer->settings()->setFontSize(QWebSettings::MinimumLogicalFontSize, MessageViewer::MessageViewerSettings::self()->minimumFontSize());
mViewer->settings()->setAttribute(QWebSettings::PrintElementBackgrounds, MessageViewer::MessageViewerSettings::self()->printBackgroundColorImages());
#endif
if (mMessage) {
update();
}
......@@ -1232,15 +1262,25 @@ void ViewerPrivate::setPrinting(bool enable)
void ViewerPrivate::printMessage(const Akonadi::Item &message)
{
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMsg);
connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMsg);
#else
disconnect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMsg);
connect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMsg);
#endif
setMessageItem(message, MimeTreeParser::Force);
}
void ViewerPrivate::printPreviewMessage(const Akonadi::Item &message)
{
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
connect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
#else
disconnect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
connect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
#endif
setMessageItem(message, MimeTreeParser::Force);
}
......@@ -1470,7 +1510,11 @@ void ViewerPrivate::createWidgets()
mTextToSpeechWidget->setObjectName(QStringLiteral("texttospeechwidget"));
readerBoxVBoxLayout->addWidget(mTextToSpeechWidget);
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
mViewer = new MailWebEngineView(mActionCollection, readerBox);
#else
mViewer = new MailWebView(mActionCollection, readerBox);
#endif
readerBoxVBoxLayout->addWidget(mViewer);
mViewer->setObjectName(QStringLiteral("mViewer"));
......@@ -1487,7 +1531,11 @@ void ViewerPrivate::createWidgets()
mSliderContainer = new KPIMTextEdit::SlideContainer(readerBox);
mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
readerBoxVBoxLayout->addWidget(mSliderContainer);
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
mFindBar = new FindBarWebEngineView(mViewer, q);
#else
mFindBar = new FindBarWebView(mViewer, q);
#endif
connect(mFindBar, &FindBarBase::hideFindBar, mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
mSliderContainer->setContent(mFindBar);
......@@ -1517,9 +1565,13 @@ void ViewerPrivate::createActions()
return;
}
mZoomActionMenu = new MessageViewer::ZoomActionMenu(this);
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
connect(mZoomActionMenu, &ZoomActionMenu::zoomChanged, mViewer, &MailWebEngineView::slotZoomChanged);
connect(mZoomActionMenu, &ZoomActionMenu::zoomTextOnlyChanged, mViewer, &MailWebEngineView::slotZoomTextOnlyChanged);
#else
connect(mZoomActionMenu, &ZoomActionMenu::zoomChanged, mViewer, &MailWebView::slotZoomChanged);
connect(mZoomActionMenu, &ZoomActionMenu::zoomTextOnlyChanged, mViewer, &MailWebView::slotZoomTextOnlyChanged);
#endif
mZoomActionMenu->setActionCollection(ac);
mZoomActionMenu->createZoomActions();
......@@ -1583,9 +1635,13 @@ void ViewerPrivate::createActions()
// copy selected text to clipboard
mCopyAction = ac->addAction(KStandardAction::Copy, QStringLiteral("kmail_copy"), this,
SLOT(slotCopySelectedText()));
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
connect(mViewer, &MailWebEngineView::selectionChanged,
this, &ViewerPrivate::viewerSelectionChanged);
#else
connect(mViewer, &QWebView::selectionChanged,
this, &ViewerPrivate::viewerSelectionChanged);
#endif
viewerSelectionChanged();
// copy all text to clipboard
......@@ -2069,6 +2125,19 @@ void ViewerPrivate::slotShowMessageSource()
return;
}
mNodeHelper->messageWithExtraContent(mMessage.data());
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
//TODO
MailSourceWebEngineViewer *viewer = new MailSourceWebEngineViewer(); // deletes itself upon close
viewer->setWindowTitle(i18n("Message as Plain Text"));
const QString rawMessage = QString::fromLatin1(mMessage->encodedContent());
viewer->setRawSource(rawMessage);
//const QString htmlSource = mViewer->page()->mainFrame()->documentElement().toOuterXml();
viewer->setDisplayedSource(htmlSource);
if (mUseFixedFont) {
viewer->setFixedFont();
}
#else
MailSourceViewer *viewer = new MailSourceViewer(); // deletes itself upon close
viewer->setWindowTitle(i18n("Message as Plain Text"));
const QString rawMessage = QString::fromLatin1(mMessage->encodedContent());
......@@ -2078,7 +2147,7 @@ void ViewerPrivate::slotShowMessageSource()
if (mUseFixedFont) {
viewer->setFixedFont();
}
#endif
// Well, there is no widget to be seen here, so we have to use QCursor::pos()
// Update: (GS) I'm not going to make this code behave according to Xinerama
// configuration because this is quite the hack.
......@@ -2208,24 +2277,40 @@ void ViewerPrivate::slotDelayedResize()
void ViewerPrivate::slotPrintPreview()
{
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
#else
disconnect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotPrintPreview);
#endif
if (!mMessage) {
return;
}
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
qDebug() << "ViewerPrivate::slotPrintPreview() not implemented";
#else
PimCommon::KPimPrintPreviewDialog previewdlg(mViewer);
connect(&previewdlg, &QPrintPreviewDialog::paintRequested, this, [this](QPrinter * printer) {
mViewer->print(printer);
});
previewdlg.exec();
#endif
}
void ViewerPrivate::slotPrintMsg()
{
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMsg);
#else
disconnect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::slotPrintMsg);
#endif
if (!mMessage) {
return;
}
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
qDebug() << " ViewerPrivate::slotPrintMsg() not implemented";
#else
QPrinter printer;
QScopedPointer<QPrintDialog> dlg(new QPrintDialog(&printer));
......@@ -2233,6 +2318,7 @@ void ViewerPrivate::slotPrintMsg()
if (dlg && dlg->exec() == QDialog::Accepted) {
mViewer->print(&printer);
}
#endif
}
void ViewerPrivate::slotSetEncoding()
......@@ -2300,7 +2386,11 @@ QString ViewerPrivate::attachmentInjectionHtml()
void ViewerPrivate::injectAttachments()
{
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
disconnect(mPartHtmlWriter.data(), &WebEnginePartHtmlWriter::finished, this, &ViewerPrivate::injectAttachments);
#else
disconnect(mPartHtmlWriter.data(), &WebKitPartHtmlWriter::finished, this, &ViewerPrivate::injectAttachments);
#endif
// inject attachments in header view
// we have to do that after the otp has run so we also see encrypted parts
......
......@@ -75,10 +75,16 @@ namespace MessageViewer
{
class HeaderStylePlugin;
class CSSHelper;
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
class FindBarWebEngineView;
class MailWebEngineView;
class WebEnginePartHtmlWriter;
#else
class FindBarWebView;
class MailWebView;
class WebKitPartHtmlWriter;
#endif
class HtmlStatusBar;
class MailWebView;
class ScamDetectionWarningWidget;
class MimePartTreeView;
class OpenAttachmentFolderWidget;
......@@ -601,8 +607,13 @@ public:
#ifndef QT_NO_TREEVIEW
MimePartTreeView *mMimePartTree;
#endif
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
FindBarWebEngineView *mFindBar;
MailWebEngineView *mViewer;
#else
MailWebView *mViewer;
FindBarWebView *mFindBar;
#endif
const MimeTreeParser::AttachmentStrategy *mAttachmentStrategy;
QTimer mUpdateReaderWinTimer;
......@@ -650,7 +661,11 @@ public:
MimeTreeParser::HtmlWriter *mHtmlWriter;
/** Used only to be able to connect and disconnect finished() signal
in printMsg() and slotPrintMsg() since mHtmlWriter points only to abstract non-QObject class. */
#ifdef MESSAGEVIEWER_USE_QTWEBENGINE
QPointer<WebEnginePartHtmlWriter> mPartHtmlWriter;
#else
QPointer<WebKitPartHtmlWriter> mPartHtmlWriter;
#endif
float mSavedRelativePosition;
int mLevelQuote;
......
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