source: calamares/trunk/fuentes/src/modules/license/LicensePage.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 8.4 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2015, Anke Boersma <demm@kaosx.us>
4 *   Copyright 2015, Alexandre Arnt <qtgzmanager@gmail.com>
5 *   Copyright 2015, Teo Mrnjavac <teo@kde.org>
6 *
7 *   Calamares is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   Calamares is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "LicensePage.h"
22
23#include "ui_LicensePage.h"
24#include "JobQueue.h"
25#include "GlobalStorage.h"
26#include "utils/Logger.h"
27#include "utils/CalamaresUtilsGui.h"
28#include "utils/Retranslator.h"
29#include "ViewManager.h"
30
31#include <QApplication>
32#include <QBoxLayout>
33#include <QDesktopServices>
34#include <QFocusEvent>
35#include <QLabel>
36#include <QComboBox>
37#include <QMessageBox>
38
39LicensePage::LicensePage(QWidget *parent)
40    : QWidget( parent )
41    , ui( new Ui::LicensePage )
42    , m_isNextEnabled( false )
43{
44    ui->setupUi( this );
45
46    ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() );
47
48    ui->mainText->setAlignment( Qt::AlignCenter );
49    ui->mainText->setWordWrap( true );
50    ui->mainText->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
51
52    ui->additionalText->setWordWrap( true );
53
54    ui->verticalLayout->insertSpacing( 4, CalamaresUtils::defaultFontHeight() / 2 );
55
56    ui->verticalLayout->setContentsMargins( CalamaresUtils::defaultFontHeight(),
57                                            CalamaresUtils::defaultFontHeight() * 3,
58                                            CalamaresUtils::defaultFontHeight(),
59                                            CalamaresUtils::defaultFontHeight() );
60   
61    ui->acceptFrame->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
62    ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
63                                    "background-color: #fff6f6;"
64                                    "border-radius: 4px;"
65                                    "padding: 2px; }" );
66    ui->acceptFrame->layout()->setMargin( CalamaresUtils::defaultFontHeight() / 2 );
67
68    connect( ui->acceptCheckBox, &QCheckBox::toggled,
69             this, [ this ]( bool checked )
70    {
71        Calamares::JobQueue::instance()->globalStorage()->insert( "licenseAgree", checked );
72        m_isNextEnabled = checked;
73        if ( !checked )
74        {
75            ui->acceptFrame->setStyleSheet( "#acceptFrame { border: 1px solid red;"
76                                            "background-color: #fff8f8;"
77                                            "border-radius: 4px;"
78                                            "padding: 2px; }" );
79        }
80        else
81        {
82            ui->acceptFrame->setStyleSheet( "#acceptFrame { padding: 3px }" );
83        }
84        emit nextStatusChanged( checked );
85    } );
86
87    CALAMARES_RETRANSLATE(
88        ui->acceptCheckBox->setText( tr( "I accept the terms and conditions above." ) );
89    );
90
91}
92
93
94void
95LicensePage::setEntries( const QList< LicenseEntry >& entriesList )
96{
97    CalamaresUtils::clearLayout( ui->licenseEntriesLayout );
98
99    bool required = false;
100    for ( const LicenseEntry& entry : entriesList )
101    {
102        if ( entry.required )
103        {
104            required = true;
105            break;
106        }
107    }
108
109    m_isNextEnabled = !required;
110    nextStatusChanged( m_isNextEnabled );
111
112    CALAMARES_RETRANSLATE(
113        if ( required )
114        {
115            ui->mainText->setText( tr( "<h1>License Agreement</h1>"
116                "This setup procedure will install proprietary "
117                "software that is subject to licensing terms." ) );
118            ui->additionalText->setText( tr( "Please review the End User License "
119                "Agreements (EULAs) above.<br/>"
120                "If you do not agree with the terms, the setup procedure cannot continue." ) );
121        }
122        else
123        {
124            ui->mainText->setText( tr( "<h1>License Agreement</h1>"
125                "This setup procedure can install proprietary "
126                "software that is subject to licensing terms "
127                "in order to provide additional features and enhance the user "
128                "experience." ) );
129            ui->additionalText->setText( tr( "Please review the End User License "
130                "Agreements (EULAs) above.<br/>"
131                "If you do not agree with the terms, proprietary software will not "
132                "be installed, and open source alternatives will be used instead." ) );
133        }
134        ui->retranslateUi( this );
135    )
136
137    for ( const LicenseEntry& entry : entriesList )
138    {
139        QWidget* widget = new QWidget( this );
140        QPalette pal( palette() );
141        pal.setColor( QPalette::Background, palette().background().color().lighter( 108 ) );
142        widget->setAutoFillBackground( true );
143        widget->setPalette( pal );
144        widget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
145        widget->setContentsMargins( 4, 4, 4, 4 );
146
147        QHBoxLayout* wiLayout = new QHBoxLayout;
148        widget->setLayout( wiLayout );
149        QLabel* label = new QLabel( widget );
150        label->setWordWrap( true );
151        wiLayout->addWidget( label );
152        label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
153
154        QString productDescription;
155        switch ( entry.type )
156        {
157        case LicenseEntry::Driver:
158            //: %1 is an untranslatable product name, example: Creative Audigy driver
159            productDescription = tr( "<strong>%1 driver</strong><br/>"
160                                     "by %2" )
161                                 .arg( entry.prettyName )
162                                 .arg( entry.prettyVendor );
163            break;
164        case LicenseEntry::GpuDriver:
165            //: %1 is usually a vendor name, example: Nvidia graphics driver
166            productDescription = tr( "<strong>%1 graphics driver</strong><br/>"
167                                     "<font color=\"Grey\">by %2</font>" )
168                                 .arg( entry.prettyName )
169                                 .arg( entry.prettyVendor );
170            break;
171        case LicenseEntry::BrowserPlugin:
172            productDescription = tr( "<strong>%1 browser plugin</strong><br/>"
173                                     "<font color=\"Grey\">by %2</font>" )
174                                 .arg( entry.prettyName )
175                                 .arg( entry.prettyVendor );
176            break;
177        case LicenseEntry::Codec:
178            productDescription = tr( "<strong>%1 codec</strong><br/>"
179                                     "<font color=\"Grey\">by %2</font>" )
180                                 .arg( entry.prettyName )
181                                 .arg( entry.prettyVendor );
182            break;
183        case LicenseEntry::Package:
184            productDescription = tr( "<strong>%1 package</strong><br/>"
185                                     "<font color=\"Grey\">by %2</font>" )
186                                 .arg( entry.prettyName )
187                                 .arg( entry.prettyVendor );
188            break;
189        case LicenseEntry::Software:
190            productDescription = tr( "<strong>%1</strong><br/>"
191                                     "<font color=\"Grey\">by %2</font>" )
192                                 .arg( entry.prettyName )
193                                 .arg( entry.prettyVendor );
194        }
195        label->setText( productDescription );
196
197        QLabel* viewLicenseLabel = new QLabel( widget );
198        wiLayout->addWidget( viewLicenseLabel );
199        viewLicenseLabel->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
200        viewLicenseLabel->setOpenExternalLinks( true );
201        viewLicenseLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
202        viewLicenseLabel->setText( tr( "<a href=\"%1\">view license agreement</a>" )
203                                   .arg( entry.url.toString() ) );
204
205        ui->licenseEntriesLayout->addWidget( widget );
206    }
207    ui->licenseEntriesLayout->addStretch();
208}
209
210
211bool
212LicensePage::isNextEnabled() const
213{
214    return m_isNextEnabled;
215}
Note: See TracBrowser for help on using the repository browser.