summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2016-04-06 17:21:16 +0200
committerKai Koehne <kai.koehne@qt.io>2016-04-20 13:02:34 +0000
commit7d76c6b2cd8989f134f678789bba2f13ed019153 (patch)
tree32d2e8b1cef5067bf389ca420c0f0698eba64051 /examples
parentddc4c40e2dcba81d36c9a4c445f1540b90403997 (diff)
SimpleBrowser: Use new QWebEnginePage::icon API
Change-Id: I38d16a57116517aee21f6f84c5fca82192cb1572 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu> Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.cpp11
-rw-r--r--examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc13
-rw-r--r--examples/webenginewidgets/simplebrowser/simplebrowser.pro2
-rw-r--r--examples/webenginewidgets/simplebrowser/tabwidget.cpp16
-rw-r--r--examples/webenginewidgets/simplebrowser/webpopupwindow.cpp7
-rw-r--r--examples/webenginewidgets/simplebrowser/webview.cpp44
-rw-r--r--examples/webenginewidgets/simplebrowser/webview.h8
7 files changed, 19 insertions, 82 deletions
diff --git a/examples/webenginewidgets/simplebrowser/browser.cpp b/examples/webenginewidgets/simplebrowser/browser.cpp
index 78b60b8f8..f1420c2a3 100644
--- a/examples/webenginewidgets/simplebrowser/browser.cpp
+++ b/examples/webenginewidgets/simplebrowser/browser.cpp
@@ -42,20 +42,9 @@
#include "browserwindow.h"
#include "webview.h"
#include <QAuthenticator>
-#include <QNetworkProxy>
-#include <QNetworkReply>
Browser::Browser()
{
- // QTBUG-47967 , downloading favIcon support is coming in 5.7
- QObject::connect(&WebView::networkAccessManager(), &QNetworkAccessManager::authenticationRequired,
- [](QNetworkReply *, QAuthenticator *) {
- qWarning("Authentication required for downloading favicon.");
- });
- QObject::connect(&WebView::networkAccessManager(), &QNetworkAccessManager::proxyAuthenticationRequired,
- [](const QNetworkProxy &, QAuthenticator *) {
- qWarning("Proxy authentication required for downloading favicon.");
- });
}
Browser::~Browser()
diff --git a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
index b8df9b02a..e57ec80ec 100644
--- a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
+++ b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
@@ -123,7 +123,6 @@
functionality:
\list
- \li Downloading favicons
\li Displaying error messages in case \c renderProcess dies
\li Handling \c createWindow requests
\li Adding custom menu items to context menus
@@ -136,21 +135,11 @@
\printuntil WebView(
\dots
\skipto protected:
- \printuntil handleIconLoaded
+ \printuntil webActionEnabledChanged
\skipto }
\dots
\printline };
- \section2 Downloading Favicons
-
- To download a favicon, we use QNetworkAccessManager and create a
- QNetworkRequest every time the URL specified by
- QWebEngineView::iconUrlChanged is emitted:
-
- \quotefromfile webenginewidgets/simplebrowser/webview.cpp
- \skipto WebView::handleIconUrlChanged(
- \printuntil }
-
\section2 Displaying Error Messages
If the render process is terminated, we display a QMessageBox with an error
diff --git a/examples/webenginewidgets/simplebrowser/simplebrowser.pro b/examples/webenginewidgets/simplebrowser/simplebrowser.pro
index ad8a9a2bd..197d68091 100644
--- a/examples/webenginewidgets/simplebrowser/simplebrowser.pro
+++ b/examples/webenginewidgets/simplebrowser/simplebrowser.pro
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = simplebrowser
-QT += webenginewidgets network
+QT += webenginewidgets
CONFIG += c++11
HEADERS += \
diff --git a/examples/webenginewidgets/simplebrowser/tabwidget.cpp b/examples/webenginewidgets/simplebrowser/tabwidget.cpp
index 3c6269f52..a7f855c2a 100644
--- a/examples/webenginewidgets/simplebrowser/tabwidget.cpp
+++ b/examples/webenginewidgets/simplebrowser/tabwidget.cpp
@@ -80,7 +80,11 @@ void TabWidget::handleCurrentChanged(int index)
emit titleChanged(view->title());
emit loadProgress(view->loadProgress());
emit urlChanged(view->url());
- emit iconChanged(view->icon());
+ QIcon pageIcon = view->page()->icon();
+ if (!pageIcon.isNull())
+ emit iconChanged(pageIcon);
+ else
+ emit iconChanged(QIcon(QStringLiteral(":defaulticon.png")));
emit webActionEnabledChanged(QWebEnginePage::Back, view->isWebActionEnabled(QWebEnginePage::Back));
emit webActionEnabledChanged(QWebEnginePage::Forward, view->isWebActionEnabled(QWebEnginePage::Forward));
emit webActionEnabledChanged(QWebEnginePage::Stop, view->isWebActionEnabled(QWebEnginePage::Stop));
@@ -89,7 +93,7 @@ void TabWidget::handleCurrentChanged(int index)
emit titleChanged(QString());
emit loadProgress(0);
emit urlChanged(QUrl());
- emit iconChanged(QIcon());
+ emit iconChanged(QIcon(QStringLiteral(":defaulticon.png")));
emit webActionEnabledChanged(QWebEnginePage::Back, false);
emit webActionEnabledChanged(QWebEnginePage::Forward, false);
emit webActionEnabledChanged(QWebEnginePage::Stop, false);
@@ -166,12 +170,14 @@ void TabWidget::setupView(WebView *webView)
if (currentIndex() == indexOf(webView))
emit linkHovered(url);
});
- connect(webView, &WebView::iconChanged, [this, webView](const QIcon& icon) {
+ connect(webPage, &WebPage::iconChanged, [this, webView](const QIcon &icon) {
int index = indexOf(webView);
+ QIcon ico = icon.isNull() ? QIcon(QStringLiteral(":defaulticon.png")) : icon;
+
if (index != -1)
- setTabIcon(index, icon);
+ setTabIcon(index, ico);
if (currentIndex() == index)
- emit iconChanged(icon);
+ emit iconChanged(ico);
});
connect(webView, &WebView::webActionEnabledChanged, [this, webView](QWebEnginePage::WebAction action, bool enabled) {
if (currentIndex() == indexOf(webView))
diff --git a/examples/webenginewidgets/simplebrowser/webpopupwindow.cpp b/examples/webenginewidgets/simplebrowser/webpopupwindow.cpp
index a3175e546..8146dcfb7 100644
--- a/examples/webenginewidgets/simplebrowser/webpopupwindow.cpp
+++ b/examples/webenginewidgets/simplebrowser/webpopupwindow.cpp
@@ -65,7 +65,7 @@ WebPopupWindow::WebPopupWindow(QWebEngineProfile *profile)
connect(m_view, &WebView::titleChanged, this, &QWidget::setWindowTitle);
connect(m_view, &WebView::urlChanged, this, &WebPopupWindow::setUrl);
- connect(m_view, &WebView::iconChanged, this, &WebPopupWindow::handleIconChanged);
+ connect(m_view->page(), &WebPage::iconChanged, this, &WebPopupWindow::handleIconChanged);
connect(m_view->page(), &WebPage::geometryChangeRequested, this, &WebPopupWindow::handleGeometryChangeRequested);
connect(m_view->page(), &WebPage::windowCloseRequested, this, &QWidget::close);
}
@@ -91,5 +91,8 @@ void WebPopupWindow::handleGeometryChangeRequested(const QRect &newGeometry)
void WebPopupWindow::handleIconChanged(const QIcon &icon)
{
- m_addressBar->setFavIcon(icon);
+ if (icon.isNull())
+ m_addressBar->setFavIcon(QIcon(QStringLiteral(":defaulticon.png")));
+ else
+ m_addressBar->setFavIcon(icon);
}
diff --git a/examples/webenginewidgets/simplebrowser/webview.cpp b/examples/webenginewidgets/simplebrowser/webview.cpp
index 559daca61..d92545620 100644
--- a/examples/webenginewidgets/simplebrowser/webview.cpp
+++ b/examples/webenginewidgets/simplebrowser/webview.cpp
@@ -47,7 +47,6 @@
#include <QContextMenuEvent>
#include <QMenu>
#include <QMessageBox>
-#include <QNetworkReply>
#include <QTimer>
WebView::WebView(QWidget *parent)
@@ -59,11 +58,10 @@ WebView::WebView(QWidget *parent)
});
connect(this, &QWebEngineView::loadFinished, [this](bool success) {
if (!success) {
- qWarning() << "Could not load page: " << url();
m_loadProgress = 0;
}
});
- connect(this, &QWebEngineView::iconUrlChanged, this, &WebView::handleIconUrlChanged);
+
connect(this, &QWebEngineView::renderProcessTerminated,
[this](QWebEnginePage::RenderProcessTerminationStatus termStatus, int statusCode) {
QString status;
@@ -95,13 +93,6 @@ void WebView::setPage(WebPage *page)
QWebEngineView::setPage(page);
}
-QIcon WebView::icon() const
-{
- if (!m_icon.isNull())
- return m_icon;
- return QIcon(QLatin1String(":defaulticon.png"));
-}
-
int WebView::loadProgress() const
{
return m_loadProgress;
@@ -120,12 +111,6 @@ bool WebView::isWebActionEnabled(QWebEnginePage::WebAction webAction) const
return page()->action(webAction)->isEnabled();
}
-QNetworkAccessManager &WebView::networkAccessManager()
-{
- static QNetworkAccessManager networkAccessManager;
- return networkAccessManager;
-}
-
QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type)
{
switch (type) {
@@ -164,30 +149,3 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
menu->popup(event->globalPos());
}
-void WebView::handleIconUrlChanged(const QUrl &url)
-{
- QNetworkRequest iconRequest(url);
-#ifndef QT_NO_OPENSSL
- QSslConfiguration conf = iconRequest.sslConfiguration();
- conf.setPeerVerifyMode(QSslSocket::VerifyNone);
- iconRequest.setSslConfiguration(conf);
-#endif
- QNetworkReply *iconReply = networkAccessManager().get(iconRequest);
- iconReply->setParent(this);
- connect(iconReply, &QNetworkReply::finished, this, &WebView::handleIconLoaded);
-}
-
-void WebView::handleIconLoaded()
-{
- QNetworkReply *iconReply = qobject_cast<QNetworkReply*>(sender());
- if (iconReply && iconReply->error() == QNetworkReply::NoError) {
- QByteArray data = iconReply->readAll();
- QPixmap pixmap;
- pixmap.loadFromData(data);
- m_icon.addPixmap(pixmap);
- iconReply->deleteLater();
- } else {
- m_icon = QIcon(QStringLiteral(":defaulticon.png"));
- }
- emit iconChanged(m_icon);
-}
diff --git a/examples/webenginewidgets/simplebrowser/webview.h b/examples/webenginewidgets/simplebrowser/webview.h
index 5450ee247..f06162ea3 100644
--- a/examples/webenginewidgets/simplebrowser/webview.h
+++ b/examples/webenginewidgets/simplebrowser/webview.h
@@ -54,29 +54,21 @@ public:
WebView(QWidget *parent = nullptr);
void setPage(WebPage *page);
- QIcon icon() const;
int loadProgress() const;
bool isWebActionEnabled(QWebEnginePage::WebAction webAction) const;
- static QNetworkAccessManager &networkAccessManager();
protected:
void contextMenuEvent(QContextMenuEvent *event) override;
QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) override;
signals:
- void iconChanged(const QIcon &icon);
void webActionEnabledChanged(QWebEnginePage::WebAction webAction, bool enabled);
-private slots:
- void handleIconUrlChanged(const QUrl &url);
- void handleIconLoaded();
-
private:
void createWebActionTrigger(QWebEnginePage *page, QWebEnginePage::WebAction);
private:
int m_loadProgress;
- QIcon m_icon;
};
#endif