From 6b8c0129fdb2a6f3f9a82ea6b45d57b78292a5d3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:24:30 +0200 Subject: [PATCH 1/9] [libcalamaresui] Add one more icon (donate) from Breeze - LGPLv3 like the others --- data/images/help-donate.svg | 18 ++++++++++++++++++ src/libcalamaresui/libcalamaresui.qrc | 1 + src/libcalamaresui/utils/CalamaresUtilsGui.cpp | 4 ++++ src/libcalamaresui/utils/CalamaresUtilsGui.h | 1 + 4 files changed, 24 insertions(+) create mode 100644 data/images/help-donate.svg diff --git a/data/images/help-donate.svg b/data/images/help-donate.svg new file mode 100644 index 000000000..2370c127e --- /dev/null +++ b/data/images/help-donate.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/src/libcalamaresui/libcalamaresui.qrc b/src/libcalamaresui/libcalamaresui.qrc index 79ae4e45f..eeb3fc490 100644 --- a/src/libcalamaresui/libcalamaresui.qrc +++ b/src/libcalamaresui/libcalamaresui.qrc @@ -7,6 +7,7 @@ ../../data/images/bugs.svg ../../data/images/help.svg ../../data/images/release.svg + ../../data/images/help-donate.svg ../../data/images/partition-disk.svg ../../data/images/partition-partition.svg ../../data/images/partition-alongside.svg diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index b6c927763..bd15d7a68 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -74,6 +74,10 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/release.svg", size ); break; + case Donate: + pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/donate.svg", size ); + break; + case PartitionDisk: pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/partition-disk.svg", size ); break; diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 012795e34..0c10dcc30 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -47,6 +47,7 @@ enum ImageType : int Bugs, Help, Release, + Donate, PartitionDisk, PartitionPartition, PartitionAlongside, From b60ec123a0937e2a65d855ec1447534a5ab42890 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 21:21:19 +0200 Subject: [PATCH 2/9] [branding] [welcome] Document interrelationship of settings --- src/branding/default/branding.desc | 5 ++++- src/modules/welcome/welcome.conf | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 1bd76cd29..3d1079a8c 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -56,6 +56,9 @@ windowSize: 800px,520px # Note that ANSI_COLOR and CPE_NAME don't make sense here, and # are not supported (the rest are). Remember to quote the string # if it contains substitutions, or you'll get YAML exceptions. +# +# The *Url* entries are used on the welcome page, and they +# are visible as buttons there if the corresponding *show* keys are set. strings: productName: "@{NAME}" shortProductName: Generic @@ -84,7 +87,7 @@ strings: # the window. Use `welcomeExpandingLogo` to make it non-scaled. # Recommended size is 320x150. # -# These strings can also use substitutions from os-release (see above). +# These filenames can also use substitutions from os-release (see above). images: productLogo: "squid.png" productIcon: "squid.png" diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index a89b63854..a430345a2 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -7,6 +7,7 @@ # can check requirements for installation. --- # Display settings for various buttons on the welcome page. +# The URLs themselves come from branding.desc showSupportUrl: true showKnownIssuesUrl: true showReleaseNotesUrl: true From 03e506a826dd2c72386babdae3e22171952f25d3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:29:01 +0200 Subject: [PATCH 3/9] [welcome] Add a donate button FIXES #1197 --- src/modules/welcome/WelcomePage.cpp | 187 ++++++++++++++---------- src/modules/welcome/WelcomePage.h | 16 +- src/modules/welcome/WelcomePage.ui | 10 ++ src/modules/welcome/WelcomeViewStep.cpp | 41 ++++-- src/modules/welcome/welcome.conf | 7 + 5 files changed, 160 insertions(+), 101 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index b29b2e23e..6d0fc0d98 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -20,8 +20,8 @@ #include "WelcomePage.h" -#include "ui_WelcomePage.h" #include "checker/CheckerContainer.h" +#include "ui_WelcomePage.h" #include "Branding.h" #include "CalamaresVersion.h" @@ -48,9 +48,18 @@ WelcomePage::WelcomePage( QWidget* parent ) , m_checkingWidget( new CheckerContainer( this ) ) , m_languages( nullptr ) { - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked ); - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete ); - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsProgress, m_checkingWidget, &CheckerContainer::requirementsProgress ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsResult, + m_checkingWidget, + &CheckerContainer::requirementsChecked ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsComplete, + m_checkingWidget, + &CheckerContainer::requirementsComplete ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsProgress, + m_checkingWidget, + &CheckerContainer::requirementsProgress ); ui->setupUi( this ); ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() * 2 ); @@ -61,38 +70,31 @@ WelcomePage::WelcomePage( QWidget* parent ) ui->mainText->setOpenExternalLinks( true ); cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() - << *Calamares::Branding::VersionedName; + << *Calamares::Branding::VersionedName; - CALAMARES_RETRANSLATE( - QString message; + CALAMARES_RETRANSLATE( QString message; - if ( Calamares::Settings::instance()->isSetupMode() ) - message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares setup program for %1.

" ) - : tr( "

Welcome to %1 setup.

" ); - else - message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares installer for %1.

" ) - : tr( "

Welcome to the %1 installer.

" ); + if ( Calamares::Settings::instance()->isSetupMode() ) message + = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares setup program for %1.

" ) + : tr( "

Welcome to %1 setup.

" ); + else message = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares installer for %1.

" ) + : tr( "

Welcome to the %1 installer.

" ); - ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); - ui->retranslateUi( this ); - ) + ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); + ui->retranslateUi( this ); ) - ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Information, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->aboutButton, &QPushButton::clicked, - this, [ this ] - { - QString title = Calamares::Settings::instance()->isSetupMode() - ? tr( "About %1 setup" ) - : tr( "About %1 installer" ); + ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Information, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->aboutButton, &QPushButton::clicked, this, [this] { + QString title + = Calamares::Settings::instance()->isSetupMode() ? tr( "About %1 setup" ) : tr( "About %1 installer" ); QMessageBox mb( QMessageBox::Information, title.arg( CALAMARES_APPLICATION_NAME ), - tr( - "

%1


" + tr( "

%1


" "%2
" "for %3


" "Copyright 2014-2017 Teo Mrnjavac <teo@kde.org>
" @@ -103,24 +105,23 @@ WelcomePage::WelcomePage( QWidget* parent ) "Calamares " "development is sponsored by
" "Blue Systems - " - "Liberating Software." - ) - .arg( CALAMARES_APPLICATION_NAME ) - .arg( CALAMARES_VERSION ) - .arg( *Calamares::Branding::VersionedName ), + "Liberating Software." ) + .arg( CALAMARES_APPLICATION_NAME ) + .arg( CALAMARES_VERSION ) + .arg( *Calamares::Branding::VersionedName ), QMessageBox::Ok, this ); - mb.setIconPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Squid, - CalamaresUtils::Original, - QSize( CalamaresUtils::defaultFontHeight() * 6, - CalamaresUtils::defaultFontHeight() * 6 ) ) ); - QGridLayout* layout = reinterpret_cast( mb.layout() ); + mb.setIconPixmap( CalamaresUtils::defaultPixmap( + CalamaresUtils::Squid, + CalamaresUtils::Original, + QSize( CalamaresUtils::defaultFontHeight() * 6, CalamaresUtils::defaultFontHeight() * 6 ) ) ); + QGridLayout* layout = reinterpret_cast< QGridLayout* >( mb.layout() ); if ( layout ) layout->setColumnMinimumWidth( 2, CalamaresUtils::defaultFontHeight() * 24 ); mb.exec(); } ); - ui->verticalLayout->insertWidget( 3, m_checkingWidget); + ui->verticalLayout->insertWidget( 3, m_checkingWidget ); } @@ -139,15 +140,16 @@ WelcomePage::initLanguages() QLocale defaultLocale = QLocale( QLocale::system().name() ); cDebug() << "Matching locale" << defaultLocale; - int matchedLocaleIndex = m_languages->find( - [&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } ); + int matchedLocaleIndex = m_languages->find( [&]( const QLocale& x ) { + return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); + } ); if ( matchedLocaleIndex < 0 ) { cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language(); - matchedLocaleIndex = m_languages->find( - [&](const QLocale& x){ return x.language() == defaultLocale.language(); } ); + matchedLocaleIndex + = m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } ); } if ( matchedLocaleIndex < 0 ) @@ -159,7 +161,9 @@ WelcomePage::initLanguages() // Now, if it matched, because we didn't match the system locale, switch to the one found if ( matchedLocaleIndex >= 0 ) + { QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() ); + } } if ( matchedLocaleIndex >= 0 ) @@ -171,44 +175,36 @@ WelcomePage::initLanguages() ui->languageWidget->setCurrentIndex( matchedLocaleIndex ); } else + { cWarning() << "No available translation matched" << defaultLocale; + } connect( ui->languageWidget, static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), this, - [&]( int newIndex ) - { + [&]( int newIndex ) { const auto& selectedLocale = m_languages->locale( newIndex ).locale(); cDebug() << "Selected locale" << selectedLocale; QLocale::setDefault( selectedLocale ); - CalamaresUtils::installTranslator( selectedLocale, - Calamares::Branding::instance()->translationsDirectory(), - qApp ); + CalamaresUtils::installTranslator( + selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp ); } ); } void -WelcomePage::setUpLinks( bool showSupportUrl, - bool showKnownIssuesUrl, - bool showReleaseNotesUrl ) +WelcomePage::setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ) { using namespace Calamares; if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() ) { - CALAMARES_RETRANSLATE( - ui->supportButton->setText( tr( "%1 support" ) - .arg( *Branding::ShortProductName ) ); - ) - ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Help, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->supportButton, &QPushButton::clicked, [] - { - QDesktopServices::openUrl( *Branding::SupportUrl ); - } ); + CALAMARES_RETRANSLATE( ui->supportButton->setText( tr( "%1 support" ).arg( *Branding::ShortProductName ) ); ) + ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Help, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->supportButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::SupportUrl ); } ); } else { @@ -217,12 +213,11 @@ WelcomePage::setUpLinks( bool showSupportUrl, if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() ) { - ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Bugs, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->knownIssuesButton, &QPushButton::clicked, [] - { + ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Bugs, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->knownIssuesButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::KnownIssuesUrl ); } ); } @@ -233,12 +228,11 @@ WelcomePage::setUpLinks( bool showSupportUrl, if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() ) { - ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->releaseNotesButton, &QPushButton::clicked, [] - { + ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Release, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->releaseNotesButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::ReleaseNotesUrl ); } ); } @@ -249,11 +243,38 @@ WelcomePage::setUpLinks( bool showSupportUrl, } +void +WelcomePage::setupDonateButton( const QString& url ) +{ + if ( url.isEmpty() ) + { + ui->donateButton->hide(); + return; + } + + QUrl u( url ); + if ( u.isValid() ) + { + ui->donateButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Donate, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->donateButton, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); + } + else + { + qWarning() << "Donate URL" << url << "is invalid."; + ui->donateButton->hide(); + } +} + void WelcomePage::focusInEvent( QFocusEvent* e ) { if ( ui->languageWidget ) + { ui->languageWidget->setFocus(); + } e->accept(); } @@ -267,7 +288,9 @@ void WelcomePage::externallySelectedLanguage( int row ) { if ( ( row >= 0 ) && ( row < ui->languageWidget->count() ) ) + { ui->languageWidget->setCurrentIndex( row ); + } } void @@ -278,8 +301,14 @@ WelcomePage::setLanguageIcon( QPixmap i ) void -LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyledItemDelegate::paint( painter, option, index ); - option.widget->style()->drawItemText( painter, option.rect, Qt::AlignRight | Qt::AlignVCenter, option.palette, false, index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() ); + option.widget->style()->drawItemText( + painter, + option.rect, + Qt::AlignRight | Qt::AlignVCenter, + option.palette, + false, + index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() ); } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index 6c244bf0c..d8a1bd4f2 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -39,9 +39,10 @@ public: explicit WelcomePage( QWidget* parent = nullptr ); /// @brief Configure the buttons for URLs from the branding configuration - void setUpLinks( bool showSupportUrl, - bool showKnownIssuesUrl, - bool showReleaseNotesUrl ); + void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); + /// @brief Configure the "Donate" button + void setupDonateButton( const QString& ); + /// @brief Set international language-selector icon void setLanguageIcon( QPixmap ); @@ -50,8 +51,9 @@ public: /// @brief Change the language from an external source. void externallySelectedLanguage( int row ); + protected: - void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus + void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus private: /// @brief Fill the list of languages with the available translations @@ -59,7 +61,7 @@ private: Ui::WelcomePage* ui; CheckerContainer* m_checkingWidget; - CalamaresUtils::Locale::LabelModel *m_languages; + CalamaresUtils::Locale::LabelModel* m_languages; }; /** @brief Delegate to display language information in two columns. @@ -72,6 +74,6 @@ public: using QStyledItemDelegate::QStyledItemDelegate; void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; -} ; +}; -#endif // WELCOMEPAGE_H +#endif // WELCOMEPAGE_H diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index 548bd5d27..0787ac6e7 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -134,6 +134,16 @@ + + + + &Donate + + + true + + + diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 938fe1f45..60dd6f500 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -33,13 +33,16 @@ #include #include -CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin(); ) +CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); ) WelcomeViewStep::WelcomeViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_requirementsChecker( new GeneralRequirements( this ) ) { - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, this, &WelcomeViewStep::nextStatusChanged ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsComplete, + this, + &WelcomeViewStep::nextStatusChanged ); m_widget = new WelcomePage(); } @@ -47,7 +50,9 @@ WelcomeViewStep::WelcomeViewStep( QObject* parent ) WelcomeViewStep::~WelcomeViewStep() { if ( m_widget && m_widget->parent() == nullptr ) + { m_widget->deleteLater(); + } } @@ -107,16 +112,17 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) bool showKnownIssuesUrl = CalamaresUtils::getBool( configurationMap, "showKnownIssuesUrl", false ); bool showReleaseNotesUrl = CalamaresUtils::getBool( configurationMap, "showReleaseNotesUrl", false ); - m_widget->setUpLinks( showSupportUrl, - showKnownIssuesUrl, - showReleaseNotesUrl ); + m_widget->setUpLinks( showSupportUrl, showKnownIssuesUrl, showReleaseNotesUrl ); + m_widget->setupDonateButton( CalamaresUtils::getString( configurationMap, "donateUrl" ) ); - if ( configurationMap.contains( "requirements" ) && - configurationMap.value( "requirements" ).type() == QVariant::Map ) + if ( configurationMap.contains( "requirements" ) + && configurationMap.value( "requirements" ).type() == QVariant::Map ) + { m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() ); + } else cWarning() << "no valid requirements map found in welcome " - "module configuration."; + "module configuration."; bool ok = false; QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); @@ -124,15 +130,13 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { using FWString = QFutureWatcher< QString >; - auto* handler = new CalamaresUtils::GeoIP::Handler( - CalamaresUtils::getString( geoip, "style" ), - CalamaresUtils::getString( geoip, "url" ), - CalamaresUtils::getString( geoip, "selector" ) ); + auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ), + CalamaresUtils::getString( geoip, "url" ), + CalamaresUtils::getString( geoip, "selector" ) ); if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) { auto* future = new FWString(); - connect( future, &FWString::finished, [view=this, f=future, h=handler]() - { + connect( future, &FWString::finished, [view = this, f = future, h = handler]() { QString countryResult = f->future().result(); cDebug() << "GeoIP result for welcome=" << countryResult; view->setCountry( countryResult, h ); @@ -154,7 +158,9 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); if ( !icon.isNull() ) + { m_widget->setLanguageIcon( icon ); + } } } @@ -169,7 +175,8 @@ logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) { if ( handler ) { - cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" << static_cast( handler->type() ) << handler->selector() << ')'; + cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" + << static_cast< int >( handler->type() ) << handler->selector() << ')'; } } @@ -194,8 +201,12 @@ WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP:: { int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode ); if ( r < 0 ) + { cDebug() << "Unusable country code" << countryCode << "(no suitable translation)"; + } if ( ( r >= 0 ) && m_widget ) + { m_widget->externallySelectedLanguage( r ); + } } } diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index a430345a2..e8433c48d 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -12,6 +12,13 @@ showSupportUrl: true showKnownIssuesUrl: true showReleaseNotesUrl: true +# If this Url is set to something non-empty, a "donate" +# button is added to the welcome page alongside the +# others (see settings, above). Clicking the button opens +# the corresponding link. +# +# donateUrl: https://kde.org/community/donations/ + # Requirements checking. These are general, generic, things # that are checked. They may not match with the actual requirements # imposed by other modules in the system. From 64d4b0a46cbbb6f630cdd348610be7ee5c7d10fd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:43:11 +0200 Subject: [PATCH 4/9] [welcome] Switch API for buttons to an enum + string - Handle buttons and their URL-opening in a more general way with an enum; drop existing three-boot method and special setupDonateButton() - Doesn't compile because consumers haven't changed. --- src/modules/welcome/WelcomePage.cpp | 51 ++++++++++++++++++++++++----- src/modules/welcome/WelcomePage.h | 14 +++++--- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 6d0fc0d98..35807e93c 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -32,6 +32,7 @@ #include "modulesystem/ModuleManager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Retranslator.h" #include @@ -244,27 +245,59 @@ WelcomePage::setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool show void -WelcomePage::setupDonateButton( const QString& url ) +WelcomePage::setupButton( Button role, const QString& url ) { + QPushButton* button = nullptr; + CalamaresUtils::ImageType icon = CalamaresUtils::Information; + + switch ( role ) + { + case Button::Donate: + button = ui->donateButton; + icon = CalamaresUtils::Donate; + break; + case Button::KnownIssues: + button = ui->knownIssuesButton; + icon = CalamaresUtils::Bugs; + break; + case Button::ReleaseNotes: + button = ui->releaseNotesButton; + icon = CalamaresUtils::Release; + break; + case Button::Support: + button = ui->supportButton; + icon = CalamaresUtils::Help; + break; + } + if ( !button ) + { + qWarning() << "Unknown button role" << smash( role ); + return; + } + if ( url.isEmpty() ) { - ui->donateButton->hide(); + button->hide(); return; } QUrl u( url ); if ( u.isValid() ) { - ui->donateButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Donate, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->donateButton, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); + auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ); + button->setIcon( CalamaresUtils::defaultPixmap( + icon, + CalamaresUtils::Original,size + ); + connect( button, &QPushButton::clicked, [u]() + { + QDesktopServices::openUrl( u ); + } ); } else { - qWarning() << "Donate URL" << url << "is invalid."; - ui->donateButton->hide(); + qWarning() << "Welcome button" << smash( role ) << "URL" << url << "is invalid."; + button->hide(); } } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index d8a1bd4f2..3e776a5f0 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -38,10 +38,16 @@ class WelcomePage : public QWidget public: explicit WelcomePage( QWidget* parent = nullptr ); - /// @brief Configure the buttons for URLs from the branding configuration - void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); - /// @brief Configure the "Donate" button - void setupDonateButton( const QString& ); + enum class Button + { + Support, + Donate, + KnownIssues, + ReleaseNotes + }; + + /// @brief Configure the button @p n, to open @p url + void setupButton( Button b, const QString& url ); /// @brief Set international language-selector icon void setLanguageIcon( QPixmap ); From 119f84d6c146b86fa659727bd57f64aabb810383 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:57:33 +0200 Subject: [PATCH 5/9] [welcome] Remove setupLinks() method, use generic - the generic (enum-based) setupButton() can handle all four of the buttons, so setupLinks() can go away. Only the (re)translation of the text on the button needs to be done, so move that to the main RETRANSLATE. --- src/modules/welcome/WelcomePage.cpp | 84 ++++++----------------------- 1 file changed, 15 insertions(+), 69 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 35807e93c..8f989c47c 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -73,18 +73,20 @@ WelcomePage::WelcomePage( QWidget* parent ) cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() << *Calamares::Branding::VersionedName; - CALAMARES_RETRANSLATE( QString message; + CALAMARES_RETRANSLATE( + QString message; - if ( Calamares::Settings::instance()->isSetupMode() ) message - = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares setup program for %1.

" ) - : tr( "

Welcome to %1 setup.

" ); - else message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares installer for %1.

" ) - : tr( "

Welcome to the %1 installer.

" ); + if ( Calamares::Settings::instance()->isSetupMode() ) message + = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares setup program for %1.

" ) + : tr( "

Welcome to %1 setup.

" ); + else message = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares installer for %1.

" ) + : tr( "

Welcome to the %1 installer.

" ); - ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); - ui->retranslateUi( this ); ) + ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); + ui->retranslateUi( this ); + ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) ); ) ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Information, @@ -194,56 +196,6 @@ WelcomePage::initLanguages() } -void -WelcomePage::setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ) -{ - using namespace Calamares; - if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() ) - { - CALAMARES_RETRANSLATE( ui->supportButton->setText( tr( "%1 support" ).arg( *Branding::ShortProductName ) ); ) - ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Help, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->supportButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::SupportUrl ); } ); - } - else - { - ui->supportButton->hide(); - } - - if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() ) - { - ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Bugs, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->knownIssuesButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( *Branding::KnownIssuesUrl ); - } ); - } - else - { - ui->knownIssuesButton->hide(); - } - - if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() ) - { - ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Release, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->releaseNotesButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( *Branding::ReleaseNotesUrl ); - } ); - } - else - { - ui->releaseNotesButton->hide(); - } -} - - void WelcomePage::setupButton( Button role, const QString& url ) { @@ -284,15 +236,9 @@ WelcomePage::setupButton( Button role, const QString& url ) QUrl u( url ); if ( u.isValid() ) { - auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ); - button->setIcon( CalamaresUtils::defaultPixmap( - icon, - CalamaresUtils::Original,size - ); - connect( button, &QPushButton::clicked, [u]() - { - QDesktopServices::openUrl( u ); - } ); + auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ); + button->setIcon( CalamaresUtils::defaultPixmap( icon, CalamaresUtils::Original, size ) ); + connect( button, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); } else { From 341965c2b1f72bf34541b89bb90ec894accd38e4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:01:52 +0200 Subject: [PATCH 6/9] [welcome] Use setupButton for all four buttons - the show* settings in welcome.conf are "upgraded" to allow setting the URL directly in the module configuration. --- src/modules/welcome/WelcomeViewStep.cpp | 45 ++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 60dd6f500..b489adc9e 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -105,15 +105,50 @@ WelcomeViewStep::jobs() const } +/** @brief Look up a URL for a button + * + * Looks up @p key in @p map; if it is a *boolean* value, then + * assume an old-style configuration, and fetch the string from + * the branding settings @p e. If it is a string, not a boolean, + * use it as-is. If not found, or a weird type, returns empty. + * + * This allows switching the showKnownIssuesUrl and similar settings + * in welcome.conf from a boolean (deferring to branding) to an + * actual string for immediate use. Empty strings, as well as + * "false" as a setting, will hide the buttons as before. + */ +static QString +jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key ) +{ + if ( !map.contains( key ) ) + { + return QString(); + } + auto v = map.value( key ); + if ( v.type() == QVariant::Bool ) + { + return v.toBool() ? ( *e ) : QString(); + } + if ( v.type() == QVariant::String ) + { + return v.toString(); + } + + return QString(); +} + void WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - bool showSupportUrl = CalamaresUtils::getBool( configurationMap, "showSupportUrl", false ); - bool showKnownIssuesUrl = CalamaresUtils::getBool( configurationMap, "showKnownIssuesUrl", false ); - bool showReleaseNotesUrl = CalamaresUtils::getBool( configurationMap, "showReleaseNotesUrl", false ); + using Calamares::Branding; - m_widget->setUpLinks( showSupportUrl, showKnownIssuesUrl, showReleaseNotesUrl ); - m_widget->setupDonateButton( CalamaresUtils::getString( configurationMap, "donateUrl" ) ); + m_widget->setupButton( WelcomePage::Button::Support, + jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); + m_widget->setupButton( WelcomePage::Button::KnownIssues, + jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); + m_widget->setupButton( WelcomePage::Button::ReleaseNotes, + jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); + m_widget->setupButton( WelcomePage::Button::Donate, CalamaresUtils::getString( configurationMap, "donateUrl" ) ); if ( configurationMap.contains( "requirements" ) && configurationMap.value( "requirements" ).type() == QVariant::Map ) From 706cc7392520f833c077b5a76879b41efecc564c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:07:21 +0200 Subject: [PATCH 7/9] [branding] [welcome] Adjust documentation for welcome-overrides --- src/branding/default/branding.desc | 3 ++- src/modules/welcome/welcome.conf | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 3d1079a8c..5d9b29c69 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -58,7 +58,8 @@ windowSize: 800px,520px # if it contains substitutions, or you'll get YAML exceptions. # # The *Url* entries are used on the welcome page, and they -# are visible as buttons there if the corresponding *show* keys are set. +# are visible as buttons there if the corresponding *show* keys +# are set to "true" (they can also be overridden). strings: productName: "@{NAME}" shortProductName: Generic diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index e8433c48d..f0f9e7394 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -7,7 +7,11 @@ # can check requirements for installation. --- # Display settings for various buttons on the welcome page. -# The URLs themselves come from branding.desc +# The URLs themselves come from branding.desc is the setting +# here is "true". If the setting is false, the button is hidden. +# The setting can also be a full URL which will then be used +# instead of the one from the branding file, or empty or not-set +# which will hide the button. showSupportUrl: true showKnownIssuesUrl: true showReleaseNotesUrl: true From c36f963954d3ad0acf4ff7ddadd9227074aaf579 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:08:33 +0200 Subject: [PATCH 8/9] [welcome] Adjust names of URLs to be consistent - having show*Url and donateUrl seems inconsistent, although the show*Url settings were originally boolean-only. - add "show" to the Donate button setting, to make them all consistent (putting a boolean there will generate a warning and hide the button, that's all). --- src/modules/welcome/WelcomeViewStep.cpp | 2 +- src/modules/welcome/welcome.conf | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index b489adc9e..17a10f754 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -148,7 +148,7 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); m_widget->setupButton( WelcomePage::Button::ReleaseNotes, jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); - m_widget->setupButton( WelcomePage::Button::Donate, CalamaresUtils::getString( configurationMap, "donateUrl" ) ); + m_widget->setupButton( WelcomePage::Button::Donate, CalamaresUtils::getString( configurationMap, "showDonateUrl" ) ); if ( configurationMap.contains( "requirements" ) && configurationMap.value( "requirements" ).type() == QVariant::Map ) diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index f0f9e7394..9488daa5e 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -19,9 +19,10 @@ showReleaseNotesUrl: true # If this Url is set to something non-empty, a "donate" # button is added to the welcome page alongside the # others (see settings, above). Clicking the button opens -# the corresponding link. +# the corresponding link. (This button has no corresponding +# branding.desc string) # -# donateUrl: https://kde.org/community/donations/ +# showDonateUrl: https://kde.org/community/donations/ # Requirements checking. These are general, generic, things # that are checked. They may not match with the actual requirements From 0b7dcf7c50559fb7a29486c2eda0751039a423b1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:22:33 +0200 Subject: [PATCH 9/9] [welcome] Fix up tooltips - the "Select language" tooltip was applied to the form, so it would show up inappropriately all over the place - the buttons didn't have useful tooltips. --- src/modules/welcome/WelcomePage.ui | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index 0787ac6e7..160daa595 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -13,9 +13,6 @@ Form - - Select language - @@ -69,7 +66,7 @@ - Select language + Select application and system language @@ -81,6 +78,9 @@ + + Select application and system language + 2 @@ -136,6 +136,9 @@ + + Open donations website + &Donate @@ -146,6 +149,9 @@ + + Open help and support website + &Support @@ -156,6 +162,9 @@ + + Open issues and bug-tracking website + &Known issues @@ -166,6 +175,9 @@ + + Open relead notes website + &Release notes