port Package usage

This commit is contained in:
Marco Martin 2014-02-26 12:38:45 +01:00
parent 0612ae0402
commit 462b2cc836
8 changed files with 35 additions and 90 deletions

View File

@ -28,7 +28,7 @@ set(scripting_SRC
scripting/configgroup.cpp
scripting/desktopscriptengine.cpp
scripting/i18n.cpp
scripting/layouttemplatepackagestructure.cpp
#scripting/layouttemplatepackagestructure.cpp
scripting/panel.cpp
scripting/rect.cpp
scripting/scriptengine.cpp

View File

@ -51,7 +51,8 @@
#include <Plasma/Package>
#include "scripting/desktopscriptengine.h"
#include "scripting/layouttemplatepackagestructure.h"
#include "packages.h"
#include "shellpluginloader.h"
//TODO:
// use text editor KPart for syntax highlighting?
@ -353,35 +354,38 @@ void InteractiveConsole::populateTemplatesMenu()
sorted.insert(service->name(), service);
}
/*QMapIterator<QString, KService::Ptr> it(sorted);
Plasma::PackageStructure::Ptr templateStructure(new WorkspaceScripting::LayoutTemplatePackageStructure);
QMapIterator<QString, KService::Ptr> it(sorted);
Plasma::Package package = ShellPluginLoader::self()->loadPackage("Plasma/LayoutTemplate");
while (it.hasNext()) {
it.next();
KPluginInfo info(it.value());
const QString path = KStandardDirs::locate("data", templateStructure->defaultPackageRoot() + '/' + info.pluginName() + '/');
const QString path = KStandardDirs::locate("data", package.defaultPackageRoot() + '/' + info.pluginName() + '/');
if (!path.isEmpty()) {
Plasma::Package package(path, templateStructure);
package.setPath(info.pluginName());
const QString scriptFile = package.filePath("mainscript");
if (!scriptFile.isEmpty()) {
QAction *action = m_snippetsMenu->addAction(info.name());
action->setData(info.pluginName());
}
}
}*/
}
}
void InteractiveConsole::loadTemplate(QAction *action)
{
/*Plasma::PackageStructure::Ptr templateStructure(new WorkspaceScripting::LayoutTemplatePackageStructure);
Plasma::Package package = ShellPluginLoader::self()->loadPackage("Plasma/LayoutTemplate");
const QString pluginName = action->data().toString();
const QString path = KStandardDirs::locate("data", templateStructure->defaultPackageRoot() + '/' + pluginName + '/');
const QString path = KStandardDirs::locate("data", package.defaultPackageRoot() + '/' + pluginName + '/');
if (!path.isEmpty()) {
Plasma::Package package(path, templateStructure);
package.setPath(pluginName);
const QString scriptFile = package.filePath("mainscript");
if (!scriptFile.isEmpty()) {
loadScriptFromUrl(QUrl::fromLocalFile(scriptFile));
}
}*/
}
}
void InteractiveConsole::useTemplate(QAction *action)

View File

@ -124,3 +124,11 @@ void QmlWallpaperPackage::initPackage(Plasma::Package *package)
package->addDirectoryDefinition("translations", "locale", i18n("Translations"));
}
void LayoutTemplatePackage::initPackage(Plasma::Package *package)
{
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

@ -39,4 +39,11 @@ public:
void initPackage(Plasma::Package *package);
};
class LayoutTemplatePackage : public Plasma::PackageStructure
{
public:
void initPackage(Plasma::Package *package);
};
#endif // LOOKANDFEELPACKAGE_H

View File

@ -1,38 +0,0 @@
/*
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
*
* 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.
*/
#include "layouttemplatepackagestructure.h"
#include <klocalizedstring.h>
namespace WorkspaceScripting
{
void LayoutTemplatePackageStructure::initPackage(Plasma::Package *package)
{
package->setServicePrefix("plasma-layout-template");
package->setDefaultPackageRoot("plasma/layout-templates");
package->addFileDefinition("mainscript", "layout.js", i18n("Main Script File"));
package->setRequired("mainscript", true);
}
}
#include "layouttemplatepackagestructure.moc"

View File

@ -1,39 +0,0 @@
/*
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
*
* 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.
*/
#ifndef TEMPLATETEMPLATEPACKAGE_H
#define TEMPLATETEMPLATEPACKAGE_H
#include <Plasma/PackageStructure>
namespace WorkspaceScripting
{
class LayoutTemplatePackageStructure : public Plasma::PackageStructure
{
Q_OBJECT
public:
void initPackage(Plasma::Package *package);
};
}
#endif

View File

@ -48,7 +48,7 @@
#include "containment.h"
#include "configgroup.h"
#include "i18n.h"
#include "layouttemplatepackagestructure.h"
#include "packages.h"
#include "widget.h"
QScriptValue constructQRectFClass(QScriptEngine *engine);
@ -269,7 +269,7 @@ QScriptValue ScriptEngine::loadTemplate(QScriptContext *context, QScriptEngine *
return false;
}
LayoutTemplatePackageStructure structure;
LayoutTemplatePackage structure;
Plasma::Package package(&structure);
KPluginInfo info(offers.first());
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, package.defaultPackageRoot() + '/' + info.pluginName() + '/');

View File

@ -43,6 +43,9 @@ Plasma::Package ShellPluginLoader::internalLoadPackage(const QString &packageFor
} else if (packageFormat == "Plasma/Wallpaper") {
Plasma::PackageStructure *structure = new QmlWallpaperPackage();
return Plasma::Package(structure);
} else if (packageFormat == "Plasma/LayoutTemplate") {
Plasma::PackageStructure *structure = new LayoutTemplatePackage();
return Plasma::Package(structure);
} else {
return Plasma::Package();
}