New License module, based on KaOS license module.

See README.md for details.
This commit is contained in:
demmm 2015-09-10 12:21:51 -04:00 committed by Teo Mrnjavac
parent 8064736580
commit c1ee36946c
9 changed files with 675 additions and 0 deletions

View File

@ -0,0 +1,21 @@
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
calamares_add_plugin( license
set_source_files_properties( PROPERTIES LANGUAGE CXX )
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules )
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
LicenseViewStep.cpp
LicensePage.cpp
UI
LicensePage.ui
LINK_LIBRARIES
calamaresui
SHARED_LIB
)

View File

@ -0,0 +1,214 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2015, Anke Boersma <demm@kaosx.us>
* Copyright 2015, Alexandre Arnt <qtgzmanager@gmail.com>
* Copyright 2015, Teo Mrnjavac <teo@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 "LicensePage.h"
#include "ui_LicensePage.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/Logger.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Retranslator.h"
#include "ViewManager.h"
#include <QApplication>
#include <QBoxLayout>
#include <QDesktopServices>
#include <QFocusEvent>
#include <QLabel>
#include <QComboBox>
#include <QMessageBox>
LicensePage::LicensePage(QWidget *parent)
: QWidget( parent )
, ui( new Ui::LicensePage )
, m_isNextEnabled( false )
{
ui->setupUi( this );
ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() );
ui->mainText->setAlignment( Qt::AlignCenter );
ui->mainText->setWordWrap( true );
ui->mainText->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
ui->additionalText->setWordWrap( true );
ui->verticalLayout->insertSpacing( 4, CalamaresUtils::defaultFontHeight() / 2 );
ui->verticalLayout->setContentsMargins( CalamaresUtils::defaultFontHeight(),
CalamaresUtils::defaultFontHeight() * 3,
CalamaresUtils::defaultFontHeight(),
CalamaresUtils::defaultFontHeight() );
ui->acceptFrame->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
"background-color: #fff6f6;"
"border-radius: 4px;"
"padding: 2px; }" );
ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
connect( ui->acceptCheckBox, &QCheckBox::toggled,
this, [ this ]( bool checked )
{
Calamares::JobQueue::instance()->globalStorage()->insert( "licenseAgree", checked );
m_isNextEnabled = checked;
if ( !checked )
{
ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
"background-color: #fff8f8;"
"border-radius: 4px;"
"padding: 2px; }" );
}
else
{
ui->acceptFrame->setStyleSheet( "#acceptFrame { padding: 3px }" );
}
emit nextStatusChanged( checked );
} );
CALAMARES_RETRANSLATE(
ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) );
);
}
void
LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
{
CalamaresUtils::clearLayout( ui->licenseEntriesLayout );
bool required = false;
foreach ( const LicenseEntry& entry, entriesList )
{
if ( entry.required )
{
required = true;
break;
}
}
m_isNextEnabled = !required;
nextStatusChanged( m_isNextEnabled );
CALAMARES_RETRANSLATE(
if ( required )
{
ui->mainText->setText( tr( "<h1>License Agreement</h1>"
"This setup procedure will install proprietary "
"software that is subject to licensing terms." ) );
ui->additionalText->setText( tr( "Please review the End User License "
"Agreements (EULAs) above.<br/>"
"If you do not agree with the terms, the setup procedure cannot continue." ) );
}
else
{
ui->mainText->setText( tr( "<h1>License Agreement</h1>"
"This setup procedure can install proprietary "
"software that is subject to licensing terms "
"in order to provide additional features and enhance the user "
"experience." ) );
ui->additionalText->setText( tr( "Please review the End User License "
"Agreements (EULAs) above.<br/>"
"If you do not agree with the terms, proprietary software will not "
"be installed, and open source alternatives will be used instead." ) );
}
ui->retranslateUi( this );
)
foreach ( const LicenseEntry& entry, entriesList )
{
QWidget* widget = new QWidget( this );
QPalette pal( palette() );
pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
widget->setAutoFillBackground( true );
widget->setPalette( pal );
widget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
widget->setContentsMargins( 4, 4, 4, 4 );
QHBoxLayout* wiLayout = new QHBoxLayout;
widget->setLayout( wiLayout );
QLabel* label = new QLabel( widget );
label->setWordWrap( true );
wiLayout->addWidget( label );
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
QString productDescription;
switch ( entry.type )
{
case LicenseEntry::Driver:
//: %1 is an untranslatable product name, example: Creative Audigy driver
productDescription = tr( "<strong>%1 driver</strong><br/>"
"by %2" )
.arg( entry.prettyName )
.arg( entry.prettyVendor );
case LicenseEntry::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>" )
.arg( entry.prettyName )
.arg( entry.prettyVendor );
break;
case LicenseEntry::BrowserPlugin:
productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.prettyName )
.arg( entry.prettyVendor );
break;
case LicenseEntry::Codec:
productDescription = tr( "<strong>%1 codec</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.prettyName )
.arg( entry.prettyVendor );
break;
case LicenseEntry::Package:
productDescription = tr( "<strong>%1 package</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.prettyName )
.arg( entry.prettyVendor );
break;
default:
productDescription = tr( "<strong>%1</strong><br/>"
"<font color=\"Grey\">by %2</font>" )
.arg( entry.prettyName )
.arg( entry.prettyVendor );
}
label->setText( productDescription );
QLabel* viewLicenseLabel = new QLabel( widget );
wiLayout->addWidget( viewLicenseLabel );
viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
viewLicenseLabel->setOpenExternalLinks( true );
viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
.arg( entry.url.toString() ) );
ui->licenseEntriesLayout->addWidget( widget );
}
ui->licenseEntriesLayout->addStretch();
}
bool
LicensePage::isNextEnabled() const
{
return m_isNextEnabled;
}

View File

@ -0,0 +1,70 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2015, Anke Boersma <demm@kaosx.us>
* Copyright 2015, Alexandre Arnt <qtgzmanager@gmail.com>
* Copyright 2015, Teo Mrnjavac <teo@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/>.
*/
#ifndef LICENSEPAGE_H
#define LICENSEPAGE_H
#include <QWidget>
#include <QUrl>
namespace Ui
{
class LicensePage;
}
struct LicenseEntry
{
enum Type : unsigned char
{
Software = 0,
Driver,
GpuDriver,
BrowserPlugin,
Codec,
Package
};
QString id;
QString prettyName;
QString prettyVendor;
Type type;
QUrl url;
bool required;
};
class LicensePage : public QWidget
{
Q_OBJECT
public:
explicit LicensePage( QWidget* parent = nullptr );
void setEntries( const QList< LicenseEntry >& entriesList );
bool isNextEnabled() const;
signals:
void nextStatusChanged( bool status );
private:
Ui::LicensePage* ui;
bool m_isNextEnabled;
};
#endif //LICENSEPAGE_H

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LicensePage</class>
<widget class="QWidget" name="LicensePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>799</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item>
<widget class="QLabel" name="mainText">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="text">
<string notr="true">&lt;Calamares license text&gt;</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="licenseEntriesLayout"/>
</item>
<item>
<widget class="QLabel" name="additionalText">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string notr="true"/>
</property>
<property name="text">
<string notr="true">&lt;additionalText&gt;</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="acceptFrame">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="acceptCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">CheckBox</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,150 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2015, Anke Boersma <demm@kaosx.us>
* Copyright 2015, Teo Mrnjavac <teo@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 "LicenseViewStep.h"
#include "LicensePage.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/Logger.h"
#include <QVariantMap>
LicenseViewStep::LicenseViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new LicensePage )
{
emit nextStatusChanged( false );
connect( m_widget, &LicensePage::nextStatusChanged,
this, &LicenseViewStep::nextStatusChanged );
}
LicenseViewStep::~LicenseViewStep()
{
if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater();
}
QString
LicenseViewStep::prettyName() const
{
return tr( "License" );
}
QWidget*
LicenseViewStep::widget()
{
return m_widget;
}
void
LicenseViewStep::next()
{
emit done();
}
void
LicenseViewStep::back()
{}
bool
LicenseViewStep::isNextEnabled() const
{
return m_widget->isNextEnabled();
}
bool
LicenseViewStep::isBackEnabled() const
{
return true;
}
bool
LicenseViewStep::isAtBeginning() const
{
return true;
}
bool
LicenseViewStep::isAtEnd() const
{
return true;
}
QList< Calamares::job_ptr >
LicenseViewStep::jobs() const
{
return QList< Calamares::job_ptr >();
}
void
LicenseViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
QList< LicenseEntry > entriesList;
if ( configurationMap.contains( "entries" ) &&
configurationMap.value( "entries" ).type() == QVariant::List )
{
foreach ( const QVariant& entryV, configurationMap.value( "entries" ).toList() )
{
if ( !entryV.type() == QVariant::Map )
continue;
QVariantMap entryMap = entryV.toMap();
if ( !entryMap.contains( "id" ) ||
!entryMap.contains( "name" ) ||
!entryMap.contains( "url" ) )
continue;
LicenseEntry entry;
entry.id = entryMap[ "id" ].toString();
entry.prettyName = entryMap[ "name" ].toString();
entry.prettyVendor =entryMap.value( "vendor" ).toString();
entry.url = QUrl( entryMap[ "url" ].toString() );
entry.required = entryMap.value( "required", QVariant( false ) ).toBool();
QString entryType = entryMap.value( "type", "software" ).toString();
if ( entryType == "driver" )
entry.type = LicenseEntry::Driver;
else if ( entryType == "gpudriver" )
entry.type = LicenseEntry::GpuDriver;
else if ( entryType == "browserplugin" )
entry.type = LicenseEntry::BrowserPlugin;
else if ( entryType == "codec" )
entry.type = LicenseEntry::Codec;
else if ( entryType == "package" )
entry.type = LicenseEntry::Package;
else
entry.type = LicenseEntry::Software;
entriesList.append( entry );
}
}
m_widget->setEntries( entriesList );
}

View File

@ -0,0 +1,64 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2015, Anke Boersma <demm@kaosx.us>
*
* 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/>.
*/
#ifndef LICENSEPAGEPLUGIN_H
#define LICENSEPAGEPLUGIN_H
#include <QObject>
#include <QUrl>
#include "viewpages/ViewStep.h"
#include "PluginDllMacro.h"
#include <QVariantMap>
class LicensePage;
class PLUGINDLLEXPORT LicenseViewStep : public Calamares::ViewStep
{
Q_OBJECT
Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" )
Q_INTERFACES( Calamares::ViewStep )
public:
explicit LicenseViewStep( QObject* parent = nullptr );
virtual ~LicenseViewStep();
QString prettyName() const override;
QWidget* widget() override;
void next() override;
void back() override;
bool isNextEnabled() const override;
bool isBackEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
QList< Calamares::job_ptr > jobs() const override;
void setConfigurationMap( const QVariantMap& configurationMap ) override;
private:
LicensePage* m_widget;
};
#endif // LICENSEPAGEPLUGIN_H

View File

@ -0,0 +1,14 @@
### License Approval Module
---------
For distributions shipping proprietary software, this module creates a globalstorage entry when the user declines to accept a presented End User License Agreements file.
The number of licenses shown are configurable. The license.conf has a few examples of how to add URLs.
If you do not want to include this module in your Calamares build, add ```-DSKIP_MODULES="license"```
to your build settings.
How to implement the removal or not installing of proprietary software is up to any distribution to implement. For example, proprietary graphics drivers cannot simply be removed in the packages module, a free version will need to be installed.
An example of where the licenseAgree globalstorage entry is used:
https://github.com/KaOSx/calamares/blob/master/src/modules/nonfree_drivers/main.py
![License Page](http://wstaw.org/m/2015/08/22/Screenshot_20150822_131050.png)

View File

@ -0,0 +1,23 @@
# Configuration file for License viewmodule, Calamares
# Syntax is YAML 1.2
---
# YAML: list of maps.
entries:
- id: nvidia # Entry identifier, must be unique. Not user visible. YAML: string.
name: Nvidia # Pretty name for the software product, user visible and untranslatable. YAML: string.
vendor: Nvidia Corporation # Pretty name for the software vendor, user visible and untranslatable. YAML: string, optional, default is empty.
type: driver # Package type for presentation, not user visible but affects user visible strings. YAML: string, allowed values: driver, gpudriver, browserplugin, codec, package, software; optional, default is software.
url: http://developer.download.nvidia.com/cg/Cg_3.0/license.pdf # Url of license text to display in a web view. YAML: string.
required: false # If set to true, the user cannot proceed without accepting this license. YAML: boolean, optional, default is false.
- id: amd
name: Catalyst
vendor: "Advanced Micro Devices, Inc."
type: gpudriver
url: http://support.amd.com/en-us/download/eula
required: false
- id: flashplugin
name: Adobe Flash
vendor: Adobe Systems Incorporated
type: browserplugin
url: http://www.adobe.com/products/eulas/pdfs/PlatformClients_PC_WWEULA_Combined_20100108_1657.pdf
required: true

View File

@ -0,0 +1,7 @@
# Module metadata file for keyboard viewmodule
# Syntax is YAML 1.2
---
type: "view"
name: "license"
interface: "qtplugin"
load: "libcalamares_viewmodule_license.so"