• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.1 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 
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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Wed Mar 20 2013 07:16:08 by doxygen 1.8.3.1 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.10.1 API Reference

Skip menu "kdelibs-4.10.1 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