source: calamares/trunk/fuentes/src/modules/netinstall/NetInstallViewStep.cpp @ 7538

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

sync with github

File size: 4.9 KB
Line 
1/*
2 *   Copyright 2016, Luca Giambonini <almack@chakraos.org>
3 *   Copyright 2016, Lisa Vitolo <shainer@chakraos.org>
4 *   Copyright 2017, Kyle Robbertze  <krobbertze@gmail.com>
5 *   Copyright 2017, Adriaan de Groot <groot@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 "NetInstallViewStep.h"
22
23#include "JobQueue.h"
24#include "GlobalStorage.h"
25
26#include "utils/CalamaresUtils.h"
27#include "utils/Logger.h"
28
29#include "NetInstallPage.h"
30
31CALAMARES_PLUGIN_FACTORY_DEFINITION( NetInstallViewStepFactory, registerPlugin<NetInstallViewStep>(); )
32
33NetInstallViewStep::NetInstallViewStep( QObject* parent )
34    : Calamares::ViewStep( parent )
35    , m_widget( new NetInstallPage() )
36    , m_nextEnabled( false )
37{
38    emit nextStatusChanged( true );
39    connect( m_widget, &NetInstallPage::checkReady,
40             this, &NetInstallViewStep::nextIsReady );
41}
42
43
44NetInstallViewStep::~NetInstallViewStep()
45{
46    if ( m_widget && m_widget->parent() == nullptr )
47        m_widget->deleteLater();
48}
49
50
51QString
52NetInstallViewStep::prettyName() const
53{
54    return tr( "Package selection" );
55}
56
57
58QString
59NetInstallViewStep::prettyStatus() const
60{
61    return m_prettyStatus;
62}
63
64
65QWidget*
66NetInstallViewStep::widget()
67{
68    return m_widget;
69}
70
71
72void
73NetInstallViewStep::next()
74{
75    emit done();
76}
77
78
79void
80NetInstallViewStep::back()
81{}
82
83
84bool
85NetInstallViewStep::isNextEnabled() const
86{
87    return m_nextEnabled;
88}
89
90
91bool
92NetInstallViewStep::isBackEnabled() const
93{
94    return true;
95}
96
97
98bool
99NetInstallViewStep::isAtBeginning() const
100{
101    return true;
102}
103
104
105bool
106NetInstallViewStep::isAtEnd() const
107{
108    return true;
109}
110
111
112QList< Calamares::job_ptr >
113NetInstallViewStep::jobs() const
114{
115    return m_jobs;
116}
117
118
119void
120NetInstallViewStep::onActivate()
121{
122    m_widget->onActivate();
123}
124
125
126void
127NetInstallViewStep::onLeave()
128{
129    cDebug() << "Leaving netinstall, adding packages to be installed"
130             << "to global storage";
131
132    PackageModel::PackageItemDataList packages = m_widget->selectedPackages();
133    QVariantList installPackages;
134    QVariantList tryInstallPackages;
135    QVariantList packageOperations;
136
137    cDebug() << "Processing" << packages.length() << "packages from netinstall.";
138
139    for ( auto package : packages )
140    {
141        QVariant details( package.packageName );
142        // If it's a package with a pre- or post-script, replace
143        // with the more complicated datastructure.
144        if ( !package.preScript.isEmpty() || !package.postScript.isEmpty() )
145        {
146            QMap<QString, QVariant> sdetails;
147            sdetails.insert( "pre-script", package.preScript );
148            sdetails.insert( "package", package.packageName );
149            sdetails.insert( "post-script", package.postScript );
150            details = sdetails;
151        }
152        if ( package.isCritical )
153            installPackages.append( details );
154        else
155            tryInstallPackages.append( details );
156    }
157
158    if ( !installPackages.empty() )
159    {
160        QMap<QString, QVariant> op;
161        op.insert( "install", QVariant( installPackages ) );
162        packageOperations.append( op );
163        cDebug() << "  .." << installPackages.length() << "critical packages.";
164    }
165    if ( !tryInstallPackages.empty() )
166    {
167        QMap<QString, QVariant> op;
168        op.insert( "try_install", QVariant( tryInstallPackages ) );
169        packageOperations.append( op );
170        cDebug() << "  .." << tryInstallPackages.length() << "non-critical packages.";
171    }
172
173    if ( !packageOperations.isEmpty() )
174    {
175        Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
176        gs->insert( "packageOperations", QVariant( packageOperations ) );
177    }
178}
179
180
181void
182NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap )
183{
184    m_widget->setRequired( CalamaresUtils::getBool( configurationMap, "required", false ) );
185
186    QString groupsUrl = CalamaresUtils::getString( configurationMap, "groupsUrl" );
187    if ( !groupsUrl.isEmpty() )
188    {
189        // Keep putting groupsUrl into the global storage,
190        // even though it's no longer used for in-module data-passing.
191        Calamares::JobQueue::instance()->globalStorage()->insert( "groupsUrl", groupsUrl );
192        m_widget->loadGroupList( groupsUrl );
193    }
194}
195
196void
197NetInstallViewStep::nextIsReady( bool b )
198{
199    m_nextEnabled = b;
200    emit nextStatusChanged( b );
201}
Note: See TracBrowser for help on using the repository browser.