diff --git a/src/lib/lib.pro b/src/lib/lib.pro index 99b1b74a1..91cc6f5b9 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -196,7 +196,6 @@ SOURCES += \ tools/html5permissions/html5permissionsdialog.cpp \ tools/html5permissions/html5permissionsmanager.cpp \ tools/html5permissions/html5permissionsnotification.cpp \ - tools/iconfetcher.cpp \ tools/iconprovider.cpp \ tools/listitemdelegate.cpp \ tools/mactoolbutton.cpp \ @@ -381,7 +380,6 @@ HEADERS += \ tools/html5permissions/html5permissionsdialog.h \ tools/html5permissions/html5permissionsmanager.h \ tools/html5permissions/html5permissionsnotification.h \ - tools/iconfetcher.h \ tools/iconprovider.h \ tools/listitemdelegate.h \ tools/mactoolbutton.h \ diff --git a/src/lib/tools/iconfetcher.cpp b/src/lib/tools/iconfetcher.cpp deleted file mode 100644 index c89d90768..000000000 --- a/src/lib/tools/iconfetcher.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* 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 . -* ============================================================ */ -#include "iconfetcher.h" -#include "followredirectreply.h" -#include "qzregexp.h" - -#include - -IconFetcher::IconFetcher(QObject* parent) - : QObject(parent) - , m_manager(0) -{ -} - -void IconFetcher::fetchIcon(const QUrl &url) -{ - if (!m_manager) { - return; - } - - FollowRedirectReply* reply = new FollowRedirectReply(url, m_manager); - connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded())); - - m_url = url; -} - -void IconFetcher::pageDownloaded() -{ - FollowRedirectReply* reply = qobject_cast (sender()); - if (!reply) { - return; - } - - QString html = reply->readAll(); - QUrl replyUrl = reply->url(); - reply->deleteLater(); - - QzRegExp rx("", Qt::CaseInsensitive); - rx.setMinimal(true); - - QString shortcutIconTag; - int pos = 0; - while ((pos = rx.indexIn(html, pos)) != -1) { - QString linkTag = rx.cap(0); - pos += rx.matchedLength(); - - if (linkTag.contains(QLatin1String("rel=\"shortcut icon\""), Qt::CaseInsensitive)) { - shortcutIconTag = linkTag; - break; - } - } - - FollowRedirectReply* newReply; - if (shortcutIconTag.isEmpty()) { -// QUrl faviconUrl = replyUrl.resolved(QUrl("favicon.ico")); -// -// Rather getting favicon.ico from base directory than from subfolders - QUrl faviconUrl = QUrl(replyUrl.toString(QUrl::RemovePath | QUrl::RemoveQuery) + "/favicon.ico"); - newReply = new FollowRedirectReply(faviconUrl, m_manager); - } - else { - QzRegExp rx("href=\"(.*)\"", Qt::CaseInsensitive); - rx.setMinimal(true); - rx.indexIn(shortcutIconTag); - QUrl url = QUrl(rx.cap(1)); - - QUrl iconUrl = QUrl(replyUrl).resolved(url); - newReply = new FollowRedirectReply(iconUrl, m_manager); - } - - connect(newReply, SIGNAL(finished()), this, SLOT(iconDownloaded())); -} - -void IconFetcher::iconDownloaded() -{ - FollowRedirectReply* reply = qobject_cast (sender()); - if (!reply) { - return; - } - - QByteArray response = reply->readAll(); - reply->deleteLater(); - - if (!response.isEmpty()) { - QImage image; - image.loadFromData(response); - if (!image.isNull()) { - emit iconFetched(image); - } - } - - emit finished(); -} diff --git a/src/lib/tools/iconfetcher.h b/src/lib/tools/iconfetcher.h deleted file mode 100644 index 681ea2e13..000000000 --- a/src/lib/tools/iconfetcher.h +++ /dev/null @@ -1,64 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca -* -* 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 . -* ============================================================ */ -#ifndef ICONFETCHER_H -#define ICONFETCHER_H - -#include "qzcommon.h" - -#include -#include -#include -#include - -class QNetworkAccessManager; -class QUrl; - -class FollowRedirectReply; - -class QUPZILLA_EXPORT IconFetcher : public QObject -{ - Q_OBJECT -public: - explicit IconFetcher(QObject* parent = 0); - void setNetworkAccessManager(QNetworkAccessManager* manager) { m_manager = manager; } - void fetchIcon(const QUrl &url); - - void setData(const QVariant &data) { m_data = data; } - QVariant data() { return m_data; } - - QUrl url() { return m_url; } - -signals: - void iconFetched(QImage); - void finished(); - -public slots: - -private slots: - void pageDownloaded(); - void iconDownloaded(); - -private: - QNetworkAccessManager* m_manager; - - QVariant m_data; - QUrl m_url; - -}; - -#endif // ICONFETCHER_H