From 98e4e20fe2928fc18513a1851e7940eddfce7b15 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 20 Jul 2007 04:23:27 +0000 Subject: [PATCH] * add createPackage to Package * remove Packager since it has no point in life anymore svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=690116 --- CMakeLists.txt | 2 - package.cpp | 54 ++++++++++++++++++++++++ package.h | 24 +++++++++-- packager.cpp | 109 ------------------------------------------------- packager.h | 58 -------------------------- 5 files changed, 75 insertions(+), 172 deletions(-) delete mode 100644 packager.cpp delete mode 100644 packager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fc0563c1..8613c480c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/package.cpp b/package.cpp index abb7690c4..1e3a64d94 100644 --- a/package.cpp +++ b/package.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #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 diff --git a/package.h b/package.h index e4b20ef50..079742ed8 100644 --- a/package.h +++ b/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; diff --git a/packager.cpp b/packager.cpp deleted file mode 100644 index d44eb65fc..000000000 --- a/packager.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** -* Copyright (C) 2007 by Riccardo Iaconelli * -* * -* 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 -#include -#include -#include -#include -#include -#include -#include - -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 diff --git a/packager.h b/packager.h deleted file mode 100644 index 6765436b3..000000000 --- a/packager.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** -* Copyright (C) 2007 by Riccardo Iaconelli * -* * -* 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 - -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