diff --git a/src/modules/netinstall/Config.cpp b/src/modules/netinstall/Config.cpp index e69b3c2a4..99fe28eb0 100644 --- a/src/modules/netinstall/Config.cpp +++ b/src/modules/netinstall/Config.cpp @@ -12,9 +12,12 @@ #include "Config.h" +#include "GlobalStorage.h" +#include "JobQueue.h" #include "network/Manager.h" #include "utils/Logger.h" #include "utils/RAII.h" +#include "utils/Variant.h" #include "utils/Yaml.h" #include @@ -54,6 +57,19 @@ Config::setStatus( Status s ) emit statusChanged( status() ); } +QString +Config::sidebarLabel() const +{ + return m_sidebarLabel ? m_sidebarLabel->get() : tr( "Package selection" ); +} + +QString +Config::titleLabel() const +{ + return m_titleLabel ? m_titleLabel->get() : QString(); +} + + void Config::loadGroupList( const QVariantList& groupData ) { @@ -143,3 +159,36 @@ Config::receivedGroupData() setStatus( Status::FailedBadData ); } } + +void +Config::setConfigurationMap( const QVariantMap& configurationMap ) +{ + setRequired( CalamaresUtils::getBool( configurationMap, "required", false ) ); + + // Get the translations, if any + bool bogus = false; + auto label = CalamaresUtils::getSubMap( configurationMap, "label", bogus ); + + if ( label.contains( "sidebar" ) ) + { + m_sidebarLabel = new CalamaresUtils::Locale::TranslatedString( label, "sidebar", metaObject()->className() ); + } + + // Lastly, load the groups data + QString groupsUrl = CalamaresUtils::getString( configurationMap, "groupsUrl" ); + if ( !groupsUrl.isEmpty() ) + { + // Keep putting groupsUrl into the global storage, + // even though it's no longer used for in-module data-passing. + Calamares::JobQueue::instance()->globalStorage()->insert( "groupsUrl", groupsUrl ); + if ( groupsUrl == QStringLiteral( "local" ) ) + { + QVariantList l = configurationMap.value( "groups" ).toList(); + loadGroupList( l ); + } + else + { + loadGroupList( groupsUrl ); + } + } +} diff --git a/src/modules/netinstall/Config.h b/src/modules/netinstall/Config.h index 13eb098c6..24c5e6b68 100644 --- a/src/modules/netinstall/Config.h +++ b/src/modules/netinstall/Config.h @@ -14,8 +14,11 @@ #include "PackageModel.h" +#include "locale/TranslatableConfiguration.h" + #include #include +#include class QNetworkReply; @@ -26,10 +29,16 @@ class Config : public QObject Q_PROPERTY( PackageModel* packageModel MEMBER m_model FINAL ) Q_PROPERTY( QString status READ status NOTIFY statusChanged FINAL ) + // Translations, of the module name (for sidebar) and above the list + Q_PROPERTY( QString sidebarLabel READ sidebarLabel NOTIFY sidebarLabelChanged FINAL ) + Q_PROPERTY( QString titleLabel READ titleLabel NOTIFY titleLabelChanged FINAL ) + public: Config( QObject* parent = nullptr ); ~Config() override; + void setConfigurationMap( const QVariantMap& configurationMap ); + enum class Status { Ok, @@ -45,6 +54,11 @@ public: bool required() const { return m_required; } void setRequired( bool r ) { m_required = r; } + PackageModel* model() const { return m_model; } + + QString sidebarLabel() const; + QString titleLabel() const; + /** @brief Retrieves the groups, with name, description and packages * * Loads data from the given URL. Once done, the data is parsed @@ -59,16 +73,19 @@ public: */ void loadGroupList( const QVariantList& groupData ); - PackageModel* model() const { return m_model; } signals: void statusChanged( QString status ); ///< Something changed + void sidebarLabelChanged( QString label ); + void titleLabelChanged( QString label ); void statusReady(); ///< Loading groups is complete private slots: void receivedGroupData(); ///< From async-loading group data private: + CalamaresUtils::Locale::TranslatedString* m_sidebarLabel = nullptr; // As it appears in the sidebar + CalamaresUtils::Locale::TranslatedString* m_titleLabel = nullptr; PackageModel* m_model = nullptr; QNetworkReply* m_reply = nullptr; // For fetching data Status m_status = Status::Ok; diff --git a/src/modules/netinstall/NetInstallViewStep.cpp b/src/modules/netinstall/NetInstallViewStep.cpp index d92058e51..2e035a8aa 100644 --- a/src/modules/netinstall/NetInstallViewStep.cpp +++ b/src/modules/netinstall/NetInstallViewStep.cpp @@ -24,7 +24,6 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( NetInstallViewStepFactory, registerPlugin< NetInstallViewStep::NetInstallViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new NetInstallPage( &m_config ) ) - , m_sidebarLabel( nullptr ) , m_nextEnabled( false ) { connect( &m_config, &Config::statusReady, this, &NetInstallViewStep::nextIsReady ); @@ -37,14 +36,13 @@ NetInstallViewStep::~NetInstallViewStep() { m_widget->deleteLater(); } - delete m_sidebarLabel; } QString NetInstallViewStep::prettyName() const { - return m_sidebarLabel ? m_sidebarLabel->get() : tr( "Package selection" ); + return m_config.sidebarLabel(); #if defined( TABLE_OF_TRANSLATIONS ) __builtin_unreachable(); @@ -201,32 +199,11 @@ NetInstallViewStep::nextIsReady() void NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - m_config.setRequired( CalamaresUtils::getBool( configurationMap, "required", false ) ); - - QString groupsUrl = CalamaresUtils::getString( configurationMap, "groupsUrl" ); - if ( !groupsUrl.isEmpty() ) - { - // Keep putting groupsUrl into the global storage, - // even though it's no longer used for in-module data-passing. - Calamares::JobQueue::instance()->globalStorage()->insert( "groupsUrl", groupsUrl ); - if ( groupsUrl == QStringLiteral( "local" ) ) - { - QVariantList l = configurationMap.value( "groups" ).toList(); - m_config.loadGroupList( l ); - } - else - { - m_config.loadGroupList( groupsUrl ); - } - } + m_config.setConfigurationMap( configurationMap ); bool bogus = false; auto label = CalamaresUtils::getSubMap( configurationMap, "label", bogus ); - if ( label.contains( "sidebar" ) ) - { - m_sidebarLabel = new CalamaresUtils::Locale::TranslatedString( label, "sidebar", metaObject()->className() ); - } if ( label.contains( "title" ) ) { m_widget->setPageTitle( diff --git a/src/modules/netinstall/NetInstallViewStep.h b/src/modules/netinstall/NetInstallViewStep.h index c500cbcd9..8949632c1 100644 --- a/src/modules/netinstall/NetInstallViewStep.h +++ b/src/modules/netinstall/NetInstallViewStep.h @@ -14,7 +14,6 @@ #include "Config.h" #include "DllMacro.h" -#include "locale/TranslatableConfiguration.h" #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" @@ -56,7 +55,6 @@ private: Config m_config; NetInstallPage* m_widget; - CalamaresUtils::Locale::TranslatedString* m_sidebarLabel; // As it appears in the sidebar bool m_nextEnabled = false; };