blob: 7c73b26de1c812b1a1e180088be773275650fb14 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// SPDX-License-Identifier: GPL-2.0
#include "qmlprefs.h"
#include "qmlmanager.h"
#include "core/membuffer.h"
#include "core/gpslocation.h"
#include "core/settings/qPrefUnit.h"
/*** Global and constructors ***/
QMLPrefs *QMLPrefs::m_instance = NULL;
QMLPrefs::QMLPrefs() :
m_credentialStatus(qPrefCloudStorage::CS_UNKNOWN),
m_oldStatus(qPrefCloudStorage::CS_UNKNOWN),
m_showPin(false)
{
// This strange construct is needed because QMLEngine calls new and that
// cannot be overwritten
if (!m_instance)
m_instance = this;
}
QMLPrefs::~QMLPrefs()
{
m_instance = NULL;
}
QMLPrefs *QMLPrefs::instance()
{
return m_instance;
}
/*** public functions ***/
const QString QMLPrefs::cloudPin() const
{
return m_cloudPin;
}
void QMLPrefs::setCloudPin(const QString &cloudPin)
{
m_cloudPin = cloudPin;
emit cloudPinChanged();
}
qPrefCloudStorage::cloud_status QMLPrefs::credentialStatus() const
{
return m_credentialStatus;
}
void QMLPrefs::setCredentialStatus(const qPrefCloudStorage::cloud_status value)
{
if (m_credentialStatus != value) {
setOldStatus(m_credentialStatus);
if (value == qPrefCloudStorage::CS_NOCLOUD) {
QMLManager::instance()->appendTextToLog("Switching to no cloud mode");
set_filename(NOCLOUD_LOCALSTORAGE);
clearCredentials();
if (qPrefUnits::unit_system() == "imperial")
prefs.units = IMPERIAL_units;
else if (qPrefUnits::unit_system() == "metric")
prefs.units = SI_units;
}
m_credentialStatus = value;
emit credentialStatusChanged();
}
}
qPrefCloudStorage::cloud_status QMLPrefs::oldStatus() const
{
return m_oldStatus;
}
void QMLPrefs::setOldStatus(const qPrefCloudStorage::cloud_status value)
{
if (m_oldStatus != value) {
m_oldStatus = value;
emit oldStatusChanged();
}
}
bool QMLPrefs::showPin() const
{
return m_showPin;
}
void QMLPrefs::setShowPin(bool enable)
{
m_showPin = enable;
emit showPinChanged();
}
/*** public slot functions ***/
void QMLPrefs::cancelCredentialsPinSetup()
{
/*
* The user selected <cancel> on the final stage of the
* cloud account generation (entering the emailed PIN).
*
* Resets the cloud credential status to CS_UNKNOWN, resulting
* in a return to the first crededentials page, with the
* email and passwd still filled in. In case of a cancel
* of registration (from the PIN page), the email address
* was probably misspelled, so the user never received a PIN to
* complete the process.
*
* Notice that this function is also used to switch to a different
* cloud account, so the name is not perfect.
*/
setCredentialStatus(qPrefCloudStorage::CS_UNKNOWN);
qPrefCloudStorage::set_cloud_verification_status(m_credentialStatus);
QMLManager::instance()->setStartPageText(tr("Starting..."));
setShowPin(false);
}
void QMLPrefs::clearCredentials()
{
qPrefCloudStorage::set_cloud_storage_email(NULL);
qPrefCloudStorage::set_cloud_storage_password(NULL);
setCloudPin(NULL);
}
|