[libcalamares] Distinguish instances with an explicit weight
- setting the weight in *instances* should be different from letting the default weight (of 1) stand; explicitly saying 1 should carry some weight (ha!)
This commit is contained in:
parent
c8964717c7
commit
7cef99605f
@ -75,7 +75,7 @@ namespace Calamares
|
||||
|
||||
InstanceDescription::InstanceDescription( const Calamares::ModuleSystem::InstanceKey& key )
|
||||
: m_instanceKey( key )
|
||||
, m_weight( 1 )
|
||||
, m_weight( -1 )
|
||||
{
|
||||
if ( !isValid() )
|
||||
{
|
||||
@ -93,9 +93,12 @@ InstanceDescription::fromSettings( const QVariantMap& m )
|
||||
InstanceDescription r(
|
||||
Calamares::ModuleSystem::InstanceKey( m.value( "module" ).toString(), m.value( "id" ).toString() ) );
|
||||
if ( r.isValid() )
|
||||
{
|
||||
if ( m.value( "weight" ).isValid() )
|
||||
{
|
||||
int w = qBound( 1, m.value( "weight" ).toInt(), 100 );
|
||||
r.m_weight = w;
|
||||
}
|
||||
|
||||
QString c = m.value( "config" ).toString();
|
||||
if ( !c.isEmpty() )
|
||||
|
@ -71,7 +71,8 @@ public:
|
||||
const InstanceKey& key() const { return m_instanceKey; }
|
||||
QString configFileName() const { return m_configFileName; }
|
||||
bool isCustom() const { return m_instanceKey.isCustom(); }
|
||||
int weight() const { return m_weight; }
|
||||
int weight() const { return m_weight < 0 ? 1 : m_weight; }
|
||||
bool explicitWeight() const { return m_weight > 0; }
|
||||
|
||||
private:
|
||||
InstanceKey m_instanceKey;
|
||||
|
@ -270,6 +270,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
QVERIFY( !d.isCustom() );
|
||||
QCOMPARE( d.weight(), 0 );
|
||||
QVERIFY( d.configFileName().isEmpty() );
|
||||
QVERIFY( !d.explicitWeight() );
|
||||
}
|
||||
|
||||
{
|
||||
@ -278,6 +279,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
QVERIFY( !d.isCustom() );
|
||||
QCOMPARE( d.weight(), 0 );
|
||||
QVERIFY( d.configFileName().isEmpty() );
|
||||
QVERIFY( !d.explicitWeight() );
|
||||
}
|
||||
|
||||
// Private constructor
|
||||
@ -290,6 +292,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
|
||||
QVERIFY( !d.configFileName().isEmpty() );
|
||||
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
|
||||
QVERIFY( !d.explicitWeight() );
|
||||
}
|
||||
|
||||
{
|
||||
@ -299,6 +302,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
|
||||
QVERIFY( !d.configFileName().isEmpty() );
|
||||
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
|
||||
QVERIFY( !d.explicitWeight() );
|
||||
}
|
||||
|
||||
|
||||
@ -317,6 +321,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
|
||||
InstanceDescription d = InstanceDescription::fromSettings( m );
|
||||
QVERIFY( !d.isValid() );
|
||||
QVERIFY( !d.explicitWeight() );
|
||||
}
|
||||
{
|
||||
QVariantMap m;
|
||||
@ -325,7 +330,27 @@ TestLibCalamares::testInstanceDescription()
|
||||
InstanceDescription d = InstanceDescription::fromSettings( m );
|
||||
QVERIFY( d.isValid() );
|
||||
QVERIFY( !d.isCustom() );
|
||||
// Valid, but no weight set by settings
|
||||
QCOMPARE( d.weight(), 1 );
|
||||
QVERIFY( !d.explicitWeight() );
|
||||
|
||||
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
||||
QCOMPARE( d.key().id(), QString( "welcome" ) );
|
||||
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
||||
}
|
||||
{
|
||||
QVariantMap m;
|
||||
m.insert( "module", "welcome" );
|
||||
m.insert( "weight", 1);
|
||||
|
||||
InstanceDescription d = InstanceDescription::fromSettings( m );
|
||||
QVERIFY( d.isValid() );
|
||||
QVERIFY( !d.isCustom() );
|
||||
|
||||
//Valid, set explicitly
|
||||
QCOMPARE( d.weight(), 1 );
|
||||
QVERIFY( d.explicitWeight() );
|
||||
|
||||
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
||||
QCOMPARE( d.key().id(), QString( "welcome" ) );
|
||||
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
||||
@ -343,6 +368,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
||||
QCOMPARE( d.key().id(), QString( "hi" ) );
|
||||
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
||||
QVERIFY( d.explicitWeight() );
|
||||
}
|
||||
{
|
||||
QVariantMap m;
|
||||
@ -358,6 +384,7 @@ TestLibCalamares::testInstanceDescription()
|
||||
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
||||
QCOMPARE( d.key().id(), QString( "hi" ) );
|
||||
QCOMPARE( d.configFileName(), QString( "hi.conf" ) );
|
||||
QVERIFY( d.explicitWeight() );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user