Plasma
appletscript.cpp
Go to the documentation of this file.00001 /* 00002 * Copyright 2007 by Aaron Seigo <aseigo@kde.org> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "scripting/appletscript.h" 00021 00022 #include "applet.h" 00023 #include "package.h" 00024 00025 namespace Plasma 00026 { 00027 00028 class AppletScriptPrivate 00029 { 00030 public: 00031 Applet *applet; 00032 }; 00033 00034 AppletScript::AppletScript(QObject *parent) 00035 : ScriptEngine(parent), 00036 d(new AppletScriptPrivate) 00037 { 00038 d->applet = 0; 00039 } 00040 00041 AppletScript::~AppletScript() 00042 { 00043 delete d; 00044 } 00045 00046 void AppletScript::setApplet(Plasma::Applet *applet) 00047 { 00048 d->applet = applet; 00049 } 00050 00051 Applet *AppletScript::applet() const 00052 { 00053 Q_ASSERT(d->applet); 00054 return d->applet; 00055 } 00056 00057 void AppletScript::paintInterface(QPainter *painter, 00058 const QStyleOptionGraphicsItem *option, 00059 const QRect &contentsRect) 00060 { 00061 Q_UNUSED(painter); 00062 Q_UNUSED(option); 00063 Q_UNUSED(contentsRect); 00064 } 00065 00066 QSizeF AppletScript::size() const 00067 { 00068 if (applet()) { 00069 return applet()->size(); 00070 } 00071 00072 return QSizeF(); 00073 } 00074 00075 void AppletScript::constraintsEvent(Plasma::Constraints constraints) 00076 { 00077 Q_UNUSED(constraints); 00078 } 00079 00080 QList<QAction*> AppletScript::contextualActions() 00081 { 00082 return QList<QAction*>(); 00083 } 00084 00085 QPainterPath AppletScript::shape() const 00086 { 00087 if (applet()) { 00088 QPainterPath path; 00089 path.addRect(applet()->boundingRect()); 00090 return path; 00091 } 00092 00093 return QPainterPath(); 00094 } 00095 00096 void AppletScript::setHasConfigurationInterface(bool hasInterface) 00097 { 00098 if (applet()) { 00099 applet()->setHasConfigurationInterface(hasInterface); 00100 } 00101 } 00102 00103 void AppletScript::setConfigurationRequired(bool req, const QString &reason) 00104 { 00105 if (applet()) { 00106 applet()->setConfigurationRequired(req, reason); 00107 } 00108 } 00109 00110 void AppletScript::setFailedToLaunch(bool failed, const QString &reason) 00111 { 00112 if (applet()) { 00113 applet()->setFailedToLaunch(failed, reason); 00114 } 00115 } 00116 00117 void AppletScript::configNeedsSaving() const 00118 { 00119 if (applet()) { 00120 emit applet()->configNeedsSaving(); 00121 } 00122 } 00123 00124 void AppletScript::showConfigurationInterface() 00125 { 00126 } 00127 00128 void AppletScript::configChanged() 00129 { 00130 } 00131 00132 DataEngine *AppletScript::dataEngine(const QString &engine) const 00133 { 00134 Q_ASSERT(d->applet); 00135 return d->applet->dataEngine(engine); 00136 } 00137 00138 QString AppletScript::mainScript() const 00139 { 00140 Q_ASSERT(d->applet); 00141 return d->applet->package()->filePath("mainscript"); 00142 } 00143 00144 const Package *AppletScript::package() const 00145 { 00146 Q_ASSERT(d->applet); 00147 return d->applet->package(); 00148 } 00149 00150 } // Plasma namespace 00151 00152 #include "appletscript.moc"