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
This commit is contained in:
Adriaan de Groot 2017-08-28 04:40:31 -04:00 committed by Philip
parent 3b15884f83
commit 47347c77fa
4 changed files with 43 additions and 22 deletions

View File

@ -21,6 +21,7 @@
#include "core/PartUtils.h" #include "core/PartUtils.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Retranslator.h"
#include <QDir> #include <QDir>
#include <QLabel> #include <QLabel>
@ -59,6 +60,12 @@ BootInfoWidget::BootInfoWidget( QWidget* parent )
m_bootIcon->setPalette( palette ); m_bootIcon->setPalette( palette );
m_bootLabel->setPalette( palette ); m_bootLabel->setPalette( palette );
CALAMARES_RETRANSLATE( retranslateUi(); )
}
void
BootInfoWidget::retranslateUi()
{
m_bootIcon->setToolTip( tr( "The <strong>boot environment</strong> of this system.<br><br>" m_bootIcon->setToolTip( tr( "The <strong>boot environment</strong> of this system.<br><br>"
"Older x86 systems only support <strong>BIOS</strong>.<br>" "Older x86 systems only support <strong>BIOS</strong>.<br>"
"Modern systems usually use <strong>EFI</strong>, but " "Modern systems usually use <strong>EFI</strong>, but "

View File

@ -30,6 +30,9 @@ class BootInfoWidget : public QWidget
public: public:
explicit BootInfoWidget( QWidget* parent = nullptr ); explicit BootInfoWidget( QWidget* parent = nullptr );
public slots:
void retranslateUi();
private: private:
QLabel* m_bootIcon; QLabel* m_bootIcon;
QLabel* m_bootLabel; QLabel* m_bootLabel;

View File

@ -19,9 +19,11 @@
#include "DeviceInfoWidget.h" #include "DeviceInfoWidget.h"
#include <utils/CalamaresUtilsGui.h> #include "utils/CalamaresUtilsGui.h"
#include <JobQueue.h> #include "utils/Logger.h"
#include <GlobalStorage.h> #include "utils/Retranslator.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include <QDir> #include <QDir>
#include <QLabel> #include <QLabel>
@ -44,7 +46,8 @@ DeviceInfoWidget::DeviceInfoWidget( QWidget* parent )
m_ptIcon->setMargin( 0 ); m_ptIcon->setMargin( 0 );
m_ptIcon->setFixedSize( iconSize ); m_ptIcon->setFixedSize( iconSize );
m_ptIcon->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionTable, m_ptIcon->setPixmap(
CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionTable,
CalamaresUtils::Original, CalamaresUtils::Original,
iconSize ) ); iconSize ) );
@ -60,28 +63,24 @@ DeviceInfoWidget::DeviceInfoWidget( QWidget* parent )
m_ptIcon->setPalette( palette ); m_ptIcon->setPalette( palette );
m_ptLabel->setPalette( palette ); m_ptLabel->setPalette( palette );
m_ptIcon->setToolTip( tr( "The type of <strong>partition table</strong> on the " CALAMARES_RETRANSLATE( retranslateUi(); )
"selected storage device.<br><br>"
"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.<br>"
"This installer will keep the current partition table "
"unless you explicitly choose otherwise.<br>"
"If unsure, on modern systems GPT is preferred." ) );
bool isEfi = false;
if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
isEfi = true;
} }
void void
DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type ) 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: // fix up if the name shouldn't be uppercase:
switch ( type ) switch ( m_tableType )
{ {
case PartitionTable::msdos: case PartitionTable::msdos:
case PartitionTable::msdos_sectorbased: case PartitionTable::msdos_sectorbased:
@ -108,7 +107,7 @@ DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type )
"table." ) "table." )
.arg( typeString ); .arg( typeString );
switch ( type ) switch ( m_tableType )
{ {
case PartitionTable::loop: case PartitionTable::loop:
toolTipString = tr( "This is a <strong>loop</strong> " toolTipString = tr( "This is a <strong>loop</strong> "
@ -146,5 +145,13 @@ DeviceInfoWidget::setPartitionTableType( PartitionTable::TableType type )
m_ptLabel->setText( typeString ); m_ptLabel->setText( typeString );
m_ptLabel->setToolTip( toolTipString ); m_ptLabel->setToolTip( toolTipString );
}
m_ptIcon->setToolTip( tr( "The type of <strong>partition table</strong> on the "
"selected storage device.<br><br>"
"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.<br>"
"This installer will keep the current partition table "
"unless you explicitly choose otherwise.<br>"
"If unsure, on modern systems GPT is preferred." ) );
}

View File

@ -34,9 +34,13 @@ public:
void setPartitionTableType( PartitionTable::TableType type ); void setPartitionTableType( PartitionTable::TableType type );
public slots:
void retranslateUi();
private: private:
QLabel* m_ptIcon; QLabel* m_ptIcon;
QLabel* m_ptLabel; QLabel* m_ptLabel;
PartitionTable::TableType m_tableType;
}; };
#endif // DEVICEINFOWIDGET_H #endif // DEVICEINFOWIDGET_H