2013-09-04 11:48:06 +02:00
|
|
|
/*
|
2020-08-13 21:08:54 +02:00
|
|
|
SPDX-FileCopyrightText: 2011 Aaron Seigo <aseigo@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
2013-09-04 11:48:06 +02:00
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QTime>
|
|
|
|
|
2020-07-08 07:44:43 +02:00
|
|
|
#include <KLocalizedString>
|
2013-09-04 14:44:53 +02:00
|
|
|
|
2013-09-04 11:48:06 +02:00
|
|
|
#include "simpleEngine.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
This DataEngine provides a static set of data that is created on
|
|
|
|
engine creation. This is a common pattern for DataEngines that relay
|
|
|
|
information such as hardware events and shows the most basic form of
|
|
|
|
a DataEngine
|
|
|
|
*/
|
|
|
|
|
|
|
|
SimpleEngine::SimpleEngine(QObject *parent, const QVariantList &args)
|
|
|
|
: Plasma::DataEngine(parent, args)
|
|
|
|
{
|
|
|
|
// we've passed the constructor's args to our parent class
|
2013-09-04 14:44:53 +02:00
|
|
|
// we're done for now! Call init()
|
|
|
|
init();
|
2013-09-04 11:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleEngine::init()
|
|
|
|
{
|
|
|
|
|
|
|
|
// So now we will set up some sources.
|
|
|
|
// Each DataEngine will, generally, be loaded once. Each DataEngine
|
|
|
|
// can provide multiple sets of data keyed by a string, called "Sources".
|
|
|
|
// In this simplest of cases, we just create some sources arbitrarily.
|
|
|
|
|
|
|
|
// This is the simplest form, with source name and one bit of data.
|
|
|
|
// Note how the source name is not translated! They can be marked with
|
|
|
|
// I18N_NOOP, however, if they should be translatable in a visualization.
|
2018-01-26 15:48:27 +01:00
|
|
|
setData(QStringLiteral("Simple Source"), i18n("Very simple data"));
|
2013-09-04 11:48:06 +02:00
|
|
|
|
|
|
|
// a source can have multiple entries, differentiated by key names,
|
|
|
|
// which are also not translated:
|
2018-01-26 15:48:27 +01:00
|
|
|
setData(QStringLiteral("Multiple Source"), QStringLiteral("First"), i18n("First"));
|
|
|
|
setData(QStringLiteral("Multiple Source"), QStringLiteral("Second"), i18n("Second"));
|
2013-09-04 11:48:06 +02:00
|
|
|
|
|
|
|
// We can also set the data up first and apply it all at once
|
|
|
|
// Note how data types other than strings can be used as well; anything
|
|
|
|
// that works with QVariant, in fact.
|
|
|
|
Plasma::DataEngine::Data data;
|
2018-01-26 15:48:27 +01:00
|
|
|
data.insert(QStringLiteral("Cow"), QStringLiteral("mooo"));
|
|
|
|
data.insert(QStringLiteral("Black"), QColor(0, 0, 0));
|
|
|
|
data.insert(QStringLiteral("Time"), QTime::currentTime());
|
|
|
|
setData(QStringLiteral("Another Source"), data);
|
2013-09-04 11:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// export the plugin; use the plugin name and the class name
|
2013-09-04 14:44:53 +02:00
|
|
|
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(org.kde.examples.simpleEngine, SimpleEngine, "plasma-dataengine-example-simpleEngine.json")
|
2013-09-04 11:48:06 +02:00
|
|
|
|
|
|
|
// include the moc file so the build system makes it for us
|
|
|
|
#include "simpleEngine.moc"
|
|
|
|
|