source: calamares/trunk/fuentes/src/modules/users/UsersViewStep.cpp @ 7538

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

sync with github

File size: 5.0 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *   Copyright 2017, Gabriel Craciunescu <crazy@frugalware.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 "UsersViewStep.h"
22
23#include "UsersPage.h"
24
25#include "utils/CalamaresUtils.h"
26#include "utils/Logger.h"
27
28#include "GlobalStorage.h"
29#include "JobQueue.h"
30
31CALAMARES_PLUGIN_FACTORY_DEFINITION( UsersViewStepFactory, registerPlugin<UsersViewStep>(); )
32
33UsersViewStep::UsersViewStep( QObject* parent )
34    : Calamares::ViewStep( parent )
35    , m_widget( new UsersPage() )
36{
37    emit nextStatusChanged( true );
38    connect( m_widget, &UsersPage::checkReady,
39             this, &UsersViewStep::nextStatusChanged );
40}
41
42
43UsersViewStep::~UsersViewStep()
44{
45    if ( m_widget && m_widget->parent() == nullptr )
46        m_widget->deleteLater();
47}
48
49
50QString
51UsersViewStep::prettyName() const
52{
53    return tr( "Users" );
54}
55
56
57QWidget*
58UsersViewStep::widget()
59{
60    return m_widget;
61}
62
63
64void
65UsersViewStep::next()
66{
67    emit done();
68}
69
70
71void
72UsersViewStep::back()
73{}
74
75
76bool
77UsersViewStep::isNextEnabled() const
78{
79    return m_widget->isReady();
80}
81
82
83bool
84UsersViewStep::isBackEnabled() const
85{
86    return true;
87}
88
89
90bool
91UsersViewStep::isAtBeginning() const
92{
93    return true;
94}
95
96
97bool
98UsersViewStep::isAtEnd() const
99{
100    return true;
101}
102
103
104QList< Calamares::job_ptr >
105UsersViewStep::jobs() const
106{
107    return m_jobs;
108}
109
110
111void
112UsersViewStep::onActivate()
113{
114    m_widget->onActivate();
115}
116
117
118void
119UsersViewStep::onLeave()
120{
121    m_jobs.clear();
122
123    m_jobs.append( m_widget->createJobs( m_defaultGroups ) );
124}
125
126
127void
128UsersViewStep::setConfigurationMap( const QVariantMap& configurationMap )
129{
130    if ( configurationMap.contains( "defaultGroups" ) &&
131         configurationMap.value( "defaultGroups" ).type() == QVariant::List )
132    {
133        m_defaultGroups = configurationMap.value( "defaultGroups" ).toStringList();
134    }
135    else
136    {
137        cWarning() << "Using fallback groups. Please check defaultGroups in users.conf";
138        m_defaultGroups = QStringList{ "lp", "video", "network", "storage", "wheel", "audio" };
139    }
140
141    if ( configurationMap.contains( "autologinGroup" ) &&
142         configurationMap.value( "autologinGroup" ).type() == QVariant::String )
143    {
144        Calamares::JobQueue::instance()->globalStorage()->insert( "autologinGroup",
145                        configurationMap.value( "autologinGroup" ).toString() );
146    }
147
148    if ( configurationMap.contains( "sudoersGroup" ) &&
149         configurationMap.value( "sudoersGroup" ).type() == QVariant::String )
150    {
151        Calamares::JobQueue::instance()->globalStorage()->insert( "sudoersGroup",
152                        configurationMap.value( "sudoersGroup" ).toString() );
153    }
154
155    if ( configurationMap.contains( "setRootPassword" ) &&
156         configurationMap.value( "setRootPassword" ).type() == QVariant::Bool )
157    {
158        Calamares::JobQueue::instance()->globalStorage()->insert( "setRootPassword",
159                        configurationMap.value( "setRootPassword" ).toBool() );
160        m_widget->setWriteRootPassword( configurationMap.value( "setRootPassword" ).toBool() );
161    }
162
163    if ( configurationMap.contains( "doAutologin" ) &&
164         configurationMap.value( "doAutologin" ).type() == QVariant::Bool )
165    {
166        m_widget->setAutologinDefault( configurationMap.value( "doAutologin" ).toBool() );
167    }
168
169    if ( configurationMap.contains( "doReusePassword" ) &&
170         configurationMap.value( "doReusePassword" ).type() == QVariant::Bool )
171    {
172        m_widget->setReusePasswordDefault( configurationMap.value( "doReusePassword" ).toBool() );
173    }
174
175    if ( configurationMap.contains( "passwordRequirements" ) &&
176        configurationMap.value( "passwordRequirements" ).type() == QVariant::Map )
177    {
178        auto pr_checks( configurationMap.value( "passwordRequirements" ).toMap() );
179
180        for (decltype(pr_checks)::const_iterator i = pr_checks.constBegin();
181            i != pr_checks.constEnd(); ++i)
182        {
183            m_widget->addPasswordCheck( i.key(), i.value() );
184        }
185    }
186
187    QString shell( QLatin1Literal( "/bin/bash" ) );  // as if it's not set at all
188    if ( configurationMap.contains( "userShell" ) )
189        shell = CalamaresUtils::getString( configurationMap, "userShell" );
190        // Now it might be explicitly set to empty, which is ok
191
192    Calamares::JobQueue::instance()->globalStorage()->insert( "userShell", shell );
193}
194
Note: See TracBrowser for help on using the repository browser.