Support for metadata in PackageStructure.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=879173
This commit is contained in:
parent
648fd5832b
commit
870e710307
11
package.cpp
11
package.cpp
@ -50,8 +50,7 @@ public:
|
|||||||
PackagePrivate(const PackageStructure::Ptr st, const QString &p)
|
PackagePrivate(const PackageStructure::Ptr st, const QString &p)
|
||||||
: structure(st),
|
: structure(st),
|
||||||
basePath(p),
|
basePath(p),
|
||||||
valid(QFile::exists(basePath)),
|
valid(QFile::exists(basePath))
|
||||||
metadata(0)
|
|
||||||
{
|
{
|
||||||
if (valid && basePath[basePath.length() - 1] != '/') {
|
if (valid && basePath[basePath.length() - 1] != '/') {
|
||||||
basePath.append('/');
|
basePath.append('/');
|
||||||
@ -60,13 +59,11 @@ public:
|
|||||||
|
|
||||||
~PackagePrivate()
|
~PackagePrivate()
|
||||||
{
|
{
|
||||||
delete metadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageStructure::Ptr structure;
|
PackageStructure::Ptr structure;
|
||||||
QString basePath;
|
QString basePath;
|
||||||
bool valid;
|
bool valid;
|
||||||
PackageMetadata *metadata;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Package::Package(const QString &packageRoot, const QString &package,
|
Package::Package(const QString &packageRoot, const QString &package,
|
||||||
@ -179,11 +176,7 @@ QStringList Package::entryList(const char *fileType) const
|
|||||||
|
|
||||||
PackageMetadata Package::metadata() const
|
PackageMetadata Package::metadata() const
|
||||||
{
|
{
|
||||||
//FIXME: this only works for native plasma packges; should fall back to... PackageStructure?
|
return d->structure->metadata();
|
||||||
if (!d->metadata) {
|
|
||||||
d->metadata = new PackageMetadata(d->basePath + "metadata.desktop");
|
|
||||||
}
|
|
||||||
return *d->metadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString Package::path() const
|
const QString Package::path() const
|
||||||
|
@ -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 *
|
* This library is free software; you can redistribute it and/or *
|
||||||
* modify it under the terms of the GNU Library General Public *
|
* modify it under the terms of the GNU Library General Public *
|
||||||
@ -20,12 +20,15 @@
|
|||||||
#include "packagestructure.h"
|
#include "packagestructure.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
#include <KStandardDirs>
|
#include <KStandardDirs>
|
||||||
#include <KServiceTypeTrader>
|
#include <KServiceTypeTrader>
|
||||||
#include <KUrl>
|
#include <KUrl>
|
||||||
#include <KTemporaryFile>
|
#include <KTemporaryFile>
|
||||||
|
#include <KTempDir>
|
||||||
|
#include <KZip>
|
||||||
#include <kio/netaccess.h>
|
#include <kio/netaccess.h>
|
||||||
#include <kio/job.h>
|
#include <kio/job.h>
|
||||||
|
|
||||||
@ -62,6 +65,15 @@ class ContentStructure
|
|||||||
class PackageStructurePrivate
|
class PackageStructurePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
PackageStructurePrivate()
|
||||||
|
: metadata(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~PackageStructurePrivate()
|
||||||
|
{
|
||||||
|
delete metadata;
|
||||||
|
}
|
||||||
|
|
||||||
QString type;
|
QString type;
|
||||||
QString path;
|
QString path;
|
||||||
QString contentsPrefix;
|
QString contentsPrefix;
|
||||||
@ -70,6 +82,7 @@ public:
|
|||||||
QMap<QByteArray, ContentStructure> contents;
|
QMap<QByteArray, ContentStructure> contents;
|
||||||
QStringList mimetypes;
|
QStringList mimetypes;
|
||||||
static QHash<QString, PackageStructure::Ptr> structures;
|
static QHash<QString, PackageStructure::Ptr> structures;
|
||||||
|
PackageMetadata *metadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<QString, PackageStructure::Ptr> PackageStructurePrivate::structures;
|
QHash<QString, PackageStructure::Ptr> PackageStructurePrivate::structures;
|
||||||
@ -403,6 +416,7 @@ bool PackageStructure::uninstallPackage(const QString &packageName, const QStrin
|
|||||||
|
|
||||||
void PackageStructure::createNewWidgetBrowser(QWidget *parent)
|
void PackageStructure::createNewWidgetBrowser(QWidget *parent)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(parent)
|
||||||
emit newWidgetBrowserFinished();
|
emit newWidgetBrowserFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,6 +440,52 @@ void PackageStructure::setServicePrefix(const QString &servicePrefix)
|
|||||||
d->servicePrefix = 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
|
} // Plasma namespace
|
||||||
|
|
||||||
#include "packagestructure.moc"
|
#include "packagestructure.moc"
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <KDE/KSharedPtr>
|
#include <KDE/KSharedPtr>
|
||||||
|
|
||||||
#include <plasma/version.h>
|
#include <plasma/version.h>
|
||||||
|
#include "packagemetadata.h"
|
||||||
|
|
||||||
class KConfigBase;
|
class KConfigBase;
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @arg type the type of package. This is often application specific.
|
* @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"));
|
const QString &type = i18nc("A non-functional package", "Invalid"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -272,6 +273,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setServicePrefix(const QString &servicePrefix);
|
void setServicePrefix(const QString &servicePrefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the package metadata object.
|
||||||
|
*/
|
||||||
|
virtual PackageMetadata metadata();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
* Emitted when the new widget browser process completes.
|
* Emitted when the new widget browser process completes.
|
||||||
|
Loading…
Reference in New Issue
Block a user