[welcome] Move GeoIP loading into Config
- The Config object can handle GeoIP loading on its own. Both View steps that used this had a derpy view->setCountry() that didn't really do anything with the view anymore.
This commit is contained in:
parent
6434374bf3
commit
713132d4af
@ -20,10 +20,14 @@
|
||||
|
||||
#include "Branding.h"
|
||||
#include "Settings.h"
|
||||
#include "geoip/Handler.h"
|
||||
#include "locale/Lookup.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Retranslator.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
Config::Config( QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_requirementsModel( new Calamares::RequirementsModel( this ) )
|
||||
@ -279,6 +283,93 @@ jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map
|
||||
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 )
|
||||
{
|
||||
@ -291,13 +382,6 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
|
||||
setDonateUrl( jobOrBrandingSetting( Branding::DonateUrl, configurationMap, "showDonateUrl" ) );
|
||||
|
||||
QString language = CalamaresUtils::getString( configurationMap, "languageIcon" );
|
||||
if ( !language.isEmpty() )
|
||||
{
|
||||
auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) );
|
||||
if ( !icon.isNull() )
|
||||
{
|
||||
setLanguageIcon( language );
|
||||
}
|
||||
}
|
||||
::setLanguageIcon( this, configurationMap );
|
||||
::setGeoIP( this, configurationMap );
|
||||
}
|
||||
|
@ -24,15 +24,10 @@
|
||||
#include "checker/GeneralRequirements.h"
|
||||
|
||||
#include "Branding.h"
|
||||
#include "geoip/Handler.h"
|
||||
#include "locale/Lookup.h"
|
||||
#include "modulesystem/ModuleManager.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
#include <QVariant>
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); )
|
||||
|
||||
WelcomeViewStep::WelcomeViewStep( QObject* parent )
|
||||
@ -123,34 +118,6 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
cWarning() << "no valid requirements map found in welcome "
|
||||
"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;
|
||||
}
|
||||
}
|
||||
|
||||
//here init the qml or qwidgets needed bits
|
||||
m_widget->init();
|
||||
}
|
||||
@ -161,43 +128,3 @@ WelcomeViewStep::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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,22 +21,15 @@
|
||||
|
||||
#include "checker/GeneralRequirements.h"
|
||||
|
||||
#include "geoip/Handler.h"
|
||||
#include "locale/LabelModel.h"
|
||||
#include "locale/Lookup.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
#include "utils/Dirs.h"
|
||||
|
||||
#include "Branding.h"
|
||||
#include "modulesystem/ModuleManager.h"
|
||||
#include <QQmlEngine>
|
||||
#include "utils/Yaml.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
#include <QPixmap>
|
||||
#include <QVariant>
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); )
|
||||
|
||||
WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent )
|
||||
@ -116,34 +109,6 @@ WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
cWarning() << "no valid requirements map found in welcome "
|
||||
"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;
|
||||
}
|
||||
}
|
||||
|
||||
Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation last
|
||||
setContextProperty( "Welcome", m_config );
|
||||
}
|
||||
@ -160,44 +125,3 @@ WelcomeQmlViewStep::getConfig()
|
||||
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