* add createPackage to Package
* remove Packager since it has no point in life anymore svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=690116
This commit is contained in:
parent
0f2acacbe7
commit
98e4e20fe2
@ -4,7 +4,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${KDEBASE_WORKSPACE_SOURCE_DIR}/
|
||||
|
||||
set(plasmagik_SRCS
|
||||
packagemetadata.cpp
|
||||
packager.cpp
|
||||
packagestructure.cpp
|
||||
package.cpp
|
||||
)
|
||||
@ -49,7 +48,6 @@ install(TARGETS plasma DESTINATION ${LIB_INSTALL_DIR})
|
||||
|
||||
set(plasmagik_HEADERS
|
||||
packagemetadata.h
|
||||
packager.h
|
||||
packagestructure.h
|
||||
package.h
|
||||
)
|
||||
|
54
package.cpp
54
package.cpp
@ -27,6 +27,7 @@
|
||||
#include <KIO/Job>
|
||||
#include <KPluginInfo>
|
||||
#include <KStandardDirs>
|
||||
#include <KTemporaryFile>
|
||||
#include <KZip>
|
||||
|
||||
#include "package.h"
|
||||
@ -244,4 +245,57 @@ bool Package::installPackage(const QString& package,
|
||||
return job->exec();
|
||||
}
|
||||
|
||||
bool Package::createPackage(const PackageMetadata & metadata,
|
||||
const QString& source,
|
||||
const QString& destination)
|
||||
{
|
||||
if (!metadata.isComplete()) {
|
||||
kWarning(550) << "Metadata file is not complete" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
KTemporaryFile metadataFile;
|
||||
metadataFile.open();
|
||||
metadata.write(metadataFile.fileName());
|
||||
|
||||
KTemporaryFile releaseNotes;
|
||||
//We just write the content of the QString containing the metadata in an
|
||||
//empty temporary file that we will package with the name metadata.desktop
|
||||
if (releaseNotes.open()) {
|
||||
QTextStream out(&releaseNotes);
|
||||
if (metadata.releaseNotes().isEmpty()) {
|
||||
out << metadata.releaseNotes();
|
||||
} else {
|
||||
out << "NO_RELEASE_NOTES";
|
||||
}
|
||||
}
|
||||
|
||||
//OK, we've got the temporary file with the metadata in it.
|
||||
//Now we just need to put everything into a zip archive.
|
||||
KZip creation(destination);
|
||||
creation.setCompression(KZip::NoCompression);
|
||||
|
||||
if (!creation.open(QIODevice::WriteOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
creation.addLocalFile(metadataFile.fileName(), "metadata.desktop");
|
||||
creation.addLocalFile(releaseNotes.fileName(), "notes.txt");
|
||||
|
||||
if (!metadata.icon().isEmpty()) {
|
||||
//TODO: just one icon?
|
||||
creation.addLocalFile(metadata.icon(), "icon.png");
|
||||
}
|
||||
|
||||
if (!metadata.preview().isEmpty()) {
|
||||
//TODO: just one icon?
|
||||
creation.addLocalFile(metadata.preview(), "preview.png");
|
||||
}
|
||||
|
||||
creation.addLocalDirectory(source, "contents/");
|
||||
creation.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // Namespace
|
||||
|
24
package.h
24
package.h
@ -31,6 +31,7 @@ namespace Plasma
|
||||
* @brief object representing an installed Plasmagik package
|
||||
**/
|
||||
|
||||
class PackageMetadata;
|
||||
class PackageStructure;
|
||||
|
||||
class PLASMA_EXPORT Package
|
||||
@ -83,25 +84,42 @@ class PLASMA_EXPORT Package
|
||||
QStringList entryList(const char* fileType);
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns a list of all installed packages
|
||||
*
|
||||
* @param packageRoot path to the directory where Plasmagik packages
|
||||
* have been installed to
|
||||
* @return a list of installed Plasmagik packages
|
||||
**/
|
||||
static QStringList knownPackages(const QString& packageRoot);
|
||||
static QStringList knownPackages(const QString &packageRoot);
|
||||
|
||||
/**
|
||||
* Installs a package.
|
||||
*
|
||||
* @param package path to the Plasmagik package
|
||||
* @param packageRoot path to the directory where the package should be
|
||||
* installed to
|
||||
* @return true on successful installation, false otherwise
|
||||
**/
|
||||
static bool installPackage(const QString& package, const QString& packageRoot);
|
||||
static bool installPackage(const QString &package,
|
||||
const QString &packageRoot);
|
||||
|
||||
//TODO implement uninstall
|
||||
//static bool uninstallPackage(const QString& package, const QString& packageRoot);
|
||||
|
||||
/**
|
||||
* Creates a package based on the metadata from the files contained
|
||||
* in the source directory
|
||||
*
|
||||
* @arg metadata description of the package to create
|
||||
* @arg source path to local directory containing the individual
|
||||
* files to be added to the package
|
||||
* @arg destination path to local directory where the package should
|
||||
* be created
|
||||
**/
|
||||
static bool createPackage(const PackageMetadata &metadata,
|
||||
const QString &source,
|
||||
const QString &destination);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(Package)
|
||||
class Private;
|
||||
|
109
packager.cpp
109
packager.cpp
@ -1,109 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2007 by Riccardo Iaconelli <ruphy@fsfe.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 <QtGui>
|
||||
#include <KTemporaryFile>
|
||||
#include <KDebug>
|
||||
#include <KZip>
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
#include <packagemetadata.h>
|
||||
#include <packager.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Packager::Private
|
||||
{
|
||||
public:
|
||||
PackageMetadata* metadata;
|
||||
};
|
||||
|
||||
Packager::Packager(PackageMetadata *metadata)
|
||||
: d(new Private)
|
||||
{
|
||||
d->metadata = metadata;
|
||||
}
|
||||
|
||||
Packager::~Packager()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
const PackageMetadata* Packager::metadata()
|
||||
{
|
||||
return d->metadata;
|
||||
}
|
||||
|
||||
void Packager::setMetadata(PackageMetadata *metadata)
|
||||
{
|
||||
d->metadata = metadata;
|
||||
}
|
||||
|
||||
bool Packager::createPackage(const QString& destination, const QString& source)
|
||||
{
|
||||
if (!d->metadata->isComplete()) {
|
||||
kWarning(550) << "Metadata file is not complete" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
KTemporaryFile metadataFile;
|
||||
metadataFile.open();
|
||||
d->metadata->write(metadataFile.fileName());
|
||||
|
||||
KTemporaryFile releaseNotes;
|
||||
//We just write the content of the QString containing the metadata in an
|
||||
//empty temporary file that we will package with the name metadata.desktop
|
||||
if (releaseNotes.open()) {
|
||||
QTextStream out(&releaseNotes);
|
||||
if (d->metadata->releaseNotes().isEmpty()) {
|
||||
out << d->metadata->releaseNotes();
|
||||
} else {
|
||||
out << "NO_RELEASE_NOTES";
|
||||
}
|
||||
}
|
||||
|
||||
//OK, we've got the temporary file with the metadata in it.
|
||||
//Now we just need to put everything into a zip archive.
|
||||
KZip creation(destination);
|
||||
creation.setCompression(KZip::NoCompression);
|
||||
|
||||
if (!creation.open(QIODevice::WriteOnly)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
creation.addLocalFile(metadataFile.fileName(), "metadata.desktop");
|
||||
creation.addLocalFile(releaseNotes.fileName(), "notes.txt");
|
||||
|
||||
if (!d->metadata->icon().isEmpty()) {
|
||||
//TODO: just one icon?
|
||||
creation.addLocalFile(d->metadata->icon(), "icon.png");
|
||||
}
|
||||
|
||||
if (!d->metadata->preview().isEmpty()) {
|
||||
//TODO: just one icon?
|
||||
creation.addLocalFile(d->metadata->preview(), "preview.png");
|
||||
}
|
||||
|
||||
creation.addLocalDirectory(source, "contents/");
|
||||
creation.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
58
packager.h
58
packager.h
@ -1,58 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2007 by Riccardo Iaconelli <ruphy@fsfe.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. *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef PACKAGER_H
|
||||
#define PACKAGER_H
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class KTemporaryFile;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class PackageMetadata;
|
||||
class PackagerPrivate;
|
||||
|
||||
class PLASMA_EXPORT Packager
|
||||
{
|
||||
public:
|
||||
Packager(PackageMetadata *metadata);
|
||||
~Packager();
|
||||
|
||||
void setMetadata(PackageMetadata *metadata);
|
||||
const PackageMetadata* metadata();
|
||||
|
||||
// If Metadata::isComplete() returns false, the packaging won't be done
|
||||
// returns: true if successful, false otherwise
|
||||
/**
|
||||
* Creates a package of the contents
|
||||
*
|
||||
* @arg destination the path of the file to create the package as
|
||||
* @arg source the directory containing the contents to package up
|
||||
**/
|
||||
bool createPackage(const QString& destination, const QString& source);
|
||||
|
||||
private:
|
||||
KTemporaryFile* generateMetadata();
|
||||
class Private;
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user