[tracking] Switch UI to use radio buttons

Following KDE Pholio M116, switch to using a radio button; instead
of 4 individually toggle-able settings, use a "level" indicator
to select none, install, machine, user .. each of which implies
the previous levels. Each level is individually enable-able from
the distro side.
This commit is contained in:
Adriaan de Groot 2017-11-21 07:51:30 -05:00
parent 188050a77c
commit 93052311aa
7 changed files with 385 additions and 276 deletions

View File

@ -28,13 +28,9 @@
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "ViewManager.h" #include "ViewManager.h"
#include <QApplication> #include <QButtonGroup>
#include <QBoxLayout>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFocusEvent>
#include <QLabel> #include <QLabel>
#include <QComboBox>
#include <QMessageBox>
TrackingPage::TrackingPage(QWidget *parent) TrackingPage::TrackingPage(QWidget *parent)
: QWidget( parent ) : QWidget( parent )
@ -45,41 +41,44 @@ TrackingPage::TrackingPage(QWidget *parent)
ui->setupUi( this ); ui->setupUi( this );
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
ui->retranslateUi( this ); ui->retranslateUi( this );
ui->installExplanation->setText( tr( "Installation tracking helps %1 count how many people use it. If you enable install-tracking, at the end of the installation, information about your hardware will be sent <b>one time only</b> to our servers. To see what will be sent, click on the help-icon." ).arg( *StringEntry::ShortProductName ) ); ui->generalExplanation->setText( tr( "Install tracking helps %1 to see how many users they have, what hardware they install %1 to and (with the last two options below), get continuous information about preferred applications. To see what will be sent, please click the help icon next to each area." ).arg( *StringEntry::ShortProductName ) );
ui->machineExplanation->setText( tr( "Machine tracking helps %1 count how many people use it on an ongoing basis. If you enable machine-tracking, the system will send limited information about your hardware and installed software <b>periodically</b> to our servers. For information about the kind of information being sent, click on the help icon." ).arg( *StringEntry::ShortProductName ) ); ui->installExplanation->setText( tr( "By selecting this you will send information about your installation and hardware. This information will <b>only be sent once</b> after the installation finishes." ) );
ui->userExplanation->setText( tr( "User tracking helps %1 understand how people use the system and the applications. If you enable user-tracking, the system will send information about your use of the installed software <b>regularly</b> to our servers. For information about the kind of information being sent and the policies that apply, click on the help icon." ).arg( *StringEntry::ShortProductName ) ); ui->machineExplanation->setText( tr( "By selecting this you will <b>periodically</b> send information about your installation, hardware and applications, to %1." ).arg( *StringEntry::ShortProductName ) );
ui->userExplanation->setText( tr( "By selecting this you will <b>regularly</b> send information about your installation, hardware, applications and usage patterns, to %1." ).arg( *StringEntry::ShortProductName ) );
) )
QButtonGroup *group = new QButtonGroup( this );
group->setExclusive( true );
group->addButton( ui->noneRadio );
group->addButton( ui->installRadio );
group->addButton( ui->machineRadio );
group->addButton( ui->userRadio );
ui->noneRadio->setChecked( true );
} }
void TrackingPage::setTrackingOption(TrackingType t, bool setting, bool user) void TrackingPage::enableTrackingOption(TrackingType t, bool enabled)
{ {
QGroupBox* group = nullptr; QWidget* group = nullptr;
QCheckBox* check = nullptr;
switch ( t ) switch ( t )
{ {
case TrackingType::InstallTracking: case TrackingType::InstallTracking:
group = ui->installTrackingBox; group = ui->installGroup;
check = ui->installCheckBox;
break; break;
case TrackingType::MachineTracking: case TrackingType::MachineTracking:
group = ui->machineTrackingBox; group = ui->machineGroup;
check = ui->machineCheckBox;
break; break;
case TrackingType::UserTracking: case TrackingType::UserTracking:
group = ui->userTrackingBox; group = ui->userGroup;
check = ui->userCheckBox;
break; break;
} }
if ( (group != nullptr) && (check != nullptr)) if ( group != nullptr )
{ {
if ( setting ) if ( enabled )
group->show(); group->show();
else else
group->hide(); group->hide();
check->setChecked( user );
} }
else else
cDebug() << "WARNING: unknown tracking option" << int(t); cDebug() << "WARNING: unknown tracking option" << int(t);
@ -87,22 +86,22 @@ void TrackingPage::setTrackingOption(TrackingType t, bool setting, bool user)
bool TrackingPage::getTrackingOption(TrackingType t) bool TrackingPage::getTrackingOption(TrackingType t)
{ {
QCheckBox* check = nullptr; bool enabled = false;
// A tracking type is enabled if it is checked, or
// any higher level is checked.
switch ( t ) switch ( t )
{ {
case TrackingType::InstallTracking: case TrackingType::InstallTracking:
check = ui->installCheckBox; enabled |= ui->installRadio->isChecked();
break; // FALLTHRU
case TrackingType::MachineTracking: case TrackingType::MachineTracking:
check = ui->machineCheckBox; enabled |= ui->machineRadio->isChecked();
break; // FALLTHRU
case TrackingType::UserTracking: case TrackingType::UserTracking:
check = ui->userCheckBox; enabled |= ui->userRadio->isChecked();
break;
} }
return enabled;
return (check != nullptr) && check->isChecked();
} }
void TrackingPage::setTrackingPolicy(TrackingType t, QString url) void TrackingPage::setTrackingPolicy(TrackingType t, QString url)
@ -132,3 +131,36 @@ void TrackingPage::setTrackingPolicy(TrackingType t, QString url)
else else
cDebug() << "WARNING: unknown tracking option" << int(t); cDebug() << "WARNING: unknown tracking option" << int(t);
} }
void TrackingPage::setGeneralPolicy( QString url )
{
if ( url.isEmpty() )
ui->generalPolicyLabel->hide();
else
{
ui->generalPolicyLabel->show();
ui->generalPolicyLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui->generalPolicyLabel->show();
connect( ui->generalPolicyLabel, &QLabel::linkActivated, [url]{ QDesktopServices::openUrl( url ); } );
}
}
void TrackingPage::setTrackingLevel(const QString& l)
{
QString level = l.toLower();
QRadioButton* button = nullptr;
if (level.isEmpty() || level == "none")
button = ui->noneRadio;
else if (level == "install")
button = ui->installRadio;
else if (level == "machine")
button = ui->machineRadio;
else if (level == "user")
button = ui->userRadio;
if ( button != nullptr )
button->setChecked( true );
else
cDebug() << "WARNING: unknown default tracking level" << l;
}

View File

@ -39,14 +39,23 @@ public:
* Enables or disables the tracking-option block for the given * Enables or disables the tracking-option block for the given
* tracking option @p t, and sets the initial state of the * tracking option @p t, and sets the initial state of the
* checkbox to the @p user default. * checkbox to the @p user default.
*
* Call this in ascending order of tracking type.
*/ */
void setTrackingOption( TrackingType t, bool setting, bool user ); void enableTrackingOption( TrackingType t, bool enabled );
/** /**
* Returns the state of the user checkbox for tracking option @p t. * Returns whether tracking type @p is selected by the user
* (i.e. is the radio button for that level, or for a higher
* tracking level, enabled).
*/ */
bool getTrackingOption( TrackingType t ); bool getTrackingOption( TrackingType t );
/* URL for given level @p t */
void setTrackingPolicy( TrackingType t, QString url ); void setTrackingPolicy( TrackingType t, QString url );
/* URL for the global link */
void setGeneralPolicy( QString url );
/* Select one of the four levels by name */
void setTrackingLevel( const QString& level );
private: private:
Ui::TrackingPage* ui; Ui::TrackingPage* ui;

View File

@ -102,12 +102,12 @@ TrackingViewStep::isAtEnd() const
void TrackingViewStep::onLeave() void TrackingViewStep::onLeave()
{ {
cDebug() << "Install tracking:" << m_installTracking.userEnabled = m_widget->getTrackingOption( TrackingType::InstallTracking );
(tracking( TrackingType::InstallTracking ).userEnabled = m_widget->getTrackingOption( TrackingType::InstallTracking )); m_machineTracking.userEnabled = m_widget->getTrackingOption( TrackingType::MachineTracking );
cDebug() << "Machine tracking:" << m_userTracking.userEnabled = m_widget->getTrackingOption( TrackingType::UserTracking );
(tracking( TrackingType::MachineTracking ).userEnabled = m_widget->getTrackingOption( TrackingType::MachineTracking )); cDebug() << "Install tracking:" << m_installTracking.enabled();
cDebug() << " User tracking:" << cDebug() << "Machine tracking:" << m_machineTracking.enabled();
(tracking( TrackingType::UserTracking ).userEnabled = m_widget->getTrackingOption( TrackingType::UserTracking )); cDebug() << " User tracking:" << m_userTracking.enabled();
} }
@ -141,10 +141,7 @@ TrackingViewStep::jobs() const
QVariantMap TrackingViewStep::setTrackingOption(const QVariantMap& configurationMap, const QString& key, TrackingType t) QVariantMap TrackingViewStep::setTrackingOption(const QVariantMap& configurationMap, const QString& key, TrackingType t)
{ {
cDebug() << "Tracking configuration" << key;
bool settingEnabled = false; bool settingEnabled = false;
bool userEnabled = false;
bool success = false; bool success = false;
auto config = CalamaresUtils::getSubMap( configurationMap, key, success ); auto config = CalamaresUtils::getSubMap( configurationMap, key, success );
@ -152,15 +149,13 @@ QVariantMap TrackingViewStep::setTrackingOption(const QVariantMap& configuration
if ( success ) if ( success )
{ {
settingEnabled = CalamaresUtils::getBool( config, "enabled", false ); settingEnabled = CalamaresUtils::getBool( config, "enabled", false );
userEnabled = settingEnabled && CalamaresUtils::getBool( config, "default", false );
} }
cDebug() << " .. settable=" << settingEnabled << "default=" << userEnabled;
TrackingEnabled& trackingConfiguration = tracking( t ); TrackingEnabled& trackingConfiguration = tracking( t );
trackingConfiguration.settingEnabled = settingEnabled; trackingConfiguration.settingEnabled = settingEnabled;
trackingConfiguration.userEnabled = userEnabled; trackingConfiguration.userEnabled = false;
m_widget->setTrackingOption(t, settingEnabled, userEnabled); m_widget->enableTrackingOption(t, settingEnabled);
m_widget->setTrackingPolicy(t, CalamaresUtils::getString( config, "policy" ) ); m_widget->setTrackingPolicy(t, CalamaresUtils::getString( config, "policy" ) );
return config; return config;
@ -177,4 +172,7 @@ TrackingViewStep::setConfigurationMap( const QVariantMap& configurationMap )
setTrackingOption( configurationMap, "machine", TrackingType::MachineTracking ); setTrackingOption( configurationMap, "machine", TrackingType::MachineTracking );
setTrackingOption( configurationMap, "user", TrackingType::UserTracking ); setTrackingOption( configurationMap, "user", TrackingType::UserTracking );
m_widget->setGeneralPolicy( CalamaresUtils::getString( configurationMap, "policy" ) );
m_widget->setTrackingLevel( CalamaresUtils::getString( configurationMap, "default" ) );
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

View File

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="tracking"> <qresource prefix="tracking">
<file>none.png</file>
<file>machine.png</file> <file>machine.png</file>
<file>../../../data/images/information.svgz</file> <file>../../../data/images/information.svgz</file>
<file>binoculars.png</file> <file>binoculars.png</file>

View File

@ -13,21 +13,87 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0"> <widget class="QLabel" name="label">
<item> <property name="text">
<widget class="QGroupBox" name="installTrackingBox"> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:16pt;&quot;&gt;Install Tracking&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<property name="title">
<string>Install Tracking</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> </widget>
</item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QLabel" name="generalExplanation">
<property name="text">
<string>Placeholder</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QWidget" name="noneGroup" native="true">
<layout class="QHBoxLayout" name="noneLayout">
<item> <item>
<widget class="QLabel" name="installActionIcon"> <widget class="QRadioButton" name="noneRadio">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="noneIcon">
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="baseSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="page_trackingstep.qrc">:/tracking/none.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="noneExplanation">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;By selecting this, you will send &lt;span style=&quot; font-weight:600;&quot;&gt;no information at all&lt;/span&gt; about your installation.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="installGroup" native="true">
<layout class="QHBoxLayout" name="installLayout">
<item>
<widget class="QRadioButton" name="installRadio">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="installIcon">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>64</width> <width>64</width>
@ -50,11 +116,14 @@
</item> </item>
<item> <item>
<widget class="QLabel" name="installExplanation"> <widget class="QLabel" name="installExplanation">
<property name="text"> <property name="sizePolicy">
<string>Placeholder text</string> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="textFormat"> <property name="text">
<enum>Qt::RichText</enum> <string>TextLabel</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -70,37 +139,23 @@
<iconset resource="page_trackingstep.qrc"> <iconset resource="page_trackingstep.qrc">
<normaloff>:/tracking/data/images/information.svgz</normaloff>:/tracking/data/images/information.svgz</iconset> <normaloff>:/tracking/data/images/information.svgz</normaloff>:/tracking/data/images/information.svgz</iconset>
</property> </property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="installCheckBox"> <widget class="QWidget" name="machineGroup" native="true">
<layout class="QHBoxLayout" name="machineLayout">
<item>
<widget class="QRadioButton" name="machineRadio">
<property name="text"> <property name="text">
<string>Enable install-tracking</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="machineTrackingBox"> <widget class="QLabel" name="machineIcon">
<property name="title">
<string>Machine Tracking</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="machineActionIcon">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>64</width> <width>64</width>
@ -123,8 +178,14 @@
</item> </item>
<item> <item>
<widget class="QLabel" name="machineExplanation"> <widget class="QLabel" name="machineExplanation">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Placeholder text</string> <string>TextLabel</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -143,31 +204,20 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="machineCheckBox"> <widget class="QWidget" name="userGroup" native="true">
<layout class="QHBoxLayout" name="userLayout">
<item>
<widget class="QRadioButton" name="userRadio">
<property name="text"> <property name="text">
<string>Enable machine-tracking</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="userTrackingBox"> <widget class="QLabel" name="userIcon">
<property name="title">
<string>User Tracking</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="userActionIcon">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>64</width> <width>64</width>
@ -190,8 +240,14 @@
</item> </item>
<item> <item>
<widget class="QLabel" name="userExplanation"> <widget class="QLabel" name="userExplanation">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Placeholder text</string> <string>TextLabel</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@ -210,17 +266,22 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
<item>
<widget class="QCheckBox" name="userCheckBox">
<property name="text">
<string>Enable user-tracking</string>
</property>
</widget> </widget>
</item> </item>
</layout> <item>
</item> <widget class="QLabel" name="generalPolicyLabel">
</layout> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;placeholder&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;Click here for more information about Install Tracking&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="openExternalLinks">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -237,8 +298,6 @@
</spacer> </spacer>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget> </widget>
<resources> <resources>
<include location="page_trackingstep.qrc"/> <include location="page_trackingstep.qrc"/>

View File

@ -27,11 +27,9 @@
# with the appropriate framework, and the KDE User Telemetry # with the appropriate framework, and the KDE User Telemetry
# policy applies. # policy applies.
# #
# Each area has a key *enabled*, and a key *default*. If the area # Each area has a key *enabled*. If the area is enabled, it is shown to
# is enabled, it is shown to the user with a checkbox to enable # the user. This defaults to off, which means no tracking would be
# or disable that piece of user-tracking. The default state of that # configured or enabled by Calamares.
# checkbox is set to the value of *default*. Both keys default to
# "off", disabling all tracking-configuration through Calamares.
# #
# Each area has a key *policy*, which is a Url to be opened when # Each area has a key *policy*, which is a Url to be opened when
# the user clicks on the corresponding Help button for an explanation # the user clicks on the corresponding Help button for an explanation
@ -41,7 +39,22 @@
# #
# Each area may have other configuration keys, depending on the # Each area may have other configuration keys, depending on the
# area and how it needs to be configured. # area and how it needs to be configured.
#
# Globally, there are two other keys:
#
# policy: (optional) url about tracking settings for this distro.
# default: (optional) level to enable by default
#
--- ---
# This is the global policy; it is displayed as a link on the page.
# If blank or commented out, no link is displayed on the tracking
# page. It is recommended to either provide policy URLs for each
# area, *or* one general link, and not to mix them.
policy: "https://github.com/calamares/calamares/wiki/Users-Guide#installation-tracking"
# This is the default level to enable for tracking. If commented out,
# empty, or otherwise invalid, "none" is used, so no tracking by default.
default: user
# The install area has one specific configuration key: # The install area has one specific configuration key:
# url: this URL (remember to include the protocol, and prefer https) # url: this URL (remember to include the protocol, and prefer https)
@ -58,7 +71,6 @@
# module then. # module then.
install: install:
enabled: false enabled: false
default: false
policy: "https://github.com/calamares/calamares/wiki/Users-Guide#installation-tracking" policy: "https://github.com/calamares/calamares/wiki/Users-Guide#installation-tracking"
# url: "https://example.com/install.php?c=$CPU&m=$MEMORY" # url: "https://example.com/install.php?c=$CPU&m=$MEMORY"
@ -69,10 +81,8 @@ install:
# system to enable system-tracking. # system to enable system-tracking.
machine: machine:
enabled: false enabled: false
default: false
style: neon style: neon
# The user area is not yet implemented, and has no specific configuration. # The user area is not yet implemented, and has no specific configuration.
user: user:
enabled: false enabled: false
default: false