• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

Plasma

  • plasma
  • scripting
appletscript.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2007 by Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "scripting/appletscript.h"
21
22#include "kconfig.h"
23#include "kconfigdialog.h"
24
25#include "animations/animationscriptengine_p.h"
26#include "animator.h"
27#include "applet.h"
28#include "package.h"
29#include "private/applet_p.h"
30
31namespace Plasma
32{
33
34class AppletScriptPrivate
35{
36public:
37 Applet *applet;
38};
39
40AppletScript::AppletScript(QObject *parent)
41 : ScriptEngine(parent),
42 d(new AppletScriptPrivate)
43{
44 d->applet = 0;
45}
46
47AppletScript::~AppletScript()
48{
49 delete d;
50}
51
52void AppletScript::setApplet(Plasma::Applet *applet)
53{
54 d->applet = applet;
55}
56
57Applet *AppletScript::applet() const
58{
59 Q_ASSERT(d->applet);
60 return d->applet;
61}
62
63void AppletScript::paintInterface(QPainter *painter,
64 const QStyleOptionGraphicsItem *option,
65 const QRect &contentsRect)
66{
67 Q_UNUSED(painter);
68 Q_UNUSED(option);
69 Q_UNUSED(contentsRect);
70}
71
72QSizeF AppletScript::size() const
73{
74 if (applet()) {
75 return applet()->size();
76 }
77
78 return QSizeF();
79}
80
81void AppletScript::constraintsEvent(Plasma::Constraints constraints)
82{
83 Q_UNUSED(constraints);
84}
85
86QList<QAction*> AppletScript::contextualActions()
87{
88 return QList<QAction*>();
89}
90
91QPainterPath AppletScript::shape() const
92{
93 if (applet()) {
94 QPainterPath path;
95 path.addRect(applet()->boundingRect());
96 return path;
97 }
98
99 return QPainterPath();
100}
101
102void AppletScript::setHasConfigurationInterface(bool hasInterface)
103{
104 if (applet()) {
105 applet()->setHasConfigurationInterface(hasInterface);
106 }
107}
108
109void AppletScript::setConfigurationRequired(bool req, const QString &reason)
110{
111 if (applet()) {
112 applet()->setConfigurationRequired(req, reason);
113 }
114}
115
116void AppletScript::setFailedToLaunch(bool failed, const QString &reason)
117{
118 if (applet()) {
119 applet()->setFailedToLaunch(failed, reason);
120 }
121}
122
123void AppletScript::configNeedsSaving() const
124{
125 if (applet()) {
126 emit applet()->configNeedsSaving();
127 }
128}
129
130void AppletScript::showConfigurationInterface()
131{
132 if (applet()) {
133 KConfigDialog *dialog = applet()->d->generateGenericConfigDialog();
134 applet()->d->addStandardConfigurationPages(dialog);
135 dialog->show();
136 }
137}
138
139KConfigDialog *AppletScript::standardConfigurationDialog()
140{
141 if (applet()) {
142 return applet()->d->generateGenericConfigDialog();
143 }
144
145 return 0;
146}
147
148void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog)
149{
150 if (applet()) {
151 applet()->d->addStandardConfigurationPages(dialog);
152 }
153}
154
155void AppletScript::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
156{
157 if (applet()) {
158 applet()->showMessage(icon, message, buttons);
159 }
160}
161
162void AppletScript::registerAsDragHandle(QGraphicsItem *item)
163{
164 if (applet()) {
165 applet()->registerAsDragHandle(item);
166 }
167}
168
169void AppletScript::unregisterAsDragHandle(QGraphicsItem *item)
170{
171 if (applet()) {
172 applet()->unregisterAsDragHandle(item);
173 }
174}
175
176bool AppletScript::isRegisteredAsDragHandle(QGraphicsItem *item)
177{
178 if (applet()) {
179 return applet()->isRegisteredAsDragHandle(item);
180 }
181 return false;
182}
183
184Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *parent)
185{
186 if (applet()) {
187 const QString scopedName = applet()->pluginName() + ":" + name;
188 if (!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
189 KConfig conf(applet()->package()->path() + "/metadata.desktop", KConfig::SimpleConfig);
190 KConfigGroup animConf(&conf, "Animations");
191 QString file;
192 foreach (const QString &possibleFile, animConf.keyList()) {
193 const QStringList anims = animConf.readEntry(possibleFile, QStringList());
194 if (anims.contains(name)) {
195 file = possibleFile;
196 break;
197 }
198 }
199
200 if (file.isEmpty()) {
201 return 0;
202 }
203
204 const QString path = applet()->package()->filePath("animations", file);
205 if (path.isEmpty()) {
206 kDebug() << "file path was empty for" << file;
207 return 0;
208 }
209
210 if (!AnimationScriptEngine::loadScript(path, applet()->pluginName() + ':') ||
211 !AnimationScriptEngine::isAnimationRegistered(scopedName)) {
212 kDebug() << "script engine loading failed for" << path;
213 return 0;
214 }
215 }
216
217 Animation *anim = Animator::create(scopedName, parent ? parent : this);
218 return anim;
219 }
220
221 return 0;
222}
223
224void AppletScript::configChanged()
225{
226}
227
228DataEngine *AppletScript::dataEngine(const QString &engine) const
229{
230 Q_ASSERT(d->applet);
231 return d->applet->dataEngine(engine);
232}
233
234QString AppletScript::mainScript() const
235{
236 Q_ASSERT(d->applet);
237 return d->applet->package()->filePath("mainscript");
238}
239
240const Package *AppletScript::package() const
241{
242 Q_ASSERT(d->applet);
243 return d->applet->package();
244}
245
246KPluginInfo AppletScript::description() const
247{
248 Q_ASSERT(d->applet);
249 return d->applet->d->appletDescription;
250}
251
252Extender *AppletScript::extender() const
253{
254 Q_ASSERT(d->applet);
255 return d->applet->extender();
256}
257
258bool AppletScript::drawWallpaper() const
259{
260 Q_ASSERT(d->applet);
261 Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
262 if (cont) {
263 return cont->drawWallpaper();
264 } else {
265 return false;
266 }
267}
268
269void AppletScript::setDrawWallpaper(bool drawWallpaper)
270{
271 Q_ASSERT(d->applet);
272 Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
273 if (cont) {
274 cont->setDrawWallpaper(drawWallpaper);
275 }
276}
277
278Containment::Type AppletScript::containmentType() const
279{
280 Q_ASSERT(d->applet);
281 Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
282 if (cont) {
283 return cont->containmentType();
284 } else {
285 return Containment::NoContainmentType;
286 }
287}
288
289void AppletScript::setContainmentType(Containment::Type type)
290{
291 Q_ASSERT(d->applet);
292 Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
293 if (cont) {
294 cont->setContainmentType(type);
295 }
296}
297
298} // Plasma namespace
299
300#include "appletscript.moc"
animator.h
applet.h
appletscript.h
Plasma::Animation
Abstract representation of a single animation.
Definition: animation.h:47
Plasma::Animator::create
static Plasma::Animation * create(Animator::Animation type, QObject *parent=0)
Factory to build new animation objects.
Definition: animator.cpp:61
Plasma::AppletScript::drawWallpaper
bool drawWallpaper() const
Definition: appletscript.cpp:258
Plasma::AppletScript::applet
Plasma::Applet * applet() const
Returns the Plasma::Applet associated with this script component.
Definition: appletscript.cpp:57
Plasma::AppletScript::package
const Package * package() const
Definition: appletscript.cpp:240
Plasma::Applet
The base Applet class.
Definition: applet.h:78
Plasma::Applet::setHasConfigurationInterface
void setHasConfigurationInterface(bool hasInterface)
Sets whether or not this applet provides a user interface for configuring the applet.
Definition: applet.cpp:1724
Plasma::Applet::showMessage
void showMessage(const QIcon &icon, const QString &message, const Plasma::MessageButtons buttons)
Shows a message as an overlay of the applet: the message has an icon, text and (optional) buttons.
Definition: applet.cpp:1062
Plasma::Applet::setConfigurationRequired
void setConfigurationRequired(bool needsConfiguring, const QString &reason=QString())
When the applet needs to be configured before being usable, this method can be called to show a stand...
Definition: applet.cpp:1010
Plasma::Applet::configNeedsSaving
void configNeedsSaving()
Emitted when an applet has changed values in its configuration and wishes for them to be saved at the...
Plasma::Applet::unregisterAsDragHandle
void unregisterAsDragHandle(QGraphicsItem *item)
Unregister a widget registered with registerAsDragHandle.
Definition: applet.cpp:1657
Plasma::Applet::pluginName
QString pluginName
Definition: applet.h:82
Plasma::Applet::package
const Package * package() const
Accessor for the associated Package object if any.
Definition: applet.cpp:691
Plasma::Applet::isRegisteredAsDragHandle
bool isRegisteredAsDragHandle(QGraphicsItem *item)
Definition: applet.cpp:1670
Plasma::Applet::registerAsDragHandle
void registerAsDragHandle(QGraphicsItem *item)
Register the widgets that manage mouse clicks but you still want to be able to drag the applet around...
Definition: applet.cpp:1647
Plasma::Applet::setFailedToLaunch
void setFailedToLaunch(bool failed, const QString &reason=QString())
Call this method when the applet fails to launch properly.
Definition: applet.cpp:366
Plasma::Containment
The base class for plugins that provide backgrounds and applet grouping containers.
Definition: containment.h:73
Plasma::Containment::setContainmentType
void setContainmentType(Containment::Type type)
Sets the type of this containment.
Definition: containment.cpp:506
Plasma::Containment::Type
Type
Definition: containment.h:99
Plasma::Containment::NoContainmentType
@ NoContainmentType
Definition: containment.h:100
Plasma::Containment::setDrawWallpaper
void setDrawWallpaper(bool drawWallpaper)
Sets whether wallpaper is painted or not.
Definition: containment.cpp:1796
Plasma::Containment::drawWallpaper
bool drawWallpaper()
Return whether wallpaper is painted or not.
Definition: containment.cpp:1810
Plasma::Containment::containmentType
Type containmentType() const
Returns the type of containment.
Definition: containment.cpp:501
Plasma::DataEngine
Data provider for plasmoids (Plasma plugins)
Definition: dataengine.h:59
Plasma::Extender
Extends applets to allow detachable parts.
Definition: extender.h:66
Plasma::Package
object representing an installed Plasmagik package
Definition: package.h:43
Plasma::Package::filePath
QString filePath(const char *fileType, const QString &filename) const
Get the path to a given file.
Definition: package.cpp:213
Plasma::ScriptEngine
The base class for scripting interfaces to be used in loading plasmoids of a given language.
Definition: scriptengine.h:66
QObject
QStyleOptionGraphicsItem
Plasma::AnimationScriptEngine::loadScript
bool loadScript(const QString &path, const QString &prefix)
Definition: animationscriptengine.cpp:187
Plasma::AnimationScriptEngine::isAnimationRegistered
bool isAnimationRegistered(const QString &anim)
Definition: animationscriptengine.cpp:60
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
Plasma::type
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:63
package.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal