2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-07-04 15:33:59 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2007 Free Software Foundation, Inc.
|
|
|
|
* SPDX-FileCopyrightText: 2014-2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-07-04 15:33:59 +02:00
|
|
|
*
|
|
|
|
* Portions from the Manjaro Installation Framework
|
|
|
|
* by Roland Singer <roland@manjaro.org>
|
|
|
|
* Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-07-04 15:33:59 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "KeyboardPage.h"
|
|
|
|
|
2020-10-28 01:10:05 +01:00
|
|
|
#include "Config.h"
|
2016-05-31 19:06:53 +02:00
|
|
|
#include "KeyboardLayoutModel.h"
|
2020-03-26 15:57:02 +01:00
|
|
|
#include "SetKeyboardLayoutJob.h"
|
|
|
|
#include "keyboardwidget/keyboardpreview.h"
|
|
|
|
#include "ui_KeyboardPage.h"
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2014-08-01 12:38:27 +02:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2014-08-06 15:37:21 +02:00
|
|
|
#include "utils/Logger.h"
|
2014-11-11 15:45:51 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2020-06-23 11:13:55 +02:00
|
|
|
#include "utils/String.h"
|
2014-08-01 12:38:27 +02:00
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2017-09-10 12:44:52 +02:00
|
|
|
class LayoutItem : public QListWidgetItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString data;
|
|
|
|
|
2020-09-22 22:34:38 +02:00
|
|
|
~LayoutItem() override;
|
2017-09-10 12:44:52 +02:00
|
|
|
};
|
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
LayoutItem::~LayoutItem() {}
|
2017-09-10 12:44:52 +02:00
|
|
|
|
2020-10-28 01:10:05 +01:00
|
|
|
KeyboardPage::KeyboardPage( Config* config, QWidget* parent )
|
2017-09-10 12:22:59 +02:00
|
|
|
: QWidget( parent )
|
2014-07-04 15:33:59 +02:00
|
|
|
, ui( new Ui::Page_Keyboard )
|
|
|
|
, m_keyboardPreview( new KeyBoardPreview( this ) )
|
|
|
|
{
|
|
|
|
ui->setupUi( this );
|
|
|
|
|
|
|
|
// Keyboard Preview
|
|
|
|
ui->KBPreviewLayout->addWidget( m_keyboardPreview );
|
|
|
|
|
2020-10-28 10:38:51 +01:00
|
|
|
ui->physicalModelSelector->setModel( config->keyboardModels() );
|
2014-07-04 15:33:59 +02:00
|
|
|
// Connect signals and slots
|
2020-10-28 10:38:51 +01:00
|
|
|
connect( ui->variantSelector, &QListWidget::currentItemChanged, this, &KeyboardPage::onListVariantCurrentItemChanged );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
connect(
|
2020-10-28 01:10:05 +01:00
|
|
|
ui->buttonRestore, &QPushButton::clicked, [this] {
|
|
|
|
cDebug() << "Restore clicked";
|
2020-10-28 10:38:51 +01:00
|
|
|
// ui->physicalModelSelector->setCurrentIndex( m_defaultIndex );
|
2020-10-28 01:10:05 +01:00
|
|
|
} );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2020-10-28 10:38:51 +01:00
|
|
|
connect( ui->physicalModelSelector, &QComboBox::currentTextChanged, [this]( const QString& text ) {
|
2020-10-28 01:10:05 +01:00
|
|
|
cDebug() << "ComboBox changed to" << text;
|
|
|
|
// QString model = m_models.value( text, "pc105" );
|
2020-10-12 14:27:01 +02:00
|
|
|
|
|
|
|
// Set Xorg keyboard model
|
2020-10-28 01:10:05 +01:00
|
|
|
// QProcess::execute( "setxkbmap", QStringList { "-model", model } );
|
2020-10-12 14:27:01 +02:00
|
|
|
} );
|
2014-11-11 15:45:51 +01:00
|
|
|
|
|
|
|
CALAMARES_RETRANSLATE( ui->retranslateUi( this ); )
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KeyboardPage::~KeyboardPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-03-26 15:57:02 +01:00
|
|
|
KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant )
|
2014-07-04 15:33:59 +02:00
|
|
|
{
|
|
|
|
// Block signals
|
2020-10-28 10:38:51 +01:00
|
|
|
ui->variantSelector->blockSignals( true );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2020-03-26 15:57:02 +01:00
|
|
|
QMap< QString, QString > variants
|
|
|
|
= currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole ).value< QMap< QString, QString > >();
|
2014-07-04 15:33:59 +02:00
|
|
|
QMapIterator< QString, QString > li( variants );
|
|
|
|
LayoutItem* defaultItem = nullptr;
|
|
|
|
|
2020-10-28 10:38:51 +01:00
|
|
|
ui->variantSelector->clear();
|
2014-07-04 15:33:59 +02:00
|
|
|
|
|
|
|
while ( li.hasNext() )
|
|
|
|
{
|
2017-09-26 11:22:51 +02:00
|
|
|
li.next();
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2017-09-26 11:22:51 +02:00
|
|
|
LayoutItem* item = new LayoutItem();
|
|
|
|
item->setText( li.key() );
|
|
|
|
item->data = li.value();
|
2020-10-28 10:38:51 +01:00
|
|
|
ui->variantSelector->addItem( item );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2017-09-26 11:22:51 +02:00
|
|
|
// currentVariant defaults to QString(). It is only non-empty during the
|
|
|
|
// initial setup.
|
|
|
|
if ( li.value() == currentVariant )
|
2020-03-26 15:57:02 +01:00
|
|
|
{
|
2017-09-26 11:22:51 +02:00
|
|
|
defaultItem = item;
|
2020-03-26 15:57:02 +01:00
|
|
|
}
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unblock signals
|
2020-10-28 10:38:51 +01:00
|
|
|
ui->variantSelector->blockSignals( false );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
|
|
|
// Set to default value
|
|
|
|
if ( defaultItem )
|
2020-03-26 15:57:02 +01:00
|
|
|
{
|
2020-10-28 10:38:51 +01:00
|
|
|
ui->variantSelector->setCurrentItem( defaultItem );
|
2020-03-26 15:57:02 +01:00
|
|
|
}
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-05 02:25:08 +01:00
|
|
|
void
|
2020-03-26 15:57:02 +01:00
|
|
|
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, const QModelIndex& previous )
|
2014-12-05 02:25:08 +01:00
|
|
|
{
|
2019-04-17 11:57:46 +02:00
|
|
|
Q_UNUSED( previous )
|
2016-05-31 19:06:53 +02:00
|
|
|
if ( !current.isValid() )
|
2020-03-26 15:57:02 +01:00
|
|
|
{
|
2016-05-31 19:06:53 +02:00
|
|
|
return;
|
2020-03-26 15:57:02 +01:00
|
|
|
}
|
2014-12-05 02:25:08 +01:00
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
updateVariants( QPersistentModelIndex( current ) );
|
2014-12-05 02:25:08 +01:00
|
|
|
}
|
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
void
|
|
|
|
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
|
|
|
{
|
2019-04-17 11:57:46 +02:00
|
|
|
Q_UNUSED( previous )
|
2017-09-10 12:22:59 +02:00
|
|
|
|
2020-10-28 01:10:05 +01:00
|
|
|
cDebug() << "item" << Logger::Pointer( current );
|
|
|
|
|
2020-10-28 10:38:51 +01:00
|
|
|
QPersistentModelIndex layoutIndex = ui->layoutSelector->currentIndex();
|
2014-07-04 15:33:59 +02:00
|
|
|
LayoutItem* variantItem = dynamic_cast< LayoutItem* >( current );
|
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
if ( !layoutIndex.isValid() || !variantItem )
|
2020-03-26 15:57:02 +01:00
|
|
|
{
|
2014-07-04 15:33:59 +02:00
|
|
|
return;
|
2020-03-26 15:57:02 +01:00
|
|
|
}
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
QString layout = layoutIndex.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
|
2014-07-04 15:33:59 +02:00
|
|
|
QString variant = variantItem->data;
|
|
|
|
|
2020-10-28 01:10:05 +01:00
|
|
|
cDebug() << Logger::SubEntry << layout << variant;
|
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
m_keyboardPreview->setLayout( layout );
|
|
|
|
m_keyboardPreview->setVariant( variant );
|
|
|
|
}
|