2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-11-25 17:23:15 +01:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-11-25 17:23:15 +01:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-11-25 17:23:15 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LCLocaleDialog.h"
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QDialogButtonBox>
|
2014-11-25 17:39:09 +01:00
|
|
|
#include <QLabel>
|
2014-11-25 17:23:15 +01:00
|
|
|
#include <QListWidget>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale, const QStringList& localeGenLines, QWidget* parent )
|
2014-11-25 17:23:15 +01:00
|
|
|
: QDialog( parent )
|
|
|
|
{
|
|
|
|
setModal( true );
|
2014-11-25 17:39:09 +01:00
|
|
|
setWindowTitle( tr( "System locale setting" ) );
|
2014-11-25 17:23:15 +01:00
|
|
|
|
|
|
|
QBoxLayout* mainLayout = new QVBoxLayout;
|
|
|
|
setLayout( mainLayout );
|
|
|
|
|
2014-11-25 17:39:09 +01:00
|
|
|
QLabel* upperText = new QLabel( this );
|
|
|
|
upperText->setWordWrap( true );
|
|
|
|
upperText->setText( tr( "The system locale setting affects the language and character "
|
|
|
|
"set for some command line user interface elements.<br/>"
|
2015-04-10 13:31:49 +02:00
|
|
|
"The current setting is <strong>%1</strong>." )
|
2019-09-07 16:58:37 +02:00
|
|
|
.arg( guessedLCLocale ) );
|
2014-11-25 17:39:09 +01:00
|
|
|
mainLayout->addWidget( upperText );
|
|
|
|
setMinimumWidth( upperText->fontMetrics().height() * 24 );
|
|
|
|
|
2014-11-25 17:23:15 +01:00
|
|
|
m_localesWidget = new QListWidget( this );
|
|
|
|
m_localesWidget->addItems( localeGenLines );
|
|
|
|
m_localesWidget->setSelectionMode( QAbstractItemView::SingleSelection );
|
|
|
|
mainLayout->addWidget( m_localesWidget );
|
|
|
|
|
|
|
|
int selected = -1;
|
|
|
|
for ( int i = 0; i < localeGenLines.count(); ++i )
|
|
|
|
{
|
|
|
|
if ( localeGenLines[ i ].contains( guessedLCLocale ) )
|
|
|
|
{
|
|
|
|
selected = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
QDialogButtonBox* dbb
|
|
|
|
= new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
|
2017-09-04 13:57:20 +02:00
|
|
|
dbb->button( QDialogButtonBox::Cancel )->setText( tr( "&Cancel" ) );
|
|
|
|
dbb->button( QDialogButtonBox::Ok )->setText( tr( "&OK" ) );
|
|
|
|
|
2014-11-25 17:23:15 +01:00
|
|
|
mainLayout->addWidget( dbb );
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
connect( dbb->button( QDialogButtonBox::Ok ), &QPushButton::clicked, this, &QDialog::accept );
|
|
|
|
connect( dbb->button( QDialogButtonBox::Cancel ), &QPushButton::clicked, this, &QDialog::reject );
|
2014-11-25 17:23:15 +01:00
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
connect( m_localesWidget, &QListWidget::itemDoubleClicked, this, &QDialog::accept );
|
|
|
|
connect( m_localesWidget,
|
|
|
|
&QListWidget::itemSelectionChanged,
|
|
|
|
[ this, dbb ]()
|
|
|
|
{
|
2014-11-25 17:23:15 +01:00
|
|
|
if ( m_localesWidget->selectedItems().isEmpty() )
|
2019-09-07 16:58:37 +02:00
|
|
|
{
|
2014-11-25 17:23:15 +01:00
|
|
|
dbb->button( QDialogButtonBox::Ok )->setEnabled( false );
|
2019-09-07 16:58:37 +02:00
|
|
|
}
|
2014-11-25 17:23:15 +01:00
|
|
|
else
|
2019-09-07 16:58:37 +02:00
|
|
|
{
|
2014-11-25 17:23:15 +01:00
|
|
|
dbb->button( QDialogButtonBox::Ok )->setEnabled( true );
|
2019-09-07 16:58:37 +02:00
|
|
|
}
|
2014-11-25 17:23:15 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
if ( selected > -1 )
|
2019-09-07 16:58:37 +02:00
|
|
|
{
|
2014-11-25 17:23:15 +01:00
|
|
|
m_localesWidget->setCurrentRow( selected );
|
2019-09-07 16:58:37 +02:00
|
|
|
}
|
2014-11-25 17:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
LCLocaleDialog::selectedLCLocale()
|
|
|
|
{
|
|
|
|
return m_localesWidget->selectedItems().first()->text();
|
|
|
|
}
|