From 4387b8061e88a635e9d9a885d4ce261d7be6976a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 31 Oct 2020 20:02:21 +0100 Subject: [PATCH] [keyboard] Move responsibility for retranslation to Config - only widgets get language change events, so we need to hook that up to the ViewSteps and inform the Config object so that it can (re)load translations for the keyboard data. --- src/modules/keyboard/Config.cpp | 5 +++++ src/modules/keyboard/Config.h | 11 +++++++++++ src/modules/keyboard/KeyboardLayoutModel.cpp | 4 ---- src/modules/keyboard/KeyboardPage.cpp | 9 ++++++++- src/modules/keyboard/KeyboardPage.h | 2 ++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/modules/keyboard/Config.cpp b/src/modules/keyboard/Config.cpp index 5d5e80d5f..85bb2e9d6 100644 --- a/src/modules/keyboard/Config.cpp +++ b/src/modules/keyboard/Config.cpp @@ -560,3 +560,8 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) m_writeEtcDefaultKeyboard = true; } } + +void +Config::retranslate() +{ +} diff --git a/src/modules/keyboard/Config.h b/src/modules/keyboard/Config.h index e35193484..90eeb0e7b 100644 --- a/src/modules/keyboard/Config.h +++ b/src/modules/keyboard/Config.h @@ -58,6 +58,17 @@ public: */ KeyboardVariantsModel* keyboardVariants() const; + /** @brief Call this to change application language + * + * The models (for keyboard model, layouts and variants) provide + * translations of strings in the xkb table, so need to be + * notified of language changes as well. + * + * Only widgets get LanguageChange events, so one of them will + * need to call this. + */ + void retranslate(); + signals: void prettyStatusChanged(); diff --git a/src/modules/keyboard/KeyboardLayoutModel.cpp b/src/modules/keyboard/KeyboardLayoutModel.cpp index 9be9c8ef9..f1e6a66c6 100644 --- a/src/modules/keyboard/KeyboardLayoutModel.cpp +++ b/src/modules/keyboard/KeyboardLayoutModel.cpp @@ -123,10 +123,6 @@ KeyboardModelsModel::KeyboardModelsModel( QObject* parent ) } cDebug() << "Loaded" << m_list.count() << "keyboard models"; - - CALAMARES_RETRANSLATE( if ( !s_kbtranslator ) { s_kbtranslator = new QTranslator; } cqDeleter d { s_kbtranslator }; - d.preserve - = CalamaresUtils::loadTranslator( QLocale(), QStringLiteral( "kb_" ), s_kbtranslator ); ) } diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 2be897e58..7522056a3 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -95,10 +95,17 @@ KeyboardPage::KeyboardPage( Config* config, QWidget* parent ) connect( config->keyboardVariants(), &KeyboardVariantsModel::currentIndexChanged, [this]( int index ) { ui->variantSelector->setCurrentIndex( m_config->keyboardVariants()->index( index ) ); } ); - CALAMARES_RETRANSLATE( ui->retranslateUi( this ); ) + CALAMARES_RETRANSLATE_SLOT( &KeyboardPage::retranslate ) } KeyboardPage::~KeyboardPage() { delete ui; } + +void +KeyboardPage::retranslate() +{ + ui->retranslateUi( this ); + m_config->retranslate(); +} diff --git a/src/modules/keyboard/KeyboardPage.h b/src/modules/keyboard/KeyboardPage.h index 98925fcad..1c644cc08 100644 --- a/src/modules/keyboard/KeyboardPage.h +++ b/src/modules/keyboard/KeyboardPage.h @@ -37,6 +37,8 @@ public: explicit KeyboardPage( Config* config, QWidget* parent = nullptr ); ~KeyboardPage() override; + void retranslate(); + private: Ui::Page_Keyboard* ui; KeyBoardPreview* m_keyboardPreview;