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

Commit 1d160e3

Browse files
committed
[settings-nfc] Add nfc settings interfaces. Contibutes JB#48464
1 parent ba125e4 commit 1d160e3

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

src/nfcsettings.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (C) 2019 Open Mobile Platform LLС. <[email protected]>
3+
*
4+
* You may use this file under the terms of the BSD license as follows:
5+
*
6+
* "Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are
8+
* met:
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
* * Neither the name of Nemo Mobile nor the names of its contributors
16+
* may be used to endorse or promote products derived from this
17+
* software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
30+
*/
31+
32+
33+
#include "nfcsettings.h"
34+
35+
#include <QDBusConnection>
36+
#include <QDBusConnectionInterface>
37+
#include <QDebug>
38+
39+
NfcSettings::NfcSettings(QObject *parent)
40+
: QObject(parent)
41+
, m_enabled(false)
42+
, m_available(false)
43+
{
44+
m_interface = new QDBusInterface("org.sailfishos.nfc.settings",
45+
"/",
46+
"org.sailfishos.nfc.Settings",
47+
QDBusConnection::systemBus(),
48+
this);
49+
if (QDBusConnection::systemBus().interface()->isServiceRegistered("org.sailfishos.nfc.settings")) {
50+
m_available = true;
51+
emit availableChanged();
52+
53+
QDBusPendingCall pcall = m_interface->asyncCall(QLatin1String("GetEnabled"));
54+
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
55+
56+
connect(watcher, &QDBusPendingCallWatcher::finished, this, &NfcSettings::getEnableStateFinished);
57+
QDBusConnection::systemBus().connect("org.sailfishos.nfc.settings", "/", "org.sailfishos.nfc.Settings", "EnabledChanged", this, SLOT(updateEnabledState(bool)));
58+
59+
} else {
60+
qWarning() << "NFC interface not available";
61+
qWarning() << m_interface->lastError();
62+
}
63+
64+
}
65+
66+
NfcSettings::~NfcSettings()
67+
{
68+
}
69+
70+
bool NfcSettings::available() const
71+
{
72+
return m_available;
73+
}
74+
75+
bool NfcSettings::enabled() const
76+
{
77+
return m_enabled;
78+
}
79+
80+
void NfcSettings::setEnabled(bool enabled)
81+
{
82+
m_interface->asyncCall("SetEnabled", enabled);
83+
}
84+
85+
void NfcSettings::getEnableStateFinished(QDBusPendingCallWatcher *call)
86+
{
87+
QDBusPendingReply<bool> reply = *call;
88+
if (reply.isError()) {
89+
qWarning() << "Get dbus error:" << reply.error();
90+
} else {
91+
updateEnabledState(reply.value());
92+
}
93+
call->deleteLater();
94+
}
95+
96+
void NfcSettings::updateEnabledState(bool enabled)
97+
{
98+
if (enabled != m_enabled) {
99+
m_enabled = enabled;
100+
emit enabledChanged();
101+
}
102+
}

src/nfcsettings.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef NFCSETTINGS_H
2+
#define NFCSETTINGS_H
3+
4+
#include <systemsettingsglobal.h>
5+
6+
#include <QObject>
7+
#include <QDBusInterface>
8+
#include <QDBusPendingCallWatcher>
9+
#include <QTimer>
10+
11+
class SYSTEMSETTINGS_EXPORT NfcSettings : public QObject
12+
{
13+
Q_OBJECT
14+
15+
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
16+
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
17+
public:
18+
explicit NfcSettings(QObject *parent = nullptr);
19+
~NfcSettings();
20+
21+
bool available() const;
22+
bool enabled() const;
23+
void setEnabled(bool enabled);
24+
25+
signals:
26+
void availableChanged();
27+
void enabledChanged();
28+
29+
private:
30+
bool m_enabled;
31+
bool m_available;
32+
QDBusInterface *m_interface;
33+
QTimer *m_timer;
34+
35+
private slots:
36+
void getEnableStateFinished(QDBusPendingCallWatcher* call);
37+
void updateEnabledState(bool enabled);
38+
};
39+
40+
#endif // NFCSETTINGS_H

src/plugin/plugin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "settingsvpnmodel.h"
5151
#include "locationsettings.h"
5252
#include "deviceinfo.h"
53+
#include "nfcsettings.h"
5354

5455
template<class T>
5556
static QObject *api_factory(QQmlEngine *, QJSEngine *)
@@ -89,6 +90,7 @@ class SystemSettingsPlugin : public QQmlExtensionPlugin
8990
qmlRegisterType<DiskUsage>(uri, 1, 0, "DiskUsage");
9091
qmlRegisterType<LocationSettings>(uri, 1, 0, "LocationSettings");
9192
qmlRegisterType<DeviceInfo>(uri, 1, 0, "DeviceInfo");
93+
qmlRegisterType<NfcSettings>(uri, 1, 0, "NfcSettings");
9294
}
9395
};
9496

src/src.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SOURCES += \
1616
localeconfig.cpp \
1717
logging.cpp \
1818
datetimesettings.cpp \
19+
nfcsettings.cpp \
1920
profilecontrol.cpp \
2021
alarmtonemodel.cpp \
2122
mceiface.cpp \
@@ -70,6 +71,7 @@ HEADERS += \
7071
diskusage_p.h \
7172
locationsettings_p.h \
7273
logging_p.h \
74+
nfcsettings.h \
7375
partition_p.h \
7476
partitionmanager_p.h \
7577
udisks2blockdevices_p.h \

0 commit comments

Comments
 (0)