enable build of desktop scripting

it still doesn't do anything and needs porting away from deprecated classes
This commit is contained in:
Marco Martin 2013-03-05 19:17:22 +01:00
parent 0af1a25b5e
commit dcd9954815
14 changed files with 81 additions and 97 deletions

View File

@ -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})

View File

@ -23,10 +23,14 @@
#include <QTimer>
#include <KGlobalSettings>
#include <KComponentData>
#include <k4aboutdata.h>
#include <Plasma/Containment>
#include <Plasma/Corona>
#include <Plasma/DataEngineManager>
#include <Plasma/DataEngine>
#include <Plasma/DataEngineConsumer>
#include <Plasma/PluginLoader>
#include <Plasma/Theme>
#ifdef Q_WS_X11
@ -89,12 +93,12 @@ QList<int> 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());

View File

@ -24,8 +24,6 @@
#include <QRectF>
#include <QStringList>
#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)

View File

@ -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();

View File

@ -25,7 +25,6 @@
#include <KConfigGroup>
#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

View File

@ -40,7 +40,6 @@
#include <QtCore/QSharedData>
#include "../plasmagenericshell_export.h"
#define DECLARE_SELF(Class, __fn__) \
Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \
@ -212,7 +211,7 @@ enum {
};
template <typename T>
class PLASMAGENERICSHELL_EXPORT Pointer : public QSharedData
class Pointer : public QSharedData
{
public:
typedef T* pointer_type;

View File

@ -21,9 +21,11 @@
#include <QAction>
#include <klocalizedstring.h>
#include <KActionCollection>
#include <Plasma/Corona>
#include <Plasma/Containment>
#include <Plasma/Wallpaper>
#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();
}

View File

@ -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<int> 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);

View File

@ -19,21 +19,17 @@
#include "layouttemplatepackagestructure.h"
#include <KLocalizedString>
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);
}
}

View File

@ -21,18 +21,16 @@
#define TEMPLATETEMPLATEPACKAGE_H
#include <Plasma/PackageStructure>
#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);
};
}

View File

@ -27,12 +27,16 @@
#include <QScriptValueIterator>
#include <KDebug>
#include <KGlobal>
#include <kdeversion.h>
#include <KGlobalSettings>
#include <KLocalizedString>
#include <KMimeTypeTrader>
#include <KServiceTypeTrader>
#include <KShell>
#include <KStandardDirs>
#include <KComponentData>
#include <k4aboutdata.h>
// KIO
#include <kemailsettings.h> // no camelcase include
@ -41,7 +45,7 @@
#include <Plasma/Containment>
#include <Plasma/Corona>
#include <Plasma/Package>
#include <Plasma/Wallpaper>
#include <Plasma/PluginLoader>
#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)

View File

@ -23,8 +23,6 @@
#include <QScriptEngine>
#include <QScriptValue>
#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

View File

@ -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<QGraphicsLinearLayout *>(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();
}
}*/
}
}

View File

@ -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)