From dcd9954815d4c5d8274d25859c1a86a3b6802392 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 5 Mar 2013 19:17:22 +0100 Subject: [PATCH] enable build of desktop scripting it still doesn't do anything and needs porting away from deprecated classes --- src/shell/CMakeLists.txt | 14 +++++++ src/shell/scripting/appinterface.cpp | 20 +++++---- src/shell/scripting/appinterface.h | 4 +- src/shell/scripting/applet.cpp | 2 +- src/shell/scripting/applet.h | 3 +- src/shell/scripting/backportglobal.h | 3 +- src/shell/scripting/containment.cpp | 42 ++++++------------- src/shell/scripting/containment.h | 8 +--- .../layouttemplatepackagestructure.cpp | 18 ++++---- .../layouttemplatepackagestructure.h | 6 +-- src/shell/scripting/scriptengine.cpp | 28 +++++++------ src/shell/scripting/scriptengine.h | 4 +- src/shell/scripting/widget.cpp | 22 +++++----- src/shell/scripting/widget.h | 4 +- 14 files changed, 81 insertions(+), 97 deletions(-) diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index ccdef75cd..fde42de52 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -19,6 +19,7 @@ add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) find_package(Qt5Transitional REQUIRED Core) find_package(Qt5Qml REQUIRED) find_package(Qt5Quick REQUIRED) +find_package(Qt5Script REQUIRED) find_package(KCoreAddons REQUIRED) @@ -33,6 +34,17 @@ add_definitions(${Qt5Widgets_DEFINITIONS} ${Qt5Quick_DEFINITIONS} ${Qt5Qml_DEFIN # without -fPIE. We add that here. set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") +set(scripting_SRC + scripting/appinterface.cpp + scripting/applet.cpp + scripting/containment.cpp + scripting/i18n.cpp + scripting/layouttemplatepackagestructure.cpp + scripting/rect.cpp + scripting/scriptengine.cpp + scripting/widget.cpp +) + add_executable(testplasma2 main.cpp desktopcorona.cpp @@ -40,6 +52,7 @@ add_executable(testplasma2 shellpluginloader.cpp shellpackage.cpp view.cpp + ${scripting_SRC} ) # The Qt5Widgets_LIBRARIES variable also includes QtGui and QtCore @@ -51,6 +64,7 @@ target_link_libraries(testplasma2 ${KWindowSystem_LIBRARIES} ${KCoreAddons_LIBRARIES} plasma + ${Qt5Script_LIBRARIES} ) install(TARGETS testplasma2 ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/shell/scripting/appinterface.cpp b/src/shell/scripting/appinterface.cpp index 78bb15837..846656105 100644 --- a/src/shell/scripting/appinterface.cpp +++ b/src/shell/scripting/appinterface.cpp @@ -23,10 +23,14 @@ #include #include +#include +#include #include #include -#include +#include +#include +#include #include #ifdef Q_WS_X11 @@ -89,12 +93,12 @@ QList AppInterface::panelIds() const QString AppInterface::applicationVersion() const { - return KGlobal::mainComponent().aboutData()->version(); + return KComponentData::mainComponent().aboutData()->version(); } QString AppInterface::platformVersion() const { - return KDE::versionString(); + return 0;//KDE::versionString(); } int AppInterface::scriptingVersion() const @@ -155,11 +159,11 @@ void AppInterface::sleep(int ms) bool AppInterface::hasBattery() const { - Plasma::DataEngineManager *engines = Plasma::DataEngineManager::self(); - Plasma::DataEngine *power = engines->loadEngine("powermanagement"); + Plasma::DataEngineConsumer *consumer = new Plasma::DataEngineConsumer(); + Plasma::DataEngine *power = consumer->dataEngine("powermanagement"); const QStringList batteries = power->query("Battery")["Sources"].toStringList(); - engines->unloadEngine("powermanagement"); + delete consumer; return !batteries.isEmpty(); } @@ -167,7 +171,7 @@ QStringList AppInterface::knownWidgetTypes() const { if (m_knownWidgets.isEmpty()) { QStringList widgets; - KPluginInfo::List infoLs = Plasma::Applet::listAppletInfo(); + KPluginInfo::List infoLs = Plasma::PluginLoader::self()->listAppletInfo(QString()); foreach (const KPluginInfo &info, infoLs) { widgets.append(info.pluginName()); @@ -192,7 +196,7 @@ QStringList AppInterface::knownPanelTypes() const QStringList AppInterface::knownContainmentTypes(const QString &type) const { QStringList containments; - KPluginInfo::List infoLs = Plasma::Containment::listContainmentsOfType(type); + KPluginInfo::List infoLs = Plasma::PluginLoader::listContainmentsOfType(type); foreach (const KPluginInfo &info, infoLs) { containments.append(info.pluginName()); diff --git a/src/shell/scripting/appinterface.h b/src/shell/scripting/appinterface.h index cfe062922..786529c54 100644 --- a/src/shell/scripting/appinterface.h +++ b/src/shell/scripting/appinterface.h @@ -24,8 +24,6 @@ #include #include -#include "../plasmagenericshell_export.h" - namespace Plasma { class Applet; @@ -38,7 +36,7 @@ namespace WorkspaceScripting class ScriptEngine; -class PLASMAGENERICSHELL_EXPORT AppInterface : public QObject +class AppInterface : public QObject { Q_OBJECT Q_PROPERTY(bool locked READ coronaLocked WRITE lockCorona) diff --git a/src/shell/scripting/applet.cpp b/src/shell/scripting/applet.cpp index 3c81f7735..1c9b1e983 100644 --- a/src/shell/scripting/applet.cpp +++ b/src/shell/scripting/applet.cpp @@ -216,7 +216,7 @@ QString Applet::version() const return QString(); } - QString type = app->pluginName(); + QString type = app->pluginInfo().pluginName(); KService::List services = KServiceTypeTrader::self()->query("Plasma/Applet", "[X-KDE-PluginInfo-Name] == '" + type + "'"); if (services.isEmpty()) { return QString(); diff --git a/src/shell/scripting/applet.h b/src/shell/scripting/applet.h index a7c96004d..a53486005 100644 --- a/src/shell/scripting/applet.h +++ b/src/shell/scripting/applet.h @@ -25,7 +25,6 @@ #include -#include "../plasmagenericshell_export.h" namespace Plasma { @@ -35,7 +34,7 @@ namespace Plasma namespace WorkspaceScripting { -class PLASMAGENERICSHELL_EXPORT Applet : public QObject +class Applet : public QObject { Q_OBJECT diff --git a/src/shell/scripting/backportglobal.h b/src/shell/scripting/backportglobal.h index 9d32711dc..2d0fff82d 100644 --- a/src/shell/scripting/backportglobal.h +++ b/src/shell/scripting/backportglobal.h @@ -40,7 +40,6 @@ #include -#include "../plasmagenericshell_export.h" #define DECLARE_SELF(Class, __fn__) \ Class* self = qscriptvalue_cast(ctx->thisObject()); \ @@ -212,7 +211,7 @@ enum { }; template -class PLASMAGENERICSHELL_EXPORT Pointer : public QSharedData +class Pointer : public QSharedData { public: typedef T* pointer_type; diff --git a/src/shell/scripting/containment.cpp b/src/shell/scripting/containment.cpp index 2823b0293..d20623771 100644 --- a/src/shell/scripting/containment.cpp +++ b/src/shell/scripting/containment.cpp @@ -21,9 +21,11 @@ #include +#include +#include + #include #include -#include #include "scriptengine.h" #include "widget.h" @@ -48,9 +50,8 @@ Containment::Containment(Plasma::Containment *containment, QObject *parent) d->containment = containment; setCurrentConfigGroup(QStringList()); setCurrentGlobalConfigGroup(QStringList()); - if (containment && containment->wallpaper()) { - d->oldWallpaperPlugin = d->wallpaperPlugin = containment->wallpaper()->pluginName(); - d->oldWallpaperMode = d->wallpaperMode = containment->wallpaper()->renderingMode().name(); + if (containment) { + d->oldWallpaperPlugin = d->wallpaperPlugin = containment->wallpaper(); } } @@ -60,12 +61,11 @@ Containment::~Containment() Plasma::Containment *containment = d->containment.data(); if (d->oldWallpaperPlugin != d->wallpaperPlugin || d->oldWallpaperMode != d->wallpaperMode) { - containment->setWallpaper(d->wallpaperPlugin, d->wallpaperMode); - } else if (wallpaperConfigDirty() && containment->wallpaper()) { + containment->setWallpaper(d->wallpaperPlugin); + } else if (wallpaperConfigDirty()) { KConfigGroup cg(containment->config()); cg = KConfigGroup(&cg, "Wallpaper"); - cg = KConfigGroup(&cg, containment->wallpaper()->pluginName()); - containment->wallpaper()->restore(cg); + cg = KConfigGroup(&cg, containment->wallpaper()); } } @@ -110,22 +110,6 @@ void Containment::setWallpaperMode(const QString &wallpaperMode) d->wallpaperMode = wallpaperMode; } -int Containment::desktop() const -{ - if (!d->containment) { - return -1; - } - - return d->containment.data()->desktop(); -} - -void Containment::setDesktop(int desktop) -{ - if (d->containment) { - d->containment.data()->setScreen(d->containment.data()->screen(), desktop); - } -} - QString Containment::formFactor() const { if (!d->containment) { @@ -208,7 +192,7 @@ QScriptValue Containment::addWidget(QScriptContext *context, QScriptEngine *engi QScriptValue v = context->argument(0); Plasma::Applet *applet = 0; if (v.isString()) { - applet = c->d->containment.data()->addApplet(v.toString()); + applet = c->d->containment.data()->createApplet(v.toString()); if (applet) { ScriptEngine *env = ScriptEngine::envFor(engine); return env->wrap(applet); @@ -236,7 +220,7 @@ QScriptValue Containment::widgets(QScriptContext *context, QScriptEngine *engine int count = 0; foreach (Plasma::Applet *widget, c->d->containment.data()->applets()) { - if (widgetType.isEmpty() || widget->pluginName() == widgetType) { + if (widgetType.isEmpty() || widget->pluginInfo().pluginName() == widgetType) { widgets.setProperty(count, env->wrap(widget)); ++count; } @@ -277,20 +261,20 @@ QString Containment::type() const return QString(); } - return d->containment.data()->pluginName(); + return d->containment.data()->pluginInfo().pluginName(); } void Containment::remove() { if (d->containment) { - d->containment.data()->destroy(false); + d->containment.data()->destroy(); } } void Containment::showConfigurationInterface() { if (d->containment) { - QAction *configAction = d->containment.data()->action("configure"); + QAction *configAction = d->containment.data()->actions()->action("configure"); if (configAction && configAction->isEnabled()) { configAction->trigger(); } diff --git a/src/shell/scripting/containment.h b/src/shell/scripting/containment.h index 852f1fb8f..390777ec4 100644 --- a/src/shell/scripting/containment.h +++ b/src/shell/scripting/containment.h @@ -26,8 +26,6 @@ #include "applet.h" -#include "../plasmagenericshell_export.h" - namespace Plasma { class Containment; @@ -36,7 +34,7 @@ namespace Plasma namespace WorkspaceScripting { -class PLASMAGENERICSHELL_EXPORT Containment : public Applet +class Containment : public Applet { Q_OBJECT Q_PROPERTY(QString version READ version) @@ -53,7 +51,6 @@ class PLASMAGENERICSHELL_EXPORT Containment : public Applet Q_PROPERTY(QString formFactor READ formFactor) Q_PROPERTY(QList widgetIds READ widgetIds) Q_PROPERTY(int screen READ screen WRITE setScreen) - Q_PROPERTY(int desktop READ desktop WRITE setDesktop) Q_PROPERTY(int id READ id) public: @@ -68,9 +65,6 @@ public: QString name() const; void setName(const QString &name); - int desktop() const; - void setDesktop(int desktop); - int screen() const; void setScreen(int screen); diff --git a/src/shell/scripting/layouttemplatepackagestructure.cpp b/src/shell/scripting/layouttemplatepackagestructure.cpp index ff9fc9655..7f8711d90 100644 --- a/src/shell/scripting/layouttemplatepackagestructure.cpp +++ b/src/shell/scripting/layouttemplatepackagestructure.cpp @@ -19,21 +19,17 @@ #include "layouttemplatepackagestructure.h" +#include + namespace WorkspaceScripting { -LayoutTemplatePackageStructure::LayoutTemplatePackageStructure(QObject *parent) - : Plasma::PackageStructure(parent) +void LayoutTemplatePackageStructure::initPackage(Plasma::Package *package) { - setServicePrefix("plasma-layout-template"); - setDefaultPackageRoot("plasma/layout-templates"); - addFileDefinition("mainscript", "layout.js", i18n("Main Script File")); - setRequired("mainscript", true); -} - -LayoutTemplatePackageStructure::~LayoutTemplatePackageStructure() -{ - + package->setServicePrefix("plasma-layout-template"); + package->setDefaultPackageRoot("plasma/layout-templates"); + package->addFileDefinition("mainscript", "layout.js", i18n("Main Script File")); + package->setRequired("mainscript", true); } } diff --git a/src/shell/scripting/layouttemplatepackagestructure.h b/src/shell/scripting/layouttemplatepackagestructure.h index b9d33285e..abc556216 100644 --- a/src/shell/scripting/layouttemplatepackagestructure.h +++ b/src/shell/scripting/layouttemplatepackagestructure.h @@ -21,18 +21,16 @@ #define TEMPLATETEMPLATEPACKAGE_H #include -#include "../plasmagenericshell_export.h" namespace WorkspaceScripting { -class PLASMAGENERICSHELL_EXPORT LayoutTemplatePackageStructure : public Plasma::PackageStructure +class LayoutTemplatePackageStructure : public Plasma::PackageStructure { Q_OBJECT public: - LayoutTemplatePackageStructure(QObject *parent = 0); - ~LayoutTemplatePackageStructure(); + void initPackage(Plasma::Package *package); }; } diff --git a/src/shell/scripting/scriptengine.cpp b/src/shell/scripting/scriptengine.cpp index 620915cc3..d6479054b 100644 --- a/src/shell/scripting/scriptengine.cpp +++ b/src/shell/scripting/scriptengine.cpp @@ -27,12 +27,16 @@ #include #include +#include #include #include +#include #include #include #include #include +#include +#include // KIO #include // no camelcase include @@ -41,7 +45,7 @@ #include #include #include -#include +#include #include "appinterface.h" #include "containment.h" @@ -97,9 +101,8 @@ QScriptValue ScriptEngine::activityForScreen(QScriptContext *context, QScriptEng } const uint screen = context->argument(0).toInt32(); - const uint desktop = context->argumentCount() > 1 ? context->argument(1).toInt32() : -1; ScriptEngine *env = envFor(engine); - return env->wrap(env->m_corona->containmentForScreen(screen, desktop)); + return env->wrap(env->m_corona->containmentForScreen(screen)); } QScriptValue ScriptEngine::newActivity(QScriptContext *context, QScriptEngine *engine) @@ -119,7 +122,7 @@ QScriptValue ScriptEngine::createContainment(const QString &type, const QString defaultPlugin; bool exists = false; - const KPluginInfo::List list = Plasma::Containment::listContainmentsOfType(type); + const KPluginInfo::List list = Plasma::PluginLoader::listContainmentsOfType(type); foreach (const KPluginInfo &info, list) { if (info.pluginName() == plugin) { exists = true; @@ -133,7 +136,7 @@ QScriptValue ScriptEngine::createContainment(const QString &type, const QString ScriptEngine *env = envFor(engine); - Plasma::Containment *c = env->m_corona->addContainment(plugin); + Plasma::Containment *c = env->m_corona->createContainment(plugin); if (c) { if (type == "panel") { // some defaults @@ -261,7 +264,7 @@ QScriptValue ScriptEngine::loadTemplate(QScriptContext *context, QScriptEngine * } const QString constraint = QString("[X-Plasma-Shell] == '%1' and [X-KDE-PluginInfo-Name] == '%2'") - .arg(KGlobal::mainComponent().componentName(),layout); + .arg(KComponentData::mainComponent().componentName(),layout); KService::List offers = KServiceTypeTrader::self()->query("Plasma/LayoutTemplate", constraint); if (offers.isEmpty()) { @@ -269,15 +272,16 @@ QScriptValue ScriptEngine::loadTemplate(QScriptContext *context, QScriptEngine * return false; } - Plasma::PackageStructure::Ptr structure(new LayoutTemplatePackageStructure); + LayoutTemplatePackageStructure structure; + Plasma::Package package(&structure); KPluginInfo info(offers.first()); - const QString path = KStandardDirs::locate("data", structure->defaultPackageRoot() + '/' + info.pluginName() + '/'); + const QString path = KStandardDirs::locate("data", package.defaultPackageRoot() + '/' + info.pluginName() + '/'); if (path.isEmpty()) { kDebug() << "script path is empty"; return false; } + package.setPath(path); - Plasma::Package package(path, structure); const QString scriptFile = package.filePath("mainscript"); if (scriptFile.isEmpty()) { kDebug() << "scriptfile is empty"; @@ -511,8 +515,6 @@ QScriptValue ScriptEngine::userDataPath(QScriptContext *context, QScriptEngine * if (type.compare("desktop", Qt::CaseInsensitive) == 0) { return KGlobalSettings::desktopPath(); - } else if (type.compare("autostart", Qt::CaseInsensitive) == 0) { - return KGlobalSettings::autostartPath(); } else if (type.compare("documents", Qt::CaseInsensitive) == 0) { return KGlobalSettings::documentPath(); } else if (type.compare("music", Qt::CaseInsensitive) == 0) { @@ -595,8 +597,8 @@ bool ScriptEngine::isPanel(const Plasma::Containment *c) return false; } - return c->containmentType() == Plasma::Containment::PanelContainment || - c->containmentType() == Plasma::Containment::CustomPanelContainment; + return c->containmentType() == Plasma::PanelContainment || + c->containmentType() == Plasma::CustomPanelContainment; } QScriptValue ScriptEngine::activities(QScriptContext *context, QScriptEngine *engine) diff --git a/src/shell/scripting/scriptengine.h b/src/shell/scripting/scriptengine.h index 0281bb03e..af93e80ce 100644 --- a/src/shell/scripting/scriptengine.h +++ b/src/shell/scripting/scriptengine.h @@ -23,8 +23,6 @@ #include #include -#include "../plasmagenericshell_export.h" - namespace Plasma { class Applet; @@ -37,7 +35,7 @@ namespace WorkspaceScripting class Containment; -class PLASMAGENERICSHELL_EXPORT ScriptEngine : public QScriptEngine +class ScriptEngine : public QScriptEngine { Q_OBJECT diff --git a/src/shell/scripting/widget.cpp b/src/shell/scripting/widget.cpp index 8ae4aa3d0..3c8d611de 100644 --- a/src/shell/scripting/widget.cpp +++ b/src/shell/scripting/widget.cpp @@ -66,7 +66,7 @@ uint Widget::id() const QString Widget::type() const { if (d->applet) { - return d->applet.data()->pluginName(); + return d->applet.data()->pluginInfo().pluginName(); } return QString(); @@ -113,7 +113,7 @@ int Widget::index() const return -1; } - QGraphicsLayout *layout = c->layout(); + /*QGraphicsLayout *layout = c->layout(); if (!layout) { return - 1; } @@ -122,7 +122,7 @@ int Widget::index() const if (layout->itemAt(i) == applet) { return i; } - } + }*/ return -1; } @@ -138,41 +138,41 @@ void Widget::setIndex(int index) if (!c) { return; } - +/* //FIXME: this is hackish. would be nice to define this for gridlayouts too QGraphicsLinearLayout *layout = dynamic_cast(c->layout()); if (!layout) { return; } - layout->insertItem(index, applet); + layout->insertItem(index, applet);*/ } QRectF Widget::geometry() const { - if (d->applet) { + /*if (d->applet) { return d->applet.data()->geometry(); } - +*/ return QRectF(); } void Widget::setGeometry(const QRectF &geometry) { - if (d->applet) { + /*if (d->applet) { d->applet.data()->setGeometry(geometry); KConfigGroup cg = d->applet.data()->config().parent(); if (cg.isValid()) { cg.writeEntry("geometry", geometry); } - } + }*/ } void Widget::showConfigurationInterface() { - if (d->applet) { + /* if (d->applet) { d->applet.data()->showConfigurationInterface(); - } + }*/ } } diff --git a/src/shell/scripting/widget.h b/src/shell/scripting/widget.h index 400d7c9bb..c93441c72 100644 --- a/src/shell/scripting/widget.h +++ b/src/shell/scripting/widget.h @@ -24,8 +24,6 @@ #include "applet.h" -#include "../plasmagenericshell_export.h" - namespace Plasma { class Applet; @@ -34,7 +32,7 @@ namespace Plasma namespace WorkspaceScripting { -class PLASMAGENERICSHELL_EXPORT Widget : public Applet +class Widget : public Applet { Q_OBJECT Q_PROPERTY(QString type READ type)