[keyboard] Initial support for translated keyboard names
This commit is contained in:
parent
b72eba8157
commit
89a180ee58
@ -11,9 +11,15 @@
|
|||||||
#include "KeyboardLayoutModel.h"
|
#include "KeyboardLayoutModel.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/RAII.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static QTranslator* s_kbtranslator = nullptr;
|
||||||
|
|
||||||
XKBListModel::XKBListModel( QObject* parent )
|
XKBListModel::XKBListModel( QObject* parent )
|
||||||
: QAbstractListModel( parent )
|
: QAbstractListModel( parent )
|
||||||
{
|
{
|
||||||
@ -41,6 +47,11 @@ XKBListModel::data( const QModelIndex& index, int role ) const
|
|||||||
switch ( role )
|
switch ( role )
|
||||||
{
|
{
|
||||||
case LabelRole:
|
case LabelRole:
|
||||||
|
if ( s_kbtranslator && m_contextname )
|
||||||
|
{
|
||||||
|
auto s = s_kbtranslator->translate( m_contextname, item.label.toUtf8().data() );
|
||||||
|
cDebug() << "Translated" << item.label << "to" << s;
|
||||||
|
}
|
||||||
return item.label;
|
return item.label;
|
||||||
case KeyRole:
|
case KeyRole:
|
||||||
return item.key;
|
return item.key;
|
||||||
@ -93,6 +104,8 @@ XKBListModel::setCurrentIndex( int index )
|
|||||||
KeyboardModelsModel::KeyboardModelsModel( QObject* parent )
|
KeyboardModelsModel::KeyboardModelsModel( QObject* parent )
|
||||||
: XKBListModel( parent )
|
: XKBListModel( parent )
|
||||||
{
|
{
|
||||||
|
m_contextname = "kb_models";
|
||||||
|
|
||||||
// The models map is from human-readable names (!) to xkb identifier
|
// The models map is from human-readable names (!) to xkb identifier
|
||||||
const auto models = KeyboardGlobal::getKeyboardModels();
|
const auto models = KeyboardGlobal::getKeyboardModels();
|
||||||
m_list.reserve( models.count() );
|
m_list.reserve( models.count() );
|
||||||
@ -110,6 +123,10 @@ KeyboardModelsModel::KeyboardModelsModel( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
cDebug() << "Loaded" << m_list.count() << "keyboard models";
|
cDebug() << "Loaded" << m_list.count() << "keyboard models";
|
||||||
|
|
||||||
|
CALAMARES_RETRANSLATE( if ( !s_kbtranslator ) { s_kbtranslator = new QTranslator; } cqDeleter<QTranslator> d { s_kbtranslator };
|
||||||
|
d.preserve
|
||||||
|
= CalamaresUtils::loadTranslator( QLocale(), QStringLiteral( "kb_" ), s_kbtranslator ); )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -207,6 +224,7 @@ KeyboardLayoutModel::currentIndex() const
|
|||||||
KeyboardVariantsModel::KeyboardVariantsModel( QObject* parent )
|
KeyboardVariantsModel::KeyboardVariantsModel( QObject* parent )
|
||||||
: XKBListModel( parent )
|
: XKBListModel( parent )
|
||||||
{
|
{
|
||||||
|
m_contextname = "kb_variants";
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
*
|
*
|
||||||
* This model acts like it has a single selection, as well.
|
* This model acts like it has a single selection, as well.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class XKBListModel : public QAbstractListModel
|
class XKBListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -70,6 +69,7 @@ protected:
|
|||||||
};
|
};
|
||||||
QVector< ModelInfo > m_list;
|
QVector< ModelInfo > m_list;
|
||||||
int m_currentIndex = -1;
|
int m_currentIndex = -1;
|
||||||
|
const char* m_contextname = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user