46
46
#include < networkmanager.h>
47
47
#include < networktechnology.h>
48
48
49
+ #include < limits>
50
+
49
51
namespace {
52
+ // TODO: replace all of this with DBus calls to a central settings service...
50
53
QString boolToString (bool value) { return value ? QStringLiteral (" true" ) : QStringLiteral (" false" ); }
51
54
const QString LocationSettingsDir = QStringLiteral(" /etc/location/" );
52
55
const QString LocationSettingsFile = QStringLiteral(" /etc/location/location.conf" );
53
56
const QString LocationSettingsKeys = QStringLiteral(
54
- " enabled" " ;"
55
- " custom_mode" " ;"
56
- " agps_providers" " ;"
57
- " gps\\ enabled" " ;"
58
- " mls\\ enabled" " ;"
59
- " mls\\ agreement_accepted" " ;"
60
- " mls\\ online_enabled" " ;"
61
- " here\\ enabled" " ;"
62
- " here\\ agreement_accepted" " ;"
63
- " here\\ online_enabled" " ;"
64
- /* and the deprecated keys: */
65
- " cell_id_positioning_enabled" " ;"
66
- " here_agreement_accepted" " ;"
67
- " agreement_accepted" );
57
+ " enabled" " ;"
58
+ " allowed_data_sources\\ online" " ;"
59
+ " allowed_data_sources\\ device_sensors" " ;"
60
+ " allowed_data_sources\\ bt_data" " ;"
61
+ " allowed_data_sources\\ wlan_data" " ;"
62
+ " allowed_data_sources\\ cell_data" " ;"
63
+ " allowed_data_sources\\ gps" " ;"
64
+ " allowed_data_sources\\ glonass" " ;"
65
+ " allowed_data_sources\\ beidou" " ;"
66
+ " allowed_data_sources\\ galileo" " ;"
67
+ " allowed_data_sources\\ qzss" " ;"
68
+ " allowed_data_sources\\ sbas" " ;"
69
+ " custom_mode" " ;"
70
+ " agps_providers" " ;"
71
+ " gps\\ enabled" " ;"
72
+ " mls\\ enabled" " ;"
73
+ " mls\\ agreement_accepted" " ;"
74
+ " mls\\ online_enabled" " ;"
75
+ " here\\ enabled" " ;"
76
+ " here\\ agreement_accepted" " ;"
77
+ " here\\ online_enabled" " ;"
78
+ /* and the deprecated keys: */
79
+ " cell_id_positioning_enabled" " ;"
80
+ " here_agreement_accepted" " ;"
81
+ " agreement_accepted" );
82
+ const int LocationSettingsValueIndex_Enabled = 0 ;
83
+ const int LocationSettingsValueIndex_AllowedDataSources_Online = 1 ;
84
+ const int LocationSettingsValueIndex_AllowedDataSources_DeviceSensors = 2 ;
85
+ const int LocationSettingsValueIndex_AllowedDataSources_Bluetooth = 3 ;
86
+ const int LocationSettingsValueIndex_AllowedDataSources_WlanData = 4 ;
87
+ const int LocationSettingsValueIndex_AllowedDataSources_CellData = 5 ;
88
+ const int LocationSettingsValueIndex_AllowedDataSources_Gps = 6 ;
89
+ const int LocationSettingsValueIndex_AllowedDataSources_Glonass = 7 ;
90
+ const int LocationSettingsValueIndex_AllowedDataSources_Beidou = 8 ;
91
+ const int LocationSettingsValueIndex_AllowedDataSources_Galileo = 9 ;
92
+ const int LocationSettingsValueIndex_AllowedDataSources_Qzss = 10 ;
93
+ const int LocationSettingsValueIndex_AllowedDataSources_Sbas = 11 ;
94
+ const int LocationSettingsValueIndex_CustomMode = 12 ;
95
+ const int LocationSettingsValueIndex_AgpsProviders = 13 ;
96
+ const int LocationSettingsValueIndex_Gps_Enabled = 14 ;
97
+ const int LocationSettingsValueIndex_Mls_Enabled = 15 ;
98
+ const int LocationSettingsValueIndex_Mls_AgreementAccepted = 16 ;
99
+ const int LocationSettingsValueIndex_Mls_OnlineEnabled = 17 ;
100
+ const int LocationSettingsValueIndex_Here_Enabled = 18 ;
101
+ const int LocationSettingsValueIndex_Here_AgreementAccepted = 19 ;
102
+ const int LocationSettingsValueIndex_Here_OnlineEnabled = 26 ;
103
+ const int LocationSettingsValueIndex_DEPRECATED_CellIdPositioningEnabled = 20 ;
104
+ const int LocationSettingsValueIndex_DEPRECATED_HereEnabled = 21 ;
105
+ const int LocationSettingsValueIndex_DEPRECATED_HereAgreementAccepted = 22 ;
106
+ QMap<int , LocationSettings::DataSource> LocationSettingsValueIndexToDataSourceMap
107
+ {
108
+ { LocationSettingsValueIndex_AllowedDataSources_Online,
109
+ LocationSettings::OnlineDataSources },
110
+ { LocationSettingsValueIndex_AllowedDataSources_DeviceSensors,
111
+ LocationSettings::DeviceSensorsData },
112
+ { LocationSettingsValueIndex_AllowedDataSources_Bluetooth,
113
+ LocationSettings::BluetoothData },
114
+ { LocationSettingsValueIndex_AllowedDataSources_WlanData,
115
+ LocationSettings::WlanData },
116
+ { LocationSettingsValueIndex_AllowedDataSources_CellData,
117
+ LocationSettings::CellTowerData },
118
+ { LocationSettingsValueIndex_AllowedDataSources_Gps,
119
+ LocationSettings::GpsData },
120
+ { LocationSettingsValueIndex_AllowedDataSources_Glonass,
121
+ LocationSettings::GlonassData },
122
+ { LocationSettingsValueIndex_AllowedDataSources_Beidou,
123
+ LocationSettings::BeidouData },
124
+ { LocationSettingsValueIndex_AllowedDataSources_Galileo,
125
+ LocationSettings::GalileoData },
126
+ { LocationSettingsValueIndex_AllowedDataSources_Qzss,
127
+ LocationSettings::QzssData },
128
+ { LocationSettingsValueIndex_AllowedDataSources_Sbas,
129
+ LocationSettings::SbasData },
130
+ };
68
131
const QString PoweredPropertyName = QStringLiteral(" Powered" );
69
132
}
70
133
@@ -79,6 +142,7 @@ LocationSettingsPrivate::LocationSettingsPrivate(LocationSettings::Mode mode, Lo
79
142
, m_locationMode(LocationSettings::CustomMode)
80
143
, m_settingLocationMode(true )
81
144
, m_settingMultipleSettings(false )
145
+ , m_allowedDataSources(static_cast <LocationSettings::DataSources>(std::numeric_limits<quint32>::max()))
82
146
, m_connMan(Q_NULLPTR)
83
147
, m_gpsTech(Q_NULLPTR)
84
148
, m_gpsTechInterface(mode == LocationSettings::AsynchronousMode
@@ -431,6 +495,23 @@ void LocationSettings::setLocationMode(LocationMode locationMode)
431
495
d->m_settingLocationMode = false ;
432
496
}
433
497
498
+ LocationSettings::DataSources LocationSettings::allowedDataSources () const
499
+ {
500
+ Q_D (const LocationSettings);
501
+ return d->m_allowedDataSources ;
502
+ }
503
+
504
+ void LocationSettings::setAllowedDataSources (LocationSettings::DataSources dataSources)
505
+ {
506
+ Q_D (LocationSettings);
507
+ if (dataSources == d->m_allowedDataSources )
508
+ return ;
509
+
510
+ d->m_allowedDataSources = dataSources;
511
+ d->writeSettings ();
512
+ emit allowedDataSourcesChanged ();
513
+ }
514
+
434
515
void LocationSettingsPrivate::readSettings ()
435
516
{
436
517
if (!m_processMutex) {
@@ -451,22 +532,44 @@ void LocationSettingsPrivate::readSettings()
451
532
}
452
533
453
534
// read the deprecated keys first, for compatibility purposes:
454
- bool oldMlsEnabled = locationSettingsValues[10 ] != NULL && strcmp (locationSettingsValues[10 ], " true" ) == 0 ;
455
- bool oldHereEnabled = locationSettingsValues[11 ] != NULL && strcmp (locationSettingsValues[11 ], " true" ) == 0 ;
456
- bool oldHereAgreementAccepted = locationSettingsValues[12 ] != NULL && strcmp (locationSettingsValues[12 ], " true" ) == 0 ;
535
+ bool oldMlsEnabled = locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_CellIdPositioningEnabled] != NULL
536
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_CellIdPositioningEnabled], " true" ) == 0 ;
537
+ bool oldHereEnabled = locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereEnabled] != NULL
538
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereEnabled], " true" ) == 0 ;
539
+ bool oldHereAgreementAccepted = locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereAgreementAccepted] != NULL
540
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_DEPRECATED_HereAgreementAccepted], " true" ) == 0 ;
541
+
457
542
// then read the new key values (overriding with deprecated values if needed):
458
- bool locationEnabled = locationSettingsValues[0 ] != NULL && strcmp (locationSettingsValues[0 ], " true" ) == 0 ;
459
- bool customMode = locationSettingsValues[1 ] != NULL && strcmp (locationSettingsValues[1 ], " true" ) == 0 ;
460
- // skip over the agps_providers value at [2]
461
- bool gpsEnabled = locationSettingsValues[3 ] != NULL && strcmp (locationSettingsValues[3 ], " true" ) == 0 ;
462
- bool mlsEnabled = oldMlsEnabled || (locationSettingsValues[4 ] != NULL && strcmp (locationSettingsValues[4 ], " true" ) == 0 );
463
- bool mlsAgreementAccepted = locationSettingsValues[5 ] != NULL && strcmp (locationSettingsValues[5 ], " true" ) == 0 ;
464
- bool mlsOnlineEnabled = locationSettingsValues[6 ] != NULL && strcmp (locationSettingsValues[6 ], " true" ) == 0 ;
465
- bool hereEnabled = oldHereEnabled || (locationSettingsValues[7 ] != NULL && strcmp (locationSettingsValues[7 ], " true" ) == 0 );
466
- bool hereAgreementAccepted = oldHereAgreementAccepted || (locationSettingsValues[8 ] != NULL && strcmp (locationSettingsValues[8 ], " true" ) == 0 );
467
- // skip over here\online_enabled value at [9]
468
-
469
- const int expectedCount = 13 ; // should equal: LocationSettingsKeys.split(';').count();
543
+ bool locationEnabled = locationSettingsValues[LocationSettingsValueIndex_Enabled] != NULL
544
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Enabled], " true" ) == 0 ;
545
+ bool customMode = locationSettingsValues[LocationSettingsValueIndex_CustomMode] != NULL
546
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_CustomMode], " true" ) == 0 ;
547
+ LocationSettings::DataSources allowedDataSources = static_cast <LocationSettings::DataSources>(std::numeric_limits<quint32>::max ());
548
+ for (QMap<int , LocationSettings::DataSource>::const_iterator it = LocationSettingsValueIndexToDataSourceMap.constBegin ();
549
+ it != LocationSettingsValueIndexToDataSourceMap.constEnd (); it++) {
550
+ if (locationSettingsValues[it.key ()] != NULL && strcmp (locationSettingsValues[it.key ()], " true" ) != 0 ) {
551
+ allowedDataSources &= ~it.value (); // mark the data source as disabled
552
+ }
553
+ }
554
+ // skip over the agps_providers value.
555
+ bool gpsEnabled = locationSettingsValues[LocationSettingsValueIndex_Gps_Enabled] != NULL
556
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Gps_Enabled], " true" ) == 0 ;
557
+ bool mlsEnabled = oldMlsEnabled
558
+ || (locationSettingsValues[LocationSettingsValueIndex_Mls_Enabled] != NULL
559
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Mls_Enabled], " true" ) == 0 );
560
+ bool mlsAgreementAccepted = locationSettingsValues[LocationSettingsValueIndex_Mls_AgreementAccepted] != NULL
561
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Mls_AgreementAccepted], " true" ) == 0 ;
562
+ bool mlsOnlineEnabled = locationSettingsValues[LocationSettingsValueIndex_Mls_OnlineEnabled] != NULL
563
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Mls_OnlineEnabled], " true" ) == 0 ;
564
+ bool hereEnabled = oldHereEnabled
565
+ || (locationSettingsValues[LocationSettingsValueIndex_Here_Enabled] != NULL
566
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Here_Enabled], " true" ) == 0 );
567
+ bool hereAgreementAccepted = oldHereAgreementAccepted
568
+ || (locationSettingsValues[LocationSettingsValueIndex_Here_AgreementAccepted] != NULL
569
+ && strcmp (locationSettingsValues[LocationSettingsValueIndex_Here_AgreementAccepted], " true" ) == 0 );
570
+ // skip over here\online_enabled value.
571
+
572
+ const int expectedCount = 23 ; // should equal: LocationSettingsKeys.split(';').count();
470
573
for (int i = 0 ; i < expectedCount; ++i) {
471
574
if (locationSettingsValues[i] != NULL ) {
472
575
free (locationSettingsValues[i]);
@@ -479,6 +582,11 @@ void LocationSettingsPrivate::readSettings()
479
582
emit q->locationEnabledChanged ();
480
583
}
481
584
585
+ if (m_allowedDataSources != allowedDataSources) {
586
+ m_allowedDataSources = allowedDataSources;
587
+ emit q->allowedDataSourcesChanged ();
588
+ }
589
+
482
590
if (m_gpsEnabled != gpsEnabled) {
483
591
m_gpsEnabled = gpsEnabled;
484
592
emit q->gpsEnabledChanged ();
@@ -541,6 +649,11 @@ void LocationSettingsPrivate::writeSettings()
541
649
QString locationSettingsValues;
542
650
locationSettingsValues.append (boolToString (m_locationEnabled));
543
651
locationSettingsValues.append (" ;" );
652
+ for (QMap<int , LocationSettings::DataSource>::const_iterator it = LocationSettingsValueIndexToDataSourceMap.constBegin ();
653
+ it != LocationSettingsValueIndexToDataSourceMap.constEnd (); it++) {
654
+ locationSettingsValues.append (boolToString (m_allowedDataSources & it.value ()));
655
+ locationSettingsValues.append (" ;" );
656
+ }
544
657
locationSettingsValues.append (boolToString (m_locationMode == LocationSettings::CustomMode));
545
658
locationSettingsValues.append (" ;" );
546
659
locationSettingsValues.append (agps_providers);
0 commit comments