source: calamares/trunk/fuentes/src/libcalamaresui/modulesystem/Module.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 5.7 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef CALAMARES_MODULE_H
20#define CALAMARES_MODULE_H
21
22#include "UiDllMacro.h"
23
24#include <Typedefs.h>
25
26#include <QStringList>
27#include <QVariant>
28
29
30namespace Calamares
31{
32class Module;
33}
34
35void operator>>( const QVariantMap& moduleDescriptor, Calamares::Module* m );
36
37namespace Calamares
38{
39
40/**
41 * @brief The Module class is a common supertype for Calamares modules.
42 * It enforces a common interface for all the different types of modules, and it
43 * takes care of creating an object of the correct type starting from a module
44 * descriptor structure.
45 */
46class UIDLLEXPORT Module
47{
48public:
49    /**
50     * @brief The Type enum represents the intended functionality of the module
51     * Every module is either a job module or a view module.
52     * A job module is a single Calamares job.
53     * A view module has a UI (one or more view pages) and zero-to-many jobs.
54     */
55    enum Type
56    {
57        Job,
58        View
59    };
60
61    /**
62     * @brief The Interface enum represents the interface through which the module
63     * talks to Calamares.
64     * Not all Type-Interface associations are valid.
65     */
66    enum Interface
67    {
68        QtPluginInterface,
69        PythonInterface,
70        ProcessInterface,
71        PythonQtInterface
72    };
73
74    /**
75     * @brief fromDescriptor creates a new Module object of the correct type.
76     * @param moduleDescriptor a module descriptor, already parsed into a variant map.
77     * @param instanceId the instance id of the new module instance.
78     * @param configFileName the name of the configuration file to read.
79     * @param moduleDirectory the path to the directory with this module's files.
80     * @return a pointer to an object of a subtype of Module.
81     */
82    static Module* fromDescriptor( const QVariantMap& moduleDescriptor,
83                                   const QString& instanceId,
84                                   const QString& configFileName,
85                                   const QString& moduleDirectory );
86    virtual ~Module();
87
88    /**
89     * @brief name returns the name of this module.
90     * @return a string with this module's name.
91     */
92    virtual QString name() const final;
93
94    /**
95     * @brief instanceId returns the instance id of this module.
96     * @return a string with this module's instance id.
97     */
98    virtual QString instanceId() const final;
99
100    /**
101     * @brief instanceKey returns the instance key of this module.
102     * @return a string with the instance key.
103     * A module instance's instance key is modulename\@instanceid.
104     * For instance, "partition\@partition" (default configuration) or
105     * "locale\@someconfig" (custom configuration)
106     */
107    virtual QString instanceKey() const final;
108
109    /**
110     * @brief requiredModules a list of names of modules required by this one.
111     * @return the list of names.
112     * The module dependencies system is currently incomplete and unused.
113     */
114    virtual QStringList requiredModules() const;
115
116    /**
117     * @brief location returns the full path of this module's directory.
118     * @return the path.
119     */
120    virtual QString location() const final;
121
122    /**
123     * @brief type returns the Type of this module object.
124     * @return the type enum value.
125     */
126    virtual Type type() const = 0;
127
128    /**
129     * @brief typeString returns a user-visible string for the module's type.
130     * @return the type string.
131     */
132    virtual QString typeString() const;
133
134    /**
135     * @brief interface the Interface used by this module.
136     * @return the interface enum value.
137     */
138    virtual Interface interface() const = 0;
139
140    /**
141     * @brief interface returns a user-visible string for the module's interface.
142     * @return the interface string.
143     */
144    virtual QString interfaceString() const;
145
146    /**
147     * @brief isLoaded reports on the loaded status of a module.
148     * @return true if the module's loading phase has finished, otherwise false.
149     */
150    virtual bool isLoaded() const;
151
152    /**
153     * @brief loadSelf initialized the module.
154     * Subclasses must reimplement this depending on the module type and interface.
155     */
156    virtual void loadSelf() = 0;
157
158    /**
159     * @brief jobs returns any jobs exposed by this module.
160     * @return a list of jobs (can be empty).
161     */
162    virtual JobList jobs() const = 0;
163
164    /**
165     * @brief configurationMap returns the contents of the configuration file for
166     * this module instance.
167     * @return the instance's configuration, already parsed from YAML into a variant map.
168     */
169    QVariantMap configurationMap();
170
171protected:
172    explicit Module();
173    virtual void initFrom( const QVariantMap& moduleDescriptor );
174    bool m_loaded;
175    QVariantMap m_configurationMap;
176
177private:
178    void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
179    QString m_name;
180    QStringList m_requiredModules;
181    QString m_directory;
182    QString m_instanceId;
183
184    friend void ::operator>>( const QVariantMap& moduleDescriptor,
185                              Calamares::Module* m );
186};
187
188}
189
190#endif // CALAMARES_MODULE_H
Note: See TracBrowser for help on using the repository browser.