[locale] Hang on to GeoIP::Handler just once

- replace configuration settings by putting them in an object
 - use unique_ptr to allow us to create one optionally.
main
Adriaan de Groot 5 years ago
parent d70d418d92
commit 0a1dc77f9b

@ -45,6 +45,7 @@ LocaleViewStep::LocaleViewStep( QObject* parent )
, m_widget( new QWidget() )
, m_actualWidget( new LocalePage() )
, m_nextEnabled( false )
, m_geoip( nullptr )
{
QBoxLayout* mainLayout = new QHBoxLayout;
m_widget->setLayout( mainLayout );
@ -55,8 +56,10 @@ LocaleViewStep::LocaleViewStep( QObject* parent )
connect( &m_initWatcher, &QFutureWatcher< void >::finished, this, [=] {
bool hasInternet = Calamares::JobQueue::instance()->globalStorage()->value( "hasInternet" ).toBool();
if ( m_geoipUrl.isEmpty() || !hasInternet )
if ( !m_geoip || !hasInternet )
{
setUpPage();
}
else
{
fetchGeoIpTimezone();
@ -65,8 +68,10 @@ LocaleViewStep::LocaleViewStep( QObject* parent )
QFuture< void > initFuture = QtConcurrent::run( [=] {
LocaleGlobal::init();
if ( m_geoipUrl.isEmpty() )
if ( !m_geoip )
{
return;
}
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
@ -109,19 +114,14 @@ LocaleViewStep::setUpPage()
void
LocaleViewStep::fetchGeoIpTimezone()
{
CalamaresUtils::GeoIP::Handler h( m_geoipStyle, m_geoipUrl, m_geoipSelector );
if ( h.isValid() )
if ( m_geoip && m_geoip->isValid() )
{
m_startingTimezone = h.get();
m_startingTimezone = m_geoip->get();
if ( !m_startingTimezone.isValid() )
{
cWarning() << "GeoIP lookup at" << m_geoipUrl << "failed.";
cWarning() << "GeoIP lookup at" << m_geoip->url() << "failed.";
}
}
else
{
cWarning() << "GeoIP Style" << m_geoipStyle << "is not recognized.";
}
setUpPage();
}
@ -233,8 +233,14 @@ LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
if ( ok )
{
m_geoipUrl = CalamaresUtils::getString( geoip, "url" );
m_geoipStyle = CalamaresUtils::getString( geoip, "style" );
m_geoipSelector = CalamaresUtils::getString( geoip, "selector" );
QString url = CalamaresUtils::getString( geoip, "url" );
QString style = CalamaresUtils::getString( geoip, "style" );
QString selector = CalamaresUtils::getString( geoip, "selector" );
m_geoip = std::make_unique< CalamaresUtils::GeoIP::Handler >( style, url, selector );
if ( !m_geoip->isValid() )
{
cWarning() << "GeoIP Style" << style << "is not recognized.";
}
}
}

@ -20,6 +20,7 @@
#ifndef LOCALEVIEWSTEP_H
#define LOCALEVIEWSTEP_H
#include "geoip/Handler.h"
#include "geoip/Interface.h"
#include "utils/PluginFactory.h"
#include "viewpages/ViewStep.h"
@ -29,6 +30,8 @@
#include <QFutureWatcher>
#include <QObject>
#include <memory>
class LocalePage;
class WaitingWidget;
@ -74,11 +77,8 @@ private:
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone;
QString m_localeGenPath;
QString m_geoipUrl; // The URL, depening on style might be modified on lookup
QString m_geoipStyle; // String selecting which kind of geoip data to expect
QString m_geoipSelector; // String selecting data from the geoip lookup
QList< Calamares::job_ptr > m_jobs;
std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip;
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( LocaleViewStepFactory )

Loading…
Cancel
Save