summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/icondownloader.cpp110
-rw-r--r--src/icondownloader.h58
-rw-r--r--src/iconmanager.cpp74
-rw-r--r--src/iconmanager.h6
-rw-r--r--src/sessionmanager.cpp4
-rw-r--r--src/sessionmanager.h2
-rw-r--r--src/webview.h2
8 files changed, 180 insertions, 77 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 63b6d09f..7f82d28d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,6 +13,7 @@ SET( rekonq_KDEINIT_SRCS
downloadmanager.cpp
filterurljob.cpp
findbar.cpp
+ icondownloader.cpp
iconmanager.cpp
mainview.cpp
mainwindow.cpp
diff --git a/src/icondownloader.cpp b/src/icondownloader.cpp
new file mode 100644
index 00000000..441c3ac2
--- /dev/null
+++ b/src/icondownloader.cpp
@@ -0,0 +1,110 @@
+/* ============================================================
+*
+* 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();
+}
diff --git a/src/icondownloader.h b/src/icondownloader.h
new file mode 100644
index 00000000..d2b1efb3
--- /dev/null
+++ b/src/icondownloader.h
@@ -0,0 +1,58 @@
+/* ============================================================
+*
+* 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
diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp
index e9554a02..86fa5393 100644
--- a/src/iconmanager.cpp
+++ b/src/iconmanager.cpp
@@ -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);
diff --git a/src/iconmanager.h b/src/iconmanager.h
index a7d03edc..4f4b9871 100644
--- a/src/iconmanager.h
+++ b/src/iconmanager.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
@@ -57,10 +57,6 @@ public:
void saveDesktopIconForUrl(const KUrl &u);
-private Q_SLOTS:
- void doLastStuffs(KJob *);
- void notifyLastStuffs(KJob *);
-
Q_SIGNALS:
void iconChanged();
diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp
index 1bb96b54..e67012a9 100644
--- a/src/sessionmanager.cpp
+++ b/src/sessionmanager.cpp
@@ -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();
diff --git a/src/sessionmanager.h b/src/sessionmanager.h
index a8560b41..b4748fde 100644
--- a/src/sessionmanager.h
+++ b/src/sessionmanager.h
@@ -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>
*
diff --git a/src/webview.h b/src/webview.h
index 0d94aaf6..6eb5b84d 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -106,7 +106,7 @@ private Q_SLOTS:
void hideAccessKeys();
void loadStarted();
-
+
Q_SIGNALS:
void loadUrl(const KUrl &, const Rekonq::OpenType &);
void zoomChanged(int);