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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • 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 
31 namespace Plasma
32 {
33 
34 class AppletScriptPrivate
35 {
36 public:
37  Applet *applet;
38 };
39 
40 AppletScript::AppletScript(QObject *parent)
41  : ScriptEngine(parent),
42  d(new AppletScriptPrivate)
43 {
44  d->applet = 0;
45 }
46 
47 AppletScript::~AppletScript()
48 {
49  delete d;
50 }
51 
52 void AppletScript::setApplet(Plasma::Applet *applet)
53 {
54  d->applet = applet;
55 }
56 
57 Applet *AppletScript::applet() const
58 {
59  Q_ASSERT(d->applet);
60  return d->applet;
61 }
62 
63 void 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 
72 QSizeF AppletScript::size() const
73 {
74  if (applet()) {
75  return applet()->size();
76  }
77 
78  return QSizeF();
79 }
80 
81 void AppletScript::constraintsEvent(Plasma::Constraints constraints)
82 {
83  Q_UNUSED(constraints);
84 }
85 
86 QList<QAction*> AppletScript::contextualActions()
87 {
88  return QList<QAction*>();
89 }
90 
91 QPainterPath 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 
102 void AppletScript::setHasConfigurationInterface(bool hasInterface)
103 {
104  if (applet()) {
105  applet()->setHasConfigurationInterface(hasInterface);
106  }
107 }
108 
109 void AppletScript::setConfigurationRequired(bool req, const QString &reason)
110 {
111  if (applet()) {
112  applet()->setConfigurationRequired(req, reason);
113  }
114 }
115 
116 void AppletScript::setFailedToLaunch(bool failed, const QString &reason)
117 {
118  if (applet()) {
119  applet()->setFailedToLaunch(failed, reason);
120  }
121 }
122 
123 void AppletScript::configNeedsSaving() const
124 {
125  if (applet()) {
126  emit applet()->configNeedsSaving();
127  }
128 }
129 
130 void AppletScript::showConfigurationInterface()
131 {
132  if (applet()) {
133  KConfigDialog *dialog = applet()->d->generateGenericConfigDialog();
134  applet()->d->addStandardConfigurationPages(dialog);
135  dialog->show();
136  }
137 }
138 
139 KConfigDialog *AppletScript::standardConfigurationDialog()
140 {
141  if (applet()) {
142  return applet()->d->generateGenericConfigDialog();
143  }
144 
145  return 0;
146 }
147 
148 void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog)
149 {
150  if (applet()) {
151  applet()->d->addStandardConfigurationPages(dialog);
152  }
153 }
154 
155 void AppletScript::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
156 {
157  if (applet()) {
158  applet()->showMessage(icon, message, buttons);
159  }
160 }
161 
162 void AppletScript::registerAsDragHandle(QGraphicsItem *item)
163 {
164  if (applet()) {
165  applet()->registerAsDragHandle(item);
166  }
167 }
168 
169 void AppletScript::unregisterAsDragHandle(QGraphicsItem *item)
170 {
171  if (applet()) {
172  applet()->unregisterAsDragHandle(item);
173  }
174 }
175 
176 bool AppletScript::isRegisteredAsDragHandle(QGraphicsItem *item)
177 {
178  if (applet()) {
179  return applet()->isRegisteredAsDragHandle(item);
180  }
181  return false;
182 }
183 
184 Animation *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 
224 void AppletScript::configChanged()
225 {
226 }
227 
228 DataEngine *AppletScript::dataEngine(const QString &engine) const
229 {
230  Q_ASSERT(d->applet);
231  return d->applet->dataEngine(engine);
232 }
233 
234 QString AppletScript::mainScript() const
235 {
236  Q_ASSERT(d->applet);
237  return d->applet->package()->filePath("mainscript");
238 }
239 
240 const Package *AppletScript::package() const
241 {
242  Q_ASSERT(d->applet);
243  return d->applet->package();
244 }
245 
246 KPluginInfo AppletScript::description() const
247 {
248  Q_ASSERT(d->applet);
249  return d->applet->d->appletDescription;
250 }
251 
252 Extender *AppletScript::extender() const
253 {
254  Q_ASSERT(d->applet);
255  return d->applet->extender();
256 }
257 
258 bool 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 
269 void 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 
278 Containment::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 
289 void 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"
Plasma::AppletScript::setContainmentType
void setContainmentType(Containment::Type type)
Definition: appletscript.cpp:289
Plasma::Applet::package
const Package * package() const
Accessor for the associated Package object if any.
Definition: applet.cpp:691
Plasma::Containment::NoContainmentType
Definition: containment.h:100
Plasma::AppletScript::paintInterface
virtual void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
Called when the script should paint the applet.
Definition: appletscript.cpp:63
Plasma::AppletScript::mainScript
QString mainScript() const
Definition: appletscript.cpp:234
Plasma::Extender
Extends applets to allow detachable parts.
Definition: extender.h:65
Plasma::AppletScript::setDrawWallpaper
void setDrawWallpaper(bool drawWallpaper)
set if the containment draws its own wallpaper: it has no effect if the applet is not a containment ...
Definition: appletscript.cpp:269
Plasma::AppletScript::showMessage
void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
Definition: appletscript.cpp:155
Plasma::Containment::setDrawWallpaper
void setDrawWallpaper(bool drawWallpaper)
Sets whether wallpaper is painted or not.
Definition: containment.cpp:1796
Plasma::Containment::containmentType
Type containmentType() const
Returns the type of containment.
Definition: containment.cpp:501
Plasma::AnimationScriptEngine::loadScript
bool loadScript(const QString &path, const QString &prefix)
Definition: animationscriptengine.cpp:187
Plasma::Animation
Abstract representation of a single animation.
Definition: animation.h:46
QObject
Plasma::AppletScript::showConfigurationInterface
virtual void showConfigurationInterface()
Show a configuration dialog.
Definition: appletscript.cpp:130
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
The base Applet class.
Definition: applet.h:77
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::AppletScript::registerAsDragHandle
void registerAsDragHandle(QGraphicsItem *item)
Definition: appletscript.cpp:162
Plasma::AppletScript::setFailedToLaunch
void setFailedToLaunch(bool failed, const QString &reason=QString())
Definition: appletscript.cpp:116
Plasma::Applet::unregisterAsDragHandle
void unregisterAsDragHandle(QGraphicsItem *item)
Unregister a widget registered with registerAsDragHandle.
Definition: applet.cpp:1657
Plasma::AppletScript::unregisterAsDragHandle
void unregisterAsDragHandle(QGraphicsItem *item)
Definition: appletscript.cpp:169
Plasma::ScriptEngine
The base class for scripting interfaces to be used in loading plasmoids of a given language...
Definition: scriptengine.h:65
Plasma::Applet::pluginName
QString pluginName
Definition: applet.h:82
Plasma::DataEngine
Data provider for plasmoids (Plasma plugins)
Definition: dataengine.h:58
Plasma::AppletScript::dataEngine
Q_INVOKABLE DataEngine * dataEngine(const QString &engine) const
Definition: appletscript.cpp:228
applet.h
Plasma::AppletScript::description
KPluginInfo description() const
Definition: appletscript.cpp:246
Plasma::AppletScript::~AppletScript
~AppletScript()
Definition: appletscript.cpp:47
Plasma::AppletScript::containmentType
Containment::Type containmentType() const
Definition: appletscript.cpp:278
Plasma::AppletScript::AppletScript
AppletScript(QObject *parent=0)
Default constructor for an AppletScript.
Definition: appletscript.cpp:40
Plasma::Package
object representing an installed Plasmagik package
Definition: package.h:42
Plasma::AppletScript::loadAnimationFromPackage
Animation * loadAnimationFromPackage(const QString &name, QObject *parent)
Loads an animation from the applet package.
Definition: appletscript.cpp:184
Plasma::AppletScript::applet
Plasma::Applet * applet() const
Returns the Plasma::Applet associated with this script component.
Definition: appletscript.cpp:57
Plasma::AppletScript::setConfigurationRequired
void setConfigurationRequired(bool req, const QString &reason=QString())
Definition: appletscript.cpp:109
Plasma::AppletScript::configNeedsSaving
void configNeedsSaving() const
Definition: appletscript.cpp:123
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::setFailedToLaunch
void setFailedToLaunch(bool failed, const QString &reason=QString())
Call this method when the applet fails to launch properly.
Definition: applet.cpp:366
Plasma::Applet::isRegisteredAsDragHandle
bool isRegisteredAsDragHandle(QGraphicsItem *item)
Definition: applet.cpp:1670
Plasma::AppletScript::extender
Extender * extender() const
Definition: appletscript.cpp:252
Plasma::Containment::setContainmentType
void setContainmentType(Containment::Type type)
Sets the type of this containment.
Definition: containment.cpp:506
Plasma::AppletScript::constraintsEvent
virtual void constraintsEvent(Plasma::Constraints constraints)
Called when any of the geometry constraints have been updated.
Definition: appletscript.cpp:81
Plasma::type
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:63
Plasma::AppletScript::setHasConfigurationInterface
void setHasConfigurationInterface(bool hasInterface)
Sets whether or not this script has a configuration interface or not.
Definition: appletscript.cpp:102
package.h
Plasma::Containment::drawWallpaper
bool drawWallpaper()
Return whether wallpaper is painted or not.
Definition: containment.cpp:1810
Plasma::AppletScript::package
const Package * package() const
Definition: appletscript.cpp:240
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::isRegisteredAsDragHandle
bool isRegisteredAsDragHandle(QGraphicsItem *item)
Definition: appletscript.cpp:176
Plasma::AppletScript::shape
virtual QPainterPath shape() const
Returns the shape of the widget, defaults to the bounding rect.
Definition: appletscript.cpp:91
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::AppletScript::addStandardConfigurationPages
void addStandardConfigurationPages(KConfigDialog *dialog)
This method should be called after a scripting applet has added its own pages to a configuration dial...
Definition: appletscript.cpp:148
Plasma::AppletScript::drawWallpaper
bool drawWallpaper() const
Definition: appletscript.cpp:258
Plasma::AnimationScriptEngine::isAnimationRegistered
bool isAnimationRegistered(const QString &anim)
Definition: animationscriptengine.cpp:60
Plasma::Containment
The base class for plugins that provide backgrounds and applet grouping containers.
Definition: containment.h:72
Plasma::Applet::configNeedsSaving
void configNeedsSaving()
Emitted when an applet has changed values in its configuration and wishes for them to be saved at the...
appletscript.h
Plasma::AppletScript::setApplet
void setApplet(Plasma::Applet *applet)
Sets the applet associated with this AppletScript.
Definition: appletscript.cpp:52
animator.h
Plasma::Containment::Type
Type
Definition: containment.h:99
QStyleOptionGraphicsItem
Plasma::AppletScript::configChanged
virtual void configChanged()
Configure was changed.
Definition: appletscript.cpp:224
Plasma::AppletScript::size
Q_INVOKABLE QSizeF size() const
Returns the area within which contents can be painted.
Definition: appletscript.cpp:72
Plasma::Package::filePath
QString filePath(const char *fileType, const QString &filename) const
Get the path to a given file.
Definition: package.cpp:213
Plasma::AppletScript::standardConfigurationDialog
KConfigDialog * standardConfigurationDialog()
Definition: appletscript.cpp:139
Plasma::AppletScript::contextualActions
virtual QList< QAction * > contextualActions()
Returns a list of context-related QAction instances.
Definition: appletscript.cpp:86
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:33 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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