1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 12:46:35 +01:00

Use QWebEngineView::icon() instead of custom icon downloading

This commit is contained in:
David Rosca 2016-10-24 21:19:27 +02:00
parent e1c97e1a6d
commit 38bf9d2b4a
7 changed files with 5 additions and 116 deletions

View File

@ -208,7 +208,6 @@ SOURCES += \
tools/toolbutton.cpp \
tools/treewidget.cpp \
tools/widget.cpp \
webengine/iconloader.cpp \
webengine/javascript/autofilljsobject.cpp \
webengine/javascript/externaljsobject.cpp \
webengine/loadrequest.cpp \
@ -391,7 +390,6 @@ HEADERS += \
tools/toolbutton.h \
tools/treewidget.h \
tools/widget.h \
webengine/iconloader.h \
webengine/javascript/autofilljsobject.h \
webengine/javascript/externaljsobject.h \
webengine/loadrequest.h \

View File

@ -130,7 +130,7 @@ void LocationBar::setWebView(TabbedWebView* view)
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
connect(m_webView, SIGNAL(urlChanged(QUrl)), this, SLOT(showUrl(QUrl)));
connect(m_webView, SIGNAL(privacyChanged(bool)), this, SLOT(setPrivacyState(bool)));
connect(m_webView, SIGNAL(iconChanged()), this, SLOT(updateSiteIcon()));
connect(m_webView, &TabbedWebView::iconChanged, this, &LocationBar::updateSiteIcon);
}
void LocationBar::setText(const QString &text)

View File

@ -55,7 +55,7 @@ void TabIcon::setWebTab(WebTab* tab)
connect(m_tab->webView(), SIGNAL(loadStarted()), this, SLOT(showLoadingAnimation()));
connect(m_tab->webView(), SIGNAL(loadFinished(bool)), this, SLOT(hideLoadingAnimation()));
connect(m_tab->webView(), SIGNAL(iconChanged()), this, SLOT(showIcon()));
connect(m_tab->webView(), &WebView::iconChanged, this, &TabIcon::showIcon);
showIcon();
}

View File

@ -1,41 +0,0 @@
/* ============================================================
* QupZilla - QtWebEngine based browser
* Copyright (C) 2015-2016 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "iconloader.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "qztools.h"
#include <QTimer>
#include <QNetworkReply>
IconLoader::IconLoader(const QUrl &url, QObject *parent)
: QObject(parent)
, m_reply(Q_NULLPTR)
{
m_reply = mApp->networkManager()->get(QNetworkRequest(url));
connect(m_reply, &QNetworkReply::finished, this, &IconLoader::finished);
}
void IconLoader::finished()
{
// Ignore error and always emit iconLoaded, even when icon is null
const QByteArray data = m_reply->readAll();
emit iconLoaded(QIcon(QPixmap::fromImage(QImage::fromData(data))));
m_reply->deleteLater();
}

View File

@ -1,47 +0,0 @@
/* ============================================================
* QupZilla - QtWebEngine based browser
* Copyright (C) 2015-2016 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef ICONLOADER_H
#define ICONLOADER_H
#include <QObject>
#include "qzcommon.h"
class QIcon;
class QNetworkReply;
class FollowRedirectReply;
class QUPZILLA_EXPORT IconLoader : public QObject
{
Q_OBJECT
public:
explicit IconLoader(const QUrl &url, QObject* parent = 0);
signals:
void iconLoaded(const QIcon &icon);
private slots:
void finished();
private:
QNetworkReply* m_reply;
};
#endif // ICONLOADER_H

View File

@ -34,7 +34,6 @@
#include "webinspector.h"
#include "scripts.h"
#include "webhittestresult.h"
#include "iconloader.h"
#include <iostream>
@ -50,7 +49,6 @@ bool WebView::s_forceContextMenuOnMouseRelease = false;
WebView::WebView(QWidget* parent)
: QWebEngineView(parent)
, m_siteIconLoader(0)
, m_progress(100)
, m_page(0)
, m_firstLoad(false)
@ -60,7 +58,6 @@ WebView::WebView(QWidget* parent)
connect(this, &QWebEngineView::loadProgress, this, &WebView::slotLoadProgress);
connect(this, &QWebEngineView::loadFinished, this, &WebView::slotLoadFinished);
connect(this, &QWebEngineView::urlChanged, this, &WebView::slotUrlChanged);
connect(this, &QWebEngineView::iconUrlChanged, this, &WebView::slotIconUrlChanged);
m_currentZoomLevel = zoomLevels().indexOf(100);
@ -77,8 +74,8 @@ WebView::~WebView()
QIcon WebView::icon() const
{
if (!m_siteIcon.isNull()) {
return m_siteIcon;
if (!QWebEngineView::icon().isNull()) {
return QWebEngineView::icon();
}
if (url().scheme() == QLatin1String("ftp")) {
@ -398,19 +395,6 @@ void WebView::slotUrlChanged(const QUrl &url)
}
}
void WebView::slotIconUrlChanged(const QUrl &url)
{
m_siteIcon = QIcon();
delete m_siteIconLoader;
m_siteIconLoader = new IconLoader(url, this);
connect(m_siteIconLoader, &IconLoader::iconLoaded, [this, url](const QIcon &icon) {
m_siteIcon = icon;
emit iconChanged();
IconProvider::instance()->saveIcon(this);
});
}
void WebView::openUrlInNewWindow()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {

View File

@ -26,12 +26,12 @@
class WebPage;
class LoadRequest;
class IconLoader;
class WebHitTestResult;
class QUPZILLA_EXPORT WebView : public QWebEngineView
{
Q_OBJECT
public:
explicit WebView(QWidget* parent = 0);
~WebView();
@ -74,7 +74,6 @@ public:
static void setForceContextMenuOnMouseRelease(bool force);
signals:
void iconChanged();
void viewportResized(QSize);
void showNotification(QWidget*);
void privacyChanged(bool);
@ -114,7 +113,6 @@ protected slots:
void slotLoadProgress(int progress);
void slotLoadFinished(bool ok);
void slotUrlChanged(const QUrl &url);
void slotIconUrlChanged(const QUrl &url);
// Context menu slots
void openUrlInNewWindow();
@ -177,9 +175,6 @@ private:
int m_currentZoomLevel;
QIcon m_siteIcon;
IconLoader* m_siteIconLoader;
int m_progress;
QUrl m_clickedUrl;