[keyboardq] apply the style script

This commit is contained in:
Camilo Higuita 2020-03-26 09:57:02 -05:00 committed by Adriaan de Groot
parent 1a46e08cc2
commit 835850c02a
11 changed files with 411 additions and 342 deletions

View File

@ -19,19 +19,20 @@
#include "Config.h"
#include "keyboardwidget/keyboardpreview.h"
#include "SetKeyboardLayoutJob.h"
#include "keyboardwidget/keyboardpreview.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include <QProcess>
#include <QApplication>
#include <QProcess>
#include <QTimer>
KeyboardModelsModel::KeyboardModelsModel(QObject* parent) : QAbstractListModel(parent)
KeyboardModelsModel::KeyboardModelsModel( QObject* parent )
: QAbstractListModel( parent )
{
detectModels();
}
@ -40,15 +41,16 @@ void
KeyboardModelsModel::detectModels()
{
beginResetModel();
const auto models = KeyboardGlobal::getKeyboardModels();
const auto models = KeyboardGlobal::getKeyboardModels();
auto index = -1;
for(const auto &key :models.keys())
for ( const auto& key : models.keys() )
{
index++;
m_list << QMap<QString, QString> {{"label", key}, {"key", models[key]}};
if ( models[key] == "pc105" )
this->setCurrentIndex(index);
m_list << QMap< QString, QString > { { "label", key }, { "key", models[ key ] } };
if ( models[ key ] == "pc105" )
{
this->setCurrentIndex( index );
}
}
endResetModel();
}
@ -57,29 +59,31 @@ void
KeyboardModelsModel::refresh()
{
m_list.clear();
setCurrentIndex(-1);
setCurrentIndex( -1 );
detectModels();
}
QVariant
KeyboardModelsModel::data(const QModelIndex& index, int role) const
KeyboardModelsModel::data( const QModelIndex& index, int role ) const
{
if(!index.isValid())
if ( !index.isValid() )
{
return QVariant();
const auto item = m_list.at(index.row());
return role == Qt::DisplayRole ? item["label"] : item["key"];
}
const auto item = m_list.at( index.row() );
return role == Qt::DisplayRole ? item[ "label" ] : item[ "key" ];
}
int
KeyboardModelsModel::rowCount(const QModelIndex&) const
KeyboardModelsModel::rowCount( const QModelIndex& ) const
{
return m_list.count();
}
QHash<int, QByteArray>
QHash< int, QByteArray >
KeyboardModelsModel::roleNames() const
{
return {{Qt::DisplayRole, "label"}, {Qt::UserRole, "key"}};
return { { Qt::DisplayRole, "label" }, { Qt::UserRole, "key" } };
}
int
@ -88,36 +92,44 @@ KeyboardModelsModel::currentIndex() const
return m_currentIndex;
}
const QMap<QString, QString>
KeyboardModelsModel::item(const int &index) const
const QMap< QString, QString >
KeyboardModelsModel::item( const int& index ) const
{
if(index >= m_list.count() || index < 0)
return QMap<QString, QString>();
if ( index >= m_list.count() || index < 0 )
{
return QMap< QString, QString >();
}
return m_list.at(index);
return m_list.at( index );
}
const QMap<QString, QString>
KeyboardVariantsModel::item(const int &index) const
const QMap< QString, QString >
KeyboardVariantsModel::item( const int& index ) const
{
if(index >= m_list.count() || index < 0)
return QMap<QString, QString>();
if ( index >= m_list.count() || index < 0 )
{
return QMap< QString, QString >();
}
return m_list.at(index);
return m_list.at( index );
}
void
KeyboardModelsModel::setCurrentIndex(const int& index)
KeyboardModelsModel::setCurrentIndex( const int& index )
{
if(index >= m_list.count() || index < 0)
if ( index >= m_list.count() || index < 0 )
{
return;
}
m_currentIndex = index;
emit currentIndexChanged(m_currentIndex);
emit currentIndexChanged( m_currentIndex );
}
KeyboardVariantsModel::KeyboardVariantsModel(QObject *parent) : QAbstractListModel(parent)
{}
KeyboardVariantsModel::KeyboardVariantsModel( QObject* parent )
: QAbstractListModel( parent )
{
}
int
KeyboardVariantsModel::currentIndex() const
@ -126,44 +138,48 @@ KeyboardVariantsModel::currentIndex() const
}
void
KeyboardVariantsModel::setCurrentIndex(const int& index)
KeyboardVariantsModel::setCurrentIndex( const int& index )
{
if(index >= m_list.count() || index < 0)
if ( index >= m_list.count() || index < 0 )
{
return;
}
m_currentIndex = index;
emit currentIndexChanged(m_currentIndex);
emit currentIndexChanged( m_currentIndex );
}
QVariant
KeyboardVariantsModel::data(const QModelIndex& index, int role) const
KeyboardVariantsModel::data( const QModelIndex& index, int role ) const
{
if(!index.isValid())
if ( !index.isValid() )
{
return QVariant();
const auto item = m_list.at(index.row());
return role == Qt::DisplayRole ? item["label"] : item["key"];
}
const auto item = m_list.at( index.row() );
return role == Qt::DisplayRole ? item[ "label" ] : item[ "key" ];
}
int
KeyboardVariantsModel::rowCount(const QModelIndex&) const
KeyboardVariantsModel::rowCount( const QModelIndex& ) const
{
return m_list.count();
}
QHash<int, QByteArray>
QHash< int, QByteArray >
KeyboardVariantsModel::roleNames() const
{
return {{Qt::DisplayRole, "label"}, {Qt::UserRole, "key"}};
return { { Qt::DisplayRole, "label" }, { Qt::UserRole, "key" } };
}
void
KeyboardVariantsModel::setVariants(QMap< QString, QString > variants)
KeyboardVariantsModel::setVariants( QMap< QString, QString > variants )
{
m_list.clear();
beginResetModel();
for(const auto &key :variants.keys())
for ( const auto& key : variants.keys() )
{
const auto item = QMap<QString, QString> {{"label", key}, {"key", variants[key]}};
const auto item = QMap< QString, QString > { { "label", key }, { "key", variants[ key ] } };
m_list << item;
}
endResetModel();
@ -172,61 +188,57 @@ KeyboardVariantsModel::setVariants(QMap< QString, QString > variants)
/* Returns stringlist with suitable setxkbmap command-line arguments
* to set the given @p layout and @p variant.
*/
static inline QStringList xkbmap_args( const QString& layout, const QString& variant )
static inline QStringList
xkbmap_args( const QString& layout, const QString& variant )
{
QStringList r{ "-layout", layout };
QStringList r { "-layout", layout };
if ( !variant.isEmpty() )
{
r << "-variant" << variant;
}
return r;
}
Config::Config(QObject *parent) : QObject(parent)
, m_keyboardModelsModel(new KeyboardModelsModel(this))
, m_keyboardLayoutsModel(new KeyboardLayoutModel(this))
, m_keyboardVariantsModel(new KeyboardVariantsModel(this))
Config::Config( QObject* parent )
: QObject( parent )
, m_keyboardModelsModel( new KeyboardModelsModel( this ) )
, m_keyboardLayoutsModel( new KeyboardLayoutModel( this ) )
, m_keyboardVariantsModel( new KeyboardVariantsModel( this ) )
{
m_setxkbmapTimer.setSingleShot( true );
// Connect signals and slots
connect( m_keyboardModelsModel, &KeyboardModelsModel::currentIndexChanged,
[&](int index)
{
m_selectedModel = m_keyboardModelsModel->item(index).value("key", "pc105" );
// Set Xorg keyboard model
QProcess::execute( "setxkbmap", QStringList{ "-model", m_selectedModel } );
emit prettyStatusChanged();
} );
connect( m_keyboardModelsModel, &KeyboardModelsModel::currentIndexChanged, [&]( int index ) {
m_selectedModel = m_keyboardModelsModel->item( index ).value( "key", "pc105" );
// Set Xorg keyboard model
QProcess::execute( "setxkbmap", QStringList { "-model", m_selectedModel } );
emit prettyStatusChanged();
} );
connect( m_keyboardLayoutsModel, &KeyboardLayoutModel::currentIndexChanged,
[&](int index)
{
m_selectedLayout = m_keyboardLayoutsModel->item(index).first;
updateVariants(QPersistentModelIndex(m_keyboardLayoutsModel->index(index)));
emit prettyStatusChanged();
} );
connect( m_keyboardLayoutsModel, &KeyboardLayoutModel::currentIndexChanged, [&]( int index ) {
m_selectedLayout = m_keyboardLayoutsModel->item( index ).first;
updateVariants( QPersistentModelIndex( m_keyboardLayoutsModel->index( index ) ) );
emit prettyStatusChanged();
} );
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged,
[&](int index)
{
m_selectedVariant = m_keyboardVariantsModel->item(index)["key"];
connect( m_keyboardVariantsModel, &KeyboardVariantsModel::currentIndexChanged, [&]( int index ) {
m_selectedVariant = m_keyboardVariantsModel->item( index )[ "key" ];
// Set Xorg keyboard layout
if ( m_setxkbmapTimer.isActive() )
{
m_setxkbmapTimer.stop();
m_setxkbmapTimer.disconnect( this );
}
// Set Xorg keyboard layout
if ( m_setxkbmapTimer.isActive() )
{
m_setxkbmapTimer.stop();
m_setxkbmapTimer.disconnect( this );
}
connect( &m_setxkbmapTimer, &QTimer::timeout,
this, [=]
{
QProcess::execute( "setxkbmap", xkbmap_args( m_selectedLayout, m_selectedVariant ) );
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant;
m_setxkbmapTimer.disconnect( this );
} );
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
emit prettyStatusChanged();
} );
connect( &m_setxkbmapTimer, &QTimer::timeout, this, [=] {
QProcess::execute( "setxkbmap", xkbmap_args( m_selectedLayout, m_selectedVariant ) );
cDebug() << "xkbmap selection changed to: " << m_selectedLayout << '-' << m_selectedVariant;
m_setxkbmapTimer.disconnect( this );
} );
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
emit prettyStatusChanged();
} );
}
KeyboardModelsModel*
@ -255,9 +267,10 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
for ( int i = 0; i < klm->rowCount(); ++i )
{
QModelIndex idx = klm->index( i );
if ( idx.isValid() &&
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
if ( idx.isValid() && idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
{
currentLayoutItem = idx;
}
}
return currentLayoutItem;
@ -274,18 +287,17 @@ Config::init()
if ( process.waitForFinished() )
{
const QStringList list = QString( process.readAll() )
.split( "\n", QString::SkipEmptyParts );
const QStringList list = QString( process.readAll() ).split( "\n", QString::SkipEmptyParts );
for ( QString line : list )
{
line = line.trimmed();
if ( !line.startsWith( "xkb_symbols" ) )
{
continue;
}
line = line.remove( "}" )
.remove( "{" )
.remove( ";" );
line = line.remove( "}" ).remove( "{" ).remove( ";" );
line = line.mid( line.indexOf( "\"" ) + 1 );
QStringList split = line.split( "+", QString::SkipEmptyParts );
@ -296,12 +308,9 @@ Config::init()
if ( currentLayout.contains( "(" ) )
{
int parenthesisIndex = currentLayout.indexOf( "(" );
currentVariant = currentLayout.mid( parenthesisIndex + 1 )
.trimmed();
currentVariant = currentLayout.mid( parenthesisIndex + 1 ).trimmed();
currentVariant.chop( 1 );
currentLayout = currentLayout
.mid( 0, parenthesisIndex )
.trimmed();
currentLayout = currentLayout.mid( 0, parenthesisIndex ).trimmed();
}
break;
@ -311,9 +320,7 @@ Config::init()
//### Layouts and Variants
QPersistentModelIndex currentLayoutItem = findLayout( m_keyboardLayoutsModel, currentLayout );
if ( !currentLayoutItem.isValid() && (
( currentLayout == "latin" )
|| ( currentLayout == "pc" ) ) )
if ( !currentLayoutItem.isValid() && ( ( currentLayout == "latin" ) || ( currentLayout == "pc" ) ) )
{
currentLayout = "us";
currentLayoutItem = findLayout( m_keyboardLayoutsModel, currentLayout );
@ -329,24 +336,29 @@ Config::init()
// 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() && m_keyboardLayoutsModel->rowCount() > 0 )
{
m_keyboardLayoutsModel->setCurrentIndex( m_keyboardLayoutsModel->index( 0 ).row() );
}
}
QString
Config::prettyStatus() const
{
QString status;
status += tr( "Set keyboard model to %1.<br/>" ).arg( m_keyboardModelsModel->item(m_keyboardModelsModel->currentIndex())["label"] );
status += tr( "Set keyboard model to %1.<br/>" )
.arg( m_keyboardModelsModel->item( m_keyboardModelsModel->currentIndex() )[ "label" ] );
QString layout = m_keyboardLayoutsModel->item(m_keyboardLayoutsModel->currentIndex()).second.description ;
QString variant = m_keyboardVariantsModel->currentIndex() >= 0 ? m_keyboardVariantsModel->item(m_keyboardVariantsModel->currentIndex())["label"] : QString( "<default>" );
QString layout = m_keyboardLayoutsModel->item( m_keyboardLayoutsModel->currentIndex() ).second.description;
QString variant = m_keyboardVariantsModel->currentIndex() >= 0
? m_keyboardVariantsModel->item( m_keyboardVariantsModel->currentIndex() )[ "label" ]
: QString( "<default>" );
status += tr( "Set keyboard layout to %1/%2." ).arg( layout, variant );
return status;
}
Calamares::JobList
Config::createJobs(const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard)
Config::createJobs( const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard )
{
QList< Calamares::job_ptr > list;
@ -362,7 +374,7 @@ Config::createJobs(const QString& xOrgConfFileName, const QString& convertedKeym
}
void
Config::guessLayout(const QStringList& langParts)
Config::guessLayout( const QStringList& langParts )
{
bool foundCountryPart = false;
for ( auto countryPart = langParts.rbegin(); !foundCountryPart && countryPart != langParts.rend(); ++countryPart )
@ -371,7 +383,8 @@ Config::guessLayout(const QStringList& langParts)
for ( int i = 0; i < m_keyboardLayoutsModel->rowCount(); ++i )
{
QModelIndex idx = m_keyboardLayoutsModel->index( i );
QString name = idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
QString name
= idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
{
cDebug() << Logger::SubEntry << "matched" << name;
@ -386,12 +399,15 @@ Config::guessLayout(const QStringList& langParts)
if ( countryPart != langParts.rend() )
{
cDebug() << "Next level:" << *countryPart;
for (int variantnumber = 0; variantnumber < m_keyboardVariantsModel->rowCount(); ++variantnumber)
for ( int variantnumber = 0; variantnumber < m_keyboardVariantsModel->rowCount(); ++variantnumber )
{
if ( m_keyboardVariantsModel->item(variantnumber)["key"].compare( *countryPart, Qt::CaseInsensitive ) )
if ( m_keyboardVariantsModel->item( variantnumber )[ "key" ].compare( *countryPart,
Qt::CaseInsensitive ) )
{
m_keyboardVariantsModel->setCurrentIndex( variantnumber );
cDebug() << Logger::SubEntry << "matched variant" << m_keyboardVariantsModel->item(variantnumber)["key"] << ' ' <<m_keyboardVariantsModel->item(variantnumber)["key"];
cDebug() << Logger::SubEntry << "matched variant"
<< m_keyboardVariantsModel->item( variantnumber )[ "key" ] << ' '
<< m_keyboardVariantsModel->item( variantnumber )[ "key" ];
}
}
}
@ -417,7 +433,7 @@ Config::onActivate()
* like <layout>_<country>.
*/
static constexpr char arabic[] = "ara";
static const auto specialCaseMap = QMap<std::string, std::string>( {
static const auto specialCaseMap = QMap< std::string, std::string >( {
/* Most Arab countries map to Arabic keyboard (Default) */
{ "ar_AE", arabic },
{ "ar_BH", arabic },
@ -441,8 +457,8 @@ Config::onActivate()
{ "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 */
{ "el_CY", "gr" }, /* Greek in Cyprus */
{ "el_GR", "gr" }, /* Greek in Greeze */
{ "ig_NG", "igbo_NG" }, /* Igbo in Nigeria */
{ "ha_NG", "hausa_NG" } /* Hausa */
} );
@ -457,10 +473,14 @@ Config::onActivate()
// Chop off .codeset and @modifier
int index = lang.indexOf( '.' );
if ( index >= 0 )
{
lang.truncate( index );
}
index = lang.indexOf( '@' );
if ( index >= 0 )
{
lang.truncate( index );
}
lang.replace( '-', '_' ); // Normalize separators
}
@ -494,27 +514,26 @@ Config::finalize()
if ( !m_selectedLayout.isEmpty() )
{
gs->insert( "keyboardLayout", m_selectedLayout );
gs->insert( "keyboardVariant", m_selectedVariant ); //empty means default variant
gs->insert( "keyboardVariant", m_selectedVariant ); //empty means default variant
}
//FIXME: also store keyboard model for something?
}
void
Config::updateVariants(const QPersistentModelIndex& currentItem, QString currentVariant)
Config::updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant )
{
const auto variants = m_keyboardLayoutsModel->item(currentItem.row()).second.variants;
m_keyboardVariantsModel->setVariants(variants);
const auto variants = m_keyboardLayoutsModel->item( currentItem.row() ).second.variants;
m_keyboardVariantsModel->setVariants( variants );
auto index = -1;
for(const auto &key : variants.keys())
for ( const auto& key : variants.keys() )
{
index++;
if(variants[key] == currentVariant)
if ( variants[ key ] == currentVariant )
{
m_keyboardVariantsModel->setCurrentIndex(index);
m_keyboardVariantsModel->setCurrentIndex( index );
return;
}
}
}

View File

@ -23,85 +23,84 @@
#include "Job.h"
#include "KeyboardLayoutModel.h"
#include <QObject>
#include <QUrl>
#include <QTimer>
#include <QMap>
#include <QAbstractListModel>
#include <QMap>
#include <QObject>
#include <QTimer>
#include <QUrl>
class KeyboardModelsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged)
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
public:
explicit KeyboardModelsModel(QObject *parent = nullptr);
int rowCount(const QModelIndex& = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role) const override;
explicit KeyboardModelsModel( QObject* parent = nullptr );
int rowCount( const QModelIndex& = QModelIndex() ) const override;
QVariant data( const QModelIndex& index, int role ) const override;
void setCurrentIndex(const int &index);
void setCurrentIndex( const int& index );
int currentIndex() const;
const QMap<QString, QString> item(const int &index) const;
const QMap< QString, QString > item( const int& index ) const;
public slots:
void refresh();
protected:
QHash<int, QByteArray> roleNames() const override;
QHash< int, QByteArray > roleNames() const override;
private:
int m_currentIndex =-1;
QVector<QMap<QString, QString>> m_list;
int m_currentIndex = -1;
QVector< QMap< QString, QString > > m_list;
void detectModels();
signals:
void currentIndexChanged(int index);
void currentIndexChanged( int index );
};
class KeyboardVariantsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged)
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
public:
explicit KeyboardVariantsModel(QObject *parent = nullptr);
void setVariants(QMap< QString, QString > variants);
explicit KeyboardVariantsModel( QObject* parent = nullptr );
void setVariants( QMap< QString, QString > variants );
int rowCount(const QModelIndex& = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role) const override;
int rowCount( const QModelIndex& = QModelIndex() ) const override;
QVariant data( const QModelIndex& index, int role ) const override;
void setCurrentIndex(const int &index);
void setCurrentIndex( const int& index );
int currentIndex() const;
const QMap<QString, QString> item(const int &index) const;
const QMap< QString, QString > item( const int& index ) const;
protected:
QHash<int, QByteArray> roleNames() const override;
QHash< int, QByteArray > roleNames() const override;
private:
int m_currentIndex =-1;
QVector<QMap<QString, QString>> m_list;
int m_currentIndex = -1;
QVector< QMap< QString, QString > > m_list;
signals:
void currentIndexChanged(int index);
void currentIndexChanged( int index );
};
class Config : public QObject
{
Q_OBJECT
Q_PROPERTY(KeyboardModelsModel * keyboardModelsModel READ keyboardModels CONSTANT FINAL)
Q_PROPERTY(KeyboardLayoutModel * keyboardLayoutsModel READ keyboardLayouts CONSTANT FINAL)
Q_PROPERTY(KeyboardVariantsModel * keyboardVariantsModel READ keyboardVariants CONSTANT FINAL)
Q_PROPERTY(QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL)
Q_PROPERTY( KeyboardModelsModel* keyboardModelsModel READ keyboardModels CONSTANT FINAL )
Q_PROPERTY( KeyboardLayoutModel* keyboardLayoutsModel READ keyboardLayouts CONSTANT FINAL )
Q_PROPERTY( KeyboardVariantsModel* keyboardVariantsModel READ keyboardVariants CONSTANT FINAL )
Q_PROPERTY( QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL )
public:
Config( QObject* parent = nullptr );
void init();
Calamares::JobList createJobs( const QString& xOrgConfFileName,
const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard );
Calamares::JobList
createJobs( const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard );
QString prettyStatus() const;
void onActivate();
@ -109,12 +108,11 @@ public:
private:
void guessLayout( const QStringList& langParts );
void updateVariants( const QPersistentModelIndex& currentItem,
QString currentVariant = QString() );
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
KeyboardModelsModel *m_keyboardModelsModel;
KeyboardLayoutModel *m_keyboardLayoutsModel;
KeyboardVariantsModel *m_keyboardVariantsModel;
KeyboardModelsModel* m_keyboardModelsModel;
KeyboardLayoutModel* m_keyboardLayoutsModel;
KeyboardVariantsModel* m_keyboardVariantsModel;
QString m_selectedLayout;
QString m_selectedModel;
@ -122,9 +120,9 @@ private:
QTimer m_setxkbmapTimer;
protected:
KeyboardModelsModel * keyboardModels() const;
KeyboardLayoutModel * keyboardLayouts() const;
KeyboardVariantsModel * keyboardVariants() const;
KeyboardModelsModel* keyboardModels() const;
KeyboardLayoutModel* keyboardLayouts() const;
KeyboardVariantsModel* keyboardVariants() const;
signals:

View File

@ -23,7 +23,7 @@
KeyboardLayoutModel::KeyboardLayoutModel( QObject* parent )
: QAbstractListModel( parent )
: QAbstractListModel( parent )
{
init();
}
@ -40,60 +40,67 @@ QVariant
KeyboardLayoutModel::data( const QModelIndex& index, int role ) const
{
if ( !index.isValid() )
{
return QVariant();
}
switch ( role )
{
case Qt::DisplayRole:
return m_layouts.at( index.row() ).second.description;
case KeyboardVariantsRole:
return QVariant::fromValue( m_layouts.at( index.row() ).second.variants );
case KeyboardLayoutKeyRole:
return m_layouts.at( index.row() ).first;
case Qt::DisplayRole:
return m_layouts.at( index.row() ).second.description;
case KeyboardVariantsRole:
return QVariant::fromValue( m_layouts.at( index.row() ).second.variants );
case KeyboardLayoutKeyRole:
return m_layouts.at( index.row() ).first;
}
return QVariant();
}
const QPair< QString, KeyboardGlobal::KeyboardInfo >
KeyboardLayoutModel::item(const int &index) const
KeyboardLayoutModel::item( const int& index ) const
{
if(index >= m_layouts.count() || index < 0)
if ( index >= m_layouts.count() || index < 0 )
{
return QPair< QString, KeyboardGlobal::KeyboardInfo >();
}
return m_layouts.at(index);
return m_layouts.at( index );
}
void
KeyboardLayoutModel::init()
{
KeyboardGlobal::LayoutsMap layouts =
KeyboardGlobal::getKeyboardLayouts();
for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin();
it != layouts.constEnd(); ++it )
m_layouts.append( qMakePair( it.key(), it.value() ) );
std::stable_sort( m_layouts.begin(), m_layouts.end(), []( const QPair< QString, KeyboardGlobal::KeyboardInfo >& a,
const QPair< QString, KeyboardGlobal::KeyboardInfo >& b )
KeyboardGlobal::LayoutsMap layouts = KeyboardGlobal::getKeyboardLayouts();
for ( KeyboardGlobal::LayoutsMap::const_iterator it = layouts.constBegin(); it != layouts.constEnd(); ++it )
{
return a.second.description < b.second.description;
} );
m_layouts.append( qMakePair( it.key(), it.value() ) );
}
std::stable_sort( m_layouts.begin(),
m_layouts.end(),
[]( const QPair< QString, KeyboardGlobal::KeyboardInfo >& a,
const QPair< QString, KeyboardGlobal::KeyboardInfo >& b ) {
return a.second.description < b.second.description;
} );
}
QHash<int, QByteArray>
QHash< int, QByteArray >
KeyboardLayoutModel::roleNames() const
{
return {{Qt::DisplayRole, "label"}, {KeyboardLayoutKeyRole, "key"}, {KeyboardVariantsRole, "variants"}};
return { { Qt::DisplayRole, "label" }, { KeyboardLayoutKeyRole, "key" }, { KeyboardVariantsRole, "variants" } };
}
void
KeyboardLayoutModel::setCurrentIndex(const int &index)
KeyboardLayoutModel::setCurrentIndex( const int& index )
{
if(index >= m_layouts.count() || index < 0)
if ( index >= m_layouts.count() || index < 0 )
{
return;
}
m_currentIndex = index;
emit currentIndexChanged(m_currentIndex);
emit currentIndexChanged( m_currentIndex );
}
int

View File

@ -29,7 +29,7 @@
class KeyboardLayoutModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
Q_PROPERTY( int currentIndex WRITE setCurrentIndex READ currentIndex NOTIFY currentIndexChanged )
public:
enum Roles : int
@ -44,20 +44,20 @@ public:
QVariant data( const QModelIndex& index, int role ) const override;
void setCurrentIndex(const int &index);
void setCurrentIndex( const int& index );
int currentIndex() const;
const QPair< QString, KeyboardGlobal::KeyboardInfo > item(const int &index) const;
const QPair< QString, KeyboardGlobal::KeyboardInfo > item( const int& index ) const;
protected:
QHash<int, QByteArray> roleNames() const override;
QHash< int, QByteArray > roleNames() const override;
private:
void init();
int m_currentIndex =-1;
int m_currentIndex = -1;
QList< QPair< QString, KeyboardGlobal::KeyboardInfo > > m_layouts;
signals:
void currentIndexChanged(int index);
void currentIndexChanged( int index );
};
#endif // KEYBOARDLAYOUTMODEL_H
#endif // KEYBOARDLAYOUTMODEL_H

View File

@ -23,10 +23,10 @@
#include "KeyboardPage.h"
#include "ui_KeyboardPage.h"
#include "keyboardwidget/keyboardpreview.h"
#include "SetKeyboardLayoutJob.h"
#include "KeyboardLayoutModel.h"
#include "SetKeyboardLayoutJob.h"
#include "keyboardwidget/keyboardpreview.h"
#include "ui_KeyboardPage.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
@ -45,9 +45,7 @@ public:
virtual ~LayoutItem();
};
LayoutItem::~LayoutItem()
{
}
LayoutItem::~LayoutItem() {}
static QPersistentModelIndex
findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
@ -57,9 +55,10 @@ findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout )
for ( int i = 0; i < klm->rowCount(); ++i )
{
QModelIndex idx = klm->index( i );
if ( idx.isValid() &&
idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
if ( idx.isValid() && idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout )
{
currentLayoutItem = idx;
}
}
return currentLayoutItem;
@ -79,24 +78,19 @@ KeyboardPage::KeyboardPage( QWidget* parent )
m_setxkbmapTimer.setSingleShot( true );
// Connect signals and slots
connect( ui->listVariant, &QListWidget::currentItemChanged,
this, &KeyboardPage::onListVariantCurrentItemChanged );
connect( ui->listVariant, &QListWidget::currentItemChanged, this, &KeyboardPage::onListVariantCurrentItemChanged );
connect( ui->buttonRestore, &QPushButton::clicked,
[this]
{
ui->comboBoxModel->setCurrentIndex( m_defaultIndex );
} );
connect(
ui->buttonRestore, &QPushButton::clicked, [this] { ui->comboBoxModel->setCurrentIndex( m_defaultIndex ); } );
connect( ui->comboBoxModel,
static_cast< void ( QComboBox::* )( const QString& ) >( &QComboBox::currentIndexChanged ),
[this]( const QString& text )
{
QString model = m_models.value( text, "pc105" );
[this]( const QString& text ) {
QString model = m_models.value( text, "pc105" );
// Set Xorg keyboard model
QProcess::execute( "setxkbmap", QStringList{ "-model", model } );
} );
// Set Xorg keyboard model
QProcess::execute( "setxkbmap", QStringList { "-model", model } );
} );
CALAMARES_RETRANSLATE( ui->retranslateUi( this ); )
}
@ -119,18 +113,17 @@ KeyboardPage::init()
if ( process.waitForFinished() )
{
const QStringList list = QString( process.readAll() )
.split( "\n", QString::SkipEmptyParts );
const QStringList list = QString( process.readAll() ).split( "\n", QString::SkipEmptyParts );
for ( QString line : list )
{
line = line.trimmed();
if ( !line.startsWith( "xkb_symbols" ) )
{
continue;
}
line = line.remove( "}" )
.remove( "{" )
.remove( ";" );
line = line.remove( "}" ).remove( "{" ).remove( ";" );
line = line.mid( line.indexOf( "\"" ) + 1 );
QStringList split = line.split( "+", QString::SkipEmptyParts );
@ -141,12 +134,9 @@ KeyboardPage::init()
if ( currentLayout.contains( "(" ) )
{
int parenthesisIndex = currentLayout.indexOf( "(" );
currentVariant = currentLayout.mid( parenthesisIndex + 1 )
.trimmed();
currentVariant = currentLayout.mid( parenthesisIndex + 1 ).trimmed();
currentVariant.chop( 1 );
currentLayout = currentLayout
.mid( 0, parenthesisIndex )
.trimmed();
currentLayout = currentLayout.mid( 0, parenthesisIndex ).trimmed();
}
break;
@ -165,7 +155,9 @@ KeyboardPage::init()
mi.next();
if ( mi.value() == "pc105" )
{
m_defaultIndex = ui->comboBoxModel->count();
}
ui->comboBoxModel->addItem( mi.key() );
}
@ -180,16 +172,16 @@ KeyboardPage::init()
KeyboardLayoutModel* klm = new KeyboardLayoutModel( this );
ui->listLayout->setModel( klm );
connect( ui->listLayout->selectionModel(), &QItemSelectionModel::currentChanged,
this, &KeyboardPage::onListLayoutCurrentItemChanged );
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" ) ) )
if ( !currentLayoutItem.isValid() && ( ( currentLayout == "latin" ) || ( currentLayout == "pc" ) ) )
{
currentLayout = "us";
currentLayoutItem = findLayout( klm, currentLayout );
@ -208,7 +200,9 @@ KeyboardPage::init()
// 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 ) );
}
}
@ -217,11 +211,11 @@ KeyboardPage::prettyStatus() const
{
QString status;
status += tr( "Set keyboard model to %1.<br/>" ).arg( ui->comboBoxModel->currentText() );
QString layout = ui->listLayout->currentIndex().data().toString();
QString variant = ui->listVariant->currentItem() ? ui->listVariant->currentItem()->text() : QString( "<default>" );
status += tr( "Set keyboard layout to %1/%2." ).arg( layout, variant );
return status;
}
@ -232,15 +226,14 @@ KeyboardPage::createJobs( const QString& xOrgConfFileName,
bool writeEtcDefaultKeyboard )
{
QList< Calamares::job_ptr > list;
QString selectedModel = m_models.value( ui->comboBoxModel->currentText(),
"pc105" );
QString selectedModel = m_models.value( ui->comboBoxModel->currentText(), "pc105" );
Calamares::Job* j = new SetKeyboardLayoutJob( selectedModel,
m_selectedLayout,
m_selectedVariant,
xOrgConfFileName,
convertedKeymapPath,
writeEtcDefaultKeyboard );
m_selectedLayout,
m_selectedVariant,
xOrgConfFileName,
convertedKeymapPath,
writeEtcDefaultKeyboard );
list.append( Calamares::job_ptr( j ) );
return list;
@ -258,7 +251,8 @@ KeyboardPage::guessLayout( const QStringList& langParts )
for ( int i = 0; i < klm->rowCount(); ++i )
{
QModelIndex idx = klm->index( i );
QString name = idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
QString name
= idx.isValid() ? idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() : QString();
if ( idx.isValid() && ( name.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
{
cDebug() << Logger::SubEntry << "matched" << name;
@ -273,13 +267,14 @@ KeyboardPage::guessLayout( const QStringList& langParts )
if ( countryPart != langParts.rend() )
{
cDebug() << "Next level:" << *countryPart;
for (int variantnumber = 0; variantnumber < ui->listVariant->count(); ++variantnumber)
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) )
LayoutItem* variantdata = dynamic_cast< LayoutItem* >( ui->listVariant->item( variantnumber ) );
if ( variantdata && ( variantdata->data.compare( *countryPart, Qt::CaseInsensitive ) == 0 ) )
{
ui->listVariant->setCurrentItem( variantdata );
cDebug() << Logger::SubEntry << "matched variant" << variantdata->data << ' ' << variantdata->text();
cDebug() << Logger::SubEntry << "matched variant" << variantdata->data << ' '
<< variantdata->text();
}
}
}
@ -306,7 +301,7 @@ KeyboardPage::onActivate()
* like <layout>_<country>.
*/
static constexpr char arabic[] = "ara";
static const auto specialCaseMap = QMap<std::string, std::string>( {
static const auto specialCaseMap = QMap< std::string, std::string >( {
/* Most Arab countries map to Arabic keyboard (Default) */
{ "ar_AE", arabic },
{ "ar_BH", arabic },
@ -330,8 +325,8 @@ KeyboardPage::onActivate()
{ "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 */
{ "el_CY", "gr" }, /* Greek in Cyprus */
{ "el_GR", "gr" }, /* Greek in Greeze */
{ "ig_NG", "igbo_NG" }, /* Igbo in Nigeria */
{ "ha_NG", "hausa_NG" } /* Hausa */
} );
@ -348,10 +343,14 @@ KeyboardPage::onActivate()
// Chop off .codeset and @modifier
int index = lang.indexOf( '.' );
if ( index >= 0 )
{
lang.truncate( index );
}
index = lang.indexOf( '@' );
if ( index >= 0 )
{
lang.truncate( index );
}
lang.replace( '-', '_' ); // Normalize separators
}
@ -386,7 +385,7 @@ KeyboardPage::finalize()
if ( !m_selectedLayout.isEmpty() )
{
gs->insert( "keyboardLayout", m_selectedLayout );
gs->insert( "keyboardVariant", m_selectedVariant ); //empty means default variant
gs->insert( "keyboardVariant", m_selectedVariant ); //empty means default variant
}
//FIXME: also store keyboard model for something?
@ -394,15 +393,13 @@ KeyboardPage::finalize()
void
KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
QString currentVariant )
KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant )
{
// Block signals
ui->listVariant->blockSignals( true );
QMap< QString, QString > variants =
currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole )
.value< QMap< QString, QString > >();
QMap< QString, QString > variants
= currentItem.data( KeyboardLayoutModel::KeyboardVariantsRole ).value< QMap< QString, QString > >();
QMapIterator< QString, QString > li( variants );
LayoutItem* defaultItem = nullptr;
@ -420,7 +417,9 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
// currentVariant defaults to QString(). It is only non-empty during the
// initial setup.
if ( li.value() == currentVariant )
{
defaultItem = item;
}
}
// Unblock signals
@ -428,17 +427,20 @@ KeyboardPage::updateVariants( const QPersistentModelIndex& currentItem,
// Set to default value
if ( defaultItem )
{
ui->listVariant->setCurrentItem( defaultItem );
}
}
void
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
const QModelIndex& previous )
KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current, const QModelIndex& previous )
{
Q_UNUSED( previous )
if ( !current.isValid() )
{
return;
}
updateVariants( QPersistentModelIndex( current ) );
}
@ -446,11 +448,14 @@ KeyboardPage::onListLayoutCurrentItemChanged( const QModelIndex& current,
/* Returns stringlist with suitable setxkbmap command-line arguments
* to set the given @p layout and @p variant.
*/
static inline QStringList xkbmap_args( const QString& layout, const QString& variant )
static inline QStringList
xkbmap_args( const QString& layout, const QString& variant )
{
QStringList r{ "-layout", layout };
QStringList r { "-layout", layout };
if ( !variant.isEmpty() )
{
r << "-variant" << variant;
}
return r;
}
@ -463,7 +468,9 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi
LayoutItem* variantItem = dynamic_cast< LayoutItem* >( current );
if ( !layoutIndex.isValid() || !variantItem )
{
return;
}
QString layout = layoutIndex.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString();
QString variant = variantItem->data;
@ -480,9 +487,7 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi
m_setxkbmapTimer.disconnect( this );
}
connect( &m_setxkbmapTimer, &QTimer::timeout,
this, [=]
{
connect( &m_setxkbmapTimer, &QTimer::timeout, this, [=] {
QProcess::execute( "setxkbmap", xkbmap_args( layout, variant ) );
cDebug() << "xkbmap selection changed to: " << layout << '-' << variant;
m_setxkbmapTimer.disconnect( this );

View File

@ -48,24 +48,20 @@ public:
QString prettyStatus() const;
Calamares::JobList createJobs( const QString& xOrgConfFileName,
const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard );
Calamares::JobList
createJobs( const QString& xOrgConfFileName, const QString& convertedKeymapPath, bool writeEtcDefaultKeyboard );
void onActivate();
void finalize();
protected slots:
void onListLayoutCurrentItemChanged( const QModelIndex& current,
const QModelIndex& previous );
void onListVariantCurrentItemChanged( QListWidgetItem* current,
QListWidgetItem* previous );
void onListLayoutCurrentItemChanged( const QModelIndex& current, const QModelIndex& previous );
void onListVariantCurrentItemChanged( QListWidgetItem* current, QListWidgetItem* previous );
private:
/// Guess a layout based on the split-apart locale
void guessLayout( const QStringList& langParts );
void updateVariants( const QPersistentModelIndex& currentItem,
QString currentVariant = QString() );
void updateVariants( const QPersistentModelIndex& currentItem, QString currentVariant = QString() );
Ui::Page_Keyboard* ui;
KeyBoardPreview* m_keyboardPreview;
@ -77,4 +73,4 @@ private:
QTimer m_setxkbmapTimer;
};
#endif // KEYBOARDPAGE_H
#endif // KEYBOARDPAGE_H

View File

@ -125,27 +125,35 @@ KeyboardViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
using namespace CalamaresUtils;
if ( configurationMap.contains( "xOrgConfFileName" ) &&
configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String &&
!getString( configurationMap, "xOrgConfFileName" ).isEmpty() )
if ( configurationMap.contains( "xOrgConfFileName" )
&& configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String
&& !getString( configurationMap, "xOrgConfFileName" ).isEmpty() )
{
m_xOrgConfFileName = getString( configurationMap, "xOrgConfFileName" );
}
else
{
m_xOrgConfFileName = "00-keyboard.conf";
}
if ( configurationMap.contains( "convertedKeymapPath" ) &&
configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String &&
!getString( configurationMap, "convertedKeymapPath" ).isEmpty() )
if ( configurationMap.contains( "convertedKeymapPath" )
&& configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String
&& !getString( configurationMap, "convertedKeymapPath" ).isEmpty() )
{
m_convertedKeymapPath = getString( configurationMap, "convertedKeymapPath" );
}
else
{
m_convertedKeymapPath = QString();
}
if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) &&
configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
m_writeEtcDefaultKeyboard = getBool( configurationMap, "writeEtcDefaultKeyboard", true);
if ( configurationMap.contains( "writeEtcDefaultKeyboard" )
&& configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
{
m_writeEtcDefaultKeyboard = getBool( configurationMap, "writeEtcDefaultKeyboard", true );
}
else
{
m_writeEtcDefaultKeyboard = true;
}
}

View File

@ -24,24 +24,24 @@
#include "SetKeyboardLayoutJob.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/Logger.h"
#include "JobQueue.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
#include <QDir>
#include <QFileInfo>
#include <QFile>
#include <QTextStream>
#include <QFileInfo>
#include <QSettings>
#include <QTextStream>
SetKeyboardLayoutJob::SetKeyboardLayoutJob( const QString& model,
const QString& layout,
const QString& variant,
const QString& xOrgConfFileName,
const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard )
const QString& layout,
const QString& variant,
const QString& xOrgConfFileName,
const QString& convertedKeymapPath,
bool writeEtcDefaultKeyboard )
: Calamares::Job()
, m_model( model )
, m_layout( layout )
@ -56,9 +56,7 @@ SetKeyboardLayoutJob::SetKeyboardLayoutJob( const QString& model,
QString
SetKeyboardLayoutJob::prettyName() const
{
return tr( "Set keyboard model to %1, layout to %2-%3" ).arg( m_model )
.arg( m_layout )
.arg( m_variant );
return tr( "Set keyboard model to %1, layout to %2-%3" ).arg( m_model ).arg( m_layout ).arg( m_variant );
}
@ -70,13 +68,14 @@ SetKeyboardLayoutJob::findConvertedKeymap( const QString& convertedKeymapPath )
// No search path supplied, assume the distribution does not provide
// converted keymaps
if ( convertedKeymapPath.isEmpty() )
{
return QString();
}
QDir convertedKeymapDir( convertedKeymapPath );
QString name = m_variant.isEmpty() ? m_layout : ( m_layout + '-' + m_variant );
if ( convertedKeymapDir.exists( name + ".map" )
|| convertedKeymapDir.exists( name + ".map.gz" ) )
if ( convertedKeymapDir.exists( name + ".map" ) || convertedKeymapDir.exists( name + ".map.gz" ) )
{
cDebug() << Logger::SubEntry << "Found converted keymap" << name;
return name;
@ -101,37 +100,53 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
{
QString line = stream.readLine().trimmed();
if ( line.isEmpty() || line.startsWith( '#' ) )
{
continue;
}
QStringList mapping = line.split( '\t', QString::SkipEmptyParts );
if ( mapping.size() < 5 )
{
continue;
}
int matching = 0;
// Determine how well matching this entry is
// We assume here that we have one X11 layout. If the UI changes to
// allow more than one layout, this should change too.
if ( m_layout == mapping[1] )
// If we got an exact match, this is best
if ( m_layout == mapping[ 1 ] )
// If we got an exact match, this is best
{
matching = 10;
}
// Look for an entry whose first layout matches ours
else if ( mapping[1].startsWith( m_layout + ',' ) )
else if ( mapping[ 1 ].startsWith( m_layout + ',' ) )
{
matching = 5;
}
if ( matching > 0 )
{
if ( m_model.isEmpty() || m_model == mapping[2] )
if ( m_model.isEmpty() || m_model == mapping[ 2 ] )
{
matching++;
}
QString mappingVariant = mapping[3];
QString mappingVariant = mapping[ 3 ];
if ( mappingVariant == "-" )
{
mappingVariant = QString();
}
else if ( mappingVariant.startsWith( ',' ) )
{
mappingVariant.remove( 1, 0 );
}
if ( m_variant == mappingVariant )
{
matching++;
}
// We ignore mapping[4], the xkb options, for now. If we ever
// allow setting options in the UI, we should match them here.
@ -140,13 +155,12 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
// The best matching entry so far, then let's save that
if ( matching >= qMax( bestMatching, 1 ) )
{
cDebug() << Logger::SubEntry << "Found legacy keymap" << mapping[0]
<< "with score" << matching;
cDebug() << Logger::SubEntry << "Found legacy keymap" << mapping[ 0 ] << "with score" << matching;
if ( matching > bestMatching )
{
bestMatching = matching;
name = mapping[0];
name = mapping[ 0 ];
}
}
}
@ -156,16 +170,16 @@ SetKeyboardLayoutJob::findLegacyKeymap() const
bool
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
const QString& convertedKeymapPath ) const
SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const
{
QString keymap = findConvertedKeymap( convertedKeymapPath );
if ( keymap.isEmpty() )
{
keymap = findLegacyKeymap();
}
if ( keymap.isEmpty() )
{
cDebug() << "Trying to use X11 layout" << m_layout
<< "as the virtual console layout";
cDebug() << "Trying to use X11 layout" << m_layout << "as the virtual console layout";
keymap = m_layout;
}
@ -178,10 +192,14 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
file.open( QIODevice::ReadOnly | QIODevice::Text );
QTextStream stream( &file );
while ( !stream.atEnd() )
{
existingLines << stream.readLine();
}
file.close();
if ( stream.status() != QTextStream::Ok )
{
return false;
}
}
// Write out the existing lines and replace the KEYMAP= line
@ -196,11 +214,15 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath,
found = true;
}
else
{
stream << existingLine << '\n';
}
}
// Add a KEYMAP= line if there wasn't any
if ( !found )
{
stream << "KEYMAP=" << keymap << '\n';
}
stream.flush();
file.close();
@ -218,28 +240,33 @@ SetKeyboardLayoutJob::writeX11Data( const QString& keyboardConfPath ) const
QTextStream stream( &file );
stream << "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n"
"# manually too freely.\n"
"Section \"InputClass\"\n"
" Identifier \"system-keyboard\"\n"
" MatchIsKeyboard \"on\"\n";
"# manually too freely.\n"
"Section \"InputClass\"\n"
" Identifier \"system-keyboard\"\n"
" MatchIsKeyboard \"on\"\n";
if ( !m_layout.isEmpty() )
{
stream << " Option \"XkbLayout\" \"" << m_layout << "\"\n";
}
if ( !m_model.isEmpty() )
{
stream << " Option \"XkbModel\" \"" << m_model << "\"\n";
}
if ( !m_variant.isEmpty() )
{
stream << " Option \"XkbVariant\" \"" << m_variant << "\"\n";
}
stream << "EndSection\n";
stream.flush();
file.close();
cDebug() << "Written XkbLayout" << m_layout <<
"; XkbModel" << m_model <<
"; XkbVariant" << m_variant << "to X.org file" << keyboardConfPath;
cDebug() << "Written XkbLayout" << m_layout << "; XkbModel" << m_model << "; XkbVariant" << m_variant
<< "to X.org file" << keyboardConfPath;
return ( stream.status() == QTextStream::Ok );
}
@ -253,7 +280,7 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
QTextStream stream( &file );
stream << "# KEYBOARD CONFIGURATION FILE\n\n"
"# Consult the keyboard(5) manual page.\n\n";
"# Consult the keyboard(5) manual page.\n\n";
stream << "XKBMODEL=\"" << m_model << "\"\n";
stream << "XKBLAYOUT=\"" << m_layout << "\"\n";
@ -264,10 +291,8 @@ SetKeyboardLayoutJob::writeDefaultKeyboardData( const QString& defaultKeyboardPa
file.close();
cDebug() << "Written XKBMODEL" << m_model <<
"; XKBLAYOUT" << m_layout <<
"; XKBVARIANT" << m_variant <<
"to /etc/default/keyboard file" << defaultKeyboardPath;
cDebug() << "Written XKBMODEL" << m_model << "; XKBLAYOUT" << m_layout << "; XKBVARIANT" << m_variant
<< "to /etc/default/keyboard file" << defaultKeyboardPath;
return ( stream.status() == QTextStream::Ok );
}
@ -292,28 +317,33 @@ SetKeyboardLayoutJob::exec()
{
keyboardConfPath = m_xOrgConfFileName;
while ( keyboardConfPath.startsWith( '/' ) )
{
keyboardConfPath.remove( 0, 1 );
}
keyboardConfPath = destDir.absoluteFilePath( keyboardConfPath );
xorgConfDPath = QFileInfo( keyboardConfPath ).path();
}
else
{
xorgConfDPath = destDir.absoluteFilePath( "etc/X11/xorg.conf.d" );
keyboardConfPath = QDir( xorgConfDPath )
.absoluteFilePath( m_xOrgConfFileName );
keyboardConfPath = QDir( xorgConfDPath ).absoluteFilePath( m_xOrgConfFileName );
}
destDir.mkpath( xorgConfDPath );
QString defaultKeyboardPath;
if ( QDir( destDir.absoluteFilePath( "etc/default" ) ).exists() )
{
defaultKeyboardPath = destDir.absoluteFilePath( "etc/default/keyboard" );
}
// Get the path to the destination's path to the converted key mappings
QString convertedKeymapPath = m_convertedKeymapPath;
if ( !convertedKeymapPath.isEmpty() )
{
while ( convertedKeymapPath.startsWith( '/' ) )
{
convertedKeymapPath.remove( 0, 1 );
}
convertedKeymapPath = destDir.absoluteFilePath( convertedKeymapPath );
}
@ -328,8 +358,9 @@ SetKeyboardLayoutJob::exec()
if ( !defaultKeyboardPath.isEmpty() && m_writeEtcDefaultKeyboard )
{
if ( !writeDefaultKeyboardData( defaultKeyboardPath ) )
return Calamares::JobResult::error( tr( "Failed to write keyboard configuration to existing /etc/default directory." ),
tr( "Failed to write to %1" ).arg( keyboardConfPath ) );
return Calamares::JobResult::error(
tr( "Failed to write keyboard configuration to existing /etc/default directory." ),
tr( "Failed to write to %1" ).arg( keyboardConfPath ) );
}
return Calamares::JobResult::ok();

View File

@ -40,8 +40,7 @@ public:
private:
QString findConvertedKeymap( const QString& convertedKeymapPath ) const;
QString findLegacyKeymap() const;
bool writeVConsoleData( const QString& vconsoleConfPath,
const QString& convertedKeymapPath ) const;
bool writeVConsoleData( const QString& vconsoleConfPath, const QString& convertedKeymapPath ) const;
bool writeX11Data( const QString& keyboardConfPath ) const;
bool writeDefaultKeyboardData( const QString& defaultKeyboardPath ) const;

View File

@ -19,15 +19,15 @@
#include "KeyboardQmlViewStep.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "utils/Variant.h"
CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardQmlViewStepFactory, registerPlugin<KeyboardQmlViewStep>(); )
CALAMARES_PLUGIN_FACTORY_DEFINITION( KeyboardQmlViewStepFactory, registerPlugin< KeyboardQmlViewStep >(); )
KeyboardQmlViewStep::KeyboardQmlViewStep( QObject* parent )
: Calamares::QmlViewStep(parent )
, m_config( new Config(this) )
: Calamares::QmlViewStep( parent )
, m_config( new Config( this ) )
, m_nextEnabled( false )
, m_writeEtcDefaultKeyboard( true )
{
@ -88,13 +88,11 @@ void
KeyboardQmlViewStep::onLeave()
{
m_config->finalize();
m_jobs = m_config->createJobs( m_xOrgConfFileName,
m_convertedKeymapPath,
m_writeEtcDefaultKeyboard );
m_jobs = m_config->createJobs( m_xOrgConfFileName, m_convertedKeymapPath, m_writeEtcDefaultKeyboard );
m_prettyStatus = m_config->prettyStatus();
}
QObject *
QObject*
KeyboardQmlViewStep::getConfig()
{
return m_config;
@ -105,29 +103,37 @@ KeyboardQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
using namespace CalamaresUtils;
if ( configurationMap.contains( "xOrgConfFileName" ) &&
configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String &&
!getString( configurationMap, "xOrgConfFileName" ).isEmpty() )
if ( configurationMap.contains( "xOrgConfFileName" )
&& configurationMap.value( "xOrgConfFileName" ).type() == QVariant::String
&& !getString( configurationMap, "xOrgConfFileName" ).isEmpty() )
{
m_xOrgConfFileName = getString( configurationMap, "xOrgConfFileName" );
}
else
{
m_xOrgConfFileName = "00-keyboard.conf";
}
if ( configurationMap.contains( "convertedKeymapPath" ) &&
configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String &&
!getString( configurationMap, "convertedKeymapPath" ).isEmpty() )
if ( configurationMap.contains( "convertedKeymapPath" )
&& configurationMap.value( "convertedKeymapPath" ).type() == QVariant::String
&& !getString( configurationMap, "convertedKeymapPath" ).isEmpty() )
{
m_convertedKeymapPath = getString( configurationMap, "convertedKeymapPath" );
}
else
{
m_convertedKeymapPath = QString();
}
if ( configurationMap.contains( "writeEtcDefaultKeyboard" ) &&
configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
m_writeEtcDefaultKeyboard = getBool( configurationMap, "writeEtcDefaultKeyboard", true);
if ( configurationMap.contains( "writeEtcDefaultKeyboard" )
&& configurationMap.value( "writeEtcDefaultKeyboard" ).type() == QVariant::Bool )
{
m_writeEtcDefaultKeyboard = getBool( configurationMap, "writeEtcDefaultKeyboard", true );
}
else
{
m_writeEtcDefaultKeyboard = true;
}
Calamares::QmlViewStep::setConfigurationMap( configurationMap );
}

View File

@ -22,9 +22,9 @@
#include "Config.h"
#include <DllMacro.h>
#include <utils/PluginFactory.h>
#include <viewpages/QmlViewStep.h>
#include <DllMacro.h>
#include <QObject>
@ -55,7 +55,7 @@ public:
QObject* getConfig() override;
private:
Config * m_config;
Config* m_config;
bool m_nextEnabled;
QString m_prettyStatus;
@ -68,4 +68,4 @@ private:
CALAMARES_PLUGIN_FACTORY_DECLARATION( KeyboardQmlViewStepFactory )
#endif // KEYBOARDQMLVIEWSTEP_H
#endif // KEYBOARDQMLVIEWSTEP_H