1
/******************************************************************************
2
* Copyright 2007 by Aaron Seigo <aseigo@kde.org> *
4
* This library is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU Library General Public *
6
* License as published by the Free Software Foundation; either *
7
* version 2 of the License, or (at your option) any later version. *
9
* This library is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12
* Library General Public License for more details. *
14
* You should have received a copy of the GNU Library General Public License *
15
* along with this library; see the file COPYING.LIB. If not, write to *
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17
* Boston, MA 02110-1301, USA. *
18
*******************************************************************************/
20
#ifndef PACKAGESTRUCTURE_H
21
#define PACKAGESTRUCTURE_H
23
#include <QtCore/QStringList>
25
#include <plasma/plasma_export.h>
31
* @brief A description of the expected file structure of a given package type
33
* PackageStructure defines what is in a package. This information is used
34
* to create packages and provides a way to programatically refer to contents.
36
* An example usage of this class might be:
39
PackageStructure structure;
41
structure.addDirectoryDefinition("images", "pics/", i18n("Images"));
42
QStringList mimetypes;
43
mimetypes << "image/svg" << "image/png" << "image/jpeg";
44
structure.setMimetypes("images", mimetypes);
46
structure.addDirectoryDefinition("scripts", "code/", i18n("Executable Scripts"));
48
mimetypes << "text/\*";
49
structure.setMimetypes("scripts", mimetypes);
51
structure.addFileDefinition("mainscript", "code/main.js", i18n("Main Script File"));
52
structure.setRequired("mainscript", true);
54
* One may also choose to create a subclass of PackageStructure and include the setup
57
* Either way, PackageStructure creates a sort of "contract" between the packager and
58
* the application which is also self-documenting.
60
class PLASMA_EXPORT PackageStructure
64
* Default constructor for a package structure definition
66
* @arg type the type of package. This is often application specific.
68
PackageStructure(const QString &type);
71
* Type of package this structure describes
76
* The directories defined for this package
78
QStringList directories();
81
* The required directories defined for this package
83
QStringList requiredDirectories();
86
* The individual files defined for this package
91
* The individual required files defined for this package
93
QStringList requiredFiles();
96
* Adds a directory to the structure of the package. It is added as
97
* a not-required element with no associated mimetypes.
99
* @param key used as an internal label for this directory
100
* @param path the path within the the package for this directory
101
* @param name the user visible (translated) name for the directory
103
void addDirectoryDefinition(const char* key, const QString& path, const QString& name);
106
* Adds a file to the structure of the package. It is added as
107
* a not-required element with no associated mimetypes.
109
* @param key used as an internal label for this file
110
* @param path the path within the the package for this file
111
* @param name the user visible (translated) name for the file
113
void addFileDefinition(const char* key, const QString& path, const QString& name);
116
* @return path relative to the package root for the given entry
118
QString path(const char* key);
121
* @return user visible name for the given entry
123
QString name(const char* key);
126
* Sets whether or not a given part of the structure is required or not.
127
* The path must already have been added using addDirectoryDefinition
128
* or addFileDefinition.
130
* @param path the path of the entry within the package
131
* @param required true if this entry is required, false if not
133
void setRequired(const char* key, bool required);
136
* @return true if the item at path exists and is required
138
bool required(const char* key);
141
* Defines the default mimetypes for any definitions that do not have
142
* associated mimetypes. Handy for packages with only one or predominantly
145
* @param mimetypes a list of mimetypes
147
void setDefaultMimetypes(QStringList mimetypes);
150
* Define mimetypes for a given part of the structure
151
* The path must already have been added using addDirectoryDefinition
152
* or addFileDefinition.
154
* @param path the path of the entry within the package
155
* @param mimetypes a list of mimetypes
157
void setMimetypes(const char* key, QStringList mimetypes);
160
* @return the mimetypes associated with the path, if any
162
QStringList mimetypes(const char* key);
167
PackageStructure(const PackageStructure& rhs);
172
virtual ~PackageStructure();
175
* Assignment operator
177
PackageStructure& operator=(const PackageStructure& rhs);
184
} // Plasma namespace