2017-12-20 14:39:09 +01:00
/* === This file is part of Calamares - <https://github.com/calamares> ===
2017-08-29 14:00:37 +02:00
*
2018-06-15 11:59:11 +02:00
* Copyright 2017 - 2018 , Adriaan de Groot < groot @ kde . org >
2017-08-29 14:00:37 +02:00
*
* 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 "TrackingPage.h"
# include "ui_page_trackingstep.h"
2017-11-08 10:25:36 +01:00
# include "Branding.h"
2017-08-29 14:00:37 +02:00
# include "JobQueue.h"
# include "GlobalStorage.h"
# include "utils/Logger.h"
# include "utils/CalamaresUtilsGui.h"
# include "utils/Retranslator.h"
# include "ViewManager.h"
2017-11-21 13:51:30 +01:00
# include <QButtonGroup>
2017-08-29 14:00:37 +02:00
# include <QDesktopServices>
# include <QLabel>
TrackingPage : : TrackingPage ( QWidget * parent )
: QWidget ( parent )
, ui ( new Ui : : TrackingPage )
{
2017-11-08 10:25:36 +01:00
using StringEntry = Calamares : : Branding : : StringEntry ;
2017-08-29 14:00:37 +02:00
ui - > setupUi ( this ) ;
2017-11-08 10:25:36 +01:00
CALAMARES_RETRANSLATE (
2017-11-08 13:46:33 +01:00
ui - > retranslateUi ( this ) ;
2017-11-21 13:51:30 +01:00
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 - > 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 - > 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 ) ) ;
2017-11-08 10:25:36 +01:00
)
2017-11-21 13:51:30 +01:00
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 ) ;
2017-08-29 14:00:37 +02:00
}
2017-11-21 13:51:30 +01:00
void TrackingPage : : enableTrackingOption ( TrackingType t , bool enabled )
2017-11-06 16:12:41 +01:00
{
2017-11-21 13:51:30 +01:00
QWidget * group = nullptr ;
2017-11-06 16:12:41 +01:00
switch ( t )
{
case TrackingType : : InstallTracking :
2017-11-21 13:51:30 +01:00
group = ui - > installGroup ;
2017-11-06 16:12:41 +01:00
break ;
case TrackingType : : MachineTracking :
2017-11-21 13:51:30 +01:00
group = ui - > machineGroup ;
2017-11-06 16:12:41 +01:00
break ;
case TrackingType : : UserTracking :
2017-11-21 13:51:30 +01:00
group = ui - > userGroup ;
2017-11-06 16:12:41 +01:00
break ;
}
2017-11-21 13:51:30 +01:00
if ( group ! = nullptr )
2017-11-08 10:25:36 +01:00
{
2017-11-21 13:51:30 +01:00
if ( enabled )
2017-11-06 16:12:41 +01:00
group - > show ( ) ;
else
group - > hide ( ) ;
2017-11-08 10:25:36 +01:00
}
2017-11-06 16:12:41 +01:00
else
2018-02-13 11:07:12 +01:00
cWarning ( ) < < " unknown tracking option " < < int ( t ) ;
2017-11-06 16:12:41 +01:00
}
2017-11-08 10:25:36 +01:00
bool TrackingPage : : getTrackingOption ( TrackingType t )
{
2017-11-21 13:51:30 +01:00
bool enabled = false ;
2017-11-08 10:25:36 +01:00
2017-11-21 13:51:30 +01:00
// A tracking type is enabled if it is checked, or
// any higher level is checked.
2018-03-06 16:11:50 +01:00
# define ch(x) ui->x->isChecked()
2017-11-08 10:25:36 +01:00
switch ( t )
{
case TrackingType : : InstallTracking :
2018-03-06 16:11:50 +01:00
enabled = ch ( installRadio ) | | ch ( machineRadio ) | | ch ( userRadio ) ;
break ;
2017-11-08 10:25:36 +01:00
case TrackingType : : MachineTracking :
2018-03-06 16:11:50 +01:00
enabled = ch ( machineRadio ) | | ch ( userRadio ) ;
break ;
2017-11-08 10:25:36 +01:00
case TrackingType : : UserTracking :
2018-03-06 16:11:50 +01:00
enabled = ch ( userRadio ) ;
break ;
2017-11-08 10:25:36 +01:00
}
2018-03-06 16:11:50 +01:00
# undef ch
2017-11-21 13:51:30 +01:00
return enabled ;
2017-11-08 10:25:36 +01:00
}
2017-11-08 13:46:33 +01:00
void TrackingPage : : setTrackingPolicy ( TrackingType t , QString url )
{
QToolButton * button = nullptr ;
switch ( t )
{
case TrackingType : : InstallTracking :
button = ui - > installPolicyButton ;
break ;
case TrackingType : : MachineTracking :
button = ui - > machinePolicyButton ;
break ;
case TrackingType : : UserTracking :
button = ui - > userPolicyButton ;
break ;
}
if ( button ! = nullptr )
if ( url . isEmpty ( ) )
button - > hide ( ) ;
else
{
connect ( button , & QToolButton : : clicked , [ url ] { QDesktopServices : : openUrl ( url ) ; } ) ;
cDebug ( ) < < " Tracking policy " < < int ( t ) < < " set to " < < url ;
}
else
2018-02-13 11:07:12 +01:00
cWarning ( ) < < " unknown tracking option " < < int ( t ) ;
2017-11-08 13:46:33 +01:00
}
2017-11-21 13:51:30 +01:00
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
2018-02-13 11:07:12 +01:00
cWarning ( ) < < " unknown default tracking level " < < l ;
2017-11-21 13:51:30 +01:00
}