* make read non-static so you have to create a PackageStructure first; better symetry with write and prevents some unecessary object copies between methods (e.g. load -> read)
* provide a load method svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=779402
This commit is contained in:
parent
954352ae1b
commit
ac195d0137
@ -20,7 +20,11 @@
|
|||||||
#include "packagestructure.h"
|
#include "packagestructure.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
|
#include <KStandardDirs>
|
||||||
|
|
||||||
|
#include "packages_p.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -75,6 +79,25 @@ PackageStructure::~PackageStructure()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PackageStructure PackageStructure::load(const QString &packageFormat)
|
||||||
|
{
|
||||||
|
PackageStructure ps;
|
||||||
|
|
||||||
|
if (packageFormat.isEmpty()) {
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString configPath("plasma/packageformats/%1rc");
|
||||||
|
configPath = KStandardDirs::locate("data", configPath.arg(packageFormat));
|
||||||
|
|
||||||
|
if (!configPath.isEmpty()) {
|
||||||
|
KConfig config(configPath);
|
||||||
|
ps.read(&config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps;
|
||||||
|
}
|
||||||
|
|
||||||
PackageStructure& PackageStructure::operator=(const PackageStructure& rhs)
|
PackageStructure& PackageStructure::operator=(const PackageStructure& rhs)
|
||||||
{
|
{
|
||||||
if (this == &rhs) {
|
if (this == &rhs) {
|
||||||
@ -232,40 +255,38 @@ QStringList PackageStructure::mimetypes(const char* key) const
|
|||||||
return it.value().mimetypes;
|
return it.value().mimetypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageStructure PackageStructure::read(const KConfigBase *config)
|
void PackageStructure::read(const KConfigBase *config)
|
||||||
{
|
{
|
||||||
QString type = config->group("").readEntry("Type", "");
|
d->contents.clear();
|
||||||
PackageStructure structure(type);
|
d->mimetypes.clear();
|
||||||
|
d->type = config->group("").readEntry("Type", QString());
|
||||||
|
|
||||||
QStringList groups = config->groupList();
|
QStringList groups = config->groupList();
|
||||||
foreach (QString groupName, groups) {
|
foreach (QString group, groups) {
|
||||||
QByteArray key = groupName.toAscii();
|
QByteArray key = group.toAscii();
|
||||||
KConfigGroup entry = config->group(key);
|
KConfigGroup entry = config->group(group);
|
||||||
|
|
||||||
QString path = entry.readEntry("Path", QString());
|
QString path = entry.readEntry("Path", QString());
|
||||||
QString name = entry.readEntry("Name", QString());
|
QString name = entry.readEntry("Name", QString());
|
||||||
QStringList mimetypes = entry.readEntry("Mimetypes", QStringList());
|
QStringList mimetypes = entry.readEntry("Mimetypes", QStringList());
|
||||||
bool directory = entry.readEntry("Directory", false);
|
bool directory = entry.readEntry("Directory", false);
|
||||||
bool required = entry.readEntry("Required", false);
|
bool required = entry.readEntry("Required", false);
|
||||||
|
|
||||||
if (directory) {
|
if (directory) {
|
||||||
structure.addDirectoryDefinition(key, path, name);
|
addDirectoryDefinition(key, path, name);
|
||||||
|
} else {
|
||||||
|
addFileDefinition(key, path, name);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
structure.addFileDefinition(key, path, name);
|
setMimetypes(key, mimetypes);
|
||||||
}
|
setRequired(key, required);
|
||||||
|
|
||||||
structure.setMimetypes(key, mimetypes);
|
|
||||||
structure.setRequired(key, required);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return structure;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PackageStructure::write(KConfigBase *config) const
|
void PackageStructure::write(KConfigBase *config) const
|
||||||
{
|
{
|
||||||
config->group("").writeEntry("Type", type());
|
config->group("").writeEntry("Type", type());
|
||||||
|
|
||||||
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
|
QMap<QByteArray, ContentStructure>::const_iterator it = d->contents.constBegin();
|
||||||
while (it != d->contents.constEnd()) {
|
while (it != d->contents.constEnd()) {
|
||||||
KConfigGroup group = config->group(it.key());
|
KConfigGroup group = config->group(it.key());
|
||||||
@ -280,7 +301,7 @@ void PackageStructure::write(KConfigBase *config) const
|
|||||||
if (it.value().required) {
|
if (it.value().required) {
|
||||||
group.writeEntry("Required", true);
|
group.writeEntry("Required", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
|
||||||
|
#include <KLocale>
|
||||||
|
|
||||||
#include <plasma/plasma_export.h>
|
#include <plasma/plasma_export.h>
|
||||||
|
|
||||||
class KConfigBase;
|
class KConfigBase;
|
||||||
@ -67,7 +69,32 @@ public:
|
|||||||
*
|
*
|
||||||
* @arg type the type of package. This is often application specific.
|
* @arg type the type of package. This is often application specific.
|
||||||
**/
|
**/
|
||||||
PackageStructure(const QString &type);
|
explicit PackageStructure(const QString &type = i18n("Invalid"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor
|
||||||
|
**/
|
||||||
|
PackageStructure(const PackageStructure& rhs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor
|
||||||
|
**/
|
||||||
|
virtual ~PackageStructure();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignment operator
|
||||||
|
**/
|
||||||
|
PackageStructure& operator=(const PackageStructure& rhs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a package format by name.
|
||||||
|
*
|
||||||
|
* @arg format If not empty, attempts to locate the given format, either
|
||||||
|
* from built-ins or via plugins.
|
||||||
|
* @return a package that matches the format, if available. The caller
|
||||||
|
* is responsible for deleting the object.
|
||||||
|
*/
|
||||||
|
static PackageStructure load(const QString &package);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of package this structure describes
|
* Type of package this structure describes
|
||||||
@ -163,26 +190,11 @@ public:
|
|||||||
**/
|
**/
|
||||||
QStringList mimetypes(const char* key) const;
|
QStringList mimetypes(const char* key) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy constructor
|
|
||||||
**/
|
|
||||||
PackageStructure(const PackageStructure& rhs);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor
|
|
||||||
**/
|
|
||||||
virtual ~PackageStructure();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assignment operator
|
|
||||||
**/
|
|
||||||
PackageStructure& operator=(const PackageStructure& rhs);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a package structure from a config file.
|
* Read a package structure from a config file.
|
||||||
*/
|
*/
|
||||||
static PackageStructure read(const KConfigBase *config);
|
void read(const KConfigBase *config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write this package structure to a config file.
|
* Write this package structure to a config file.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user