Support for metadata in PackageStructure.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=879173
This commit is contained in:
Petri Damstén 2008-11-02 15:28:59 +00:00
parent 648fd5832b
commit 870e710307
3 changed files with 70 additions and 11 deletions

View File

@ -50,8 +50,7 @@ public:
PackagePrivate(const PackageStructure::Ptr st, const QString &p)
: structure(st),
basePath(p),
valid(QFile::exists(basePath)),
metadata(0)
valid(QFile::exists(basePath))
{
if (valid && basePath[basePath.length() - 1] != '/') {
basePath.append('/');
@ -60,13 +59,11 @@ public:
~PackagePrivate()
{
delete metadata;
}
PackageStructure::Ptr structure;
QString basePath;
bool valid;
PackageMetadata *metadata;
};
Package::Package(const QString &packageRoot, const QString &package,
@ -179,11 +176,7 @@ QStringList Package::entryList(const char *fileType) const
PackageMetadata Package::metadata() const
{
//FIXME: this only works for native plasma packges; should fall back to... PackageStructure?
if (!d->metadata) {
d->metadata = new PackageMetadata(d->basePath + "metadata.desktop");
}
return *d->metadata;
return d->structure->metadata();
}
const QString Package::path() const

View File

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
@ -20,12 +20,15 @@
#include "packagestructure.h"
#include <QMap>
#include <QFileInfo>
#include <KConfigGroup>
#include <KStandardDirs>
#include <KServiceTypeTrader>
#include <KUrl>
#include <KTemporaryFile>
#include <KTempDir>
#include <KZip>
#include <kio/netaccess.h>
#include <kio/job.h>
@ -62,6 +65,15 @@ class ContentStructure
class PackageStructurePrivate
{
public:
PackageStructurePrivate()
: metadata(0)
{
}
~PackageStructurePrivate()
{
delete metadata;
}
QString type;
QString path;
QString contentsPrefix;
@ -70,6 +82,7 @@ public:
QMap<QByteArray, ContentStructure> contents;
QStringList mimetypes;
static QHash<QString, PackageStructure::Ptr> structures;
PackageMetadata *metadata;
};
QHash<QString, PackageStructure::Ptr> PackageStructurePrivate::structures;
@ -403,6 +416,7 @@ bool PackageStructure::uninstallPackage(const QString &packageName, const QStrin
void PackageStructure::createNewWidgetBrowser(QWidget *parent)
{
Q_UNUSED(parent)
emit newWidgetBrowserFinished();
}
@ -426,6 +440,52 @@ void PackageStructure::setServicePrefix(const QString &servicePrefix)
d->servicePrefix = servicePrefix;
}
PackageMetadata PackageStructure::metadata()
{
if (!d->metadata) {
QString metadataPath;
QString package = d->path;
KTempDir tempdir;
QFileInfo fileInfo(package);
if (fileInfo.exists()) {
QString path;
if (fileInfo.isDir()) {
path = package;
} else {
KZip archive(package);
if (archive.open(QIODevice::ReadOnly)) {
const KArchiveDirectory *source = archive.directory();
const KArchiveEntry *metadata = source->entry("metadata.desktop");
if (metadata) {
path = tempdir.name();
source->copyTo(path);
} else {
kWarning() << "No metadata file in package" << package;
}
} else {
kWarning() << "Could not open package file:" << package;
}
}
if (!path.isEmpty()) {
metadataPath = path + "/metadata.desktop";
if (!QFile::exists(metadataPath)) {
metadataPath.clear();
kWarning() << "No such file:" << metadataPath;
}
}
}
if (metadataPath.isEmpty()) {
d->metadata = new PackageMetadata();
} else {
d->metadata = new PackageMetadata(metadataPath);
}
}
return *d->metadata;
}
} // Plasma namespace
#include "packagestructure.moc"

View File

@ -28,6 +28,7 @@
#include <KDE/KSharedPtr>
#include <plasma/version.h>
#include "packagemetadata.h"
class KConfigBase;
@ -80,7 +81,7 @@ public:
*
* @arg type the type of package. This is often application specific.
**/
explicit PackageStructure(QObject *parent = 0,
explicit PackageStructure(QObject *parent = 0,
const QString &type = i18nc("A non-functional package", "Invalid"));
/**
@ -272,6 +273,11 @@ public:
*/
void setServicePrefix(const QString &servicePrefix);
/**
* @return the package metadata object.
*/
virtual PackageMetadata metadata();
Q_SIGNALS:
/**
* Emitted when the new widget browser process completes.