diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 3bfc8e479..3eab21a99 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -60,6 +60,7 @@ set( libSources locale/TranslatableString.cpp # Modules + modulesystem/Descriptor.cpp modulesystem/InstanceKey.cpp modulesystem/Module.cpp modulesystem/RequirementsChecker.cpp diff --git a/src/libcalamares/modulesystem/Descriptor.cpp b/src/libcalamares/modulesystem/Descriptor.cpp new file mode 100644 index 000000000..c8a3c3118 --- /dev/null +++ b/src/libcalamares/modulesystem/Descriptor.cpp @@ -0,0 +1,48 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2020 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "Descriptor.h" + +namespace Calamares +{ +namespace ModuleSystem +{ + +const NamedEnumTable< Type >& +typeNames() +{ + // *INDENT-OFF* + // clang-format off + static const NamedEnumTable< Type > table{ + { QStringLiteral( "job" ), Type::Job }, + { QStringLiteral( "view" ), Type::View }, + { QStringLiteral( "viewmodule" ), Type::View }, + { QStringLiteral( "jobmodule" ), Type::Job } + }; + // *INDENT-ON* + // clang-format on + return table; +} + +const NamedEnumTable< Interface >& +interfaceNames() +{ + // *INDENT-OFF* + // clang-format off + static const NamedEnumTable< Interface > table { + { QStringLiteral("process"), Interface::Process }, + { QStringLiteral("qtplugin"), Interface::QtPlugin }, + { QStringLiteral("python"), Interface::Python }, + { QStringLiteral("pythonqt"), Interface::PythonQt } + }; + // *INDENT-ON* + // clang-format on + return table; +} + +} // namespace ModuleSystem +} // namespace Calamares diff --git a/src/libcalamares/modulesystem/Descriptor.h b/src/libcalamares/modulesystem/Descriptor.h index c6b5ab5cf..1d1a24b8b 100644 --- a/src/libcalamares/modulesystem/Descriptor.h +++ b/src/libcalamares/modulesystem/Descriptor.h @@ -21,17 +21,59 @@ #ifndef MODULESYSTEM_DESCRIPTOR_H #define MODULESYSTEM_DESCRIPTOR_H +#include "utils/NamedEnum.h" + #include namespace Calamares { namespace ModuleSystem { +/** + * @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. + */ +enum class Type +{ + Job, + View +}; +const NamedEnumTable< Type >& typeNames(); + +/** + * @brief The Interface enum represents the interface through which the module + * talks to Calamares. + * Not all Type-Interface associations are valid. + */ +enum class Interface +{ + QtPlugin, // Jobs or Views + Python, // Jobs only + Process, // Deprecated interface + PythonQt // Views only, available as enum even if PythonQt isn't used +}; +const NamedEnumTable< Interface >& interfaceNames(); + + /* While this isn't a useful *using* right now, the intention is * to create a more strongly-typed Module Descriptor that carries * only the necessary information and no variants. */ -using Descriptor = QVariantMap; +// using Descriptor = QVariantMap; + +class Descriptor +{ +public: + Descriptor(); + + bool isValid() const { return false; } + + QString name() const { return QString(); } + bool isEmergency() const { return false; } +}; + } // namespace ModuleSystem } // namespace Calamares diff --git a/src/libcalamares/modulesystem/Module.cpp b/src/libcalamares/modulesystem/Module.cpp index dae3c84aa..18c33bde8 100644 --- a/src/libcalamares/modulesystem/Module.cpp +++ b/src/libcalamares/modulesystem/Module.cpp @@ -49,10 +49,10 @@ Module::~Module() {} void Module::initFrom( const Calamares::ModuleSystem::Descriptor& moduleDescriptor, const QString& id ) { - m_key = ModuleSystem::InstanceKey( moduleDescriptor.value( "name" ).toString(), id ); - if ( moduleDescriptor.contains( EMERGENCY ) ) + m_key = ModuleSystem::InstanceKey( moduleDescriptor.name(), id ); + if ( moduleDescriptor.isEmergency() ) { - m_maybe_emergency = moduleDescriptor[ EMERGENCY ].toBool(); + m_maybe_emergency = true; } } @@ -133,54 +133,20 @@ Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::E } -static const NamedEnumTable< Module::Type >& -typeNames() -{ - using Type = Module::Type; - // *INDENT-OFF* - // clang-format off - static const NamedEnumTable< Type > table{ - { QStringLiteral( "job" ), Type::Job }, - { QStringLiteral( "view" ), Type::View }, - { QStringLiteral( "viewmodule" ), Type::View }, - { QStringLiteral( "jobmodule" ), Type::Job } - }; - // *INDENT-ON* - // clang-format on - return table; -} - QString Module::typeString() const { bool ok = false; - QString v = typeNames().find( type(), ok ); + QString v = Calamares::ModuleSystem::typeNames().find( type(), ok ); return ok ? v : QString(); } -static const NamedEnumTable< Module::Interface >& -interfaceNames() -{ - using Interface = Module::Interface; - // *INDENT-OFF* - // clang-format off - static const NamedEnumTable< Interface > table { - { QStringLiteral("process"), Interface::Process }, - { QStringLiteral("qtplugin"), Interface::QtPlugin }, - { QStringLiteral("python"), Interface::Python }, - { QStringLiteral("pythonqt"), Interface::PythonQt } - }; - // *INDENT-ON* - // clang-format on - return table; -} - QString Module::interfaceString() const { bool ok = false; - QString v = interfaceNames().find( interface(), ok ); + QString v = Calamares::ModuleSystem::interfaceNames().find( interface(), ok ); return ok ? v : QString(); } diff --git a/src/libcalamares/modulesystem/Module.h b/src/libcalamares/modulesystem/Module.h index 44e89fd75..a9492c21c 100644 --- a/src/libcalamares/modulesystem/Module.h +++ b/src/libcalamares/modulesystem/Module.h @@ -51,31 +51,6 @@ Module* moduleFromDescriptor( const ModuleSystem::Descriptor& moduleDescriptor, class DLLEXPORT Module { public: - /** - * @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. - */ - enum class Type - { - Job, - View - }; - - /** - * @brief The Interface enum represents the interface through which the module - * talks to Calamares. - * Not all Type-Interface associations are valid. - */ - enum class Interface - { - QtPlugin, // Jobs or Views - Python, // Jobs only - Process, // Deprecated interface - PythonQt // Views only, available as enum even if PythonQt isn't used - }; - virtual ~Module(); /** @@ -157,13 +132,13 @@ public: * @brief type returns the Type of this module object. * @return the type enum value. */ - virtual Type type() const = 0; + virtual ModuleSystem::Type type() const = 0; /** * @brief interface the Interface used by this module. * @return the interface enum value. */ - virtual Interface interface() const = 0; + virtual ModuleSystem::Interface interface() const = 0; /** * @brief Check the requirements of this module.