[libcalamaresui] Migrate module to using InstanceKey
- Trying to get away from untyped strings with special meaning. - The "split identifier" branch tried the same thing, but was duplicating the existing InstanceKey.h work.
This commit is contained in:
parent
a7e1a1f9fc
commit
f89c137c90
@ -58,8 +58,7 @@ Module::~Module() {}
|
|||||||
void
|
void
|
||||||
Module::initFrom( const QVariantMap& moduleDescriptor, const QString& id )
|
Module::initFrom( const QVariantMap& moduleDescriptor, const QString& id )
|
||||||
{
|
{
|
||||||
m_name = moduleDescriptor.value( "name" ).toString();
|
m_key = ModuleSystem::InstanceKey( moduleDescriptor.value( "name" ).toString(), id );
|
||||||
m_instanceId = id;
|
|
||||||
if ( moduleDescriptor.contains( EMERGENCY ) )
|
if ( moduleDescriptor.contains( EMERGENCY ) )
|
||||||
{
|
{
|
||||||
m_maybe_emergency = moduleDescriptor[ EMERGENCY ].toBool();
|
m_maybe_emergency = moduleDescriptor[ EMERGENCY ].toBool();
|
||||||
@ -148,6 +147,12 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
m->initFrom( moduleDescriptor, instanceId );
|
m->initFrom( moduleDescriptor, instanceId );
|
||||||
|
if ( !m->m_key.isValid() )
|
||||||
|
{
|
||||||
|
cError() << "Module" << instanceId << "invalid ID";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
m->initFrom( moduleDescriptor );
|
m->initFrom( moduleDescriptor );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -205,7 +210,7 @@ moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, c
|
|||||||
void Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
|
void Module::loadConfigurationFile( const QString& configFileName ) //throws YAML::Exception
|
||||||
{
|
{
|
||||||
QStringList configCandidates
|
QStringList configCandidates
|
||||||
= moduleConfigurationCandidates( Settings::instance()->debugMode(), m_name, configFileName );
|
= moduleConfigurationCandidates( Settings::instance()->debugMode(), name(), configFileName );
|
||||||
for ( const QString& path : configCandidates )
|
for ( const QString& path : configCandidates )
|
||||||
{
|
{
|
||||||
QFile configFile( path );
|
QFile configFile( path );
|
||||||
@ -234,28 +239,7 @@ void Module::loadConfigurationFile( const QString& configFileName ) //throws YA
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cDebug() << "No config file for" << m_name << "found anywhere at" << Logger::DebugList( configCandidates );
|
cDebug() << "No config file for" << name() << "found anywhere at" << Logger::DebugList( configCandidates );
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
Module::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
Module::instanceId() const
|
|
||||||
{
|
|
||||||
return m_instanceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
Module::instanceKey() const
|
|
||||||
{
|
|
||||||
return QString( "%1@%2" ).arg( m_name ).arg( m_instanceId );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "Requirement.h"
|
#include "Requirement.h"
|
||||||
#include "UiDllMacro.h"
|
#include "UiDllMacro.h"
|
||||||
|
|
||||||
|
#include "modulesystem/InstanceKey.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
@ -83,13 +85,13 @@ public:
|
|||||||
* @brief name returns the name of this module.
|
* @brief name returns the name of this module.
|
||||||
* @return a string with this module's name.
|
* @return a string with this module's name.
|
||||||
*/
|
*/
|
||||||
virtual QString name() const final;
|
QString name() const { return m_key.module(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief instanceId returns the instance id of this module.
|
* @brief instanceId returns the instance id of this module.
|
||||||
* @return a string with this module's instance id.
|
* @return a string with this module's instance id.
|
||||||
*/
|
*/
|
||||||
virtual QString instanceId() const final;
|
QString instanceId() const { return m_key.id(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief instanceKey returns the instance key of this module.
|
* @brief instanceKey returns the instance key of this module.
|
||||||
@ -98,7 +100,7 @@ public:
|
|||||||
* For instance, "partition\@partition" (default configuration) or
|
* For instance, "partition\@partition" (default configuration) or
|
||||||
* "locale\@someconfig" (custom configuration)
|
* "locale\@someconfig" (custom configuration)
|
||||||
*/
|
*/
|
||||||
virtual QString instanceKey() const final;
|
QString instanceKey() const { return m_key.toString(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief location returns the full path of this module's directory.
|
* @brief location returns the full path of this module's directory.
|
||||||
@ -188,9 +190,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
|
void loadConfigurationFile( const QString& configFileName ); //throws YAML::Exception
|
||||||
|
|
||||||
QString m_name;
|
|
||||||
QString m_directory;
|
QString m_directory;
|
||||||
QString m_instanceId;
|
ModuleSystem::InstanceKey m_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
Loading…
Reference in New Issue
Block a user