Commit 1efea8ed authored by Andrea Diamantini's avatar Andrea Diamantini
Browse files

Move icon manager download system to QNAM

& Search also for favicon.ico files

This seems to be the unique method to surely workaround this bug
rekonq encounters when tries to load an unextant favicon with KIO (see
BUG:289029
)
parent 167c9c55
......@@ -13,6 +13,7 @@ SET( rekonq_KDEINIT_SRCS
downloadmanager.cpp
filterurljob.cpp
findbar.cpp
icondownloader.cpp
iconmanager.cpp
mainview.cpp
mainwindow.cpp
......
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot 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 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 "icondownloader.h"
#include "icondownloader.moc"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QFile>
#include <QPixmap>
IconDownloader::IconDownloader(const KUrl &srcUrl, const KUrl &destUrl, QObject *parent)
: QObject(parent)
, m_srcUrl(srcUrl)
, m_destUrl(destUrl)
{
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(srcUrl));
}
void IconDownloader::replyFinished(QNetworkReply *reply)
{
if (reply->error())
{
kDebug() << "FAVICON JOB ERROR";
emit iconReady();
this->deleteLater();
return;
}
QString s = m_destUrl.url().remove(QL1S("file://"));
QFile favicon(s);
if (!favicon.open(QIODevice::WriteOnly))
{
kDebug() << "FAVICON FILE NOT OPENED";
emit iconReady();
this->deleteLater();
return;
}
favicon.write(reply->readAll());
favicon.close();
if (favicon.size() == 0)
{
kDebug() << "SIZE ZERO FAVICON";
favicon.remove();
emit iconReady();
this->deleteLater();
return;
}
QPixmap px;
if (!px.load(s))
{
kDebug() << "PIXMAP NOT LOADED";
emit iconReady();
this->deleteLater();
return;
}
if (px.isNull())
{
kDebug() << "PIXMAP IS NULL";
favicon.remove();
emit iconReady();
this->deleteLater();
return;
}
px = px.scaled(16, 16);
if (!px.save(s + QL1S(".png"), "PNG"))
{
kDebug() << "PIXMAP NOT SAVED";
emit iconReady();
this->deleteLater();
return;
}
QFile::remove(s);
emit iconReady();
this->deleteLater();
}
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2012 by Andrea Diamantini <adjam7 at gmail dot 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 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 ICON_DOWNLOADER_H
#define ICON_DOWNLOADER_H
// rekonq includes
#include "rekonq_defines.h"
#include <QObject>
#include <KUrl>
class QNetworkReply;
class IconDownloader : public QObject
{
Q_OBJECT
public:
IconDownloader(const KUrl &srcUrl, const KUrl &destUrl, QObject *parent = 0);
private Q_SLOTS:
void replyFinished(QNetworkReply *);
Q_SIGNALS:
void iconReady();
private:
KUrl m_srcUrl;
KUrl m_destUrl;
};
#endif // ICON_DOWNLOADER_H
......@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
* Copyright (C) 2010-2011 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2010-2012 by Andrea Diamantini <adjam7 at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
......@@ -31,6 +31,7 @@
// Local Includes
#include "application.h"
#include "webicon.h"
#include "icondownloader.h"
// KDE Includes
#include <KIO/Job>
......@@ -124,7 +125,8 @@ void IconManager::provideIcon(QWebFrame *mFrame, const KUrl &url, bool notify)
const QString rootUrlString = url.scheme() + QL1S("://") + url.host();
// find favicon url
KUrl faviconUrl;
KUrl faviconUrl(rootUrlString + QL1S("/favicon.ico"));
QWebElement root = mFrame->documentElement();
QWebElement e = root.findFirst(QL1S("link[rel~=\"icon\"]"));
......@@ -142,18 +144,12 @@ void IconManager::provideIcon(QWebFrame *mFrame, const KUrl &url, bool notify)
: KUrl(rootUrlString + QL1C('/') + relUrlString);
}
if (faviconUrl.isEmpty())
return;
// dest url
KUrl destUrl(_faviconsDir + url.host());
// download icon
KIO::FileCopyJob *job = KIO::file_copy(faviconUrl, destUrl, -1, KIO::HideProgressInfo | KIO::Overwrite);
IconDownloader *id = new IconDownloader(faviconUrl, destUrl, this);
if (notify)
connect(job, SIGNAL(result(KJob*)), this, SLOT(notifyLastStuffs(KJob *)));
else
connect(job, SIGNAL(result(KJob*)), this, SLOT(doLastStuffs(KJob *)));
connect(id, SIGNAL(iconReady()), this, SIGNAL(iconChanged()));
}
......@@ -174,64 +170,6 @@ void IconManager::clearIconCache()
}
void IconManager::doLastStuffs(KJob *j)
{
if (j->error())
{
kDebug() << "FAVICON JOB ERROR";
return;
}
KIO::FileCopyJob *job = static_cast<KIO::FileCopyJob *>(j);
KUrl dest = job->destUrl();
QString s = dest.url().remove(QL1S("file://"));
QFile fav(s);
if (!fav.exists())
{
kDebug() << "FAVICON DOES NOT EXISTS";
fav.remove();
return;
}
if (fav.size() == 0)
{
kDebug() << "SIZE ZERO FAVICON";
fav.remove();
return;
}
QPixmap px;
if (!px.load(s))
{
kDebug() << "PIXMAP NOT LOADED";
return;
}
if (px.isNull())
{
kDebug() << "PIXMAP IS NULL";
fav.remove();
return;
}
px = px.scaled(16, 16);
if (!px.save(s + QL1S(".png"), "PNG"))
{
kDebug() << "PIXMAP NOT SAVED";
return;
}
QFile::remove(s);
}
void IconManager::notifyLastStuffs(KJob *j)
{
doLastStuffs(j);
emit iconChanged();
}
void IconManager::saveDesktopIconForUrl(const KUrl &u)
{
KIcon icon = iconForUrl(u);
......
......@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
* Copyright (C) 2010-2011 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2010-2012 by Andrea Diamantini <adjam7 at gmail dot com>
*
*
* This program is free software; you can redistribute it and/or
......@@ -57,10 +57,6 @@ public:
void saveDesktopIconForUrl(const KUrl &u);
private Q_SLOTS:
void doLastStuffs(KJob *);
void notifyLastStuffs(KJob *);
Q_SIGNALS:
void iconChanged();
......
......@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
* Copyright (C) 2009-2011 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Yoram Bar-Haim <<yoram.b at zend dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
*
......@@ -311,7 +311,7 @@ bool SessionManager::restoreMainWindow(MainWindow* window)
int currentTab = 0;
if (window->objectName() != savedWindowElement.attribute("name", ""))
continue;
continue;
MainView *mv = window->mainView();
......
......@@ -2,7 +2,7 @@
*
* This file is a part of the rekonq project
*
* Copyright (C) 2009-2011 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009-2012 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009 by Yoram Bar-Haim <<yoram.b at zend dot com>
* Copyright (C) 2009-2011 by Lionel Chauvin <megabigbug@yahoo.fr>
*
......
......@@ -106,7 +106,7 @@ private Q_SLOTS:
void hideAccessKeys();
void loadStarted();
Q_SIGNALS:
void loadUrl(const KUrl &, const Rekonq::OpenType &);
void zoomChanged(int);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment