summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/browser/webview.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-28 16:35:16 +0200
committerAllan Sandfeld Jensen <allan.jensen@digia.com>2014-07-30 12:45:12 +0200
commita99922affdc7953f092dcfcf34ea741567a5bddc (patch)
tree3c6a0c272060c4e35b345e17803d76c4e29b641e /examples/webenginewidgets/browser/webview.cpp
parente1b98a164799d90f51336c718724fe8e6db01568 (diff)
Add api to get the favicon URL
Adds one of the missing pieces of the QWebFrame and QWebView APIs. Unlike the QtWebKit version this only fetches the favicon URL, and not the icon. This is because we do not want to implement an icon database, and that the icon would be loaded asynchronous anyway, bringing no guarantee to be a valid icon/image yet. Change-Id: I227311ae3676044da850e687b82bee752b5079c8 Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'examples/webenginewidgets/browser/webview.cpp')
-rw-r--r--examples/webenginewidgets/browser/webview.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/webenginewidgets/browser/webview.cpp b/examples/webenginewidgets/browser/webview.cpp
index edbaadca9..d4dd2649c 100644
--- a/examples/webenginewidgets/browser/webview.cpp
+++ b/examples/webenginewidgets/browser/webview.cpp
@@ -311,6 +311,7 @@ WebView::WebView(QWidget* parent)
: QWebEngineView(parent)
, m_progress(0)
, m_page(new WebPage(this))
+ , m_iconReply(0)
{
setPage(m_page);
#if defined(QWEBENGINEPAGE_STATUSBARMESSAGE)
@@ -323,6 +324,8 @@ WebView::WebView(QWidget* parent)
this, SLOT(loadFinished()));
connect(page(), SIGNAL(loadingUrl(QUrl)),
this, SIGNAL(urlChanged(QUrl)));
+ connect(page(), SIGNAL(iconUrlChanged(QUrl)),
+ this, SLOT(onIconUrlChanged(QUrl)));
#if defined(QWEBENGINEPAGE_DOWNLOADREQUESTED)
connect(page(), SIGNAL(downloadRequested(QNetworkRequest)),
this, SLOT(downloadRequested(QNetworkRequest)));
@@ -423,6 +426,35 @@ QUrl WebView::url() const
return m_initialUrl;
}
+QIcon WebView::icon() const
+{
+ if (!m_icon.isNull())
+ return m_icon;
+ return BrowserApplication::instance()->defaultIcon();
+}
+
+void WebView::onIconUrlChanged(const QUrl &url)
+{
+ QNetworkRequest iconRequest(url);
+ m_iconReply = BrowserApplication::networkAccessManager()->get(iconRequest);
+ m_iconReply->setParent(this);
+ connect(m_iconReply, SIGNAL(finished()), this, SLOT(iconLoaded()));
+}
+
+void WebView::iconLoaded()
+{
+ m_icon = QIcon();
+ if (m_iconReply) {
+ QByteArray data = m_iconReply->readAll();
+ QPixmap pixmap;
+ pixmap.loadFromData(data);
+ m_icon.addPixmap(pixmap);
+ m_iconReply->deleteLater();
+ m_iconReply = 0;
+ }
+ emit iconChanged();
+}
+
void WebView::mousePressEvent(QMouseEvent *event)
{
m_page->m_pressedButtons = event->buttons();