| 1 | /* |
|---|---|
| 2 | * BluezQt - Asynchronous Bluez wrapper library |
| 3 | * |
| 4 | * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com> |
| 5 | * |
| 6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | |
| 9 | #include "input.h" |
| 10 | #include "input_p.h" |
| 11 | #include "macros.h" |
| 12 | #include "utils.h" |
| 13 | |
| 14 | #include <QVariantMap> |
| 15 | |
| 16 | namespace BluezQt |
| 17 | { |
| 18 | static Input::ReconnectMode stringToReconnectMode(const QString &mode) |
| 19 | { |
| 20 | if (mode == QLatin1String("none")) { |
| 21 | return Input::NoReconnect; |
| 22 | } else if (mode == QLatin1String("host")) { |
| 23 | return Input::HostReconnect; |
| 24 | } else if (mode == QLatin1String("device")) { |
| 25 | return Input::DeviceReconnect; |
| 26 | } |
| 27 | return Input::AnyReconnect; |
| 28 | } |
| 29 | |
| 30 | InputPrivate::InputPrivate(const QString &path, const QVariantMap &properties) |
| 31 | : QObject() |
| 32 | , m_path(path) |
| 33 | { |
| 34 | // Init properties |
| 35 | m_reconnectMode = stringToReconnectMode(mode: properties.value(QStringLiteral("ReconnectMode")).toString()); |
| 36 | } |
| 37 | |
| 38 | void InputPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) |
| 39 | { |
| 40 | Q_UNUSED(invalidated) |
| 41 | |
| 42 | if (interface != Strings::orgBluezInput1()) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | QVariantMap::const_iterator i; |
| 47 | for (i = changed.constBegin(); i != changed.constEnd(); ++i) { |
| 48 | const QVariant &value = i.value(); |
| 49 | const QString &property = i.key(); |
| 50 | |
| 51 | if (property == QLatin1String("ReconnectMode")) { |
| 52 | PROPERTY_CHANGED2(m_reconnectMode, stringToReconnectMode(value.toString()), reconnectModeChanged); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | Input::Input(const QString &path, const QVariantMap &properties) |
| 58 | : d(new InputPrivate(path, properties)) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | Input::~Input() = default; |
| 63 | |
| 64 | InputPtr Input::toSharedPtr() const |
| 65 | { |
| 66 | return d->q.toStrongRef(); |
| 67 | } |
| 68 | |
| 69 | Input::ReconnectMode Input::reconnectMode() const |
| 70 | { |
| 71 | return d->m_reconnectMode; |
| 72 | } |
| 73 | |
| 74 | } // namespace BluezQt |
| 75 | |
| 76 | #include "moc_input.cpp" |
| 77 | #include "moc_input_p.cpp" |
| 78 |
