Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit d43924e

Browse files
committed
[LocationSettings] Allow Yandex Locator services. Fixes JB#47250
1 parent 6014bfe commit d43924e

File tree

3 files changed

+139
-18
lines changed

3 files changed

+139
-18
lines changed

src/locationsettings.cpp

Lines changed: 124 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ namespace {
6666
const QString LocationSettingsHereEnabledKey = QStringLiteral("here\\enabled");
6767
const QString LocationSettingsHereAgreementAcceptedKey = QStringLiteral("here\\agreement_accepted");
6868
const QString LocationSettingsHereOnlineEnabledKey = QStringLiteral("here\\online_enabled");
69+
const QString LocationSettingsYandexLocatorEnabledKey = QStringLiteral("yandex\\enabled");
70+
const QString LocationSettingsYandexLocatorAgreementAcceptedKey = QStringLiteral("yandex\\agreement_accepted");
71+
const QString LocationSettingsYandexLocatorOnlineEnabledKey = QStringLiteral("yandex\\online_enabled");
6972
const QMap<LocationSettings::DataSource, QString> AllowedDataSourcesKeys {
7073
{ LocationSettings::OnlineDataSources, QStringLiteral("allowed_data_sources\\online") },
7174
{ LocationSettings::DeviceSensorsData, QStringLiteral("allowed_data_sources\\device_sensors") },
@@ -180,7 +183,9 @@ LocationSettingsPrivate::LocationSettingsPrivate(LocationSettings::Mode mode, Lo
180183
, m_locationEnabled(false)
181184
, m_gpsEnabled(false)
182185
, m_mlsEnabled(true)
186+
, m_yandexLocatorEnabled(true)
183187
, m_mlsOnlineState(LocationSettings::OnlineAGpsAgreementNotAccepted)
188+
, m_yandexLocatorOnlineState(LocationSettings::OnlineAGpsAgreementNotAccepted)
184189
, m_hereState(LocationSettings::OnlineAGpsAgreementNotAccepted)
185190
, m_locationMode(LocationSettings::CustomMode)
186191
, m_settingLocationMode(true)
@@ -201,6 +206,10 @@ LocationSettingsPrivate::LocationSettingsPrivate(LocationSettings::Mode mode, Lo
201206
this, &LocationSettingsPrivate::recalculateLocationMode);
202207
connect(q, &LocationSettings::mlsOnlineStateChanged,
203208
this, &LocationSettingsPrivate::recalculateLocationMode);
209+
connect(q, &LocationSettings::yandexLocatorEnabledChanged,
210+
this, &LocationSettingsPrivate::recalculateLocationMode);
211+
connect(q, &LocationSettings::yandexLocatorOnlineStateChanged,
212+
this, &LocationSettingsPrivate::recalculateLocationMode);
204213
connect(q, &LocationSettings::hereStateChanged,
205214
this, &LocationSettingsPrivate::recalculateLocationMode);
206215

@@ -271,25 +280,28 @@ void LocationSettingsPrivate::findGpsTech()
271280
LocationSettings::LocationMode
272281
LocationSettingsPrivate::calculateLocationMode() const
273282
{
283+
bool nls = m_mlsEnabled || m_yandexLocatorEnabled;
284+
bool nls_available = mlsAvailable() || yandexLocatorAvailable();
285+
274286
if (m_gpsEnabled
275-
&& (!mlsAvailable() ||
276-
(m_mlsEnabled && m_mlsOnlineState == LocationSettings::OnlineAGpsEnabled))
287+
&& (!nls_available ||
288+
(nls && (m_mlsOnlineState == LocationSettings::OnlineAGpsEnabled || m_yandexLocatorOnlineState == LocationSettings::OnlineAGpsEnabled)))
277289
&& (!hereAvailable() || m_hereState == LocationSettings::OnlineAGpsEnabled)) {
278290
return LocationSettings::HighAccuracyMode;
279291
} else if (!m_gpsEnabled
280-
&& (!mlsAvailable() ||
281-
(m_mlsEnabled &&
282-
(m_mlsOnlineState == LocationSettings::OnlineAGpsEnabled
283-
|| m_mlsOnlineState == LocationSettings::OnlineAGpsAgreementNotAccepted)))
292+
&& (!nls_available ||
293+
(nls &&
294+
((m_mlsOnlineState == LocationSettings::OnlineAGpsEnabled || m_yandexLocatorOnlineState == LocationSettings::OnlineAGpsEnabled )
295+
|| (m_mlsOnlineState == LocationSettings::OnlineAGpsAgreementNotAccepted || m_yandexLocatorOnlineState == LocationSettings::OnlineAGpsAgreementNotAccepted))))
284296
&& (!hereAvailable() ||
285297
(m_hereState == LocationSettings::OnlineAGpsEnabled
286298
|| m_hereState == LocationSettings::OnlineAGpsAgreementNotAccepted))) {
287299
return LocationSettings::BatterySavingMode;
288300
} else if (m_gpsEnabled
289-
&& (!mlsAvailable() ||
290-
(m_mlsEnabled &&
291-
(m_mlsOnlineState == LocationSettings::OnlineAGpsDisabled
292-
|| m_mlsOnlineState == LocationSettings::OnlineAGpsAgreementNotAccepted)))
301+
&& (!nls_available ||
302+
(nls &&
303+
((m_mlsOnlineState == LocationSettings::OnlineAGpsDisabled || m_yandexLocatorOnlineState == LocationSettings::OnlineAGpsDisabled)
304+
||(m_mlsOnlineState == LocationSettings::OnlineAGpsAgreementNotAccepted || m_yandexLocatorOnlineState == LocationSettings::OnlineAGpsAgreementNotAccepted))))
293305
&& (!hereAvailable() ||
294306
(m_hereState == LocationSettings::OnlineAGpsDisabled
295307
|| m_hereState == LocationSettings::OnlineAGpsAgreementNotAccepted))) {
@@ -315,6 +327,11 @@ bool LocationSettingsPrivate::mlsAvailable() const
315327
return QFile::exists(QStringLiteral("/usr/libexec/geoclue-mlsdb"));
316328
}
317329

330+
bool LocationSettingsPrivate::yandexLocatorAvailable() const
331+
{
332+
return QFile::exists(QStringLiteral("/usr/libexec/geoclue-yandex"));
333+
}
334+
318335
bool LocationSettingsPrivate::hereAvailable() const
319336
{
320337
return QFile::exists(QStringLiteral("/usr/libexec/geoclue-here"));
@@ -409,6 +426,8 @@ bool LocationSettings::gpsAvailable() const
409426
return QFile::exists(QStringLiteral("/usr/libexec/geoclue-hybris"));
410427
}
411428

429+
/*Mozilla Location services*/
430+
412431
bool LocationSettings::mlsEnabled() const
413432
{
414433
Q_D(const LocationSettings);
@@ -448,6 +467,48 @@ bool LocationSettings::mlsAvailable() const
448467
return d->mlsAvailable();
449468
}
450469

470+
/*Yandex locator services*/
471+
472+
bool LocationSettings::yandexLocatorEnabled() const
473+
{
474+
Q_D(const LocationSettings);
475+
return d->m_yandexLocatorEnabled;
476+
}
477+
478+
void LocationSettings::setYandexLocatorEnabled(bool enabled)
479+
{
480+
Q_D(LocationSettings);
481+
if (enabled != d->m_yandexLocatorEnabled) {
482+
d->m_yandexLocatorEnabled = enabled;
483+
d->writeSettings();
484+
emit yandexLocatorEnabledChanged();
485+
}
486+
}
487+
488+
LocationSettings::OnlineAGpsState LocationSettings::yandexLocatorOnlineState() const
489+
{
490+
Q_D(const LocationSettings);
491+
return d->m_yandexLocatorOnlineState;
492+
}
493+
494+
void LocationSettings::setYandexLocatorOnlineState(LocationSettings::OnlineAGpsState state)
495+
{
496+
Q_D(LocationSettings);
497+
if (state == d->m_yandexLocatorOnlineState)
498+
return;
499+
500+
d->m_yandexLocatorOnlineState = state;
501+
d->writeSettings();
502+
emit yandexLocatorOnlineStateChanged();
503+
}
504+
505+
bool LocationSettings::yandexLocatorAvailable() const
506+
{
507+
Q_D(const LocationSettings);
508+
return d->yandexLocatorAvailable();
509+
}
510+
511+
/*HERE*/
451512
LocationSettings::OnlineAGpsState LocationSettings::hereState() const
452513
{
453514
Q_D(const LocationSettings);
@@ -498,6 +559,12 @@ void LocationSettings::setLocationMode(LocationMode locationMode)
498559
setMlsOnlineState(LocationSettings::OnlineAGpsEnabled);
499560
}
500561
}
562+
if (yandexLocatorAvailable()) {
563+
setYandexLocatorEnabled(true);
564+
if (yandexLocatorOnlineState() != LocationSettings::OnlineAGpsAgreementNotAccepted) {
565+
setYandexLocatorOnlineState(LocationSettings::OnlineAGpsEnabled);
566+
}
567+
}
501568
if (hereAvailable()) {
502569
if (hereState() != LocationSettings::OnlineAGpsAgreementNotAccepted) {
503570
setHereState(LocationSettings::OnlineAGpsEnabled);
@@ -511,6 +578,12 @@ void LocationSettings::setLocationMode(LocationMode locationMode)
511578
setMlsOnlineState(LocationSettings::OnlineAGpsEnabled);
512579
}
513580
}
581+
if (yandexLocatorAvailable()) {
582+
setYandexLocatorEnabled(true);
583+
if (yandexLocatorOnlineState() != LocationSettings::OnlineAGpsAgreementNotAccepted) {
584+
setYandexLocatorOnlineState(LocationSettings::OnlineAGpsEnabled);
585+
}
586+
}
514587
if (hereAvailable()) {
515588
if (hereState() != LocationSettings::OnlineAGpsAgreementNotAccepted) {
516589
setHereState(LocationSettings::OnlineAGpsEnabled);
@@ -524,6 +597,12 @@ void LocationSettings::setLocationMode(LocationMode locationMode)
524597
setMlsOnlineState(LocationSettings::OnlineAGpsDisabled);
525598
}
526599
}
600+
if (yandexLocatorAvailable()) {
601+
setYandexLocatorEnabled(true);
602+
if (yandexLocatorOnlineState() != LocationSettings::OnlineAGpsAgreementNotAccepted) {
603+
setYandexLocatorOnlineState(LocationSettings::OnlineAGpsDisabled);
604+
}
605+
}
527606
if (hereAvailable()) {
528607
if (hereState() != LocationSettings::OnlineAGpsAgreementNotAccepted) {
529608
setHereState(LocationSettings::OnlineAGpsDisabled);
@@ -561,6 +640,7 @@ void LocationSettingsPrivate::readSettings()
561640
bool oldMlsEnabled = false;
562641
bool oldHereEnabled = false;
563642
bool oldHereAgreementAccepted = false;
643+
bool oldYandexLocatorEnabled = false;
564644

565645
// current key values
566646
bool locationEnabled = false;
@@ -569,6 +649,10 @@ void LocationSettingsPrivate::readSettings()
569649
bool mlsEnabled = false;
570650
bool mlsAgreementAccepted = false;
571651
bool mlsOnlineEnabled = false;
652+
bool yandexLocatorEnabled = false;
653+
bool yandexLocatorAgreementAccepted = false;
654+
bool yandexLocatorOnlineEnabled = false;
655+
572656
bool hereEnabled = false;
573657
bool hereAgreementAccepted = false;
574658

@@ -595,6 +679,9 @@ void LocationSettingsPrivate::readSettings()
595679
ini.readBool(LocationSettingsSection, LocationSettingsMlsEnabledKey, &mlsEnabled, oldMlsEnabled);
596680
ini.readBool(LocationSettingsSection, LocationSettingsMlsAgreementAcceptedKey, &mlsAgreementAccepted);
597681
ini.readBool(LocationSettingsSection, LocationSettingsMlsOnlineEnabledKey, &mlsOnlineEnabled);
682+
ini.readBool(LocationSettingsSection, LocationSettingsYandexLocatorEnabledKey, &yandexLocatorEnabled, oldYandexLocatorEnabled);
683+
ini.readBool(LocationSettingsSection, LocationSettingsYandexLocatorAgreementAcceptedKey, &yandexLocatorAgreementAccepted);
684+
ini.readBool(LocationSettingsSection, LocationSettingsYandexLocatorOnlineEnabledKey, &yandexLocatorOnlineEnabled);
598685
ini.readBool(LocationSettingsSection, LocationSettingsHereEnabledKey, &hereEnabled, oldHereEnabled);
599686
ini.readBool(LocationSettingsSection, LocationSettingsHereAgreementAcceptedKey, &hereAgreementAccepted, oldHereAgreementAccepted);
600687

@@ -639,6 +726,11 @@ void LocationSettingsPrivate::readSettings()
639726
emit q->mlsEnabledChanged();
640727
}
641728

729+
if (m_yandexLocatorEnabled != yandexLocatorEnabled) {
730+
m_yandexLocatorEnabled = yandexLocatorEnabled;
731+
emit q->yandexLocatorEnabledChanged();
732+
}
733+
642734
LocationSettings::OnlineAGpsState mlsOnlineState = mlsAgreementAccepted
643735
? ((mlsOnlineEnabled && m_mlsEnabled) ? LocationSettings::OnlineAGpsEnabled : LocationSettings::OnlineAGpsDisabled)
644736
: LocationSettings::OnlineAGpsAgreementNotAccepted;
@@ -647,6 +739,14 @@ void LocationSettingsPrivate::readSettings()
647739
emit q->mlsOnlineStateChanged();
648740
}
649741

742+
LocationSettings::OnlineAGpsState yandexLocatorOnlineState = yandexLocatorAgreementAccepted
743+
? ((yandexLocatorOnlineEnabled && m_yandexLocatorEnabled) ? LocationSettings::OnlineAGpsEnabled : LocationSettings::OnlineAGpsDisabled)
744+
: LocationSettings::OnlineAGpsAgreementNotAccepted;
745+
if (m_yandexLocatorOnlineState != yandexLocatorOnlineState) {
746+
m_yandexLocatorOnlineState = yandexLocatorOnlineState;
747+
emit q->yandexLocatorOnlineStateChanged();
748+
}
749+
650750
if ((m_locationMode == LocationSettings::CustomMode) != customMode) {
651751
if (customMode) {
652752
m_locationMode = LocationSettings::CustomMode;
@@ -671,13 +771,16 @@ void LocationSettingsPrivate::writeSettings()
671771
}
672772

673773
// set the available location providers value based upon the enabled providers
674-
QString agps_providers;
675-
if (m_mlsEnabled && m_hereState == LocationSettings::OnlineAGpsEnabled) {
676-
agps_providers = QStringLiteral("\"mls,here\"");
677-
} else if (m_mlsEnabled) {
678-
agps_providers = QStringLiteral("\"mls\"");
679-
} else if (m_hereState == LocationSettings::OnlineAGpsEnabled) {
680-
agps_providers = QStringLiteral("\"here\"");
774+
QStringList agps_providers;
775+
776+
if (m_mlsEnabled) {
777+
agps_providers.append("mls");
778+
}
779+
if (m_hereState == LocationSettings::OnlineAGpsEnabled) {
780+
agps_providers.append("here");
781+
}
782+
if (m_yandexLocatorEnabled) {
783+
agps_providers.append("yandex");
681784
}
682785

683786
// write the values to the conf file
@@ -696,12 +799,15 @@ void LocationSettingsPrivate::writeSettings()
696799
ini.writeBool(LocationSettingsSection, LocationSettingsMlsEnabledKey, m_mlsEnabled);
697800
ini.writeBool(LocationSettingsSection, LocationSettingsMlsAgreementAcceptedKey, m_mlsOnlineState != LocationSettings::OnlineAGpsAgreementNotAccepted);
698801
ini.writeBool(LocationSettingsSection, LocationSettingsMlsOnlineEnabledKey, m_mlsOnlineState == LocationSettings::OnlineAGpsEnabled);
802+
ini.writeBool(LocationSettingsSection, LocationSettingsYandexLocatorEnabledKey, m_yandexLocatorEnabled);
803+
ini.writeBool(LocationSettingsSection, LocationSettingsYandexLocatorAgreementAcceptedKey, m_yandexLocatorOnlineState != LocationSettings::OnlineAGpsAgreementNotAccepted);
804+
ini.writeBool(LocationSettingsSection, LocationSettingsYandexLocatorOnlineEnabledKey, m_yandexLocatorOnlineState == LocationSettings::OnlineAGpsEnabled);
699805
ini.writeBool(LocationSettingsSection, LocationSettingsHereEnabledKey, m_hereState == LocationSettings::OnlineAGpsEnabled);
700806
ini.writeBool(LocationSettingsSection, LocationSettingsHereAgreementAcceptedKey, m_hereState != LocationSettings::OnlineAGpsAgreementNotAccepted);
701807
ini.writeBool(LocationSettingsSection, LocationSettingsHereOnlineEnabledKey, m_hereState == LocationSettings::OnlineAGpsEnabled);
702808

703809
// write the available location providers based on the enabled plugins
704-
ini.writeString(LocationSettingsSection, LocationSettingsAgpsProvidersKey, agps_providers);
810+
ini.writeString(LocationSettingsSection, LocationSettingsAgpsProvidersKey, "\""+agps_providers.join(",")+"\"");
705811

706812
// write the MDM allowed allowed data source keys
707813
for (QMap<LocationSettings::DataSource, QString>::const_iterator

src/locationsettings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
5858
Q_PROPERTY(OnlineAGpsState mlsOnlineState READ mlsOnlineState WRITE setMlsOnlineState NOTIFY mlsOnlineStateChanged)
5959
Q_PROPERTY(bool mlsAvailable READ mlsAvailable CONSTANT)
6060

61+
Q_PROPERTY(bool yandexLocatorEnabled READ yandexLocatorEnabled WRITE setYandexLocatorEnabled NOTIFY yandexLocatorEnabledChanged)
62+
Q_PROPERTY(OnlineAGpsState yandexLocatorOnlineState READ yandexLocatorOnlineState WRITE setYandexLocatorOnlineState NOTIFY yandexLocatorOnlineStateChanged)
63+
Q_PROPERTY(bool yandexLocatorAvailable READ yandexLocatorAvailable CONSTANT)
64+
6165
Q_PROPERTY(LocationMode locationMode READ locationMode WRITE setLocationMode NOTIFY locationModeChanged)
6266

6367
Q_PROPERTY(DataSources allowedDataSources READ allowedDataSources WRITE setAllowedDataSources NOTIFY allowedDataSourcesChanged)
@@ -100,6 +104,12 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
100104
void setMlsOnlineState(OnlineAGpsState state);
101105
bool mlsAvailable() const;
102106

107+
bool yandexLocatorEnabled() const;
108+
void setYandexLocatorEnabled(bool enabled);
109+
OnlineAGpsState yandexLocatorOnlineState() const;
110+
void setYandexLocatorOnlineState(OnlineAGpsState state);
111+
bool yandexLocatorAvailable() const;
112+
103113
enum LocationMode {
104114
HighAccuracyMode,
105115
BatterySavingMode,
@@ -144,6 +154,8 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
144154
void gpsFlightModeChanged();
145155
void mlsEnabledChanged();
146156
void mlsOnlineStateChanged();
157+
void yandexLocatorEnabledChanged();
158+
void yandexLocatorOnlineStateChanged();
147159
void locationModeChanged();
148160
void allowedDataSourcesChanged();
149161

src/locationsettings_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ class LocationSettingsPrivate : public QObject
6262
void writeSettings();
6363

6464
bool mlsAvailable() const;
65+
bool yandexLocatorAvailable() const;
6566
bool hereAvailable() const;
6667

6768
QFileSystemWatcher m_watcher;
6869
bool m_locationEnabled;
6970
bool m_gpsEnabled;
7071
bool m_mlsEnabled;
72+
bool m_yandexLocatorEnabled;
7173
LocationSettings::OnlineAGpsState m_mlsOnlineState;
74+
LocationSettings::OnlineAGpsState m_yandexLocatorOnlineState;
7275
LocationSettings::OnlineAGpsState m_hereState;
7376
LocationSettings::LocationMode m_locationMode;
7477
bool m_settingLocationMode;

0 commit comments

Comments
 (0)