From 1a74a713b663485c68a35591c74c389b29d305dd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 27 Mar 2020 14:54:06 +0100 Subject: [PATCH] [netinstall] Make status an enum - Since we might change translations after loading, display the message based on the status enum, rather than setting it once at load-time. --- src/modules/netinstall/Config.cpp | 35 ++++++++++++++++++++++++------- src/modules/netinstall/Config.h | 18 +++++++++++----- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/modules/netinstall/Config.cpp b/src/modules/netinstall/Config.cpp index 1856e5a49..3ed9074c6 100644 --- a/src/modules/netinstall/Config.cpp +++ b/src/modules/netinstall/Config.cpp @@ -29,17 +29,38 @@ Config::Config( QObject* parent ) : QObject( parent ) + , m_status( Status::Ok ) , m_model( new PackageModel( this ) ) { } Config::~Config() {} +QString +Config::status() const +{ + switch ( m_status ) + { + case Status::Ok: + return QString(); + case Status::FailedBadConfiguration: + return tr( "Network Installation. (Disabled: Incorrect configuration)" ); + case Status::FailedBadData: + return tr( "Network Installation. (Disabled: Received invalid groups data)" ); + case Status::FailedInternalError: + return tr( "Network Installation. (Disabled: internal error)" ); + case Status::FailedNetworkError: + return tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ); + } + NOTREACHED return QString(); +} + + void -Config::setStatus( const QString& s ) +Config::setStatus( Status s ) { m_status = s; - emit statusChanged( m_status ); + emit statusChanged( status() ); } void @@ -53,7 +74,7 @@ Config::loadGroupList( const QUrl& url ) { if ( !url.isValid() ) { - setStatus( tr( "Network Installation. (Disabled: Incorrect configuration)" ) ); + setStatus( Status::FailedBadConfiguration ); } using namespace CalamaresUtils::Network; @@ -66,7 +87,7 @@ Config::loadGroupList( const QUrl& url ) if ( !reply ) { cDebug() << Logger::Continuation << "request failed immediately."; - setStatus( tr( "Network Installation. (Disabled: Incorrect configuration)" ) ); + setStatus( Status::FailedBadConfiguration ); } else { @@ -96,7 +117,7 @@ Config::receivedGroupData() if ( !m_reply || !m_reply->isFinished() ) { cWarning() << "NetInstall data called too early."; - setStatus( tr( "Network Installation. (Disabled: internal error)" ) ); + setStatus( Status::FailedInternalError ); return; } @@ -112,7 +133,7 @@ Config::receivedGroupData() cDebug() << Logger::SubEntry << "Netinstall reply error: " << m_reply->error(); cDebug() << Logger::SubEntry << "Request for url: " << m_reply->url().toString() << " failed with: " << m_reply->errorString(); - setStatus( tr( "Network Installation. (Disabled: Unable to fetch package lists, check your network connection)" ) ); + setStatus( Status::FailedNetworkError ); return; } @@ -130,6 +151,6 @@ Config::receivedGroupData() catch ( YAML::Exception& e ) { CalamaresUtils::explainYamlException( e, yamlData, "netinstall groups data" ); - setStatus( tr( "Network Installation. (Disabled: Received invalid groups data)" ) ); + setStatus( Status::FailedBadData ); } } diff --git a/src/modules/netinstall/Config.h b/src/modules/netinstall/Config.h index 17bfab31a..62d43c17e 100644 --- a/src/modules/netinstall/Config.h +++ b/src/modules/netinstall/Config.h @@ -33,15 +33,23 @@ class Config : public QObject Q_OBJECT Q_PROPERTY( PackageModel* packageModel MEMBER m_model FINAL ) - - Q_PROPERTY( QString status READ status WRITE setStatus NOTIFY statusChanged FINAL ) + Q_PROPERTY( QString status READ status NOTIFY statusChanged FINAL ) public: Config( QObject* parent = nullptr ); virtual ~Config(); - QString status() const { return m_status; } - void setStatus( const QString& s ); + enum class Status + { + Ok, + FailedBadConfiguration, + FailedInternalError, + FailedNetworkError, + FailedBadData + }; + + QString status() const; + void setStatus( Status s ); /** @brief Retrieves the groups, with name, description and packages * @@ -64,7 +72,7 @@ private slots: void receivedGroupData(); ///< From async-loading group data private: - QString m_status; + Status m_status; PackageModel* m_model; QNetworkReply* m_reply = nullptr; // For fetching data };