[partition] Support translations of swap choices

- Introduce enum to indicate what is selected
 - Support translations
 - Fill selections for erase
main
Adriaan de Groot 6 years ago
parent 7d0451fe69
commit cfa940b35c

@ -78,6 +78,9 @@ ChoicePage::ChoicePage( QWidget* parent )
, m_eraseButton( nullptr )
, m_replaceButton( nullptr )
, m_somethingElseButton( nullptr )
, m_eraseSwapChoices( nullptr )
, m_replaceSwapChoices( nullptr )
, m_alongsideSwapChoices( nullptr )
, m_deviceInfoWidget( nullptr )
, m_beforePartitionBarsView( nullptr )
, m_beforePartitionLabelsView( nullptr )
@ -172,19 +175,6 @@ ChoicePage::init( PartitionCoreModule* core )
ChoicePage::applyDeviceChoice();
}
static QComboBox*
swapSelectionCombo()
{
QComboBox* box = new QComboBox;
box->addItem( box->tr( "No swap" ), 0 );
box->addItem( box->tr( "Re-use swap" ), 1 );
box->addItem( box->tr( "Limited swap" ), 2 );
box->addItem( box->tr( "Full swap" ), 3 );
box->addItem( box->tr( "Swap file" ), 4 );
return box;
}
/**
* @brief ChoicePage::setupChoices creates PrettyRadioButton objects for the action
* choices.
@ -228,7 +218,6 @@ ChoicePage::setupChoices()
m_eraseButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionEraseAuto,
CalamaresUtils::Original,
iconSize ) );
m_eraseButton->addOptionsComboBox( swapSelectionCombo() );
m_grp->addButton( m_eraseButton->buttonWidget(), Erase );
m_replaceButton = new PrettyRadioButton;
@ -239,6 +228,13 @@ ChoicePage::setupChoices()
iconSize ) );
m_grp->addButton( m_replaceButton->buttonWidget(), Replace );
// Fill up swap options
// .. TODO: only if enabled in the config
m_eraseSwapChoices = new QComboBox;
for ( SwapChoice c : { NoSwap, SmallSwap, FullSwap } )
m_eraseSwapChoices->addItem( QString(), c );
m_eraseButton->addOptionsComboBox( m_eraseSwapChoices );
m_itemsLayout->addWidget( m_alongsideButton );
m_itemsLayout->addWidget( m_replaceButton );
m_itemsLayout->addWidget( m_eraseButton );
@ -292,6 +288,12 @@ ChoicePage::setupChoices()
applyActionChoice( currentChoice() );
}
} );
CALAMARES_RETRANSLATE(
updateSwapChoicesTr( m_eraseSwapChoices );
updateSwapChoicesTr( m_alongsideSwapChoices );
updateSwapChoicesTr( m_replaceSwapChoices );
)
}
@ -1404,3 +1406,42 @@ ChoicePage::updateNextEnabled()
emit nextStatusChanged( enabled );
}
void
ChoicePage::updateSwapChoicesTr(QComboBox* box)
{
if ( !box )
return;
static_assert(NoSwap == 0, "Enum values out-of-sync");
for ( int index = 0; index < box->count(); ++index )
{
bool ok = false;
int value = 0;
switch ( value = box->itemData( index ).toInt( &ok ) )
{
// case 0:
case NoSwap:
// toInt() returns 0 on failure, so check for ok
if ( ok ) // It was explicitly set to 0
box->setItemText( index, tr( "No Swap" ) );
else
cWarning() << "Box item" << index << box->itemText( index ) << "has non-integer role.";
break;
case ReuseSwap:
box->setItemText( index, tr( "Reuse Swap" ) );
break;
case SmallSwap:
box->setItemText( index, tr( "Swap (no Hibernate)" ) );
break;
case FullSwap:
box->setItemText( index, tr( "Swap (with Hibernate)" ) );
break;
case SwapFile:
box->setItemText( index, tr( "Swap to file" ) );
break;
default:
cWarning() << "Box item" << index << box->itemText( index ) << "has role" << value;
}
}
}

@ -62,6 +62,15 @@ public:
Manual
};
enum SwapChoice
{
NoSwap, // don't create any swap, don't use any
ReuseSwap, // don't create, but do use existing
SmallSwap, // up to 8GiB of swap
FullSwap, // ensureSuspendToDisk -- at least RAM size
SwapFile // use a file (if supported)
};
explicit ChoicePage( QWidget* parent = nullptr );
virtual ~ChoicePage();
@ -127,6 +136,9 @@ private:
void doAlongsideApply();
void setupEfiSystemPartitionSelector();
// Translations support
void updateSwapChoicesTr( QComboBox* box );
bool m_nextEnabled;
PartitionCoreModule* m_core;
@ -142,6 +154,9 @@ private:
PrettyRadioButton* m_eraseButton;
PrettyRadioButton* m_replaceButton;
PrettyRadioButton* m_somethingElseButton;
QComboBox* m_eraseSwapChoices;
QComboBox* m_replaceSwapChoices;
QComboBox* m_alongsideSwapChoices;
DeviceInfoWidget* m_deviceInfoWidget;

Loading…
Cancel
Save