C++ trickery to make the code shorter to read.

This commit is contained in:
Adriaan de Groot 2017-07-03 18:07:18 -04:00 committed by Philip
parent 843706e38d
commit f6cbf48b17
6 changed files with 32 additions and 37 deletions

View File

@ -43,8 +43,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
setWindowTitle( tr( "%1 Installer" ) setWindowTitle( tr( "%1 Installer" )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ProductName ) );
string( Calamares::Branding::ProductName ) ) );
) )
using CalamaresUtils::windowMinimumHeight; using CalamaresUtils::windowMinimumHeight;

View File

@ -37,6 +37,11 @@ class UIDLLEXPORT Branding : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
/**
* Descriptive strings in the configuration file. use
* e.g. *Branding::ProductName to get the string value for
* the product name.
*/
enum StringEntry : short enum StringEntry : short
{ {
ProductName, ProductName,
@ -112,6 +117,8 @@ private:
bool m_welcomeStyleCalamares; bool m_welcomeStyleCalamares;
}; };
template<typename U> inline QString operator*(U e) { return Branding::instance()->string( e ); }
} }
#endif // BRANDING_H #endif // BRANDING_H

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -226,10 +227,8 @@ ViewManager::next()
tr( "The %1 installer is about to make changes to your " tr( "The %1 installer is about to make changes to your "
"disk in order to install %2.<br/><strong>You will not be able " "disk in order to install %2.<br/><strong>You will not be able "
"to undo these changes.</strong>" ) "to undo these changes.</strong>" )
.arg( Calamares::Branding::instance()->string( .arg( *Calamares::Branding::ShortProductName )
Calamares::Branding::ShortProductName ) ) .arg( *Calamares::Branding::ShortVersionedName ),
.arg( Calamares::Branding::instance()->string(
Calamares::Branding::ShortVersionedName ) ),
tr( "&Install now" ), tr( "&Install now" ),
tr( "Go &back" ), tr( "Go &back" ),
QString(), QString(),

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -474,8 +475,7 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current,
qRound64( part->used() * 1.1 ), qRound64( part->used() * 1.1 ),
part->capacity() - requiredStorageB, part->capacity() - requiredStorageB,
part->capacity() / 2, part->capacity() / 2,
Calamares::Branding::instance()-> *Calamares::Branding::ProductName );
string( Calamares::Branding::ProductName ) );
if ( m_isEfi ) if ( m_isEfi )
setupEfiSystemPartitionSelector(); setupEfiSystemPartitionSelector();
@ -775,8 +775,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current )
if ( !homePartitionPath->isEmpty() ) if ( !homePartitionPath->isEmpty() )
m_reuseHomeCheckBox->setText( tr( "Reuse %1 as home partition for %2." ) m_reuseHomeCheckBox->setText( tr( "Reuse %1 as home partition for %2." )
.arg( *homePartitionPath ) .arg( *homePartitionPath )
.arg( Calamares::Branding::instance()->string( .arg( *Calamares::Branding::ShortProductName ) );
Calamares::Branding::ShortProductName ) ) );
delete homePartitionPath; delete homePartitionPath;
if ( m_isEfi ) if ( m_isEfi )
@ -919,8 +918,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice )
.arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() ) .arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() )
.arg( size / ( 1024 * 1024 ) ) .arg( size / ( 1024 * 1024 ) )
.arg( sizeNext / ( 1024 * 1024 ) ) .arg( sizeNext / ( 1024 * 1024 ) )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortProductName ) );
string( Calamares::Branding::ShortProductName ) ) );
} ); } );
m_previewAfterFrame->show(); m_previewAfterFrame->show();
@ -948,8 +946,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice )
m_afterPartitionBarsView->setNestedPartitionsMode( mode ); m_afterPartitionBarsView->setNestedPartitionsMode( mode );
m_afterPartitionLabelsView = new PartitionLabelsView( m_previewAfterFrame ); m_afterPartitionLabelsView = new PartitionLabelsView( m_previewAfterFrame );
m_afterPartitionLabelsView->setExtendedPartitionHidden( mode == PartitionBarsView::NoNestedPartitions ); m_afterPartitionLabelsView->setExtendedPartitionHidden( mode == PartitionBarsView::NoNestedPartitions );
m_afterPartitionLabelsView->setCustomNewRootLabel( Calamares::Branding::instance()-> m_afterPartitionLabelsView->setCustomNewRootLabel( *Calamares::Branding::BootloaderEntryName );
string( Calamares::Branding::BootloaderEntryName ) );
PartitionModel* model = m_core->partitionModelForDevice( selectedDevice() ); PartitionModel* model = m_core->partitionModelForDevice( selectedDevice() );
@ -1073,8 +1070,7 @@ ChoicePage::setupEfiSystemPartitionSelector()
tr( "An EFI system partition cannot be found anywhere " tr( "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 ) ) );
updateNextEnabled(); updateNextEnabled();
} }
else if ( efiSystemPartitions.count() == 1 ) //probably most usual situation else if ( efiSystemPartitions.count() == 1 ) //probably most usual situation
@ -1083,8 +1079,7 @@ ChoicePage::setupEfiSystemPartitionSelector()
tr( "The EFI system partition at %1 will be used for " tr( "The EFI system partition at %1 will be used for "
"starting %2." ) "starting %2." )
.arg( efiSystemPartitions.first()->partitionPath() ) .arg( efiSystemPartitions.first()->partitionPath() )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortProductName ) );
string( Calamares::Branding::ShortProductName ) ) );
} }
else else
{ {

View File

@ -54,12 +54,11 @@ WelcomePage::WelcomePage( RequirementsChecker* requirementsChecker, QWidget* par
ui->mainText->setOpenExternalLinks( true ); ui->mainText->setOpenExternalLinks( true );
cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares()
<< Calamares::Branding::instance()->string( Calamares::Branding::VersionedName ); << *Calamares::Branding::VersionedName;
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
ui->mainText->setText( (Calamares::Branding::instance()->welcomeStyleCalamares() ? tr( "<h1>Welcome to the Calamares installer for %1.</h1>" ) : tr( "<h1>Welcome to the %1 installer.</h1>" )) ui->mainText->setText( (Calamares::Branding::instance()->welcomeStyleCalamares() ? tr( "<h1>Welcome to the Calamares installer for %1.</h1>" ) : tr( "<h1>Welcome to the %1 installer.</h1>" ))
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::VersionedName ) );
string( Calamares::Branding::VersionedName ) ) );
ui->retranslateUi( this ); ui->retranslateUi( this );
) )
@ -89,8 +88,7 @@ WelcomePage::WelcomePage( RequirementsChecker* requirementsChecker, QWidget* par
) )
.arg( CALAMARES_APPLICATION_NAME ) .arg( CALAMARES_APPLICATION_NAME )
.arg( CALAMARES_VERSION ) .arg( CALAMARES_VERSION )
.arg( Calamares::Branding::instance()->string( .arg( *Calamares::Branding::VersionedName ),
Calamares::Branding::VersionedName ) ),
QMessageBox::Ok, QMessageBox::Ok,
this ); this );
mb.setIconPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Squid, mb.setIconPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Squid,
@ -193,12 +191,11 @@ WelcomePage::setUpLinks( bool showSupportUrl,
bool showReleaseNotesUrl ) bool showReleaseNotesUrl )
{ {
using namespace Calamares; using namespace Calamares;
Branding* b = Branding::instance(); if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() )
if ( showSupportUrl && !b->string( Branding::SupportUrl ).isEmpty() )
{ {
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
ui->supportButton->setText( tr( "%1 support" ) ui->supportButton->setText( tr( "%1 support" )
.arg( b->string( Branding::ShortProductName ) ) ); .arg( *Branding::ShortProductName ) );
) )
ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Help, ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Help,
CalamaresUtils::Original, CalamaresUtils::Original,
@ -206,7 +203,7 @@ WelcomePage::setUpLinks( bool showSupportUrl,
CalamaresUtils::defaultFontHeight() ) ) ); CalamaresUtils::defaultFontHeight() ) ) );
connect( ui->supportButton, &QPushButton::clicked, [] connect( ui->supportButton, &QPushButton::clicked, []
{ {
QDesktopServices::openUrl( Branding::instance()->string( Branding::SupportUrl ) ); QDesktopServices::openUrl( *Branding::SupportUrl );
} ); } );
} }
else else
@ -214,7 +211,7 @@ WelcomePage::setUpLinks( bool showSupportUrl,
ui->supportButton->hide(); ui->supportButton->hide();
} }
if ( showKnownIssuesUrl && !b->string( Branding::KnownIssuesUrl ).isEmpty() ) if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() )
{ {
ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Bugs, ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Bugs,
CalamaresUtils::Original, CalamaresUtils::Original,
@ -222,7 +219,7 @@ WelcomePage::setUpLinks( bool showSupportUrl,
CalamaresUtils::defaultFontHeight() ) ) ); CalamaresUtils::defaultFontHeight() ) ) );
connect( ui->knownIssuesButton, &QPushButton::clicked, [] connect( ui->knownIssuesButton, &QPushButton::clicked, []
{ {
QDesktopServices::openUrl( Branding::instance()->string( Branding::KnownIssuesUrl ) ); QDesktopServices::openUrl( *Branding::KnownIssuesUrl );
} ); } );
} }
else else
@ -230,7 +227,7 @@ WelcomePage::setUpLinks( bool showSupportUrl,
ui->knownIssuesButton->hide(); ui->knownIssuesButton->hide();
} }
if ( showReleaseNotesUrl && !b->string( Branding::ReleaseNotesUrl ).isEmpty() ) if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() )
{ {
ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release, ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release,
CalamaresUtils::Original, CalamaresUtils::Original,
@ -238,7 +235,7 @@ WelcomePage::setUpLinks( bool showSupportUrl,
CalamaresUtils::defaultFontHeight() ) ) ); CalamaresUtils::defaultFontHeight() ) ) );
connect( ui->releaseNotesButton, &QPushButton::clicked, [] connect( ui->releaseNotesButton, &QPushButton::clicked, []
{ {
QDesktopServices::openUrl( Branding::instance()->string( Branding::ReleaseNotesUrl ) ); QDesktopServices::openUrl( *Branding::ReleaseNotesUrl );
} ); } );
} }
else else

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -96,8 +97,7 @@ CheckerWidget::init( const QList< PrepareEntry >& checkEntries )
"requirements for installing %1.<br/>" "requirements for installing %1.<br/>"
"Installation cannot continue. " "Installation cannot continue. "
"<a href=\"#details\">Details...</a>" ) "<a href=\"#details\">Details...</a>" )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
) )
textLabel->setOpenExternalLinks( false ); textLabel->setOpenExternalLinks( false );
connect( textLabel, &QLabel::linkActivated, connect( textLabel, &QLabel::linkActivated,
@ -114,8 +114,7 @@ CheckerWidget::init( const QList< PrepareEntry >& checkEntries )
"recommended requirements for installing %1.<br/>" "recommended requirements for installing %1.<br/>"
"Installation can continue, but some features " "Installation can continue, but some features "
"might be disabled." ) "might be disabled." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ShortVersionedName ) );
string( Calamares::Branding::ShortVersionedName ) ) );
) )
} }
} }
@ -141,8 +140,7 @@ CheckerWidget::init( const QList< PrepareEntry >& checkEntries )
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
textLabel->setText( tr( "This program will ask you some questions and " textLabel->setText( tr( "This program will ask you some questions and "
"set up %2 on your computer." ) "set up %2 on your computer." )
.arg( Calamares::Branding::instance()-> .arg( *Calamares::Branding::ProductName ) );
string( Calamares::Branding::ProductName ) ) );
textLabel->setAlignment( Qt::AlignCenter ); textLabel->setAlignment( Qt::AlignCenter );
) )
} }