From 433bb098dd76c08af7fdd9f1b5da9bec31f793e3 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 3 Nov 2010 22:11:28 +0000 Subject: [PATCH] FEATURE: allow entire search paths for a given key, as seen on RB#5763 svn path=/trunk/KDE/kdelibs/; revision=1192747 --- packagestructure.cpp | 51 ++++++++++++++++++++++++++++++++++++-------- packagestructure.h | 20 +++++++++++++++++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/packagestructure.cpp b/packagestructure.cpp index 7c5d44d0e..a65ab137c 100644 --- a/packagestructure.cpp +++ b/packagestructure.cpp @@ -56,14 +56,14 @@ class ContentStructure ContentStructure(const ContentStructure &other) { - path = other.path; + paths = other.paths; name = other.name; mimetypes = other.mimetypes; directory = other.directory; required = other.required; } - QString path; + QStringList paths; QString name; QStringList mimetypes; bool directory : 1; @@ -304,8 +304,16 @@ void PackageStructure::addDirectoryDefinition(const char *key, const QString &path, const QString &name) { ContentStructure s; - s.name = name; - s.path = path; + + if (d->contents.contains(key)) { + s = d->contents[key]; + } + + if (!name.isEmpty()) { + s.name = name; + } + + s.paths.append(path); s.directory = true; d->contents[key] = s; @@ -314,13 +322,26 @@ void PackageStructure::addDirectoryDefinition(const char *key, void PackageStructure::addFileDefinition(const char *key, const QString &path, const QString &name) { ContentStructure s; - s.name = name; - s.path = path; + + if (d->contents.contains(key)) { + s = d->contents[key]; + } + + if (!name.isEmpty()) { + s.name = name; + } + + s.paths.append(path); s.directory = false; d->contents[key] = s; } +void PackageStructure::removeDefinition(const char *key) +{ + d->contents.remove(key); +} + QString PackageStructure::path(const char *key) const { //kDebug() << "looking for" << key; @@ -329,8 +350,20 @@ QString PackageStructure::path(const char *key) const return QString(); } - //kDebug() << "found" << key << "and the value is" << it.value().path; - return it.value().path; + //kDebug() << "found" << key << "and the value is" << it.value().paths.first(); + return it.value().paths.first(); +} + +QStringList PackageStructure::searchPath(const char *key) const +{ + //kDebug() << "looking for" << key; + QMap::const_iterator it = d->contents.constFind(key); + if (it == d->contents.constEnd()) { + return QStringList(); + } + + //kDebug() << "found" << key << "and the value is" << it.value().paths; + return it.value().paths; } QString PackageStructure::name(const char *key) const @@ -473,7 +506,7 @@ void PackageStructure::write(KConfigBase *config) const QMap::const_iterator it = d->contents.constBegin(); while (it != d->contents.constEnd()) { KConfigGroup group = config->group(it.key()); - group.writeEntry("Path", it.value().path); + group.writeEntry("Path", it.value().paths); group.writeEntry("Name", it.value().name); if (!it.value().mimetypes.isEmpty()) { group.writeEntry("Mimetypes", it.value().mimetypes); diff --git a/packagestructure.h b/packagestructure.h index 63232813e..7519a5852 100644 --- a/packagestructure.h +++ b/packagestructure.h @@ -133,6 +133,9 @@ public: * Adds a directory to the structure of the package. It is added as * a not-required element with no associated mimetypes. * + * Starting in 4.6, if an entry with the given key + * already exists, the path is added to it as a search alternative. + * * @param key used as an internal label for this directory * @param path the path within the package for this directory * @param name the user visible (translated) name for the directory @@ -143,17 +146,34 @@ public: * Adds a file to the structure of the package. It is added as * a not-required element with no associated mimetypes. * + * Starting in 4.6, if an entry with the given key + * already exists, the path is added to it as a search alternative. + * * @param key used as an internal label for this file * @param path the path within the package for this file * @param name the user visible (translated) name for the file **/ void addFileDefinition(const char *key, const QString &path, const QString &name); + /** + * Removes a definition from the structure of the package. + * @since 4.6 + * @param key the internal label of the file or directory to remove + */ + void removeDefinition(const char *key); + /** * @return path relative to the package root for the given entry + * @deprecatd use searchPaths instead **/ QString path(const char *key) const; + /** + * @return a list of paths relative to the package root for the given entry + * @since 4.6 + **/ + QStringList searchPath(const char *key) const; + /** * Get the list of files of a given type. *