[libcalamares] Migrate module type and interface to descriptor
- move the enums - expose the named-enum functions for them - **start** replacing Descriptor with something stronger; this fails zero tests so it obviously wasn't tested at all
This commit is contained in:
parent
7cef99605f
commit
bdd6bdc3b2
@ -60,6 +60,7 @@ set( libSources
|
||||
locale/TranslatableString.cpp
|
||||
|
||||
# Modules
|
||||
modulesystem/Descriptor.cpp
|
||||
modulesystem/InstanceKey.cpp
|
||||
modulesystem/Module.cpp
|
||||
modulesystem/RequirementsChecker.cpp
|
||||
|
48
src/libcalamares/modulesystem/Descriptor.cpp
Normal file
48
src/libcalamares/modulesystem/Descriptor.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
|
||||
* 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
|
@ -21,17 +21,59 @@
|
||||
#ifndef MODULESYSTEM_DESCRIPTOR_H
|
||||
#define MODULESYSTEM_DESCRIPTOR_H
|
||||
|
||||
#include "utils/NamedEnum.h"
|
||||
|
||||
#include <QVariantMap>
|
||||
|
||||
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
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user