1 | /* === This file is part of Calamares - <https://github.com/calamares> === |
---|
2 | * |
---|
3 | * Copyright 2014, Teo Mrnjavac <teo@kde.org> |
---|
4 | * Copyright 2017, Adriaan de Groot <groot@kde.org> |
---|
5 | * |
---|
6 | * Calamares is free software: you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation, either version 3 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * Calamares is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with Calamares. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | */ |
---|
19 | |
---|
20 | #include "LCLocaleDialog.h" |
---|
21 | |
---|
22 | #include <QBoxLayout> |
---|
23 | #include <QDialogButtonBox> |
---|
24 | #include <QLabel> |
---|
25 | #include <QListWidget> |
---|
26 | #include <QPushButton> |
---|
27 | |
---|
28 | LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale, |
---|
29 | const QStringList& localeGenLines, |
---|
30 | QWidget* parent ) |
---|
31 | : QDialog( parent ) |
---|
32 | { |
---|
33 | setModal( true ); |
---|
34 | setWindowTitle( tr( "System locale setting" ) ); |
---|
35 | |
---|
36 | QBoxLayout* mainLayout = new QVBoxLayout; |
---|
37 | setLayout( mainLayout ); |
---|
38 | |
---|
39 | QLabel* upperText = new QLabel( this ); |
---|
40 | upperText->setWordWrap( true ); |
---|
41 | upperText->setText( tr( "The system locale setting affects the language and character " |
---|
42 | "set for some command line user interface elements.<br/>" |
---|
43 | "The current setting is <strong>%1</strong>." ) |
---|
44 | .arg( guessedLCLocale ) ); |
---|
45 | mainLayout->addWidget( upperText ); |
---|
46 | setMinimumWidth( upperText->fontMetrics().height() * 24 ); |
---|
47 | |
---|
48 | m_localesWidget = new QListWidget( this ); |
---|
49 | m_localesWidget->addItems( localeGenLines ); |
---|
50 | m_localesWidget->setSelectionMode( QAbstractItemView::SingleSelection ); |
---|
51 | mainLayout->addWidget( m_localesWidget ); |
---|
52 | |
---|
53 | int selected = -1; |
---|
54 | for ( int i = 0; i < localeGenLines.count(); ++i ) |
---|
55 | { |
---|
56 | if ( localeGenLines[ i ].contains( guessedLCLocale ) ) |
---|
57 | { |
---|
58 | selected = i; |
---|
59 | break; |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | QDialogButtonBox* dbb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, |
---|
64 | Qt::Horizontal, |
---|
65 | this ); |
---|
66 | dbb->button( QDialogButtonBox::Cancel )->setText( tr( "&Cancel" ) ); |
---|
67 | dbb->button( QDialogButtonBox::Ok )->setText( tr( "&OK" ) ); |
---|
68 | |
---|
69 | mainLayout->addWidget( dbb ); |
---|
70 | |
---|
71 | connect( dbb->button( QDialogButtonBox::Ok ), &QPushButton::clicked, |
---|
72 | this, &QDialog::accept ); |
---|
73 | connect( dbb->button( QDialogButtonBox::Cancel ), &QPushButton::clicked, |
---|
74 | this, &QDialog::reject ); |
---|
75 | |
---|
76 | connect( m_localesWidget, &QListWidget::itemDoubleClicked, |
---|
77 | this, &QDialog::accept ); |
---|
78 | connect( m_localesWidget, &QListWidget::itemSelectionChanged, |
---|
79 | [this, dbb]() |
---|
80 | { |
---|
81 | if ( m_localesWidget->selectedItems().isEmpty() ) |
---|
82 | dbb->button( QDialogButtonBox::Ok )->setEnabled( false ); |
---|
83 | else |
---|
84 | dbb->button( QDialogButtonBox::Ok )->setEnabled( true ); |
---|
85 | |
---|
86 | } ); |
---|
87 | |
---|
88 | if ( selected > -1 ) |
---|
89 | m_localesWidget->setCurrentRow( selected ); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | QString |
---|
94 | LCLocaleDialog::selectedLCLocale() |
---|
95 | { |
---|
96 | return m_localesWidget->selectedItems().first()->text(); |
---|
97 | } |
---|