From: romibi Date: Fri, 10 Jun 2016 09:05:20 +0000 (+0200) Subject: Use QtWebEngine instead of QtWebKit if available X-Git-Tag: travis-deploy-test~455 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=138e6d461c259df8052497d7228391ce6548bd5f Use QtWebEngine instead of QtWebKit if available --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 681cceb7..75c4d577 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,10 @@ if (NOT WITH_KDE) endif() # For this, the feature info is added after we know if QtWebkit is installed -option(WITH_WEBKIT "WebKit support (for link previews)" ON) +option(WITH_WEBKIT "WebKit support (for link previews) (legacy)" ON) + +# For this, the feature info is added after we know if QtWebEngine is installed +option(WITH_WEBENGINE "WebEngine support (for link previews)" ON) if (APPLE) # Notification Center is only available in > 10.8, which is Darwin v12 @@ -267,7 +270,29 @@ if (USE_QT5) if (WITH_WEBKIT AND Qt5WebKitWidgets_FOUND) set(HAVE_WEBKIT true) endif() - add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat") + add_feature_info("WITH_WEBKIT, QtWebKit and QtWebKitWidgets modules" HAVE_WEBKIT "Support showing previews for URLs in chat (legacy)") + + if (WITH_WEBENGINE) + find_package(Qt5WebEngine QUIET) + set_package_properties(Qt5WebEngine PROPERTIES TYPE RECOMMENDED + URL "http://qt.digia.com" + DESCRIPTION "a WebEngine implementation for Qt" + PURPOSE "Needed for displaying previews for URLs in chat" + ) + if (Qt5WebEngine_FOUND) + find_package(Qt5WebEngineWidgets QUIET) + set_package_properties(Qt5WebEngineWidgets PROPERTIES TYPE RECOMMENDED + URL "http://qt.digia.com" + DESCRIPTION "widgets for Qt's WebEngine implementation" + PURPOSE "Needed for displaying previews for URLs in chat" + ) + endif() + endif() + + if (WITH_WEBENGINE AND Qt5WebEngineWidgets_FOUND) + set(HAVE_WEBENGINE true) + endif() + add_feature_info("WITH_WEBENGINE, QtWebEngine and QtWebEngineWidgets modules" HAVE_WEBENGINE "Support showing previews for URLs in chat") # KDE Frameworks ################ diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index fdf5eaa8..7e1574cf 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -144,6 +144,14 @@ if (HAVE_WEBKIT) endif() endif() +if (HAVE_WEBENGINE) + add_definitions(-DHAVE_WEBENGINE) + list(APPEND QT_MODULES WebEngine) + if (USE_QT5) + list(APPEND QT_MODULES WebEngineWidgets) + endif() +endif() + if(HAVE_SSL) set(SOURCES ${SOURCES} sslinfodlg.cpp) set(FORMS ${FORMS} sslinfodlg.ui) diff --git a/src/qtui/chatitem.cpp b/src/qtui/chatitem.cpp index 45abc82b..47106398 100644 --- a/src/qtui/chatitem.cpp +++ b/src/qtui/chatitem.cpp @@ -836,7 +836,7 @@ void ContentsChatItem::copyLinkToClipboard() void ContentsChatItem::showWebPreview(const Clickable &click) { -#ifndef HAVE_WEBKIT +#if !defined HAVE_WEBKIT && !defined HAVE_WEBENGINE Q_UNUSED(click); #else QTextLine line = layout()->lineForTextPosition(click.start()); @@ -859,7 +859,7 @@ void ContentsChatItem::showWebPreview(const Clickable &click) void ContentsChatItem::clearWebPreview() { -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE chatScene()->clearWebPreview(this); #endif } diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 07adaa08..2f147428 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -36,7 +36,9 @@ # include #endif -#ifdef HAVE_WEBKIT +#ifdef HAVE_WEBENGINE +# include +#elif defined HAVE_WEBKIT # include #endif @@ -122,7 +124,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w this, SLOT(rowsRemoved())); connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE webPreview.timer.setSingleShot(true); connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep())); #endif @@ -1171,9 +1173,9 @@ void ChatScene::updateSceneRect(const QRectF &rect) // ======================================== -// Webkit Only stuff +// Webkit/WebEngine Only stuff // ======================================== -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE void ChatScene::loadWebPreview(ChatItem *parentItem, const QUrl &url, const QRectF &urlRect) { if (!_showWebPreview) diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index a30879be..c1e35157 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -149,7 +149,7 @@ public slots: void requestBacklog(); -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE void loadWebPreview(ChatItem *parentItem, const QUrl &url, const QRectF &urlRect); void clearWebPreview(ChatItem *parentItem = 0); #endif @@ -175,7 +175,7 @@ protected slots: private slots: void firstHandlePositionChanged(qreal xpos); void secondHandlePositionChanged(qreal xpos); -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE void webPreviewNextStep(); #endif void showWebPreviewChanged(); @@ -228,7 +228,7 @@ private: static const int _webSearchSelectionTextMaxVisible = 24; -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE struct WebPreview { enum PreviewState { NoPreview, @@ -246,7 +246,7 @@ private: WebPreview() : parentItem(0), previewItem(0), previewState(NoPreview) {} }; WebPreview webPreview; -#endif // HAVE_WEBKIT +#endif // HAVE_WEBKIT || HAVE_WEBENGINE }; diff --git a/src/qtui/settingspages/chatviewsettingspage.cpp b/src/qtui/settingspages/chatviewsettingspage.cpp index 7f1de1ff..47463881 100644 --- a/src/qtui/settingspages/chatviewsettingspage.cpp +++ b/src/qtui/settingspages/chatviewsettingspage.cpp @@ -29,7 +29,7 @@ ChatViewSettingsPage::ChatViewSettingsPage(QWidget *parent) { ui.setupUi(this); -#ifndef HAVE_WEBKIT +#if !defined HAVE_WEBKIT && !defined HAVE_WEBENGINE ui.showWebPreview->hide(); ui.showWebPreview->setEnabled(false); #endif diff --git a/src/qtui/webpreviewitem.cpp b/src/qtui/webpreviewitem.cpp index 7f4c4bdc..4941fa22 100644 --- a/src/qtui/webpreviewitem.cpp +++ b/src/qtui/webpreviewitem.cpp @@ -20,12 +20,18 @@ #include "webpreviewitem.h" -#ifdef HAVE_WEBKIT +#ifdef HAVE_WEBENGINE +#include +#include +#elif defined HAVE_WEBKIT +#include +#include +#endif + +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE #include #include -#include -#include WebPreviewItem::WebPreviewItem(const QUrl &url) : QGraphicsItem(0), // needs to be a top level item as we otherwise cannot guarantee that it's on top of other chatlines @@ -33,8 +39,13 @@ WebPreviewItem::WebPreviewItem(const QUrl &url) { qreal frameWidth = 5; +#ifdef HAVE_WEBENGINE + QWebEngineView *webView = new QWebEngineView; + webView->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); +#elif defined HAVE_WEBKIT QWebView *webView = new QWebView; webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, false); +#endif webView->load(url); webView->setDisabled(true); webView->resize(1000, 750); @@ -62,4 +73,4 @@ void WebPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op } -#endif //#ifdef HAVE_WEBKIT +#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE diff --git a/src/qtui/webpreviewitem.h b/src/qtui/webpreviewitem.h index d6b90efa..51caacac 100644 --- a/src/qtui/webpreviewitem.h +++ b/src/qtui/webpreviewitem.h @@ -21,7 +21,7 @@ #ifndef WEBPREVIEWITEM_H #define WEBPREVIEWITEM_H -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE #include @@ -37,6 +37,6 @@ private: }; -#endif //#ifdef HAVE_WEBKIT +#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE #endif //WEBPREVIEWITEM_H