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 QString host
= faviconUrl
.host();
73 faviconUrl
= KUrl("http://" + url
);
76 QString fileName
= KMimeType::favIconForUrl(faviconUrl
.url());
78 if (!fileName
.isEmpty()) {
79 d
->cachePath
= KStandardDirs::locateLocal("cache", fileName
+ ".png");
80 d
->image
.load(d
->cachePath
, "PNG");
82 d
->cachePath
= KStandardDirs::locateLocal("cache", "favicons/" + faviconUrl
.host() + ".png");
83 faviconUrl
.setPath("/favicon.ico");
85 if (faviconUrl
.isValid()) {
86 KIO::StoredTransferJob
*job
= KIO::storedGet(faviconUrl
, KIO::NoReload
, KIO::HideProgressInfo
);
87 //job->setProperty("uid", id);
88 connect(job
, SIGNAL(result(KJob
*)), this, SLOT(imageRequestFinished(KJob
*)));
93 FaviconProvider::~FaviconProvider()
98 QImage
FaviconProvider::image() const
103 QString
FaviconProvider::identifier() const
108 #include "faviconprovider.moc"