File: simpleEngine.cpp

package info (click to toggle)
plasma-framework 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,088 kB
  • sloc: cpp: 29,562; javascript: 637; sh: 517; python: 145; xml: 110; php: 27; makefile: 7
file content (62 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
    SPDX-FileCopyrightText: 2011 Aaron Seigo <aseigo@kde.org>

    SPDX-License-Identifier: BSD-2-Clause
*/

#include <QColor>
#include <QTime>

#include <KLocalizedString>

#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
    // we're done for now! Call init()
    init();
}

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.
    setData(QStringLiteral("Simple Source"), i18n("Very simple data"));

    // a source can have multiple entries, differentiated by key names,
    // which are also not translated:
    setData(QStringLiteral("Multiple Source"), QStringLiteral("First"), i18n("First"));
    setData(QStringLiteral("Multiple Source"), QStringLiteral("Second"), i18n("Second"));

    // 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;
    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);
}

// export the plugin; use the plugin name and the class name
K_PLUGIN_CLASS_WITH_JSON(SimpleEngine, "plasma-dataengine-example-simpleEngine.json")

// include the moc file so the build system makes it for us
#include "simpleEngine.moc"

#include "moc_simpleEngine.cpp"