calamares/src/modules/welcome/WelcomePage.cpp

276 lines
8.9 KiB
C++
Raw Normal View History

/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2015, Anke Boersma <demm@kaosx.us>
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WelcomePage.h"
#include "checker/CheckerContainer.h"
#include "ui_WelcomePage.h"
#include "Branding.h"
#include "CalamaresVersion.h"
2020-03-25 11:41:39 +01:00
#include "Config.h"
#include "Settings.h"
#include "ViewManager.h"
#include "locale/LabelModel.h"
#include "modulesystem/ModuleManager.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/Retranslator.h"
#include <QApplication>
#include <QBoxLayout>
#include <QComboBox>
#include <QDesktopServices>
#include <QFocusEvent>
#include <QLabel>
2014-11-20 09:40:55 +01:00
#include <QMessageBox>
2020-03-25 11:41:39 +01:00
WelcomePage::WelcomePage( Config* conf, QWidget* parent )
2014-11-20 09:40:55 +01:00
: QWidget( parent )
, ui( new Ui::WelcomePage )
, m_checkingWidget( new CheckerContainer( conf->requirementsModel(), this ) )
, m_languages( nullptr )
, m_conf( conf )
{
connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsComplete,
m_checkingWidget,
&CheckerContainer::requirementsComplete );
connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsProgress,
m_checkingWidget,
&CheckerContainer::requirementsProgress );
2014-11-20 09:40:55 +01:00
ui->setupUi( this );
2017-06-28 08:46:24 +02:00
ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() * 2 );
initLanguages();
ui->mainText->setAlignment( Qt::AlignCenter );
ui->mainText->setWordWrap( true );
ui->mainText->setOpenExternalLinks( true );
cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares()
<< *Calamares::Branding::VersionedName;
CALAMARES_RETRANSLATE_SLOT( &WelcomePage::retranslate )
ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap(
CalamaresUtils::Information,
CalamaresUtils::Original,
2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) );
connect( ui->aboutButton, &QPushButton::clicked, this, &WelcomePage::showAboutBox );
int welcome_text_idx = ui->verticalLayout->indexOf( ui->mainText );
ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget );
}
2020-03-25 11:41:39 +01:00
void
WelcomePage::init()
{
//setup the url buttons
2020-03-25 11:41:39 +01:00
setupButton( WelcomePage::Button::Support, m_conf->supportUrl() );
setupButton( WelcomePage::Button::KnownIssues, m_conf->knownIssuesUrl() );
setupButton( WelcomePage::Button::ReleaseNotes, m_conf->releaseNotesUrl() );
2020-03-25 11:41:39 +01:00
setupButton( WelcomePage::Button::Donate, m_conf->donateUrl() );
//language icon
auto icon = Calamares::Branding::instance()->image( m_conf->languageIcon(), QSize( 48, 48 ) );
if ( !icon.isNull() )
{
setLanguageIcon( icon );
}
}
void
WelcomePage::initLanguages()
{
// Fill the list of translations
ui->languageWidget->clear();
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
ui->languageWidget->setModel( m_conf->languagesModel() );
ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) );
ui->languageWidget->setCurrentIndex( m_conf->localeIndex() );
connect( ui->languageWidget,
2020-03-25 11:41:39 +01:00
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
m_conf,
&Config::setLocaleIndex );
}
void
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() )
{
button->hide();
return;
}
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 ); } );
}
else
{
qWarning() << "Welcome button" << smash( role ) << "URL" << url << "is invalid.";
button->hide();
}
}
void
WelcomePage::focusInEvent( QFocusEvent* e )
{
2014-11-20 09:40:55 +01:00
if ( ui->languageWidget )
{
2014-11-20 09:40:55 +01:00
ui->languageWidget->setFocus();
}
e->accept();
}
bool
WelcomePage::verdict() const
{
return m_checkingWidget->verdict();
}
void
WelcomePage::externallySelectedLanguage( int row )
{
if ( ( row >= 0 ) && ( row < ui->languageWidget->count() ) )
{
ui->languageWidget->setCurrentIndex( row );
}
}
void
WelcomePage::setLanguageIcon( QPixmap i )
{
ui->languageIcon->setPixmap( i );
}
void
WelcomePage::retranslate()
{
QString message;
if ( Calamares::Settings::instance()->isSetupMode() )
{
message = Calamares::Branding::instance()->welcomeStyleCalamares()
? tr( "<h1>Welcome to the Calamares setup program for %1.</h1>" )
: tr( "<h1>Welcome to %1 setup.</h1>" );
}
else
{
message = 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( message.arg( *Calamares::Branding::VersionedName ) );
ui->retranslateUi( this );
ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) );
}
void
WelcomePage::showAboutBox()
{
QString title
= Calamares::Settings::instance()->isSetupMode() ? tr( "About %1 setup" ) : tr( "About %1 installer" );
QMessageBox mb( QMessageBox::Information,
title.arg( CALAMARES_APPLICATION_NAME ),
tr( "<h1>%1</h1><br/>"
"<strong>%2<br/>"
"for %3</strong><br/><br/>"
"Copyright 2014-2017 Teo Mrnjavac &lt;teo@kde.org&gt;<br/>"
"Copyright 2017-2020 Adriaan de Groot &lt;groot@kde.org&gt;<br/>"
"Thanks to <a href=\"https://calamares.io/team/\">the Calamares team</a> "
"and the <a href=\"https://www.transifex.com/calamares/calamares/\">Calamares "
"translators team</a>.<br/><br/>"
"<a href=\"https://calamares.io/\">Calamares</a> "
"development is sponsored by <br/>"
"<a href=\"http://www.blue-systems.com/\">Blue Systems</a> - "
"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< QGridLayout* >( mb.layout() );
if ( layout )
{
layout->setColumnMinimumWidth( 2, CalamaresUtils::defaultFontHeight() * 24 );
}
mb.exec();
}
void
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() );
}