2019-04-21 12:43:04 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2015, Anke Boersma <demm@kaosx.us>
|
|
|
|
* Copyright 2015, Alexandre Arnt <qtgzmanager@gmail.com>
|
|
|
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
|
|
|
* Copyright 2018, 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 "LicenseWidget.h"
|
2019-04-21 13:36:28 +02:00
|
|
|
|
2019-04-23 14:29:32 +02:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
2019-04-23 10:10:43 +02:00
|
|
|
#include <QDesktopServices>
|
2019-04-23 14:29:32 +02:00
|
|
|
#include <QFile>
|
2019-04-21 13:36:28 +02:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
2019-04-21 20:36:11 +02:00
|
|
|
#include <QToolButton>
|
2019-04-23 14:29:32 +02:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
static QString
|
|
|
|
loadLocalFile( const QUrl& u )
|
|
|
|
{
|
|
|
|
if ( !u.isLocalFile() )
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
QFile file( u.path() );
|
|
|
|
if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
|
|
|
|
{
|
|
|
|
cWarning() << "Could not load license file" << u;
|
|
|
|
return QString();
|
|
|
|
}
|
2019-04-21 13:36:28 +02:00
|
|
|
|
2019-04-23 14:41:05 +02:00
|
|
|
return QString( "\n" ) + file.readAll();
|
2019-04-23 14:29:32 +02:00
|
|
|
}
|
2019-04-21 13:36:28 +02:00
|
|
|
|
|
|
|
LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
, m_entry( std::move( entry ) )
|
2019-04-21 13:50:06 +02:00
|
|
|
, m_label( new QLabel( this ) )
|
|
|
|
, m_viewLicenseLabel( new QLabel( this ) )
|
2019-04-21 20:36:11 +02:00
|
|
|
, m_expandLicenseButton( nullptr )
|
2019-04-23 14:29:32 +02:00
|
|
|
, m_fullText( nullptr )
|
2019-04-21 13:36:28 +02:00
|
|
|
{
|
|
|
|
QPalette pal( palette() );
|
|
|
|
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
|
|
|
|
|
|
|
|
setAutoFillBackground( true );
|
|
|
|
setPalette( pal );
|
|
|
|
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|
|
|
setContentsMargins( 4, 4, 4, 4 );
|
|
|
|
|
|
|
|
QHBoxLayout* wiLayout = new QHBoxLayout;
|
|
|
|
|
2019-04-21 13:50:06 +02:00
|
|
|
m_label->setWordWrap( true );
|
|
|
|
m_label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
|
|
|
wiLayout->addWidget( m_label );
|
|
|
|
|
|
|
|
m_viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
|
|
|
|
m_viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
|
|
|
|
wiLayout->addWidget( m_viewLicenseLabel );
|
|
|
|
|
2019-04-21 20:36:11 +02:00
|
|
|
if ( m_entry.isLocal() )
|
|
|
|
{
|
2019-04-23 14:29:32 +02:00
|
|
|
QVBoxLayout* vLayout = new QVBoxLayout;
|
|
|
|
|
2019-04-21 20:36:11 +02:00
|
|
|
m_expandLicenseButton = new QToolButton( this );
|
2019-04-23 14:29:32 +02:00
|
|
|
m_expandLicenseButton->setArrowType( Qt::UpArrow );
|
2019-04-21 20:36:11 +02:00
|
|
|
wiLayout->addWidget( m_expandLicenseButton );
|
|
|
|
|
|
|
|
connect( m_expandLicenseButton, &QAbstractButton::clicked, this, &LicenseWidget::expandClicked );
|
2019-04-23 14:29:32 +02:00
|
|
|
|
|
|
|
vLayout->addLayout( wiLayout );
|
|
|
|
m_fullText = new QLabel( this );
|
|
|
|
m_fullText->setText( loadLocalFile( m_entry.m_url ) );
|
|
|
|
m_fullText->hide();
|
2019-04-23 14:41:05 +02:00
|
|
|
m_fullText->setStyleSheet( "border-top: 1px solid black; margin-top: 1em; padding-top: 1em;" );
|
2019-04-23 14:29:32 +02:00
|
|
|
|
|
|
|
vLayout->addWidget( m_fullText );
|
|
|
|
setLayout( vLayout );
|
2019-04-21 20:36:11 +02:00
|
|
|
}
|
|
|
|
else
|
2019-04-23 10:10:43 +02:00
|
|
|
{
|
|
|
|
auto* button = new QToolButton( this );
|
|
|
|
button->setArrowType( Qt::RightArrow );
|
|
|
|
wiLayout->addWidget( button );
|
|
|
|
|
|
|
|
connect( button, &QAbstractButton::clicked, this, &LicenseWidget::viewClicked );
|
|
|
|
// Normally setOpenExternalLinks( true ) would do, but we need the
|
|
|
|
// open code anyway for the toolbutton, let's share it.
|
|
|
|
connect( m_viewLicenseLabel, &QLabel::linkActivated, this, &LicenseWidget::viewClicked );
|
2019-04-23 14:29:32 +02:00
|
|
|
|
|
|
|
setLayout( wiLayout ); // Only the horizontal layout needed
|
2019-04-23 10:10:43 +02:00
|
|
|
}
|
2019-04-21 20:36:11 +02:00
|
|
|
|
2019-04-21 13:50:06 +02:00
|
|
|
retranslateUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
LicenseWidget::~LicenseWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LicenseWidget::retranslateUi()
|
|
|
|
{
|
2019-04-21 13:36:28 +02:00
|
|
|
QString productDescription;
|
2019-04-21 13:50:06 +02:00
|
|
|
switch ( m_entry.m_type )
|
2019-04-21 13:36:28 +02:00
|
|
|
{
|
|
|
|
case LicenseEntry::Type::Driver:
|
|
|
|
//: %1 is an untranslatable product name, example: Creative Audigy driver
|
|
|
|
productDescription = tr( "<strong>%1 driver</strong><br/>"
|
|
|
|
"by %2" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_prettyName )
|
|
|
|
.arg( m_entry.m_prettyVendor );
|
2019-04-21 13:36:28 +02:00
|
|
|
break;
|
|
|
|
case LicenseEntry::Type::GpuDriver:
|
|
|
|
//: %1 is usually a vendor name, example: Nvidia graphics driver
|
|
|
|
productDescription = tr( "<strong>%1 graphics driver</strong><br/>"
|
|
|
|
"<font color=\"Grey\">by %2</font>" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_prettyName )
|
|
|
|
.arg( m_entry.m_prettyVendor );
|
2019-04-21 13:36:28 +02:00
|
|
|
break;
|
|
|
|
case LicenseEntry::Type::BrowserPlugin:
|
|
|
|
productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
|
|
|
|
"<font color=\"Grey\">by %2</font>" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_prettyName )
|
|
|
|
.arg( m_entry.m_prettyVendor );
|
2019-04-21 13:36:28 +02:00
|
|
|
break;
|
|
|
|
case LicenseEntry::Type::Codec:
|
|
|
|
productDescription = tr( "<strong>%1 codec</strong><br/>"
|
|
|
|
"<font color=\"Grey\">by %2</font>" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_prettyName )
|
|
|
|
.arg( m_entry.m_prettyVendor );
|
2019-04-21 13:36:28 +02:00
|
|
|
break;
|
|
|
|
case LicenseEntry::Type::Package:
|
|
|
|
productDescription = tr( "<strong>%1 package</strong><br/>"
|
|
|
|
"<font color=\"Grey\">by %2</font>" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_prettyName )
|
|
|
|
.arg( m_entry.m_prettyVendor );
|
2019-04-21 13:36:28 +02:00
|
|
|
break;
|
|
|
|
case LicenseEntry::Type::Software:
|
|
|
|
productDescription = tr( "<strong>%1</strong><br/>"
|
|
|
|
"<font color=\"Grey\">by %2</font>" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_prettyName )
|
|
|
|
.arg( m_entry.m_prettyVendor );
|
2019-04-21 13:36:28 +02:00
|
|
|
}
|
2019-04-21 13:50:06 +02:00
|
|
|
m_label->setText( productDescription );
|
2019-04-21 13:36:28 +02:00
|
|
|
|
2019-04-21 20:36:11 +02:00
|
|
|
if ( m_entry.isLocal() )
|
|
|
|
{
|
|
|
|
m_viewLicenseLabel->setText( tr( "Show license agreement" ) );
|
|
|
|
updateExpandToolTip();
|
|
|
|
}
|
|
|
|
else
|
2019-04-23 10:10:43 +02:00
|
|
|
m_viewLicenseLabel->setText( tr( "<a href=\"%1\">View license agreement</a>" )
|
2019-04-21 13:50:06 +02:00
|
|
|
.arg( m_entry.m_url.toString() ) );
|
2019-04-21 13:36:28 +02:00
|
|
|
}
|
2019-04-21 20:36:11 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
LicenseWidget::expandClicked()
|
|
|
|
{
|
|
|
|
if ( m_expandLicenseButton->arrowType() == Qt::DownArrow )
|
|
|
|
{
|
|
|
|
m_expandLicenseButton->setArrowType( Qt::UpArrow );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_expandLicenseButton->setArrowType( Qt::DownArrow );
|
|
|
|
}
|
2019-04-23 14:29:32 +02:00
|
|
|
|
|
|
|
// Show/hide based on the new arrow direction.
|
|
|
|
if ( m_fullText )
|
|
|
|
m_fullText->setHidden( m_expandLicenseButton->arrowType() == Qt::UpArrow );
|
|
|
|
|
2019-04-21 20:36:11 +02:00
|
|
|
updateExpandToolTip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LicenseWidget::updateExpandToolTip()
|
|
|
|
{
|
|
|
|
if ( !m_expandLicenseButton )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_expandLicenseButton->setToolTip(
|
2019-04-23 14:29:32 +02:00
|
|
|
( m_expandLicenseButton->arrowType() == Qt::UpArrow )
|
2019-04-21 20:36:11 +02:00
|
|
|
? tr( "Show complete license text" )
|
|
|
|
: tr( "Hide license text" )
|
|
|
|
) ;
|
|
|
|
}
|
2019-04-23 10:10:43 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
LicenseWidget::viewClicked()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl( m_entry.m_url );
|
|
|
|
}
|