From 11cba27eeefb99e0f8d4eff807a15b2d08fc0908 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 20 Jul 2007 03:21:40 +0000 Subject: [PATCH] * 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 --- package.cpp | 30 +++++++++++++++++++++++++++++- package.h | 7 +++++++ packagestructure.cpp | 37 +++++++++++++++++++++++++++++++++++++ packagestructure.h | 10 ++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) diff --git a/package.cpp b/package.cpp index 6ceeb2452..18b8308f7 100644 --- a/package.cpp +++ b/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) { 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); } diff --git a/package.h b/package.h index 983d77063..95225231c 100644 --- a/package.h +++ b/package.h @@ -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; }; diff --git a/packagestructure.cpp b/packagestructure.cpp index 4f9daf43e..209d6004f 100644 --- a/packagestructure.cpp +++ b/packagestructure.cpp @@ -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_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_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_iterator it = d->contents.constBegin(); diff --git a/packagestructure.h b/packagestructure.h index b17cfba7f..c535f94f8 100644 --- a/packagestructure.h +++ b/packagestructure.h @@ -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.