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

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

sync with github

File size: 3.2 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 MODULELOADER_H
20#define MODULELOADER_H
21
22#include "Typedefs.h"
23
24#include <QObject>
25#include <QStringList>
26#include <QVariantMap>
27
28namespace Calamares
29{
30
31class Module;
32
33/**
34 * @brief The ModuleManager class is a singleton which manages Calamares modules.
35 *
36 * It goes through the module search directories and reads module metadata. It then
37 * constructs objects of type Module, loads them and makes them accessible by their
38 * instance key.
39 */
40class ModuleManager : public QObject
41{
42    Q_OBJECT
43public:
44    explicit ModuleManager( const QStringList& paths, QObject* parent = nullptr );
45    virtual ~ModuleManager() override;
46
47    static ModuleManager* instance();
48
49    /**
50     * @brief init goes through the module search directories and gets a list of
51     * modules available for loading, along with their metadata.
52     * This information is stored as a map of Module* objects, indexed by name.
53     */
54    void init();
55
56    /**
57     * @brief loadedInstanceKeys returns a list of instance keys for the available
58     * modules.
59     * @return a QStringList with the instance keys.
60     */
61    QStringList loadedInstanceKeys();
62
63    /**
64     * @brief moduleDescriptor returns the module descriptor structure for a given module.
65     * @param name the name of the module for which to return the module descriptor.
66     * @return the module descriptor, as a variant map already parsed from YAML.
67     */
68    QVariantMap moduleDescriptor( const QString& name );
69
70    /**
71     * @brief moduleInstance returns a Module object for a given instance key.
72     * @param instanceKey the instance key for a module instance.
73     * @return a pointer to an object of a subtype of Module.
74     */
75    Module* moduleInstance( const QString& instanceKey );
76
77    /**
78     * @brief loadModules initiates the asynchronous module loading operation.
79     * When this is done, the signal modulesLoaded is emitted.
80     */
81    void loadModules();
82
83signals:
84    void initDone();
85    void modulesLoaded();  /// All of the modules were loaded successfully
86    void modulesFailed( QStringList );   /// .. or not
87
88private slots:
89    void doInit();
90
91private:
92    void checkDependencies();
93
94    QMap< QString, QVariantMap > m_availableDescriptorsByModuleName;
95    QMap< QString, QString > m_moduleDirectoriesByModuleName;
96    QMap< QString, Module* > m_loadedModulesByInstanceKey;
97    const QStringList m_paths;
98
99    static ModuleManager* s_instance;
100};
101
102}
103
104#endif // MODULELOADER_H
Note: See TracBrowser for help on using the repository browser.