[tracking] Polish UI some more

- Enable translations, substitute ShortProductName into string,
 - Simplify code for enabling tracking option blocks,
 - Set checkboxes based on configuration,
 - Read checkboxes when leaving page,
 - Don't stretch the tracking option blocks.
This commit is contained in:
Adriaan de Groot 2017-11-08 04:25:36 -05:00
parent 20a2465cc7
commit c7120277ca
6 changed files with 155 additions and 41 deletions

View File

@ -20,6 +20,7 @@
#include "ui_page_trackingstep.h"
#include "Branding.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/Logger.h"
@ -39,32 +40,66 @@ TrackingPage::TrackingPage(QWidget *parent)
: QWidget( parent )
, ui( new Ui::TrackingPage )
{
using StringEntry = Calamares::Branding::StringEntry;
ui->setupUi( this );
CALAMARES_RETRANSLATE(
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->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->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 ) );
)
}
void TrackingPage::showTrackingOption(TrackingType t, bool show)
void TrackingPage::setTrackingOption(TrackingType t, bool setting, bool user)
{
QGroupBox *group = nullptr;
QGroupBox* group = nullptr;
QCheckBox* check = nullptr;
cDebug() << "Showing tracking option" << int(t) << show;
switch ( t )
{
case TrackingType::InstallTracking:
group = ui->installTrackingBox;
check = ui->installCheckBox;
break;
case TrackingType::MachineTracking:
group = ui->machineTrackingBox;
check = ui->machineCheckBox;
break;
case TrackingType::UserTracking:
group = ui->UserTrackingBox;
group = ui->userTrackingBox;
check = ui->userCheckBox;
break;
}
if ( group != nullptr )
if ( show )
if ( (group != nullptr) && (check != nullptr))
{
if ( setting )
group->show();
else
group->hide();
check->setChecked( user );
}
else
cDebug() << " .. unknown option" << int(t);
}
bool TrackingPage::getTrackingOption(TrackingType t)
{
QCheckBox* check = nullptr;
switch ( t )
{
case TrackingType::InstallTracking:
check = ui->installCheckBox;
break;
case TrackingType::MachineTracking:
check = ui->machineCheckBox;
break;
case TrackingType::UserTracking:
check = ui->userCheckBox;
break;
}
return (check != nullptr) && check->isChecked();
}

View File

@ -19,6 +19,8 @@
#ifndef TRACKINGPAGE_H
#define TRACKINGPAGE_H
#include "TrackingType.h"
#include <QWidget>
#include <QUrl>
@ -33,14 +35,16 @@ class TrackingPage : public QWidget
public:
explicit TrackingPage( QWidget* parent = nullptr );
enum class TrackingType
{
InstallTracking,
MachineTracking,
UserTracking
} ;
void showTrackingOption( TrackingType t, bool show );
/**
* Enables or disables the tracking-option block for the given
* tracking option @p t, and sets the initial state of the
* checkbox to the @p user default.
*/
void setTrackingOption( TrackingType t, bool setting, bool user );
/**
* Returns the state of the user checkbox for tracking option @p t.
*/
bool getTrackingOption( TrackingType t );
private:
Ui::TrackingPage* ui;

View File

@ -0,0 +1,29 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, 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/>.
*/
#ifndef TRACKINGTYPE_H
#define TRACKINGTYPE_H
enum class TrackingType
{
InstallTracking,
MachineTracking,
UserTracking
} ;
#endif //TRACKINGTYPE_H

View File

@ -97,6 +97,17 @@ TrackingViewStep::isAtEnd() const
}
void TrackingViewStep::onLeave()
{
cDebug() << "Install tracking:" <<
(tracking( TrackingType::InstallTracking ).userEnabled = m_widget->getTrackingOption( TrackingType::InstallTracking ));
cDebug() << "Machine tracking:" <<
(tracking( TrackingType::MachineTracking ).userEnabled = m_widget->getTrackingOption( TrackingType::MachineTracking ));
cDebug() << " User tracking:" <<
(tracking( TrackingType::UserTracking ).userEnabled = m_widget->getTrackingOption( TrackingType::UserTracking ));
}
QList< Calamares::job_ptr >
TrackingViewStep::jobs() const
{
@ -105,33 +116,35 @@ TrackingViewStep::jobs() const
}
static
bool getTrackingEnabled( const QVariantMap& configurationMap, const QString& key, TrackingEnabled& track )
void TrackingViewStep::setTrackingOption(const QVariantMap& configurationMap, const QString& key, TrackingType t)
{
cDebug() << "Tracking configuration" << key;
// Switch it off by default
track.settingEnabled = false;
track.userEnabled = false;
bool settingEnabled = false;
bool userEnabled = false;
bool success = false;
auto config = CalamaresUtils::getSubMap( configurationMap, key, success );
if ( success )
{
track.settingEnabled = CalamaresUtils::getBool( config, "enabled", false );
track.userEnabled = track.settingEnabled && CalamaresUtils::getBool( config, "default", false );
settingEnabled = CalamaresUtils::getBool( config, "enabled", false );
userEnabled = settingEnabled && CalamaresUtils::getBool( config, "default", false );
}
cDebug() << " .. Install tracking: enabled=" <<track.settingEnabled << "default=" << track.userEnabled;
cDebug() << " .. Install tracking: enabled=" << settingEnabled << "default=" << userEnabled;
return track.settingEnabled;
auto trackingConfiguration = tracking( t );
trackingConfiguration.settingEnabled = settingEnabled;
trackingConfiguration.userEnabled = userEnabled;
m_widget->setTrackingOption(t, settingEnabled, userEnabled);
}
void
TrackingViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
getTrackingEnabled( configurationMap, "install", m_installTracking );
getTrackingEnabled( configurationMap, "machine", m_machineTracking );
getTrackingEnabled( configurationMap, "user", m_userTracking );
setTrackingOption( configurationMap, "install", TrackingType::InstallTracking );
setTrackingOption( configurationMap, "machine", TrackingType::MachineTracking );
setTrackingOption( configurationMap, "user", TrackingType::UserTracking );
}

View File

@ -19,6 +19,8 @@
#ifndef TRACKINGVIEWSTEP_H
#define TRACKINGVIEWSTEP_H
#include "TrackingType.h"
#include <utils/PluginFactory.h>
#include <viewpages/ViewStep.h>
#include <PluginDllMacro.h>
@ -29,12 +31,6 @@
class TrackingPage;
struct TrackingEnabled
{
bool settingEnabled; // Enabled in config file
bool userEnabled; // User checked "yes"
};
class PLUGINDLLEXPORT TrackingViewStep : public Calamares::ViewStep
{
Q_OBJECT
@ -56,14 +52,38 @@ public:
bool isAtBeginning() const override;
bool isAtEnd() const override;
void onLeave() override;
QList< Calamares::job_ptr > jobs() const override;
void setConfigurationMap( const QVariantMap& configurationMap ) override;
private:
void setTrackingOption( const QVariantMap& configurationMap, const QString& key, TrackingType t );
struct TrackingEnabled
{
bool settingEnabled; // Enabled in config file
bool userEnabled; // User checked "yes"
TrackingEnabled()
: settingEnabled( false )
, userEnabled( false )
{}
};
TrackingEnabled m_installTracking, m_machineTracking, m_userTracking;
TrackingPage* m_widget;
TrackingEnabled m_installTracking, m_machineTracking, m_userTracking;
inline TrackingEnabled& tracking( TrackingType t )
{
if (t == TrackingType::UserTracking)
return m_userTracking;
else if (t == TrackingType::MachineTracking)
return m_machineTracking;
else
return m_installTracking;
}
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( TrackingViewStepFactory )

View File

@ -15,7 +15,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<item>
<widget class="QGroupBox" name="installTrackingBox">
<property name="title">
@ -51,7 +51,7 @@
<item>
<widget class="QLabel" name="installExplanation">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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 &lt;span style=&quot; font-weight:600;&quot;&gt;one time only&lt;/span&gt; to our servers. To see what will be sent, click on the help-icon.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Placeholder text</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
@ -78,7 +78,7 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="installCheckBox">
<property name="text">
<string>Enable install-tracking</string>
</property>
@ -124,7 +124,7 @@
<item>
<widget class="QLabel" name="machineExplanation">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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 &lt;span style=&quot; font-weight:600;&quot;&gt;periodically&lt;/span&gt; to our servers. For information about the kind of information being sent, click on the help icon.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Placeholder text</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -145,7 +145,7 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="machineCheckBox">
<property name="text">
<string>Enable machine-tracking</string>
</property>
@ -157,7 +157,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="UserTrackingBox">
<widget class="QGroupBox" name="userTrackingBox">
<property name="title">
<string>User Tracking</string>
</property>
@ -191,7 +191,7 @@
<item>
<widget class="QLabel" name="userExplanation">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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 &lt;span style=&quot; font-weight:600;&quot;&gt;regularly&lt;/span&gt; to our servers. For information about the kind of information being sent and the policies that apply, click on the help icon.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Placeholder text</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -212,7 +212,7 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<widget class="QCheckBox" name="userCheckBox">
<property name="text">
<string>Enable user-tracking</string>
</property>
@ -223,6 +223,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>