set directly the fallback package not its path

This commit is contained in:
Marco Martin 2014-09-01 14:54:10 +02:00
parent aba4dcb915
commit 21cf68dbd2
3 changed files with 14 additions and 38 deletions

View File

@ -189,19 +189,24 @@ void Package::setDefaultPackageRoot(const QString &packageRoot)
} }
} }
void Package::setFallbackPackagePath(const QString &path) void Package::setFallbackPackage(const Plasma::Package &package)
{ {
if (d->fallbackPackagePath == path) { if ((d->fallbackPackage && d->fallbackPackage->path() == package.path() && d->fallbackPackage->metadata() == package.metadata()) ||
//can't be fallback of itself
(package.path() == path() && package.metadata() == metadata())) {
return; return;
} }
d->fallbackPackagePath = path; (*d->fallbackPackage) = package;
d->updateFallbackPackage();
} }
QString Package::fallbackPackagePath() const Plasma::Package Package::fallbackPackage() const
{ {
return d->fallbackPackagePath; if (d->fallbackPackage) {
return (*d->fallbackPackage);
} else {
return Package();
}
} }
QString Package::servicePrefix() const QString Package::servicePrefix() const
@ -527,8 +532,6 @@ void Package::setPath(const QString &path)
QString fallback; QString fallback;
d->updateFallbackPackage();
// uh-oh, but we didn't end up with anything valid, so we sadly reset ourselves // uh-oh, but we didn't end up with anything valid, so we sadly reset ourselves
// to futility. // to futility.
if (!d->valid) { if (!d->valid) {
@ -808,31 +811,6 @@ PackagePrivate::~PackagePrivate()
delete fallbackPackage; delete fallbackPackage;
} }
void PackagePrivate::updateFallbackPackage()
{
if (!fallbackPackagePath.isEmpty() && fallbackPackagePath != path) {
if (!fallbackPackage) {
fallbackPackage = new Package(structure.data());
}
fallbackPackage->setPath(fallbackPackagePath);
Plasma::Package *pkg = fallbackPackage;
int depth = 0;
while (pkg->d->fallbackPackage) {
//cycle or too deep?
if (depth > 10 || (metadata && metadata->isValid() && pkg->d->fallbackPackage->metadata().pluginName() == metadata->pluginName())) {
delete pkg->d->fallbackPackage;
pkg->d->fallbackPackage = 0;
break;
}
pkg = pkg->d->fallbackPackage;
++depth;
}
} else {
delete fallbackPackage;
fallbackPackage = 0;
}
}
PackagePrivate &PackagePrivate::operator=(const PackagePrivate &rhs) PackagePrivate &PackagePrivate::operator=(const PackagePrivate &rhs)
{ {
if (&rhs == this) { if (&rhs == this) {
@ -840,7 +818,7 @@ PackagePrivate &PackagePrivate::operator=(const PackagePrivate &rhs)
} }
structure = rhs.structure; structure = rhs.structure;
fallbackPackage = rhs.fallbackPackage; (*fallbackPackage) = (*rhs.fallbackPackage);
path = rhs.path; path = rhs.path;
contentsPrefixPaths = rhs.contentsPrefixPaths; contentsPrefixPaths = rhs.contentsPrefixPaths;
servicePrefix = rhs.servicePrefix; servicePrefix = rhs.servicePrefix;

View File

@ -297,12 +297,12 @@ public:
* It is intended to be used by the packageStructure * It is intended to be used by the packageStructure
* @param path package root path @see setPath * @param path package root path @see setPath
*/ */
void setFallbackPackagePath(const QString &path); void setFallbackPackage(const Plasma::Package &package);
/** /**
* @return The fallback package root path * @return The fallback package root path
*/ */
QString fallbackPackagePath() const; Plasma::Package fallbackPackage() const;
// Content structure description methods // Content structure description methods
/** /**

View File

@ -74,7 +74,6 @@ public:
QString unpack(const QString &filePath); QString unpack(const QString &filePath);
void updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash); void updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCryptographicHash &hash);
QString fallbackFilePath(const char *key, const QString &filename = QString()) const; QString fallbackFilePath(const char *key, const QString &filename = QString()) const;
void updateFallbackPackage();
QWeakPointer<PackageStructure> structure; QWeakPointer<PackageStructure> structure;
QString path; QString path;
@ -84,7 +83,6 @@ public:
QString servicePrefix; QString servicePrefix;
QHash<QString, QString> discoveries; QHash<QString, QString> discoveries;
QHash<QByteArray, ContentStructure> contents; QHash<QByteArray, ContentStructure> contents;
QString fallbackPackagePath;
Package *fallbackPackage; Package *fallbackPackage;
#ifndef PLASMA_NO_PACKAGE_EXTRADATA #ifndef PLASMA_NO_PACKAGE_EXTRADATA
QStringList mimeTypes; QStringList mimeTypes;