C++ trickery, part two: shorten code

This commit is contained in:
Adriaan de Groot 2017-07-04 08:29:31 -04:00 committed by Philip
parent f6cbf48b17
commit 854e6d3883
5 changed files with 31 additions and 62 deletions

View File

@ -53,10 +53,8 @@ FinishedPage::FinishedPage( QWidget* parent )
"%1 has been installed on your computer.<br/>" "%1 has been installed on your computer.<br/>"
"You may now restart into your new system, or continue " "You may now restart into your new system, or continue "
"using the %2 Live environment." ) "using the %2 Live environment." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName )
string( Calamares::Branding::VersionedName ) ) .arg( *Calamares::Branding::ProductName ) );
.arg( Calamares::Branding::instance()->
string( Calamares::Branding::ProductName ) ) );
) )
} }

View File

@ -1180,13 +1180,11 @@ ChoicePage::setupActions()
m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>" m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>"
"The installer will shrink a partition to make room for %1." ) "The installer will shrink a partition to make room for %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>" m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>"
"Replaces a partition with %1." ) "Replaces a partition with %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
) )
m_replaceButton->hide(); m_replaceButton->hide();
@ -1211,8 +1209,7 @@ ChoicePage::setupActions()
m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>" m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>"
"The installer will shrink a partition to make room for %1." ) "The installer will shrink a partition to make room for %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
m_eraseButton->setText( tr( "<strong>Erase disk</strong><br/>" m_eraseButton->setText( tr( "<strong>Erase disk</strong><br/>"
"This will <font color=\"red\">delete</font> all data " "This will <font color=\"red\">delete</font> all data "
@ -1221,8 +1218,7 @@ ChoicePage::setupActions()
m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>" m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>"
"Replaces a partition with %1." ) "Replaces a partition with %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
) )
} }
else else
@ -1235,8 +1231,7 @@ ChoicePage::setupActions()
m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>" m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>"
"The installer will shrink a partition to make room for %1." ) "The installer will shrink a partition to make room for %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
m_eraseButton->setText( tr( "<strong>Erase disk</strong><br/>" m_eraseButton->setText( tr( "<strong>Erase disk</strong><br/>"
"This will <font color=\"red\">delete</font> all data " "This will <font color=\"red\">delete</font> all data "
@ -1244,8 +1239,7 @@ ChoicePage::setupActions()
m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>" m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>"
"Replaces a partition with %1." ) "Replaces a partition with %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
) )
} }
@ -1273,8 +1267,7 @@ ChoicePage::setupActions()
m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>" m_alongsideButton->setText( tr( "<strong>Install alongside</strong><br/>"
"The installer will shrink a partition to make room for %1." ) "The installer will shrink a partition to make room for %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
m_eraseButton->setText( tr( "<strong>Erase disk</strong><br/>" m_eraseButton->setText( tr( "<strong>Erase disk</strong><br/>"
"This will <font color=\"red\">delete</font> all data " "This will <font color=\"red\">delete</font> all data "
@ -1282,8 +1275,7 @@ ChoicePage::setupActions()
m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>" m_replaceButton->setText( tr( "<strong>Replace a partition</strong><br/>"
"Replaces a partition with %1." ) "Replaces a partition with %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
) )
m_replaceButton->show(); m_replaceButton->show();

View File

@ -156,18 +156,15 @@ PartitionViewStep::createSummaryWidget() const
{ {
case ChoicePage::Alongside: case ChoicePage::Alongside:
modeText = tr( "Install %1 <strong>alongside</strong> another operating system." ) modeText = tr( "Install %1 <strong>alongside</strong> another operating system." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName );
string( Calamares::Branding::ShortVersionedName ) );
break; break;
case ChoicePage::Erase: case ChoicePage::Erase:
modeText = tr( "<strong>Erase</strong> disk and install %1." ) modeText = tr( "<strong>Erase</strong> disk and install %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName );
string( Calamares::Branding::ShortVersionedName ) );
break; break;
case ChoicePage::Replace: case ChoicePage::Replace:
modeText = tr( "<strong>Replace</strong> a partition with %1." ) modeText = tr( "<strong>Replace</strong> a partition with %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName );
string( Calamares::Branding::ShortVersionedName ) );
break; break;
default: default:
modeText = tr( "<strong>Manual</strong> partitioning." ); modeText = tr( "<strong>Manual</strong> partitioning." );
@ -184,22 +181,19 @@ PartitionViewStep::createSummaryWidget() const
{ {
case ChoicePage::Alongside: case ChoicePage::Alongside:
modeText = tr( "Install %1 <strong>alongside</strong> another operating system on disk <strong>%2</strong> (%3)." ) modeText = tr( "Install %1 <strong>alongside</strong> another operating system on disk <strong>%2</strong> (%3)." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName )
string( Calamares::Branding::ShortVersionedName ) )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
break; break;
case ChoicePage::Erase: case ChoicePage::Erase:
modeText = tr( "<strong>Erase</strong> disk <strong>%2</strong> (%3) and install %1." ) modeText = tr( "<strong>Erase</strong> disk <strong>%2</strong> (%3) and install %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName )
string( Calamares::Branding::ShortVersionedName ) )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
break; break;
case ChoicePage::Replace: case ChoicePage::Replace:
modeText = tr( "<strong>Replace</strong> a partition on disk <strong>%2</strong> (%3) with %1." ) modeText = tr( "<strong>Replace</strong> a partition on disk <strong>%2</strong> (%3) with %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName )
string( Calamares::Branding::ShortVersionedName ) )
.arg( info.deviceNode ) .arg( info.deviceNode )
.arg( info.deviceName ); .arg( info.deviceName );
break; break;
@ -250,8 +244,7 @@ PartitionViewStep::createSummaryWidget() const
previewLabels->setModel( info.partitionModelAfter ); previewLabels->setModel( info.partitionModelAfter );
preview->setSelectionMode( QAbstractItemView::NoSelection ); preview->setSelectionMode( QAbstractItemView::NoSelection );
previewLabels->setSelectionMode( QAbstractItemView::NoSelection ); previewLabels->setSelectionMode( QAbstractItemView::NoSelection );
previewLabels->setCustomNewRootLabel( Calamares::Branding::instance()-> previewLabels->setCustomNewRootLabel( *Calamares::Branding::BootloaderEntryName );
string( Calamares::Branding::BootloaderEntryName ) );
info.partitionModelAfter->setParent( widget ); info.partitionModelAfter->setParent( widget );
field = new QVBoxLayout; field = new QVBoxLayout;
CalamaresUtils::unmarginLayout( field ); CalamaresUtils::unmarginLayout( field );
@ -411,8 +404,7 @@ PartitionViewStep::onLeave()
"<strong>%2</strong>.<br/><br/>" "<strong>%2</strong>.<br/><br/>"
"You can continue without setting up an EFI system " "You can continue without setting up an EFI system "
"partition but your system may fail to start." ) "partition but your system may fail to start." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortProductName )
string( Calamares::Branding::ShortProductName ) )
.arg( espMountPoint ); .arg( espMountPoint );
} }
else if ( esp && !esp->activeFlags().testFlag( PartitionTable::FlagEsp ) ) else if ( esp && !esp->activeFlags().testFlag( PartitionTable::FlagEsp ) )
@ -427,8 +419,7 @@ PartitionViewStep::onLeave()
"<br/><br/>" "<br/><br/>"
"You can continue without setting the flag but your " "You can continue without setting the flag but your "
"system may fail to start." ) "system may fail to start." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortProductName )
string( Calamares::Branding::ShortProductName ) )
.arg( espMountPoint ); .arg( espMountPoint );
} }

View File

@ -134,8 +134,7 @@ ReplaceWidget::onPartitionSelected()
tr( "Select where to install %1.<br/>" tr( "Select where to install %1.<br/>"
"<font color=\"red\">Warning: </font>this will delete all files " "<font color=\"red\">Warning: </font>this will delete all files "
"on the selected partition." ) "on the selected partition." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName ) );
string( Calamares::Branding::VersionedName ) ) );
setNextEnabled( false ); setNextEnabled( false );
return; return;
} }
@ -168,8 +167,7 @@ ReplaceWidget::onPartitionSelected()
updateStatus( CalamaresUtils::Fail, updateStatus( CalamaresUtils::Fail,
tr( "%1 cannot be installed on empty space. Please select an " tr( "%1 cannot be installed on empty space. Please select an "
"existing partition." ) "existing partition." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName ) );
string( Calamares::Branding::VersionedName ) ) );
setNextEnabled( false ); setNextEnabled( false );
return; return;
} }
@ -179,8 +177,7 @@ ReplaceWidget::onPartitionSelected()
updateStatus( CalamaresUtils::Fail, updateStatus( CalamaresUtils::Fail,
tr( "%1 cannot be installed on an extended partition. Please select an " tr( "%1 cannot be installed on an extended partition. Please select an "
"existing primary or logical partition." ) "existing primary or logical partition." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName ) );
string( Calamares::Branding::VersionedName ) ) );
setNextEnabled( false ); setNextEnabled( false );
return; return;
} }
@ -189,8 +186,7 @@ ReplaceWidget::onPartitionSelected()
{ {
updateStatus( CalamaresUtils::Fail, updateStatus( CalamaresUtils::Fail,
tr( "%1 cannot be installed on this partition." ) tr( "%1 cannot be installed on this partition." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName ) );
string( Calamares::Branding::VersionedName ) ) );
setNextEnabled( false ); setNextEnabled( false );
return; return;
} }
@ -232,8 +228,7 @@ ReplaceWidget::onPartitionSelected()
"The partition %1 is too small for %2. Please select a partition " "The partition %1 is too small for %2. Please select a partition "
"with capacity at least %3 GiB." ) "with capacity at least %3 GiB." )
.arg( partition->partitionPath() ) .arg( partition->partitionPath() )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName )
string( Calamares::Branding::VersionedName ) )
.arg( requiredSpaceB / ( 1024. * 1024. * 1024. ), .arg( requiredSpaceB / ( 1024. * 1024. * 1024. ),
0, 'f', 1 ) 0, 'f', 1 )
.arg( prettyName ) ); .arg( prettyName ) );
@ -256,8 +251,7 @@ ReplaceWidget::onPartitionSelected()
"An EFI system partition cannot be found anywhere " "An EFI system partition cannot be found anywhere "
"on this system. Please go back and use manual " "on this system. Please go back and use manual "
"partitioning to set up %1." ) "partitioning to set up %1." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortProductName )
string( Calamares::Branding::ShortProductName ) )
.arg( prettyName ) ); .arg( prettyName ) );
setNextEnabled( false ); setNextEnabled( false );
} }
@ -268,16 +262,14 @@ ReplaceWidget::onPartitionSelected()
"%1 will be installed on %2.<br/>" "%1 will be installed on %2.<br/>"
"<font color=\"red\">Warning: </font>all data on partition " "<font color=\"red\">Warning: </font>all data on partition "
"%2 will be lost.") "%2 will be lost.")
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName )
string( Calamares::Branding::VersionedName ) )
.arg( partition->partitionPath() ) .arg( partition->partitionPath() )
.arg( prettyName ) ); .arg( prettyName ) );
m_ui->bootStatusLabel->show(); m_ui->bootStatusLabel->show();
m_ui->bootStatusLabel->setText( m_ui->bootStatusLabel->setText(
tr( "The EFI system partition at %1 will be used for starting %2." ) tr( "The EFI system partition at %1 will be used for starting %2." )
.arg( efiSystemPartitions.first()->partitionPath() ) .arg( efiSystemPartitions.first()->partitionPath() )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortProductName ) );
string( Calamares::Branding::ShortProductName ) ) );
setNextEnabled( true ); setNextEnabled( true );
} }
else else
@ -287,8 +279,7 @@ ReplaceWidget::onPartitionSelected()
"%1 will be installed on %2.<br/>" "%1 will be installed on %2.<br/>"
"<font color=\"red\">Warning: </font>all data on partition " "<font color=\"red\">Warning: </font>all data on partition "
"%2 will be lost.") "%2 will be lost.")
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName )
string( Calamares::Branding::VersionedName ) )
.arg( partition->partitionPath() ) .arg( partition->partitionPath() )
.arg( prettyName ) ); .arg( prettyName ) );
m_ui->bootStatusLabel->show(); m_ui->bootStatusLabel->show();
@ -312,8 +303,7 @@ ReplaceWidget::onPartitionSelected()
"%1 will be installed on %2.<br/>" "%1 will be installed on %2.<br/>"
"<font color=\"red\">Warning: </font>all data on partition " "<font color=\"red\">Warning: </font>all data on partition "
"%2 will be lost.") "%2 will be lost.")
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName )
string( Calamares::Branding::VersionedName ) )
.arg( partition->partitionPath() ) .arg( partition->partitionPath() )
.arg( prettyName ) ); .arg( prettyName ) );
setNextEnabled( true ); setNextEnabled( true );

View File

@ -145,8 +145,7 @@ FillGlobalStorageJob::prettyDescription() const
{ {
if ( mountPoint == "/" ) if ( mountPoint == "/" )
lines.append( tr( "Install %1 on <strong>new</strong> %2 system partition." ) lines.append( tr( "Install %1 on <strong>new</strong> %2 system partition." )
.arg( Calamares::Branding::instance()->string( .arg( *Calamares::Branding::ShortProductName )
Calamares::Branding::ShortProductName ) )
.arg( fsType ) ); .arg( fsType ) );
else else
lines.append( tr( "Set up <strong>new</strong> %2 partition with mount point " lines.append( tr( "Set up <strong>new</strong> %2 partition with mount point "
@ -159,8 +158,7 @@ FillGlobalStorageJob::prettyDescription() const
if ( mountPoint == "/" ) if ( mountPoint == "/" )
lines.append( tr( "Install %2 on %3 system partition <strong>%1</strong>." ) lines.append( tr( "Install %2 on %3 system partition <strong>%1</strong>." )
.arg( path ) .arg( path )
.arg( Calamares::Branding::instance()->string( .arg( *Calamares::Branding::ShortProductName )
Calamares::Branding::ShortProductName ) )
.arg( fsType ) ); .arg( fsType ) );
else else
lines.append( tr( "Set up %3 partition <strong>%1</strong> with mount point " lines.append( tr( "Set up %3 partition <strong>%1</strong> with mount point "