no longer provide access to the package from the class, let Package do that; adapt to Package merge

This commit is contained in:
Aaron Seigo 2011-07-15 12:59:51 +02:00
parent 976c668a13
commit 4b3b687088
3 changed files with 59 additions and 70 deletions

View File

@ -223,15 +223,6 @@ Applet::~Applet()
delete d; delete d;
} }
PackageStructure::Ptr Applet::packageStructure()
{
if (!AppletPrivate::packageStructure) {
AppletPrivate::packageStructure = new PlasmoidPackage();
}
return AppletPrivate::packageStructure;
}
void Applet::init() void Applet::init()
{ {
setFlag(ItemIsMovable, true); setFlag(ItemIsMovable, true);
@ -676,9 +667,9 @@ DataEngine *Applet::dataEngine(const QString &name) const
} }
} }
const Package *Applet::package() const Package Applet::package() const
{ {
return d->package; return d->package ? *d->package : Package();
} }
QGraphicsView *Applet::view() const QGraphicsView *Applet::view() const
@ -1654,7 +1645,7 @@ void Applet::publish(AnnouncementMethods methods, const QString &resourceName)
: resourceName; : resourceName;
kDebug() << "publishing package under name " << resName; kDebug() << "publishing package under name " << resName;
if (d->package && d->package->isValid()) { if (d->package && d->package->isValid()) {
d->service->d->publish(methods, resName, d->package->structure()->metadata()); d->service->d->publish(methods, resName, d->package->metadata());
} else if (!d->package && d->appletDescription.isValid()) { } else if (!d->package && d->appletDescription.isValid()) {
d->service->d->publish(methods, resName, d->appletDescription); d->service->d->publish(methods, resName, d->appletDescription);
} else { } else {
@ -2648,56 +2639,63 @@ void AppletPrivate::init(const QString &packagePath)
QString api = appletDescription.property("X-Plasma-API").toString(); QString api = appletDescription.property("X-Plasma-API").toString();
// we have a scripted plasmoid // we have a scripted plasmoid
if (!api.isEmpty()) { if (api.isEmpty()) {
// find where the Package is q->setFailedToLaunch(true, i18n("The %2 widget did not define which ScriptEngine to use.", appletDescription.name()));
QString path = packagePath; return;
if (path.isEmpty()) { }
QString subPath = q->packageStructure()->defaultPackageRoot() + '/' + appletDescription.pluginName() + '/';
path = KStandardDirs::locate("data", subPath + "metadata.desktop");
if (path.isEmpty()) {
path = KStandardDirs::locate("data", subPath);
} else {
path.remove(QString("metadata.desktop"));
}
} else if (!path.endsWith('/')) {
path.append('/');
}
package = new Package(Package::load("Plasma/Applet", api));
// find where the Package is
QString path = packagePath;
if (path.isEmpty()) {
QString subPath = package->defaultPackageRoot() + appletDescription.pluginName() + '/';
path = KStandardDirs::locate("data", subPath + "metadata.desktop");
if (path.isEmpty()) { if (path.isEmpty()) {
q->setFailedToLaunch( path = KStandardDirs::locate("data", subPath);
true,
i18nc("Package file, name of the widget",
"Could not locate the %1 package required for the %2 widget.",
appletDescription.pluginName(), appletDescription.name()));
} else { } else {
// create the package and see if we have something real path.remove(QString("metadata.desktop"));
//kDebug() << "trying for" << path;
PackageStructure::Ptr structure = Plasma::packageStructure(api, Plasma::AppletComponent);
structure->setPath(path);
package = new Package(path, structure);
if (package->isValid()) {
// now we try and set up the script engine.
// it will be parented to this applet and so will get
// deleted when the applet does
script = Plasma::loadScriptEngine(api, q);
if (!script) {
delete package;
package = 0;
q->setFailedToLaunch(true,
i18nc("API or programming language the widget was written in, name of the widget",
"Could not create a %1 ScriptEngine for the %2 widget.",
api, appletDescription.name()));
}
} else {
q->setFailedToLaunch(true, i18nc("Package file, name of the widget",
"Could not open the %1 package required for the %2 widget.",
appletDescription.pluginName(), appletDescription.name()));
delete package;
package = 0;
}
} }
} else if (!path.endsWith('/')) {
path.append('/');
}
if (path.isEmpty()) {
delete package;
package = 0;
q->setFailedToLaunch(true,
i18nc("Package file, name of the widget",
"Could not locate the %1 package required for the %2 widget.",
appletDescription.pluginName(), appletDescription.name()));
return;
}
package->setPath(path);
if (!package->isValid()) {
delete package;
package = 0;
q->setFailedToLaunch(true, i18nc("Package file, name of the widget",
"Could not open the %1 package required for the %2 widget.",
appletDescription.pluginName(), appletDescription.name()));
return;
}
// create the package and see if we have something real
//kDebug() << "trying for" << path;
// now we try and set up the script engine.
// it will be parented to this applet and so will get
// deleted when the applet does
script = Plasma::loadScriptEngine(api, q);
if (!script) {
delete package;
package = 0;
q->setFailedToLaunch(true,
i18nc("API or programming language the widget was written in, name of the widget",
"Could not create a %1 ScriptEngine for the %2 widget.",
api, appletDescription.name()));
} }
} }
@ -2710,7 +2708,6 @@ void AppletPrivate::setupScriptSupport()
} }
kDebug() << "setting up script support, package is in" << package->path() kDebug() << "setting up script support, package is in" << package->path()
<< "which is a" << package->structure()->type() << "package"
<< ", main script is" << package->filePath("mainscript"); << ", main script is" << package->filePath("mainscript");
const QString translationsPath = package->filePath("translations"); const QString translationsPath = package->filePath("translations");
@ -2829,9 +2826,9 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
if (newGroup) { if (newGroup) {
//see if we have a default configuration in our package //see if we have a default configuration in our package
const QString defaultConfigFile = q->package()->filePath("defaultconfig"); const QString defaultConfigFile = package->filePath("defaultconfig");
if (!defaultConfigFile.isEmpty()) { if (!defaultConfigFile.isEmpty()) {
kDebug() << "copying default config: " << q->package()->filePath("defaultconfig"); kDebug() << "copying default config: " << package->filePath("defaultconfig");
KConfigGroup defaultConfig(KSharedConfig::openConfig(defaultConfigFile)->group("Configuration")); KConfigGroup defaultConfig(KSharedConfig::openConfig(defaultConfigFile)->group("Configuration"));
defaultConfig.copyTo(mainConfig); defaultConfig.copyTo(mainConfig);
} }
@ -2905,7 +2902,6 @@ void ContainmentPrivate::checkRemoveAction()
uint AppletPrivate::s_maxAppletId = 0; uint AppletPrivate::s_maxAppletId = 0;
int AppletPrivate::s_maxZValue = 0; int AppletPrivate::s_maxZValue = 0;
int AppletPrivate::s_minZValue = 0; int AppletPrivate::s_minZValue = 0;
PackageStructure::Ptr AppletPrivate::packageStructure(0);
QSet<QString> AppletPrivate::s_customCategories; QSet<QString> AppletPrivate::s_customCategories;
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent) AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)

View File

@ -32,7 +32,6 @@
#include <kshortcut.h> #include <kshortcut.h>
#include <plasma/configloader.h> #include <plasma/configloader.h>
#include <plasma/packagestructure.h>
#include <plasma/plasma.h> #include <plasma/plasma.h>
#include <plasma/animator.h> #include <plasma/animator.h>
#include <plasma/version.h> #include <plasma/version.h>
@ -96,11 +95,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
~Applet(); ~Applet();
/**
* @return a package structure representing an Applet
*/
static PackageStructure::Ptr packageStructure();
/** /**
* @return the id of this applet * @return the id of this applet
*/ */
@ -188,7 +182,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
* *
* @return the Package object, or 0 if none * @return the Package object, or 0 if none
**/ **/
const Package *package() const; Package package() const;
/** /**
* Returns the view this widget is visible on, or 0 if none can be found. * Returns the view this widget is visible on, or 0 if none can be found.

View File

@ -145,7 +145,6 @@ public:
static uint s_maxAppletId; static uint s_maxAppletId;
static int s_maxZValue; static int s_maxZValue;
static int s_minZValue; static int s_minZValue;
static PackageStructure::Ptr packageStructure;
static QSet<QString> s_customCategories; static QSet<QString> s_customCategories;
//TODO: examine the usage of memory here; there's a pretty large //TODO: examine the usage of memory here; there's a pretty large