From f97a0756a9af62ce544475d6631e93de2c9f012a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 May 2020 17:09:01 +0200 Subject: [PATCH] [tracking] Introduce configuration for install-tracking - subclass of TrackingStyleConfig holds the URL that is pinged with information when the installation is done. --- src/modules/tracking/Config.cpp | 43 ++++++++++++++++++++++++--------- src/modules/tracking/Config.h | 18 +++++++++++++- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/modules/tracking/Config.cpp b/src/modules/tracking/Config.cpp index 217babba4..7997556bf 100644 --- a/src/modules/tracking/Config.cpp +++ b/src/modules/tracking/Config.cpp @@ -46,29 +46,50 @@ TrackingStyleConfig::setTracking( TrackingStyleConfig::TrackingState state ) emit trackingChanged(); } +void +TrackingStyleConfig::validateUrl( QString& urlString ) +{ + if ( !QUrl( urlString ).isValid() ) + { + if ( m_state != DisabledByConfig ) + { + cError() << "URL" << urlString << "is not valid; disabling this tracking type."; + m_state = DisabledByConfig; + emit trackingChanged(); + } + urlString = QString(); + } +} + + void TrackingStyleConfig::setConfigurationMap( const QVariantMap& config ) { m_state = CalamaresUtils::getBool( config, "enabled", false ) ? DisabledByUser : DisabledByConfig; m_policy = CalamaresUtils::getString( config, "policy" ); - if ( !QUrl( m_policy ).isValid() ) - { - if ( m_state != DisabledByConfig ) - { - cError() << "Tracking policy URL" << m_policy << "is not valid; disabling this tracking type."; - } - m_policy = QString(); - m_state = DisabledByConfig; - } - + validateUrl( m_policy ); emit policyChanged( m_policy ); emit trackingChanged(); } +InstallTrackingConfig::InstallTrackingConfig( QObject* parent ) + : TrackingStyleConfig( parent ) +{ +} + +void +InstallTrackingConfig::setConfigurationMap( const QVariantMap& configurationMap ) +{ + TrackingStyleConfig::setConfigurationMap( configurationMap ); + + m_installTrackingUrl = CalamaresUtils::getString( configurationMap, "url" ); + validateUrl( m_installTrackingUrl ); +} + Config::Config( QObject* parent ) : QObject( parent ) - , m_installTracking( new TrackingStyleConfig( this ) ) + , m_installTracking( new InstallTrackingConfig( this ) ) { } diff --git a/src/modules/tracking/Config.h b/src/modules/tracking/Config.h index 80f6d74d1..0fbf8495b 100644 --- a/src/modules/tracking/Config.h +++ b/src/modules/tracking/Config.h @@ -84,11 +84,27 @@ signals: void trackingChanged(); void policyChanged( QString ); +protected: + /// @brief Validates the @p urlString, disables tracking if invalid + void validateUrl( QString& urlString ); + private: TrackingState m_state = DisabledByConfig; QString m_policy; // URL }; +class InstallTrackingConfig : public TrackingStyleConfig +{ +public: + InstallTrackingConfig( QObject* parent ); + void setConfigurationMap( const QVariantMap& configurationMap ); + + QString installTrackingUrl() { return m_installTrackingUrl; } + +private: + QString m_installTrackingUrl; +}; + class Config : public QObject { Q_OBJECT @@ -109,7 +125,7 @@ signals: private: QString m_generalPolicy; - TrackingStyleConfig* m_installTracking; + InstallTrackingConfig* m_installTracking; }; #endif