Use QtWebEngine instead of QtWebKit if available
authorromibi <romibi@bluewin.ch>
Fri, 10 Jun 2016 09:05:20 +0000 (11:05 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 28 Feb 2018 22:10:07 +0000 (23:10 +0100)
(cherry picked from commit 138e6d461c259df8052497d7228391ce6548bd5f)

CMakeLists.txt
src/qtui/CMakeLists.txt
src/qtui/chatitem.cpp
src/qtui/chatscene.cpp
src/qtui/chatscene.h
src/qtui/settingspages/chatviewsettingspage.cpp
src/qtui/webpreviewitem.cpp
src/qtui/webpreviewitem.h

index 03ac969..0e9296b 100644 (file)
@@ -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
@@ -258,7 +261,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
         ################
index 8510a71..f082602 100644 (file)
@@ -137,6 +137,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)
index 20dad9d..fd68ecc 100644 (file)
@@ -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
 }
index 3d5534d..c9816d5 100644 (file)
@@ -36,7 +36,9 @@
 #  include <QMenuBar>
 #endif
 
-#ifdef HAVE_WEBKIT
+#ifdef HAVE_WEBENGINE
+#  include <QWebEngineView>
+#elif defined HAVE_WEBKIT
 #  include <QWebView>
 #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)
index d950c72..d821b12 100644 (file)
@@ -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
 };
 
 
index 9106613..f317eda 100644 (file)
@@ -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
index 1d7a27c..ebee5ea 100644 (file)
 
 #include "webpreviewitem.h"
 
-#ifdef HAVE_WEBKIT
+#ifdef HAVE_WEBENGINE
+#include <QWebEngineView>
+#include <QWebEngineSettings>
+#elif defined HAVE_WEBKIT
+#include <QWebView>
+#include <QWebSettings>
+#endif
+
+#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE
 
 #include <QGraphicsProxyWidget>
 #include <QPainter>
-#include <QWebView>
-#include <QWebSettings>
 
 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
index 1ad2e85..71620c8 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef WEBPREVIEWITEM_H
 #define WEBPREVIEWITEM_H
 
-#ifdef HAVE_WEBKIT
+#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE
 
 #include <QGraphicsItem>
 
@@ -37,6 +37,6 @@ private:
 };
 
 
-#endif //#ifdef HAVE_WEBKIT
+#endif //#ifdef HAVE_WEBKIT || HAVE_WEBENGINE
 
 #endif //WEBPREVIEWITEM_H