Merge branch 'welcome-config'
This commit is contained in:
commit
ea51ff9285
@ -103,6 +103,7 @@ strings:
|
|||||||
supportUrl: https://github.com/calamares/calamares/issues
|
supportUrl: https://github.com/calamares/calamares/issues
|
||||||
knownIssuesUrl: https://calamares.io/about/
|
knownIssuesUrl: https://calamares.io/about/
|
||||||
releaseNotesUrl: https://calamares.io/about/
|
releaseNotesUrl: https://calamares.io/about/
|
||||||
|
donateUrl: https://kde.org/community/donations/index.php
|
||||||
|
|
||||||
# These images are loaded from the branding module directory.
|
# These images are loaded from the branding module directory.
|
||||||
#
|
#
|
||||||
|
@ -67,7 +67,8 @@ const QStringList Branding::s_stringEntryStrings =
|
|||||||
"productUrl",
|
"productUrl",
|
||||||
"supportUrl",
|
"supportUrl",
|
||||||
"knownIssuesUrl",
|
"knownIssuesUrl",
|
||||||
"releaseNotesUrl"
|
"releaseNotesUrl",
|
||||||
|
"donateUrl"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QSize>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
namespace YAML
|
namespace YAML
|
||||||
@ -61,7 +63,8 @@ public:
|
|||||||
ProductUrl,
|
ProductUrl,
|
||||||
SupportUrl,
|
SupportUrl,
|
||||||
KnownIssuesUrl,
|
KnownIssuesUrl,
|
||||||
ReleaseNotesUrl
|
ReleaseNotesUrl,
|
||||||
|
DonateUrl
|
||||||
};
|
};
|
||||||
Q_ENUM( StringEntry )
|
Q_ENUM( StringEntry )
|
||||||
|
|
||||||
|
@ -20,8 +20,13 @@
|
|||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "geoip/Handler.h"
|
||||||
|
#include "locale/Lookup.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Retranslator.h"
|
#include "utils/Retranslator.h"
|
||||||
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
Config::Config( QObject* parent )
|
Config::Config( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
@ -103,7 +108,7 @@ Config::initLanguages()
|
|||||||
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
||||||
|
|
||||||
cDebug() << "Matching locale" << defaultLocale;
|
cDebug() << "Matching locale" << defaultLocale;
|
||||||
int matchedLocaleIndex = m_languages->find( [ & ]( const QLocale& x ) {
|
int matchedLocaleIndex = m_languages->find( [&]( const QLocale& x ) {
|
||||||
return x.language() == defaultLocale.language() && x.country() == defaultLocale.country();
|
return x.language() == defaultLocale.language() && x.country() == defaultLocale.country();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
@ -112,7 +117,7 @@ Config::initLanguages()
|
|||||||
cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language();
|
cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language();
|
||||||
|
|
||||||
matchedLocaleIndex
|
matchedLocaleIndex
|
||||||
= m_languages->find( [ & ]( const QLocale& x ) { return x.language() == defaultLocale.language(); } );
|
= m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( matchedLocaleIndex < 0 )
|
if ( matchedLocaleIndex < 0 )
|
||||||
@ -245,3 +250,136 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
setLanguageIcon( Config* c, const QVariantMap& configurationMap )
|
||||||
|
{
|
||||||
|
QString language = CalamaresUtils::getString( configurationMap, "languageIcon" );
|
||||||
|
if ( !language.isEmpty() )
|
||||||
|
{
|
||||||
|
auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) );
|
||||||
|
if ( !icon.isNull() )
|
||||||
|
{
|
||||||
|
c->setLanguageIcon( language );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
|
||||||
|
{
|
||||||
|
if ( handler )
|
||||||
|
{
|
||||||
|
cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " ("
|
||||||
|
<< static_cast< int >( handler->type() ) << handler->selector() << ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
setCountry( Config* config, const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler )
|
||||||
|
{
|
||||||
|
if ( countryCode.length() != 2 )
|
||||||
|
{
|
||||||
|
cDebug() << "Unusable country code" << countryCode;
|
||||||
|
logGeoIPHandler( handler );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto c_l = CalamaresUtils::Locale::countryData( countryCode );
|
||||||
|
if ( c_l.first == QLocale::Country::AnyCountry )
|
||||||
|
{
|
||||||
|
cDebug() << "Unusable country code" << countryCode;
|
||||||
|
logGeoIPHandler( handler );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode );
|
||||||
|
if ( r < 0 )
|
||||||
|
{
|
||||||
|
cDebug() << "Unusable country code" << countryCode << "(no suitable translation)";
|
||||||
|
}
|
||||||
|
if ( ( r >= 0 ) && config )
|
||||||
|
{
|
||||||
|
config->setCountryCode( countryCode );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
setGeoIP( Config* c, const QVariantMap& configurationMap )
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
||||||
|
if ( ok )
|
||||||
|
{
|
||||||
|
using FWString = QFutureWatcher< QString >;
|
||||||
|
|
||||||
|
auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ),
|
||||||
|
CalamaresUtils::getString( geoip, "url" ),
|
||||||
|
CalamaresUtils::getString( geoip, "selector" ) );
|
||||||
|
if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None )
|
||||||
|
{
|
||||||
|
auto* future = new FWString();
|
||||||
|
QObject::connect( future, &FWString::finished, [config = c, f = future, h = handler]() {
|
||||||
|
QString countryResult = f->future().result();
|
||||||
|
cDebug() << "GeoIP result for welcome=" << countryResult;
|
||||||
|
::setCountry( config, countryResult, h );
|
||||||
|
f->deleteLater();
|
||||||
|
delete h;
|
||||||
|
} );
|
||||||
|
future->setFuture( handler->queryRaw() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Would not produce useful country code anyway.
|
||||||
|
delete handler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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" ) );
|
||||||
|
|
||||||
|
::setLanguageIcon( this, configurationMap );
|
||||||
|
::setGeoIP( this, configurationMap );
|
||||||
|
}
|
||||||
|
@ -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 );
|
||||||
|
@ -173,7 +173,7 @@ WelcomePage::setupButton( Button role, const QString& url )
|
|||||||
{
|
{
|
||||||
auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() );
|
auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() );
|
||||||
button->setIcon( CalamaresUtils::defaultPixmap( icon, CalamaresUtils::Original, size ) );
|
button->setIcon( CalamaresUtils::defaultPixmap( icon, CalamaresUtils::Original, size ) );
|
||||||
connect( button, &QPushButton::clicked, [ u ]() { QDesktopServices::openUrl( u ); } );
|
connect( button, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -24,15 +24,10 @@
|
|||||||
#include "checker/GeneralRequirements.h"
|
#include "checker/GeneralRequirements.h"
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "geoip/Handler.h"
|
|
||||||
#include "locale/Lookup.h"
|
|
||||||
#include "modulesystem/ModuleManager.h"
|
#include "modulesystem/ModuleManager.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
#include <QFutureWatcher>
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); )
|
||||||
|
|
||||||
WelcomeViewStep::WelcomeViewStep( QObject* parent )
|
WelcomeViewStep::WelcomeViewStep( QObject* parent )
|
||||||
@ -107,49 +102,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 )
|
||||||
@ -162,40 +118,6 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
cWarning() << "no valid requirements map found in welcome "
|
cWarning() << "no valid requirements map found in welcome "
|
||||||
"module configuration.";
|
"module configuration.";
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
|
||||||
if ( ok )
|
|
||||||
{
|
|
||||||
using FWString = QFutureWatcher< QString >;
|
|
||||||
|
|
||||||
auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ),
|
|
||||||
CalamaresUtils::getString( geoip, "url" ),
|
|
||||||
CalamaresUtils::getString( geoip, "selector" ) );
|
|
||||||
if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None )
|
|
||||||
{
|
|
||||||
auto* future = new FWString();
|
|
||||||
connect( future, &FWString::finished, [ view = this, f = future, h = handler ]() {
|
|
||||||
QString countryResult = f->future().result();
|
|
||||||
cDebug() << "GeoIP result for welcome=" << countryResult;
|
|
||||||
view->setCountry( countryResult, h );
|
|
||||||
f->deleteLater();
|
|
||||||
delete h;
|
|
||||||
} );
|
|
||||||
future->setFuture( handler->queryRaw() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Would not produce useful country code anyway.
|
|
||||||
delete handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString language = CalamaresUtils::getString( configurationMap, "languageIcon" );
|
|
||||||
if ( !language.isEmpty() )
|
|
||||||
{
|
|
||||||
m_conf->setLanguageIcon( language );
|
|
||||||
}
|
|
||||||
|
|
||||||
//here init the qml or qwidgets needed bits
|
//here init the qml or qwidgets needed bits
|
||||||
m_widget->init();
|
m_widget->init();
|
||||||
}
|
}
|
||||||
@ -205,44 +127,3 @@ WelcomeViewStep::checkRequirements()
|
|||||||
{
|
{
|
||||||
return m_requirementsChecker->checkRequirements();
|
return m_requirementsChecker->checkRequirements();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
|
|
||||||
{
|
|
||||||
if ( handler )
|
|
||||||
{
|
|
||||||
cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " ("
|
|
||||||
<< static_cast< int >( handler->type() ) << handler->selector() << ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler )
|
|
||||||
{
|
|
||||||
if ( countryCode.length() != 2 )
|
|
||||||
{
|
|
||||||
cDebug() << "Unusable country code" << countryCode;
|
|
||||||
logGeoIPHandler( handler );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto c_l = CalamaresUtils::Locale::countryData( countryCode );
|
|
||||||
if ( c_l.first == QLocale::Country::AnyCountry )
|
|
||||||
{
|
|
||||||
cDebug() << "Unusable country code" << countryCode;
|
|
||||||
logGeoIPHandler( handler );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode );
|
|
||||||
if ( r < 0 )
|
|
||||||
{
|
|
||||||
cDebug() << "Unusable country code" << countryCode << "(no suitable translation)";
|
|
||||||
}
|
|
||||||
if ( ( r >= 0 ) && m_conf )
|
|
||||||
{
|
|
||||||
m_conf->setCountryCode( countryCode );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -14,15 +14,8 @@
|
|||||||
# which will hide the button.
|
# which will hide the button.
|
||||||
showSupportUrl: true
|
showSupportUrl: true
|
||||||
showKnownIssuesUrl: true
|
showKnownIssuesUrl: true
|
||||||
showReleaseNotesUrl: true
|
showReleaseNotesUrl: false
|
||||||
|
showDonateUrl: https://kde.org/community/donations/
|
||||||
# If this Url is set to something non-empty, a "donate"
|
|
||||||
# button is added to the welcome page alongside the
|
|
||||||
# others (see settings, above). Clicking the button opens
|
|
||||||
# the corresponding link. (This button has no corresponding
|
|
||||||
# branding.desc string)
|
|
||||||
#
|
|
||||||
# showDonateUrl: https://kde.org/community/donations/
|
|
||||||
|
|
||||||
# Requirements checking. These are general, generic, things
|
# Requirements checking. These are general, generic, things
|
||||||
# that are checked. They may not match with the actual requirements
|
# that are checked. They may not match with the actual requirements
|
||||||
|
@ -21,22 +21,15 @@
|
|||||||
|
|
||||||
#include "checker/GeneralRequirements.h"
|
#include "checker/GeneralRequirements.h"
|
||||||
|
|
||||||
#include "geoip/Handler.h"
|
|
||||||
#include "locale/LabelModel.h"
|
#include "locale/LabelModel.h"
|
||||||
#include "locale/Lookup.h"
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
#include "utils/Dirs.h"
|
#include "utils/Dirs.h"
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "modulesystem/ModuleManager.h"
|
#include "modulesystem/ModuleManager.h"
|
||||||
#include <QQmlEngine>
|
|
||||||
#include "utils/Yaml.h"
|
#include "utils/Yaml.h"
|
||||||
|
|
||||||
#include <QFutureWatcher>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); )
|
||||||
|
|
||||||
WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent )
|
WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent )
|
||||||
@ -98,48 +91,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
|
||||||
@ -154,44 +109,6 @@ WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
cWarning() << "no valid requirements map found in welcome "
|
cWarning() << "no valid requirements map found in welcome "
|
||||||
"module configuration.";
|
"module configuration.";
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
|
||||||
if ( ok )
|
|
||||||
{
|
|
||||||
using FWString = QFutureWatcher< QString >;
|
|
||||||
|
|
||||||
auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ),
|
|
||||||
CalamaresUtils::getString( geoip, "url" ),
|
|
||||||
CalamaresUtils::getString( geoip, "selector" ) );
|
|
||||||
if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None )
|
|
||||||
{
|
|
||||||
auto* future = new FWString();
|
|
||||||
connect( future, &FWString::finished, [view = this, f = future, h = handler]() {
|
|
||||||
QString countryResult = f->future().result();
|
|
||||||
cDebug() << "GeoIP result for welcome=" << countryResult;
|
|
||||||
view->setCountry( countryResult, h );
|
|
||||||
f->deleteLater();
|
|
||||||
delete h;
|
|
||||||
} );
|
|
||||||
future->setFuture( handler->queryRaw() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Would not produce useful country code anyway.
|
|
||||||
delete handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString language = CalamaresUtils::getString( configurationMap, "languageIcon" );
|
|
||||||
if ( !language.isEmpty() )
|
|
||||||
{
|
|
||||||
auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) );
|
|
||||||
if ( !icon.isNull() )
|
|
||||||
{
|
|
||||||
m_config->setLanguageIcon(language);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last
|
Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last
|
||||||
setContextProperty( "Welcome", m_config );
|
setContextProperty( "Welcome", m_config );
|
||||||
}
|
}
|
||||||
@ -208,44 +125,3 @@ WelcomeQmlViewStep::getConfig()
|
|||||||
return m_config;
|
return m_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
|
||||||
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
|
|
||||||
{
|
|
||||||
if ( handler )
|
|
||||||
{
|
|
||||||
cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " ("
|
|
||||||
<< static_cast< int >( handler->type() ) << handler->selector() << ')';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler )
|
|
||||||
{
|
|
||||||
if ( countryCode.length() != 2 )
|
|
||||||
{
|
|
||||||
cDebug() << "Unusable country code" << countryCode;
|
|
||||||
logGeoIPHandler( handler );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto c_l = CalamaresUtils::Locale::countryData( countryCode );
|
|
||||||
if ( c_l.first == QLocale::Country::AnyCountry )
|
|
||||||
{
|
|
||||||
cDebug() << "Unusable country code" << countryCode;
|
|
||||||
logGeoIPHandler( handler );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode );
|
|
||||||
if ( r < 0 )
|
|
||||||
{
|
|
||||||
cDebug() << "Unusable country code" << countryCode << "(no suitable translation)";
|
|
||||||
}
|
|
||||||
if ( ( r >= 0 ) )
|
|
||||||
{
|
|
||||||
// TODO: update Config to point to selected language
|
|
||||||
m_config->setCountryCode( countryCode );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user