2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-07-02 17:59:24 +02:00
|
|
|
*
|
2020-08-04 13:45:36 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014-2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-07-02 17:59:24 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-07-02 17:59:24 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LocalePage.h"
|
|
|
|
|
2020-07-20 12:58:35 +02:00
|
|
|
#include "Config.h"
|
2020-07-21 17:44:44 +02:00
|
|
|
#include "LCLocaleDialog.h"
|
2019-04-19 10:10:36 +02:00
|
|
|
#include "timezonewidget/timezonewidget.h"
|
|
|
|
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
|
|
#include "utils/Logger.h"
|
2020-07-21 00:21:42 +02:00
|
|
|
#include "utils/RAII.h"
|
2019-04-19 10:10:36 +02:00
|
|
|
#include "utils/Retranslator.h"
|
|
|
|
|
2014-07-02 17:59:24 +02:00
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QLabel>
|
2020-07-21 14:57:09 +02:00
|
|
|
#include <QPointer>
|
2019-09-07 15:48:22 +02:00
|
|
|
#include <QPushButton>
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2020-07-20 12:58:35 +02:00
|
|
|
LocalePage::LocalePage( Config* config, QWidget* parent )
|
2016-07-27 13:35:03 +02:00
|
|
|
: QWidget( parent )
|
2020-07-20 12:58:35 +02:00
|
|
|
, m_config( config )
|
2020-01-07 10:46:26 +01:00
|
|
|
, m_blockTzWidgetSet( false )
|
2014-07-02 17:59:24 +02:00
|
|
|
{
|
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;
|
2020-08-06 01:27:03 +02:00
|
|
|
m_tzWidget = new TimeZoneWidget( m_config->zonesModel(), this );
|
2014-07-02 18:12:20 +02:00
|
|
|
tzwLayout->addStretch();
|
|
|
|
tzwLayout->addWidget( m_tzWidget );
|
|
|
|
tzwLayout->addStretch();
|
2020-04-17 10:19:41 +02:00
|
|
|
// Adjust for margins and spacing in this page
|
|
|
|
m_tzWidget->setMinimumHeight( m_tzWidget->minimumHeight() + 12 ); // 2 * spacing
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2020-04-17 10:19:41 +02:00
|
|
|
QBoxLayout* zoneAndRegionLayout = new QHBoxLayout;
|
2014-11-25 17:41:27 +01:00
|
|
|
m_regionLabel = new QLabel( this );
|
2020-04-17 10:19:41 +02:00
|
|
|
zoneAndRegionLayout->addWidget( m_regionLabel );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
m_regionCombo = new QComboBox( this );
|
2020-04-17 10:19:41 +02:00
|
|
|
zoneAndRegionLayout->addWidget( m_regionCombo );
|
2014-07-02 17:59:24 +02:00
|
|
|
m_regionCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
2014-11-25 17:41:27 +01:00
|
|
|
m_regionLabel->setBuddy( m_regionCombo );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2020-04-17 10:19:41 +02:00
|
|
|
zoneAndRegionLayout->addSpacing( 20 );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2014-11-25 17:41:27 +01:00
|
|
|
m_zoneLabel = new QLabel( this );
|
2020-04-17 10:19:41 +02:00
|
|
|
zoneAndRegionLayout->addWidget( m_zoneLabel );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
2014-11-25 17:41:27 +01:00
|
|
|
m_zoneCombo = new QComboBox( this );
|
|
|
|
m_zoneCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
2020-04-17 10:19:41 +02:00
|
|
|
zoneAndRegionLayout->addWidget( m_zoneCombo );
|
2014-11-25 17:41:27 +01:00
|
|
|
m_zoneLabel->setBuddy( m_zoneCombo );
|
2014-07-02 17:59:24 +02:00
|
|
|
|
|
|
|
|
2014-11-25 17:41:27 +01:00
|
|
|
QBoxLayout* localeLayout = new QHBoxLayout;
|
|
|
|
m_localeLabel = new QLabel( this );
|
|
|
|
m_localeLabel->setWordWrap( true );
|
|
|
|
m_localeLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
|
|
|
localeLayout->addWidget( m_localeLabel );
|
|
|
|
|
|
|
|
m_localeChangeButton = new QPushButton( this );
|
|
|
|
m_localeChangeButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
|
|
|
localeLayout->addWidget( m_localeChangeButton );
|
|
|
|
|
2016-08-10 11:45:22 +02:00
|
|
|
QBoxLayout* formatsLayout = new QHBoxLayout;
|
|
|
|
m_formatsLabel = new QLabel( this );
|
|
|
|
m_formatsLabel->setWordWrap( true );
|
|
|
|
m_formatsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
|
|
|
formatsLayout->addWidget( m_formatsLabel );
|
|
|
|
|
|
|
|
m_formatsChangeButton = new QPushButton( this );
|
|
|
|
m_formatsChangeButton->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
|
|
|
formatsLayout->addWidget( m_formatsChangeButton );
|
|
|
|
|
2020-04-17 10:19:41 +02:00
|
|
|
mainLayout->addLayout( tzwLayout );
|
|
|
|
mainLayout->addStretch();
|
|
|
|
mainLayout->addLayout( zoneAndRegionLayout );
|
|
|
|
mainLayout->addStretch();
|
|
|
|
mainLayout->addLayout( localeLayout );
|
|
|
|
mainLayout->addLayout( formatsLayout );
|
|
|
|
setMinimumWidth( m_tzWidget->width() );
|
2014-07-02 17:59:24 +02:00
|
|
|
setLayout( mainLayout );
|
|
|
|
|
2020-07-22 17:03:25 +02:00
|
|
|
// Set up the location before connecting signals, to avoid a signal
|
|
|
|
// storm as various parts interact.
|
2020-11-05 00:33:45 +01:00
|
|
|
{
|
|
|
|
auto* regions = m_config->regionModel();
|
|
|
|
auto* zones = m_config->regionalZonesModel();
|
|
|
|
auto* location = m_config->currentLocation();
|
|
|
|
zones->setRegion( location->region() );
|
|
|
|
m_regionCombo->setModel( regions );
|
|
|
|
m_zoneCombo->setModel( zones );
|
|
|
|
m_tzWidget->setCurrentLocation( location );
|
|
|
|
locationChanged( location ); // doesn't inform TZ widget
|
|
|
|
}
|
2020-07-22 17:03:25 +02:00
|
|
|
|
2020-07-21 16:27:21 +02:00
|
|
|
connect( config, &Config::currentLCStatusChanged, m_formatsLabel, &QLabel::setText );
|
|
|
|
connect( config, &Config::currentLanguageStatusChanged, m_localeLabel, &QLabel::setText );
|
2020-07-20 23:06:12 +02:00
|
|
|
connect( config, &Config::currentLocationChanged, m_tzWidget, &TimeZoneWidget::setCurrentLocation );
|
|
|
|
connect( config, &Config::currentLocationChanged, this, &LocalePage::locationChanged );
|
2020-07-21 00:21:42 +02:00
|
|
|
connect( m_tzWidget,
|
|
|
|
&TimeZoneWidget::locationChanged,
|
|
|
|
config,
|
2020-08-06 01:27:03 +02:00
|
|
|
QOverload< const CalamaresUtils::Locale::TimeZoneData* >::of( &Config::setCurrentLocation ) );
|
2020-07-20 23:06:12 +02:00
|
|
|
|
2019-09-07 15:18:58 +02:00
|
|
|
connect( m_regionCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::regionChanged );
|
|
|
|
connect( m_zoneCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::zoneChanged );
|
2020-07-20 23:06:12 +02:00
|
|
|
|
2019-09-07 15:47:12 +02:00
|
|
|
connect( m_localeChangeButton, &QPushButton::clicked, this, &LocalePage::changeLocale );
|
|
|
|
connect( m_formatsChangeButton, &QPushButton::clicked, this, &LocalePage::changeFormats );
|
2016-08-10 11:45:22 +02:00
|
|
|
|
2021-03-16 14:55:26 +01:00
|
|
|
CALAMARES_RETRANSLATE_SLOT( &LocalePage::updateLocaleLabels );
|
2014-07-02 17:59:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-20 22:21:29 +02:00
|
|
|
LocalePage::~LocalePage() {}
|
2014-11-25 17:41:27 +01:00
|
|
|
|
|
|
|
|
2016-08-10 11:45:22 +02:00
|
|
|
void
|
|
|
|
LocalePage::updateLocaleLabels()
|
|
|
|
{
|
2019-09-07 12:38:49 +02:00
|
|
|
m_regionLabel->setText( tr( "Region:" ) );
|
|
|
|
m_zoneLabel->setText( tr( "Zone:" ) );
|
|
|
|
m_localeChangeButton->setText( tr( "&Change..." ) );
|
|
|
|
m_formatsChangeButton->setText( tr( "&Change..." ) );
|
2020-07-21 16:27:21 +02:00
|
|
|
m_localeLabel->setText( m_config->currentLanguageStatus() );
|
|
|
|
m_formatsLabel->setText( m_config->currentLCStatus() );
|
2016-08-10 11:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 18:25:54 +02:00
|
|
|
|
2014-11-26 18:52:44 +01:00
|
|
|
void
|
|
|
|
LocalePage::onActivate()
|
|
|
|
{
|
|
|
|
m_regionCombo->setFocus();
|
2020-07-21 13:16:52 +02:00
|
|
|
updateLocaleLabels();
|
2014-11-25 17:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-07 15:18:58 +02:00
|
|
|
void
|
|
|
|
LocalePage::regionChanged( int currentIndex )
|
|
|
|
{
|
2019-12-10 16:04:09 +01:00
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
|
2020-08-06 01:27:03 +02:00
|
|
|
QString selectedRegion = m_regionCombo->itemData( currentIndex ).toString();
|
2020-07-21 00:21:42 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
cSignalBlocker z( m_zoneCombo );
|
|
|
|
m_config->regionalZonesModel()->setRegion( selectedRegion );
|
2020-07-21 00:21:42 +02:00
|
|
|
}
|
2020-08-06 01:27:03 +02:00
|
|
|
m_zoneCombo->currentIndexChanged( 0 );
|
2019-09-07 15:18:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocalePage::zoneChanged( int currentIndex )
|
|
|
|
{
|
|
|
|
if ( !m_blockTzWidgetSet )
|
2020-07-20 23:06:12 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
m_config->setCurrentLocation( m_regionCombo->currentData().toString(),
|
|
|
|
m_zoneCombo->itemData( currentIndex ).toString() );
|
2020-07-20 23:06:12 +02:00
|
|
|
}
|
2019-09-07 15:18:58 +02:00
|
|
|
}
|
2019-09-07 15:47:12 +02:00
|
|
|
|
|
|
|
void
|
2020-08-06 01:27:03 +02:00
|
|
|
LocalePage::locationChanged( const CalamaresUtils::Locale::TimeZoneData* location )
|
2019-09-07 15:47:12 +02:00
|
|
|
{
|
2020-07-22 17:03:25 +02:00
|
|
|
if ( !location )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-09-22 11:26:28 +02:00
|
|
|
cScopedAssignment b( &m_blockTzWidgetSet, true, false );
|
2019-09-07 15:47:12 +02:00
|
|
|
|
|
|
|
// Set region index
|
2019-12-11 14:36:23 +01:00
|
|
|
int index = m_regionCombo->findData( location->region() );
|
2019-09-07 15:47:12 +02:00
|
|
|
if ( index < 0 )
|
2019-09-07 15:48:22 +02:00
|
|
|
{
|
2019-09-07 15:47:12 +02:00
|
|
|
return;
|
2019-09-07 15:48:22 +02:00
|
|
|
}
|
2019-09-07 15:47:12 +02:00
|
|
|
|
|
|
|
m_regionCombo->setCurrentIndex( index );
|
|
|
|
|
|
|
|
// Set zone index
|
2019-12-11 14:36:23 +01:00
|
|
|
index = m_zoneCombo->findData( location->zone() );
|
2019-09-07 15:47:12 +02:00
|
|
|
if ( index < 0 )
|
2019-09-07 15:48:22 +02:00
|
|
|
{
|
2019-09-07 15:47:12 +02:00
|
|
|
return;
|
2019-09-07 15:48:22 +02:00
|
|
|
}
|
2019-09-07 15:47:12 +02:00
|
|
|
|
|
|
|
m_zoneCombo->setCurrentIndex( index );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocalePage::changeLocale()
|
|
|
|
{
|
2020-07-21 14:57:09 +02:00
|
|
|
QPointer< LCLocaleDialog > dlg(
|
|
|
|
new LCLocaleDialog( m_config->localeConfiguration().language(), m_config->supportedLocales(), this ) );
|
2019-09-07 15:47:12 +02:00
|
|
|
dlg->exec();
|
2020-07-21 14:57:09 +02:00
|
|
|
if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
2019-09-07 15:47:12 +02:00
|
|
|
{
|
2020-07-21 13:16:52 +02:00
|
|
|
m_config->setLanguageExplicitly( dlg->selectedLCLocale() );
|
|
|
|
updateLocaleLabels();
|
2019-09-07 15:47:12 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 14:57:09 +02:00
|
|
|
delete dlg;
|
2019-09-07 15:47:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocalePage::changeFormats()
|
|
|
|
{
|
2020-07-21 14:57:09 +02:00
|
|
|
QPointer< LCLocaleDialog > dlg(
|
|
|
|
new LCLocaleDialog( m_config->localeConfiguration().lc_numeric, m_config->supportedLocales(), this ) );
|
2019-09-07 15:47:12 +02:00
|
|
|
dlg->exec();
|
2020-07-21 14:57:09 +02:00
|
|
|
if ( dlg && dlg->result() == QDialog::Accepted && !dlg->selectedLCLocale().isEmpty() )
|
2019-09-07 15:47:12 +02:00
|
|
|
{
|
2020-07-21 13:16:52 +02:00
|
|
|
m_config->setLCLocaleExplicitly( dlg->selectedLCLocale() );
|
|
|
|
updateLocaleLabels();
|
2019-09-07 15:47:12 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 14:57:09 +02:00
|
|
|
delete dlg;
|
2019-09-07 15:47:12 +02:00
|
|
|
}
|