diff --git a/src/modules/tracking/Config.cpp b/src/modules/tracking/Config.cpp index 67da7025d..217babba4 100644 --- a/src/modules/tracking/Config.cpp +++ b/src/modules/tracking/Config.cpp @@ -23,22 +23,72 @@ #include -Config::Config( QObject* parent ) +TrackingStyleConfig::TrackingStyleConfig( QObject* parent ) : QObject( parent ) { } +TrackingStyleConfig::~TrackingStyleConfig() { } + void -Config::setConfigurationMap( const QVariantMap& m ) +TrackingStyleConfig::setTracking( bool enabled ) { - m_generalPolicy = CalamaresUtils::getString( m, "policy" ); + setTracking( enabled ? EnabledByUser : DisabledByUser ); +} + +void +TrackingStyleConfig::setTracking( TrackingStyleConfig::TrackingState state ) +{ + if ( m_state != TrackingState::DisabledByConfig ) + { + m_state = state; + } + emit trackingChanged(); +} + +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; + } + + emit policyChanged( m_policy ); + emit trackingChanged(); +} + + +Config::Config( QObject* parent ) + : QObject( parent ) + , m_installTracking( new TrackingStyleConfig( this ) ) +{ +} + +void +Config::setConfigurationMap( const QVariantMap& configurationMap ) +{ + m_generalPolicy = CalamaresUtils::getString( configurationMap, "policy" ); if ( !QUrl( m_generalPolicy ).isValid() ) { m_generalPolicy = QString(); } - emit generalPolicyChanged( m_generalPolicy ); + + bool success = false; + auto subconfig = CalamaresUtils::getSubMap( configurationMap, "install", success ); + if ( success ) + { + m_installTracking->setConfigurationMap( subconfig ); + } } QString diff --git a/src/modules/tracking/Config.h b/src/modules/tracking/Config.h index d0d6f6e0c..80f6d74d1 100644 --- a/src/modules/tracking/Config.h +++ b/src/modules/tracking/Config.h @@ -23,10 +23,77 @@ #include #include +/** @brief Base class for configuring a specific kind of tracking. + * + * All tracking types have a policy URL, which is used to explain what + * kind of tracking is involved, what data is sent, etc. The content + * of that URL is the responsibility of the distro. + * + * A tracking type is disabled by default: if it isn't specifically + * enabled (for configuration) in the config file, it will always be disabled. + * If it is enabled (for configuration) in the config file, it still + * defaults to disabled, but the user can choose to enable it. + */ +class TrackingStyleConfig : public QObject +{ + Q_OBJECT + + Q_PROPERTY( TrackingState trackingStatus READ tracking WRITE setTracking NOTIFY trackingChanged FINAL ) + Q_PROPERTY( bool isEnabled READ isEnabled NOTIFY trackingChanged FINAL ) + Q_PROPERTY( bool isConfigurable READ isConfigurable NOTIFY trackingChanged FINAL ) + Q_PROPERTY( QString policy READ policy NOTIFY policyChanged FINAL ) + +public: + TrackingStyleConfig( QObject* parent ); + virtual ~TrackingStyleConfig(); + + void setConfigurationMap( const QVariantMap& ); + + enum TrackingState + { + DisabledByConfig, + DisabledByUser, + EnabledByUser + }; + Q_ENUM( TrackingState ); + +public Q_SLOTS: + TrackingState tracking() const { return m_state; } + /// @brief Has the user specifically enabled this kind of tracking? + bool isEnabled() const { return m_state == EnabledByUser; } + /// @brief Is this tracking enabled for configuration? + bool isConfigurable() const { return m_state != DisabledByConfig; } + /** @brief Sets the tracking state + * + * Unless the tracking is enabled for configuration, it always + * remains disabled. + */ + void setTracking( TrackingState ); + /** @brief Sets the tracking state + * + * Use @c true for @c EnabledByUser, @c false for DisabledByUser, + * but keep in mind that if the tracking is not enabled for + * configuration, it will always remain disabled. + */ + void setTracking( bool ); + + /// @brief URL for the policy explaining this tracking + QString policy() const { return m_policy; } + +signals: + void trackingChanged(); + void policyChanged( QString ); + +private: + TrackingState m_state = DisabledByConfig; + QString m_policy; // URL +}; + class Config : public QObject { Q_OBJECT Q_PROPERTY( QString generalPolicy READ generalPolicy NOTIFY generalPolicyChanged FINAL ) + Q_PROPERTY( TrackingStyleConfig* installTracking READ installTracking FINAL ) public: Config( QObject* parent = nullptr ); @@ -34,12 +101,15 @@ public: public Q_SLOTS: QString generalPolicy() const; + TrackingStyleConfig* installTracking() const { return m_installTracking; } signals: void generalPolicyChanged( QString ); private: QString m_generalPolicy; + + TrackingStyleConfig* m_installTracking; }; #endif