[libcalamaresui] Refactor Requirements classes

- improve naming of member variables
 - expand documentation
This commit is contained in:
Adriaan de Groot 2019-02-15 20:53:55 +01:00
parent 43eae0bc47
commit d33752c66c
3 changed files with 26 additions and 18 deletions

View File

@ -317,7 +317,7 @@ ModuleManager::checkRequirements()
for (const auto& module : m_loadedModulesByInstanceKey ) for (const auto& module : m_loadedModulesByInstanceKey )
{ {
auto l = module->checkRequirements(); RequirementsList l = module->checkRequirements();
if ( l.length() > 0 ) if ( l.length() > 0 )
{ {
cDebug() << " .." << module->name() << l.length() << "requirements"; cDebug() << " .." << module->name() << l.length() << "requirements";
@ -325,7 +325,7 @@ ModuleManager::checkRequirements()
} }
for (const auto& r : l) for (const auto& r : l)
{ {
if (r.required && !r.checked) if ( r.mandatory && !r.satisfied )
acceptable = false; acceptable = false;
} }
} }

View File

@ -28,22 +28,30 @@ namespace Calamares
/** /**
* An indication of a requirement, which is checked in preparation * An indication of a requirement, which is checked in preparation
* for system installation. An entry has a name and some explanation, * for system installation. An entry has a name and some explanation functions
* as well as three meaningful states: * (functions, because they need to respond to translations).
* - checked = true, the requirement is met (green) *
* - checked = false, the requirement is not met * A requirement can be *satisfied* or not.
* - required = false, warn about it (yellow), no failure * A requirement can be optional (i.e. a "good to have") or mandatory.
* - required = true, prohibit installation (red) *
* Requirements which are not satisfied, and also mandatory, will prevent the
* installation from proceeding.
*/ */
struct RequirementEntry struct RequirementEntry
{ {
using TextFunction = std::function< QString() >;
/// @brief name of this requirement; not shown to user and used as ID
QString name; QString name;
std::function< QString() > enumerationText; //Partial string, inserted in a
//list of requirements to satisfy. /// @brief Description of this requirement, for use in user-visible lists
std::function< QString() > negatedText; //Complete sentence about this requirement TextFunction enumerationText;
//not having been met.
bool checked; /// @brief User-visible string to show that the requirement is not met
bool required; std::function< QString() > negatedText;
bool satisfied;
bool mandatory;
}; };
using RequirementsList = QList< RequirementEntry >; using RequirementsList = QList< RequirementEntry >;

View File

@ -60,15 +60,15 @@ CheckerWidget::init( const Calamares::RequirementsList& checkEntries )
for ( const auto& entry : checkEntries ) for ( const auto& entry : checkEntries )
{ {
if ( !entry.checked ) if ( !entry.satisfied )
{ {
CheckItemWidget* ciw = new CheckItemWidget( entry.checked, entry.required ); CheckItemWidget* ciw = new CheckItemWidget( entry.satisfied, entry.mandatory );
CALAMARES_RETRANSLATE( ciw->setText( entry.negatedText() ); ) CALAMARES_RETRANSLATE( ciw->setText( entry.negatedText() ); )
m_entriesLayout->addWidget( ciw ); m_entriesLayout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
allChecked = false; allChecked = false;
if ( entry.required ) if ( entry.mandatory )
{ {
requirementsSatisfied = false; requirementsSatisfied = false;
} }
@ -182,7 +182,7 @@ CheckerWidget::showDetailsDialog( const Calamares::RequirementsList& checkEntrie
if ( entry.enumerationText().isEmpty() ) if ( entry.enumerationText().isEmpty() )
continue; continue;
CheckItemWidget* ciw = new CheckItemWidget( entry.checked, entry.required ); CheckItemWidget* ciw = new CheckItemWidget( entry.satisfied, entry.mandatory );
CALAMARES_RETRANSLATE( ciw->setText( entry.enumerationText() ); ) CALAMARES_RETRANSLATE( ciw->setText( entry.enumerationText() ); )
entriesLayout->addWidget( ciw ); entriesLayout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );