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 "LocalePage.h"
|
|
|
|
|
|
|
|
#include "timezonewidget/timezonewidget.h"
|
2014-08-01 16:29:19 +02:00
|
|
|
#include "SetTimezoneJob.h"
|
2014-11-11 12:44:06 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
|
|
|
|
LocalePage::LocalePage( QWidget* parent )
|
|
|
|
: QWidget()
|
|
|
|
, m_blockTzWidgetSet( false )
|
|
|
|
{
|
2014-07-02 18:12:20 +02:00
|
|
|
QBoxLayout* mainLayout = new QVBoxLayout;
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2014-07-02 18:12:20 +02:00
|
|
|
QBoxLayout* tzwLayout = new QHBoxLayout;
|
|
|
|
mainLayout->addLayout( tzwLayout );
|
2014-07-02 17:59:24 +02:00
|
|
|
m_tzWidget = new TimeZoneWidget( this );
|
2014-07-02 18:12:20 +02:00
|
|
|
tzwLayout->addStretch();
|
|
|
|
tzwLayout->addWidget( m_tzWidget );
|
|
|
|
tzwLayout->addStretch();
|
|
|
|
setMinimumWidth( m_tzWidget->width() );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2014-07-02 18:12:20 +02:00
|
|
|
QBoxLayout* bottomLayout = new QHBoxLayout;
|
2014-07-02 17:59:24 +02:00
|
|
|
mainLayout->addLayout( bottomLayout );
|
|
|
|
|
2014-11-10 14:56:29 +01:00
|
|
|
m_cityLabel = new QLabel( this );
|
|
|
|
bottomLayout->addWidget( m_cityLabel );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
m_regionCombo = new QComboBox( this );
|
|
|
|
bottomLayout->addWidget( m_regionCombo );
|
|
|
|
m_regionCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
2014-11-10 14:56:29 +01:00
|
|
|
m_cityLabel->setBuddy( m_regionCombo );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
bottomLayout->addSpacing( 20 );
|
|
|
|
|
2014-11-10 14:56:29 +01:00
|
|
|
m_timezoneLabel = new QLabel( this );
|
|
|
|
bottomLayout->addWidget( m_timezoneLabel );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
m_timezoneCombo = new QComboBox( this );
|
|
|
|
m_timezoneCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
|
|
|
bottomLayout->addWidget( m_timezoneCombo );
|
2014-11-10 14:56:29 +01:00
|
|
|
m_timezoneLabel->setBuddy( m_timezoneCombo );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
mainLayout->addStretch();
|
|
|
|
|
|
|
|
setLayout( mainLayout );
|
|
|
|
|
|
|
|
connect( m_regionCombo,
|
|
|
|
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
|
|
|
|
[this]( const QString& current )
|
|
|
|
{
|
|
|
|
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
|
|
|
|
if ( !regions.contains( current ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_timezoneCombo->blockSignals( true );
|
|
|
|
|
|
|
|
m_timezoneCombo->clear();
|
|
|
|
|
|
|
|
QList< LocaleGlobal::Location > zones = regions.value( current );
|
|
|
|
foreach ( const LocaleGlobal::Location& zone, zones )
|
|
|
|
{
|
|
|
|
m_timezoneCombo->addItem( zone.zone );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_timezoneCombo->model()->sort( 0 );
|
|
|
|
|
|
|
|
m_timezoneCombo->blockSignals( false );
|
|
|
|
|
|
|
|
m_timezoneCombo->currentIndexChanged( m_timezoneCombo->currentText() );
|
|
|
|
});
|
|
|
|
|
|
|
|
connect( m_timezoneCombo,
|
|
|
|
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
|
|
|
|
[this]( const QString& current )
|
|
|
|
{
|
|
|
|
if ( !m_blockTzWidgetSet )
|
|
|
|
m_tzWidget->setCurrentLocation( m_regionCombo->currentText(), current );
|
|
|
|
});
|
|
|
|
|
|
|
|
connect( m_tzWidget, &TimeZoneWidget::locationChanged,
|
|
|
|
[this]( LocaleGlobal::Location location )
|
|
|
|
{
|
|
|
|
m_blockTzWidgetSet = true;
|
|
|
|
|
|
|
|
// Set region index
|
|
|
|
int index = m_regionCombo->findText( location.region );
|
|
|
|
if ( index < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_regionCombo->setCurrentIndex( index );
|
|
|
|
|
|
|
|
// Set zone index
|
|
|
|
index = m_timezoneCombo->findText( location.zone );
|
|
|
|
if ( index < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_timezoneCombo->setCurrentIndex( index );
|
|
|
|
|
|
|
|
m_blockTzWidgetSet = false;
|
|
|
|
});
|
2014-11-11 12:44:06 +01:00
|
|
|
|
2014-11-11 15:11:06 +01:00
|
|
|
RETRANSLATE(
|
2014-11-11 12:44:06 +01:00
|
|
|
m_cityLabel->setText( tr( "Region:" ) );
|
|
|
|
m_timezoneLabel->setText( tr( "Zone:" ) );
|
2014-11-11 15:11:06 +01:00
|
|
|
)
|
2014-07-02 17:59:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-07-15 11:35:05 +02:00
|
|
|
LocalePage::init( const QString& initialRegion, const QString& initialZone )
|
2014-07-02 17:59:24 +02:00
|
|
|
{
|
|
|
|
m_regionCombo->blockSignals( true );
|
|
|
|
m_timezoneCombo->blockSignals( true );
|
|
|
|
|
|
|
|
// Setup locations
|
|
|
|
QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations();
|
|
|
|
|
|
|
|
QStringList keys = regions.keys();
|
|
|
|
keys.sort();
|
|
|
|
|
|
|
|
foreach ( const QString& key, keys )
|
|
|
|
{
|
|
|
|
m_regionCombo->addItem( key );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_regionCombo->blockSignals( false );
|
|
|
|
m_timezoneCombo->blockSignals( false );
|
|
|
|
|
|
|
|
m_regionCombo->currentIndexChanged( m_regionCombo->currentText() );
|
2014-07-02 18:12:20 +02:00
|
|
|
|
|
|
|
// Default location
|
2014-07-15 11:35:05 +02:00
|
|
|
auto containsLocation = []( const QList< LocaleGlobal::Location >& locations,
|
|
|
|
const QString& zone ) -> bool
|
|
|
|
{
|
|
|
|
foreach ( const LocaleGlobal::Location& location, locations )
|
|
|
|
{
|
|
|
|
if ( location.zone == zone )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( keys.contains( initialRegion ) &&
|
|
|
|
containsLocation( regions.value( initialRegion ), initialZone ) )
|
|
|
|
{
|
|
|
|
m_tzWidget->setCurrentLocation( initialRegion, initialZone );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_tzWidget->setCurrentLocation( "Europe", "Berlin" );
|
|
|
|
}
|
2014-07-02 18:12:20 +02:00
|
|
|
emit m_tzWidget->locationChanged( m_tzWidget->getCurrentLocation() );
|
2014-07-02 17:59:24 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 18:25:54 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
LocalePage::prettyStatus() const
|
|
|
|
{
|
|
|
|
QString status;
|
|
|
|
status += tr( "Set timezone to %1/%2.<br/>" )
|
|
|
|
.arg( m_regionCombo->currentText() )
|
|
|
|
.arg( m_timezoneCombo->currentText() );
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-08-01 16:29:19 +02:00
|
|
|
|
|
|
|
QList< Calamares::job_ptr >
|
|
|
|
LocalePage::createJobs()
|
|
|
|
{
|
|
|
|
QList< Calamares::job_ptr > list;
|
|
|
|
LocaleGlobal::Location location = m_tzWidget->getCurrentLocation();
|
|
|
|
|
|
|
|
Calamares::Job* j = new SetTimezoneJob( location.region, location.zone );
|
|
|
|
list.append( Calamares::job_ptr( j ) );
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
2014-11-10 14:56:29 +01:00
|
|
|
|