2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-06-18 18:05:04 +02:00
|
|
|
*
|
2015-03-10 19:47:39 +01:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2017-11-30 18:01:11 +01:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2014-06-18 18:05:04 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
#ifndef CALAMARES_MODULE_H
|
|
|
|
#define CALAMARES_MODULE_H
|
2014-06-18 18:05:04 +02:00
|
|
|
|
2019-05-07 15:51:23 +02:00
|
|
|
#include "Job.h"
|
2017-11-30 18:42:59 +01:00
|
|
|
#include "Requirement.h"
|
2020-02-17 11:32:28 +01:00
|
|
|
#include "DllMacro.h"
|
2014-06-18 18:05:04 +02:00
|
|
|
|
2020-01-24 12:59:35 +01:00
|
|
|
#include "modulesystem/Descriptor.h"
|
2020-01-12 11:49:10 +01:00
|
|
|
#include "modulesystem/InstanceKey.h"
|
2020-01-24 12:59:35 +01:00
|
|
|
|
2014-06-18 18:05:04 +02:00
|
|
|
#include <QStringList>
|
2014-07-14 18:10:48 +02:00
|
|
|
#include <QVariant>
|
2014-06-18 18:05:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief The Module class is a common supertype for Calamares modules.
|
|
|
|
* It enforces a common interface for all the different types of modules, and it
|
|
|
|
* takes care of creating an object of the correct type starting from a module
|
|
|
|
* descriptor structure.
|
|
|
|
*/
|
2020-02-17 16:52:45 +01:00
|
|
|
class UIDLLEXPORT Module
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
|
|
|
public:
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief The Type enum represents the intended functionality of the module
|
|
|
|
* Every module is either a job module or a view module.
|
|
|
|
* A job module is a single Calamares job.
|
|
|
|
* A view module has a UI (one or more view pages) and zero-to-many jobs.
|
|
|
|
*/
|
2019-05-07 12:33:31 +02:00
|
|
|
enum class Type
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
2014-07-10 12:27:53 +02:00
|
|
|
Job,
|
2014-06-18 18:05:04 +02:00
|
|
|
View
|
|
|
|
};
|
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief The Interface enum represents the interface through which the module
|
|
|
|
* talks to Calamares.
|
|
|
|
* Not all Type-Interface associations are valid.
|
|
|
|
*/
|
2019-05-07 12:33:31 +02:00
|
|
|
enum class Interface
|
2014-06-18 18:05:04 +02:00
|
|
|
{
|
2019-06-27 15:15:47 +02:00
|
|
|
QtPlugin, // Jobs or Views
|
|
|
|
Python, // Jobs only
|
2019-05-07 12:33:31 +02:00
|
|
|
Process, // Deprecated interface
|
|
|
|
PythonQt // Views only, available as enum even if PythonQt isn't used
|
2014-06-18 18:05:04 +02:00
|
|
|
};
|
2014-06-27 13:58:53 +02:00
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief fromDescriptor creates a new Module object of the correct type.
|
|
|
|
* @param moduleDescriptor a module descriptor, already parsed into a variant map.
|
|
|
|
* @param instanceId the instance id of the new module instance.
|
|
|
|
* @param configFileName the name of the configuration file to read.
|
|
|
|
* @param moduleDirectory the path to the directory with this module's files.
|
|
|
|
* @return a pointer to an object of a subtype of Module.
|
|
|
|
*/
|
2020-01-24 12:59:35 +01:00
|
|
|
static Module* fromDescriptor( const ModuleSystem::Descriptor& moduleDescriptor,
|
2015-09-09 19:01:56 +02:00
|
|
|
const QString& instanceId,
|
|
|
|
const QString& configFileName,
|
|
|
|
const QString& moduleDirectory );
|
2017-11-03 15:10:37 +01:00
|
|
|
virtual ~Module();
|
2014-06-27 13:58:53 +02:00
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief name returns the name of this module.
|
|
|
|
* @return a string with this module's name.
|
|
|
|
*/
|
2020-01-12 11:49:10 +01:00
|
|
|
QString name() const { return m_key.module(); }
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief instanceId returns the instance id of this module.
|
|
|
|
* @return a string with this module's instance id.
|
|
|
|
*/
|
2020-01-12 11:49:10 +01:00
|
|
|
QString instanceId() const { return m_key.id(); }
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief instanceKey returns the instance key of this module.
|
|
|
|
* @return a string with the instance key.
|
2017-09-10 13:45:42 +02:00
|
|
|
* A module instance's instance key is modulename\@instanceid.
|
|
|
|
* For instance, "partition\@partition" (default configuration) or
|
|
|
|
* "locale\@someconfig" (custom configuration)
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-24 17:47:06 +01:00
|
|
|
ModuleSystem::InstanceKey instanceKey() const { return m_key; }
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief location returns the full path of this module's directory.
|
|
|
|
* @return the path.
|
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
QString location() const { return m_directory; }
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-12 12:18:13 +01:00
|
|
|
* @brief Is this an emergency module?
|
|
|
|
*
|
|
|
|
* An emergency module is run even if an error occurs
|
|
|
|
* which would terminate Calamares earlier in the same
|
|
|
|
* *exec* block. Emergency modules in later exec blocks
|
|
|
|
* are not run (in the common case where there is only
|
|
|
|
* one exec block, this doesn't really matter).
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
bool isEmergency() const { return m_emergency; }
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-12 12:18:13 +01:00
|
|
|
* @brief isLoaded reports on the loaded status of a module.
|
|
|
|
* @return true if the module's loading phase has finished, otherwise false.
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
bool isLoaded() const { return m_loaded; }
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-12 12:18:13 +01:00
|
|
|
* @brief configurationMap returns the contents of the configuration file for
|
|
|
|
* this module instance.
|
|
|
|
* @return the instance's configuration, already parsed from YAML into a variant map.
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
QVariantMap configurationMap();
|
2017-02-28 18:08:02 +01:00
|
|
|
|
|
|
|
/**
|
2020-01-12 12:18:13 +01:00
|
|
|
* @brief typeString returns a user-visible string for the module's type.
|
|
|
|
* @return the type string.
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
QString typeString() const;
|
2014-06-27 13:58:53 +02:00
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
2020-01-12 12:18:13 +01:00
|
|
|
* @brief interface returns a user-visible string for the module's interface.
|
|
|
|
* @return the interface string.
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
QString interfaceString() const;
|
2014-06-27 13:58:53 +02:00
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief loadSelf initialized the module.
|
|
|
|
* Subclasses must reimplement this depending on the module type and interface.
|
|
|
|
*/
|
2014-06-27 13:58:53 +02:00
|
|
|
virtual void loadSelf() = 0;
|
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
|
|
|
* @brief jobs returns any jobs exposed by this module.
|
|
|
|
* @return a list of jobs (can be empty).
|
|
|
|
*/
|
2017-11-03 15:10:37 +01:00
|
|
|
virtual JobList jobs() const = 0;
|
2014-07-22 16:54:34 +02:00
|
|
|
|
2017-02-28 18:08:02 +01:00
|
|
|
/**
|
2020-01-12 12:18:13 +01:00
|
|
|
* @brief type returns the Type of this module object.
|
|
|
|
* @return the type enum value.
|
2017-02-28 18:08:02 +01:00
|
|
|
*/
|
2020-01-12 12:18:13 +01:00
|
|
|
virtual Type type() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief interface the Interface used by this module.
|
|
|
|
* @return the interface enum value.
|
|
|
|
*/
|
|
|
|
virtual Interface interface() const = 0;
|
2015-03-10 19:47:39 +01:00
|
|
|
|
2017-11-30 18:01:11 +01:00
|
|
|
/**
|
|
|
|
* @brief Check the requirements of this module.
|
|
|
|
*/
|
2017-11-30 18:42:59 +01:00
|
|
|
virtual RequirementsList checkRequirements();
|
2017-11-30 18:01:11 +01:00
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
protected:
|
|
|
|
explicit Module();
|
2020-01-12 12:18:13 +01:00
|
|
|
|
2020-01-12 11:37:22 +01:00
|
|
|
/// @brief For subclasses to read their part of the descriptor
|
|
|
|
virtual void initFrom( const QVariantMap& moduleDescriptor ) = 0;
|
|
|
|
/// @brief Generic part of descriptor reading (and instance id)
|
|
|
|
void initFrom( const QVariantMap& moduleDescriptor, const QString& id );
|
2020-01-12 12:18:13 +01:00
|
|
|
|
2014-07-15 11:27:26 +02:00
|
|
|
QVariantMap m_configurationMap;
|
2014-06-27 13:58:53 +02:00
|
|
|
|
2018-06-15 13:11:17 +02:00
|
|
|
bool m_loaded = false;
|
2018-06-15 15:32:19 +02:00
|
|
|
bool m_emergency = false; // Based on module and local config
|
|
|
|
bool m_maybe_emergency = false; // Based on the module.desc
|
2018-06-15 13:11:17 +02:00
|
|
|
|
2014-06-18 18:05:04 +02:00
|
|
|
private:
|
2019-06-27 15:15:47 +02:00
|
|
|
void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
|
2017-09-27 11:34:06 +02:00
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
QString m_directory;
|
2020-01-12 11:49:10 +01:00
|
|
|
ModuleSystem::InstanceKey m_key;
|
2014-06-18 18:05:04 +02:00
|
|
|
};
|
|
|
|
|
2019-06-27 15:15:47 +02:00
|
|
|
} // namespace Calamares
|
2014-06-18 18:05:04 +02:00
|
|
|
|
2019-06-27 15:15:47 +02:00
|
|
|
#endif // CALAMARES_MODULE_H
|