kde-workspace/plasma/dataengines/favicons/favicons.cpp

63 lines
1.9 KiB
C++
Raw Normal View History

2014-11-13 19:30:51 +02:00
/*
* Copyright (C) 2007 Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "favicons.h"
#include <KMimeType>
#include <KStandardDirs>
#include <KDebug>
2014-11-13 19:30:51 +02:00
FaviconsEngine::FaviconsEngine(QObject* parent, const QVariantList& args)
: Plasma::DataEngine(parent, args)
{
}
bool FaviconsEngine::updateSourceEvent(const QString &identifier)
2014-11-13 19:30:51 +02:00
{
KUrl faviconUrl(identifier);
if (faviconUrl.protocol().isEmpty()) {
faviconUrl = KUrl("http://" + identifier);
}
2014-11-13 19:30:51 +02:00
const QString fileName = KMimeType::favIconForUrl(faviconUrl.url(), true);
if (fileName.isEmpty()) {
kDebug() << "No icon available for " << identifier;
setData(identifier, QImage());
return false;
}
2014-11-13 19:30:51 +02:00
const QString cachePath = KStandardDirs::locateLocal("cache", fileName + ".png");
const QImage image(cachePath, "PNG");
if (image.isNull()) {
kWarning() << "Could not load the image" << cachePath;
setData(identifier, QImage());
return false;
2014-11-13 19:30:51 +02:00
}
setData(identifier, image);
2014-11-13 19:30:51 +02:00
return true;
}
bool FaviconsEngine::sourceRequestEvent(const QString &identifier)
{
return updateSourceEvent(identifier);
}
2015-02-27 09:28:46 +00:00
#include "moc_favicons.cpp"