Skip to content

Commit

Permalink
Merge tag '0.5.38' into tama
Browse files Browse the repository at this point in the history
  • Loading branch information
rinigus committed May 10, 2020
2 parents 02025ac + cc0a430 commit d56b627
Show file tree
Hide file tree
Showing 9 changed files with 518 additions and 355 deletions.
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-systemsettings.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: nemo-qml-plugin-systemsettings
Summary: System settings plugin for Nemo Mobile
Version: 0.5.27
Version: 0.5.37
Release: 1
Group: System/Libraries
License: BSD
Expand Down
551 changes: 266 additions & 285 deletions src/locationsettings.cpp

Large diffs are not rendered by default.

116 changes: 66 additions & 50 deletions src/locationsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -75,51 +87,19 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
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,
DeviceOnlyMode,
CustomMode
};

LocationMode locationMode() const;
void setLocationMode(LocationMode locationMode);

// Data sources are grouped roughly by type,
// with gaps left for future expansion.
enum DataSource {
Expand All @@ -144,20 +124,56 @@ class SYSTEMSETTINGS_EXPORT LocationSettings : public QObject
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;
Expand Down
19 changes: 8 additions & 11 deletions src/locationsettings_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <QDBusInterface>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QHash>

#include <sailfishkeyprovider_processmutex.h>

Expand All @@ -58,24 +60,20 @@ class LocationSettingsPrivate : public QObject
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;
Expand All @@ -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...
Expand Down
110 changes: 110 additions & 0 deletions src/nfcsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2019 Open Mobile Platform LLС. <[email protected]>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/


#include "nfcsettings.h"

#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDebug>

NfcSettings::NfcSettings(QObject *parent)
: QObject(parent)
, m_valid(false)
, m_enabled(false)
, m_available(false)
{
m_interface = new QDBusInterface("org.sailfishos.nfc.settings",
"/",
"org.sailfishos.nfc.Settings",
QDBusConnection::systemBus(),
this);
if (QDBusConnection::systemBus().interface()->isServiceRegistered("org.sailfishos.nfc.settings")) {
m_available = true;
emit availableChanged();

QDBusPendingCall pcall = m_interface->asyncCall(QLatin1String("GetEnabled"));
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);

connect(watcher, &QDBusPendingCallWatcher::finished, this, &NfcSettings::getEnableStateFinished);
QDBusConnection::systemBus().connect("org.sailfishos.nfc.settings", "/", "org.sailfishos.nfc.Settings", "EnabledChanged", this, SLOT(updateEnabledState(bool)));

} else {
qWarning() << "NFC interface not available";
qWarning() << m_interface->lastError();
}

}

NfcSettings::~NfcSettings()
{
}

bool NfcSettings::valid() const
{
return m_valid;
}

bool NfcSettings::available() const
{
return m_available;
}

bool NfcSettings::enabled() const
{
return m_enabled;
}

void NfcSettings::setEnabled(bool enabled)
{
m_interface->asyncCall("SetEnabled", enabled);
}

void NfcSettings::getEnableStateFinished(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<bool> reply = *call;
if (reply.isError()) {
qWarning() << "Get dbus error:" << reply.error();
} else {
updateEnabledState(reply.value());
m_valid = true;
emit validChanged();
}
call->deleteLater();
}

void NfcSettings::updateEnabledState(bool enabled)
{
if (enabled != m_enabled) {
m_enabled = enabled;
emit enabledChanged();
}
}
44 changes: 44 additions & 0 deletions src/nfcsettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef NFCSETTINGS_H
#define NFCSETTINGS_H

#include <systemsettingsglobal.h>

#include <QObject>
#include <QDBusInterface>
#include <QDBusPendingCallWatcher>
#include <QTimer>

class SYSTEMSETTINGS_EXPORT NfcSettings : public QObject
{
Q_OBJECT
Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)

public:
explicit NfcSettings(QObject *parent = nullptr);
~NfcSettings();

bool valid() const;
bool available() const;
bool enabled() const;
void setEnabled(bool enabled);

signals:
void validChanged();
void availableChanged();
void enabledChanged();

private:
bool m_valid;
bool m_enabled;
bool m_available;
QDBusInterface *m_interface;
QTimer *m_timer;

private slots:
void getEnableStateFinished(QDBusPendingCallWatcher* call);
void updateEnabledState(bool enabled);
};

#endif // NFCSETTINGS_H
Loading

0 comments on commit d56b627

Please sign in to comment.