Add bluez module
parent
40dd871f08
commit
01ac677dae
@ -0,0 +1,26 @@
|
|||||||
|
set(bluezqtextensionplugin_SRCS
|
||||||
|
declarativemanager.cpp
|
||||||
|
declarativeadapter.cpp
|
||||||
|
# declarativebattery.cpp
|
||||||
|
declarativedevice.cpp
|
||||||
|
declarativeinput.cpp
|
||||||
|
declarativemediaplayer.cpp
|
||||||
|
declarativedevicesmodel.cpp
|
||||||
|
bluezqtextensionplugin.cpp
|
||||||
|
applet/devicesproxymodel.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(cutefishbluez_qmlplugins SHARED ${bluezqtextensionplugin_SRCS})
|
||||||
|
|
||||||
|
find_package(KF5BluezQt REQUIRED)
|
||||||
|
|
||||||
|
target_link_libraries(cutefishbluez_qmlplugins
|
||||||
|
Qt5::Core
|
||||||
|
Qt5::Qml
|
||||||
|
Qt5::DBus
|
||||||
|
KF5::BluezQt
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS cutefishbluez_qmlplugins DESTINATION ${INSTALL_QMLDIR}/Cutefish/Bluez)
|
||||||
|
install(FILES DevicesModel.qml DESTINATION ${INSTALL_QMLDIR}/Cutefish/Bluez)
|
||||||
|
install(FILES qmldir DESTINATION ${INSTALL_QMLDIR}/Cutefish/Bluez)
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Cutefish.Bluez 1.0 as Bluez
|
||||||
|
|
||||||
|
Bluez.DevicesModelPrivate {
|
||||||
|
manager: Bluez.Manager
|
||||||
|
}
|
||||||
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "devicesproxymodel.h"
|
||||||
|
|
||||||
|
#include <BluezQt/Adapter>
|
||||||
|
#include <BluezQt/Device>
|
||||||
|
|
||||||
|
DevicesProxyModel::DevicesProxyModel(QObject *parent)
|
||||||
|
: QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
setDynamicSortFilter(true);
|
||||||
|
sort(0, Qt::DescendingOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> DevicesProxyModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles = QSortFilterProxyModel::roleNames();
|
||||||
|
roles[SectionRole] = QByteArrayLiteral("Section");
|
||||||
|
roles[DeviceFullNameRole] = QByteArrayLiteral("DeviceFullName");
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DevicesProxyModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
switch (role) {
|
||||||
|
case SectionRole:
|
||||||
|
if (index.data(BluezQt::DevicesModel::ConnectedRole).toBool()) {
|
||||||
|
return QStringLiteral("Connected");
|
||||||
|
}
|
||||||
|
return QStringLiteral("Available");
|
||||||
|
|
||||||
|
case DeviceFullNameRole:
|
||||||
|
if (duplicateIndexAddress(index)) {
|
||||||
|
const QString &name = QSortFilterProxyModel::data(index, BluezQt::DevicesModel::NameRole).toString();
|
||||||
|
const QString &ubi = QSortFilterProxyModel::data(index, BluezQt::DevicesModel::UbiRole).toString();
|
||||||
|
const QString &hci = adapterHciString(ubi);
|
||||||
|
|
||||||
|
if (!hci.isEmpty()) {
|
||||||
|
return QStringLiteral("%1 - %2").arg(name, hci);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QSortFilterProxyModel::data(index, BluezQt::DevicesModel::NameRole);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return QSortFilterProxyModel::data(index, role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DevicesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||||
|
{
|
||||||
|
bool leftConnected = left.data(BluezQt::DevicesModel::ConnectedRole).toBool();
|
||||||
|
bool rightConnected = right.data(BluezQt::DevicesModel::ConnectedRole).toBool();
|
||||||
|
|
||||||
|
if (leftConnected < rightConnected) {
|
||||||
|
return true;
|
||||||
|
} else if (leftConnected > rightConnected) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &leftName = left.data(BluezQt::DevicesModel::NameRole).toString();
|
||||||
|
const QString &rightName = right.data(BluezQt::DevicesModel::NameRole).toString();
|
||||||
|
|
||||||
|
return QString::localeAwareCompare(leftName, rightName) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns "hciX" part from UBI "/org/bluez/hciX/dev_xx_xx_xx_xx_xx_xx"
|
||||||
|
QString DevicesProxyModel::adapterHciString(const QString &ubi) const
|
||||||
|
{
|
||||||
|
int startIndex = ubi.indexOf(QLatin1String("/hci")) + 1;
|
||||||
|
|
||||||
|
if (startIndex < 1) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int endIndex = ubi.indexOf(QLatin1Char('/'), startIndex);
|
||||||
|
|
||||||
|
if (endIndex == -1) {
|
||||||
|
return ubi.mid(startIndex);
|
||||||
|
}
|
||||||
|
return ubi.mid(startIndex, endIndex - startIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DevicesProxyModel::duplicateIndexAddress(const QModelIndex &idx) const
|
||||||
|
{
|
||||||
|
const QModelIndexList &list = match(index(0, 0), //
|
||||||
|
BluezQt::DevicesModel::AddressRole,
|
||||||
|
idx.data(BluezQt::DevicesModel::AddressRole).toString(),
|
||||||
|
2,
|
||||||
|
Qt::MatchExactly);
|
||||||
|
return list.size() > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DevicesProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||||
|
{
|
||||||
|
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
|
||||||
|
// Only show paired devices in the KCM and applet
|
||||||
|
return index.data(BluezQt::DevicesModel::PairedRole).toBool();
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DEVICESPROXYMODEL_H
|
||||||
|
#define DEVICESPROXYMODEL_H
|
||||||
|
|
||||||
|
#include <BluezQt/DevicesModel>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
class DevicesProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum AdditionalRoles {
|
||||||
|
SectionRole = BluezQt::DevicesModel::LastRole + 10,
|
||||||
|
DeviceFullNameRole = BluezQt::DevicesModel::LastRole + 11,
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit DevicesProxyModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||||
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||||
|
|
||||||
|
Q_INVOKABLE QString adapterHciString(const QString &ubi) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool duplicateIndexAddress(const QModelIndex &idx) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICESPROXYMODEL_H
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bluezqtextensionplugin.h"
|
||||||
|
#include "declarativeadapter.h"
|
||||||
|
// #include "declarativebattery.h"
|
||||||
|
#include "declarativedevice.h"
|
||||||
|
#include "declarativedevicesmodel.h"
|
||||||
|
#include "declarativeinput.h"
|
||||||
|
#include "declarativemanager.h"
|
||||||
|
#include "declarativemediaplayer.h"
|
||||||
|
|
||||||
|
#include "applet/devicesproxymodel.h"
|
||||||
|
|
||||||
|
#include <BluezQt/Device>
|
||||||
|
#include <BluezQt/PendingCall>
|
||||||
|
#include <BluezQt/Rfkill>
|
||||||
|
#include <BluezQt/Services>
|
||||||
|
|
||||||
|
#include <QtQml> // krazy:exclude=includes
|
||||||
|
|
||||||
|
static QObject *manager_singleton(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||||
|
{
|
||||||
|
Q_UNUSED(engine)
|
||||||
|
Q_UNUSED(scriptEngine)
|
||||||
|
|
||||||
|
return new DeclarativeManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QJSValue services_singleton(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||||
|
{
|
||||||
|
Q_UNUSED(engine)
|
||||||
|
|
||||||
|
QJSValue object = scriptEngine->newObject();
|
||||||
|
object.setProperty(QStringLiteral("ServiceDiscoveryServer"), BluezQt::Services::ServiceDiscoveryServer);
|
||||||
|
object.setProperty(QStringLiteral("SerialPort"), BluezQt::Services::SerialPort);
|
||||||
|
object.setProperty(QStringLiteral("DialupNetworking"), BluezQt::Services::DialupNetworking);
|
||||||
|
object.setProperty(QStringLiteral("ObexObjectPush"), BluezQt::Services::ObexObjectPush);
|
||||||
|
object.setProperty(QStringLiteral("ObexFileTransfer"), BluezQt::Services::ObexFileTransfer);
|
||||||
|
object.setProperty(QStringLiteral("Headset"), BluezQt::Services::Headset);
|
||||||
|
object.setProperty(QStringLiteral("AudioSource"), BluezQt::Services::AudioSource);
|
||||||
|
object.setProperty(QStringLiteral("AudioVideoRemoteControlTarget"), BluezQt::Services::AudioVideoRemoteControlTarget);
|
||||||
|
object.setProperty(QStringLiteral("AdvancedAudioDistribution"), BluezQt::Services::AdvancedAudioDistribution);
|
||||||
|
object.setProperty(QStringLiteral("AudioVideoRemoteControl"), BluezQt::Services::AudioVideoRemoteControl);
|
||||||
|
object.setProperty(QStringLiteral("HeadsetAudioGateway"), BluezQt::Services::HeadsetAudioGateway);
|
||||||
|
object.setProperty(QStringLiteral("Panu"), BluezQt::Services::Panu);
|
||||||
|
object.setProperty(QStringLiteral("Nap"), BluezQt::Services::Nap);
|
||||||
|
object.setProperty(QStringLiteral("Handsfree"), BluezQt::Services::Handsfree);
|
||||||
|
object.setProperty(QStringLiteral("HandsfreeAudioGateway"), BluezQt::Services::HandsfreeAudioGateway);
|
||||||
|
object.setProperty(QStringLiteral("HumanInterfaceDevice"), BluezQt::Services::HumanInterfaceDevice);
|
||||||
|
object.setProperty(QStringLiteral("SimAccess"), BluezQt::Services::SimAccess);
|
||||||
|
object.setProperty(QStringLiteral("PhonebookAccessServer"), BluezQt::Services::PhonebookAccessServer);
|
||||||
|
object.setProperty(QStringLiteral("MessageAccessServer"), BluezQt::Services::MessageAccessServer);
|
||||||
|
object.setProperty(QStringLiteral("PnpInformation"), BluezQt::Services::PnpInformation);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluezQtExtensionPlugin::registerTypes(const char *uri)
|
||||||
|
{
|
||||||
|
using namespace BluezQt;
|
||||||
|
|
||||||
|
Q_ASSERT(QLatin1String(uri) == QLatin1String("Cutefish.Bluez"));
|
||||||
|
|
||||||
|
qmlRegisterType<DevicesProxyModel>(uri, 1, 0, "DevicesProxyModel");
|
||||||
|
|
||||||
|
qmlRegisterSingletonType<DeclarativeManager>(uri, 1, 0, "Manager", manager_singleton);
|
||||||
|
qmlRegisterType<DeclarativeDevicesModel>(uri, 1, 0, "DevicesModelPrivate");
|
||||||
|
qmlRegisterUncreatableType<DeclarativeAdapter>(uri, 1, 0, "Adapter", QStringLiteral("Adapter cannot be created"));
|
||||||
|
// qmlRegisterUncreatableType<DeclarativeBattery>(uri, 1, 0, "Battery", QStringLiteral("Battery cannot be created"));
|
||||||
|
qmlRegisterUncreatableType<DeclarativeDevice>(uri, 1, 0, "Device", QStringLiteral("Device cannot be created"));
|
||||||
|
qmlRegisterUncreatableType<DeclarativeInput>(uri, 1, 0, "Input", QStringLiteral("Input cannot be created"));
|
||||||
|
qmlRegisterUncreatableType<DeclarativeMediaPlayer>(uri, 1, 0, "MediaPlayer", QStringLiteral("MediaPlayer cannot be created"));
|
||||||
|
qmlRegisterUncreatableType<PendingCall>(uri, 1, 0, "PendingCall", QStringLiteral("PendingCall cannot be created"));
|
||||||
|
qmlRegisterUncreatableType<Rfkill>(uri, 1, 0, "Rfkill", QStringLiteral("Rfkill cannot be created"));
|
||||||
|
qmlRegisterSingletonType(uri, 1, 0, "Services", services_singleton);
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLUEZQTEXTENSIONPLUGIN_H
|
||||||
|
#define BLUEZQTEXTENSIONPLUGIN_H
|
||||||
|
|
||||||
|
#include <QQmlExtensionPlugin>
|
||||||
|
|
||||||
|
class BluezQtExtensionPlugin : public QQmlExtensionPlugin
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PLUGIN_METADATA(IID "Cutefish.Bluez")
|
||||||
|
|
||||||
|
public:
|
||||||
|
void registerTypes(const char *uri) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BLUEZQTEXTENSIONPLUGIN_H
|
||||||
@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativeadapter.h"
|
||||||
|
#include "declarativedevice.h"
|
||||||
|
|
||||||
|
static int devicesCountDeclarativeAdapterFunction(QQmlListProperty<DeclarativeDevice> *property)
|
||||||
|
{
|
||||||
|
Q_ASSERT(qobject_cast<DeclarativeAdapter *>(property->object));
|
||||||
|
DeclarativeAdapter *adapter = static_cast<DeclarativeAdapter *>(property->object);
|
||||||
|
|
||||||
|
return adapter->m_devices.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
static DeclarativeDevice *devicesAtDeclarativeAdapterFunction(QQmlListProperty<DeclarativeDevice> *property, int index)
|
||||||
|
{
|
||||||
|
Q_ASSERT(qobject_cast<DeclarativeAdapter *>(property->object));
|
||||||
|
DeclarativeAdapter *adapter = static_cast<DeclarativeAdapter *>(property->object);
|
||||||
|
|
||||||
|
return adapter->m_devices.values().at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeAdapter::DeclarativeAdapter(BluezQt::AdapterPtr adapter, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_adapter(adapter)
|
||||||
|
{
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::nameChanged, this, &DeclarativeAdapter::nameChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::systemNameChanged, this, &DeclarativeAdapter::systemNameChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::adapterClassChanged, this, &DeclarativeAdapter::adapterClassChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::poweredChanged, this, &DeclarativeAdapter::poweredChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::discoverableChanged, this, &DeclarativeAdapter::discoverableChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::discoverableTimeoutChanged, this, &DeclarativeAdapter::discoverableTimeoutChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::pairableChanged, this, &DeclarativeAdapter::pairableChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::pairableTimeoutChanged, this, &DeclarativeAdapter::pairableTimeoutChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::discoveringChanged, this, &DeclarativeAdapter::discoveringChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::uuidsChanged, this, &DeclarativeAdapter::uuidsChanged);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::modaliasChanged, this, &DeclarativeAdapter::modaliasChanged);
|
||||||
|
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::deviceAdded, this, &DeclarativeAdapter::slotDeviceAdded);
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::deviceRemoved, this, &DeclarativeAdapter::slotDeviceRemoved);
|
||||||
|
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::adapterRemoved, this, [this]() {
|
||||||
|
Q_EMIT adapterRemoved(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::adapterChanged, this, [this]() {
|
||||||
|
Q_EMIT adapterChanged(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_adapter.data(), &BluezQt::Adapter::deviceChanged, this, [this](const BluezQt::DevicePtr &device) {
|
||||||
|
Q_EMIT deviceChanged(declarativeDeviceFromPtr(device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeAdapter::ubi() const
|
||||||
|
{
|
||||||
|
return m_adapter->ubi();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeAdapter::address() const
|
||||||
|
{
|
||||||
|
return m_adapter->address();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeAdapter::name() const
|
||||||
|
{
|
||||||
|
return m_adapter->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_adapter->setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeAdapter::systemName() const
|
||||||
|
{
|
||||||
|
return m_adapter->systemName();
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 DeclarativeAdapter::adapterClass() const
|
||||||
|
{
|
||||||
|
return m_adapter->adapterClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeAdapter::isPowered() const
|
||||||
|
{
|
||||||
|
return m_adapter->isPowered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::setPowered(bool powered)
|
||||||
|
{
|
||||||
|
m_adapter->setPowered(powered);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeAdapter::isDiscoverable() const
|
||||||
|
{
|
||||||
|
return m_adapter->isDiscoverable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::setDiscoverable(bool discoverable)
|
||||||
|
{
|
||||||
|
m_adapter->setDiscoverable(discoverable);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 DeclarativeAdapter::discoverableTimeout() const
|
||||||
|
{
|
||||||
|
return m_adapter->discoverableTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::setDiscoverableTimeout(quint32 timeout)
|
||||||
|
{
|
||||||
|
m_adapter->setDiscoverableTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeAdapter::isPairable() const
|
||||||
|
{
|
||||||
|
return m_adapter->isPairable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::setPairable(bool pairable)
|
||||||
|
{
|
||||||
|
m_adapter->setPairable(pairable);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 DeclarativeAdapter::pairableTimeout() const
|
||||||
|
{
|
||||||
|
return m_adapter->pairableTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::setPairableTimeout(quint32 timeout)
|
||||||
|
{
|
||||||
|
m_adapter->setPairableTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeAdapter::isDiscovering()
|
||||||
|
{
|
||||||
|
return m_adapter->isDiscovering();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList DeclarativeAdapter::uuids() const
|
||||||
|
{
|
||||||
|
return m_adapter->uuids();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeAdapter::modalias() const
|
||||||
|
{
|
||||||
|
return m_adapter->modalias();
|
||||||
|
}
|
||||||
|
|
||||||
|
QQmlListProperty<DeclarativeDevice> DeclarativeAdapter::devices()
|
||||||
|
{
|
||||||
|
return QQmlListProperty<DeclarativeDevice>(this, nullptr, devicesCountDeclarativeAdapterFunction, devicesAtDeclarativeAdapterFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeDevice *DeclarativeAdapter::deviceForAddress(const QString &address) const
|
||||||
|
{
|
||||||
|
return declarativeDeviceFromPtr(m_adapter->deviceForAddress(address));
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeAdapter::startDiscovery()
|
||||||
|
{
|
||||||
|
return m_adapter->startDiscovery();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeAdapter::stopDiscovery()
|
||||||
|
{
|
||||||
|
return m_adapter->stopDiscovery();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeAdapter::removeDevice(DeclarativeDevice *device)
|
||||||
|
{
|
||||||
|
return m_adapter->removeDevice(m_adapter->deviceForAddress(device->address()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::slotDeviceAdded(BluezQt::DevicePtr device)
|
||||||
|
{
|
||||||
|
Q_EMIT deviceFound(declarativeDeviceFromPtr(device));
|
||||||
|
Q_EMIT devicesChanged(devices());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeAdapter::slotDeviceRemoved(BluezQt::DevicePtr device)
|
||||||
|
{
|
||||||
|
Q_EMIT deviceRemoved(declarativeDeviceFromPtr(device));
|
||||||
|
Q_EMIT devicesChanged(devices());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeDevice *DeclarativeAdapter::declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const
|
||||||
|
{
|
||||||
|
if (!ptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return m_devices.value(ptr->ubi());
|
||||||
|
}
|
||||||
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEADAPTER_H
|
||||||
|
#define DECLARATIVEADAPTER_H
|
||||||
|
|
||||||
|
#include <QQmlListProperty>
|
||||||
|
|
||||||
|
#include <BluezQt/Adapter>
|
||||||
|
|
||||||
|
class DeclarativeDevice;
|
||||||
|
|
||||||
|
class DeclarativeAdapter : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString ubi READ ubi CONSTANT)
|
||||||
|
Q_PROPERTY(QString address READ address CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(QString systemName READ systemName NOTIFY systemNameChanged)
|
||||||
|
Q_PROPERTY(quint32 adapterClass READ adapterClass NOTIFY adapterClassChanged)
|
||||||
|
Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged)
|
||||||
|
Q_PROPERTY(bool discoverable READ isDiscoverable WRITE setDiscoverable NOTIFY discoverableChanged)
|
||||||
|
Q_PROPERTY(quint32 discoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout NOTIFY discoverableTimeoutChanged)
|
||||||
|
Q_PROPERTY(bool pairable READ isPairable WRITE setPairable NOTIFY pairableChanged)
|
||||||
|
Q_PROPERTY(quint32 pairableTimeout READ pairableTimeout WRITE setPairableTimeout NOTIFY pairableTimeoutChanged)
|
||||||
|
Q_PROPERTY(bool discovering READ isDiscovering NOTIFY discoveringChanged)
|
||||||
|
Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged)
|
||||||
|
Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged)
|
||||||
|
Q_PROPERTY(QQmlListProperty<DeclarativeDevice> devices READ devices NOTIFY devicesChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeclarativeAdapter(BluezQt::AdapterPtr adapter, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QString ubi() const;
|
||||||
|
|
||||||
|
QString address() const;
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QString systemName() const;
|
||||||
|
|
||||||
|
quint32 adapterClass() const;
|
||||||
|
|
||||||
|
bool isPowered() const;
|
||||||
|
void setPowered(bool powered);
|
||||||
|
|
||||||
|
bool isDiscoverable() const;
|
||||||
|
void setDiscoverable(bool discoverable);
|
||||||
|
|
||||||
|
quint32 discoverableTimeout() const;
|
||||||
|
void setDiscoverableTimeout(quint32 timeout);
|
||||||
|
|
||||||
|
bool isPairable() const;
|
||||||
|
void setPairable(bool pairable);
|
||||||
|
|
||||||
|
quint32 pairableTimeout() const;
|
||||||
|
void setPairableTimeout(quint32 timeout);
|
||||||
|
|
||||||
|
bool isDiscovering();
|
||||||
|
|
||||||
|
QStringList uuids() const;
|
||||||
|
|
||||||
|
QString modalias() const;
|
||||||
|
|
||||||
|
QQmlListProperty<DeclarativeDevice> devices();
|
||||||
|
|
||||||
|
BluezQt::AdapterPtr m_adapter;
|
||||||
|
QHash<QString, DeclarativeDevice *> m_devices;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
DeclarativeDevice *deviceForAddress(const QString &address) const;
|
||||||
|
BluezQt::PendingCall *startDiscovery();
|
||||||
|
BluezQt::PendingCall *stopDiscovery();
|
||||||
|
BluezQt::PendingCall *removeDevice(DeclarativeDevice *device);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void adapterRemoved(DeclarativeAdapter *adapter);
|
||||||
|
void adapterChanged(DeclarativeAdapter *adapter);
|
||||||
|
void nameChanged(const QString &name);
|
||||||
|
void systemNameChanged(const QString &name);
|
||||||
|
void adapterClassChanged(quint32 adapterClass);
|
||||||
|
void poweredChanged(bool powered);
|
||||||
|
void discoverableChanged(bool discoverable);
|
||||||
|
void discoverableTimeoutChanged(quint32 timeout);
|
||||||
|
void pairableChanged(bool pairable);
|
||||||
|
void pairableTimeoutChanged(quint32 timeout);
|
||||||
|
void discoveringChanged(bool discovering);
|
||||||
|
void uuidsChanged(const QStringList &uuids);
|
||||||
|
void modaliasChanged(const QString &modalias);
|
||||||
|
void deviceFound(DeclarativeDevice *device);
|
||||||
|
void deviceRemoved(DeclarativeDevice *device);
|
||||||
|
void deviceChanged(DeclarativeDevice *device);
|
||||||
|
|
||||||
|
void devicesChanged(QQmlListProperty<DeclarativeDevice> devices);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void slotDeviceAdded(BluezQt::DevicePtr device);
|
||||||
|
void slotDeviceRemoved(BluezQt::DevicePtr device);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeclarativeDevice *declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEADAPTER_H
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativebattery.h"
|
||||||
|
|
||||||
|
DeclarativeBattery::DeclarativeBattery(const BluezQt::BatteryPtr &battery, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_battery(battery)
|
||||||
|
{
|
||||||
|
connect(m_battery.data(), &BluezQt::Battery::percentageChanged, this, &DeclarativeBattery::percentageChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DeclarativeBattery::percentage() const
|
||||||
|
{
|
||||||
|
return m_battery->percentage();
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEBATTERY_H
|
||||||
|
#define DECLARATIVEBATTERY_H
|
||||||
|
|
||||||
|
#include <BluezQt/Device>
|
||||||
|
#include <BluezQt/Types>
|
||||||
|
|
||||||
|
class DeclarativeBattery : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int percentage READ percentage NOTIFY percentageChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeclarativeBattery(const BluezQt::BatteryPtr &battery, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
int percentage() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void percentageChanged(int percentage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BluezQt::BatteryPtr m_battery;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEBATTERY_H
|
||||||
@ -0,0 +1,246 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativedevice.h"
|
||||||
|
#include "declarativeadapter.h"
|
||||||
|
// #include "declarativebattery.h"
|
||||||
|
#include "declarativeinput.h"
|
||||||
|
#include "declarativemediaplayer.h"
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
DeclarativeDevice::DeclarativeDevice(BluezQt::DevicePtr device, DeclarativeAdapter *adapter)
|
||||||
|
: QObject(adapter)
|
||||||
|
, m_device(device)
|
||||||
|
, m_adapter(adapter)
|
||||||
|
// , m_battery(nullptr)
|
||||||
|
, m_input(nullptr)
|
||||||
|
, m_mediaPlayer(nullptr)
|
||||||
|
{
|
||||||
|
connect(m_device.data(), &BluezQt::Device::nameChanged, this, &DeclarativeDevice::nameChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::friendlyNameChanged, this, &DeclarativeDevice::friendlyNameChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::remoteNameChanged, this, &DeclarativeDevice::remoteNameChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::deviceClassChanged, this, &DeclarativeDevice::deviceClassChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::typeChanged, this, &DeclarativeDevice::typeChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::appearanceChanged, this, &DeclarativeDevice::appearanceChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::iconChanged, this, &DeclarativeDevice::iconChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::pairedChanged, this, &DeclarativeDevice::pairedChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::trustedChanged, this, &DeclarativeDevice::trustedChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::blockedChanged, this, &DeclarativeDevice::blockedChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::legacyPairingChanged, this, &DeclarativeDevice::legacyPairingChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::rssiChanged, this, &DeclarativeDevice::rssiChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::connectedChanged, this, &DeclarativeDevice::connectedChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::uuidsChanged, this, &DeclarativeDevice::uuidsChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::modaliasChanged, this, &DeclarativeDevice::modaliasChanged);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::mediaPlayerChanged, this, &DeclarativeDevice::updateMediaPlayer);
|
||||||
|
connect(m_device.data(), &BluezQt::Device::inputChanged, this, &DeclarativeDevice::updateInput);
|
||||||
|
// connect(m_device.data(), &BluezQt::Device::batteryChanged, this, &DeclarativeDevice::updateBattery);
|
||||||
|
|
||||||
|
connect(m_device.data(), &BluezQt::Device::deviceRemoved, this, [this]() {
|
||||||
|
Q_EMIT deviceRemoved(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_device.data(), &BluezQt::Device::deviceChanged, this, [this]() {
|
||||||
|
Q_EMIT deviceChanged(this);
|
||||||
|
});
|
||||||
|
|
||||||
|
updateInput();
|
||||||
|
updateMediaPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::ubi() const
|
||||||
|
{
|
||||||
|
return m_device->ubi();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::address() const
|
||||||
|
{
|
||||||
|
return m_device->address();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::name() const
|
||||||
|
{
|
||||||
|
return m_device->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevice::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_device->setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::friendlyName() const
|
||||||
|
{
|
||||||
|
return m_device->friendlyName();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::remoteName() const
|
||||||
|
{
|
||||||
|
return m_device->remoteName();
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 DeclarativeDevice::deviceClass() const
|
||||||
|
{
|
||||||
|
return m_device->deviceClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::Device::Type DeclarativeDevice::type() const
|
||||||
|
{
|
||||||
|
return m_device->type();
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 DeclarativeDevice::appearance() const
|
||||||
|
{
|
||||||
|
return m_device->appearance();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::icon() const
|
||||||
|
{
|
||||||
|
return m_device->icon();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeDevice::isPaired() const
|
||||||
|
{
|
||||||
|
return m_device->isPaired();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeDevice::isTrusted() const
|
||||||
|
{
|
||||||
|
return m_device->isTrusted();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevice::setTrusted(bool trusted)
|
||||||
|
{
|
||||||
|
m_device->setTrusted(trusted);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeDevice::isBlocked() const
|
||||||
|
{
|
||||||
|
return m_device->isBlocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevice::setBlocked(bool blocked)
|
||||||
|
{
|
||||||
|
m_device->setBlocked(blocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeDevice::hasLegacyPairing() const
|
||||||
|
{
|
||||||
|
return m_device->hasLegacyPairing();
|
||||||
|
}
|
||||||
|
|
||||||
|
qint16 DeclarativeDevice::rssi() const
|
||||||
|
{
|
||||||
|
return m_device->rssi();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeclarativeDevice::isConnected() const
|
||||||
|
{
|
||||||
|
return m_device->isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList DeclarativeDevice::uuids() const
|
||||||
|
{
|
||||||
|
return m_device->uuids();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeDevice::modalias() const
|
||||||
|
{
|
||||||
|
return m_device->modalias();
|
||||||
|
}
|
||||||
|
|
||||||
|
//DeclarativeBattery *DeclarativeDevice::battery() const
|
||||||
|
//{
|
||||||
|
// return m_battery;
|
||||||
|
//}
|
||||||
|
|
||||||
|
DeclarativeInput *DeclarativeDevice::input() const
|
||||||
|
{
|
||||||
|
return m_input;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeMediaPlayer *DeclarativeDevice::mediaPlayer() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeAdapter *DeclarativeDevice::adapter() const
|
||||||
|
{
|
||||||
|
return m_adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeDevice::connectToDevice()
|
||||||
|
{
|
||||||
|
return m_device->connectToDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeDevice::disconnectFromDevice()
|
||||||
|
{
|
||||||
|
return m_device->disconnectFromDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeDevice::connectProfile(const QString &uuid)
|
||||||
|
{
|
||||||
|
return m_device->connectProfile(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeDevice::disconnectProfile(const QString &uuid)
|
||||||
|
{
|
||||||
|
return m_device->disconnectProfile(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeDevice::pair()
|
||||||
|
{
|
||||||
|
return m_device->pair();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeDevice::cancelPairing()
|
||||||
|
{
|
||||||
|
return m_device->cancelPairing();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevice::updateBattery()
|
||||||
|
{
|
||||||
|
// if (m_battery) {
|
||||||
|
// m_battery->deleteLater();
|
||||||
|
// m_battery = nullptr;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (m_device->battery()) {
|
||||||
|
// m_battery = new DeclarativeBattery(m_device->battery(), this);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Q_EMIT batteryChanged(m_battery);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevice::updateInput()
|
||||||
|
{
|
||||||
|
if (m_input) {
|
||||||
|
m_input->deleteLater();
|
||||||
|
m_input = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_device->input()) {
|
||||||
|
m_input = new DeclarativeInput(m_device->input(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_EMIT inputChanged(m_input);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevice::updateMediaPlayer()
|
||||||
|
{
|
||||||
|
if (m_mediaPlayer) {
|
||||||
|
m_mediaPlayer->deleteLater();
|
||||||
|
m_mediaPlayer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_device->mediaPlayer()) {
|
||||||
|
m_mediaPlayer = new DeclarativeMediaPlayer(m_device->mediaPlayer(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_EMIT mediaPlayerChanged(m_mediaPlayer);
|
||||||
|
}
|
||||||
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEDEVICE_H
|
||||||
|
#define DECLARATIVEDEVICE_H
|
||||||
|
|
||||||
|
#include "declarativeinput.h"
|
||||||
|
#include "declarativemediaplayer.h"
|
||||||
|
|
||||||
|
#include <BluezQt/Device>
|
||||||
|
|
||||||
|
class DeclarativeAdapter;
|
||||||
|
// class DeclarativeBattery;
|
||||||
|
|
||||||
|
class DeclarativeDevice : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString ubi READ ubi CONSTANT)
|
||||||
|
Q_PROPERTY(QString address READ address CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(QString friendlyName READ friendlyName NOTIFY friendlyNameChanged)
|
||||||
|
Q_PROPERTY(QString remoteName READ remoteName NOTIFY remoteNameChanged)
|
||||||
|
Q_PROPERTY(quint32 deviceClass READ deviceClass NOTIFY deviceClassChanged)
|
||||||
|
Q_PROPERTY(BluezQt::Device::Type type READ type NOTIFY typeChanged)
|
||||||
|
Q_PROPERTY(quint16 appearance READ appearance NOTIFY appearanceChanged)
|
||||||
|
Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
|
||||||
|
Q_PROPERTY(bool paired READ isPaired NOTIFY pairedChanged)
|
||||||
|
Q_PROPERTY(bool trusted READ isTrusted WRITE setTrusted NOTIFY trustedChanged)
|
||||||
|
Q_PROPERTY(bool blocked READ isBlocked WRITE setBlocked NOTIFY blockedChanged)
|
||||||
|
Q_PROPERTY(bool legacyPairing READ hasLegacyPairing NOTIFY legacyPairingChanged)
|
||||||
|
Q_PROPERTY(qint16 rssi READ rssi NOTIFY rssiChanged)
|
||||||
|
Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged)
|
||||||
|
Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged)
|
||||||
|
Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged)
|
||||||
|
Q_PROPERTY(DeclarativeInput *input READ input NOTIFY inputChanged)
|
||||||
|
Q_PROPERTY(DeclarativeMediaPlayer *mediaPlayer READ mediaPlayer NOTIFY mediaPlayerChanged)
|
||||||
|
Q_PROPERTY(DeclarativeAdapter *adapter READ adapter CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeclarativeDevice(BluezQt::DevicePtr device, DeclarativeAdapter *adapter);
|
||||||
|
|
||||||
|
QString ubi() const;
|
||||||
|
|
||||||
|
QString address() const;
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
QString friendlyName() const;
|
||||||
|
|
||||||
|
QString remoteName() const;
|
||||||
|
|
||||||
|
quint32 deviceClass() const;
|
||||||
|
|
||||||
|
BluezQt::Device::Type type() const;
|
||||||
|
|
||||||
|
quint16 appearance() const;
|
||||||
|
|
||||||
|
QString icon() const;
|
||||||
|
|
||||||
|
bool isPaired() const;
|
||||||
|
|
||||||
|
bool isTrusted() const;
|
||||||
|
void setTrusted(bool trusted);
|
||||||
|
|
||||||
|
bool isBlocked() const;
|
||||||
|
void setBlocked(bool blocked);
|
||||||
|
|
||||||
|
bool hasLegacyPairing() const;
|
||||||
|
|
||||||
|
qint16 rssi() const;
|
||||||
|
|
||||||
|
bool isConnected() const;
|
||||||
|
|
||||||
|
QStringList uuids() const;
|
||||||
|
|
||||||
|
QString modalias() const;
|
||||||
|
|
||||||
|
// DeclarativeBattery *battery() const;
|
||||||
|
|
||||||
|
DeclarativeInput *input() const;
|
||||||
|
|
||||||
|
DeclarativeMediaPlayer *mediaPlayer() const;
|
||||||
|
|
||||||
|
DeclarativeAdapter *adapter() const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
BluezQt::PendingCall *connectToDevice();
|
||||||
|
BluezQt::PendingCall *disconnectFromDevice();
|
||||||
|
BluezQt::PendingCall *connectProfile(const QString &uuid);
|
||||||
|
BluezQt::PendingCall *disconnectProfile(const QString &uuid);
|
||||||
|
BluezQt::PendingCall *pair();
|
||||||
|
BluezQt::PendingCall *cancelPairing();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void deviceRemoved(DeclarativeDevice *device);
|
||||||
|
void deviceChanged(DeclarativeDevice *device);
|
||||||
|
void nameChanged(const QString &name);
|
||||||
|
void friendlyNameChanged(const QString &friendlyName);
|
||||||
|
void remoteNameChanged(const QString &remoteName);
|
||||||
|
void deviceClassChanged(quint32 deviceClass);
|
||||||
|
void typeChanged(BluezQt::Device::Type type);
|
||||||
|
void appearanceChanged(quint16 appearance);
|
||||||
|
void iconChanged(const QString &icon);
|
||||||
|
void pairedChanged(bool paired);
|
||||||
|
void trustedChanged(bool trusted);
|
||||||
|
void blockedChanged(bool blocked);
|
||||||
|
void legacyPairingChanged(bool legacyPairing);
|
||||||
|
void rssiChanged(qint16 rssi);
|
||||||
|
void connectedChanged(bool connected);
|
||||||
|
void uuidsChanged(const QStringList &uuids);
|
||||||
|
void modaliasChanged(const QString &modalias);
|
||||||
|
// void batteryChanged(DeclarativeBattery *battery);
|
||||||
|
void inputChanged(DeclarativeInput *input);
|
||||||
|
void mediaPlayerChanged(DeclarativeMediaPlayer *mediaPlayer);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateBattery();
|
||||||
|
void updateInput();
|
||||||
|
void updateMediaPlayer();
|
||||||
|
|
||||||
|
BluezQt::DevicePtr m_device;
|
||||||
|
DeclarativeAdapter *m_adapter;
|
||||||
|
// DeclarativeBattery *m_battery;
|
||||||
|
DeclarativeInput *m_input;
|
||||||
|
DeclarativeMediaPlayer *m_mediaPlayer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEDEVICE_H
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativedevicesmodel.h"
|
||||||
|
#include "declarativeadapter.h"
|
||||||
|
// #include "declarativebattery.h"
|
||||||
|
#include "declarativedevice.h"
|
||||||
|
#include "declarativemanager.h"
|
||||||
|
#include "declarativemediaplayer.h"
|
||||||
|
|
||||||
|
DeclarativeDevicesModel::DeclarativeDevicesModel(QObject *parent)
|
||||||
|
: QSortFilterProxyModel(parent)
|
||||||
|
, m_manager(nullptr)
|
||||||
|
, m_model(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeManager *DeclarativeDevicesModel::manager() const
|
||||||
|
{
|
||||||
|
return m_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeDevicesModel::setManager(DeclarativeManager *manager)
|
||||||
|
{
|
||||||
|
m_manager = manager;
|
||||||
|
m_model = new BluezQt::DevicesModel(m_manager, this);
|
||||||
|
setSourceModel(m_model);
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> DeclarativeDevicesModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles = QSortFilterProxyModel::roleNames();
|
||||||
|
|
||||||
|
roles[DeviceRole] = QByteArrayLiteral("Device");
|
||||||
|
roles[AdapterRole] = QByteArrayLiteral("Adapter");
|
||||||
|
roles[MediaPlayerRole] = QByteArrayLiteral("MediaPlayer");
|
||||||
|
// roles[BatteryRole] = QByteArrayLiteral("Battery");
|
||||||
|
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant DeclarativeDevicesModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!m_model) {
|
||||||
|
return QSortFilterProxyModel::data(index, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::DevicePtr dev = m_model->device(mapToSource(index));
|
||||||
|
if (!dev) {
|
||||||
|
return QSortFilterProxyModel::data(index, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case DeviceRole:
|
||||||
|
return QVariant::fromValue(m_manager->declarativeDeviceFromPtr(dev));
|
||||||
|
case AdapterRole:
|
||||||
|
return QVariant::fromValue(m_manager->declarativeAdapterFromPtr(dev->adapter()));
|
||||||
|
case MediaPlayerRole:
|
||||||
|
if (DeclarativeDevice *device = m_manager->declarativeDeviceFromPtr(dev)) {
|
||||||
|
return QVariant::fromValue(device->mediaPlayer());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// case BatteryRole:
|
||||||
|
// if (DeclarativeDevice *device = m_manager->declarativeDeviceFromPtr(dev)) {
|
||||||
|
// return QVariant::fromValue(device->battery());
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QSortFilterProxyModel::data(index, role);
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEDEVICESMODEL_H
|
||||||
|
#define DECLARATIVEDEVICESMODEL_H
|
||||||
|
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
#include "declarativemanager.h"
|
||||||
|
|
||||||
|
#include <BluezQt/DevicesModel>
|
||||||
|
|
||||||
|
class DeclarativeDevicesModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(DeclarativeManager *manager READ manager WRITE setManager)
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum DeclarativeDeviceRoles {
|
||||||
|
DeviceRole = BluezQt::DevicesModel::LastRole + 1,
|
||||||
|
AdapterRole = BluezQt::DevicesModel::LastRole + 2,
|
||||||
|
MediaPlayerRole = BluezQt::DevicesModel::LastRole + 3,
|
||||||
|
// BatteryRole = BluezQt::DevicesModel::LastRole + 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit DeclarativeDevicesModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
DeclarativeManager *manager() const;
|
||||||
|
void setManager(DeclarativeManager *manager);
|
||||||
|
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DeclarativeManager *m_manager;
|
||||||
|
BluezQt::DevicesModel *m_model;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEMANAGER_H
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativeinput.h"
|
||||||
|
|
||||||
|
DeclarativeInput::DeclarativeInput(const BluezQt::InputPtr &input, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_input(input)
|
||||||
|
{
|
||||||
|
connect(m_input.data(), &BluezQt::Input::reconnectModeChanged, this, &DeclarativeInput::reconnectModeChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::Input::ReconnectMode DeclarativeInput::reconnectMode() const
|
||||||
|
{
|
||||||
|
return m_input->reconnectMode();
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous BlueZ wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEINPUT_H
|
||||||
|
#define DECLARATIVEINPUT_H
|
||||||
|
|
||||||
|
#include <BluezQt/Input>
|
||||||
|
|
||||||
|
class DeclarativeInput : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(BluezQt::Input::ReconnectMode reconnectMode READ reconnectMode NOTIFY reconnectModeChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeclarativeInput(const BluezQt::InputPtr &input, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
BluezQt::Input::ReconnectMode reconnectMode() const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void reconnectModeChanged(BluezQt::Input::ReconnectMode mode);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BluezQt::InputPtr m_input;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEINPUT_H
|
||||||
@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativemanager.h"
|
||||||
|
#include "declarativeadapter.h"
|
||||||
|
#include "declarativedevice.h"
|
||||||
|
|
||||||
|
#include <BluezQt/InitManagerJob>
|
||||||
|
#include <BluezQt/Adapter>
|
||||||
|
#include <BluezQt/Device>
|
||||||
|
|
||||||
|
static int adaptersCountFunction(QQmlListProperty<DeclarativeAdapter> *property)
|
||||||
|
{
|
||||||
|
Q_ASSERT(qobject_cast<DeclarativeManager *>(property->object));
|
||||||
|
DeclarativeManager *manager = static_cast<DeclarativeManager *>(property->object);
|
||||||
|
|
||||||
|
return manager->m_adapters.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
static DeclarativeAdapter *adaptersAtFunction(QQmlListProperty<DeclarativeAdapter> *property, int index)
|
||||||
|
{
|
||||||
|
Q_ASSERT(qobject_cast<DeclarativeManager *>(property->object));
|
||||||
|
DeclarativeManager *manager = static_cast<DeclarativeManager *>(property->object);
|
||||||
|
|
||||||
|
return manager->m_adapters.values().at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int devicesCountFunction(QQmlListProperty<DeclarativeDevice> *property)
|
||||||
|
{
|
||||||
|
Q_ASSERT(qobject_cast<DeclarativeManager *>(property->object));
|
||||||
|
DeclarativeManager *manager = static_cast<DeclarativeManager *>(property->object);
|
||||||
|
|
||||||
|
return manager->m_devices.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
static DeclarativeDevice *devicesAtFunction(QQmlListProperty<DeclarativeDevice> *property, int index)
|
||||||
|
{
|
||||||
|
Q_ASSERT(qobject_cast<DeclarativeManager *>(property->object));
|
||||||
|
DeclarativeManager *manager = static_cast<DeclarativeManager *>(property->object);
|
||||||
|
|
||||||
|
return manager->m_devices.values().at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeManager::DeclarativeManager(QObject *parent)
|
||||||
|
: BluezQt::Manager(parent)
|
||||||
|
{
|
||||||
|
BluezQt::InitManagerJob *job = init();
|
||||||
|
job->start();
|
||||||
|
connect(job, &BluezQt::InitManagerJob::result, this, &DeclarativeManager::initJobResult);
|
||||||
|
|
||||||
|
connect(this, &BluezQt::Manager::adapterAdded, this, &DeclarativeManager::slotAdapterAdded);
|
||||||
|
connect(this, &BluezQt::Manager::adapterRemoved, this, &DeclarativeManager::slotAdapterRemoved);
|
||||||
|
connect(this, &BluezQt::Manager::usableAdapterChanged, this, &DeclarativeManager::slotUsableAdapterChanged);
|
||||||
|
connect(this, &BluezQt::Manager::deviceAdded, this, &DeclarativeManager::slotDeviceAdded);
|
||||||
|
connect(this, &BluezQt::Manager::deviceRemoved, this, &DeclarativeManager::slotDeviceRemoved);
|
||||||
|
|
||||||
|
connect(this, &BluezQt::Manager::adapterChanged, this, [this](const BluezQt::AdapterPtr &adapter) {
|
||||||
|
Q_EMIT adapterChanged(declarativeAdapterFromPtr(adapter));
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(this, &BluezQt::Manager::deviceChanged, this, [this](const BluezQt::DevicePtr &device) {
|
||||||
|
Q_EMIT deviceChanged(declarativeDeviceFromPtr(device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeAdapter *DeclarativeManager::usableAdapter() const
|
||||||
|
{
|
||||||
|
return declarativeAdapterFromPtr(BluezQt::Manager::usableAdapter());
|
||||||
|
}
|
||||||
|
|
||||||
|
QQmlListProperty<DeclarativeAdapter> DeclarativeManager::declarativeAdapters()
|
||||||
|
{
|
||||||
|
return QQmlListProperty<DeclarativeAdapter>(this, nullptr, adaptersCountFunction, adaptersAtFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
QQmlListProperty<DeclarativeDevice> DeclarativeManager::declarativeDevices()
|
||||||
|
{
|
||||||
|
return QQmlListProperty<DeclarativeDevice>(this, nullptr, devicesCountFunction, devicesAtFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeAdapter *DeclarativeManager::declarativeAdapterFromPtr(BluezQt::AdapterPtr ptr) const
|
||||||
|
{
|
||||||
|
if (!ptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return m_adapters.value(ptr->ubi());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeDevice *DeclarativeManager::declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const
|
||||||
|
{
|
||||||
|
if (!ptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return m_devices.value(ptr->ubi());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeAdapter *DeclarativeManager::adapterForAddress(const QString &address) const
|
||||||
|
{
|
||||||
|
return declarativeAdapterFromPtr(BluezQt::Manager::adapterForAddress(address));
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeAdapter *DeclarativeManager::adapterForUbi(const QString &ubi) const
|
||||||
|
{
|
||||||
|
return declarativeAdapterFromPtr(BluezQt::Manager::adapterForUbi(ubi));
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeDevice *DeclarativeManager::deviceForAddress(const QString &address) const
|
||||||
|
{
|
||||||
|
return declarativeDeviceFromPtr(BluezQt::Manager::deviceForAddress(address));
|
||||||
|
}
|
||||||
|
|
||||||
|
DeclarativeDevice *DeclarativeManager::deviceForUbi(const QString &ubi) const
|
||||||
|
{
|
||||||
|
return declarativeDeviceFromPtr(BluezQt::Manager::deviceForUbi(ubi));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeManager::initJobResult(BluezQt::InitManagerJob *job)
|
||||||
|
{
|
||||||
|
if (job->error()) {
|
||||||
|
Q_EMIT initError(job->errorText());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_EMIT initFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeManager::slotAdapterAdded(BluezQt::AdapterPtr adapter)
|
||||||
|
{
|
||||||
|
DeclarativeAdapter *dAdapter = new DeclarativeAdapter(adapter, this);
|
||||||
|
m_adapters[adapter->ubi()] = dAdapter;
|
||||||
|
|
||||||
|
Q_EMIT adapterAdded(dAdapter);
|
||||||
|
Q_EMIT adaptersChanged(declarativeAdapters());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeManager::slotAdapterRemoved(BluezQt::AdapterPtr adapter)
|
||||||
|
{
|
||||||
|
DeclarativeAdapter *dAdapter = m_adapters.take(adapter->ubi());
|
||||||
|
dAdapter->deleteLater();
|
||||||
|
|
||||||
|
Q_EMIT adapterRemoved(dAdapter);
|
||||||
|
Q_EMIT adaptersChanged(declarativeAdapters());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeManager::slotDeviceAdded(BluezQt::DevicePtr device)
|
||||||
|
{
|
||||||
|
DeclarativeAdapter *dAdapter = declarativeAdapterFromPtr(device->adapter());
|
||||||
|
DeclarativeDevice *dDevice = new DeclarativeDevice(device, dAdapter);
|
||||||
|
m_devices[device->ubi()] = dDevice;
|
||||||
|
dAdapter->m_devices[device->ubi()] = dDevice;
|
||||||
|
|
||||||
|
Q_EMIT deviceAdded(dDevice);
|
||||||
|
Q_EMIT devicesChanged(declarativeDevices());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeManager::slotDeviceRemoved(BluezQt::DevicePtr device)
|
||||||
|
{
|
||||||
|
DeclarativeDevice *dDevice = m_devices.take(device->ubi());
|
||||||
|
dDevice->adapter()->m_devices.take(device->ubi());
|
||||||
|
dDevice->deleteLater();
|
||||||
|
|
||||||
|
Q_EMIT deviceRemoved(dDevice);
|
||||||
|
Q_EMIT devicesChanged(declarativeDevices());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeManager::slotUsableAdapterChanged(BluezQt::AdapterPtr adapter)
|
||||||
|
{
|
||||||
|
Q_EMIT usableAdapterChanged(declarativeAdapterFromPtr(adapter));
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEMANAGER_H
|
||||||
|
#define DECLARATIVEMANAGER_H
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
#include <QQmlListProperty>
|
||||||
|
|
||||||
|
#include <BluezQt/Manager>
|
||||||
|
|
||||||
|
class DeclarativeDevice;
|
||||||
|
class DeclarativeAdapter;
|
||||||
|
|
||||||
|
class DeclarativeManager : public BluezQt::Manager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(DeclarativeAdapter *usableAdapter READ usableAdapter NOTIFY usableAdapterChanged)
|
||||||
|
Q_PROPERTY(QQmlListProperty<DeclarativeAdapter> adapters READ declarativeAdapters NOTIFY adaptersChanged)
|
||||||
|
Q_PROPERTY(QQmlListProperty<DeclarativeDevice> devices READ declarativeDevices NOTIFY devicesChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeclarativeManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
DeclarativeAdapter *usableAdapter() const;
|
||||||
|
QQmlListProperty<DeclarativeAdapter> declarativeAdapters();
|
||||||
|
QQmlListProperty<DeclarativeDevice> declarativeDevices();
|
||||||
|
|
||||||
|
DeclarativeAdapter *declarativeAdapterFromPtr(BluezQt::AdapterPtr ptr) const;
|
||||||
|
DeclarativeDevice *declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const;
|
||||||
|
|
||||||
|
QHash<QString, DeclarativeAdapter *> m_adapters;
|
||||||
|
QHash<QString, DeclarativeDevice *> m_devices;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
DeclarativeAdapter *adapterForAddress(const QString &address) const;
|
||||||
|
DeclarativeAdapter *adapterForUbi(const QString &ubi) const;
|
||||||
|
DeclarativeDevice *deviceForAddress(const QString &address) const;
|
||||||
|
DeclarativeDevice *deviceForUbi(const QString &ubi) const;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void initFinished();
|
||||||
|
void initError(const QString &errorText);
|
||||||
|
void adapterAdded(DeclarativeAdapter *adapter);
|
||||||
|
void adapterRemoved(DeclarativeAdapter *adapter);
|
||||||
|
void adapterChanged(DeclarativeAdapter *adapter);
|
||||||
|
void deviceAdded(DeclarativeDevice *device);
|
||||||
|
void deviceRemoved(DeclarativeDevice *device);
|
||||||
|
void deviceChanged(DeclarativeDevice *device);
|
||||||
|
void usableAdapterChanged(DeclarativeAdapter *adapter);
|
||||||
|
|
||||||
|
void adaptersChanged(QQmlListProperty<DeclarativeAdapter> adapters);
|
||||||
|
void devicesChanged(QQmlListProperty<DeclarativeDevice> devices);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void initJobResult(BluezQt::InitManagerJob *job);
|
||||||
|
|
||||||
|
void slotAdapterAdded(BluezQt::AdapterPtr adapter);
|
||||||
|
void slotAdapterRemoved(BluezQt::AdapterPtr adapter);
|
||||||
|
void slotDeviceAdded(BluezQt::DevicePtr device);
|
||||||
|
void slotDeviceRemoved(BluezQt::DevicePtr device);
|
||||||
|
void slotUsableAdapterChanged(BluezQt::AdapterPtr adapter);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEMANAGER_H
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "declarativemediaplayer.h"
|
||||||
|
|
||||||
|
DeclarativeMediaPlayer::DeclarativeMediaPlayer(BluezQt::MediaPlayerPtr mediaPlayer, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_mediaPlayer(mediaPlayer)
|
||||||
|
{
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::nameChanged, this, &DeclarativeMediaPlayer::nameChanged);
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::equalizerChanged, this, &DeclarativeMediaPlayer::equalizerChanged);
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::repeatChanged, this, &DeclarativeMediaPlayer::repeatChanged);
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::shuffleChanged, this, &DeclarativeMediaPlayer::shuffleChanged);
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::statusChanged, this, &DeclarativeMediaPlayer::statusChanged);
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::positionChanged, this, &DeclarativeMediaPlayer::positionChanged);
|
||||||
|
|
||||||
|
connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::trackChanged, this, [this]() {
|
||||||
|
updateTrack();
|
||||||
|
Q_EMIT trackChanged(m_track);
|
||||||
|
});
|
||||||
|
|
||||||
|
updateTrack();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DeclarativeMediaPlayer::name() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Equalizer DeclarativeMediaPlayer::equalizer() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->equalizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeMediaPlayer::setEqualizer(BluezQt::MediaPlayer::Equalizer equalizer)
|
||||||
|
{
|
||||||
|
m_mediaPlayer->setEqualizer(equalizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Repeat DeclarativeMediaPlayer::repeat() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->repeat();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeMediaPlayer::setRepeat(BluezQt::MediaPlayer::Repeat repeat)
|
||||||
|
{
|
||||||
|
m_mediaPlayer->setRepeat(repeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Shuffle DeclarativeMediaPlayer::shuffle() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->shuffle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeMediaPlayer::setShuffle(BluezQt::MediaPlayer::Shuffle shuffle)
|
||||||
|
{
|
||||||
|
m_mediaPlayer->setShuffle(shuffle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Status DeclarativeMediaPlayer::status() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->status();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject DeclarativeMediaPlayer::track() const
|
||||||
|
{
|
||||||
|
return m_track;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 DeclarativeMediaPlayer::position() const
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->position();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::play()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->play();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::pause()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::stop()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::next()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::previous()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::fastForward()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->fastForward();
|
||||||
|
}
|
||||||
|
|
||||||
|
BluezQt::PendingCall *DeclarativeMediaPlayer::rewind()
|
||||||
|
{
|
||||||
|
return m_mediaPlayer->rewind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeclarativeMediaPlayer::updateTrack()
|
||||||
|
{
|
||||||
|
m_track[QStringLiteral("valid")] = m_mediaPlayer->track().isValid();
|
||||||
|
m_track[QStringLiteral("title")] = m_mediaPlayer->track().title();
|
||||||
|
m_track[QStringLiteral("artist")] = m_mediaPlayer->track().artist();
|
||||||
|
m_track[QStringLiteral("album")] = m_mediaPlayer->track().album();
|
||||||
|
m_track[QStringLiteral("genre")] = m_mediaPlayer->track().genre();
|
||||||
|
m_track[QStringLiteral("numberOfTracks")] = qint64(m_mediaPlayer->track().numberOfTracks());
|
||||||
|
m_track[QStringLiteral("trackNumber")] = qint64(m_mediaPlayer->track().trackNumber());
|
||||||
|
m_track[QStringLiteral("duration")] = qint64(m_mediaPlayer->track().duration());
|
||||||
|
}
|
||||||
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* BluezQt - Asynchronous Bluez wrapper library
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DECLARATIVEMEDIAPLAYER_H
|
||||||
|
#define DECLARATIVEMEDIAPLAYER_H
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include <BluezQt/MediaPlayer>
|
||||||
|
|
||||||
|
class DeclarativeMediaPlayer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||||
|
Q_PROPERTY(BluezQt::MediaPlayer::Equalizer equalizer READ equalizer WRITE setEqualizer NOTIFY equalizerChanged)
|
||||||
|
Q_PROPERTY(BluezQt::MediaPlayer::Repeat repeat READ repeat WRITE setRepeat NOTIFY repeatChanged)
|
||||||
|
Q_PROPERTY(BluezQt::MediaPlayer::Shuffle shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged)
|
||||||
|
Q_PROPERTY(BluezQt::MediaPlayer::Status status READ status NOTIFY statusChanged)
|
||||||
|
Q_PROPERTY(QJsonObject track READ track NOTIFY trackChanged)
|
||||||
|
Q_PROPERTY(quint32 position READ position NOTIFY positionChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DeclarativeMediaPlayer(BluezQt::MediaPlayerPtr mediaPlayer, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Equalizer equalizer() const;
|
||||||
|
void setEqualizer(BluezQt::MediaPlayer::Equalizer equalizer);
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Repeat repeat() const;
|
||||||
|
void setRepeat(BluezQt::MediaPlayer::Repeat repeat);
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Shuffle shuffle() const;
|
||||||
|
void setShuffle(BluezQt::MediaPlayer::Shuffle shuffle);
|
||||||
|
|
||||||
|
BluezQt::MediaPlayer::Status status() const;
|
||||||
|
|
||||||
|
QJsonObject track() const;
|
||||||
|
|
||||||
|
quint32 position() const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
BluezQt::PendingCall *play();
|
||||||
|
BluezQt::PendingCall *pause();
|
||||||
|
BluezQt::PendingCall *stop();
|
||||||
|
BluezQt::PendingCall *next();
|
||||||
|
BluezQt::PendingCall *previous();
|
||||||
|
BluezQt::PendingCall *fastForward();
|
||||||
|
BluezQt::PendingCall *rewind();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void nameChanged(const QString &name);
|
||||||
|
void equalizerChanged(BluezQt::MediaPlayer::Equalizer equalizer);
|
||||||
|
void repeatChanged(BluezQt::MediaPlayer::Repeat repeat);
|
||||||
|
void shuffleChanged(BluezQt::MediaPlayer::Shuffle shuffle);
|
||||||
|
void statusChanged(BluezQt::MediaPlayer::Status status);
|
||||||
|
void trackChanged(const QJsonObject &track);
|
||||||
|
void positionChanged(quint32 position);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateTrack();
|
||||||
|
|
||||||
|
BluezQt::MediaPlayerPtr m_mediaPlayer;
|
||||||
|
QJsonObject m_track;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DECLARATIVEMEDIAPLAYER_H
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
module Cutefish.Bluez
|
||||||
|
plugin cutefishbluez_qmlplugins
|
||||||
|
|
||||||
|
DevicesModel 1.0 DevicesModel.qml
|
||||||
Loading…
Reference in New Issue