mirror of https://github.com/cutefishos/calamares
commit
a3c966cc6c
@ -0,0 +1,81 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "RequirementsModel.h"
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
|
void
|
||||||
|
RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements )
|
||||||
|
{
|
||||||
|
emit beginResetModel();
|
||||||
|
m_requirements = requirements;
|
||||||
|
|
||||||
|
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
|
||||||
|
auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; };
|
||||||
|
|
||||||
|
m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied );
|
||||||
|
m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied );
|
||||||
|
|
||||||
|
emit satisfiedRequirementsChanged( m_satisfiedRequirements );
|
||||||
|
emit satisfiedMandatoryChanged( m_satisfiedMandatory );
|
||||||
|
emit endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
RequirementsModel::rowCount( const QModelIndex& ) const
|
||||||
|
{
|
||||||
|
return m_requirements.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
RequirementsModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
const auto requirement = m_requirements.at( index.row() );
|
||||||
|
|
||||||
|
switch ( role )
|
||||||
|
{
|
||||||
|
case Roles::Name:
|
||||||
|
return requirement.name;
|
||||||
|
case Roles::Details:
|
||||||
|
return requirement.enumerationText();
|
||||||
|
case Roles::NegatedText:
|
||||||
|
return requirement.negatedText();
|
||||||
|
case Roles::Satisfied:
|
||||||
|
return requirement.satisfied;
|
||||||
|
case Roles::Mandatory:
|
||||||
|
return requirement.mandatory;
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash< int, QByteArray >
|
||||||
|
RequirementsModel::roleNames() const
|
||||||
|
{
|
||||||
|
static QHash< int, QByteArray > roles;
|
||||||
|
roles[ Roles::Name ] = "name";
|
||||||
|
roles[ Roles::Details ] = "details";
|
||||||
|
roles[ Roles::NegatedText ] = "negatedText";
|
||||||
|
roles[ Roles::Satisfied ] = "satisfied";
|
||||||
|
roles[ Roles::Mandatory ] = "mandatory";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Calamares
|
@ -0,0 +1,81 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CALAMARES_REQUIREMENTSMODEL_H
|
||||||
|
#define CALAMARES_REQUIREMENTSMODEL_H
|
||||||
|
|
||||||
|
#include "Requirement.h"
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
|
class DLLEXPORT RequirementsModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL )
|
||||||
|
Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL )
|
||||||
|
|
||||||
|
public:
|
||||||
|
using QAbstractListModel::QAbstractListModel;
|
||||||
|
|
||||||
|
enum Roles : short
|
||||||
|
{
|
||||||
|
Name,
|
||||||
|
Satisfied,
|
||||||
|
Mandatory,
|
||||||
|
Details,
|
||||||
|
NegatedText,
|
||||||
|
HasDetails
|
||||||
|
};
|
||||||
|
// No Q_ENUM because these are exposed through roleNames()
|
||||||
|
|
||||||
|
bool satisfiedRequirements() const { return m_satisfiedRequirements; }
|
||||||
|
bool satisfiedMandatory() const { return m_satisfiedMandatory; }
|
||||||
|
|
||||||
|
const Calamares::RequirementEntry& getEntry( int index ) const
|
||||||
|
{
|
||||||
|
return m_requirements.at( index );
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRequirementsList( const Calamares::RequirementsList& requirements );
|
||||||
|
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
int rowCount( const QModelIndex& ) const override;
|
||||||
|
int count() const { return m_requirements.count(); }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void satisfiedRequirementsChanged( bool value );
|
||||||
|
void satisfiedMandatoryChanged( bool value );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash< int, QByteArray > roleNames() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Calamares::RequirementsList m_requirements;
|
||||||
|
bool m_satisfiedRequirements = false;
|
||||||
|
bool m_satisfiedMandatory = false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Calamares
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,154 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ModuleFactory.h"
|
||||||
|
|
||||||
|
#include "CalamaresConfig.h"
|
||||||
|
#include "CppJobModule.h"
|
||||||
|
#include "ProcessJobModule.h"
|
||||||
|
#include "ViewModule.h"
|
||||||
|
|
||||||
|
#include "utils/Dirs.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/NamedEnum.h"
|
||||||
|
#include "utils/Yaml.h"
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
#include "PythonJobModule.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHONQT
|
||||||
|
#include "PythonQtViewModule.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
|
Module*
|
||||||
|
moduleFromDescriptor( const Calamares::ModuleSystem::Descriptor& moduleDescriptor,
|
||||||
|
const QString& instanceId,
|
||||||
|
const QString& configFileName,
|
||||||
|
const QString& moduleDirectory )
|
||||||
|
{
|
||||||
|
std::unique_ptr< Module > m;
|
||||||
|
|
||||||
|
QString typeString = moduleDescriptor.value( "type" ).toString();
|
||||||
|
QString intfString = moduleDescriptor.value( "interface" ).toString();
|
||||||
|
|
||||||
|
if ( typeString.isEmpty() || intfString.isEmpty() )
|
||||||
|
{
|
||||||
|
cError() << "Bad module descriptor format" << instanceId;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if ( ( typeString == "view" ) || ( typeString == "viewmodule" ) )
|
||||||
|
{
|
||||||
|
if ( intfString == "qtplugin" )
|
||||||
|
{
|
||||||
|
m.reset( new ViewModule() );
|
||||||
|
}
|
||||||
|
else if ( intfString == "pythonqt" )
|
||||||
|
{
|
||||||
|
#ifdef WITH_PYTHONQT
|
||||||
|
m.reset( new PythonQtViewModule() );
|
||||||
|
#else
|
||||||
|
cError() << "PythonQt view modules are not supported in this version of Calamares.";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cError() << "Bad interface" << intfString << "for module type" << typeString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( typeString == "job" )
|
||||||
|
{
|
||||||
|
if ( intfString == "qtplugin" )
|
||||||
|
{
|
||||||
|
m.reset( new CppJobModule() );
|
||||||
|
}
|
||||||
|
else if ( intfString == "process" )
|
||||||
|
{
|
||||||
|
m.reset( new ProcessJobModule() );
|
||||||
|
}
|
||||||
|
else if ( intfString == "python" )
|
||||||
|
{
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
m.reset( new PythonJobModule() );
|
||||||
|
#else
|
||||||
|
cError() << "Python modules are not supported in this version of Calamares.";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cError() << "Bad interface" << intfString << "for module type" << typeString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cError() << "Bad module type" << typeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m )
|
||||||
|
{
|
||||||
|
cError() << "Bad module type (" << typeString << ") or interface string (" << intfString << ") for module "
|
||||||
|
<< instanceId;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir moduleDir( moduleDirectory );
|
||||||
|
if ( moduleDir.exists() && moduleDir.isReadable() )
|
||||||
|
{
|
||||||
|
m->m_directory = moduleDir.absolutePath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cError() << "Bad module directory" << moduleDirectory << "for" << instanceId;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m->initFrom( moduleDescriptor, instanceId );
|
||||||
|
if ( !m->m_key.isValid() )
|
||||||
|
{
|
||||||
|
cError() << "Module" << instanceId << "invalid ID";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
m->initFrom( moduleDescriptor );
|
||||||
|
if ( !configFileName.isEmpty() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m->loadConfigurationFile( configFileName );
|
||||||
|
}
|
||||||
|
catch ( YAML::Exception& e )
|
||||||
|
{
|
||||||
|
cError() << "YAML parser error " << e.what();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Calamares
|
@ -0,0 +1,47 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CALAMARES_MODULEFACTORY_H
|
||||||
|
#define CALAMARES_MODULEFACTORY_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include "modulesystem/Descriptor.h"
|
||||||
|
#include "modulesystem/Module.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace Calamares
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief fromDescriptor creates a new Module object of the correct type.
|
||||||
|
* @param moduleDescriptor a module descriptor, already parsed into a variant map.
|
||||||
|
* @param instanceId the instance id of the new module instance.
|
||||||
|
* @param configFileName the name of the configuration file to read.
|
||||||
|
* @param moduleDirectory the path to the directory with this module's files.
|
||||||
|
* @return a pointer to an object of a subtype of Module.
|
||||||
|
*/
|
||||||
|
UIDLLEXPORT Module* moduleFromDescriptor( const ModuleSystem::Descriptor& moduleDescriptor,
|
||||||
|
const QString& instanceId,
|
||||||
|
const QString& configFileName,
|
||||||
|
const QString& moduleDirectory );
|
||||||
|
} // namespace Calamares
|
||||||
|
|
||||||
|
#endif // CALAMARES_MODULEFACTORY_H
|
Loading…
Reference in New Issue