From f6cbf48b1748d1f0e4da93fef471648ddfbd87d7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 3 Jul 2017 18:07:18 -0400 Subject: [PATCH] C++ trickery to make the code shorter to read. --- src/calamares/CalamaresWindow.cpp | 3 +-- src/libcalamaresui/Branding.h | 7 ++++++ src/libcalamaresui/ViewManager.cpp | 7 +++--- src/modules/partition/gui/ChoicePage.cpp | 19 ++++++--------- src/modules/welcome/WelcomePage.cpp | 23 ++++++++----------- src/modules/welcome/checker/CheckerWidget.cpp | 10 ++++---- 6 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 271e22cb9..f0a827a0d 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -43,8 +43,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) CALAMARES_RETRANSLATE( setWindowTitle( tr( "%1 Installer" ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ProductName ) ) ); + .arg( *Calamares::Branding::ProductName ) ); ) using CalamaresUtils::windowMinimumHeight; diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 36534ea44..5198f44f1 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -37,6 +37,11 @@ class UIDLLEXPORT Branding : public QObject { Q_OBJECT public: + /** + * Descriptive strings in the configuration file. use + * e.g. *Branding::ProductName to get the string value for + * the product name. + */ enum StringEntry : short { ProductName, @@ -112,6 +117,8 @@ private: bool m_welcomeStyleCalamares; }; +template inline QString operator*(U e) { return Branding::instance()->string( e ); } + } #endif // BRANDING_H diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index efdc3a3fe..c4685ddee 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * 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 " "disk in order to install %2.
You will not be able " "to undo these changes." ) - .arg( Calamares::Branding::instance()->string( - Calamares::Branding::ShortProductName ) ) - .arg( Calamares::Branding::instance()->string( - Calamares::Branding::ShortVersionedName ) ), + .arg( *Calamares::Branding::ShortProductName ) + .arg( *Calamares::Branding::ShortVersionedName ), tr( "&Install now" ), tr( "Go &back" ), QString(), diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index a213e62fa..6b57a23f4 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2017, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * 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 ), part->capacity() - requiredStorageB, part->capacity() / 2, - Calamares::Branding::instance()-> - string( Calamares::Branding::ProductName ) ); + *Calamares::Branding::ProductName ); if ( m_isEfi ) setupEfiSystemPartitionSelector(); @@ -775,8 +775,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current ) if ( !homePartitionPath->isEmpty() ) m_reuseHomeCheckBox->setText( tr( "Reuse %1 as home partition for %2." ) .arg( *homePartitionPath ) - .arg( Calamares::Branding::instance()->string( - Calamares::Branding::ShortProductName ) ) ); + .arg( *Calamares::Branding::ShortProductName ) ); delete homePartitionPath; if ( m_isEfi ) @@ -919,8 +918,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice ) .arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() ) .arg( size / ( 1024 * 1024 ) ) .arg( sizeNext / ( 1024 * 1024 ) ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ShortProductName ) ) ); + .arg( *Calamares::Branding::ShortProductName ) ); } ); m_previewAfterFrame->show(); @@ -948,8 +946,7 @@ ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice ) m_afterPartitionBarsView->setNestedPartitionsMode( mode ); m_afterPartitionLabelsView = new PartitionLabelsView( m_previewAfterFrame ); m_afterPartitionLabelsView->setExtendedPartitionHidden( mode == PartitionBarsView::NoNestedPartitions ); - m_afterPartitionLabelsView->setCustomNewRootLabel( Calamares::Branding::instance()-> - string( Calamares::Branding::BootloaderEntryName ) ); + m_afterPartitionLabelsView->setCustomNewRootLabel( *Calamares::Branding::BootloaderEntryName ); PartitionModel* model = m_core->partitionModelForDevice( selectedDevice() ); @@ -1073,8 +1070,7 @@ ChoicePage::setupEfiSystemPartitionSelector() tr( "An EFI system partition cannot be found anywhere " "on this system. Please go back and use manual " "partitioning to set up %1." ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ShortProductName ) ) ); + .arg( *Calamares::Branding::ShortProductName ) ); updateNextEnabled(); } 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 " "starting %2." ) .arg( efiSystemPartitions.first()->partitionPath() ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ShortProductName ) ) ); + .arg( *Calamares::Branding::ShortProductName ) ); } else { diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 838148a76..c556c4189 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -54,12 +54,11 @@ WelcomePage::WelcomePage( RequirementsChecker* requirementsChecker, QWidget* par ui->mainText->setOpenExternalLinks( true ); cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() - << Calamares::Branding::instance()->string( Calamares::Branding::VersionedName ); + << *Calamares::Branding::VersionedName; CALAMARES_RETRANSLATE( ui->mainText->setText( (Calamares::Branding::instance()->welcomeStyleCalamares() ? tr( "

Welcome to the Calamares installer for %1.

" ) : tr( "

Welcome to the %1 installer.

" )) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::VersionedName ) ) ); + .arg( *Calamares::Branding::VersionedName ) ); ui->retranslateUi( this ); ) @@ -89,8 +88,7 @@ WelcomePage::WelcomePage( RequirementsChecker* requirementsChecker, QWidget* par ) .arg( CALAMARES_APPLICATION_NAME ) .arg( CALAMARES_VERSION ) - .arg( Calamares::Branding::instance()->string( - Calamares::Branding::VersionedName ) ), + .arg( *Calamares::Branding::VersionedName ), QMessageBox::Ok, this ); mb.setIconPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Squid, @@ -193,12 +191,11 @@ WelcomePage::setUpLinks( bool showSupportUrl, bool showReleaseNotesUrl ) { using namespace Calamares; - Branding* b = Branding::instance(); - if ( showSupportUrl && !b->string( Branding::SupportUrl ).isEmpty() ) + if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() ) { CALAMARES_RETRANSLATE( ui->supportButton->setText( tr( "%1 support" ) - .arg( b->string( Branding::ShortProductName ) ) ); + .arg( *Branding::ShortProductName ) ); ) ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Help, CalamaresUtils::Original, @@ -206,7 +203,7 @@ WelcomePage::setUpLinks( bool showSupportUrl, CalamaresUtils::defaultFontHeight() ) ) ); connect( ui->supportButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( Branding::instance()->string( Branding::SupportUrl ) ); + QDesktopServices::openUrl( *Branding::SupportUrl ); } ); } else @@ -214,7 +211,7 @@ WelcomePage::setUpLinks( bool showSupportUrl, ui->supportButton->hide(); } - if ( showKnownIssuesUrl && !b->string( Branding::KnownIssuesUrl ).isEmpty() ) + if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() ) { ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Bugs, CalamaresUtils::Original, @@ -222,7 +219,7 @@ WelcomePage::setUpLinks( bool showSupportUrl, CalamaresUtils::defaultFontHeight() ) ) ); connect( ui->knownIssuesButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( Branding::instance()->string( Branding::KnownIssuesUrl ) ); + QDesktopServices::openUrl( *Branding::KnownIssuesUrl ); } ); } else @@ -230,7 +227,7 @@ WelcomePage::setUpLinks( bool showSupportUrl, ui->knownIssuesButton->hide(); } - if ( showReleaseNotesUrl && !b->string( Branding::ReleaseNotesUrl ).isEmpty() ) + if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() ) { ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release, CalamaresUtils::Original, @@ -238,7 +235,7 @@ WelcomePage::setUpLinks( bool showSupportUrl, CalamaresUtils::defaultFontHeight() ) ) ); connect( ui->releaseNotesButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( Branding::instance()->string( Branding::ReleaseNotesUrl ) ); + QDesktopServices::openUrl( *Branding::ReleaseNotesUrl ); } ); } else diff --git a/src/modules/welcome/checker/CheckerWidget.cpp b/src/modules/welcome/checker/CheckerWidget.cpp index be341acc0..8e1bf4dce 100644 --- a/src/modules/welcome/checker/CheckerWidget.cpp +++ b/src/modules/welcome/checker/CheckerWidget.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2017, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * 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.
" "Installation cannot continue. " "Details..." ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ShortVersionedName ) ) ); + .arg( *Calamares::Branding::ShortVersionedName ) ); ) textLabel->setOpenExternalLinks( false ); connect( textLabel, &QLabel::linkActivated, @@ -114,8 +114,7 @@ CheckerWidget::init( const QList< PrepareEntry >& checkEntries ) "recommended requirements for installing %1.
" "Installation can continue, but some features " "might be disabled." ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ShortVersionedName ) ) ); + .arg( *Calamares::Branding::ShortVersionedName ) ); ) } } @@ -141,8 +140,7 @@ CheckerWidget::init( const QList< PrepareEntry >& checkEntries ) CALAMARES_RETRANSLATE( textLabel->setText( tr( "This program will ask you some questions and " "set up %2 on your computer." ) - .arg( Calamares::Branding::instance()-> - string( Calamares::Branding::ProductName ) ) ); + .arg( *Calamares::Branding::ProductName ) ); textLabel->setAlignment( Qt::AlignCenter ); ) }