diff --git a/src/modules/locale/LCLocaleDialog.cpp b/src/modules/locale/LCLocaleDialog.cpp new file mode 100644 index 000000000..5bb08d582 --- /dev/null +++ b/src/modules/locale/LCLocaleDialog.cpp @@ -0,0 +1,82 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 . + */ + +#include "LCLocaleDialog.h" + +#include +#include +#include +#include + +LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale, + const QStringList& localeGenLines, + QWidget* parent ) + : QDialog( parent ) +{ + setModal( true ); + + QBoxLayout* mainLayout = new QVBoxLayout; + setLayout( mainLayout ); + + 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; + } + } + + QDialogButtonBox* dbb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, + Qt::Horizontal, + this ); + mainLayout->addWidget( dbb ); + + connect( dbb->button( QDialogButtonBox::Ok ), &QPushButton::clicked, + this, &QDialog::accept ); + connect( dbb->button( QDialogButtonBox::Cancel ), &QPushButton::clicked, + this, &QDialog::reject ); + + connect( m_localesWidget, &QListWidget::itemSelectionChanged, + [this, dbb]() + { + if ( m_localesWidget->selectedItems().isEmpty() ) + dbb->button( QDialogButtonBox::Ok )->setEnabled( false ); + else + dbb->button( QDialogButtonBox::Ok )->setEnabled( true ); + + } ); + + if ( selected > -1 ) + { + m_localesWidget->setCurrentRow( selected ); + } +} + + +QString +LCLocaleDialog::selectedLCLocale() +{ + return m_localesWidget->selectedItems().first()->text(); +} diff --git a/src/modules/locale/LCLocaleDialog.h b/src/modules/locale/LCLocaleDialog.h new file mode 100644 index 000000000..3654eb147 --- /dev/null +++ b/src/modules/locale/LCLocaleDialog.h @@ -0,0 +1,40 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * + * 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 . + */ + +#ifndef LCLOCALEDIALOG_H +#define LCLOCALEDIALOG_H + +#include + +class QListWidget; + +class LCLocaleDialog : public QDialog +{ + Q_OBJECT +public: + explicit LCLocaleDialog( const QString& guessedLCLocale, + const QStringList& localeGenLines, + QWidget* parent = nullptr ); + + QString selectedLCLocale(); + +private: + QListWidget* m_localesWidget; +}; + +#endif // LCLOCALEDIALOG_H