2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-07-04 15:33:59 +02:00
|
|
|
*
|
2016-05-31 19:06:53 +02:00
|
|
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
2017-06-07 20:05:13 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
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.
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "KeyboardPage.h"
|
|
|
|
|
|
|
|
#include "ui_KeyboardPage.h"
|
|
|
|
#include "keyboardwidget/keyboardpreview.h"
|
2014-11-11 02:58:14 +01:00
|
|
|
#include "SetKeyboardLayoutJob.h"
|
2016-05-31 19:06:53 +02:00
|
|
|
#include "KeyboardLayoutModel.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"
|
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;
|
|
|
|
|
|
|
|
virtual ~LayoutItem();
|
|
|
|
};
|
|
|
|
|
|
|
|
LayoutItem::~LayoutItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:11:08 +02:00
|
|
|
static QPersistentModelIndex
|
|
|
|
findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
|
|
|
|
{
|
|
|
|
QPersistentModelIndex currentLayoutItem;
|
|
|
|
|
|
|
|
for ( int i = 0; i < klm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
QModelIndex idx = klm->index( i );
|
|
|
|
if ( idx.isValid() &&
|
2017-09-26 11:22:51 +02:00
|
|
|
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
|
2017-06-19 17:11:08 +02:00
|
|
|
currentLayoutItem = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentLayoutItem;
|
|
|
|
}
|
2014-07-04 15:33:59 +02:00
|
|
|
|
|
|
|
KeyboardPage::KeyboardPage( 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 ) )
|
2015-06-13 21:33:00 +02:00
|
|
|
, m_defaultIndex( 0 )
|
2014-07-04 15:33:59 +02:00
|
|
|
{
|
|
|
|
ui->setupUi( this );
|
|
|
|
|
|
|
|
// Keyboard Preview
|
|
|
|
ui->KBPreviewLayout->addWidget( m_keyboardPreview );
|
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
m_setxkbmapTimer.setSingleShot( true );
|
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
// Connect signals and slots
|
|
|
|
connect( ui->listVariant, &QListWidget::currentItemChanged,
|
|
|
|
this, &KeyboardPage::onListVariantCurrentItemChanged );
|
|
|
|
|
|
|
|
connect( ui->buttonRestore, &QPushButton::clicked,
|
|
|
|
[this]
|
|
|
|
{
|
|
|
|
ui->comboBoxModel->setCurrentIndex( m_defaultIndex );
|
2017-09-26 11:22:51 +02:00
|
|
|
} );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
|
|
|
connect( ui->comboBoxModel,
|
|
|
|
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
|
|
|
|
[this]( const QString& text )
|
|
|
|
{
|
|
|
|
QString model = m_models.value( text, "pc105" );
|
|
|
|
|
|
|
|
// Set Xorg keyboard model
|
2017-06-19 16:41:56 +02:00
|
|
|
QProcess::execute( QLatin1Literal( "setxkbmap" ),
|
|
|
|
QStringList() << "-model" << model );
|
2017-09-26 11:22:51 +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
|
|
|
|
KeyboardPage::init()
|
|
|
|
{
|
|
|
|
//### Detect current keyboard layout and variant
|
|
|
|
QString currentLayout;
|
2014-12-05 02:25:08 +01:00
|
|
|
QString currentVariant;
|
2014-07-04 15:33:59 +02:00
|
|
|
QProcess process;
|
|
|
|
process.start( "setxkbmap", QStringList() << "-print" );
|
|
|
|
|
|
|
|
if ( process.waitForFinished() )
|
|
|
|
{
|
2016-09-01 14:21:05 +02:00
|
|
|
const QStringList list = QString( process.readAll() )
|
2017-09-26 11:22:51 +02:00
|
|
|
.split( "\n", QString::SkipEmptyParts );
|
2014-07-04 15:33:59 +02:00
|
|
|
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( QString line : list )
|
2014-07-04 15:33:59 +02:00
|
|
|
{
|
|
|
|
line = line.trimmed();
|
|
|
|
if ( !line.startsWith( "xkb_symbols" ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
line = line.remove( "}" )
|
2017-09-26 11:22:51 +02:00
|
|
|
.remove( "{" )
|
|
|
|
.remove( ";" );
|
2014-07-04 15:33:59 +02:00
|
|
|
line = line.mid( line.indexOf( "\"" ) + 1 );
|
|
|
|
|
|
|
|
QStringList split = line.split( "+", QString::SkipEmptyParts );
|
|
|
|
if ( split.size() >= 2 )
|
|
|
|
{
|
|
|
|
currentLayout = split.at( 1 );
|
|
|
|
|
|
|
|
if ( currentLayout.contains( "(" ) )
|
2014-12-05 02:25:08 +01:00
|
|
|
{
|
|
|
|
int parenthesisIndex = currentLayout.indexOf( "(" );
|
|
|
|
currentVariant = currentLayout.mid( parenthesisIndex + 1 )
|
2017-09-26 11:22:51 +02:00
|
|
|
.trimmed();
|
2014-12-05 02:25:08 +01:00
|
|
|
currentVariant.chop( 1 );
|
2014-07-04 15:33:59 +02:00
|
|
|
currentLayout = currentLayout
|
2014-12-05 02:25:08 +01:00
|
|
|
.mid( 0, parenthesisIndex )
|
2014-07-04 15:33:59 +02:00
|
|
|
.trimmed();
|
2014-12-05 02:25:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//### Models
|
|
|
|
m_models = KeyboardGlobal::getKeyboardModels();
|
|
|
|
QMapIterator< QString, QString > mi( m_models );
|
|
|
|
|
|
|
|
ui->comboBoxModel->blockSignals( true );
|
|
|
|
|
|
|
|
while ( mi.hasNext() )
|
|
|
|
{
|
|
|
|
mi.next();
|
|
|
|
|
|
|
|
if ( mi.value() == "pc105" )
|
|
|
|
m_defaultIndex = ui->comboBoxModel->count();
|
|
|
|
|
|
|
|
ui->comboBoxModel->addItem( mi.key() );
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->comboBoxModel->blockSignals( false );
|
|
|
|
|
|
|
|
// Set to default value pc105
|
|
|
|
ui->comboBoxModel->setCurrentIndex( m_defaultIndex );
|
|
|
|
|
|
|
|
|
|
|
|
//### Layouts and Variants
|
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
KeyboardLayoutModel* klm = new KeyboardLayoutModel( this );
|
|
|
|
ui->listLayout->setModel( klm );
|
|
|
|
connect( ui->listLayout->selectionModel(), &QItemSelectionModel::currentChanged,
|
|
|
|
this, &KeyboardPage::onListLayoutCurrentItemChanged );
|
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
// Block signals
|
|
|
|
ui->listLayout->blockSignals( true );
|
|
|
|
|
2017-06-19 17:11:08 +02:00
|
|
|
QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout );
|
|
|
|
if ( !currentLayoutItem.isValid() && (
|
2017-09-26 11:22:51 +02:00
|
|
|
( currentLayout == "latin" )
|
|
|
|
|| ( currentLayout == "pc" ) ) )
|
2014-07-04 15:33:59 +02:00
|
|
|
{
|
2017-06-19 17:11:08 +02:00
|
|
|
currentLayout = "us";
|
|
|
|
currentLayoutItem = findLayout( klm, currentLayout );
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
2014-12-05 02:25:08 +01:00
|
|
|
// Set current layout and variant
|
2016-05-31 19:06:53 +02:00
|
|
|
if ( currentLayoutItem.isValid() )
|
2014-12-05 02:25:08 +01:00
|
|
|
{
|
2016-05-31 19:06:53 +02:00
|
|
|
ui->listLayout->setCurrentIndex( currentLayoutItem );
|
2014-12-05 02:25:08 +01:00
|
|
|
updateVariants( currentLayoutItem, currentVariant );
|
|
|
|
}
|
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
// Unblock signals
|
|
|
|
ui->listLayout->blockSignals( false );
|
|
|
|
|
2014-12-05 02:25:08 +01:00
|
|
|
// Default to the first available layout if none was set
|
|
|
|
// Do this after unblocking signals so we get the default variant handling.
|
2016-05-31 19:06:53 +02:00
|
|
|
if ( !currentLayoutItem.isValid() && klm->rowCount() > 0 )
|
|
|
|
ui->listLayout->setCurrentIndex( klm->index( 0 ) );
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-08 18:25:39 +02:00
|
|
|
QString
|
|
|
|
KeyboardPage::prettyStatus() const
|
|
|
|
{
|
|
|
|
QString status;
|
|
|
|
status += tr( "Set keyboard model to %1.<br/>" )
|
|
|
|
.arg( ui->comboBoxModel->currentText() );
|
|
|
|
status += tr( "Set keyboard layout to %1/%2." )
|
2016-05-31 19:06:53 +02:00
|
|
|
.arg( ui->listLayout->currentIndex().data().toString() )
|
2014-07-08 18:25:39 +02:00
|
|
|
.arg( ui->listVariant->currentItem()->text() );
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 02:58:14 +01:00
|
|
|
QList< Calamares::job_ptr >
|
2014-11-11 14:37:05 +01:00
|
|
|
KeyboardPage::createJobs( const QString& xOrgConfFileName,
|
2016-09-26 10:57:23 +02:00
|
|
|
const QString& convertedKeymapPath,
|
|
|
|
bool writeEtcDefaultKeyboard )
|
2014-11-11 02:58:14 +01:00
|
|
|
{
|
|
|
|
QList< Calamares::job_ptr > list;
|
|
|
|
QString selectedModel = m_models.value( ui->comboBoxModel->currentText(),
|
|
|
|
"pc105" );
|
|
|
|
|
|
|
|
Calamares::Job* j = new SetKeyboardLayoutJob( selectedModel,
|
2017-09-26 11:22:51 +02:00
|
|
|
m_selectedLayout,
|
|
|
|
m_selectedVariant,
|
|
|
|
xOrgConfFileName,
|
|
|
|
convertedKeymapPath,
|
|
|
|
writeEtcDefaultKeyboard );
|
2014-11-11 02:58:14 +01:00
|
|
|
list.append( Calamares::job_ptr( j ) );
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-07 20:05:13 +02:00
|
|
|
void
|
|
|
|
KeyboardPage::guessLayout( const QStringList& langParts )
|
|
|
|
{
|
|
|
|
const KeyboardLayoutModel* klm = dynamic_cast< KeyboardLayoutModel* >( ui->listLayout->model() );
|
|
|
|
bool foundCountryPart = false;
|
2017-09-26 11:22:51 +02:00
|
|
|
for ( auto countryPart = langParts.rbegin(); !foundCountryPart && countryPart != langParts.rend(); ++countryPart )
|
2017-06-07 20:05:13 +02:00
|
|
|
{
|
|
|
|
cDebug() << " .. looking for locale part" << *countryPart;
|
|
|
|
for ( int i = 0; i < klm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
QModelIndex idx = klm->index( i );
|
2017-09-26 17:32:52 +02:00
|
|
|
QString name = idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
|
|
|
|
if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
|
2017-06-07 20:05:13 +02:00
|
|
|
{
|
2017-09-26 17:32:52 +02:00
|
|
|
cDebug() << " .. matched" << name;
|
2017-06-07 20:05:13 +02:00
|
|
|
ui->listLayout->setCurrentIndex( idx );
|
|
|
|
foundCountryPart = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 17:32:52 +02:00
|
|
|
if ( foundCountryPart )
|
|
|
|
{
|
|
|
|
++countryPart;
|
|
|
|
if ( countryPart != langParts.rend() )
|
|
|
|
{
|
|
|
|
cDebug() << "Next level:" << *countryPart;
|
|
|
|
for (int variantnumber = 0; variantnumber < ui->listVariant->count(); ++variantnumber)
|
|
|
|
{
|
|
|
|
LayoutItem *variantdata = dynamic_cast< LayoutItem* >( ui->listVariant->item( variantnumber ) );
|
|
|
|
if ( variantdata && (variantdata->data.compare( *countryPart, Qt::CaseInsensitive ) == 0) )
|
|
|
|
{
|
|
|
|
ui->listVariant->setCurrentItem( variantdata );
|
|
|
|
cDebug() << " .. matched variant" << variantdata->data << ' ' << variantdata->text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-07 20:05:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-26 18:56:09 +01:00
|
|
|
void
|
|
|
|
KeyboardPage::onActivate()
|
|
|
|
{
|
2018-01-08 17:02:20 +01:00
|
|
|
/* Guessing a keyboard layout based on the locale means
|
|
|
|
* mapping between language identifiers in <lang>_<country>
|
|
|
|
* format to keyboard mappings, which are <country>_<layout>
|
|
|
|
* format; in addition, some countries have multiple languages,
|
|
|
|
* so fr_BE and nl_BE want different layouts (both Belgian)
|
|
|
|
* and sometimes the language-country name doesn't match the
|
|
|
|
* keyboard-country name at all (e.g. Ellas vs. Greek).
|
|
|
|
*
|
|
|
|
* This is a table of language-to-keyboard mappings. The
|
|
|
|
* language identifier is the key, while the value is
|
|
|
|
* a string that is used instead of the real language
|
|
|
|
* identifier in guessing -- so it should be something
|
|
|
|
* like <layout>_<country>.
|
|
|
|
*/
|
2017-09-26 17:32:52 +02:00
|
|
|
static auto specialCaseMap = QMap<std::string, std::string>( {
|
2018-01-08 17:02:20 +01:00
|
|
|
{ "ar_EG", "ara" }, /* Egyptian Arabic */
|
|
|
|
{ "ca_ES", "cat_ES" }, /* Catalan */
|
|
|
|
{ "as_ES", "ast_ES" }, /* Asturian */
|
|
|
|
{ "en_CA", "eng_CA" }, /* Canadian English */
|
|
|
|
{ "el_CY", "gr" }, /* Greek in Cyprus */
|
|
|
|
{ "el_GR", "gr" }, /* Greek in Greeze */
|
|
|
|
{ "ig_NG", "igbo_NG" }, /* Igbo in Nigeria */
|
|
|
|
{ "ha_NG", "hausa_NG" } /* Hausa */
|
2017-09-26 17:32:52 +02:00
|
|
|
} );
|
|
|
|
|
2014-11-26 18:56:09 +01:00
|
|
|
ui->listLayout->setFocus();
|
2017-06-07 20:05:13 +02:00
|
|
|
|
|
|
|
// Try to preselect a layout, depending on language and locale
|
|
|
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
|
|
|
QString lang = gs->value( "localeConf" ).toMap().value( "LANG" ).toString();
|
|
|
|
|
|
|
|
cDebug() << "Got locale language" << lang;
|
|
|
|
if ( !lang.isEmpty() )
|
|
|
|
{
|
|
|
|
// Chop off .codeset and @modifier
|
2017-09-26 11:22:51 +02:00
|
|
|
int index = lang.indexOf( '.' );
|
2017-06-07 20:05:13 +02:00
|
|
|
if ( index >= 0 )
|
|
|
|
lang.truncate( index );
|
2017-09-26 11:22:51 +02:00
|
|
|
index = lang.indexOf( '@' );
|
2017-06-07 20:05:13 +02:00
|
|
|
if ( index >= 0 )
|
|
|
|
lang.truncate( index );
|
|
|
|
|
|
|
|
lang.replace( '-', '_' ); // Normalize separators
|
2017-09-26 17:32:52 +02:00
|
|
|
}
|
|
|
|
if ( !lang.isEmpty() && specialCaseMap.contains( lang.toStdString() ) )
|
|
|
|
{
|
|
|
|
QLatin1String newLang( specialCaseMap.value( lang.toStdString() ).c_str() );
|
|
|
|
cDebug() << " .. special case language" << lang << '>' << newLang;
|
|
|
|
lang = newLang;
|
|
|
|
}
|
|
|
|
if ( !lang.isEmpty() )
|
|
|
|
{
|
2017-09-26 11:22:51 +02:00
|
|
|
const auto langParts = lang.split( '_', QString::SkipEmptyParts );
|
2017-06-07 20:05:13 +02:00
|
|
|
|
|
|
|
QString country = QLocale::countryToString( QLocale( lang ).country() );
|
|
|
|
cDebug() << " .. extracted country" << country << "::" << langParts;
|
|
|
|
|
|
|
|
guessLayout( langParts );
|
|
|
|
}
|
2014-11-26 18:56:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-01 12:38:27 +02:00
|
|
|
void
|
|
|
|
KeyboardPage::finalize()
|
|
|
|
{
|
|
|
|
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
|
|
|
if ( !m_selectedLayout.isEmpty() )
|
|
|
|
{
|
|
|
|
gs->insert( "keyboardLayout", m_selectedLayout );
|
|
|
|
gs->insert( "keyboardVariant", m_selectedVariant ); //empty means default variant
|
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: also store keyboard model for something?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
void
|
2016-05-31 19:06:53 +02:00
|
|
|
KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
|
|
|
|
QString currentVariant )
|
2014-07-04 15:33:59 +02:00
|
|
|
{
|
|
|
|
// Block signals
|
|
|
|
ui->listVariant->blockSignals( true );
|
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
QMap< QString, QString > variants =
|
2017-09-26 11:22:51 +02:00
|
|
|
currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole )
|
|
|
|
.value< QMap< QString, QString > >();
|
2014-07-04 15:33:59 +02:00
|
|
|
QMapIterator< QString, QString > li( variants );
|
|
|
|
LayoutItem* defaultItem = nullptr;
|
|
|
|
|
|
|
|
ui->listVariant->clear();
|
|
|
|
|
|
|
|
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();
|
|
|
|
ui->listVariant->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 )
|
|
|
|
defaultItem = item;
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unblock signals
|
|
|
|
ui->listVariant->blockSignals( false );
|
|
|
|
|
|
|
|
// Set to default value
|
|
|
|
if ( defaultItem )
|
2017-09-26 11:22:51 +02:00
|
|
|
ui->listVariant->setCurrentItem( defaultItem );
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-05 02:25:08 +01:00
|
|
|
void
|
2016-05-31 19:06:53 +02:00
|
|
|
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
|
2017-09-26 11:22:51 +02:00
|
|
|
const QModelIndex& previous )
|
2014-12-05 02:25:08 +01:00
|
|
|
{
|
2016-05-31 19:06:53 +02:00
|
|
|
Q_UNUSED( previous );
|
|
|
|
if ( !current.isValid() )
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
2017-06-19 16:46:30 +02:00
|
|
|
/* Returns stringlist with suitable setxkbmap command-line arguments
|
|
|
|
* to set the given @p layout and @p variant.
|
|
|
|
*/
|
2017-09-26 11:22:51 +02:00
|
|
|
static inline QStringList xkbmap_args( QStringList&& r, const QString& layout, const QString& variant )
|
2017-06-19 16:41:56 +02:00
|
|
|
{
|
|
|
|
r << "-layout" << layout;
|
|
|
|
if ( !variant.isEmpty() )
|
|
|
|
r << "-variant" << variant;
|
|
|
|
return r;
|
|
|
|
}
|
2014-12-05 02:25:08 +01:00
|
|
|
|
2014-07-04 15:33:59 +02:00
|
|
|
void
|
|
|
|
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
|
|
|
{
|
2017-09-10 12:22:59 +02:00
|
|
|
Q_UNUSED( previous );
|
|
|
|
|
2016-05-31 19:06:53 +02:00
|
|
|
QPersistentModelIndex layoutIndex = ui->listLayout->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 )
|
2014-07-04 15:33:59 +02:00
|
|
|
return;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
m_keyboardPreview->setLayout( layout );
|
|
|
|
m_keyboardPreview->setVariant( variant );
|
|
|
|
|
|
|
|
//emit checkReady();
|
|
|
|
|
|
|
|
// Set Xorg keyboard layout
|
2016-05-31 19:06:53 +02:00
|
|
|
if ( m_setxkbmapTimer.isActive() )
|
|
|
|
{
|
|
|
|
m_setxkbmapTimer.stop();
|
|
|
|
m_setxkbmapTimer.disconnect( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
connect( &m_setxkbmapTimer, &QTimer::timeout,
|
|
|
|
this, [=]
|
|
|
|
{
|
2017-06-19 16:41:56 +02:00
|
|
|
QProcess::execute( QLatin1Literal( "setxkbmap" ),
|
|
|
|
xkbmap_args( QStringList(), layout, variant ) );
|
2016-05-31 19:06:53 +02:00
|
|
|
cDebug() << "xkbmap selection changed to: " << layout << "-" << variant;
|
2017-06-05 20:50:27 +02:00
|
|
|
m_setxkbmapTimer.disconnect( this );
|
2016-05-31 19:06:53 +02:00
|
|
|
} );
|
|
|
|
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
|
2014-08-01 12:38:27 +02:00
|
|
|
|
|
|
|
m_selectedLayout = layout;
|
|
|
|
m_selectedVariant = variant;
|
2014-07-04 15:33:59 +02:00
|
|
|
}
|