Use KeyboardLayoutModel+QListView instead of QListWidget, and defer setxkbmap until keyboardSearch is over.
This commit is contained in:
parent
4a2cd903f7
commit
09f650ecf5
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Portions from the Manjaro Installation Framework
|
* Portions from the Manjaro Installation Framework
|
||||||
* by Roland Singer <roland@manjaro.org>
|
* by Roland Singer <roland@manjaro.org>
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include "ui_KeyboardPage.h"
|
#include "ui_KeyboardPage.h"
|
||||||
#include "keyboardwidget/keyboardpreview.h"
|
#include "keyboardwidget/keyboardpreview.h"
|
||||||
#include "SetKeyboardLayoutJob.h"
|
#include "SetKeyboardLayoutJob.h"
|
||||||
|
#include "KeyboardLayoutModel.h"
|
||||||
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
@ -47,9 +48,9 @@ KeyboardPage::KeyboardPage( QWidget* parent )
|
|||||||
// Keyboard Preview
|
// Keyboard Preview
|
||||||
ui->KBPreviewLayout->addWidget( m_keyboardPreview );
|
ui->KBPreviewLayout->addWidget( m_keyboardPreview );
|
||||||
|
|
||||||
|
m_setxkbmapTimer.setSingleShot( true );
|
||||||
|
|
||||||
// Connect signals and slots
|
// Connect signals and slots
|
||||||
connect( ui->listLayout, &QListWidget::currentItemChanged,
|
|
||||||
this, &KeyboardPage::onListLayoutCurrentItemChanged );
|
|
||||||
connect( ui->listVariant, &QListWidget::currentItemChanged,
|
connect( ui->listVariant, &QListWidget::currentItemChanged,
|
||||||
this, &KeyboardPage::onListVariantCurrentItemChanged );
|
this, &KeyboardPage::onListVariantCurrentItemChanged );
|
||||||
|
|
||||||
@ -150,37 +151,28 @@ KeyboardPage::init()
|
|||||||
|
|
||||||
//### Layouts and Variants
|
//### Layouts and Variants
|
||||||
|
|
||||||
|
KeyboardLayoutModel* klm = new KeyboardLayoutModel( this );
|
||||||
|
ui->listLayout->setModel( klm );
|
||||||
|
connect( ui->listLayout->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
|
this, &KeyboardPage::onListLayoutCurrentItemChanged );
|
||||||
|
|
||||||
// Block signals
|
// Block signals
|
||||||
ui->listLayout->blockSignals( true );
|
ui->listLayout->blockSignals( true );
|
||||||
|
|
||||||
QMap< QString, KeyboardGlobal::KeyboardInfo > layouts =
|
QPersistentModelIndex currentLayoutItem;
|
||||||
KeyboardGlobal::getKeyboardLayouts();
|
|
||||||
QMapIterator< QString, KeyboardGlobal::KeyboardInfo > li( layouts );
|
|
||||||
LayoutItem* currentLayoutItem = nullptr;
|
|
||||||
|
|
||||||
while ( li.hasNext() )
|
for ( int i = 0; i < klm->rowCount(); ++i )
|
||||||
{
|
{
|
||||||
li.next();
|
QModelIndex idx = klm->index( i );
|
||||||
|
if ( idx.isValid() &&
|
||||||
LayoutItem* item = new LayoutItem();
|
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
|
||||||
KeyboardGlobal::KeyboardInfo info = li.value();
|
currentLayoutItem = idx;
|
||||||
|
|
||||||
item->setText( info.description );
|
|
||||||
item->data = li.key();
|
|
||||||
item->info = info;
|
|
||||||
ui->listLayout->addItem( item );
|
|
||||||
|
|
||||||
// Find current layout index
|
|
||||||
if ( li.key() == currentLayout )
|
|
||||||
currentLayoutItem = item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->listLayout->sortItems();
|
|
||||||
|
|
||||||
// Set current layout and variant
|
// Set current layout and variant
|
||||||
if ( currentLayoutItem )
|
if ( currentLayoutItem.isValid() )
|
||||||
{
|
{
|
||||||
ui->listLayout->setCurrentItem( currentLayoutItem );
|
ui->listLayout->setCurrentIndex( currentLayoutItem );
|
||||||
updateVariants( currentLayoutItem, currentVariant );
|
updateVariants( currentLayoutItem, currentVariant );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,8 +181,8 @@ KeyboardPage::init()
|
|||||||
|
|
||||||
// Default to the first available layout if none was set
|
// Default to the first available layout if none was set
|
||||||
// Do this after unblocking signals so we get the default variant handling.
|
// Do this after unblocking signals so we get the default variant handling.
|
||||||
if ( !currentLayoutItem && ui->listLayout->count() > 0 )
|
if ( !currentLayoutItem.isValid() && klm->rowCount() > 0 )
|
||||||
ui->listLayout->setCurrentRow( 0 );
|
ui->listLayout->setCurrentIndex( klm->index( 0 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -201,7 +193,7 @@ KeyboardPage::prettyStatus() const
|
|||||||
status += tr( "Set keyboard model to %1.<br/>" )
|
status += tr( "Set keyboard model to %1.<br/>" )
|
||||||
.arg( ui->comboBoxModel->currentText() );
|
.arg( ui->comboBoxModel->currentText() );
|
||||||
status += tr( "Set keyboard layout to %1/%2." )
|
status += tr( "Set keyboard layout to %1/%2." )
|
||||||
.arg( ui->listLayout->currentItem()->text() )
|
.arg( ui->listLayout->currentIndex().data().toString() )
|
||||||
.arg( ui->listVariant->currentItem()->text() );
|
.arg( ui->listVariant->currentItem()->text() );
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -249,12 +241,15 @@ KeyboardPage::finalize()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardPage::updateVariants( LayoutItem* currentItem, QString currentVariant )
|
KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
|
||||||
|
QString currentVariant )
|
||||||
{
|
{
|
||||||
// Block signals
|
// Block signals
|
||||||
ui->listVariant->blockSignals( true );
|
ui->listVariant->blockSignals( true );
|
||||||
|
|
||||||
QMap< QString, QString > variants = currentItem->info.variants;
|
QMap< QString, QString > variants =
|
||||||
|
currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole )
|
||||||
|
.value< QMap< QString, QString > >();
|
||||||
QMapIterator< QString, QString > li( variants );
|
QMapIterator< QString, QString > li( variants );
|
||||||
LayoutItem* defaultItem = nullptr;
|
LayoutItem* defaultItem = nullptr;
|
||||||
|
|
||||||
@ -285,26 +280,27 @@ KeyboardPage::updateVariants( LayoutItem* currentItem, QString currentVariant )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardPage::onListLayoutCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
|
||||||
|
const QModelIndex& previous )
|
||||||
{
|
{
|
||||||
LayoutItem* item = dynamic_cast< LayoutItem* >( current );
|
Q_UNUSED( previous );
|
||||||
if ( !item )
|
if ( !current.isValid() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateVariants( item );
|
updateVariants( QPersistentModelIndex( current ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
|
||||||
{
|
{
|
||||||
LayoutItem* layoutItem = dynamic_cast< LayoutItem* >( ui->listLayout->currentItem() );
|
QPersistentModelIndex layoutIndex = ui->listLayout->currentIndex();
|
||||||
LayoutItem* variantItem = dynamic_cast< LayoutItem* >( current );
|
LayoutItem* variantItem = dynamic_cast< LayoutItem* >( current );
|
||||||
|
|
||||||
if ( !layoutItem || !variantItem )
|
if ( !layoutIndex.isValid() || !variantItem )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString layout = layoutItem->data;
|
QString layout = layoutIndex.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
|
||||||
QString variant = variantItem->data;
|
QString variant = variantItem->data;
|
||||||
|
|
||||||
m_keyboardPreview->setLayout( layout );
|
m_keyboardPreview->setLayout( layout );
|
||||||
@ -313,11 +309,22 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi
|
|||||||
//emit checkReady();
|
//emit checkReady();
|
||||||
|
|
||||||
// Set Xorg keyboard layout
|
// Set Xorg keyboard layout
|
||||||
QProcess::execute( QString( "setxkbmap -layout \"%1\" -variant \"%2\"" )
|
if ( m_setxkbmapTimer.isActive() )
|
||||||
.arg( layout, variant ).toUtf8() );
|
{
|
||||||
|
m_setxkbmapTimer.stop();
|
||||||
|
m_setxkbmapTimer.disconnect( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
connect( &m_setxkbmapTimer, &QTimer::timeout,
|
||||||
|
this, [=]
|
||||||
|
{
|
||||||
|
QProcess::execute( QString( "setxkbmap -layout \"%1\" -variant \"%2\"" )
|
||||||
|
.arg( layout, variant ).toUtf8() );
|
||||||
|
cDebug() << "xkbmap selection changed to: " << layout << "-" << variant;
|
||||||
|
} );
|
||||||
|
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
|
||||||
|
|
||||||
m_selectedLayout = layout;
|
m_selectedLayout = layout;
|
||||||
m_selectedVariant = variant;
|
m_selectedVariant = variant;
|
||||||
cDebug() << "xkbmap selection changed to: " << layout << "-" << variant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Portions from the Manjaro Installation Framework
|
* Portions from the Manjaro Installation Framework
|
||||||
* by Roland Singer <roland@manjaro.org>
|
* by Roland Singer <roland@manjaro.org>
|
||||||
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -55,8 +56,8 @@ public:
|
|||||||
void finalize();
|
void finalize();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onListLayoutCurrentItemChanged( QListWidgetItem* current,
|
void onListLayoutCurrentItemChanged( const QModelIndex& current,
|
||||||
QListWidgetItem* previous );
|
const QModelIndex& previous );
|
||||||
void onListVariantCurrentItemChanged( QListWidgetItem* current,
|
void onListVariantCurrentItemChanged( QListWidgetItem* current,
|
||||||
QListWidgetItem* previous );
|
QListWidgetItem* previous );
|
||||||
|
|
||||||
@ -68,7 +69,8 @@ private:
|
|||||||
KeyboardGlobal::KeyboardInfo info;
|
KeyboardGlobal::KeyboardInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
void updateVariants( LayoutItem* currentItem, QString currentVariant = QString() );
|
void updateVariants( const QPersistentModelIndex& currentItem,
|
||||||
|
QString currentVariant = QString() );
|
||||||
|
|
||||||
Ui::Page_Keyboard* ui;
|
Ui::Page_Keyboard* ui;
|
||||||
KeyBoardPreview* m_keyboardPreview;
|
KeyBoardPreview* m_keyboardPreview;
|
||||||
@ -77,6 +79,7 @@ private:
|
|||||||
|
|
||||||
QString m_selectedLayout;
|
QString m_selectedLayout;
|
||||||
QString m_selectedVariant;
|
QString m_selectedVariant;
|
||||||
|
QTimer m_setxkbmapTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEYBOARDPAGE_H
|
#endif // KEYBOARDPAGE_H
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="keyboard.qrc">
|
||||||
<normaloff>:/images/restore.png</normaloff>:/images/restore.png</iconset>
|
<normaloff>:/images/restore.png</normaloff>:/images/restore.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -106,7 +106,7 @@
|
|||||||
<number>9</number>
|
<number>9</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="listLayout"/>
|
<widget class="QListView" name="listLayout"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="listVariant"/>
|
<widget class="QListWidget" name="listVariant"/>
|
||||||
@ -141,6 +141,8 @@
|
|||||||
<tabstop>LE_TestKeyboard</tabstop>
|
<tabstop>LE_TestKeyboard</tabstop>
|
||||||
<tabstop>buttonRestore</tabstop>
|
<tabstop>buttonRestore</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="keyboard.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
Reference in New Issue
Block a user