-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
declarativeappletscript.cpp
128 lines (101 loc) · 3.92 KB
/
declarativeappletscript.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
SPDX-FileCopyrightText: 2009 Alan Alpert <alan.alpert@nokia.com>
SPDX-FileCopyrightText: 2010 Ménard Alexis <menard@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <QFile>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlExpression>
#include <QQmlProperty>
#include <QTimer>
#include <QWidget>
#include <KConfigGroup>
#include <KLocalizedString>
#include <QDebug>
#include <Plasma/Applet>
#include <Plasma/Corona>
#include <Plasma/Package>
#include <Plasma/PluginLoader>
#include <Plasma/Service>
#include "plasmoid/declarativeappletscript.h"
#include "plasmoid/appletinterface.h"
#include "plasmoid/containmentinterface.h"
#include "plasmoid/wallpaperinterface.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <kdeclarative/configpropertymap.h>
#else
#include <KConfigPropertyMap>
#endif
#include <kdeclarative/qmlobject.h>
DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariantList &args)
: Plasma::AppletScript(parent)
, m_interface(nullptr)
, m_args(args)
{
const char *uri = "org.kde.plasma.plasmoid";
// qmlRegisterType<AppletInterface>();
// FIXME: use this if/when will be possible to have properties of attached items subclasses on the left hand of expressions
/*qmlRegisterUncreatableType<AppletLoader>("org.kde.plasma.plasmoid", 2, 0, "Plasmoid",
QLatin1String("Do not create objects of type Plasmoid"));*/
qmlRegisterUncreatableType<AppletInterface>(uri, 2, 0, "Plasmoid", QStringLiteral("Do not create objects of type Plasmoid"));
qmlRegisterUncreatableType<ContainmentInterface>(uri,
2,
0,
"Containment",
QStringLiteral("Do not create objects of type Containment"));
qmlRegisterUncreatableType<WallpaperInterface>(uri, 2, 0, "Wallpaper", QStringLiteral("Do not create objects of type Wallpaper"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qmlRegisterAnonymousType<KDeclarative::ConfigPropertyMap>(uri, 1);
#else
qmlRegisterAnonymousType<KConfigPropertyMap>(uri, 1);
#endif
}
DeclarativeAppletScript::~DeclarativeAppletScript()
{
}
bool DeclarativeAppletScript::init()
{
// make possible to import extensions from the package
// FIXME: probably to be removed, would make possible to use native code from within the package :/
// m_interface->qmlObject()->engine()->addImportPath(package()->path()+"/contents/imports");
Plasma::Applet *a = applet();
Plasma::Containment *pc = qobject_cast<Plasma::Containment *>(a);
if (pc && pc->isContainment()) {
m_interface = new ContainmentInterface(this, m_args);
// fail? so it's a normal Applet
} else {
m_interface = new AppletInterface(this, m_args);
}
m_interface->setParent(this);
return true;
}
QString DeclarativeAppletScript::filePath(const QString &type, const QString &file) const
{
return applet()->kPackage().filePath(type.toLocal8Bit().constData(), file);
}
void DeclarativeAppletScript::constraintsEvent(Plasma::Types::Constraints constraints)
{
if (constraints & Plasma::Types::FormFactorConstraint) {
Q_EMIT formFactorChanged();
}
if (constraints & Plasma::Types::LocationConstraint) {
Q_EMIT locationChanged();
}
if (constraints & Plasma::Types::ContextConstraint) {
Q_EMIT contextChanged();
}
}
void DeclarativeAppletScript::executeAction(const QString &name)
{
m_interface->executeAction(name);
}
QList<QAction *> DeclarativeAppletScript::contextualActions()
{
if (!m_interface) {
return QList<QAction *>();
}
return m_interface->contextualActions();
}
K_PLUGIN_CLASS_WITH_JSON(DeclarativeAppletScript, "plasma-scriptengine-applet-declarative.json")
#include "declarativeappletscript.moc"