2009-05-13 02:55:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Chani Armitage <chani@kde.org>
|
2010-10-13 18:12:43 +02:00
|
|
|
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2010 Marco Martin <mart@kde.org>
|
2009-05-13 02:55:25 +02:00
|
|
|
*
|
|
|
|
* 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 "appletinterface.h"
|
2012-10-24 22:52:01 +02:00
|
|
|
#include "../declarative/appletcontainer.h"
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <QAction>
|
2011-12-05 22:40:16 +01:00
|
|
|
#include <QDir>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <QFile>
|
2009-12-16 23:05:46 +01:00
|
|
|
#include <QScriptEngine>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <QSignalMapper>
|
2009-11-18 23:57:09 +01:00
|
|
|
#include <QTimer>
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2010-11-10 17:03:55 +01:00
|
|
|
#include <KDebug>
|
2011-12-05 22:40:16 +01:00
|
|
|
#include <KGlobalSettings>
|
2009-11-14 01:24:14 +01:00
|
|
|
#include <KIcon>
|
|
|
|
#include <KService>
|
|
|
|
#include <KServiceTypeTrader>
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
#include <Plasma/Plasma>
|
|
|
|
#include <Plasma/Applet>
|
2011-03-02 14:41:38 +01:00
|
|
|
#include <Plasma/Corona>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <Plasma/Context>
|
|
|
|
#include <Plasma/Package>
|
2012-08-22 12:03:27 +02:00
|
|
|
#include <Plasma/ToolTipManager>
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2010-08-06 04:01:40 +02:00
|
|
|
Q_DECLARE_METATYPE(AppletInterface*)
|
|
|
|
|
2010-10-13 18:12:43 +02:00
|
|
|
AppletInterface::AppletInterface(AbstractJsAppletScript *parent)
|
2009-05-13 02:55:25 +02:00
|
|
|
: QObject(parent),
|
|
|
|
m_appletScriptEngine(parent),
|
2010-01-07 03:04:59 +01:00
|
|
|
m_actionSignals(0)
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
|
|
|
|
connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving()));
|
2010-10-13 18:12:43 +02:00
|
|
|
connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged()));
|
2011-04-14 22:49:13 +02:00
|
|
|
connect(applet(), SIGNAL(newStatus(Plasma::ItemStatus)), this, SIGNAL(statusChanged()));
|
2012-08-09 15:43:30 +02:00
|
|
|
connect(m_appletScriptEngine, SIGNAL(formFactorChanged()),
|
|
|
|
this, SIGNAL(formFactorChanged()));
|
|
|
|
connect(m_appletScriptEngine, SIGNAL(locationChanged()),
|
|
|
|
this, SIGNAL(locationChanged()));
|
|
|
|
connect(m_appletScriptEngine, SIGNAL(contextChanged()),
|
|
|
|
this, SIGNAL(contextChanged()));
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AppletInterface::~AppletInterface()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-06 04:01:40 +02:00
|
|
|
AppletInterface *AppletInterface::extract(QScriptEngine *engine)
|
|
|
|
{
|
|
|
|
QScriptValue appletValue = engine->globalObject().property("plasmoid");
|
|
|
|
return qobject_cast<AppletInterface*>(appletValue.toQObject());
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
Plasma::DataEngine* AppletInterface::dataEngine(const QString &name)
|
|
|
|
{
|
|
|
|
return applet()->dataEngine(name);
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
AppletInterface::FormFactor AppletInterface::formFactor() const
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
return static_cast<FormFactor>(applet()->formFactor());
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
AppletInterface::Location AppletInterface::location() const
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
return static_cast<Location>(applet()->location());
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
QString AppletInterface::currentActivity() const
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
return applet()->context()->currentActivity();
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
AppletInterface::AspectRatioMode AppletInterface::aspectRatioMode() const
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
return static_cast<AspectRatioMode>(applet()->aspectRatioMode());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setAspectRatioMode(AppletInterface::AspectRatioMode mode)
|
|
|
|
{
|
|
|
|
applet()->setAspectRatioMode(static_cast<Plasma::AspectRatioMode>(mode));
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
bool AppletInterface::shouldConserveResources() const
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
return applet()->shouldConserveResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setFailedToLaunch(bool failed, const QString &reason)
|
|
|
|
{
|
|
|
|
m_appletScriptEngine->setFailedToLaunch(failed, reason);
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
bool AppletInterface::isBusy() const
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
|
|
|
return applet()->isBusy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setBusy(bool busy)
|
|
|
|
{
|
|
|
|
applet()->setBusy(busy);
|
|
|
|
}
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
AppletInterface::BackgroundHints AppletInterface::backgroundHints() const
|
|
|
|
{
|
|
|
|
return static_cast<BackgroundHints>(static_cast<int>(applet()->backgroundHints()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setBackgroundHints(BackgroundHints hint)
|
|
|
|
{
|
|
|
|
applet()->setBackgroundHints(Plasma::Applet::BackgroundHints(hint));
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason)
|
|
|
|
{
|
|
|
|
m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason);
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:44:35 +01:00
|
|
|
void JsAppletInterface::update(const QRectF &rect)
|
2009-05-13 02:55:25 +02:00
|
|
|
{
|
2009-11-13 23:10:32 +01:00
|
|
|
applet()->update(rect);
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
2011-01-28 20:44:35 +01:00
|
|
|
QGraphicsLayout *JsAppletInterface::layout() const
|
2010-10-13 18:12:43 +02:00
|
|
|
{
|
|
|
|
return applet()->layout();
|
|
|
|
}
|
|
|
|
|
2011-01-28 20:44:35 +01:00
|
|
|
void JsAppletInterface::setLayout(QGraphicsLayout *layout)
|
2010-10-13 18:12:43 +02:00
|
|
|
{
|
|
|
|
applet()->setLayout(layout);
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
QString AppletInterface::activeConfig() const
|
|
|
|
{
|
|
|
|
return m_currentConfig.isEmpty() ? "main" : m_currentConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setActiveConfig(const QString &name)
|
|
|
|
{
|
|
|
|
if (name == "main") {
|
2009-05-26 20:03:15 +02:00
|
|
|
m_currentConfig.clear();
|
2009-05-13 02:55:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::ConfigLoader *loader = m_configs.value(name, 0);
|
|
|
|
|
|
|
|
if (!loader) {
|
2010-09-05 00:51:13 +02:00
|
|
|
QString path = m_appletScriptEngine->filePath("config", name + ".xml");
|
2009-05-13 02:55:25 +02:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile f(path);
|
|
|
|
KConfigGroup cg = applet()->config();
|
|
|
|
loader = new Plasma::ConfigLoader(&cg, &f, this);
|
|
|
|
m_configs.insert(name, loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentConfig = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::writeConfig(const QString &entry, const QVariant &value)
|
|
|
|
{
|
|
|
|
Plasma::ConfigLoader *config = 0;
|
|
|
|
if (m_currentConfig.isEmpty()) {
|
|
|
|
config = applet()->configScheme();
|
|
|
|
} else {
|
|
|
|
config = m_configs.value(m_currentConfig, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
KConfigSkeletonItem *item = config->findItemByName(entry);
|
|
|
|
if (item) {
|
|
|
|
item->setProperty(value);
|
2009-05-26 20:03:15 +02:00
|
|
|
config->blockSignals(true);
|
2009-05-13 02:55:25 +02:00
|
|
|
config->writeConfig();
|
2009-05-26 20:03:15 +02:00
|
|
|
config->blockSignals(false);
|
2009-05-13 02:55:25 +02:00
|
|
|
m_appletScriptEngine->configNeedsSaving();
|
|
|
|
}
|
2013-01-10 04:59:30 +01:00
|
|
|
} else
|
|
|
|
kWarning() << "Couldn't find a configuration entry";
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QScriptValue AppletInterface::readConfig(const QString &entry) const
|
|
|
|
{
|
|
|
|
Plasma::ConfigLoader *config = 0;
|
|
|
|
QVariant result;
|
2009-05-26 20:03:15 +02:00
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
if (m_currentConfig.isEmpty()) {
|
|
|
|
config = applet()->configScheme();
|
|
|
|
} else {
|
|
|
|
config = m_configs.value(m_currentConfig, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config) {
|
|
|
|
result = config->property(entry);
|
|
|
|
}
|
2009-05-26 20:03:15 +02:00
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
return m_appletScriptEngine->variantToScriptValue(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletInterface::file(const QString &fileType)
|
|
|
|
{
|
2010-09-05 00:51:13 +02:00
|
|
|
return m_appletScriptEngine->filePath(fileType, QString());
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletInterface::file(const QString &fileType, const QString &filePath)
|
|
|
|
{
|
2010-09-05 00:51:13 +02:00
|
|
|
return m_appletScriptEngine->filePath(fileType, filePath);
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<QAction*> AppletInterface::contextualActions() const
|
|
|
|
{
|
|
|
|
QList<QAction*> actions;
|
|
|
|
Plasma::Applet *a = applet();
|
2011-09-22 18:36:18 +02:00
|
|
|
if (a->hasFailedToLaunch()) {
|
|
|
|
return actions;
|
|
|
|
}
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
foreach (const QString &name, m_actions) {
|
|
|
|
QAction *action = a->action(name);
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
actions << action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF AppletInterface::size() const
|
|
|
|
{
|
|
|
|
return applet()->size();
|
|
|
|
}
|
|
|
|
|
2009-10-21 01:30:36 +02:00
|
|
|
QRectF AppletInterface::rect() const
|
|
|
|
{
|
2009-10-21 01:49:48 +02:00
|
|
|
return applet()->contentsRect();
|
2009-10-21 01:30:36 +02:00
|
|
|
}
|
|
|
|
|
2011-10-27 16:43:55 +02:00
|
|
|
void AppletInterface::setActionSeparator(const QString &name)
|
|
|
|
{
|
|
|
|
Plasma::Applet *a = applet();
|
|
|
|
QAction *action = a->action(name);
|
|
|
|
|
2011-10-28 11:42:30 +02:00
|
|
|
if (action) {
|
2011-10-27 16:43:55 +02:00
|
|
|
action->setSeparator(true);
|
|
|
|
} else {
|
|
|
|
action = new QAction(this);
|
|
|
|
action->setSeparator(true);
|
|
|
|
a->addAction(name, action);
|
|
|
|
m_actions.append(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
void AppletInterface::setAction(const QString &name, const QString &text, const QString &icon, const QString &shortcut)
|
|
|
|
{
|
|
|
|
Plasma::Applet *a = applet();
|
|
|
|
QAction *action = a->action(name);
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
action->setText(text);
|
|
|
|
} else {
|
|
|
|
action = new QAction(text, this);
|
|
|
|
a->addAction(name, action);
|
|
|
|
|
|
|
|
Q_ASSERT(!m_actions.contains(name));
|
2011-09-28 08:50:07 +02:00
|
|
|
m_actions.append(name);
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
if (!m_actionSignals) {
|
|
|
|
m_actionSignals = new QSignalMapper(this);
|
|
|
|
connect(m_actionSignals, SIGNAL(mapped(QString)),
|
|
|
|
m_appletScriptEngine, SLOT(executeAction(QString)));
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(action, SIGNAL(triggered()), m_actionSignals, SLOT(map()));
|
|
|
|
m_actionSignals->setMapping(action, name);
|
|
|
|
}
|
|
|
|
|
2010-03-09 06:33:40 +01:00
|
|
|
if (!icon.isEmpty()) {
|
|
|
|
action->setIcon(KIcon(icon));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shortcut.isEmpty()) {
|
|
|
|
action->setShortcut(shortcut);
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
action->setObjectName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::removeAction(const QString &name)
|
|
|
|
{
|
|
|
|
Plasma::Applet *a = applet();
|
|
|
|
QAction *action = a->action(name);
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
if (m_actionSignals) {
|
|
|
|
m_actionSignals->removeMappings(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete action;
|
|
|
|
}
|
|
|
|
|
2011-09-28 08:50:07 +02:00
|
|
|
m_actions.removeAll(name);
|
2009-05-13 02:55:25 +02:00
|
|
|
}
|
|
|
|
|
2011-02-28 20:42:06 +01:00
|
|
|
QAction *AppletInterface::action(QString name) const
|
|
|
|
{
|
|
|
|
return applet()->action(name);
|
|
|
|
}
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
void AppletInterface::resize(qreal w, qreal h)
|
|
|
|
{
|
|
|
|
applet()->resize(w,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setMinimumSize(qreal w, qreal h)
|
|
|
|
{
|
|
|
|
applet()->setMinimumSize(w,h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletInterface::setPreferredSize(qreal w, qreal h)
|
|
|
|
{
|
|
|
|
applet()->setPreferredSize(w,h);
|
|
|
|
}
|
|
|
|
|
2009-11-13 23:27:30 +01:00
|
|
|
bool AppletInterface::immutable() const
|
|
|
|
{
|
|
|
|
return applet()->immutability() != Plasma::Mutable;
|
|
|
|
}
|
|
|
|
|
2010-02-01 17:19:32 +01:00
|
|
|
bool AppletInterface::userConfiguring() const
|
|
|
|
{
|
|
|
|
return applet()->isUserConfiguring();
|
|
|
|
}
|
|
|
|
|
2009-11-14 01:24:14 +01:00
|
|
|
int AppletInterface::apiVersion() const
|
|
|
|
{
|
|
|
|
const QString constraint("[X-Plasma-API] == 'javascript' and 'Applet' in [X-Plasma-ComponentTypes]");
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ScriptEngine", constraint);
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offers.first()->property("X-KDE-PluginInfo-Version", QVariant::Int).toInt();
|
|
|
|
}
|
|
|
|
|
2009-11-14 06:19:19 +01:00
|
|
|
bool AppletInterface::include(const QString &script)
|
|
|
|
{
|
2010-09-05 00:51:13 +02:00
|
|
|
const QString path = m_appletScriptEngine->filePath("scripts", script);
|
2010-09-04 02:06:18 +02:00
|
|
|
|
2009-11-14 06:19:19 +01:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_appletScriptEngine->include(path);
|
|
|
|
}
|
|
|
|
|
2009-11-14 08:32:00 +01:00
|
|
|
void AppletInterface::debug(const QString &msg)
|
|
|
|
{
|
|
|
|
kDebug() << msg;
|
|
|
|
}
|
|
|
|
|
2010-01-06 01:23:31 +01:00
|
|
|
QObject *AppletInterface::findChild(const QString &name) const
|
|
|
|
{
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QGraphicsItem *item, applet()->childItems()) {
|
|
|
|
QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget *>(item);
|
|
|
|
if (widget && widget->objectName() == name) {
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-20 22:40:55 +01:00
|
|
|
Plasma::Extender *AppletInterface::extender() const
|
|
|
|
{
|
|
|
|
return m_appletScriptEngine->extender();
|
|
|
|
}
|
|
|
|
|
2011-03-27 16:59:08 +02:00
|
|
|
void AppletInterface::setAssociatedApplication(const QString &string)
|
|
|
|
{
|
|
|
|
applet()->setAssociatedApplication(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletInterface::associatedApplication() const
|
|
|
|
{
|
|
|
|
return applet()->associatedApplication();
|
|
|
|
}
|
2010-10-13 18:12:43 +02:00
|
|
|
|
2011-04-14 16:35:38 +02:00
|
|
|
void AppletInterface::setStatus(const AppletInterface::ItemStatus &status)
|
|
|
|
{
|
|
|
|
applet()->setStatus((Plasma::ItemStatus)status);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppletInterface::ItemStatus AppletInterface::status() const
|
|
|
|
{
|
|
|
|
return (AppletInterface::ItemStatus)((int)(applet()->status()));
|
|
|
|
}
|
|
|
|
|
2012-08-01 20:38:35 +02:00
|
|
|
void AppletInterface::setHorizontalSizePolicy(QtSizePolicy horizPolicy)
|
|
|
|
{
|
|
|
|
QSizePolicy policy = applet()->sizePolicy();
|
|
|
|
policy.setHorizontalPolicy((QSizePolicy::Policy)horizPolicy);
|
|
|
|
applet()->setSizePolicy(policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppletInterface::QtSizePolicy AppletInterface::horizontalSizePolicy() const
|
|
|
|
{
|
|
|
|
return (AppletInterface::QtSizePolicy)applet()->sizePolicy().horizontalPolicy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AppletInterface::setVerticalSizePolicy(QtSizePolicy vertPolicy)
|
|
|
|
{
|
|
|
|
QSizePolicy policy = applet()->sizePolicy();
|
|
|
|
policy.setVerticalPolicy((QSizePolicy::Policy)vertPolicy);
|
|
|
|
applet()->setSizePolicy(policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppletInterface::QtSizePolicy AppletInterface::verticalSizePolicy() const
|
|
|
|
{
|
|
|
|
return (AppletInterface::QtSizePolicy)applet()->sizePolicy().verticalPolicy();
|
|
|
|
}
|
|
|
|
|
2011-12-05 22:40:16 +01:00
|
|
|
/*
|
|
|
|
QString AppletInterface::downloadPath(const QString &file)
|
|
|
|
{
|
|
|
|
KDesktopFile config(v.toVariant().value<Plasma::Package>().path() + "/metadata.desktop");
|
|
|
|
KConfigGroup cg = config.desktopGroup();
|
|
|
|
const QString pluginName = cg.readEntry("X-KDE-PluginInfo-Name", QString());
|
|
|
|
destination = KGlobalSettings::downloadPath() + "/Plasma/" + pluginName + '/';
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
QStringList AppletInterface::downloadedFiles() const
|
|
|
|
{
|
|
|
|
const QString downloadDir = KGlobalSettings::downloadPath() + "/Plasma/" + applet()->pluginName();
|
|
|
|
QDir dir(downloadDir);
|
|
|
|
return dir.entryList(QDir::Files | QDir::NoSymLinks | QDir::Readable);
|
|
|
|
}
|
|
|
|
|
2009-11-18 23:40:38 +01:00
|
|
|
void AppletInterface::gc()
|
|
|
|
{
|
|
|
|
QTimer::singleShot(0, m_appletScriptEngine, SLOT(collectGarbage()));
|
|
|
|
}
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
|
2010-10-13 18:12:43 +02:00
|
|
|
PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent)
|
2011-02-20 19:45:12 +01:00
|
|
|
: APPLETSUPERCLASS(parent)
|
2009-12-16 23:05:46 +01:00
|
|
|
{
|
2011-11-24 18:04:43 +01:00
|
|
|
connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SIGNAL(popupEvent(bool)));
|
2012-08-22 12:03:27 +02:00
|
|
|
connect(m_appletScriptEngine, SIGNAL(popupEvent(bool)), this, SLOT(sourceAppletPopupEvent(bool)));
|
2009-12-16 23:05:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletInterface::setPopupIcon(const QIcon &icon)
|
|
|
|
{
|
|
|
|
popupApplet()->setPopupIcon(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon PopupAppletInterface::popupIcon()
|
|
|
|
{
|
|
|
|
return popupApplet()->popupIcon();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletInterface::setPopupIconByName(const QString &name)
|
|
|
|
{
|
|
|
|
return popupApplet()->setPopupIcon(name);
|
|
|
|
}
|
|
|
|
|
2012-08-22 12:03:27 +02:00
|
|
|
void PopupAppletInterface::setPopupIconToolTip(const QVariantHash &data)
|
|
|
|
{
|
|
|
|
if (data == m_rawToolTipData) {
|
|
|
|
return;
|
|
|
|
} else if (!data.contains("image") && !data.contains("mainText") &&
|
|
|
|
!data.contains("subText")) {
|
|
|
|
m_rawToolTipData = QVariantHash();
|
|
|
|
Plasma::ToolTipManager::self()->clearContent(popupApplet());
|
|
|
|
Plasma::ToolTipManager::self()->unregisterWidget(popupApplet());
|
|
|
|
emit popupIconToolTipChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::ToolTipContent content(data.value("mainText").toString(), data.value("subText").toString());
|
|
|
|
|
|
|
|
const QVariant image = data.value("image");
|
|
|
|
if (image.canConvert<QIcon>()) {
|
|
|
|
content.setImage(image.value<QIcon>());
|
|
|
|
} else if (image.canConvert<QPixmap>()) {
|
|
|
|
content.setImage(image.value<QPixmap>());
|
|
|
|
} else if (image.canConvert<QImage>()) {
|
|
|
|
content.setImage(QPixmap::fromImage(image.value<QImage>()));
|
|
|
|
} else if (image.canConvert<QString>()) {
|
|
|
|
content.setImage(KIcon(image.toString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::ToolTipManager::self()->registerWidget(popupApplet());
|
|
|
|
Plasma::ToolTipManager::self()->setContent(popupApplet(), content);
|
|
|
|
m_rawToolTipData = data;
|
|
|
|
m_toolTipData = content;
|
|
|
|
emit popupIconToolTipChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantHash PopupAppletInterface::popupIconToolTip() const
|
|
|
|
{
|
|
|
|
return m_rawToolTipData;
|
|
|
|
}
|
|
|
|
|
2010-02-28 17:11:48 +01:00
|
|
|
void PopupAppletInterface::setPassivePopup(bool passive)
|
|
|
|
{
|
|
|
|
popupApplet()->setPassivePopup(passive);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PopupAppletInterface::isPassivePopup() const
|
|
|
|
{
|
|
|
|
return popupApplet()->isPassivePopup();
|
|
|
|
}
|
|
|
|
|
2012-09-20 17:07:07 +02:00
|
|
|
bool PopupAppletInterface::isPopupShowing() const
|
|
|
|
{
|
|
|
|
return popupApplet()->isPopupShowing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletInterface::setPopupShowing(bool show)
|
|
|
|
{
|
|
|
|
show ? popupApplet()->showPopup() : popupApplet()->hidePopup();
|
|
|
|
}
|
|
|
|
|
2010-02-28 17:11:48 +01:00
|
|
|
void PopupAppletInterface::togglePopup()
|
|
|
|
{
|
|
|
|
popupApplet()->togglePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletInterface::hidePopup()
|
|
|
|
{
|
|
|
|
popupApplet()->hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupAppletInterface::showPopup()
|
|
|
|
{
|
|
|
|
popupApplet()->showPopup();
|
|
|
|
}
|
|
|
|
|
2011-11-01 21:30:03 +01:00
|
|
|
void PopupAppletInterface::showPopup(int timeout)
|
|
|
|
{
|
|
|
|
popupApplet()->showPopup(timeout);
|
|
|
|
}
|
|
|
|
|
2010-02-28 17:11:48 +01:00
|
|
|
void PopupAppletInterface::setPopupWidget(QGraphicsWidget *widget)
|
|
|
|
{
|
|
|
|
popupApplet()->setGraphicsWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget *PopupAppletInterface::popupWidget()
|
|
|
|
{
|
|
|
|
return popupApplet()->graphicsWidget();
|
|
|
|
}
|
|
|
|
|
2012-08-22 12:03:27 +02:00
|
|
|
void PopupAppletInterface::sourceAppletPopupEvent(bool show)
|
|
|
|
{
|
|
|
|
if (show) {
|
|
|
|
Plasma::ToolTipManager::self()->clearContent(popupApplet());
|
|
|
|
} else {
|
|
|
|
Plasma::ToolTipManager::self()->registerWidget(popupApplet());
|
|
|
|
Plasma::ToolTipManager::self()->setContent(popupApplet(), m_toolTipData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////// ContainmentInterface
|
|
|
|
|
2011-02-20 19:45:12 +01:00
|
|
|
ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
|
2011-03-07 20:16:49 +01:00
|
|
|
: APPLETSUPERCLASS(parent),
|
ToolBox bindings for declarative containments
This adds the necessary bits, actions handling, showing / hiding of
toolbox and a hooks for config interface and add widgets.
The interesting bits:
Toolbox separate on the scene
For declarative containments, we add a declarativewidget on top of the
view which loads the "org.kde.toolbox" package. The toolbox can differ
per platform, layout of toolbox and containment can not "leak" into each
other.
ToolBox import
The most important and interesting bit is the list of actions the
ToolBox exposes, it's collected from corona, containment. The latter is
actually problematic, since we don't get access to the actions
internally provided by Containment
(ContainmentPrivate::addDefaultActions).
Containment::setToolBox(AbstractToolBox) being protected, we cannot
register our declarative ToolBoxProxy implementation to the containment,
so we have to wire up settings and addwidgets separately. Sorting of the
actions is "random", and expected to be done by the QML toolbox
implementation, based on objectName strings.
REVIEW:107232
2012-11-07 17:21:26 +01:00
|
|
|
m_movableApplets(true),
|
|
|
|
m_toolBox(0)
|
2011-02-20 19:45:12 +01:00
|
|
|
{
|
|
|
|
connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *)));
|
|
|
|
|
|
|
|
connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &)));
|
2011-03-02 15:40:47 +01:00
|
|
|
|
2012-10-25 14:54:05 +02:00
|
|
|
connect(containment(), SIGNAL(screenChanged(int, int, Plasma::Containment*)), this, SIGNAL(screenChanged()));
|
2011-04-04 15:14:19 +02:00
|
|
|
|
|
|
|
connect(containment()->context(), SIGNAL(activityChanged(Plasma::Context *)), this, SIGNAL(activityNameChanged()));
|
|
|
|
connect(containment()->context(), SIGNAL(changed(Plasma::Context *)), this, SIGNAL(activityIdChanged()));
|
2011-10-01 15:14:00 +02:00
|
|
|
|
|
|
|
if (containment()->corona()) {
|
|
|
|
connect(containment()->corona(), SIGNAL(availableScreenRegionChanged()),
|
|
|
|
this, SIGNAL(availableScreenRegionChanged()));
|
|
|
|
}
|
2012-10-24 22:52:01 +02:00
|
|
|
|
|
|
|
qmlRegisterType<AppletContainer>("org.kde.plasma.containments", 0, 1, "AppletContainer");
|
ToolBox bindings for declarative containments
This adds the necessary bits, actions handling, showing / hiding of
toolbox and a hooks for config interface and add widgets.
The interesting bits:
Toolbox separate on the scene
For declarative containments, we add a declarativewidget on top of the
view which loads the "org.kde.toolbox" package. The toolbox can differ
per platform, layout of toolbox and containment can not "leak" into each
other.
ToolBox import
The most important and interesting bit is the list of actions the
ToolBox exposes, it's collected from corona, containment. The latter is
actually problematic, since we don't get access to the actions
internally provided by Containment
(ContainmentPrivate::addDefaultActions).
Containment::setToolBox(AbstractToolBox) being protected, we cannot
register our declarative ToolBoxProxy implementation to the containment,
so we have to wire up settings and addwidgets separately. Sorting of the
actions is "random", and expected to be done by the QML toolbox
implementation, based on objectName strings.
REVIEW:107232
2012-11-07 17:21:26 +01:00
|
|
|
qmlRegisterType<ToolBoxProxy>();
|
2011-02-20 19:45:12 +01:00
|
|
|
}
|
|
|
|
|
2011-04-04 15:14:19 +02:00
|
|
|
QScriptValue ContainmentInterface::applets()
|
2011-02-20 19:45:12 +01:00
|
|
|
{
|
|
|
|
QScriptValue list = m_appletScriptEngine->engine()->newArray(containment()->applets().size());
|
|
|
|
int i = 0;
|
|
|
|
foreach (Plasma::Applet *applet, containment()->applets()) {
|
|
|
|
list.setProperty(i, m_appletScriptEngine->engine()->newQObject(applet));
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2011-02-22 13:23:36 +01:00
|
|
|
void ContainmentInterface::setDrawWallpaper(bool drawWallpaper)
|
|
|
|
{
|
|
|
|
m_appletScriptEngine->setDrawWallpaper(drawWallpaper);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContainmentInterface::drawWallpaper()
|
|
|
|
{
|
|
|
|
return m_appletScriptEngine->drawWallpaper();
|
|
|
|
}
|
|
|
|
|
|
|
|
ContainmentInterface::Type ContainmentInterface::containmentType() const
|
|
|
|
{
|
|
|
|
return (ContainmentInterface::Type)m_appletScriptEngine->containmentType();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentInterface::setContainmentType(ContainmentInterface::Type type)
|
|
|
|
{
|
|
|
|
m_appletScriptEngine->setContainmentType((Plasma::Containment::Type)type);
|
|
|
|
}
|
|
|
|
|
2011-03-02 14:41:38 +01:00
|
|
|
int ContainmentInterface::screen() const
|
|
|
|
{
|
2011-03-02 15:40:47 +01:00
|
|
|
return containment()->screen();
|
2011-03-02 14:41:38 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 15:40:47 +01:00
|
|
|
QScriptValue ContainmentInterface::screenGeometry(int id) const
|
2011-03-02 14:41:38 +01:00
|
|
|
{
|
2011-03-02 15:40:47 +01:00
|
|
|
QRectF rect;
|
2011-03-02 14:41:38 +01:00
|
|
|
if (containment()->corona()) {
|
2011-03-02 15:40:47 +01:00
|
|
|
rect = QRectF(containment()->corona()->screenGeometry(id));
|
2011-03-02 14:41:38 +01:00
|
|
|
}
|
2011-03-02 15:40:47 +01:00
|
|
|
|
|
|
|
QScriptValue val = m_appletScriptEngine->engine()->newObject();
|
|
|
|
val.setProperty("x", rect.x());
|
|
|
|
val.setProperty("y", rect.y());
|
|
|
|
val.setProperty("width", rect.width());
|
|
|
|
val.setProperty("height", rect.height());
|
|
|
|
return val;
|
2011-03-02 14:41:38 +01:00
|
|
|
}
|
|
|
|
|
2011-03-13 17:26:08 +01:00
|
|
|
QScriptValue ContainmentInterface::availableScreenRegion(int id) const
|
|
|
|
{
|
|
|
|
QRegion reg;
|
|
|
|
if (containment()->corona()) {
|
|
|
|
reg = containment()->corona()->availableScreenRegion(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
QScriptValue regVal = m_appletScriptEngine->engine()->newArray(reg.rects().size());
|
|
|
|
int i = 0;
|
|
|
|
foreach (QRect rect, reg.rects()) {
|
|
|
|
QScriptValue val = m_appletScriptEngine->engine()->newObject();
|
|
|
|
val.setProperty("x", rect.x());
|
|
|
|
val.setProperty("y", rect.y());
|
|
|
|
val.setProperty("width", rect.width());
|
|
|
|
val.setProperty("height", rect.height());
|
|
|
|
regVal.setProperty(i++, val);
|
|
|
|
}
|
|
|
|
return regVal;
|
|
|
|
}
|
|
|
|
|
2011-02-20 19:45:12 +01:00
|
|
|
void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos)
|
|
|
|
{
|
2011-03-07 20:16:49 +01:00
|
|
|
applet->setFlag(QGraphicsItem::ItemIsMovable, m_movableApplets);
|
2011-02-20 19:45:12 +01:00
|
|
|
emit appletAdded(applet, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet)
|
|
|
|
{
|
2011-03-07 20:16:49 +01:00
|
|
|
applet->setFlag(QGraphicsItem::ItemIsMovable, true);
|
2011-02-20 19:45:12 +01:00
|
|
|
emit appletRemoved(applet);
|
|
|
|
}
|
|
|
|
|
2011-03-07 20:16:49 +01:00
|
|
|
void ContainmentInterface::setMovableApplets(bool movable)
|
|
|
|
{
|
|
|
|
if (m_movableApplets == movable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_movableApplets = movable;
|
|
|
|
|
|
|
|
foreach (Plasma::Applet *applet, containment()->applets()) {
|
|
|
|
applet->setFlag(QGraphicsItem::ItemIsMovable, movable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContainmentInterface::hasMovableApplets() const
|
|
|
|
{
|
|
|
|
return m_movableApplets;
|
|
|
|
}
|
|
|
|
|
2011-04-04 15:14:19 +02:00
|
|
|
QString ContainmentInterface::activityName() const
|
|
|
|
{
|
|
|
|
return containment()->context()->currentActivity();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ContainmentInterface::activityId() const
|
|
|
|
{
|
|
|
|
return containment()->context()->currentActivityId();
|
|
|
|
}
|
|
|
|
|
ToolBox bindings for declarative containments
This adds the necessary bits, actions handling, showing / hiding of
toolbox and a hooks for config interface and add widgets.
The interesting bits:
Toolbox separate on the scene
For declarative containments, we add a declarativewidget on top of the
view which loads the "org.kde.toolbox" package. The toolbox can differ
per platform, layout of toolbox and containment can not "leak" into each
other.
ToolBox import
The most important and interesting bit is the list of actions the
ToolBox exposes, it's collected from corona, containment. The latter is
actually problematic, since we don't get access to the actions
internally provided by Containment
(ContainmentPrivate::addDefaultActions).
Containment::setToolBox(AbstractToolBox) being protected, we cannot
register our declarative ToolBoxProxy implementation to the containment,
so we have to wire up settings and addwidgets separately. Sorting of the
actions is "random", and expected to be done by the QML toolbox
implementation, based on objectName strings.
REVIEW:107232
2012-11-07 17:21:26 +01:00
|
|
|
ToolBoxProxy* ContainmentInterface::toolBox()
|
|
|
|
{
|
|
|
|
if (!m_toolBox) {
|
|
|
|
m_toolBox = new ToolBoxProxy(containment(), this);
|
|
|
|
//m_appletScriptEngine->setToolBox(m_toolBox); // setToolBox() is protected :/
|
|
|
|
}
|
|
|
|
return m_toolBox;
|
|
|
|
}
|
|
|
|
|
2010-10-13 18:12:43 +02:00
|
|
|
#ifndef USE_JS_SCRIPTENGINE
|
2009-05-13 02:55:25 +02:00
|
|
|
#include "appletinterface.moc"
|
2010-10-13 18:12:43 +02:00
|
|
|
#endif
|