make Package::setPath a bit more like the version now in libplasma1
This commit is contained in:
parent
d6f0502960
commit
151311f9b9
@ -75,10 +75,12 @@ Package &Package::operator=(const Package &rhs)
|
|||||||
|
|
||||||
bool Package::isValid() const
|
bool Package::isValid() const
|
||||||
{
|
{
|
||||||
if (!d->valid) {
|
if (d->checkedValid) {
|
||||||
return false;
|
return d->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->valid = false;
|
||||||
|
|
||||||
//search for the file in all prefixes and in all possible paths for each prefix
|
//search for the file in all prefixes and in all possible paths for each prefix
|
||||||
//even if it's a big nested loop, usually there is one prefix and one location
|
//even if it's a big nested loop, usually there is one prefix and one location
|
||||||
//so shouldn't cause too much disk access
|
//so shouldn't cause too much disk access
|
||||||
@ -97,6 +99,7 @@ bool Package::isValid() const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -105,11 +108,11 @@ bool Package::isValid() const
|
|||||||
if (failed) {
|
if (failed) {
|
||||||
kWarning() << "Could not find required" << (it.value().directory ? "directory" : "file") << it.key();
|
kWarning() << "Could not find required" << (it.value().directory ? "directory" : "file") << it.key();
|
||||||
d->valid = false;
|
d->valid = false;
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return d->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Package::name(const char *key) const
|
QString Package::name(const char *key) const
|
||||||
@ -388,54 +391,49 @@ void Package::setPath(const QString &path)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir dir(path);
|
QStringList paths;
|
||||||
if (dir.isRelative()) {
|
if (QDir::isRelativePath(path)) {
|
||||||
QString location;
|
QString p;
|
||||||
//kDebug() <<
|
|
||||||
if (!d->defaultPackageRoot.isEmpty()) {
|
if (!d->defaultPackageRoot.isEmpty()) {
|
||||||
dir.setPath(d->defaultPackageRoot);
|
p = path % "/";
|
||||||
if (dir.isRelative()) {
|
} else {
|
||||||
location = QStandardPaths::locate(QStandardPaths::GenericDataLocation, d->defaultPackageRoot + path, QStandardPaths::LocateDirectory);
|
p = d->defaultPackageRoot % "/" % path % "/";
|
||||||
} else {
|
}
|
||||||
location = d->defaultPackageRoot + path;
|
|
||||||
|
if (QDir::isRelativePath(p)) {
|
||||||
|
paths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, path, QStandardPaths::LocateDirectory);
|
||||||
|
} else {
|
||||||
|
const QDir dir(p);
|
||||||
|
if (QFile::exists(dir.canonicalPath())) {
|
||||||
|
paths << p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (location.isEmpty()) {
|
|
||||||
location = QStandardPaths::locate(QStandardPaths::GenericDataLocation, path, QStandardPaths::LocateDirectory);
|
|
||||||
|
|
||||||
if (location.isEmpty()) {
|
|
||||||
d->path.clear();
|
|
||||||
d->valid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dir.setPath(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString basePath = dir.canonicalPath();
|
|
||||||
bool valid = QFile::exists(basePath);
|
|
||||||
|
|
||||||
if (valid) {
|
|
||||||
QFileInfo info(basePath);
|
|
||||||
if (info.isDir() && !basePath.endsWith('/')) {
|
|
||||||
basePath.append('/');
|
|
||||||
}
|
|
||||||
kDebug() << "basePath is" << basePath;
|
|
||||||
} else {
|
} else {
|
||||||
#ifndef NDEBUG
|
const QDir dir(path);
|
||||||
kDebug() << path << "invalid, basePath is" << basePath;
|
if (QFile::exists(dir.canonicalPath())) {
|
||||||
#endif
|
paths << path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString previousPath = d->path;
|
||||||
|
foreach (const QString &p, paths) {
|
||||||
|
d->checkedValid = false;
|
||||||
|
d->path = p;
|
||||||
|
if (!d->path.endsWith('/')) {
|
||||||
|
d->path.append('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValid()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d->path == previousPath) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->path == basePath) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
d->path = basePath;
|
|
||||||
delete d->metadata;
|
delete d->metadata;
|
||||||
d->metadata = 0;
|
d->metadata = 0;
|
||||||
d->valid = !d->path.isEmpty();
|
|
||||||
|
|
||||||
if (d->structure) {
|
if (d->structure) {
|
||||||
d->structure.data()->pathChanged(this);
|
d->structure.data()->pathChanged(this);
|
||||||
@ -671,7 +669,8 @@ PackagePrivate::PackagePrivate()
|
|||||||
servicePrefix("plasma-applet-"),
|
servicePrefix("plasma-applet-"),
|
||||||
metadata(0),
|
metadata(0),
|
||||||
externalPaths(false),
|
externalPaths(false),
|
||||||
valid(false)
|
valid(false),
|
||||||
|
checkedValid(false)
|
||||||
{
|
{
|
||||||
contentsPrefixPaths << "contents/";
|
contentsPrefixPaths << "contents/";
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,7 @@ public:
|
|||||||
KPluginInfo *metadata;
|
KPluginInfo *metadata;
|
||||||
bool externalPaths : 1;
|
bool externalPaths : 1;
|
||||||
bool valid : 1;
|
bool valid : 1;
|
||||||
|
bool checkedValid : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user