[libcalamaresui] Expose registering-a-single-module
- For testing purposes, it's useful to load a module externally and then register it to the ModuleManager (this hands off ownership). - Refactor overall module loading to use the exposed single-module method.
This commit is contained in:
parent
1fec95ac48
commit
c7d0df223a
@ -300,22 +300,12 @@ ModuleManager::loadModules()
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !checkModuleDependencies( *thisModule ) )
|
||||
if ( !addModule( thisModule ) )
|
||||
{
|
||||
// Error message is already printed
|
||||
failedModules.append( instanceKey.toString() );
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's a ViewModule, it also appends the ViewStep to the ViewManager.
|
||||
thisModule->loadSelf();
|
||||
m_loadedModulesByInstanceKey.insert( instanceKey, thisModule );
|
||||
if ( !thisModule->isLoaded() )
|
||||
{
|
||||
cError() << "Module" << instanceKey.toString() << "loading FAILED.";
|
||||
failedModules.append( instanceKey.toString() );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// At this point we most certainly have a pointer to a loaded module in
|
||||
@ -345,6 +335,40 @@ ModuleManager::loadModules()
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ModuleManager::addModule( Module *module )
|
||||
{
|
||||
if ( !module )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !module->instanceKey().isValid() )
|
||||
{
|
||||
cWarning() << "Module" << module->location() << '@' << (void*)module << "has invalid instance key.";
|
||||
return false;
|
||||
}
|
||||
if ( !checkModuleDependencies( *module ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !module->isLoaded() )
|
||||
{
|
||||
module->loadSelf();
|
||||
}
|
||||
|
||||
// Even if the load failed, we keep the module, so that if it tried to
|
||||
// get loaded **again**, we already know.
|
||||
m_loadedModulesByInstanceKey.insert( module->instanceKey(), module );
|
||||
if ( !module->isLoaded() )
|
||||
{
|
||||
cError() << "Module" << module->instanceKey().toString() << "loading FAILED.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ModuleManager::checkRequirements()
|
||||
{
|
||||
@ -414,6 +438,12 @@ ModuleManager::checkDependencies()
|
||||
bool
|
||||
ModuleManager::checkModuleDependencies( const Module& m )
|
||||
{
|
||||
if ( !m_availableDescriptorsByModuleName.contains( m.name() ) )
|
||||
{
|
||||
cWarning() << "Module" << m.name() << "loaded externally, no dependency information.";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool allRequirementsFound = true;
|
||||
QStringList requiredModules
|
||||
= m_availableDescriptorsByModuleName[ m.name() ].value( "requiredModules" ).toStringList();
|
||||
|
@ -85,6 +85,14 @@ public:
|
||||
*/
|
||||
void loadModules();
|
||||
|
||||
/**
|
||||
* @brief Adds a single module (loaded by some other means)
|
||||
*
|
||||
* Returns @c true on success (that is, the module's dependencies
|
||||
* are satisfied, it wasn't already loaded, ...).
|
||||
*/
|
||||
bool addModule( Module* );
|
||||
|
||||
/**
|
||||
* @brief Starts asynchronous requirements checking for each module.
|
||||
* When this is done, the signal requirementsComplete is emitted.
|
||||
|
Loading…
Reference in New Issue
Block a user