Plasma5Support

favicons.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Marco Martin <notmart@gmail.com>
3 SPDX-FileCopyrightText: 2013 Andrea Scarpino <scarpino@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "favicons.h"
9
10#include <QImage>
11#include <QPixmap>
12
13#include "faviconprovider.h"
14
15FaviconsEngine::FaviconsEngine(QObject *parent)
16 : Plasma5Support::DataEngine(parent)
17{
18}
19
20FaviconsEngine::~FaviconsEngine()
21{
22}
23
24bool FaviconsEngine::updateSourceEvent(const QString &identifier)
25{
26 FaviconProvider *provider = new FaviconProvider(this, identifier);
27
28 connect(provider, &FaviconProvider::finished, this, &FaviconsEngine::finished);
29 connect(provider, &FaviconProvider::error, this, &FaviconsEngine::error);
30
31 if (!provider->image().isNull()) {
32 setData(provider->identifier(), QStringLiteral("Icon"), provider->image());
33 }
34
35 return true;
36}
37
39{
40 setData(identifier, QPixmap());
41 return updateSourceEvent(identifier);
42}
43
44void FaviconsEngine::finished(FaviconProvider *provider)
45{
46 setData(provider->identifier(), QStringLiteral("Icon"), provider->image());
47 provider->deleteLater();
48}
49
50void FaviconsEngine::error(FaviconProvider *provider)
51{
52 setData(provider->identifier(), QImage());
53 provider->deleteLater();
54}
55
56K_PLUGIN_CLASS_WITH_JSON(FaviconsEngine, "plasma-dataengine-favicons.json")
57
58#include "favicons.moc"
This class provides a favicon for a given url.
QString identifier() const
Returns the identifier of the comic request (name + date).
QImage image() const
Returns the requested image.
void finished(FaviconProvider *provider)
This signal is emitted whenever a request has been finished successfully.
void error(FaviconProvider *provider)
This signal is emitted whenever an error has occurred.
This class provides favicons for websites.
Definition favicons.h:21
bool sourceRequestEvent(const QString &identifier) override
When a source that does not currently exist is requested by the consumer, this method is called to gi...
Definition favicons.cpp:38
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
void setData(const QString &source, const QVariant &value)
Sets a value for a data source.
Namespace for everything in libplasma.
Definition datamodel.cpp:15
bool isNull() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.