2008-11-04 00:08:39 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
|
2011-07-08 19:36:29 +02:00
|
|
|
* Copyright 2010 by Marco Martin <notmart@gmail.com> *
|
|
|
|
* Copyright 2010 by Kevin Ottens <ervin@kde.org> *
|
|
|
|
* Copyright 2009 by Rob Scheepmaker *
|
2008-11-04 00:08:39 +01: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 "package.h"
|
|
|
|
|
2011-12-06 20:08:22 +01:00
|
|
|
#include <qtemporarydir.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:20:46 +01:00
|
|
|
#include <karchive.h>
|
2013-07-29 19:05:59 +02:00
|
|
|
#include <QDebug>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdesktopfile.h>
|
2012-06-12 12:59:34 +02:00
|
|
|
#include <ktar.h>
|
|
|
|
#include <kzip.h>
|
2014-11-11 16:44:48 +01:00
|
|
|
#include <KJob>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-09-02 10:50:04 +02:00
|
|
|
#include "config-plasma.h"
|
|
|
|
|
2012-06-12 12:59:34 +02:00
|
|
|
#include <qstandardpaths.h>
|
2012-06-21 09:19:32 +02:00
|
|
|
#include <qmimedatabase.h>
|
2011-07-15 12:57:46 +02:00
|
|
|
|
2011-07-19 21:37:39 +02:00
|
|
|
#include "packagestructure.h"
|
2011-07-15 13:34:10 +02:00
|
|
|
#include "pluginloader.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/package_p.h"
|
2014-11-11 16:44:48 +01:00
|
|
|
#include "private/packagestructure_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2014-11-11 16:44:48 +01:00
|
|
|
|
|
|
|
PackagePrivate::PackagePrivate()
|
2018-04-13 13:58:44 +02:00
|
|
|
: internalPackage(nullptr),
|
|
|
|
fallbackPackage(nullptr),
|
|
|
|
structure(nullptr)
|
2014-11-11 16:44:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PackagePrivate::~PackagePrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-19 21:37:39 +02:00
|
|
|
Package::Package(PackageStructure *structure)
|
2014-11-11 16:44:48 +01:00
|
|
|
: d(new Plasma::PackagePrivate())
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2011-07-19 21:37:39 +02:00
|
|
|
d->structure = structure;
|
2014-08-22 19:25:49 +02:00
|
|
|
|
2014-11-11 16:44:48 +01:00
|
|
|
if (!structure) {
|
|
|
|
d->internalPackage = new KPackage::Package();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!structure->d->internalStructure) {
|
|
|
|
d->structure->d->internalStructure = new KPackage::PackageStructure;
|
2011-07-21 15:04:56 +02:00
|
|
|
}
|
2014-11-11 16:44:48 +01:00
|
|
|
|
|
|
|
d->internalPackage = new KPackage::Package(structure->d->internalStructure);
|
|
|
|
PackageStructureWrapper::s_packagesMap[d->internalPackage] = this;
|
|
|
|
structure->initPackage(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-03 21:44:28 +02:00
|
|
|
Package::Package(const Package &other)
|
2014-11-11 16:44:48 +01:00
|
|
|
: d(new Plasma::PackagePrivate())
|
2010-09-03 21:44:28 +02:00
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage = new KPackage::Package(*other.d->internalPackage);
|
|
|
|
d->structure = other.d->structure;
|
|
|
|
PackageStructureWrapper::s_packagesMap[d->internalPackage] = this;
|
2017-05-31 02:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Package::Package(const KPackage::Package &other)
|
|
|
|
: d(new Plasma::PackagePrivate())
|
|
|
|
{
|
|
|
|
d->internalPackage = new KPackage::Package(other);
|
|
|
|
PackageStructureWrapper::s_packagesMap[d->internalPackage] = this;
|
2010-09-03 21:44:28 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Package::~Package()
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
PackageStructureWrapper::s_packagesMap.remove(d->internalPackage);
|
|
|
|
delete d->internalPackage;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-03 21:44:28 +02:00
|
|
|
Package &Package::operator=(const Package &rhs)
|
|
|
|
{
|
|
|
|
if (&rhs != this) {
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage = new KPackage::Package(*rhs.d->internalPackage);
|
|
|
|
d->structure = rhs.d->structure;
|
|
|
|
PackageStructureWrapper::s_packagesMap[d->internalPackage] = this;
|
2010-09-03 21:44:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-08-08 14:11:50 +02:00
|
|
|
bool Package::hasValidStructure() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->hasValidStructure();
|
2014-08-08 14:11:50 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
bool Package::isValid() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->isValid();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Package::name(const char *key) const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->name(key);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Package::isRequired(const char *key) const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->isRequired(key);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Package::mimeTypes(const char *key) const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->mimeTypes(key);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Package::defaultPackageRoot() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->defaultPackageRoot();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::setDefaultPackageRoot(const QString &packageRoot)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setDefaultPackageRoot(packageRoot);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
2014-09-01 14:54:10 +02:00
|
|
|
void Package::setFallbackPackage(const Plasma::Package &package)
|
2014-09-01 14:00:06 +02:00
|
|
|
{
|
2014-09-01 15:51:05 +02:00
|
|
|
d->fallbackPackage = new Package(package);
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setFallbackPackage(*package.d->internalPackage);
|
2014-09-01 14:00:06 +02:00
|
|
|
}
|
|
|
|
|
2014-09-01 14:54:10 +02:00
|
|
|
Plasma::Package Package::fallbackPackage() const
|
2014-09-01 14:00:06 +02:00
|
|
|
{
|
2014-09-01 14:54:10 +02:00
|
|
|
if (d->fallbackPackage) {
|
|
|
|
return (*d->fallbackPackage);
|
|
|
|
} else {
|
|
|
|
return Package();
|
|
|
|
}
|
2014-09-01 14:00:06 +02:00
|
|
|
}
|
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
QString Package::servicePrefix() const
|
|
|
|
{
|
|
|
|
return d->servicePrefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Package::setServicePrefix(const QString &servicePrefix)
|
|
|
|
{
|
|
|
|
d->servicePrefix = servicePrefix;
|
|
|
|
}
|
|
|
|
|
2016-10-31 12:04:06 +01:00
|
|
|
KPackage::Package Package::kPackage() const
|
|
|
|
{
|
|
|
|
return *d->internalPackage;
|
|
|
|
}
|
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
bool Package::allowExternalPaths() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->allowExternalPaths();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::setAllowExternalPaths(bool allow)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setAllowExternalPaths(allow);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo Package::metadata() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return KPluginInfo::fromMetaData(d->internalPackage->metadata());
|
2013-02-27 06:46:28 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString Package::filePath(const char *fileType, const QString &filename) const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->filePath(fileType, filename);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
QStringList Package::entryList(const char *key) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->entryList(key);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-05-13 01:05:40 +02:00
|
|
|
void Package::setPath(const QString &path)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
if (path == d->internalPackage->path()) {
|
2011-07-15 12:57:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setPath(path);
|
2009-05-13 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
const QString Package::path() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->path();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Package::contentsPrefixPaths() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->contentsPrefixPaths();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::setContentsPrefixPaths(const QStringList &prefixPaths)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setContentsPrefixPaths(prefixPaths);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Package::contentsHash() const
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->internalPackage->contentsHash();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::addDirectoryDefinition(const char *key, const QString &path, const QString &name)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->addDirectoryDefinition(key, path, name);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::addFileDefinition(const char *key, const QString &path, const QString &name)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->addFileDefinition(key, path, name);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::removeDefinition(const char *key)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->removeDefinition(key);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::setRequired(const char *key, bool required)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setRequired(key, required);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
void Package::setDefaultMimeTypes(QStringList mimeTypes)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setDefaultMimeTypes(mimeTypes);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Package::setMimeTypes(const char *key, QStringList mimeTypes)
|
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
d->internalPackage->setMimeTypes(key, mimeTypes);
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> Package::directories() const
|
2011-07-15 12:57:46 +02:00
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> dirs;
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (const auto &data, d->internalPackage->directories()) {
|
2014-11-11 16:44:48 +01:00
|
|
|
dirs << data.constData();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
2014-11-11 16:44:48 +01:00
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
return dirs;
|
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> Package::requiredDirectories() const
|
2011-07-15 12:57:46 +02:00
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> dirs;
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (const auto &data, d->internalPackage->requiredDirectories()) {
|
2014-11-11 16:44:48 +01:00
|
|
|
dirs << data.constData();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
2014-11-11 16:44:48 +01:00
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
return dirs;
|
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> Package::files() const
|
2011-07-15 12:57:46 +02:00
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> files;
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (const auto &data, d->internalPackage->files()) {
|
2014-11-11 16:44:48 +01:00
|
|
|
files << data.constData();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
2014-11-11 16:44:48 +01:00
|
|
|
|
2011-07-15 12:57:46 +02:00
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> Package::requiredFiles() const
|
2011-07-15 12:57:46 +02:00
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<const char *> files;
|
2016-02-29 00:08:05 +01:00
|
|
|
foreach (const auto &data, d->internalPackage->requiredFiles()) {
|
2014-11-11 16:44:48 +01:00
|
|
|
files << data.constData();
|
2011-07-15 12:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
KJob *Package::install(const QString &sourcePackage, const QString &packageRoot)
|
2011-07-19 21:37:39 +02:00
|
|
|
{
|
2012-12-09 14:12:55 +01:00
|
|
|
const QString src = sourcePackage;
|
|
|
|
const QString dest = packageRoot.isEmpty() ? defaultPackageRoot() : packageRoot;
|
2015-12-15 22:56:40 +01:00
|
|
|
//qCDebug(LOG_PLASMA) << "Source: " << src;
|
|
|
|
//qCDebug(LOG_PLASMA) << "PackageRoot: " << dest;
|
2014-11-11 16:44:48 +01:00
|
|
|
KJob *j = d->structure->install(this, src, dest);
|
2012-12-09 14:12:55 +01:00
|
|
|
return j;
|
2011-07-19 21:37:39 +02:00
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
KJob *Package::uninstall(const QString &packageName, const QString &packageRoot)
|
2011-07-15 12:57:46 +02:00
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
setPath(packageRoot + packageName);
|
2014-09-01 15:15:54 +02:00
|
|
|
|
2014-11-11 16:44:48 +01:00
|
|
|
return d->structure->uninstall(this, packageRoot);
|
2014-09-01 15:15:54 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Namespace
|