2007-06-17 02:25:16 +02:00
|
|
|
/******************************************************************************
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
|
2007-06-17 02:25:16 +02:00
|
|
|
* *
|
|
|
|
* This library is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Library General Public *
|
|
|
|
* License as published by the Free Software Foundation; either *
|
|
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This library is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
|
|
* Library General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Library General Public License *
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to *
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
|
|
|
* Boston, MA 02110-1301, USA. *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include "packagestructure.h"
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
#include <QMap>
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class ContentStructure
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ContentStructure()
|
|
|
|
: directory(false),
|
|
|
|
required(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-20 05:21:40 +02:00
|
|
|
ContentStructure(const ContentStructure& other)
|
|
|
|
{
|
|
|
|
path = other.path;
|
|
|
|
name = other.name;
|
|
|
|
mimetypes = other.mimetypes;
|
|
|
|
directory = other.directory;
|
|
|
|
required = other.required;
|
|
|
|
}
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
QString path;
|
|
|
|
QString name;
|
|
|
|
QStringList mimetypes;
|
|
|
|
bool directory;
|
|
|
|
bool required;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PackageStructure::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString type;
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure> contents;
|
2007-06-17 03:04:59 +02:00
|
|
|
QStringList mimetypes;
|
2007-06-17 02:25:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
PackageStructure::PackageStructure(const QString &type)
|
|
|
|
: d(new Private)
|
|
|
|
{
|
|
|
|
d->type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageStructure::PackageStructure(const PackageStructure& rhs)
|
|
|
|
: d(new Private)
|
|
|
|
{
|
|
|
|
*d = *rhs.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageStructure::~PackageStructure()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageStructure& PackageStructure::operator=(const PackageStructure& rhs)
|
|
|
|
{
|
|
|
|
if (this == &rhs) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
*d = *rhs.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QString PackageStructure::type() const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
return d->type;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> PackageStructure::directories() const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2007-10-22 03:28:48 +02:00
|
|
|
QList<const char*> dirs;
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
|
2007-06-17 02:25:16 +02:00
|
|
|
while (it != d->contents.constEnd()) {
|
|
|
|
if (it.value().directory) {
|
2007-11-26 20:16:40 +01:00
|
|
|
dirs << it.key().constData();
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
return dirs;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> PackageStructure::requiredDirectories() const
|
2007-07-20 05:21:40 +02:00
|
|
|
{
|
2007-10-22 03:28:48 +02:00
|
|
|
QList<const char*> dirs;
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
|
2007-07-20 05:21:40 +02:00
|
|
|
while (it != d->contents.constEnd()) {
|
|
|
|
if (it.value().directory &&
|
|
|
|
it.value().required) {
|
2007-10-22 03:28:48 +02:00
|
|
|
dirs << it.key();
|
2007-07-20 05:21:40 +02:00
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
return dirs;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> PackageStructure::files() const
|
2007-07-20 05:21:40 +02:00
|
|
|
{
|
2007-10-22 03:28:48 +02:00
|
|
|
QList<const char*> files;
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
|
2007-07-20 05:21:40 +02:00
|
|
|
while (it != d->contents.constEnd()) {
|
2007-10-22 03:28:48 +02:00
|
|
|
if (!it.value().directory) {
|
|
|
|
files << it.key();
|
2007-07-20 05:21:40 +02:00
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> PackageStructure::requiredFiles() const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2007-10-22 03:28:48 +02:00
|
|
|
QList<const char*> files;
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
|
2007-06-17 02:25:16 +02:00
|
|
|
while (it != d->contents.constEnd()) {
|
2007-10-22 03:28:48 +02:00
|
|
|
if (!it.value().directory && it.value().required) {
|
|
|
|
files << it.key();
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructure::addDirectoryDefinition(const char* key, const QString& path, const QString& name)
|
|
|
|
{
|
|
|
|
ContentStructure s;
|
|
|
|
s.name = name;
|
|
|
|
s.path = path;
|
2007-10-09 19:22:52 +02:00
|
|
|
s.directory = true;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
d->contents[key] = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructure::addFileDefinition(const char* key, const QString& path, const QString& name)
|
|
|
|
{
|
|
|
|
ContentStructure s;
|
|
|
|
s.name = name;
|
|
|
|
s.path = path;
|
|
|
|
s.directory = false;
|
|
|
|
|
|
|
|
d->contents[key] = s;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QString PackageStructure::path(const char* key) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.find(key);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (it == d->contents.constEnd()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return it.value().path;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QString PackageStructure::name(const char* key) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.find(key);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (it == d->contents.constEnd()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return it.value().name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackageStructure::setRequired(const char* key, bool required)
|
|
|
|
{
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::iterator it = d->contents.find(key);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (it == d->contents.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
it.value().required = required;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
bool PackageStructure::required(const char* key) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.find(key);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (it == d->contents.constEnd()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it.value().required;
|
|
|
|
}
|
|
|
|
|
2007-06-17 03:04:59 +02:00
|
|
|
void PackageStructure::setDefaultMimetypes(QStringList mimetypes)
|
|
|
|
{
|
|
|
|
d->mimetypes = mimetypes;
|
|
|
|
}
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
void PackageStructure::setMimetypes(const char* key, QStringList mimetypes)
|
|
|
|
{
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::iterator it = d->contents.find(key);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (it == d->contents.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
it.value().mimetypes = mimetypes;
|
|
|
|
}
|
|
|
|
|
2007-11-26 20:16:40 +01:00
|
|
|
QStringList PackageStructure::mimetypes(const char* key) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2007-11-26 20:16:40 +01:00
|
|
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.find(key);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (it == d->contents.constEnd()) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2007-06-17 03:04:59 +02:00
|
|
|
if (it.value().mimetypes.isEmpty()) {
|
|
|
|
return d->mimetypes;
|
|
|
|
}
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
return it.value().mimetypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|