introduce setFallbackPackagePath
the fallback package would then be decided by the packagestructure
This commit is contained in:
parent
5b9bb128d8
commit
aba4dcb915
@ -189,6 +189,21 @@ void Package::setDefaultPackageRoot(const QString &packageRoot)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Package::setFallbackPackagePath(const QString &path)
|
||||||
|
{
|
||||||
|
if (d->fallbackPackagePath == path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->fallbackPackagePath = path;
|
||||||
|
d->updateFallbackPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Package::fallbackPackagePath() const
|
||||||
|
{
|
||||||
|
return d->fallbackPackagePath;
|
||||||
|
}
|
||||||
|
|
||||||
QString Package::servicePrefix() const
|
QString Package::servicePrefix() const
|
||||||
{
|
{
|
||||||
return d->servicePrefix;
|
return d->servicePrefix;
|
||||||
@ -512,33 +527,7 @@ void Package::setPath(const QString &path)
|
|||||||
|
|
||||||
QString fallback;
|
QString fallback;
|
||||||
|
|
||||||
if (metadata().isValid()) {
|
d->updateFallbackPackage();
|
||||||
fallback = metadata().property("X-KDE-fallbackPackage").toString();
|
|
||||||
if (fallback == metadata().pluginName()) {
|
|
||||||
fallback = QString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!fallback.isEmpty()) {
|
|
||||||
if (!d->fallbackPackage) {
|
|
||||||
d->fallbackPackage = new Package(d->structure.data());
|
|
||||||
}
|
|
||||||
d->fallbackPackage->setPath(fallback);
|
|
||||||
Plasma::Package *pkg = d->fallbackPackage;
|
|
||||||
int depth = 0;
|
|
||||||
while (pkg->d->fallbackPackage) {
|
|
||||||
//cycle or too deep?
|
|
||||||
if (depth > 10 || pkg->d->fallbackPackage->metadata().pluginName() == metadata().pluginName()) {
|
|
||||||
delete pkg->d->fallbackPackage;
|
|
||||||
pkg->d->fallbackPackage = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pkg = pkg->d->fallbackPackage;
|
|
||||||
++depth;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete d->fallbackPackage;
|
|
||||||
d->fallbackPackage = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
@ -819,6 +808,31 @@ 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) {
|
||||||
@ -909,7 +923,7 @@ void PackagePrivate::createPackageMetadata(const QString &path)
|
|||||||
QString PackagePrivate::fallbackFilePath(const char *key, const QString &filename) const
|
QString PackagePrivate::fallbackFilePath(const char *key, const QString &filename) const
|
||||||
{
|
{
|
||||||
//don't fallback if the package isn't valid and never fallback the metadata file
|
//don't fallback if the package isn't valid and never fallback the metadata file
|
||||||
if (fallbackPackage && fallbackPackage->isValid() && key != "metadata") {
|
if (fallbackPackage && fallbackPackage->isValid() && strcmp(key, "metadata") != 0) {
|
||||||
return fallbackPackage->filePath(key, filename);
|
return fallbackPackage->filePath(key, filename);
|
||||||
} else {
|
} else {
|
||||||
return QString();
|
return QString();
|
||||||
|
@ -290,6 +290,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setDefaultPackageRoot(const QString &packageRoot);
|
void setDefaultPackageRoot(const QString &packageRoot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the fallback package root path
|
||||||
|
* If a file won't be found in this package, it will search it in the package
|
||||||
|
* with the same structure identified by path
|
||||||
|
* It is intended to be used by the packageStructure
|
||||||
|
* @param path package root path @see setPath
|
||||||
|
*/
|
||||||
|
void setFallbackPackagePath(const QString &path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The fallback package root path
|
||||||
|
*/
|
||||||
|
QString fallbackPackagePath() const;
|
||||||
|
|
||||||
// Content structure description methods
|
// Content structure description methods
|
||||||
/**
|
/**
|
||||||
* @return all directories registered as part of this Package's structure
|
* @return all directories registered as part of this Package's structure
|
||||||
@ -328,6 +342,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QExplicitlySharedDataPointer<PackagePrivate> d;
|
QExplicitlySharedDataPointer<PackagePrivate> d;
|
||||||
|
friend class PackagePrivate;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@ 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;
|
||||||
@ -83,6 +84,7 @@ 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user