make the desktop scripting finally work

completely migrate to X-Plasma-ContainmentType from the desktop file, use it to set the containment type as soon as possible (in Containment::init())
in this way the desktop script can recognize panels as what they are immediately
This commit is contained in:
Marco Martin 2013-03-07 21:25:30 +01:00
parent 0830c5047b
commit af6e538fa4
10 changed files with 35 additions and 38 deletions

View File

@ -27,6 +27,7 @@
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QFile>
#include <QContextMenuEvent>
#include <QMimeData>
@ -103,7 +104,20 @@ void Containment::init()
}
if (d->type == NoContainmentType) {
setContainmentType(DesktopContainment);
//setContainmentType(Plasma::DesktopContainment);
//Try to determine the containment type. It must be done as soon as possible
QString type = pluginInfo().property("X-Plasma-ContainmentType").toString();
if (type == "Panel") {
setContainmentType(Plasma::PanelContainment);
} else if (type == "Custom") {
setContainmentType(Plasma::CustomContainment);
} else if (type == "CustomPanel") {
setContainmentType(Plasma::CustomPanelContainment);
//default to desktop
} else {
setContainmentType(Plasma::DesktopContainment);
}
}
//connect actions

View File

@ -13,8 +13,5 @@ Comment[sv]=Plasmaminiprogram-omgivning och bakgrundsuppritning
Comment[uk]=Контейнер аплетів Плазми і малювання у тлі
Comment[x-test]=xxPlasma applet container and background painterxx
[PropertyDef::X-Plasma-ContainmentCategories]
Type=QStringList
[PropertyDef::X-Plasma-ContainmentType]
Type=QString

View File

@ -82,18 +82,6 @@ bool DeclarativeAppletScript::init()
if (pc) {
m_interface = new ContainmentInterface(this);
//Try to determine the containment type
QString type = pc->pluginInfo().property("X-Plasma-ContainmentType").toString();
if (type == "DesktopContainment") {
pc->setContainmentType(Plasma::DesktopContainment);
} else if (type == "PanelContainment") {
pc->setContainmentType(Plasma::PanelContainment);
} if (type == "CustomContainment") {
pc->setContainmentType(Plasma::CustomContainment);
} else if (type == "CustomPanelContainment") {
pc->setContainmentType(Plasma::CustomPanelContainment);
}
//fail? so it's a normal Applet
} else {
m_interface = new AppletInterface(this);

View File

@ -1,3 +1,3 @@
installPackage(testcontainment org.kde.testcontainment)
installPackage(testpanel org.kde.testpanel)
installPackage(testpanel org.kde.panel)

View File

@ -19,8 +19,8 @@ X-KDE-PluginInfo-Author=Marco Martin
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Email=mart@kde.org
X-KDE-PluginInfo-License=GPLv2+
X-KDE-PluginInfo-Name=org.kde.testpanel
X-KDE-PluginInfo-Name=org.kde.panel
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-Plasma-MainScript=ui/main.qml
X-Plasma-ContainmentType=PanelContainment
X-Plasma-ContainmentType=Panel

View File

@ -57,20 +57,12 @@ DesktopCorona::~DesktopCorona()
void DesktopCorona::loadDefaultLayout()
{
//TODO: use Javascript here
/*Plasma::Containment *cont = createContainment("org.kde.testcontainment");
cont->setScreen(0);
qDebug() << containmentForScreen(0);
Plasma::Applet *appl = cont->createApplet("org.kde.testapplet");
qDebug() << "Containment:" << cont << cont->title();
qDebug() << "Applet:" << appl->title() << appl;*/
WorkspaceScripting::DesktopScriptEngine scriptEngine(this, true);
connect(&scriptEngine, SIGNAL(printError(QString)), this, SLOT(printScriptError(QString)));
connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString)));
QString script = package().filePath("defaultlayout");
QFile file(script);
if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
QString code = file.readAll();
@ -224,7 +216,7 @@ void DesktopCorona::checkViews()
void DesktopCorona::updateScreenOwner(int wasScreen, int isScreen, Plasma::Containment *containment)
{
qDebug() << "Was screen" << wasScreen << "Is screen" << isScreen <<"Containment" << containment;
qDebug() << "Was screen" << wasScreen << "Is screen" << isScreen <<"Containment" << containment << containment->title();
if (containment->formFactor() == Plasma::Horizontal ||
containment->formFactor() == Plasma::Vertical) {

View File

@ -87,21 +87,27 @@ void Panel::setLocation(const QString &locationString)
const QString lower = locationString.toLower();
Plasma::Location loc = Plasma::Floating;
Plasma::FormFactor ff = Plasma::Planar;
if (lower == "desktop") {
loc = Plasma::Desktop;
} else if (lower == "fullscreen") {
loc = Plasma::FullScreen;
} else if (lower == "top") {
loc = Plasma::TopEdge;
ff = Plasma::Horizontal;
} else if (lower == "bottom") {
loc = Plasma::BottomEdge;
ff = Plasma::Horizontal;
} else if (lower == "left") {
loc = Plasma::LeftEdge;
ff = Plasma::Vertical;
} else if (lower == "right") {
loc = Plasma::RightEdge;
ff = Plasma::Vertical;
}
c->setLocation(loc);
c->setFormFactor(ff);
}
PanelView *Panel::panel() const

View File

@ -107,12 +107,13 @@ QScriptValue ScriptEngine::activityForScreen(QScriptContext *context, QScriptEng
QScriptValue ScriptEngine::newActivity(QScriptContext *context, QScriptEngine *engine)
{
return createContainment("desktop", "desktop", context, engine);
//FIXME: will be org.kde.desktop
return createContainment("Desktop", "org.kde.testcontainment", context, engine);
}
QScriptValue ScriptEngine::newPanel(QScriptContext *context, QScriptEngine *engine)
{
return createContainment("panel", "panel", context, engine);
return createContainment("Panel", "org.kde.panel", context, engine);
}
QScriptValue ScriptEngine::createContainment(const QString &type, const QString &defaultPlugin,
@ -138,14 +139,14 @@ QScriptValue ScriptEngine::createContainment(const QString &type, const QString
ScriptEngine *env = envFor(engine);
Plasma::Containment *c = env->m_corona->createContainment(plugin);
if (c) {
if (type == "panel") {
if (type == "Panel") {
// some defaults
c->setScreen(env->defaultPanelScreen());
c->setFormFactor(Plasma::Horizontal);
c->setLocation(Plasma::TopEdge);
c->setScreen(env->defaultPanelScreen());
}
c->updateConstraints(Plasma::AllConstraints | Plasma::StartupCompletedConstraint);
c->flushPendingConstraintsEvents();
emit env->createPendingPanelViews();
}
return env->wrap(c);
@ -574,7 +575,7 @@ void ScriptEngine::setupEngine()
m_scriptSelf.setProperty("QRectF", constructQRectFClass(this));
m_scriptSelf.setProperty("Activity", newFunction(ScriptEngine::newActivity));
m_scriptSelf.setProperty("Panel", newFunction(ScriptEngine::newPanel));
m_scriptSelf.setProperty("Panel", newFunction(ScriptEngine::newPanel, newObject()));
m_scriptSelf.setProperty("activities", newFunction(ScriptEngine::activities));
m_scriptSelf.setProperty("activityById", newFunction(ScriptEngine::activityById));
m_scriptSelf.setProperty("activityForScreen", newFunction(ScriptEngine::activityForScreen));

View File

@ -59,7 +59,6 @@ public:
Q_SIGNALS:
void print(const QString &string);
void printError(const QString &string);
void createPendingPanelViews();
private:
void setupEngine();

View File

@ -36,10 +36,10 @@ void ShellPackageStructure::initPackage(Plasma::Package *package)
package->setMimeTypes("views", QStringList() << "text/x-qml");
//Files
package->addFileDefinition("layout", "layout.js", i18n("Default layout file"));
package->addFileDefinition("defaultlayout", "layout.js", i18n("Default layout file"));
package->addFileDefinition("defaults", "defaults", i18n("Default plugins for containments, containmentActions etc"));
package->setMimeTypes("layout", QStringList() << "application/javascript");
package->setMimeTypes("defaultlayout", QStringList() << "application/javascript");
package->setMimeTypes("defaults", QStringList() << "text/plain");
package->addFileDefinition("appleterror", "components/AppletError.qml", i18n("Error message shown when an applet fails loading"));