* dissallow copying of PackageStructure as it has a dptr but no copy ctor
* Package::isValid() checks if the Package is valid, e.g. all required files and dirs are present * add methods to PackageStructure which return just the required bits svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=690102
This commit is contained in:
parent
0e193f1924
commit
11cba27eee
30
package.cpp
30
package.cpp
@ -62,6 +62,29 @@ Package::~Package()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Package::isValid()
|
||||||
|
{
|
||||||
|
if (!d->valid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const QString& dir, d->structure.requiredDirectories()) {
|
||||||
|
if (QFile::exists(d->basePath + "/" + dir)) {
|
||||||
|
d->valid = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (const QString& file, d->structure.requiredFiles()) {
|
||||||
|
if (QFile::exists(d->basePath + "/" + file)) {
|
||||||
|
d->valid = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString Package::filePath(const char* fileType, const QString& filename)
|
QString Package::filePath(const char* fileType, const QString& filename)
|
||||||
{
|
{
|
||||||
if (!d->valid) {
|
if (!d->valid) {
|
||||||
@ -69,7 +92,12 @@ QString Package::filePath(const char* fileType, const QString& filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString path = d->structure.path(fileType);
|
QString path = d->structure.path(fileType);
|
||||||
if (!path.isEmpty() && !filename.isEmpty()) {
|
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
path.prepend(d->basePath);
|
path.prepend(d->basePath);
|
||||||
path.append("/").append(filename);
|
path.append("/").append(filename);
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,12 @@ class PLASMA_EXPORT Package
|
|||||||
const PackageStructure& structure);
|
const PackageStructure& structure);
|
||||||
~Package();
|
~Package();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if all the required components as defined in
|
||||||
|
* the PackageStructure exist
|
||||||
|
**/
|
||||||
|
bool isValid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the path to a given file.
|
* Get the path to a given file.
|
||||||
*
|
*
|
||||||
@ -94,6 +100,7 @@ class PLASMA_EXPORT Package
|
|||||||
static bool installPackage(const QString& package, const QString& packageRoot);
|
static bool installPackage(const QString& package, const QString& packageRoot);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Q_DISABLE_COPY(Package)
|
||||||
class Private;
|
class Private;
|
||||||
Private * const d;
|
Private * const d;
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,15 @@ class ContentStructure
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContentStructure(const ContentStructure& other)
|
||||||
|
{
|
||||||
|
path = other.path;
|
||||||
|
name = other.name;
|
||||||
|
mimetypes = other.mimetypes;
|
||||||
|
directory = other.directory;
|
||||||
|
required = other.required;
|
||||||
|
}
|
||||||
|
|
||||||
QString path;
|
QString path;
|
||||||
QString name;
|
QString name;
|
||||||
QStringList mimetypes;
|
QStringList mimetypes;
|
||||||
@ -93,7 +102,35 @@ QStringList PackageStructure::directories()
|
|||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList PackageStructure::requiredDirectories()
|
||||||
|
{
|
||||||
|
QStringList dirs;
|
||||||
|
QHash<const char*, ContentStructure>::const_iterator it = d->contents.constBegin();
|
||||||
|
while (it != d->contents.constEnd()) {
|
||||||
|
if (it.value().directory &&
|
||||||
|
it.value().required) {
|
||||||
|
dirs << it.value().path;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
return dirs;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList PackageStructure::files()
|
QStringList PackageStructure::files()
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
QHash<const char*, ContentStructure>::const_iterator it = d->contents.constBegin();
|
||||||
|
while (it != d->contents.constEnd()) {
|
||||||
|
if (!it.value().directory &&
|
||||||
|
it.value().required) {
|
||||||
|
files << it.value().path;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList PackageStructure::requiredFiles()
|
||||||
{
|
{
|
||||||
QStringList files;
|
QStringList files;
|
||||||
QHash<const char*, ContentStructure>::const_iterator it = d->contents.constBegin();
|
QHash<const char*, ContentStructure>::const_iterator it = d->contents.constBegin();
|
||||||
|
@ -77,11 +77,21 @@ public:
|
|||||||
**/
|
**/
|
||||||
QStringList directories();
|
QStringList directories();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The required directories defined for this package
|
||||||
|
**/
|
||||||
|
QStringList requiredDirectories();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The individual files defined for this package
|
* The individual files defined for this package
|
||||||
**/
|
**/
|
||||||
QStringList files();
|
QStringList files();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The individual required files defined for this package
|
||||||
|
**/
|
||||||
|
QStringList requiredFiles();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directory to the structure of the package. It is added as
|
* Adds a directory to the structure of the package. It is added as
|
||||||
* a not-required element with no associated mimetypes.
|
* a not-required element with no associated mimetypes.
|
||||||
|
Loading…
Reference in New Issue
Block a user