@ -10,6 +10,7 @@
# include "Config.h"
# include "Preset.h"
# include "utils/Logger.h"
# include "utils/Variant.h"
namespace Calamares
@ -33,47 +34,63 @@ Config::Config( QObject* parent )
Config : : ~ Config ( ) { }
void
Config : : loadPresets( const QVariantMap & configurationMap )
bool
Config : : isEditable( const QString & fieldName ) const
{
const QString key ( " presets " ) ;
if ( ! configurationMap . contains ( key ) )
if ( m_unlocked )
{
d - > m_presets . reset ( ) ;
return ;
return true ;
}
bool bogus = true ;
d - > m_presets = std : : make_unique < Presets > ( CalamaresUtils : : getSubMap ( configurationMap , key , bogus ) ) ;
if ( d & & d - > m_presets )
{
return d - > m_presets - > isEditable ( fieldName ) ;
}
else
{
cWarning ( ) < < " Checking isEditable, but no presets are configured. " ;
}
return true ;
}
void
Config : : loadPresets ( const QVariantMap & configurationMap , const QStringList & recognizedKeys )
Config : : ApplyPresets : : ApplyPresets ( Calamares : : ModuleSystem : : Config & c , const QVariantMap & configurationMap )
: m_c ( c )
, m_bogus ( true )
, m_map ( CalamaresUtils : : getSubMap ( configurationMap , " presets " , m_bogus ) )
{
const QString key ( " presets " ) ;
if ( ! configurationMap . contains ( key ) )
c . m_unlocked = true ;
if ( ! c . d - > m_presets )
{
d - > m_presets . reset ( ) ;
return ;
c . d - > m_presets = std : : make_unique < Presets > ( ) ;
}
bool bogus = true ;
d - > m_presets
= std : : make_unique < Presets > ( CalamaresUtils : : getSubMap ( configurationMap , key , bogus ) , recognizedKeys ) ;
}
bool
Config : : isEditable ( const QString & fieldName ) const
Config : : ApplyPresets &
Config : : ApplyPresets : : apply ( const char * fieldName )
{
if ( m_unlocked )
const auto prop = m_c . property ( fieldName ) ;
if ( ! prop . isValid ( ) )
{
return tru e;
cWarning ( ) < < " Applying invalid property " < < fieldNam e;
}
if ( d & & d - > m_pr esets )
el se
{
return d - > m_presets - > isEditable ( fieldName ) ;
const QString key ( fieldName ) ;
if ( ! key . isEmpty ( ) & & m_map . contains ( key ) )
{
QVariantMap m = CalamaresUtils : : getSubMap ( m_map , key , m_bogus ) ;
QVariant value = m [ " value " ] ;
bool editable = CalamaresUtils : : getBool ( m , " editable " , true ) ;
if ( value . isValid ( ) )
{
m_c . setProperty ( fieldName , value ) ;
}
m_c . d - > m_presets - > append ( PresetField { key , value , editable } ) ;
}
}
return true ;
return * this ;
}
} // namespace ModuleSystem
} // namespace Calamares