From 47347c77fa8351a778e3ed41481aa322a9649722 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 28 Aug 2017 04:40:31 -0400 Subject: [PATCH] DeviceInfo: refactor translation of DeviceInfoPage - For Boot and Device info widgets, add a retranslateUi() method, since the labels change not only in response to translation events but also UI events. FIXES #779 --- src/modules/partition/gui/BootInfoWidget.cpp | 7 +++ src/modules/partition/gui/BootInfoWidget.h | 3 ++ .../partition/gui/DeviceInfoWidget.cpp | 51 +++++++++++-------- src/modules/partition/gui/DeviceInfoWidget.h | 4 ++ 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/modules/partition/gui/BootInfoWidget.cpp b/src/modules/partition/gui/BootInfoWidget.cpp index c24f28121..cb89432b0 100644 --- a/src/modules/partition/gui/BootInfoWidget.cpp +++ b/src/modules/partition/gui/BootInfoWidget.cpp @@ -21,6 +21,7 @@ #include "core/PartUtils.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/Retranslator.h" #include #include @@ -59,6 +60,12 @@ BootInfoWidget::BootInfoWidget( QWidget* parent ) m_bootIcon->setPalette( palette ); m_bootLabel->setPalette( palette ); + CALAMARES_RETRANSLATE( retranslateUi(); ) +} + +void +BootInfoWidget::retranslateUi() +{ m_bootIcon->setToolTip( tr( "The boot environment of this system.

" "Older x86 systems only support BIOS.
" "Modern systems usually use EFI, but " diff --git a/src/modules/partition/gui/BootInfoWidget.h b/src/modules/partition/gui/BootInfoWidget.h index b8012b361..ac70a7b9a 100644 --- a/src/modules/partition/gui/BootInfoWidget.h +++ b/src/modules/partition/gui/BootInfoWidget.h @@ -30,6 +30,9 @@ class BootInfoWidget : public QWidget public: explicit BootInfoWidget( QWidget* parent = nullptr ); +public slots: + void retranslateUi(); + private: QLabel* m_bootIcon; QLabel* m_bootLabel; diff --git a/src/modules/partition/gui/DeviceInfoWidget.cpp b/src/modules/partition/gui/DeviceInfoWidget.cpp index dc4473521..1fadb9566 100644 --- a/src/modules/partition/gui/DeviceInfoWidget.cpp +++ b/src/modules/partition/gui/DeviceInfoWidget.cpp @@ -19,9 +19,11 @@ #include "DeviceInfoWidget.h" -#include -#include -#include +#include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" +#include "utils/Retranslator.h" +#include "JobQueue.h" +#include "GlobalStorage.h" #include #include @@ -44,9 +46,10 @@ DeviceInfoWidget::DeviceInfoWidget( QWidget* parent ) m_ptIcon->setMargin( 0 ); m_ptIcon->setFixedSize( iconSize ); - m_ptIcon->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionTable, - CalamaresUtils::Original, - iconSize ) ); + m_ptIcon->setPixmap( + CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionTable, + CalamaresUtils::Original, + iconSize ) ); QFontMetrics fm = QFontMetrics( QFont() ); m_ptLabel->setMinimumWidth( fm.boundingRect( "Amiga" ).width() + CalamaresUtils::defaultFontHeight() / 2 ); @@ -60,28 +63,24 @@ DeviceInfoWidget::DeviceInfoWidget( QWidget* parent ) m_ptIcon->setPalette( palette ); m_ptLabel->setPalette( palette ); - m_ptIcon->setToolTip( tr( "The type of partition table on the " - "selected storage device.

" - "The only way to change the partition table type is to " - "erase and recreate the partition table from scratch, " - "which destroys all data on the storage device.
" - "This installer will keep the current partition table " - "unless you explicitly choose otherwise.
" - "If unsure, on modern systems GPT is preferred." ) ); - - bool isEfi = false; - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) - isEfi = true; + CALAMARES_RETRANSLATE( retranslateUi(); ) } void DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type ) { - QString typeString = PartitionTable::tableTypeToName( type ).toUpper(); + m_tableType = type; + retranslateUi(); +} + +void +DeviceInfoWidget::retranslateUi() +{ + QString typeString = PartitionTable::tableTypeToName( m_tableType ).toUpper(); // fix up if the name shouldn't be uppercase: - switch ( type ) + switch ( m_tableType ) { case PartitionTable::msdos: case PartitionTable::msdos_sectorbased: @@ -108,7 +107,7 @@ DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type ) "table." ) .arg( typeString ); - switch ( type ) + switch ( m_tableType ) { case PartitionTable::loop: toolTipString = tr( "This is a loop " @@ -146,5 +145,13 @@ DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type ) m_ptLabel->setText( typeString ); m_ptLabel->setToolTip( toolTipString ); -} + m_ptIcon->setToolTip( tr( "The type of partition table on the " + "selected storage device.

" + "The only way to change the partition table type is to " + "erase and recreate the partition table from scratch, " + "which destroys all data on the storage device.
" + "This installer will keep the current partition table " + "unless you explicitly choose otherwise.
" + "If unsure, on modern systems GPT is preferred." ) ); +} diff --git a/src/modules/partition/gui/DeviceInfoWidget.h b/src/modules/partition/gui/DeviceInfoWidget.h index ab67c102c..f8bd07ca3 100644 --- a/src/modules/partition/gui/DeviceInfoWidget.h +++ b/src/modules/partition/gui/DeviceInfoWidget.h @@ -34,9 +34,13 @@ public: void setPartitionTableType( PartitionTable::TableType type ); +public slots: + void retranslateUi(); + private: QLabel* m_ptIcon; QLabel* m_ptLabel; + PartitionTable::TableType m_tableType; }; #endif // DEVICEINFOWIDGET_H