2007-06-17 02:25:16 +02:00
|
|
|
/******************************************************************************
|
2008-06-26 20:09:45 +02:00
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@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. *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2007-07-20 10:06:27 +02:00
|
|
|
#include "package.h"
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
2008-08-14 11:03:24 +02:00
|
|
|
#include <QRegExp>
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
#include <KArchiveDirectory>
|
|
|
|
#include <KArchiveEntry>
|
2007-07-20 06:07:00 +02:00
|
|
|
#include <KComponentData>
|
2008-02-29 09:14:32 +01:00
|
|
|
#include <KDesktopFile>
|
2008-06-26 18:30:40 +02:00
|
|
|
#include <KIO/CopyJob>
|
2008-08-13 18:40:31 +02:00
|
|
|
#include <KIO/DeleteJob>
|
2007-06-17 02:25:16 +02:00
|
|
|
#include <KIO/FileCopyJob>
|
|
|
|
#include <KIO/Job>
|
2007-07-20 06:07:00 +02:00
|
|
|
#include <KPluginInfo>
|
2007-06-17 02:25:16 +02:00
|
|
|
#include <KStandardDirs>
|
2007-12-02 13:04:57 +01:00
|
|
|
#include <KTempDir>
|
2007-07-20 06:23:27 +02:00
|
|
|
#include <KTemporaryFile>
|
2007-06-17 02:25:16 +02:00
|
|
|
#include <KZip>
|
2007-10-06 00:21:25 +02:00
|
|
|
#include <KDebug>
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
#include "packagemetadata.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class PackagePrivate
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
public:
|
2008-07-01 20:56:43 +02:00
|
|
|
PackagePrivate(const PackageStructure::Ptr st, const QString& p)
|
2007-06-17 02:25:16 +02:00
|
|
|
: structure(st),
|
|
|
|
basePath(p),
|
2007-12-02 13:04:57 +01:00
|
|
|
valid(QFile::exists(basePath)),
|
|
|
|
metadata(0)
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
if (valid && basePath[basePath.length() - 1] != '/') {
|
|
|
|
basePath.append('/');
|
|
|
|
}
|
2007-12-02 13:04:57 +01:00
|
|
|
}
|
2008-02-26 05:07:07 +01:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
~PackagePrivate()
|
2007-12-02 13:04:57 +01:00
|
|
|
{
|
|
|
|
delete metadata;
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-02-28 04:53:26 +01:00
|
|
|
PackageStructure::Ptr structure;
|
2007-06-17 02:25:16 +02:00
|
|
|
QString basePath;
|
|
|
|
bool valid;
|
2007-12-02 13:04:57 +01:00
|
|
|
PackageMetadata *metadata;
|
2007-06-17 02:25:16 +02:00
|
|
|
};
|
|
|
|
|
2008-02-28 04:53:26 +01:00
|
|
|
Package::Package(const QString& packageRoot, const QString& package, PackageStructure::Ptr structure)
|
2008-07-01 20:56:43 +02:00
|
|
|
: d(new PackagePrivate(structure, packageRoot + '/' + package))
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2008-02-28 04:53:26 +01:00
|
|
|
structure->setPath(d->basePath);
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-02-28 04:53:26 +01:00
|
|
|
Package::Package(const QString &packagePath, PackageStructure::Ptr structure)
|
2008-07-01 20:56:43 +02:00
|
|
|
: d(new PackagePrivate(structure, packagePath))
|
2007-11-26 20:16:40 +01:00
|
|
|
{
|
2008-02-28 04:53:26 +01:00
|
|
|
structure->setPath(d->basePath);
|
2007-11-26 20:16:40 +01:00
|
|
|
}
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
Package::~Package()
|
|
|
|
{
|
2007-10-27 16:27:25 +02:00
|
|
|
delete d;
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 09:26:28 +02:00
|
|
|
bool Package::isValid() const
|
2007-07-20 05:21:40 +02:00
|
|
|
{
|
|
|
|
if (!d->valid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:07:07 +01:00
|
|
|
foreach (const char *dir, d->structure->requiredDirectories()) {
|
2008-02-29 09:14:32 +01:00
|
|
|
if (!QFile::exists(d->basePath + d->structure->contentsPrefix() + d->structure->path(dir))) {
|
2007-12-02 13:04:57 +01:00
|
|
|
kWarning(505) << "Could not find required directory" << dir;
|
2007-07-20 05:21:40 +02:00
|
|
|
d->valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:07:07 +01:00
|
|
|
foreach (const char *file, d->structure->requiredFiles()) {
|
2008-02-29 09:14:32 +01:00
|
|
|
if (!QFile::exists(d->basePath + d->structure->contentsPrefix() + d->structure->path(file))) {
|
2008-01-18 01:10:27 +01:00
|
|
|
kWarning(505) << "Could not find required file" << file << ", look in"
|
2008-02-29 09:14:32 +01:00
|
|
|
<< d->basePath + d->structure->contentsPrefix() + d->structure->path(file) << endl;
|
2007-07-20 05:21:40 +02:00
|
|
|
d->valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-23 09:26:28 +02:00
|
|
|
QString Package::filePath(const char* fileType, const QString& filename) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
if (!d->valid) {
|
2008-02-29 09:14:32 +01:00
|
|
|
kDebug() << "package is not valid";
|
2007-06-17 02:25:16 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:07:07 +01:00
|
|
|
QString path = d->structure->path(fileType);
|
2007-07-20 05:21:40 +02:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
2008-02-29 09:14:32 +01:00
|
|
|
kDebug() << "no matching path came of it";
|
2007-07-20 05:21:40 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
path.prepend(d->basePath + d->structure->contentsPrefix());
|
2007-11-03 13:22:21 +01:00
|
|
|
|
2007-07-20 05:21:40 +02:00
|
|
|
if (!filename.isEmpty()) {
|
2007-06-17 02:25:16 +02:00
|
|
|
path.append("/").append(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QFile::exists(path)) {
|
2008-08-17 22:52:37 +02:00
|
|
|
// ensure that we don't return files outside of our base path
|
|
|
|
// due to symlink or ../ games
|
|
|
|
QDir dir(path);
|
2008-09-15 15:35:17 +02:00
|
|
|
QString canonicalized = dir.canonicalPath() + QDir::separator();
|
2008-08-17 22:52:37 +02:00
|
|
|
if (canonicalized.startsWith(d->basePath)) {
|
|
|
|
return path;
|
|
|
|
}
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
kDebug() << path << "does not exist";
|
2007-06-17 02:25:16 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-23 09:26:28 +02:00
|
|
|
QString Package::filePath(const char* fileType) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
return filePath(fileType, QString());
|
|
|
|
}
|
|
|
|
|
2007-07-23 09:26:28 +02:00
|
|
|
QStringList Package::entryList(const char* fileType) const
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
if (!d->valid) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:07:07 +01:00
|
|
|
QString path = d->structure->path(fileType);
|
2007-06-17 02:25:16 +02:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
QDir dir(d->basePath + d->structure->contentsPrefix() + path);
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-08-17 22:52:37 +02:00
|
|
|
if (dir.exists()) {
|
|
|
|
// ensure that we don't return files outside of our base path
|
|
|
|
// due to symlink or ../ games
|
|
|
|
QString canonicalized = dir.canonicalPath();
|
|
|
|
if (canonicalized.startsWith(d->basePath)) {
|
|
|
|
return dir.entryList(QDir::Files | QDir::Readable);
|
|
|
|
}
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-08-17 22:52:37 +02:00
|
|
|
return QStringList();
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2008-02-26 05:07:07 +01:00
|
|
|
const PackageMetadata* Package::metadata() const
|
2007-12-02 13:04:57 +01:00
|
|
|
{
|
2008-02-28 04:53:26 +01:00
|
|
|
//FIXME: this only works for native plasma packges; should fall back to... PackageStructure?
|
2007-12-02 13:04:57 +01:00
|
|
|
if (!d->metadata) {
|
|
|
|
d->metadata = new PackageMetadata(d->basePath + "metadata.desktop");
|
|
|
|
}
|
|
|
|
return d->metadata;
|
|
|
|
}
|
|
|
|
|
2008-02-28 04:53:26 +01:00
|
|
|
const QString Package::path() const
|
|
|
|
{
|
|
|
|
return d->basePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PackageStructure::Ptr Package::structure() const
|
|
|
|
{
|
|
|
|
return d->structure;
|
|
|
|
}
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
//TODO: provide a version of this that allows one to ask for certain types of packages, etc?
|
2007-11-05 00:38:07 +01:00
|
|
|
// should we be using KService here instead/as well?
|
2008-04-27 21:22:29 +02:00
|
|
|
QStringList Package::listInstalled(const QString& packageRoot) // static
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
QDir dir(packageRoot);
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList packages;
|
|
|
|
|
2007-12-03 04:43:30 +01:00
|
|
|
foreach (const QString& sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) {
|
|
|
|
QString metadata = packageRoot + '/' + sdir + "/metadata.desktop";
|
2007-06-17 02:25:16 +02:00
|
|
|
if (QFile::exists(metadata)) {
|
|
|
|
PackageMetadata m(metadata);
|
2008-03-02 11:44:12 +01:00
|
|
|
packages << m.pluginName();
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return packages;
|
|
|
|
}
|
|
|
|
|
2007-07-20 06:07:00 +02:00
|
|
|
bool Package::installPackage(const QString& package,
|
2008-09-26 17:43:32 +02:00
|
|
|
const QString& packageRoot,
|
|
|
|
const QString& servicePrefix) // static
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
|
|
|
//TODO: report *what* failed if something does fail
|
|
|
|
QDir root(packageRoot);
|
|
|
|
|
|
|
|
if (!root.exists()) {
|
|
|
|
KStandardDirs::makeDir(packageRoot);
|
|
|
|
if (!root.exists()) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << "Could not create package root directory:" << packageRoot;
|
2007-06-17 02:25:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
QFileInfo fileInfo(package);
|
|
|
|
if (!fileInfo.exists()) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << "No such file:" << package;
|
2007-06-17 02:25:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
QString path;
|
|
|
|
KTempDir tempdir;
|
|
|
|
bool archivedPackage = false;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
if (fileInfo.isDir()) {
|
|
|
|
// we have a directory, so let's just install what is in there
|
|
|
|
path = package;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
// make sure we end in a slash!
|
|
|
|
if (path[path.size() - 1] != '/') {
|
|
|
|
path.append('/');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
KZip archive(package);
|
|
|
|
if (!archive.open(QIODevice::ReadOnly)) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << "Could not open package file:" << package;
|
2008-03-31 00:27:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
archivedPackage = true;
|
|
|
|
const KArchiveDirectory* source = archive.directory();
|
|
|
|
const KArchiveEntry* metadata = source->entry("metadata.desktop");
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
if (!metadata) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << "No metadata file in package" << package;
|
2008-03-31 00:27:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = tempdir.name();
|
|
|
|
source->copyTo(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString metadataPath = path + "metadata.desktop";
|
2007-06-17 02:25:16 +02:00
|
|
|
if (!QFile::exists(metadataPath)) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << "No metadata file in package" << package;
|
2007-06-17 02:25:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-03-31 00:27:32 +02:00
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
PackageMetadata meta(metadataPath);
|
2008-03-02 11:44:12 +01:00
|
|
|
QString targetName = meta.pluginName();
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
if (targetName.isEmpty()) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << "Package plugin name not specified";
|
2007-06-17 02:25:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-14 11:03:24 +02:00
|
|
|
// Ensure that package names are safe so package uninstall can't inject
|
|
|
|
// bad characters into the paths used for removal.
|
|
|
|
QRegExp validatePluginName("^[\\w-\\.]+$"); // Only allow letters, numbers, underscore and period.
|
|
|
|
if ( !validatePluginName.exactMatch(targetName) ) {
|
|
|
|
kWarning() << "Package plugin name " << targetName << "contains invalid characters";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-04 14:55:07 +02:00
|
|
|
targetName = packageRoot + '/' + targetName;
|
2007-06-17 02:25:16 +02:00
|
|
|
if (QFile::exists(targetName)) {
|
2008-06-18 01:32:36 +02:00
|
|
|
kWarning() << targetName << "already exists";
|
2007-06-17 02:25:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
if (archivedPackage) {
|
|
|
|
// it's in a temp dir, so just move it over.
|
2008-06-26 20:09:45 +02:00
|
|
|
KIO::CopyJob *job = KIO::move(KUrl(path), KUrl(targetName), KIO::HideProgressInfo);
|
2008-06-26 18:30:40 +02:00
|
|
|
if (!job->exec()) {
|
2008-06-26 20:39:52 +02:00
|
|
|
kWarning() << "Could not move package to destination:" << targetName << " : " << job->errorString();
|
2008-06-26 18:30:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-03-31 00:27:32 +02:00
|
|
|
} else {
|
|
|
|
// it's a directory containing the stuff, so copy the contents rather
|
|
|
|
// than move them
|
2008-06-26 20:09:45 +02:00
|
|
|
KIO::CopyJob *job = KIO::copy(KUrl(path), KUrl(targetName), KIO::HideProgressInfo);
|
2008-06-26 18:30:40 +02:00
|
|
|
if (!job->exec()) {
|
2008-06-26 20:39:52 +02:00
|
|
|
kWarning() << "Could not copy package to destination:" << targetName << " : " << job->errorString();
|
2008-06-26 18:30:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
2008-02-27 01:51:04 +01:00
|
|
|
|
2008-03-31 00:27:32 +02:00
|
|
|
if (archivedPackage) {
|
|
|
|
// no need to remove the temp dir (which has been successfully moved if it's an archive)
|
|
|
|
tempdir.setAutoRemove(false);
|
|
|
|
}
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2007-07-20 06:07:00 +02:00
|
|
|
// and now we register it as a service =)
|
2008-06-26 20:09:45 +02:00
|
|
|
QString metaPath = targetName + "/metadata.desktop";
|
2008-07-13 14:06:53 +02:00
|
|
|
KDesktopFile df(metaPath);
|
|
|
|
KConfigGroup cg = df.desktopGroup();
|
2008-02-27 01:51:04 +01:00
|
|
|
|
2008-06-26 20:09:45 +02:00
|
|
|
// Q: should not installing it as a service disqualify it?
|
|
|
|
// Q: i don't think so since KServiceTypeTrader may not be
|
2008-02-27 01:51:04 +01:00
|
|
|
// used by the installing app in any case, and the
|
|
|
|
// package is properly installed - aseigo
|
2008-02-29 09:14:32 +01:00
|
|
|
|
|
|
|
//TODO: reduce code duplication with registerPackage below
|
|
|
|
|
2008-09-26 17:43:32 +02:00
|
|
|
QString serviceName = servicePrefix + meta.pluginName();
|
2008-02-29 09:14:32 +01:00
|
|
|
|
|
|
|
QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop");
|
2008-06-26 20:09:45 +02:00
|
|
|
KIO::FileCopyJob *job = KIO::file_copy(metaPath, service, -1, KIO::HideProgressInfo);
|
|
|
|
if (job->exec()) {
|
|
|
|
// the icon in the installed file needs to point to the icon in the
|
|
|
|
// installation dir!
|
|
|
|
QString iconPath = targetName + '/' + cg.readEntry("Icon");
|
|
|
|
QFile icon(iconPath);
|
|
|
|
if (icon.exists()) {
|
2008-09-12 17:15:38 +02:00
|
|
|
KDesktopFile df(service);
|
|
|
|
KConfigGroup cg = df.desktopGroup();
|
2008-06-26 20:09:45 +02:00
|
|
|
cg.writeEntry("Icon", iconPath);
|
|
|
|
}
|
|
|
|
}
|
2008-02-29 09:14:32 +01:00
|
|
|
|
2008-02-27 01:51:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-13 18:40:31 +02:00
|
|
|
bool Package::uninstallPackage(const QString& pluginName,
|
2008-09-26 17:43:32 +02:00
|
|
|
const QString& packageRoot,
|
|
|
|
const QString& servicePrefix) // static
|
2008-08-13 18:40:31 +02:00
|
|
|
{
|
|
|
|
// We need to remove the package directory and its metadata file.
|
|
|
|
QString targetName = pluginName;
|
|
|
|
targetName = packageRoot + '/' + targetName;
|
|
|
|
|
|
|
|
if (!QFile::exists(targetName)) {
|
|
|
|
kWarning() << targetName << "does not exist";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:43:32 +02:00
|
|
|
QString serviceName = servicePrefix + pluginName;
|
2008-08-13 18:40:31 +02:00
|
|
|
|
|
|
|
QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop");
|
|
|
|
kDebug() << "Removing service file " << service;
|
2008-08-17 22:52:37 +02:00
|
|
|
bool ok = QFile::remove(service);
|
2008-08-13 18:40:31 +02:00
|
|
|
|
2008-08-17 22:52:37 +02:00
|
|
|
if (!ok) {
|
|
|
|
kWarning() << "Unable to remove " << service;
|
|
|
|
return ok;
|
2008-08-13 18:40:31 +02:00
|
|
|
}
|
|
|
|
|
2008-08-17 22:52:37 +02:00
|
|
|
KIO::DeleteJob *job = KIO::del(KUrl(targetName));
|
2008-08-13 18:40:31 +02:00
|
|
|
if (!job->exec()) {
|
2008-08-17 22:52:37 +02:00
|
|
|
kWarning() << "Could not delete package from:" << targetName << " : " << job->errorString();
|
|
|
|
return false;
|
2008-08-13 18:40:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
bool Package::registerPackage(const PackageMetadata &data, const QString &iconPath)
|
2008-02-27 01:51:04 +01:00
|
|
|
{
|
2008-02-29 09:14:32 +01:00
|
|
|
QString serviceName("plasma-applet-" + data.pluginName());
|
|
|
|
QString service = KStandardDirs::locateLocal("services", serviceName + ".desktop");
|
2007-07-20 06:07:00 +02:00
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
if (data.pluginName().isEmpty()) {
|
2008-02-27 01:51:04 +01:00
|
|
|
return false;
|
2007-07-20 06:07:00 +02:00
|
|
|
}
|
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
data.write(service);
|
|
|
|
|
|
|
|
KDesktopFile config(service);
|
|
|
|
KConfigGroup cg = config.desktopGroup();
|
2008-07-05 07:21:07 +02:00
|
|
|
const QString type = data.type().isEmpty() ? "Service" : data.type();
|
|
|
|
cg.writeEntry("Type", type);
|
2008-05-18 19:16:10 +02:00
|
|
|
const QString serviceTypes = data.serviceType().isNull() ? "Plasma/Applet,Plasma/Containment" : data.serviceType();
|
|
|
|
cg.writeEntry("X-KDE-ServiceTypes", serviceTypes);
|
2008-02-29 09:14:32 +01:00
|
|
|
cg.writeEntry("X-KDE-PluginInfo-EnabledByDefault", true);
|
|
|
|
|
|
|
|
QFile icon(iconPath);
|
|
|
|
if (icon.exists()) {
|
|
|
|
//FIXME: the '/' search will break on non-UNIX. do we care?
|
|
|
|
QString installedIcon("plasma_applet_" + data.pluginName() +
|
|
|
|
iconPath.right(iconPath.length() - iconPath.lastIndexOf("/")));
|
|
|
|
cg.writeEntry("Icon", installedIcon);
|
|
|
|
installedIcon = KStandardDirs::locateLocal("icon", installedIcon);
|
|
|
|
KIO::FileCopyJob *job = KIO::file_copy(iconPath, installedIcon, -1, KIO::HideProgressInfo);
|
|
|
|
job->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2007-06-17 02:25:16 +02:00
|
|
|
}
|
|
|
|
|
2007-12-02 13:04:57 +01:00
|
|
|
bool Package::createPackage(const PackageMetadata &metadata,
|
|
|
|
const QString &source,
|
|
|
|
const QString &destination,
|
|
|
|
const QString &icon) // static
|
2007-07-20 06:23:27 +02:00
|
|
|
{
|
2008-09-12 17:15:38 +02:00
|
|
|
Q_UNUSED(icon)
|
2008-04-26 17:37:42 +02:00
|
|
|
if (!metadata.isValid()) {
|
2007-12-02 13:04:57 +01:00
|
|
|
kWarning(550) << "Metadata file is not complete";
|
2007-07-20 06:23:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-12-02 13:04:57 +01:00
|
|
|
// write metadata in a temporary file
|
2007-07-20 06:23:27 +02:00
|
|
|
KTemporaryFile metadataFile;
|
2007-12-02 13:04:57 +01:00
|
|
|
if (!metadataFile.open()) {
|
|
|
|
return false;
|
2007-07-20 06:23:27 +02:00
|
|
|
}
|
2008-04-26 17:48:47 +02:00
|
|
|
metadata.write(metadataFile.fileName());
|
2007-07-20 06:23:27 +02:00
|
|
|
|
2007-12-02 13:04:57 +01:00
|
|
|
// put everything into a zip archive
|
2007-07-20 06:23:27 +02:00
|
|
|
KZip creation(destination);
|
|
|
|
creation.setCompression(KZip::NoCompression);
|
|
|
|
if (!creation.open(QIODevice::WriteOnly)) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-29 09:14:32 +01:00
|
|
|
|
2007-07-20 06:23:27 +02:00
|
|
|
creation.addLocalFile(metadataFile.fileName(), "metadata.desktop");
|
2007-10-19 03:03:21 +02:00
|
|
|
creation.addLocalDirectory(source, "contents");
|
2007-07-20 06:23:27 +02:00
|
|
|
creation.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
} // Namespace
|