2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scripting/appletscript.h"
|
|
|
|
|
2010-05-13 02:47:24 +02:00
|
|
|
#include "kconfig.h"
|
2009-02-24 03:32:48 +01:00
|
|
|
#include "kconfigdialog.h"
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "applet.h"
|
|
|
|
#include "package.h"
|
2009-01-20 03:11:01 +01:00
|
|
|
#include "private/applet_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class AppletScriptPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Applet *applet;
|
|
|
|
};
|
|
|
|
|
|
|
|
AppletScript::AppletScript(QObject *parent)
|
|
|
|
: ScriptEngine(parent),
|
|
|
|
d(new AppletScriptPrivate)
|
|
|
|
{
|
|
|
|
d->applet = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppletScript::~AppletScript()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::setApplet(Plasma::Applet *applet)
|
|
|
|
{
|
|
|
|
d->applet = applet;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *AppletScript::applet() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
return d->applet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::paintInterface(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
const QRect &contentsRect)
|
|
|
|
{
|
|
|
|
Q_UNUSED(painter);
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(contentsRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::constraintsEvent(Plasma::Constraints constraints)
|
|
|
|
{
|
|
|
|
Q_UNUSED(constraints);
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QAction*> AppletScript::contextualActions()
|
|
|
|
{
|
|
|
|
return QList<QAction*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::setHasConfigurationInterface(bool hasInterface)
|
|
|
|
{
|
|
|
|
if (applet()) {
|
2008-12-29 05:45:05 +01:00
|
|
|
applet()->setHasConfigurationInterface(hasInterface);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 09:22:28 +01:00
|
|
|
void AppletScript::setConfigurationRequired(bool req, const QString &reason)
|
|
|
|
{
|
|
|
|
if (applet()) {
|
|
|
|
applet()->setConfigurationRequired(req, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::setFailedToLaunch(bool failed, const QString &reason)
|
|
|
|
{
|
|
|
|
if (applet()) {
|
|
|
|
applet()->setFailedToLaunch(failed, reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 04:02:22 +01:00
|
|
|
void AppletScript::configNeedsSaving() const
|
|
|
|
{
|
|
|
|
if (applet()) {
|
|
|
|
emit applet()->configNeedsSaving();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void AppletScript::showConfigurationInterface()
|
|
|
|
{
|
2009-01-20 03:11:01 +01:00
|
|
|
if (applet()) {
|
2010-03-01 18:57:37 +01:00
|
|
|
KConfigDialog *dialog = applet()->d->generateGenericConfigDialog();
|
|
|
|
applet()->d->addStandardConfigurationPages(dialog);
|
|
|
|
dialog->show();
|
2009-01-20 03:11:01 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-02-24 03:32:48 +01:00
|
|
|
KConfigDialog *AppletScript::standardConfigurationDialog()
|
|
|
|
{
|
|
|
|
if (applet()) {
|
|
|
|
return applet()->d->generateGenericConfigDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-20 20:19:44 +02:00
|
|
|
void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog)
|
|
|
|
{
|
|
|
|
if (applet()) {
|
2009-10-23 15:48:29 +02:00
|
|
|
applet()->d->addStandardConfigurationPages(dialog);
|
2009-08-20 20:19:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-05 19:43:39 +01:00
|
|
|
void AppletScript::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
|
|
|
|
{
|
|
|
|
if (applet()) {
|
|
|
|
applet()->showMessage(icon, message, buttons);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void AppletScript::configChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DataEngine *AppletScript::dataEngine(const QString &engine) const
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
return d->applet->dataEngine(engine);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletScript::mainScript() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
2011-07-15 13:04:16 +02:00
|
|
|
return d->applet->package().filePath("mainscript");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 13:04:16 +02:00
|
|
|
Package AppletScript::package() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
return d->applet->package();
|
|
|
|
}
|
|
|
|
|
2009-11-11 01:25:54 +01:00
|
|
|
KPluginInfo AppletScript::description() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
return d->applet->d->appletDescription;
|
|
|
|
}
|
|
|
|
|
2011-02-22 13:21:33 +01:00
|
|
|
bool AppletScript::drawWallpaper() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
|
|
|
if (cont) {
|
|
|
|
return cont->drawWallpaper();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::setDrawWallpaper(bool drawWallpaper)
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
|
|
|
if (cont) {
|
|
|
|
cont->setDrawWallpaper(drawWallpaper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::Type AppletScript::containmentType() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
|
|
|
if (cont) {
|
|
|
|
return cont->containmentType();
|
|
|
|
} else {
|
|
|
|
return Containment::NoContainmentType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletScript::setContainmentType(Containment::Type type)
|
|
|
|
{
|
|
|
|
Q_ASSERT(d->applet);
|
|
|
|
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(d->applet);
|
|
|
|
if (cont) {
|
|
|
|
cont->setContainmentType(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
|
|
|
|
#include "moc_appletscript.cpp"
|