2
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
3
* Copyright (C) 2008 Marco Martin <notmart@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details
15
* You should have received a copy of the GNU Library General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include "faviconprovider.h"
24
#include <QtGui/QImage>
25
#include <QtCore/QFile>
29
#include <KIO/StoredTransferJob>
32
#include <kstandarddirs.h>
34
class FaviconProvider::Private
37
Private( FaviconProvider *parent )
42
void imageRequestFinished( KJob *job );
49
void FaviconProvider::Private::imageRequestFinished(KJob *job)
56
KIO::StoredTransferJob *storedJob = qobject_cast<KIO::StoredTransferJob*>(job);
57
image = QImage::fromData(storedJob->data());
58
if (!image.isNull()) {
59
image.save(cachePath, "PNG");
65
FaviconProvider::FaviconProvider(QObject *parent, const QString &url)
71
if (faviconUrl.protocol().isEmpty()) {
72
faviconUrl = KUrl("http://" + url);
75
const QString fileName = KMimeType::favIconForUrl(faviconUrl.url());
77
if (!fileName.isEmpty()) {
78
d->cachePath = KStandardDirs::locateLocal("cache", fileName + ".png");
79
d->image.load(d->cachePath, "PNG");
81
d->cachePath = KStandardDirs::locateLocal("cache", "favicons/" + faviconUrl.host() + ".png");
82
faviconUrl.setPath("/favicon.ico");
84
if (faviconUrl.isValid()) {
85
KIO::StoredTransferJob *job = KIO::storedGet(faviconUrl, KIO::NoReload, KIO::HideProgressInfo);
86
//job->setProperty("uid", id);
87
connect(job, SIGNAL(result(KJob*)), this, SLOT(imageRequestFinished(KJob*)));
92
FaviconProvider::~FaviconProvider()
97
QImage FaviconProvider::image() const
102
QString FaviconProvider::identifier() const
107
#include "faviconprovider.moc"