|
|
|
@ -93,108 +93,6 @@ KeyboardPage::~KeyboardPage()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
KeyboardPage::init()
|
|
|
|
|
{
|
|
|
|
|
//### Detect current keyboard layout and variant
|
|
|
|
|
QString currentLayout;
|
|
|
|
|
QString currentVariant;
|
|
|
|
|
QProcess process;
|
|
|
|
|
process.start( "setxkbmap", QStringList() << "-print" );
|
|
|
|
|
|
|
|
|
|
if ( process.waitForFinished() )
|
|
|
|
|
{
|
|
|
|
|
const QStringList list = QString( process.readAll() ).split( "\n", SplitSkipEmptyParts );
|
|
|
|
|
|
|
|
|
|
for ( QString line : list )
|
|
|
|
|
{
|
|
|
|
|
line = line.trimmed();
|
|
|
|
|
if ( !line.startsWith( "xkb_symbols" ) )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
line = line.remove( "}" ).remove( "{" ).remove( ";" );
|
|
|
|
|
line = line.mid( line.indexOf( "\"" ) + 1 );
|
|
|
|
|
|
|
|
|
|
QStringList split = line.split( "+", SplitSkipEmptyParts );
|
|
|
|
|
if ( split.size() >= 2 )
|
|
|
|
|
{
|
|
|
|
|
currentLayout = split.at( 1 );
|
|
|
|
|
|
|
|
|
|
if ( currentLayout.contains( "(" ) )
|
|
|
|
|
{
|
|
|
|
|
int parenthesisIndex = currentLayout.indexOf( "(" );
|
|
|
|
|
currentVariant = currentLayout.mid( parenthesisIndex + 1 ).trimmed();
|
|
|
|
|
currentVariant.chop( 1 );
|
|
|
|
|
currentLayout = currentLayout.mid( 0, parenthesisIndex ).trimmed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//### 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
|
|
|
|
|
|
|
|
|
|
KeyboardLayoutModel* klm = new KeyboardLayoutModel( this );
|
|
|
|
|
ui->listLayout->setModel( klm );
|
|
|
|
|
connect( ui->listLayout->selectionModel(),
|
|
|
|
|
&QItemSelectionModel::currentChanged,
|
|
|
|
|
this,
|
|
|
|
|
&KeyboardPage::onListLayoutCurrentItemChanged );
|
|
|
|
|
|
|
|
|
|
// Block signals
|
|
|
|
|
ui->listLayout->blockSignals( true );
|
|
|
|
|
|
|
|
|
|
QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout );
|
|
|
|
|
if ( !currentLayoutItem.isValid() && ( ( currentLayout == "latin" ) || ( currentLayout == "pc" ) ) )
|
|
|
|
|
{
|
|
|
|
|
currentLayout = "us";
|
|
|
|
|
currentLayoutItem = findLayout( klm, currentLayout );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set current layout and variant
|
|
|
|
|
if ( currentLayoutItem.isValid() )
|
|
|
|
|
{
|
|
|
|
|
ui->listLayout->setCurrentIndex( currentLayoutItem );
|
|
|
|
|
updateVariants( currentLayoutItem, currentVariant );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Unblock signals
|
|
|
|
|
ui->listLayout->blockSignals( false );
|
|
|
|
|
|
|
|
|
|
// Default to the first available layout if none was set
|
|
|
|
|
// Do this after unblocking signals so we get the default variant handling.
|
|
|
|
|
if ( !currentLayoutItem.isValid() && klm->rowCount() > 0 )
|
|
|
|
|
{
|
|
|
|
|
ui->listLayout->setCurrentIndex( klm->index( 0 ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
|