[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 )
|
InstanceDescription::InstanceDescription( const Calamares::ModuleSystem::InstanceKey& key )
|
||||||
: m_instanceKey( key )
|
: m_instanceKey( key )
|
||||||
, m_weight( 1 )
|
, m_weight( -1 )
|
||||||
{
|
{
|
||||||
if ( !isValid() )
|
if ( !isValid() )
|
||||||
{
|
{
|
||||||
@ -94,8 +94,11 @@ InstanceDescription::fromSettings( const QVariantMap& m )
|
|||||||
Calamares::ModuleSystem::InstanceKey( m.value( "module" ).toString(), m.value( "id" ).toString() ) );
|
Calamares::ModuleSystem::InstanceKey( m.value( "module" ).toString(), m.value( "id" ).toString() ) );
|
||||||
if ( r.isValid() )
|
if ( r.isValid() )
|
||||||
{
|
{
|
||||||
int w = qBound( 1, m.value( "weight" ).toInt(), 100 );
|
if ( m.value( "weight" ).isValid() )
|
||||||
r.m_weight = w;
|
{
|
||||||
|
int w = qBound( 1, m.value( "weight" ).toInt(), 100 );
|
||||||
|
r.m_weight = w;
|
||||||
|
}
|
||||||
|
|
||||||
QString c = m.value( "config" ).toString();
|
QString c = m.value( "config" ).toString();
|
||||||
if ( !c.isEmpty() )
|
if ( !c.isEmpty() )
|
||||||
|
@ -71,7 +71,8 @@ public:
|
|||||||
const InstanceKey& key() const { return m_instanceKey; }
|
const InstanceKey& key() const { return m_instanceKey; }
|
||||||
QString configFileName() const { return m_configFileName; }
|
QString configFileName() const { return m_configFileName; }
|
||||||
bool isCustom() const { return m_instanceKey.isCustom(); }
|
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:
|
private:
|
||||||
InstanceKey m_instanceKey;
|
InstanceKey m_instanceKey;
|
||||||
|
@ -270,6 +270,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
QVERIFY( !d.isCustom() );
|
QVERIFY( !d.isCustom() );
|
||||||
QCOMPARE( d.weight(), 0 );
|
QCOMPARE( d.weight(), 0 );
|
||||||
QVERIFY( d.configFileName().isEmpty() );
|
QVERIFY( d.configFileName().isEmpty() );
|
||||||
|
QVERIFY( !d.explicitWeight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -278,6 +279,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
QVERIFY( !d.isCustom() );
|
QVERIFY( !d.isCustom() );
|
||||||
QCOMPARE( d.weight(), 0 );
|
QCOMPARE( d.weight(), 0 );
|
||||||
QVERIFY( d.configFileName().isEmpty() );
|
QVERIFY( d.configFileName().isEmpty() );
|
||||||
|
QVERIFY( !d.explicitWeight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private constructor
|
// Private constructor
|
||||||
@ -290,6 +292,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
|
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
|
||||||
QVERIFY( !d.configFileName().isEmpty() );
|
QVERIFY( !d.configFileName().isEmpty() );
|
||||||
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
|
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
|
||||||
|
QVERIFY( !d.explicitWeight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -299,6 +302,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
|
QCOMPARE( d.weight(), 1 ); // **now** the constraints kick in
|
||||||
QVERIFY( !d.configFileName().isEmpty() );
|
QVERIFY( !d.configFileName().isEmpty() );
|
||||||
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
|
QCOMPARE( d.configFileName(), QStringLiteral( "welcome.conf" ) );
|
||||||
|
QVERIFY( !d.explicitWeight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -317,6 +321,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
|
|
||||||
InstanceDescription d = InstanceDescription::fromSettings( m );
|
InstanceDescription d = InstanceDescription::fromSettings( m );
|
||||||
QVERIFY( !d.isValid() );
|
QVERIFY( !d.isValid() );
|
||||||
|
QVERIFY( !d.explicitWeight() );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
@ -325,7 +330,27 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
InstanceDescription d = InstanceDescription::fromSettings( m );
|
InstanceDescription d = InstanceDescription::fromSettings( m );
|
||||||
QVERIFY( d.isValid() );
|
QVERIFY( d.isValid() );
|
||||||
QVERIFY( !d.isCustom() );
|
QVERIFY( !d.isCustom() );
|
||||||
|
// Valid, but no weight set by settings
|
||||||
QCOMPARE( d.weight(), 1 );
|
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().module(), QString( "welcome" ) );
|
||||||
QCOMPARE( d.key().id(), QString( "welcome" ) );
|
QCOMPARE( d.key().id(), QString( "welcome" ) );
|
||||||
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
||||||
@ -343,6 +368,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
||||||
QCOMPARE( d.key().id(), QString( "hi" ) );
|
QCOMPARE( d.key().id(), QString( "hi" ) );
|
||||||
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
QCOMPARE( d.configFileName(), QString( "welcome.conf" ) );
|
||||||
|
QVERIFY( d.explicitWeight() );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
@ -358,6 +384,7 @@ TestLibCalamares::testInstanceDescription()
|
|||||||
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
QCOMPARE( d.key().module(), QString( "welcome" ) );
|
||||||
QCOMPARE( d.key().id(), QString( "hi" ) );
|
QCOMPARE( d.key().id(), QString( "hi" ) );
|
||||||
QCOMPARE( d.configFileName(), QString( "hi.conf" ) );
|
QCOMPARE( d.configFileName(), QString( "hi.conf" ) );
|
||||||
|
QVERIFY( d.explicitWeight() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user