Commit 1a74a713 authored by Adriaan de Groot's avatar Adriaan de Groot

[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.
parent f5b4e5d5
......@@ -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 );
}
}
......@@ -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
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment