Commit 498d3260 authored by pvuorela's avatar pvuorela

Merge branch 'refactor_location_settings' into 'master'

[nemo-qml-plugin-systemsettings] Refactor location settings. Contributes  to JB#47257

See merge request mer-core/nemo-qml-plugin-systemsettings!129
parents d469f881 2f399d79
This diff is collapsed.
......@@ -37,34 +37,46 @@
#include <QObject>
#include <QString>
#include <QStringList>
#define LOCATION_SETTINGS_LAST_DATA_SOURCE_BIT 31
struct LocationProvider {
bool hasAgreement = false;
bool agreementAccepted = false;
bool onlineCapable = true;
bool onlineEnabled = false;
bool offlineCapable = false;
bool offlineEnabled = false;
};
// The settings component here expects two types of usage for modifications.
// Either locationMode to high level location types, after which pendingAgreements tells
// which location services need to be explicitly turned on to ensure the usage agreement is acknowledged.
// Or setting location mode to custom, and modifying specific details.
class LocationSettingsPrivate;
class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
{
Q_OBJECT
Q_PROPERTY(bool locationEnabled READ locationEnabled WRITE setLocationEnabled NOTIFY locationEnabledChanged)
Q_PROPERTY(LocationMode locationMode READ locationMode WRITE setLocationMode NOTIFY locationModeChanged)
Q_PROPERTY(QStringList pendingAgreements READ pendingAgreements NOTIFY pendingAgreementsChanged)
Q_PROPERTY(DataSources allowedDataSources READ allowedDataSources WRITE setAllowedDataSources NOTIFY allowedDataSourcesChanged)
Q_PROPERTY(bool gpsAvailable READ gpsAvailable CONSTANT)
Q_PROPERTY(bool gpsEnabled READ gpsEnabled WRITE setGpsEnabled NOTIFY gpsEnabledChanged)
Q_PROPERTY(bool gpsFlightMode READ gpsFlightMode WRITE setGpsFlightMode NOTIFY gpsFlightModeChanged)
Q_PROPERTY(bool gpsAvailable READ gpsAvailable CONSTANT)
Q_PROPERTY(QStringList locationProviders READ locationProviders CONSTANT)
Q_PROPERTY(OnlineAGpsState hereState READ hereState WRITE setHereState NOTIFY hereStateChanged)
// Some specific locators provided as convenience for qml
Q_PROPERTY(bool hereAvailable READ hereAvailable CONSTANT)
Q_PROPERTY(OnlineAGpsState hereState READ hereState WRITE setHereState NOTIFY hereStateChanged)
Q_PROPERTY(bool mlsAvailable READ mlsAvailable CONSTANT)
Q_PROPERTY(bool mlsEnabled READ mlsEnabled WRITE setMlsEnabled NOTIFY mlsEnabledChanged)
Q_PROPERTY(OnlineAGpsState mlsOnlineState READ mlsOnlineState WRITE setMlsOnlineState NOTIFY mlsOnlineStateChanged)
Q_PROPERTY(bool mlsAvailable READ mlsAvailable CONSTANT)
Q_PROPERTY(bool yandexLocatorEnabled READ yandexLocatorEnabled WRITE setYandexLocatorEnabled NOTIFY yandexLocatorEnabledChanged)
Q_PROPERTY(OnlineAGpsState yandexLocatorOnlineState READ yandexLocatorOnlineState WRITE setYandexLocatorOnlineState NOTIFY yandexLocatorOnlineStateChanged)
Q_PROPERTY(bool yandexLocatorAvailable READ yandexLocatorAvailable CONSTANT)
Q_PROPERTY(LocationMode locationMode READ locationMode WRITE setLocationMode NOTIFY locationModeChanged)
Q_PROPERTY(DataSources allowedDataSources READ allowedDataSources WRITE setAllowedDataSources NOTIFY allowedDataSourcesChanged)
Q_PROPERTY(bool yandexAvailable READ yandexAvailable CONSTANT)
Q_PROPERTY(OnlineAGpsState yandexOnlineState READ yandexOnlineState WRITE setYandexOnlineState NOTIFY yandexOnlineStateChanged)
Q_ENUMS(OnlineAGpsState)
Q_ENUMS(LocationMode)
......@@ -75,41 +87,12 @@ public:
SynchronousMode
};
explicit LocationSettings(QObject *parent = 0);
explicit LocationSettings(Mode mode, QObject *parent = 0);
virtual ~LocationSettings();
bool locationEnabled() const;
void setLocationEnabled(bool enabled);
bool gpsEnabled() const;
void setGpsEnabled(bool enabled);
bool gpsFlightMode() const;
void setGpsFlightMode(bool flightMode);
bool gpsAvailable() const;
enum OnlineAGpsState {
OnlineAGpsAgreementNotAccepted,
OnlineAGpsDisabled,
OnlineAGpsEnabled
};
OnlineAGpsState hereState() const;
void setHereState(OnlineAGpsState state);
bool hereAvailable() const;
bool mlsEnabled() const;
void setMlsEnabled(bool enabled);
OnlineAGpsState mlsOnlineState() const;
void setMlsOnlineState(OnlineAGpsState state);
bool mlsAvailable() const;
bool yandexLocatorEnabled() const;
void setYandexLocatorEnabled(bool enabled);
OnlineAGpsState yandexLocatorOnlineState() const;
void setYandexLocatorOnlineState(OnlineAGpsState state);
bool yandexLocatorAvailable() const;
enum LocationMode {
HighAccuracyMode,
BatterySavingMode,
......@@ -117,9 +100,6 @@ public:
CustomMode
};
LocationMode locationMode() const;
void setLocationMode(LocationMode locationMode);
// Data sources are grouped roughly by type,
// with gaps left for future expansion.
enum DataSource {
......@@ -144,20 +124,56 @@ public:
Q_DECLARE_FLAGS(DataSources, DataSource)
Q_FLAG(DataSources)
explicit LocationSettings(QObject *parent = 0);
explicit LocationSettings(Mode mode, QObject *parent = 0);
virtual ~LocationSettings();
bool locationEnabled() const;
void setLocationEnabled(bool enabled);
bool gpsEnabled() const;
void setGpsEnabled(bool enabled);
bool gpsFlightMode() const;
void setGpsFlightMode(bool flightMode);
bool gpsAvailable() const;
QStringList locationProviders() const;
LocationProvider providerInfo(const QString &name) const;
bool updateLocationProvider(const QString &name, const LocationProvider &providerState);
// qml helpers for specific location providers
OnlineAGpsState hereState() const;
void setHereState(OnlineAGpsState state);
bool hereAvailable() const;
bool mlsEnabled() const;
void setMlsEnabled(bool enabled);
OnlineAGpsState mlsOnlineState() const;
void setMlsOnlineState(OnlineAGpsState state);
bool mlsAvailable() const;
OnlineAGpsState yandexOnlineState() const;
void setYandexOnlineState(OnlineAGpsState state);
bool yandexAvailable() const;
LocationMode locationMode() const;
void setLocationMode(LocationMode locationMode);
QStringList pendingAgreements() const;
DataSources allowedDataSources() const;
void setAllowedDataSources(DataSources dataSources);
signals:
void hereStateChanged();
void locationEnabledChanged();
void gpsEnabledChanged();
void gpsFlightModeChanged();
void mlsEnabledChanged();
void mlsOnlineStateChanged();
void yandexLocatorEnabledChanged();
void yandexLocatorOnlineStateChanged();
void locationModeChanged();
void pendingAgreementsChanged();
void allowedDataSourcesChanged();
void hereStateChanged();
void mlsEnabledChanged();
void mlsOnlineStateChanged();
void yandexOnlineStateChanged();
private:
LocationSettingsPrivate *d_ptr;
......
......@@ -38,6 +38,8 @@
#include <QDBusInterface>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QHash>
#include <sailfishkeyprovider_processmutex.h>
......@@ -58,24 +60,20 @@ public:
LocationSettingsPrivate(LocationSettings::Mode mode, LocationSettings *settings);
~LocationSettingsPrivate();
void loadProviders();
bool updateProvider(const QString &name, const LocationProvider &state);
LocationSettings::OnlineAGpsState onlineState(const QString &name, bool *valid = nullptr) const;
void updateOnlineAgpsState(const QString &name, LocationSettings::OnlineAGpsState state);
LocationSettings::LocationMode calculateLocationMode() const;
void writeSettings();
bool mlsAvailable() const;
bool yandexLocatorAvailable() const;
bool hereAvailable() const;
QFileSystemWatcher m_watcher;
bool m_locationEnabled;
bool m_gpsEnabled;
bool m_mlsEnabled;
bool m_yandexLocatorEnabled;
LocationSettings::OnlineAGpsState m_mlsOnlineState;
LocationSettings::OnlineAGpsState m_yandexLocatorOnlineState;
LocationSettings::OnlineAGpsState m_hereState;
QHash<QString, LocationProvider> m_providers;
LocationSettings::LocationMode m_locationMode;
bool m_settingLocationMode;
bool m_settingMultipleSettings;
QStringList m_pendingAgreements;
LocationSettings::DataSources m_allowedDataSources;
NetworkManager *m_connMan;
NetworkTechnology *m_gpsTech;
......@@ -85,7 +83,6 @@ private slots:
void readSettings();
void findGpsTech();
void gpsTechPropertyChanged(const QString &propertyName, const QVariant &value);
void recalculateLocationMode();
};
// TODO: replace this with DBus calls to a central settings service...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment