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

Commit d095d76

Browse files
committed
Merge branch 'nfc' into 'master'
Add nfc settings interfaces See merge request mer-core/nemo-qml-plugin-systemsettings!130
2 parents ba125e4 + 44716f0 commit d095d76

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-0
lines changed

src/nfcsettings.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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_valid(false)
42+
, m_enabled(false)
43+
, m_available(false)
44+
{
45+
m_interface = new QDBusInterface("org.sailfishos.nfc.settings",
46+
"/",
47+
"org.sailfishos.nfc.Settings",
48+
QDBusConnection::systemBus(),
49+
this);
50+
if (QDBusConnection::systemBus().interface()->isServiceRegistered("org.sailfishos.nfc.settings")) {
51+
m_available = true;
52+
emit availableChanged();
53+
54+
QDBusPendingCall pcall = m_interface->asyncCall(QLatin1String("GetEnabled"));
55+
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
56+
57+
connect(watcher, &QDBusPendingCallWatcher::finished, this, &NfcSettings::getEnableStateFinished);
58+
QDBusConnection::systemBus().connect("org.sailfishos.nfc.settings", "/", "org.sailfishos.nfc.Settings", "EnabledChanged", this, SLOT(updateEnabledState(bool)));
59+
60+
} else {
61+
qWarning() << "NFC interface not available";
62+
qWarning() << m_interface->lastError();
63+
}
64+
65+
}
66+
67+
NfcSettings::~NfcSettings()
68+
{
69+
}
70+
71+
bool NfcSettings::valid() const
72+
{
73+
return m_valid;
74+
}
75+
76+
bool NfcSettings::available() const
77+
{
78+
return m_available;
79+
}
80+
81+
bool NfcSettings::enabled() const
82+
{
83+
return m_enabled;
84+
}
85+
86+
void NfcSettings::setEnabled(bool enabled)
87+
{
88+
m_interface->asyncCall("SetEnabled", enabled);
89+
}
90+
91+
void NfcSettings::getEnableStateFinished(QDBusPendingCallWatcher *call)
92+
{
93+
QDBusPendingReply<bool> reply = *call;
94+
if (reply.isError()) {
95+
qWarning() << "Get dbus error:" << reply.error();
96+
} else {
97+
updateEnabledState(reply.value());
98+
m_valid = true;
99+
emit validChanged();
100+
}
101+
call->deleteLater();
102+
}
103+
104+
void NfcSettings::updateEnabledState(bool enabled)
105+
{
106+
if (enabled != m_enabled) {
107+
m_enabled = enabled;
108+
emit enabledChanged();
109+
}
110+
}

src/nfcsettings.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
15+
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
16+
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
17+
18+
public:
19+
explicit NfcSettings(QObject *parent = nullptr);
20+
~NfcSettings();
21+
22+
bool valid() const;
23+
bool available() const;
24+
bool enabled() const;
25+
void setEnabled(bool enabled);
26+
27+
signals:
28+
void validChanged();
29+
void availableChanged();
30+
void enabledChanged();
31+
32+
private:
33+
bool m_valid;
34+
bool m_enabled;
35+
bool m_available;
36+
QDBusInterface *m_interface;
37+
QTimer *m_timer;
38+
39+
private slots:
40+
void getEnableStateFinished(QDBusPendingCallWatcher* call);
41+
void updateEnabledState(bool enabled);
42+
};
43+
44+
#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)