2007-06-17 02:25:16 +02:00
|
|
|
/******************************************************************************
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@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. *
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2008-08-06 11:19:29 +02:00
|
|
|
#ifndef PLASMA_PACKAGESTRUCTURE_H
|
|
|
|
#define PLASMA_PACKAGESTRUCTURE_H
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2007-07-15 00:40:00 +02:00
|
|
|
#include <QtCore/QStringList>
|
2008-02-26 05:07:07 +01:00
|
|
|
#include <QtCore/QSharedData>
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-03-02 03:18:10 +01:00
|
|
|
#include <KDE/KGenericFactory>
|
|
|
|
#include <KDE/KLocale>
|
|
|
|
#include <KDE/KSharedPtr>
|
2008-02-26 02:46:17 +01:00
|
|
|
|
2008-07-17 18:26:29 +02:00
|
|
|
#include <plasma/version.h>
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
class KConfigBase;
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class PackageStructurePrivate;
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
/**
|
2008-08-25 19:47:48 +02:00
|
|
|
* @class PackageStructure plasma/packagestructure.h <Plasma/PackageStructure>
|
|
|
|
*
|
|
|
|
* @short A description of the expected file structure of a given package type
|
2007-06-17 02:25:16 +02:00
|
|
|
*
|
|
|
|
* PackageStructure defines what is in a package. This information is used
|
|
|
|
* to create packages and provides a way to programatically refer to contents.
|
|
|
|
*
|
|
|
|
* An example usage of this class might be:
|
|
|
|
*
|
|
|
|
@code
|
|
|
|
PackageStructure structure;
|
|
|
|
|
2007-06-17 03:04:59 +02:00
|
|
|
structure.addDirectoryDefinition("images", "pics/", i18n("Images"));
|
2007-06-17 02:25:16 +02:00
|
|
|
QStringList mimetypes;
|
|
|
|
mimetypes << "image/svg" << "image/png" << "image/jpeg";
|
|
|
|
structure.setMimetypes("images", mimetypes);
|
|
|
|
|
|
|
|
structure.addDirectoryDefinition("scripts", "code/", i18n("Executable Scripts"));
|
|
|
|
mimetypes.clear();
|
|
|
|
mimetypes << "text/\*";
|
|
|
|
structure.setMimetypes("scripts", mimetypes);
|
|
|
|
|
|
|
|
structure.addFileDefinition("mainscript", "code/main.js", i18n("Main Script File"));
|
|
|
|
structure.setRequired("mainscript", true);
|
|
|
|
@endcode
|
|
|
|
* One may also choose to create a subclass of PackageStructure and include the setup
|
|
|
|
* in the constructor.
|
|
|
|
*
|
|
|
|
* Either way, PackageStructure creates a sort of "contract" between the packager and
|
|
|
|
* the application which is also self-documenting.
|
|
|
|
**/
|
2008-02-26 05:07:07 +01:00
|
|
|
class PLASMA_EXPORT PackageStructure : public QObject, public QSharedData
|
2007-06-17 02:25:16 +02:00
|
|
|
{
|
2008-02-26 05:07:07 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
public:
|
2008-02-26 05:07:07 +01:00
|
|
|
typedef KSharedPtr<PackageStructure> Ptr;
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
/**
|
|
|
|
* Default constructor for a package structure definition
|
|
|
|
*
|
|
|
|
* @arg type the type of package. This is often application specific.
|
|
|
|
**/
|
2008-02-26 05:07:07 +01:00
|
|
|
explicit PackageStructure(QObject *parent = 0, const QString &type = i18n("Invalid"));
|
2008-02-26 02:46:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
**/
|
|
|
|
virtual ~PackageStructure();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator
|
|
|
|
**/
|
|
|
|
PackageStructure& operator=(const PackageStructure& rhs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a package format by name.
|
|
|
|
*
|
|
|
|
* @arg format If not empty, attempts to locate the given format, either
|
|
|
|
* from built-ins or via plugins.
|
|
|
|
* @return a package that matches the format, if available. The caller
|
|
|
|
* is responsible for deleting the object.
|
|
|
|
*/
|
2008-02-28 04:53:26 +01:00
|
|
|
static PackageStructure::Ptr load(const QString &packageFormat);
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of package this structure describes
|
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QString type() const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The directories defined for this package
|
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> directories() const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2007-07-20 05:21:40 +02:00
|
|
|
/**
|
|
|
|
* The required directories defined for this package
|
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> requiredDirectories() const;
|
2007-07-20 05:21:40 +02:00
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
/**
|
2007-10-22 03:29:27 +02:00
|
|
|
* The individual files, by key, that are defined for this package
|
2007-06-17 02:25:16 +02:00
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> files() const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2007-07-20 05:21:40 +02:00
|
|
|
/**
|
2007-10-22 03:29:27 +02:00
|
|
|
* The individual required files, by key, that are defined for this package
|
2007-07-20 05:21:40 +02:00
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QList<const char*> requiredFiles() const;
|
2007-07-20 05:21:40 +02:00
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
/**
|
|
|
|
* Adds a directory to the structure of the package. It is added as
|
|
|
|
* a not-required element with no associated mimetypes.
|
|
|
|
*
|
|
|
|
* @param key used as an internal label for this directory
|
2008-09-25 17:05:22 +02:00
|
|
|
* @param path the path within the package for this directory
|
2007-06-17 02:25:16 +02:00
|
|
|
* @param name the user visible (translated) name for the directory
|
|
|
|
**/
|
|
|
|
void addDirectoryDefinition(const char* key, const QString& path, const QString& name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a file to the structure of the package. It is added as
|
|
|
|
* a not-required element with no associated mimetypes.
|
|
|
|
*
|
|
|
|
* @param key used as an internal label for this file
|
2008-09-25 17:05:22 +02:00
|
|
|
* @param path the path within the package for this file
|
2007-06-17 02:25:16 +02:00
|
|
|
* @param name the user visible (translated) name for the file
|
|
|
|
**/
|
|
|
|
void addFileDefinition(const char* key, const QString& path, const QString& name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return path relative to the package root for the given entry
|
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QString path(const char* key) const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return user visible name for the given entry
|
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QString name(const char* key) const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether or not a given part of the structure is required or not.
|
|
|
|
* The path must already have been added using addDirectoryDefinition
|
|
|
|
* or addFileDefinition.
|
|
|
|
*
|
|
|
|
* @param path the path of the entry within the package
|
2007-06-17 03:04:59 +02:00
|
|
|
* @param required true if this entry is required, false if not
|
2007-06-17 02:25:16 +02:00
|
|
|
*/
|
|
|
|
void setRequired(const char* key, bool required);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the item at path exists and is required
|
|
|
|
**/
|
2008-04-26 17:26:40 +02:00
|
|
|
bool isRequired(const char* key) const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2007-06-17 03:04:59 +02:00
|
|
|
/**
|
|
|
|
* Defines the default mimetypes for any definitions that do not have
|
|
|
|
* associated mimetypes. Handy for packages with only one or predominantly
|
|
|
|
* one file type.
|
|
|
|
*
|
|
|
|
* @param mimetypes a list of mimetypes
|
|
|
|
**/
|
|
|
|
void setDefaultMimetypes(QStringList mimetypes);
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
/**
|
|
|
|
* Define mimetypes for a given part of the structure
|
|
|
|
* The path must already have been added using addDirectoryDefinition
|
|
|
|
* or addFileDefinition.
|
|
|
|
*
|
|
|
|
* @param path the path of the entry within the package
|
2007-06-17 03:04:59 +02:00
|
|
|
* @param mimetypes a list of mimetypes
|
2007-06-17 02:25:16 +02:00
|
|
|
**/
|
|
|
|
void setMimetypes(const char* key, QStringList mimetypes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the mimetypes associated with the path, if any
|
|
|
|
**/
|
2007-11-26 20:16:40 +01:00
|
|
|
QStringList mimetypes(const char* key) const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-02-28 04:53:26 +01:00
|
|
|
/**
|
|
|
|
* Sets the path to the package. Useful for package formats
|
|
|
|
* which do not have well defined contents prior to installation.
|
|
|
|
*/
|
|
|
|
void setPath(const QString &path);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the path to the package, or QString() if none
|
|
|
|
*/
|
|
|
|
QString path() const;
|
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
/**
|
2008-07-03 07:45:32 +02:00
|
|
|
* Read a package structure from a config file.
|
|
|
|
*/
|
2008-02-26 02:46:17 +01:00
|
|
|
void read(const KConfigBase *config);
|
|
|
|
|
2007-12-02 14:16:39 +01:00
|
|
|
/**
|
2008-07-03 07:45:32 +02:00
|
|
|
* Write this package structure to a config file.
|
|
|
|
*/
|
2007-12-02 14:16:39 +01:00
|
|
|
void write(KConfigBase *config) const;
|
2007-06-17 02:25:16 +02:00
|
|
|
|
2008-02-27 01:51:04 +01:00
|
|
|
/**
|
2008-03-30 01:56:09 +01:00
|
|
|
* Installs a package matching this package structure. By default installs a
|
|
|
|
* native Plasma::Package.
|
2008-02-27 01:51:04 +01:00
|
|
|
*
|
2008-02-28 04:53:26 +01:00
|
|
|
* @param archivePath path to the package archive file
|
2008-02-27 01:51:04 +01:00
|
|
|
* @param packageRoot path to the directory where the package should be
|
|
|
|
* installed to
|
|
|
|
* @return true on successful installation, false otherwise
|
|
|
|
**/
|
2008-02-28 04:53:26 +01:00
|
|
|
virtual bool installPackage(const QString &archivePath, const QString &packageRoot);
|
|
|
|
|
2008-03-30 01:56:09 +01:00
|
|
|
/**
|
|
|
|
* Uninstalls a package matching this package structure.
|
|
|
|
*
|
2008-04-29 02:56:33 +02:00
|
|
|
* @arg packageName the name of the package to remove
|
2008-03-30 01:56:09 +01:00
|
|
|
* @arg packageRoot path to the directory where the package should be installed to
|
|
|
|
* @return true on successful removal of the package, false otherwise
|
|
|
|
*/
|
2008-04-29 02:56:33 +02:00
|
|
|
virtual bool uninstallPackage(const QString& packageName, const QString& packageRoot);
|
2008-03-30 01:56:09 +01:00
|
|
|
|
2008-02-29 09:14:32 +01:00
|
|
|
/**
|
|
|
|
* @return the prefix inserted between the base path and content entries
|
|
|
|
*/
|
|
|
|
QString contentsPrefix() const;
|
|
|
|
|
2008-02-28 04:53:26 +01:00
|
|
|
protected:
|
2008-02-29 09:14:32 +01:00
|
|
|
/**
|
|
|
|
* Sets the prefix that all the contents in this package should
|
|
|
|
* appear under. This defaults to "contents/" and is added automatically
|
|
|
|
* between the base path and the entries as defined by the package
|
|
|
|
* structure
|
|
|
|
*
|
|
|
|
* @arg prefix the directory prefix to use
|
|
|
|
*/
|
|
|
|
void setContentsPrefix(const QString &prefix);
|
|
|
|
|
2008-06-05 21:32:15 +02:00
|
|
|
/**
|
|
|
|
* Called whenever the path changes so that subclasses may take
|
|
|
|
* package specific actions.
|
|
|
|
*/
|
|
|
|
virtual void pathChanged();
|
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
private:
|
2008-07-01 20:56:43 +02:00
|
|
|
PackageStructurePrivate * const d;
|
2007-06-17 02:25:16 +02:00
|
|
|
};
|
|
|
|
|
2008-02-26 05:07:07 +01:00
|
|
|
/**
|
|
|
|
* Register an applet when it is contained in a loadable module
|
|
|
|
*/
|
|
|
|
#define K_EXPORT_PLASMA_PACKAGESTRUCTURE(libname, classname) \
|
|
|
|
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
2008-07-17 18:26:29 +02:00
|
|
|
K_EXPORT_PLUGIN(factory("plasma_packagestructure_" #libname)) \
|
|
|
|
K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
|
2008-02-26 05:07:07 +01:00
|
|
|
|
2007-06-17 02:25:16 +02:00
|
|
|
} // Plasma namespace
|
|
|
|
#endif
|