source: calamares/trunk/fuentes/src/modules/tracking/TrackingViewStep.cpp @ 7538

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

sync with github

File size: 5.1 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "JobQueue.h"
20#include "GlobalStorage.h"
21#include "utils/Logger.h"
22#include "utils/CalamaresUtils.h"
23#include "utils/CalamaresUtilsSystem.h"
24
25#include "TrackingJobs.h"
26#include "TrackingPage.h"
27#include "TrackingViewStep.h"
28
29#include <QDesktopServices>
30#include <QVariantMap>
31
32CALAMARES_PLUGIN_FACTORY_DEFINITION( TrackingViewStepFactory, registerPlugin<TrackingViewStep>(); )
33
34/** @brief Is @p s a valid machine-tracking style. */
35static bool isValidStyle( const QString& s )
36{
37    static QStringList knownStyles { "neon" };
38    return knownStyles.contains( s );
39}
40
41TrackingViewStep::TrackingViewStep( QObject* parent )
42    : Calamares::ViewStep( parent )
43    , m_widget( new TrackingPage )
44{
45    emit nextStatusChanged( false );
46}
47
48
49TrackingViewStep::~TrackingViewStep()
50{
51    if ( m_widget && m_widget->parent() == nullptr )
52        m_widget->deleteLater();
53}
54
55
56QString
57TrackingViewStep::prettyName() const
58{
59    return tr( "Feedback" );
60}
61
62
63QWidget*
64TrackingViewStep::widget()
65{
66    return m_widget;
67}
68
69
70void
71TrackingViewStep::next()
72{
73    emit done();
74}
75
76
77void
78TrackingViewStep::back()
79{}
80
81
82bool
83TrackingViewStep::isNextEnabled() const
84{
85    return true;
86}
87
88
89bool
90TrackingViewStep::isBackEnabled() const
91{
92    return true;
93}
94
95
96bool
97TrackingViewStep::isAtBeginning() const
98{
99    return true;
100}
101
102
103bool
104TrackingViewStep::isAtEnd() const
105{
106    return true;
107}
108
109
110void TrackingViewStep::onLeave()
111{
112    m_installTracking.userEnabled =  m_widget->getTrackingOption( TrackingType::InstallTracking );
113    m_machineTracking.userEnabled =  m_widget->getTrackingOption( TrackingType::MachineTracking );
114    m_userTracking.userEnabled =  m_widget->getTrackingOption( TrackingType::UserTracking );
115    cDebug() << "Install tracking:" << m_installTracking.enabled();
116    cDebug() << "Machine tracking:" << m_machineTracking.enabled();
117    cDebug() << "   User tracking:" << m_userTracking.enabled();
118}
119
120
121Calamares::JobList
122TrackingViewStep::jobs() const
123{
124    Calamares::JobList l;
125
126    cDebug() << "Creating tracking jobs ..";
127    if ( m_installTracking.enabled() && !m_installTrackingUrl.isEmpty() )
128    {
129        QString installUrl = m_installTrackingUrl;
130        const auto s = CalamaresUtils::System::instance();
131
132        QString memory, disk;
133        memory.setNum( s->getTotalMemoryB().first );
134        disk.setNum( s->getTotalDiskB() );
135
136        installUrl
137            .replace( "$CPU", s->getCpuDescription() )
138            .replace( "$MEMORY",  memory )
139            .replace( "$DISK", disk );
140
141        cDebug() << "  .. install-tracking URL" << installUrl;
142
143        l.append( Calamares::job_ptr( new TrackingInstallJob( installUrl ) ) );
144    }
145
146    if ( m_machineTracking.enabled() && !m_machineTrackingStyle.isEmpty() )
147    {
148        Q_ASSERT( isValidStyle( m_machineTrackingStyle ) );
149        if ( m_machineTrackingStyle == "neon" )
150            l.append( Calamares::job_ptr( new TrackingMachineNeonJob() ) );
151    }
152    return l;
153}
154
155
156QVariantMap TrackingViewStep::setTrackingOption(const QVariantMap& configurationMap, const QString& key, TrackingType t)
157{
158    bool settingEnabled = false;
159
160    bool success = false;
161    auto config = CalamaresUtils::getSubMap( configurationMap, key, success );
162
163    if ( success )
164    {
165        settingEnabled = CalamaresUtils::getBool( config, "enabled", false );
166    }
167
168    TrackingEnabled& trackingConfiguration = tracking( t );
169    trackingConfiguration.settingEnabled = settingEnabled;
170    trackingConfiguration.userEnabled = false;
171
172    m_widget->enableTrackingOption(t, settingEnabled);
173    m_widget->setTrackingPolicy(t, CalamaresUtils::getString( config, "policy" ) );
174
175    return config;
176}
177
178void
179TrackingViewStep::setConfigurationMap( const QVariantMap& configurationMap )
180{
181    QVariantMap config;
182
183    config = setTrackingOption( configurationMap, "install", TrackingType::InstallTracking );
184    m_installTrackingUrl = CalamaresUtils::getString( config, "url" );
185
186    config = setTrackingOption( configurationMap, "machine", TrackingType::MachineTracking );
187    auto s = CalamaresUtils::getString( config, "style" );
188    if ( isValidStyle( s ) )
189        m_machineTrackingStyle = s;
190
191    setTrackingOption( configurationMap, "user", TrackingType::UserTracking );
192
193    m_widget->setGeneralPolicy( CalamaresUtils::getString( configurationMap, "policy" ) );
194    m_widget->setTrackingLevel( CalamaresUtils::getString( configurationMap, "default" ) );
195}
Note: See TracBrowser for help on using the repository browser.