File indexing completed on 2024-12-08 12:15:34

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "input.h"
0010 #include "input_p.h"
0011 #include "macros.h"
0012 #include "utils.h"
0013 
0014 #include <QVariantMap>
0015 
0016 namespace BluezQt
0017 {
0018 static Input::ReconnectMode stringToReconnectMode(const QString &mode)
0019 {
0020     if (mode == QLatin1String("none")) {
0021         return Input::NoReconnect;
0022     } else if (mode == QLatin1String("host")) {
0023         return Input::HostReconnect;
0024     } else if (mode == QLatin1String("device")) {
0025         return Input::DeviceReconnect;
0026     }
0027     return Input::AnyReconnect;
0028 }
0029 
0030 InputPrivate::InputPrivate(const QString &path, const QVariantMap &properties)
0031     : QObject()
0032     , m_path(path)
0033 {
0034     // Init properties
0035     m_reconnectMode = stringToReconnectMode(properties.value(QStringLiteral("ReconnectMode")).toString());
0036 }
0037 
0038 void InputPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated)
0039 {
0040     Q_UNUSED(invalidated)
0041 
0042     if (interface != Strings::orgBluezInput1()) {
0043         return;
0044     }
0045 
0046     QVariantMap::const_iterator i;
0047     for (i = changed.constBegin(); i != changed.constEnd(); ++i) {
0048         const QVariant &value = i.value();
0049         const QString &property = i.key();
0050 
0051         if (property == QLatin1String("ReconnectMode")) {
0052             PROPERTY_CHANGED2(m_reconnectMode, stringToReconnectMode(value.toString()), reconnectModeChanged);
0053         }
0054     }
0055 }
0056 
0057 Input::Input(const QString &path, const QVariantMap &properties)
0058     : d(new InputPrivate(path, properties))
0059 {
0060 }
0061 
0062 Input::~Input()
0063 {
0064     delete d;
0065 }
0066 
0067 InputPtr Input::toSharedPtr() const
0068 {
0069     return d->q.toStrongRef();
0070 }
0071 
0072 Input::ReconnectMode Input::reconnectMode() const
0073 {
0074     return d->m_reconnectMode;
0075 }
0076 
0077 } // namespace BluezQt
0078 
0079 #include "moc_input.cpp"
0080 #include "moc_input_p.cpp"