From 64d4b0a46cbbb6f630cdd348610be7ee5c7d10fd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:43:11 +0200 Subject: [PATCH] [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 );