2008-11-04 00:08:39 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org> *
|
|
|
|
* *
|
|
|
|
* 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"
|
2009-09-21 23:37:44 +02:00
|
|
|
#include "config-plasma.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QRegExp>
|
2009-10-20 01:04:42 +02:00
|
|
|
#include <QtNetwork/QHostInfo>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-21 23:37:44 +02:00
|
|
|
#ifdef QCA2_FOUND
|
|
|
|
#include <QtCrypto>
|
|
|
|
#endif
|
|
|
|
|
2008-11-04 03:20:46 +01:00
|
|
|
#include <karchive.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kcomponentdata.h>
|
|
|
|
#include <kdesktopfile.h>
|
2010-10-14 14:27:15 +02:00
|
|
|
#ifndef PLASMA_NO_KIO
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kio/copyjob.h>
|
|
|
|
#include <kio/deletejob.h>
|
2008-11-04 03:20:46 +01:00
|
|
|
#include <kio/jobclasses.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kio/job.h>
|
2010-10-14 14:27:15 +02:00
|
|
|
#endif
|
2009-07-25 11:34:19 +02:00
|
|
|
#include <kmimetype.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kplugininfo.h>
|
|
|
|
#include <kstandarddirs.h>
|
2009-07-25 11:34:19 +02:00
|
|
|
#include <ktar.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <ktempdir.h>
|
|
|
|
#include <ktemporaryfile.h>
|
|
|
|
#include <kzip.h>
|
|
|
|
#include <kdebug.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "authorizationmanager.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "packagemetadata.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/authorizationmanager_p.h"
|
|
|
|
#include "private/package_p.h"
|
2009-11-25 02:09:17 +01:00
|
|
|
#include "private/plasmoidservice_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/service_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-10-14 15:23:56 +02:00
|
|
|
#ifdef PLASMA_NO_KIO // Provide some convenience for dealing with folders
|
|
|
|
|
|
|
|
bool copyFolder(QString sourcePath, QString targetPath)
|
|
|
|
{
|
|
|
|
QDir source(sourcePath);
|
|
|
|
if(!source.exists())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QDir target(targetPath);
|
|
|
|
if(!target.exists()) {
|
|
|
|
QString targetName = target.dirName();
|
|
|
|
target.cdUp();
|
|
|
|
target.mkdir(targetName);
|
|
|
|
target = QDir(targetPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QString &fileName, source.entryList(QDir::Files)) {
|
|
|
|
QString sourceFilePath = sourcePath + QDir::separator() + fileName;
|
|
|
|
QString targetFilePath = targetPath + QDir::separator() + fileName;
|
|
|
|
|
|
|
|
if (!QFile::copy(sourceFilePath, targetFilePath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QString &subFolderName, source.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)) {
|
|
|
|
QString sourceSubFolderPath = sourcePath + QDir::separator() + subFolderName;
|
|
|
|
QString targetSubFolderPath = targetPath + QDir::separator() + subFolderName;
|
|
|
|
|
|
|
|
if (!copyFolder(sourceSubFolderPath, targetSubFolderPath)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool removeFolder(QString folderPath)
|
|
|
|
{
|
|
|
|
QDir folder(folderPath);
|
|
|
|
if(!folder.exists())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
foreach (const QString &fileName, folder.entryList(QDir::Files)) {
|
|
|
|
if (!QFile::remove(folderPath + QDir::separator() + fileName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QString &subFolderName, folder.entryList(QDir::AllDirs | QDir::NoDotAndDotDot)) {
|
|
|
|
if (!removeFolder(folderPath + QDir::separator() + subFolderName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString folderName = folder.dirName();
|
|
|
|
folder.cdUp();
|
|
|
|
return folder.rmdir(folderName);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PLASMA_NO_KIO
|
|
|
|
|
|
|
|
|
2010-09-03 21:44:28 +02:00
|
|
|
Package::Package()
|
|
|
|
: d(new PackagePrivate(PackageStructure::Ptr(0), QString()))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Package::Package(const QString &packageRoot, const QString &package,
|
|
|
|
PackageStructure::Ptr structure)
|
|
|
|
: d(new PackagePrivate(structure, packageRoot + '/' + package))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Package::Package(const QString &packagePath, PackageStructure::Ptr structure)
|
|
|
|
: d(new PackagePrivate(structure, packagePath))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-03 21:44:28 +02:00
|
|
|
Package::Package(const Package &other)
|
|
|
|
: d(new PackagePrivate(*other.d))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Package::~Package()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2010-09-03 21:44:28 +02:00
|
|
|
Package &Package::operator=(const Package &rhs)
|
|
|
|
{
|
|
|
|
if (&rhs != this) {
|
|
|
|
*d = *rhs.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
bool Package::isValid() const
|
|
|
|
{
|
2010-12-15 07:29:36 +01:00
|
|
|
if (!d->valid) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-04 20:18:32 +01:00
|
|
|
//search for the file in all prefixes and in all possible paths for each prefix
|
|
|
|
//even if it's a big nested loop, usually there is one prefix and one location
|
|
|
|
//so shouldn't cause too much disk access
|
2010-12-15 07:29:36 +01:00
|
|
|
QStringList prefixes = d->structure->contentsPrefixPaths();
|
|
|
|
if (prefixes.isEmpty()) {
|
|
|
|
prefixes << QString();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (const char *dir, d->structure->requiredDirectories()) {
|
2010-11-03 23:12:30 +01:00
|
|
|
bool failed = true;
|
|
|
|
foreach (const QString &path, d->structure->searchPath(dir)) {
|
2010-12-15 07:29:36 +01:00
|
|
|
foreach (const QString &prefix, prefixes) {
|
2010-11-04 22:54:14 +01:00
|
|
|
if (QFile::exists(d->structure->path() + prefix + path)) {
|
2010-11-04 20:18:32 +01:00
|
|
|
failed = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!failed) {
|
2010-11-03 23:12:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
2008-11-04 00:08:39 +01:00
|
|
|
kWarning() << "Could not find required directory" << dir;
|
|
|
|
d->valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const char *file, d->structure->requiredFiles()) {
|
2010-11-03 23:12:30 +01:00
|
|
|
bool failed = true;
|
|
|
|
foreach (const QString &path, d->structure->searchPath(file)) {
|
2010-12-15 07:29:36 +01:00
|
|
|
foreach (const QString &prefix, prefixes) {
|
2010-11-04 22:54:14 +01:00
|
|
|
if (QFile::exists(d->structure->path() + prefix + path)) {
|
2010-11-04 20:18:32 +01:00
|
|
|
failed = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!failed) {
|
2010-11-03 23:12:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
kWarning() << "Could not find required file" << file;
|
2008-11-04 00:08:39 +01:00
|
|
|
d->valid = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Package::filePath(const char *fileType, const QString &filename) const
|
|
|
|
{
|
|
|
|
if (!d->valid) {
|
2010-09-05 00:50:50 +02:00
|
|
|
//kDebug() << "package is not valid";
|
2008-11-04 00:08:39 +01:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2010-11-03 23:12:30 +01:00
|
|
|
QStringList paths;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-03-09 06:57:57 +01:00
|
|
|
if (qstrlen(fileType) != 0) {
|
2010-11-03 23:12:30 +01:00
|
|
|
paths = d->structure->searchPath(fileType);
|
2010-03-09 06:57:57 +01:00
|
|
|
|
2010-11-03 23:12:30 +01:00
|
|
|
if (paths.isEmpty()) {
|
2010-09-05 00:50:50 +02:00
|
|
|
//kDebug() << "no matching path came of it, while looking for" << fileType << filename;
|
2010-03-09 06:57:57 +01:00
|
|
|
return QString();
|
|
|
|
}
|
2010-11-04 20:18:32 +01:00
|
|
|
} else {
|
2010-12-15 08:13:20 +01:00
|
|
|
//when filetype is empty paths is always empty, so try with an empty string
|
2010-11-04 20:18:32 +01:00
|
|
|
paths << QString();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-11-04 20:18:32 +01:00
|
|
|
//Nested loop, but in the medium case resolves to just one iteration
|
2010-12-15 07:29:36 +01:00
|
|
|
QStringList prefixes = d->structure->contentsPrefixPaths();
|
|
|
|
if (prefixes.isEmpty()) {
|
|
|
|
prefixes << QString();
|
|
|
|
}
|
|
|
|
|
2010-12-15 08:13:20 +01:00
|
|
|
//kDebug() << "prefixes:" << prefixes.count() << prefixes;
|
2010-12-15 07:29:36 +01:00
|
|
|
foreach (const QString &contentsPrefix, prefixes) {
|
2010-11-04 22:54:14 +01:00
|
|
|
const QString prefix(d->structure->path() + contentsPrefix);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-11-04 20:18:32 +01:00
|
|
|
foreach (const QString &path, paths) {
|
|
|
|
QString file = prefix + path;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-11-04 20:18:32 +01:00
|
|
|
if (!filename.isEmpty()) {
|
|
|
|
file.append("/").append(filename);
|
2010-11-03 23:12:30 +01:00
|
|
|
}
|
|
|
|
|
2010-12-15 08:13:20 +01:00
|
|
|
//kDebug() << "testing" << file << QFile::exists("/bin/ls") << QFile::exists(file);
|
2010-11-04 20:18:32 +01:00
|
|
|
if (QFile::exists(file)) {
|
|
|
|
if (d->structure->allowExternalPaths()) {
|
2010-12-15 08:13:20 +01:00
|
|
|
//kDebug() << "found" << file;
|
2010-11-04 20:18:32 +01:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure that we don't return files outside of our base path
|
|
|
|
// due to symlink or ../ games
|
|
|
|
QDir dir(file);
|
|
|
|
QString canonicalized = dir.canonicalPath() + QDir::separator();
|
|
|
|
|
2010-12-15 08:13:20 +01:00
|
|
|
//kDebug() << "testing that" << canonicalized << "is in" << d->structure->path();
|
2010-11-04 20:18:32 +01:00
|
|
|
if (canonicalized.startsWith(d->structure->path())) {
|
2010-12-15 08:13:20 +01:00
|
|
|
//kDebug() << "found" << file;
|
2010-11-04 20:18:32 +01:00
|
|
|
return file;
|
|
|
|
}
|
2010-11-03 23:12:30 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 08:13:20 +01:00
|
|
|
//kDebug() << fileType << filename << "does not exist in" << prefixes << "at root" << d->structure->path();
|
2008-11-04 00:08:39 +01:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Package::filePath(const char *fileType) const
|
|
|
|
{
|
|
|
|
return filePath(fileType, QString());
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Package::entryList(const char *fileType) const
|
|
|
|
{
|
|
|
|
if (!d->valid) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
2009-04-07 07:42:30 +02:00
|
|
|
return d->structure->entryList(fileType);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PackageMetadata Package::metadata() const
|
|
|
|
{
|
2010-09-03 21:44:28 +02:00
|
|
|
if (d->structure) {
|
|
|
|
return d->structure->metadata();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PackageMetadata();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-05-13 01:05:40 +02:00
|
|
|
void Package::setPath(const QString &path)
|
|
|
|
{
|
2010-09-03 21:44:28 +02:00
|
|
|
if (d->structure) {
|
|
|
|
d->structure->setPath(path);
|
|
|
|
d->valid = !d->structure->path().isEmpty();
|
|
|
|
}
|
2009-05-13 01:05:40 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
const QString Package::path() const
|
|
|
|
{
|
2010-09-03 21:44:28 +02:00
|
|
|
return d->structure ? d->structure->path() : QString();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const PackageStructure::Ptr Package::structure() const
|
|
|
|
{
|
|
|
|
return d->structure;
|
|
|
|
}
|
|
|
|
|
2009-09-21 23:37:44 +02:00
|
|
|
#ifdef QCA2_FOUND
|
|
|
|
void PackagePrivate::updateHash(const QString &basePath, const QString &subPath, const QDir &dir, QCA::Hash &hash)
|
|
|
|
{
|
|
|
|
// hash is calculated as a function of:
|
|
|
|
// * files ordered alphabetically by name, with each file's:
|
|
|
|
// * path relative to the content root
|
|
|
|
// * file data
|
|
|
|
// * directories ordered alphabetically by name, with each dir's:
|
|
|
|
// * path relative to the content root
|
|
|
|
// * file listing (recursing)
|
|
|
|
// symlinks (in both the file and dir case) are handled by adding
|
|
|
|
// the name of the symlink itself and the abs path of what it points to
|
|
|
|
|
|
|
|
const QDir::SortFlags sorting = QDir::Name | QDir::IgnoreCase;
|
|
|
|
const QDir::Filters filters = QDir::Hidden | QDir::System | QDir::NoDotAndDotDot;
|
|
|
|
foreach (const QString &file, dir.entryList(QDir::Files | filters, sorting)) {
|
|
|
|
if (!subPath.isEmpty()) {
|
|
|
|
hash.update(subPath.toUtf8());
|
|
|
|
}
|
|
|
|
|
|
|
|
hash.update(file.toUtf8());
|
|
|
|
|
|
|
|
QFileInfo info(dir.path() + '/' + file);
|
|
|
|
if (info.isSymLink()) {
|
|
|
|
hash.update(info.symLinkTarget().toUtf8());
|
|
|
|
} else {
|
|
|
|
QFile f(info.filePath());
|
|
|
|
if (f.open(QIODevice::ReadOnly)) {
|
|
|
|
while (!f.atEnd()) {
|
|
|
|
hash.update(f.read(1024));
|
|
|
|
}
|
|
|
|
} else {
|
2009-09-21 23:48:19 +02:00
|
|
|
kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading. "
|
|
|
|
<< "permissions fail?" << info.permissions() << info.isFile();
|
2009-09-21 23:37:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QString &subDirPath, dir.entryList(QDir::Dirs | filters, sorting)) {
|
|
|
|
const QString relativePath = subPath + subDirPath + '/';
|
|
|
|
hash.update(relativePath.toUtf8());
|
|
|
|
|
|
|
|
QDir subDir(dir.path());
|
|
|
|
subDir.cd(subDirPath);
|
|
|
|
|
|
|
|
if (subDir.path() != subDir.canonicalPath()) {
|
|
|
|
hash.update(subDir.canonicalPath().toUtf8());
|
|
|
|
} else {
|
|
|
|
updateHash(basePath, relativePath, subDir, hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-21 23:48:19 +02:00
|
|
|
QString Package::contentsHash() const
|
2009-09-21 23:37:44 +02:00
|
|
|
{
|
|
|
|
#ifdef QCA2_FOUND
|
2010-09-03 21:44:28 +02:00
|
|
|
if (!d->valid) {
|
|
|
|
kWarning() << "can not create hash due to Package being invalid";
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-09-21 23:37:44 +02:00
|
|
|
if (!QCA::isSupported("sha1")) {
|
|
|
|
kWarning() << "can not create hash for" << path() << "due to no SHA1 support in QCA2";
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QCA::Hash hash("sha1");
|
2009-09-21 23:48:19 +02:00
|
|
|
QString metadataPath = d->structure->path() + "metadata.desktop";
|
|
|
|
if (QFile::exists(metadataPath)) {
|
|
|
|
QFile f(metadataPath);
|
|
|
|
if (f.open(QIODevice::ReadOnly)) {
|
|
|
|
while (!f.atEnd()) {
|
|
|
|
hash.update(f.read(1024));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kWarning() << "could not add" << f.fileName() << "to the hash; file could not be opened for reading.";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kWarning() << "no metadata at" << metadataPath;
|
|
|
|
}
|
|
|
|
|
2010-12-15 07:29:36 +01:00
|
|
|
QStringList prefixes = d->structure->contentsPrefixPaths();
|
|
|
|
if (prefixes.isEmpty()) {
|
|
|
|
prefixes << QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QString prefix, prefixes) {
|
2010-11-04 22:54:14 +01:00
|
|
|
const QString basePath = d->structure->path() + prefix;
|
2010-11-04 20:18:32 +01:00
|
|
|
QDir dir(basePath);
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
d->updateHash(basePath, QString(), dir, hash);
|
|
|
|
}
|
2009-09-21 23:37:44 +02:00
|
|
|
return QCA::arrayToHex(hash.final().toByteArray());
|
|
|
|
#else
|
|
|
|
// no QCA2!
|
|
|
|
kWarning() << "can not create hash for" << path() << "due to no cryptographic support (QCA2)";
|
|
|
|
return QString();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//TODO: provide a version of this that allows one to ask for certain types of packages, etc?
|
|
|
|
// should we be using KService here instead/as well?
|
|
|
|
QStringList Package::listInstalled(const QString &packageRoot) // static
|
|
|
|
{
|
|
|
|
QDir dir(packageRoot);
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList packages;
|
|
|
|
|
|
|
|
foreach (const QString &sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) {
|
|
|
|
QString metadata = packageRoot + '/' + sdir + "/metadata.desktop";
|
|
|
|
if (QFile::exists(metadata)) {
|
|
|
|
PackageMetadata m(metadata);
|
|
|
|
packages << m.pluginName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return packages;
|
|
|
|
}
|
|
|
|
|
2009-01-05 19:49:54 +01:00
|
|
|
QStringList Package::listInstalledPaths(const QString &packageRoot) // static
|
|
|
|
{
|
|
|
|
QDir dir(packageRoot);
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
return QStringList();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList packages;
|
|
|
|
|
|
|
|
foreach (const QString &sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) {
|
|
|
|
QString metadata = packageRoot + '/' + sdir + "/metadata.desktop";
|
|
|
|
if (QFile::exists(metadata)) {
|
|
|
|
packages << sdir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return packages;
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
PackagePrivate::PackagePrivate(const PackageStructure::Ptr st, const QString &p)
|
|
|
|
: structure(st),
|
|
|
|
service(0)
|
|
|
|
{
|
2010-09-03 21:44:28 +02:00
|
|
|
if (structure) {
|
|
|
|
structure->setPath(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = structure && !structure->path().isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
PackagePrivate::PackagePrivate(const PackagePrivate &other)
|
|
|
|
: structure(other.structure),
|
|
|
|
service(other.service),
|
|
|
|
valid(other.valid)
|
|
|
|
{
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PackagePrivate::~PackagePrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-03 21:44:28 +02:00
|
|
|
PackagePrivate &PackagePrivate::operator=(const PackagePrivate &rhs)
|
|
|
|
{
|
|
|
|
structure = rhs.structure;
|
|
|
|
service = rhs.service;
|
|
|
|
valid = rhs.valid;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
void PackagePrivate::publish(AnnouncementMethods methods)
|
|
|
|
{
|
2010-09-03 21:44:28 +02:00
|
|
|
if (!structure) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:34:34 +02:00
|
|
|
if (!service) {
|
2009-09-02 04:27:16 +02:00
|
|
|
service = new PlasmoidService(structure->path());
|
|
|
|
}
|
|
|
|
|
2009-10-20 01:04:42 +02:00
|
|
|
QString resourceName =
|
2009-09-02 04:27:16 +02:00
|
|
|
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
|
2009-10-20 01:04:42 +02:00
|
|
|
"%1 on %2", structure->metadata().name(), QHostInfo::localHostName());
|
2009-09-02 04:27:16 +02:00
|
|
|
kDebug() << "publishing package under name " << resourceName;
|
|
|
|
service->d->publish(methods, resourceName, structure->metadata());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PackagePrivate::unpublish()
|
|
|
|
{
|
|
|
|
if (service) {
|
|
|
|
service->d->unpublish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PackagePrivate::isPublished() const
|
|
|
|
{
|
|
|
|
if (service) {
|
|
|
|
return service->d->isPublished();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // Namespace
|