diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 7e10de0e8..592ffd02d 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -75,7 +75,7 @@ namespace Calamares InstanceDescription::InstanceDescription( const Calamares::ModuleSystem::InstanceKey& key ) : m_instanceKey( key ) - , m_weight( 1 ) + , m_weight( -1 ) { if ( !isValid() ) { @@ -94,8 +94,11 @@ InstanceDescription::fromSettings( const QVariantMap& m ) Calamares::ModuleSystem::InstanceKey( m.value( "module" ).toString(), m.value( "id" ).toString() ) ); if ( r.isValid() ) { - int w = qBound( 1, m.value( "weight" ).toInt(), 100 ); - r.m_weight = w; + 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() ) diff --git a/src/libcalamares/Settings.h b/src/libcalamares/Settings.h index 8e463fc70..1cff4b34a 100644 --- a/src/libcalamares/Settings.h +++ b/src/libcalamares/Settings.h @@ -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; diff --git a/src/libcalamares/Tests.cpp b/src/libcalamares/Tests.cpp index 1dc297dd4..5903dfde6 100644 --- a/src/libcalamares/Tests.cpp +++ b/src/libcalamares/Tests.cpp @@ -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() ); } }