2020-05-12 14:24:33 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2020, Adriaan de Groot <groot@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 "Config.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
2020-05-12 14:42:04 +02:00
|
|
|
#include <QUrl>
|
|
|
|
|
2020-05-18 16:41:25 +02:00
|
|
|
TrackingStyleConfig::TrackingStyleConfig( QObject* parent )
|
|
|
|
: QObject( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TrackingStyleConfig::~TrackingStyleConfig() { }
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingStyleConfig::setTracking( bool enabled )
|
|
|
|
{
|
|
|
|
setTracking( enabled ? EnabledByUser : DisabledByUser );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TrackingStyleConfig::setTracking( TrackingStyleConfig::TrackingState state )
|
|
|
|
{
|
|
|
|
if ( m_state != TrackingState::DisabledByConfig )
|
|
|
|
{
|
|
|
|
m_state = state;
|
|
|
|
}
|
|
|
|
emit trackingChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-18 17:09:01 +02:00
|
|
|
TrackingStyleConfig::validateUrl( QString& urlString )
|
2020-05-18 16:41:25 +02:00
|
|
|
{
|
2020-05-18 17:09:01 +02:00
|
|
|
if ( !QUrl( urlString ).isValid() )
|
2020-05-18 16:41:25 +02:00
|
|
|
{
|
|
|
|
if ( m_state != DisabledByConfig )
|
|
|
|
{
|
2020-05-18 17:09:01 +02:00
|
|
|
cError() << "URL" << urlString << "is not valid; disabling this tracking type.";
|
|
|
|
m_state = DisabledByConfig;
|
|
|
|
emit trackingChanged();
|
2020-05-18 16:41:25 +02:00
|
|
|
}
|
2020-05-18 17:09:01 +02:00
|
|
|
urlString = QString();
|
2020-05-18 16:41:25 +02:00
|
|
|
}
|
2020-05-18 17:09:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 16:41:25 +02:00
|
|
|
|
2020-05-18 17:09:01 +02:00
|
|
|
void
|
|
|
|
TrackingStyleConfig::setConfigurationMap( const QVariantMap& config )
|
|
|
|
{
|
|
|
|
m_state = CalamaresUtils::getBool( config, "enabled", false ) ? DisabledByUser : DisabledByConfig;
|
|
|
|
m_policy = CalamaresUtils::getString( config, "policy" );
|
|
|
|
validateUrl( m_policy );
|
2020-05-18 16:41:25 +02:00
|
|
|
emit policyChanged( m_policy );
|
|
|
|
emit trackingChanged();
|
|
|
|
}
|
|
|
|
|
2020-05-18 17:09:01 +02:00
|
|
|
InstallTrackingConfig::InstallTrackingConfig( QObject* parent )
|
|
|
|
: TrackingStyleConfig( parent )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InstallTrackingConfig::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
TrackingStyleConfig::setConfigurationMap( configurationMap );
|
|
|
|
|
|
|
|
m_installTrackingUrl = CalamaresUtils::getString( configurationMap, "url" );
|
|
|
|
validateUrl( m_installTrackingUrl );
|
|
|
|
}
|
|
|
|
|
2020-05-18 16:41:25 +02:00
|
|
|
|
2020-05-12 14:24:33 +02:00
|
|
|
Config::Config( QObject* parent )
|
|
|
|
: QObject( parent )
|
2020-05-18 17:09:01 +02:00
|
|
|
, m_installTracking( new InstallTrackingConfig( this ) )
|
2020-05-12 14:24:33 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-05-18 16:41:25 +02:00
|
|
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
2020-05-12 14:24:33 +02:00
|
|
|
{
|
2020-05-18 16:41:25 +02:00
|
|
|
m_generalPolicy = CalamaresUtils::getString( configurationMap, "policy" );
|
2020-05-12 14:42:04 +02:00
|
|
|
|
|
|
|
if ( !QUrl( m_generalPolicy ).isValid() )
|
|
|
|
{
|
|
|
|
m_generalPolicy = QString();
|
|
|
|
}
|
2020-05-12 14:24:33 +02:00
|
|
|
emit generalPolicyChanged( m_generalPolicy );
|
2020-05-18 16:41:25 +02:00
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
auto subconfig = CalamaresUtils::getSubMap( configurationMap, "install", success );
|
|
|
|
if ( success )
|
|
|
|
{
|
|
|
|
m_installTracking->setConfigurationMap( subconfig );
|
|
|
|
}
|
2020-05-12 14:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
Config::generalPolicy() const
|
|
|
|
{
|
|
|
|
return m_generalPolicy;
|
|
|
|
}
|