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 "kconfigdialog.h" 00023 00024 #include "applet.h" 00025 #include "package.h" 00026 #include "private/applet_p.h" 00027 00028 namespace Plasma 00029 { 00030 00031 class AppletScriptPrivate 00032 { 00033 public: 00034 Applet *applet; 00035 }; 00036 00037 AppletScript::AppletScript(QObject *parent) 00038 : ScriptEngine(parent), 00039 d(new AppletScriptPrivate) 00040 { 00041 d->applet = 0; 00042 } 00043 00044 AppletScript::~AppletScript() 00045 { 00046 delete d; 00047 } 00048 00049 void AppletScript::setApplet(Plasma::Applet *applet) 00050 { 00051 d->applet = applet; 00052 } 00053 00054 Applet *AppletScript::applet() const 00055 { 00056 Q_ASSERT(d->applet); 00057 return d->applet; 00058 } 00059 00060 void AppletScript::paintInterface(QPainter *painter, 00061 const QStyleOptionGraphicsItem *option, 00062 const QRect &contentsRect) 00063 { 00064 Q_UNUSED(painter); 00065 Q_UNUSED(option); 00066 Q_UNUSED(contentsRect); 00067 } 00068 00069 QSizeF AppletScript::size() const 00070 { 00071 if (applet()) { 00072 return applet()->size(); 00073 } 00074 00075 return QSizeF(); 00076 } 00077 00078 void AppletScript::constraintsEvent(Plasma::Constraints constraints) 00079 { 00080 Q_UNUSED(constraints); 00081 } 00082 00083 QList<QAction*> AppletScript::contextualActions() 00084 { 00085 return QList<QAction*>(); 00086 } 00087 00088 QPainterPath AppletScript::shape() const 00089 { 00090 if (applet()) { 00091 QPainterPath path; 00092 path.addRect(applet()->boundingRect()); 00093 return path; 00094 } 00095 00096 return QPainterPath(); 00097 } 00098 00099 void AppletScript::setHasConfigurationInterface(bool hasInterface) 00100 { 00101 if (applet()) { 00102 applet()->setHasConfigurationInterface(hasInterface); 00103 } 00104 } 00105 00106 void AppletScript::setConfigurationRequired(bool req, const QString &reason) 00107 { 00108 if (applet()) { 00109 applet()->setConfigurationRequired(req, reason); 00110 } 00111 } 00112 00113 void AppletScript::setFailedToLaunch(bool failed, const QString &reason) 00114 { 00115 if (applet()) { 00116 applet()->setFailedToLaunch(failed, reason); 00117 } 00118 } 00119 00120 void AppletScript::configNeedsSaving() const 00121 { 00122 if (applet()) { 00123 emit applet()->configNeedsSaving(); 00124 } 00125 } 00126 00127 void AppletScript::showConfigurationInterface() 00128 { 00129 if (applet()) { 00130 applet()->d->generateGenericConfigDialog()->show(); 00131 } 00132 } 00133 00134 KConfigDialog *AppletScript::standardConfigurationDialog() 00135 { 00136 if (applet()) { 00137 return applet()->d->generateGenericConfigDialog(); 00138 } 00139 00140 return 0; 00141 } 00142 00143 void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog) 00144 { 00145 if (applet()) { 00146 applet()->d->addGlobalShortcutsPage(dialog); 00147 } 00148 00149 return; 00150 } 00151 00152 void AppletScript::configChanged() 00153 { 00154 } 00155 00156 DataEngine *AppletScript::dataEngine(const QString &engine) const 00157 { 00158 Q_ASSERT(d->applet); 00159 return d->applet->dataEngine(engine); 00160 } 00161 00162 QString AppletScript::mainScript() const 00163 { 00164 Q_ASSERT(d->applet); 00165 return d->applet->package()->filePath("mainscript"); 00166 } 00167 00168 const Package *AppletScript::package() const 00169 { 00170 Q_ASSERT(d->applet); 00171 return d->applet->package(); 00172 } 00173 00174 Extender *AppletScript::extender() const 00175 { 00176 Q_ASSERT(d->applet); 00177 return d->applet->extender(); 00178 } 00179 00180 } // Plasma namespace 00181 00182 #include "appletscript.moc"