* 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:
Aaron J. Seigo 2007-07-20 03:21:40 +00:00
parent 0e193f1924
commit 11cba27eee
4 changed files with 83 additions and 1 deletions

View File

@ -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)
{
if (!d->valid) {
@ -69,7 +92,12 @@ QString Package::filePath(const char* fileType, const QString& filename)
}
QString path = d->structure.path(fileType);
if (!path.isEmpty() && !filename.isEmpty()) {
if (path.isEmpty()) {
return QString();
}
if (!filename.isEmpty()) {
path.prepend(d->basePath);
path.append("/").append(filename);
}

View File

@ -47,6 +47,12 @@ class PLASMA_EXPORT Package
const PackageStructure& structure);
~Package();
/**
* @return true if all the required components as defined in
* the PackageStructure exist
**/
bool isValid();
/**
* Get the path to a given file.
*
@ -94,6 +100,7 @@ class PLASMA_EXPORT Package
static bool installPackage(const QString& package, const QString& packageRoot);
private:
Q_DISABLE_COPY(Package)
class Private;
Private * const d;
};

View File

@ -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 name;
QStringList mimetypes;
@ -93,7 +102,35 @@ QStringList PackageStructure::directories()
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 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;
QHash<const char*, ContentStructure>::const_iterator it = d->contents.constBegin();

View File

@ -77,11 +77,21 @@ public:
**/
QStringList directories();
/**
* The required directories defined for this package
**/
QStringList requiredDirectories();
/**
* The individual files defined for this package
**/
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
* a not-required element with no associated mimetypes.