2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-06-27 13:58:53 +02:00
|
|
|
*
|
2020-08-20 22:42:19 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-06-27 13:58:53 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-06-27 13:58:53 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ViewModule.h"
|
|
|
|
|
2019-06-27 15:15:47 +02:00
|
|
|
#include "ViewManager.h"
|
2014-06-27 13:58:53 +02:00
|
|
|
#include "utils/Logger.h"
|
2019-06-27 15:15:47 +02:00
|
|
|
#include "utils/PluginFactory.h"
|
2014-06-27 18:00:27 +02:00
|
|
|
#include "viewpages/ViewStep.h"
|
2014-06-27 13:58:53 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QPluginLoader>
|
|
|
|
|
2018-06-18 16:56:10 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
2014-06-27 13:58:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
Module::Type
|
2014-07-10 12:27:53 +02:00
|
|
|
ViewModule::type() const
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
2019-05-07 12:33:31 +02:00
|
|
|
return Module::Type::View;
|
2014-06-27 13:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Module::Interface
|
2014-07-10 12:27:53 +02:00
|
|
|
ViewModule::interface() const
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
2019-05-07 12:33:31 +02:00
|
|
|
return Module::Interface::QtPlugin;
|
2014-06-27 13:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ViewModule::loadSelf()
|
|
|
|
{
|
|
|
|
if ( m_loader )
|
|
|
|
{
|
2019-08-12 15:52:59 +02:00
|
|
|
CalamaresPluginFactory* pf = qobject_cast< CalamaresPluginFactory* >( m_loader->instance() );
|
2015-09-09 19:01:56 +02:00
|
|
|
if ( !pf )
|
|
|
|
{
|
2020-05-19 15:06:43 +02:00
|
|
|
cWarning() << "No factory:" << m_loader->errorString();
|
2015-09-09 19:01:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_viewStep = pf->create< Calamares::ViewStep >();
|
2014-08-09 09:10:26 +02:00
|
|
|
if ( !m_viewStep )
|
2014-07-01 12:00:24 +02:00
|
|
|
{
|
2020-05-19 15:06:43 +02:00
|
|
|
cWarning() << "create() failed" << m_loader->errorString();
|
2014-08-09 09:10:26 +02:00
|
|
|
return;
|
2014-07-01 12:00:24 +02:00
|
|
|
}
|
2018-06-13 10:37:52 +02:00
|
|
|
}
|
2015-09-09 19:01:56 +02:00
|
|
|
|
2018-06-13 10:37:52 +02:00
|
|
|
// If any method created the view step, use it now.
|
|
|
|
if ( m_viewStep )
|
|
|
|
{
|
2015-09-09 19:01:56 +02:00
|
|
|
m_viewStep->setModuleInstanceKey( instanceKey() );
|
2014-08-09 09:10:26 +02:00
|
|
|
m_viewStep->setConfigurationMap( m_configurationMap );
|
|
|
|
ViewManager::instance()->addViewStep( m_viewStep );
|
|
|
|
m_loaded = true;
|
2016-09-19 12:34:45 +02:00
|
|
|
cDebug() << "ViewModule" << instanceKey() << "loading complete.";
|
2014-06-27 13:58:53 +02:00
|
|
|
}
|
2018-06-13 10:37:52 +02:00
|
|
|
else
|
2019-06-27 15:15:47 +02:00
|
|
|
{
|
2020-05-19 15:06:43 +02:00
|
|
|
cWarning() << "No view step was created";
|
2019-06-27 15:15:47 +02:00
|
|
|
}
|
2014-06-27 13:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-03 15:10:37 +01:00
|
|
|
JobList
|
2014-07-22 16:54:34 +02:00
|
|
|
ViewModule::jobs() const
|
|
|
|
{
|
|
|
|
return m_viewStep->jobs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-27 13:58:53 +02:00
|
|
|
void
|
2020-08-11 22:12:16 +02:00
|
|
|
ViewModule::initFrom( const ModuleSystem::Descriptor& moduleDescriptor )
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
|
|
|
QDir directory( location() );
|
2020-08-11 22:12:16 +02:00
|
|
|
QString load = moduleDescriptor.load();
|
|
|
|
if ( !load.isEmpty() )
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
|
|
|
load = directory.absoluteFilePath( load );
|
|
|
|
}
|
|
|
|
// If a load path is not specified, we look for a plugin to load in the directory.
|
|
|
|
if ( load.isEmpty() || !QLibrary::isLibrary( load ) )
|
|
|
|
{
|
2019-06-27 15:15:47 +02:00
|
|
|
const QStringList ls = directory.entryList( QStringList { "*.so" } );
|
2014-06-27 13:58:53 +02:00
|
|
|
if ( !ls.isEmpty() )
|
|
|
|
{
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( QString entry : ls )
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
|
|
|
entry = directory.absoluteFilePath( entry );
|
|
|
|
if ( QLibrary::isLibrary( entry ) )
|
|
|
|
{
|
|
|
|
load = entry;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_loader = new QPluginLoader( load );
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewModule::ViewModule()
|
|
|
|
: Module()
|
|
|
|
, m_loader( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewModule::~ViewModule()
|
|
|
|
{
|
|
|
|
delete m_loader;
|
|
|
|
}
|
|
|
|
|
2017-12-02 17:20:45 +01:00
|
|
|
RequirementsList
|
|
|
|
ViewModule::checkRequirements()
|
|
|
|
{
|
|
|
|
return m_viewStep->checkRequirements();
|
|
|
|
}
|
|
|
|
|
2019-06-27 15:15:47 +02:00
|
|
|
} // namespace Calamares
|