2009-08-18 00:30:29 +02:00
|
|
|
/*
|
2009-08-18 00:31:18 +02:00
|
|
|
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
2009-08-18 00:30:29 +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.
|
|
|
|
*/
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
#include "containmentactions.h"
|
2009-08-18 00:30:46 +02:00
|
|
|
#include "containment.h"
|
|
|
|
|
2009-08-18 00:31:23 +02:00
|
|
|
#include "private/dataengineconsumer_p.h"
|
2009-08-18 00:31:03 +02:00
|
|
|
#include "private/packages_p.h"
|
2009-08-18 00:31:32 +02:00
|
|
|
#include "private/containmentactions_p.h"
|
2009-08-18 00:31:03 +02:00
|
|
|
#include "private/containment_p.h"
|
|
|
|
|
2009-08-18 00:30:58 +02:00
|
|
|
#include <QMetaEnum>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QWheelEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsSceneWheelEvent>
|
2009-08-18 00:30:29 +02:00
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kservicetypetrader.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
|
|
|
|
#include <version.h>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
PackageStructure::Ptr ContainmentActionsPrivate::s_packageStructure(0);
|
2009-08-18 00:30:29 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions::ContainmentActions(QObject * parentObject)
|
|
|
|
: d(new ContainmentActionsPrivate(KService::serviceByStorageId(QString()), this))
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
setParent(parentObject);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions::ContainmentActions(QObject *parentObject, const QVariantList &args)
|
|
|
|
: d(new ContainmentActionsPrivate(KService::serviceByStorageId(args.count() > 0 ?
|
2009-08-18 00:30:29 +02:00
|
|
|
args[0].toString() : QString()), this))
|
|
|
|
{
|
|
|
|
// now remove first item since those are managed by Wallpaper and subclasses shouldn't
|
|
|
|
// need to worry about them. yes, it violates the constness of this var, but it lets us add
|
|
|
|
// or remove items later while applets can just pretend that their args always start at 0
|
|
|
|
QVariantList &mutableArgs = const_cast<QVariantList &>(args);
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
setParent(parentObject);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions::~ContainmentActions()
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
KPluginInfo::List ContainmentActions::listContainmentActionsInfo()
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
QString constraint;
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ContainmentActions", constraint);
|
2009-08-18 00:30:29 +02:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *ContainmentActions::load(Containment *parent, const QString &containmentActionsName, const QVariantList &args)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!parent) {
|
2009-08-18 00:30:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (containmentActionsName.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(containmentActionsName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/ContainmentActions", constraint);
|
2009-08-18 00:30:29 +02:00
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
2009-08-18 00:31:32 +02:00
|
|
|
kDebug() << "offers is empty for " << containmentActionsName;
|
2009-08-18 00:30:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::Ptr offer = offers.first();
|
|
|
|
KPluginLoader plugin(*offer);
|
|
|
|
|
|
|
|
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << offer->storageId() << args;
|
|
|
|
QString error;
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *containmentActions = offer->createInstance<Plasma::ContainmentActions>(0, allArgs, &error);
|
2009-08-18 00:30:29 +02:00
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!containmentActions) {
|
|
|
|
kDebug() << "Couldn't load containmentActions \"" << containmentActionsName << "\"! reason given: " << error;
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
containmentActions->setParent(parent);
|
|
|
|
containmentActions->d->containment = parent;
|
|
|
|
|
|
|
|
return containmentActions;
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
ContainmentActions *ContainmentActions::load(Containment *parent, const KPluginInfo &info, const QVariantList &args)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
if (!info.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-18 00:31:32 +02:00
|
|
|
return load(parent, info.pluginName(), args);
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
PackageStructure::Ptr ContainmentActions::packageStructure()
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!ContainmentActionsPrivate::s_packageStructure) {
|
|
|
|
ContainmentActionsPrivate::s_packageStructure = new ContainmentActionsPackage();
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
return ContainmentActionsPrivate::s_packageStructure;
|
2009-08-18 00:31:08 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
Containment *ContainmentActions::containment()
|
2009-08-18 00:30:46 +02:00
|
|
|
{
|
2009-08-18 00:31:08 +02:00
|
|
|
return d->containment;
|
2009-08-18 00:30:46 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString ContainmentActions::name() const
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!d->containmentActionsDescription.isValid()) {
|
|
|
|
return i18n("Unknown ContainmentActions");
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
return d->containmentActionsDescription.name();
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString ContainmentActions::icon() const
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!d->containmentActionsDescription.isValid()) {
|
2009-08-18 00:30:29 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
return d->containmentActionsDescription.icon();
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString ContainmentActions::pluginName() const
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
2009-08-18 00:31:32 +02:00
|
|
|
if (!d->containmentActionsDescription.isValid()) {
|
2009-08-18 00:30:29 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
return d->containmentActionsDescription.pluginName();
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
bool ContainmentActions::isInitialized() const
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
return d->initialized;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::restore(const KConfigGroup &config)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
init(config);
|
|
|
|
d->initialized = true;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::init(const KConfigGroup &config)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(config);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::save(KConfigGroup &config)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(config);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QWidget *ContainmentActions::createConfigurationInterface(QWidget *parent)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(parent);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::configurationAccepted()
|
2009-08-18 00:30:54 +02:00
|
|
|
{
|
|
|
|
//do nothing by default
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::contextEvent(QEvent *event)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QList<QAction*> ContainmentActions::contextualActions()
|
2009-08-18 00:30:46 +02:00
|
|
|
{
|
|
|
|
//empty list
|
|
|
|
return QList<QAction*>();
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
DataEngine *ContainmentActions::dataEngine(const QString &name) const
|
2009-08-18 00:31:23 +02:00
|
|
|
{
|
|
|
|
return d->dataEngine(name);
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
bool ContainmentActions::configurationRequired() const
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
|
|
|
return d->needsConfig;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::setConfigurationRequired(bool needsConfig)
|
2009-08-18 00:30:46 +02:00
|
|
|
{
|
2009-08-18 00:30:58 +02:00
|
|
|
//TODO: reason?
|
|
|
|
d->needsConfig = needsConfig;
|
2009-08-18 00:30:46 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
bool ContainmentActions::hasConfigurationInterface() const
|
2009-08-18 00:31:08 +02:00
|
|
|
{
|
|
|
|
return d->hasConfig;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::setHasConfigurationInterface(bool hasConfig)
|
2009-08-18 00:31:08 +02:00
|
|
|
{
|
|
|
|
d->hasConfig = hasConfig;
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
QString ContainmentActions::eventToString(QEvent *event)
|
2009-08-18 00:30:29 +02:00
|
|
|
{
|
2009-08-18 00:30:58 +02:00
|
|
|
QString trigger;
|
|
|
|
Qt::KeyboardModifiers modifiers;
|
|
|
|
|
|
|
|
//strict typing sucks sometimes.
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
{
|
|
|
|
QMouseEvent *e = dynamic_cast<QMouseEvent*>(event);
|
|
|
|
int m = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons");
|
|
|
|
QMetaEnum mouse = QObject::staticQtMetaObject.enumerator(m);
|
|
|
|
trigger += mouse.valueToKey(e->button());
|
|
|
|
modifiers = e->modifiers();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::GraphicsSceneMousePress:
|
|
|
|
case QEvent::GraphicsSceneMouseRelease:
|
|
|
|
{
|
|
|
|
QGraphicsSceneMouseEvent *e = dynamic_cast<QGraphicsSceneMouseEvent*>(event);
|
|
|
|
int m = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons");
|
|
|
|
QMetaEnum mouse = QObject::staticQtMetaObject.enumerator(m);
|
|
|
|
trigger += mouse.valueToKey(e->button());
|
|
|
|
modifiers = e->modifiers();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::Wheel:
|
|
|
|
{
|
|
|
|
QWheelEvent *e = dynamic_cast<QWheelEvent*>(event);
|
|
|
|
int o = QObject::staticQtMetaObject.indexOfEnumerator("Orientations");
|
|
|
|
QMetaEnum orient = QObject::staticQtMetaObject.enumerator(o);
|
|
|
|
trigger = "wheel:";
|
|
|
|
trigger += orient.valueToKey(e->orientation());
|
|
|
|
modifiers = e->modifiers();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::GraphicsSceneWheel:
|
|
|
|
{
|
|
|
|
QGraphicsSceneWheelEvent *e = dynamic_cast<QGraphicsSceneWheelEvent*>(event);
|
|
|
|
int o = QObject::staticQtMetaObject.indexOfEnumerator("Orientations");
|
|
|
|
QMetaEnum orient = QObject::staticQtMetaObject.enumerator(o);
|
|
|
|
trigger = "wheel:";
|
|
|
|
trigger += orient.valueToKey(e->orientation());
|
|
|
|
modifiers = e->modifiers();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QString();
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:58 +02:00
|
|
|
int k = QObject::staticQtMetaObject.indexOfEnumerator("KeyboardModifiers");
|
|
|
|
QMetaEnum kbd = QObject::staticQtMetaObject.enumerator(k);
|
|
|
|
trigger += ";";
|
|
|
|
trigger += kbd.valueToKeys(modifiers);
|
|
|
|
|
|
|
|
return trigger;
|
2009-08-18 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
void ContainmentActions::paste(QPointF scenePos, QPoint screenPos)
|
2009-08-18 00:31:03 +02:00
|
|
|
{
|
|
|
|
Containment *c = containment();
|
|
|
|
if (c) {
|
|
|
|
c->d->dropData(scenePos, screenPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:30:29 +02:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2009-08-18 00:31:32 +02:00
|
|
|
#include "containmentactions.moc"
|