[locale] Create widgets when needed instead of at startup
- this blocks forever, since now the GeoIP lookup isn't done at all.
This commit is contained in:
parent
0a1dc77f9b
commit
41ece863de
@ -43,7 +43,8 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( LocaleViewStepFactory, registerPlugin< Loca
|
||||
LocaleViewStep::LocaleViewStep( QObject* parent )
|
||||
: Calamares::ViewStep( parent )
|
||||
, m_widget( new QWidget() )
|
||||
, m_actualWidget( new LocalePage() )
|
||||
, m_waitingWidget( nullptr )
|
||||
, m_actualWidget( nullptr )
|
||||
, m_nextEnabled( false )
|
||||
, m_geoip( nullptr )
|
||||
{
|
||||
@ -51,41 +52,6 @@ LocaleViewStep::LocaleViewStep( QObject* parent )
|
||||
m_widget->setLayout( mainLayout );
|
||||
CalamaresUtils::unmarginLayout( mainLayout );
|
||||
|
||||
m_waitingWidget = new WaitingWidget( tr( "Loading location data..." ) );
|
||||
mainLayout->addWidget( m_waitingWidget );
|
||||
|
||||
connect( &m_initWatcher, &QFutureWatcher< void >::finished, this, [=] {
|
||||
bool hasInternet = Calamares::JobQueue::instance()->globalStorage()->value( "hasInternet" ).toBool();
|
||||
if ( !m_geoip || !hasInternet )
|
||||
{
|
||||
setUpPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
fetchGeoIpTimezone();
|
||||
}
|
||||
} );
|
||||
|
||||
QFuture< void > initFuture = QtConcurrent::run( [=] {
|
||||
LocaleGlobal::init();
|
||||
if ( !m_geoip )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||
|
||||
// Max 10sec wait for RequirementsChecker to finish, assuming the welcome
|
||||
// module is used.
|
||||
// If welcome is not used, either "hasInternet" should be set by other means,
|
||||
// or the GeoIP feature should be disabled.
|
||||
for ( int i = 0; i < 10; ++i )
|
||||
if ( !gs->contains( "hasInternet" ) )
|
||||
QThread::sleep( 1 );
|
||||
} );
|
||||
|
||||
m_initWatcher.setFuture( initFuture );
|
||||
|
||||
emit nextStatusChanged( m_nextEnabled );
|
||||
}
|
||||
|
||||
@ -102,10 +68,19 @@ LocaleViewStep::~LocaleViewStep()
|
||||
void
|
||||
LocaleViewStep::setUpPage()
|
||||
{
|
||||
m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second, m_localeGenPath );
|
||||
if ( m_waitingWidget )
|
||||
{
|
||||
m_widget->layout()->removeWidget( m_waitingWidget );
|
||||
m_waitingWidget->deleteLater();
|
||||
}
|
||||
|
||||
if ( !m_actualWidget )
|
||||
{
|
||||
m_actualWidget = new LocalePage();
|
||||
}
|
||||
m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second, m_localeGenPath );
|
||||
m_widget->layout()->addWidget( m_actualWidget );
|
||||
|
||||
m_nextEnabled = true;
|
||||
emit nextStatusChanged( m_nextEnabled );
|
||||
}
|
||||
@ -122,7 +97,6 @@ LocaleViewStep::fetchGeoIpTimezone()
|
||||
cWarning() << "GeoIP lookup at" << m_geoip->url() << "failed.";
|
||||
}
|
||||
}
|
||||
setUpPage();
|
||||
}
|
||||
|
||||
|
||||
@ -143,6 +117,12 @@ LocaleViewStep::prettyStatus() const
|
||||
QWidget*
|
||||
LocaleViewStep::widget()
|
||||
{
|
||||
// If none of the inner widgets is already created, create the spinner
|
||||
if ( !m_actualWidget && !m_waitingWidget )
|
||||
{
|
||||
m_waitingWidget = new WaitingWidget( tr( "Loading location data..." ) );
|
||||
m_widget->layout()->addWidget( m_waitingWidget );
|
||||
}
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
@ -185,7 +165,10 @@ LocaleViewStep::jobs() const
|
||||
void
|
||||
LocaleViewStep::onActivate()
|
||||
{
|
||||
if ( m_actualWidget )
|
||||
{
|
||||
m_actualWidget->onActivate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -193,6 +176,9 @@ void
|
||||
LocaleViewStep::onLeave()
|
||||
{
|
||||
m_jobs.clear();
|
||||
|
||||
if ( m_actualWidget )
|
||||
{
|
||||
m_jobs.append( m_actualWidget->createJobs() );
|
||||
|
||||
m_prettyStatus = m_actualWidget->prettyStatus();
|
||||
@ -205,6 +191,11 @@ LocaleViewStep::onLeave()
|
||||
}
|
||||
|
||||
Calamares::JobQueue::instance()->globalStorage()->insert( "localeConf", vm );
|
||||
}
|
||||
else
|
||||
{
|
||||
Calamares::JobQueue::instance()->globalStorage()->remove( "localeConf" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user