[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.
This commit is contained in:
Adriaan de Groot 2020-03-27 14:54:06 +01:00
parent f5b4e5d5e1
commit 1a74a713b6
2 changed files with 41 additions and 12 deletions

View File

@ -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 );
}
}

View File

@ -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
};