2014-07-02 17:59:24 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LocaleViewStep.h"
|
|
|
|
|
|
|
|
#include "LocalePage.h"
|
2014-08-21 17:44:35 +02:00
|
|
|
#include "widgets/QtWaitingSpinner.h"
|
2014-07-02 17:59:24 +02:00
|
|
|
#include "timezonewidget/localeglobal.h"
|
|
|
|
|
2014-07-03 13:13:38 +02:00
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
|
|
|
|
2014-07-02 17:59:24 +02:00
|
|
|
LocaleViewStep::LocaleViewStep( QObject* parent )
|
|
|
|
: Calamares::ViewStep( parent )
|
2014-07-03 13:13:38 +02:00
|
|
|
, m_widget( new QWidget() )
|
|
|
|
, m_actualWidget( new LocalePage() )
|
2014-07-03 13:19:32 +02:00
|
|
|
, m_nextEnabled( false )
|
2014-07-02 17:59:24 +02:00
|
|
|
{
|
2014-07-03 13:13:38 +02:00
|
|
|
QBoxLayout* mainLayout = new QHBoxLayout;
|
|
|
|
m_widget->setLayout( mainLayout );
|
|
|
|
CalamaresUtils::unmarginLayout( mainLayout );
|
|
|
|
|
2014-07-03 15:38:55 +02:00
|
|
|
QWidget* waitingWidget = new QWidget;
|
|
|
|
{
|
|
|
|
QBoxLayout* waitingLayout = new QVBoxLayout;
|
|
|
|
waitingWidget->setLayout( waitingLayout );
|
|
|
|
waitingLayout->addStretch();
|
|
|
|
QBoxLayout* pbLayout = new QHBoxLayout;
|
|
|
|
waitingLayout->addLayout( pbLayout );
|
|
|
|
pbLayout->addStretch();
|
|
|
|
|
|
|
|
QtWaitingSpinner* spnr = new QtWaitingSpinner();
|
|
|
|
pbLayout->addWidget( spnr );
|
|
|
|
|
|
|
|
pbLayout->addStretch();
|
|
|
|
|
|
|
|
QLabel* waitingLabel = new QLabel( "Loading location data..." );
|
|
|
|
|
|
|
|
int spnrSize = waitingLabel->fontMetrics().height() * 4;
|
|
|
|
spnr->setFixedSize( spnrSize, spnrSize );
|
|
|
|
spnr->setRadius( spnrSize / 2 );
|
|
|
|
spnr->setLength( spnrSize / 2 );
|
|
|
|
spnr->setWidth( spnrSize / 8 );
|
|
|
|
spnr->start();
|
|
|
|
|
|
|
|
waitingLabel->setAlignment( Qt::AlignCenter);
|
|
|
|
waitingLayout->addSpacing( spnrSize / 2 );
|
|
|
|
waitingLayout->addWidget( waitingLabel );
|
|
|
|
waitingLayout->addStretch();
|
|
|
|
|
|
|
|
mainLayout->addWidget( waitingWidget );
|
|
|
|
|
|
|
|
CalamaresUtils::unmarginLayout( waitingLayout );
|
|
|
|
}
|
2014-07-03 13:13:38 +02:00
|
|
|
|
|
|
|
connect( &m_initWatcher, &QFutureWatcher< void >::finished,
|
|
|
|
[=]
|
|
|
|
{
|
2014-07-15 11:35:05 +02:00
|
|
|
m_actualWidget->init( m_startingTimezone.first, m_startingTimezone.second );
|
2014-07-03 15:38:55 +02:00
|
|
|
m_widget->layout()->removeWidget( waitingWidget );
|
|
|
|
waitingWidget->deleteLater();
|
2014-07-03 13:13:38 +02:00
|
|
|
m_widget->layout()->addWidget( m_actualWidget );
|
2014-07-03 13:19:32 +02:00
|
|
|
m_nextEnabled = true;
|
|
|
|
emit nextStatusChanged( m_nextEnabled );
|
2014-07-03 13:13:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
QFuture< void > initFuture = QtConcurrent::run( LocaleGlobal::init );
|
|
|
|
m_initWatcher.setFuture( initFuture );
|
|
|
|
|
2014-07-03 13:19:32 +02:00
|
|
|
emit nextStatusChanged( m_nextEnabled );
|
2014-07-02 17:59:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LocaleViewStep::~LocaleViewStep()
|
|
|
|
{
|
|
|
|
if ( m_widget && m_widget->parent() == nullptr )
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
LocaleViewStep::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Location" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-08 18:25:54 +02:00
|
|
|
QString
|
|
|
|
LocaleViewStep::prettyStatus() const
|
|
|
|
{
|
|
|
|
return m_prettyStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-02 17:59:24 +02:00
|
|
|
QWidget*
|
|
|
|
LocaleViewStep::widget()
|
|
|
|
{
|
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleViewStep::next()
|
|
|
|
{
|
|
|
|
//TODO: actually save those settings somewhere
|
|
|
|
emit done();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleViewStep::back()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
LocaleViewStep::isNextEnabled() const
|
|
|
|
{
|
2014-07-03 13:19:32 +02:00
|
|
|
return m_nextEnabled;
|
2014-07-02 17:59:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
LocaleViewStep::isAtBeginning() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
LocaleViewStep::isAtEnd() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-08 14:02:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
QList< Calamares::job_ptr >
|
|
|
|
LocaleViewStep::jobs() const
|
|
|
|
{
|
2014-08-01 16:29:19 +02:00
|
|
|
return m_jobs;
|
2014-07-08 14:02:21 +02:00
|
|
|
}
|
2014-07-08 18:25:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleViewStep::onLeave()
|
|
|
|
{
|
2014-08-01 16:29:19 +02:00
|
|
|
m_jobs.clear();
|
|
|
|
m_jobs.append( m_actualWidget->createJobs() );
|
|
|
|
|
2014-07-08 18:25:54 +02:00
|
|
|
m_prettyStatus = m_actualWidget->prettyStatus();
|
|
|
|
}
|
2014-07-15 11:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
if ( configurationMap.contains( "region" ) &&
|
|
|
|
configurationMap.value( "region" ).type() == QVariant::String &&
|
|
|
|
!configurationMap.value( "region" ).toString().isEmpty() &&
|
|
|
|
configurationMap.contains( "zone" ) &&
|
|
|
|
configurationMap.value( "zone" ).type() == QVariant::String &&
|
|
|
|
!configurationMap.value( "zone" ).toString().isEmpty() )
|
|
|
|
{
|
|
|
|
m_startingTimezone = qMakePair( configurationMap.value( "region" ).toString(),
|
|
|
|
configurationMap.value( "zone" ).toString() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_startingTimezone = qMakePair( QStringLiteral( "Europe" ),
|
|
|
|
QStringLiteral( "Berlin" ) );
|
|
|
|
}
|
|
|
|
}
|