source: calamares/trunk/fuentes/src/modules/tracking/TrackingPage.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 5.6 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "TrackingPage.h"
20
21#include "ui_page_trackingstep.h"
22
23#include "Branding.h"
24#include "JobQueue.h"
25#include "GlobalStorage.h"
26#include "utils/Logger.h"
27#include "utils/CalamaresUtilsGui.h"
28#include "utils/Retranslator.h"
29#include "ViewManager.h"
30
31#include <QButtonGroup>
32#include <QDesktopServices>
33#include <QLabel>
34
35TrackingPage::TrackingPage(QWidget *parent)
36    : QWidget( parent )
37    , ui( new Ui::TrackingPage )
38{
39    using StringEntry = Calamares::Branding::StringEntry;
40
41    ui->setupUi( this );
42    CALAMARES_RETRANSLATE(
43        ui->retranslateUi( this );
44        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 ) );
45        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." ) );
46        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 ) );
47        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 ) );
48    )
49
50    QButtonGroup *group = new QButtonGroup( this );
51    group->setExclusive( true );
52    group->addButton( ui->noneRadio );
53    group->addButton( ui->installRadio );
54    group->addButton( ui->machineRadio );
55    group->addButton( ui->userRadio );
56    ui->noneRadio->setChecked( true );
57}
58
59void TrackingPage::enableTrackingOption(TrackingType t, bool enabled)
60{
61    QWidget* group = nullptr;
62
63    switch ( t )
64    {
65        case TrackingType::InstallTracking:
66            group = ui->installGroup;
67            break;
68        case TrackingType::MachineTracking:
69            group = ui->machineGroup;
70            break;
71        case TrackingType::UserTracking:
72            group = ui->userGroup;
73            break;
74    }
75
76    if ( group != nullptr )
77    {
78        if ( enabled )
79            group->show();
80        else
81            group->hide();
82    }
83    else
84        cWarning() << "unknown tracking option" << int(t);
85}
86
87bool TrackingPage::getTrackingOption(TrackingType t)
88{
89    bool enabled = false;
90
91    // A tracking type is enabled if it is checked, or
92    // any higher level is checked.
93#define ch(x) ui->x->isChecked()
94    switch ( t )
95    {
96        case TrackingType::InstallTracking:
97            enabled = ch(installRadio) || ch(machineRadio) || ch(userRadio);
98            break;
99        case TrackingType::MachineTracking:
100            enabled = ch(machineRadio) || ch(userRadio);
101            break;
102        case TrackingType::UserTracking:
103            enabled = ch(userRadio);
104            break;
105    }
106#undef ch
107    return enabled;
108}
109
110void TrackingPage::setTrackingPolicy(TrackingType t, QString url)
111{
112    QToolButton *button = nullptr;
113    switch( t )
114    {
115        case TrackingType::InstallTracking:
116            button = ui->installPolicyButton;
117            break;
118        case TrackingType::MachineTracking:
119            button = ui->machinePolicyButton;
120            break;
121        case TrackingType::UserTracking:
122            button = ui->userPolicyButton;
123            break;
124    }
125
126    if ( button != nullptr )
127        if ( url.isEmpty() )
128            button->hide();
129        else
130        {
131            connect( button, &QToolButton::clicked, [url]{ QDesktopServices::openUrl( url ); } );
132            cDebug() << "Tracking policy" << int(t) << "set to" << url;
133        }
134    else
135        cWarning() << "unknown tracking option" << int(t);
136}
137
138void TrackingPage::setGeneralPolicy( QString url )
139{
140    if ( url.isEmpty() )
141        ui->generalPolicyLabel->hide();
142    else
143    {
144        ui->generalPolicyLabel->show();
145        ui->generalPolicyLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
146        ui->generalPolicyLabel->show();
147        connect( ui->generalPolicyLabel, &QLabel::linkActivated, [url]{ QDesktopServices::openUrl( url ); } );
148    }
149}
150
151void TrackingPage::setTrackingLevel(const QString& l)
152{
153    QString level = l.toLower();
154    QRadioButton* button = nullptr;
155
156    if (level.isEmpty() || level == "none")
157        button = ui->noneRadio;
158    else if (level == "install")
159        button = ui->installRadio;
160    else if (level == "machine")
161        button = ui->machineRadio;
162    else if (level == "user")
163        button = ui->userRadio;
164
165    if ( button != nullptr )
166        button->setChecked( true );
167    else
168        cWarning() << "unknown default tracking level" << l;
169}
Note: See TracBrowser for help on using the repository browser.