[welcome] Move get-the-show*Url code into Config
- Since this is configuration-loading, put it in the Config class; reduces code duplication between welcome and welcomeq.
This commit is contained in:
parent
e65a0ee617
commit
120a2b0f03
@ -245,3 +245,48 @@ Config::warningMessage() const
|
|||||||
{
|
{
|
||||||
return m_warningMessage;
|
return m_warningMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Look up a URL for a button
|
||||||
|
*
|
||||||
|
* Looks up @p key in @p map; if it is a *boolean* value, then
|
||||||
|
* assume an old-style configuration, and fetch the string from
|
||||||
|
* the branding settings @p e. If it is a string, not a boolean,
|
||||||
|
* use it as-is. If not found, or a weird type, returns empty.
|
||||||
|
*
|
||||||
|
* This allows switching the showKnownIssuesUrl and similar settings
|
||||||
|
* in welcome.conf from a boolean (deferring to branding) to an
|
||||||
|
* actual string for immediate use. Empty strings, as well as
|
||||||
|
* "false" as a setting, will hide the buttons as before.
|
||||||
|
*/
|
||||||
|
static QString
|
||||||
|
jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key )
|
||||||
|
{
|
||||||
|
if ( !map.contains( key ) )
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
auto v = map.value( key );
|
||||||
|
if ( v.type() == QVariant::Bool )
|
||||||
|
{
|
||||||
|
return v.toBool() ? ( Calamares::Branding::instance()->string( e ) ) : QString();
|
||||||
|
}
|
||||||
|
if ( v.type() == QVariant::String )
|
||||||
|
{
|
||||||
|
return v.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
|
{
|
||||||
|
using Calamares::Branding;
|
||||||
|
|
||||||
|
setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
|
||||||
|
setKnownIssuesUrl(
|
||||||
|
jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
|
||||||
|
setReleaseNotesUrl(
|
||||||
|
jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
|
||||||
|
setDonateUrl( jobOrBrandingSetting( Branding::DonateUrl, configurationMap, "showDonateUrl" ) );
|
||||||
|
}
|
||||||
|
@ -50,6 +50,8 @@ class Config : public QObject
|
|||||||
public:
|
public:
|
||||||
Config( QObject* parent = nullptr );
|
Config( QObject* parent = nullptr );
|
||||||
|
|
||||||
|
void setConfigurationMap( const QVariantMap& );
|
||||||
|
|
||||||
Calamares::RequirementsModel& requirementsModel() const;
|
Calamares::RequirementsModel& requirementsModel() const;
|
||||||
|
|
||||||
void setCountryCode( const QString& countryCode );
|
void setCountryCode( const QString& countryCode );
|
||||||
|
@ -107,49 +107,10 @@ WelcomeViewStep::jobs() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @brief Look up a URL for a button
|
|
||||||
*
|
|
||||||
* Looks up @p key in @p map; if it is a *boolean* value, then
|
|
||||||
* assume an old-style configuration, and fetch the string from
|
|
||||||
* the branding settings @p e. If it is a string, not a boolean,
|
|
||||||
* use it as-is. If not found, or a weird type, returns empty.
|
|
||||||
*
|
|
||||||
* This allows switching the showKnownIssuesUrl and similar settings
|
|
||||||
* in welcome.conf from a boolean (deferring to branding) to an
|
|
||||||
* actual string for immediate use. Empty strings, as well as
|
|
||||||
* "false" as a setting, will hide the buttons as before.
|
|
||||||
*/
|
|
||||||
static QString
|
|
||||||
jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key )
|
|
||||||
{
|
|
||||||
if ( !map.contains( key ) )
|
|
||||||
{
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
auto v = map.value( key );
|
|
||||||
if ( v.type() == QVariant::Bool )
|
|
||||||
{
|
|
||||||
return v.toBool() ? ( Calamares::Branding::instance()->string( e ) ) : QString();
|
|
||||||
}
|
|
||||||
if ( v.type() == QVariant::String )
|
|
||||||
{
|
|
||||||
return v.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
using Calamares::Branding;
|
m_conf->setConfigurationMap( configurationMap );
|
||||||
|
|
||||||
m_conf->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
|
|
||||||
m_conf->setKnownIssuesUrl(
|
|
||||||
jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
|
|
||||||
m_conf->setReleaseNotesUrl(
|
|
||||||
jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
|
|
||||||
m_conf->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
|
|
||||||
|
|
||||||
if ( configurationMap.contains( "requirements" )
|
if ( configurationMap.contains( "requirements" )
|
||||||
&& configurationMap.value( "requirements" ).type() == QVariant::Map )
|
&& configurationMap.value( "requirements" ).type() == QVariant::Map )
|
||||||
|
@ -98,48 +98,10 @@ WelcomeQmlViewStep::jobs() const
|
|||||||
return Calamares::JobList();
|
return Calamares::JobList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Look up a URL for a button
|
|
||||||
*
|
|
||||||
* Looks up @p key in @p map; if it is a *boolean* value, then
|
|
||||||
* assume an old-style configuration, and fetch the string from
|
|
||||||
* the branding settings @p e. If it is a string, not a boolean,
|
|
||||||
* use it as-is. If not found, or a weird type, returns empty.
|
|
||||||
*
|
|
||||||
* This allows switching the showKnownIssuesUrl and similar settings
|
|
||||||
* in welcome.conf from a boolean (deferring to branding) to an
|
|
||||||
* actual string for immediate use. Empty strings, as well as
|
|
||||||
* "false" as a setting, will hide the buttons as before.
|
|
||||||
*/
|
|
||||||
static QString
|
|
||||||
jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key )
|
|
||||||
{
|
|
||||||
if ( !map.contains( key ) )
|
|
||||||
{
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
auto v = map.value( key );
|
|
||||||
if ( v.type() == QVariant::Bool )
|
|
||||||
{
|
|
||||||
return v.toBool() ? ( Calamares::Branding::instance()->string( e ) ) : QString();
|
|
||||||
}
|
|
||||||
if ( v.type() == QVariant::String )
|
|
||||||
{
|
|
||||||
return v.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
using Calamares::Branding;
|
m_config->setConfigurationMap( configurationMap );
|
||||||
m_config->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
|
|
||||||
m_config->setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
|
|
||||||
m_config->setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
|
|
||||||
m_config->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
|
|
||||||
|
|
||||||
// TODO: expand Config class and set the remaining fields // with the configurationMap all those properties can be accessed without having to declare a property, get and setter for each
|
|
||||||
|
|
||||||
// TODO: figure out how the requirements (held by ModuleManager) should be accessible
|
// TODO: figure out how the requirements (held by ModuleManager) should be accessible
|
||||||
// to QML as a model. //will be model as a qvariantmap containing a alert level and the message string
|
// to QML as a model. //will be model as a qvariantmap containing a alert level and the message string
|
||||||
|
Loading…
Reference in New Issue
Block a user