[kwin] Move finding of scripted effect source file to ScriptedEffect

New ScriptedEffect::create(KService::Ptr). This is a preparation for
adding the ordering directly to the Effect.
This commit is contained in:
Martin Gräßlin 2014-03-24 11:02:28 +01:00
parent ba12fe3cc0
commit 42ff5e0c08
4 changed files with 21 additions and 13 deletions

View file

@ -36,7 +36,7 @@ Q_DECLARE_METATYPE(KWin::Effect*)
namespace KWin namespace KWin
{ {
ScriptedEffect *ScriptedEffect::create(const QString &, const QString &) ScriptedEffect *ScriptedEffect::create(KService::Ptr)
{ {
return nullptr; return nullptr;
} }

View file

@ -243,18 +243,7 @@ bool ScriptedEffectLoader::loadEffect(KService::Ptr effect, LoadEffectFlags flag
return false; return false;
} }
const QString scriptName = effect->property(QStringLiteral("X-Plasma-MainScript")).toString(); ScriptedEffect *e = ScriptedEffect::create(effect);
if (scriptName.isEmpty()) {
qDebug() << "X-Plasma-MainScript not set";
return false;
}
const QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral(KWIN_NAME) + QStringLiteral("/effects/") + name + QStringLiteral("/contents/") + scriptName);
if (scriptFile.isNull()) {
qDebug() << "Could not locate the effect script";
return false;
}
ScriptedEffect *e = ScriptedEffect::create(name, scriptFile);
if (!e) { if (!e) {
qDebug() << "Could not initialize scripted effect: " << name; qDebug() << "Could not initialize scripted effect: " << name;
return false; return false;

View file

@ -366,6 +366,23 @@ void fpx2FromScriptValue(const QScriptValue &value, KWin::FPx2 &fpx2)
} }
} }
ScriptedEffect *ScriptedEffect::create(KService::Ptr effect)
{
const QString name = effect->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString();
const QString scriptName = effect->property(QStringLiteral("X-Plasma-MainScript")).toString();
if (scriptName.isEmpty()) {
qDebug() << "X-Plasma-MainScript not set";
return nullptr;
}
const QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral(KWIN_NAME) + QStringLiteral("/effects/") + name + QStringLiteral("/contents/") + scriptName);
if (scriptFile.isNull()) {
qDebug() << "Could not locate the effect script";
return nullptr;
}
return ScriptedEffect::create(name, scriptFile);
}
ScriptedEffect *ScriptedEffect::create(const QString& effectName, const QString& pathToScript) ScriptedEffect *ScriptedEffect::create(const QString& effectName, const QString& pathToScript)
{ {
ScriptedEffect *effect = new ScriptedEffect(); ScriptedEffect *effect = new ScriptedEffect();

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KWIN_SCRIPTEDEFFECT_H #define KWIN_SCRIPTEDEFFECT_H
#include <kwinanimationeffect.h> #include <kwinanimationeffect.h>
#include <KService>
class KConfigLoader; class KConfigLoader;
class QScriptEngine; class QScriptEngine;
@ -105,6 +106,7 @@ public:
virtual void reconfigure(ReconfigureFlags flags); virtual void reconfigure(ReconfigureFlags flags);
QString activeConfig() const; QString activeConfig() const;
void setActiveConfig(const QString &name); void setActiveConfig(const QString &name);
static ScriptedEffect *create(KService::Ptr effect);
static ScriptedEffect *create(const QString &effectName, const QString &pathToScript); static ScriptedEffect *create(const QString &effectName, const QString &pathToScript);
virtual ~ScriptedEffect(); virtual ~ScriptedEffect();
/** /**