Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[BluetoothAgent] Fixup connected status
  • Loading branch information
neochapay committed Apr 25, 2020
1 parent 81764f3 commit a4e942d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/bluetooth/bluetoothagent.cpp
Expand Up @@ -28,6 +28,7 @@
BluetoothAgent::BluetoothAgent(QObject *parent)
: BluezQt::Agent(parent)
{
m_connected = false;
m_manager = new BluezQt::Manager(this);

BluezQt::InitManagerJob *job = m_manager->init();
Expand Down Expand Up @@ -117,6 +118,9 @@ void BluetoothAgent::usableAdapterChanged(BluezQt::AdapterPtr adapter)
{
emit adapterAdded(adapter);
m_usableAdapter = adapter;

connect(m_usableAdapter.data(), &BluezQt::Adapter::connectedChanged,
this, &BluetoothAgent::updateConnectedStatus);
}
}

Expand Down Expand Up @@ -160,4 +164,17 @@ void BluetoothAgent::requestDefaultAgentFinished(BluezQt::PendingCall *call)
qDebug() << "BT: bt agent registring as system" << objectPath().path();
}

void BluetoothAgent::updateConnectedStatus()
{
if(m_connected != m_usableAdapter->isConnected())
{
m_connected = m_usableAdapter->isConnected();
emit connectedChanged();
}
}

bool BluetoothAgent::isConnected()
{
return m_connected;
}

12 changes: 8 additions & 4 deletions src/bluetooth/bluetoothagent.h
Expand Up @@ -2,9 +2,6 @@
#define BLUETOOTHAGENT_H

#include <QObject>

#include <QDBusObjectPath>
#include <agent.h>
// This file is part of glacier-home, a nice user experience for NemoMobile.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -27,15 +24,18 @@
//
// Copyright (c) 2020, Chupligin Sergey <neochapay@gmail.com>

#include <adapter.h>
#include <QDBusObjectPath>

#include <agent.h>
#include <adapter.h>
#include <request.h>
#include <manager.h>
#include <pendingcall.h>

class BluetoothAgent : public BluezQt::Agent
{
Q_OBJECT
Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged)
public:
BluetoothAgent(QObject *parent = Q_NULLPTR);
QDBusObjectPath objectPath() const;
Expand All @@ -49,10 +49,12 @@ class BluetoothAgent : public BluezQt::Agent
Q_INVOKABLE void unPair(const QString &btMacAddress);

Q_INVOKABLE void connectDevice(const QString &btMacAddress);
bool isConnected();

signals:
void adapterAdded(const BluezQt::AdapterPtr adapter);
void showRequiesDialog(const QString btMacAddres, const QString name, const QString code);
void connectedChanged();

private:
void initManagerJobResult(BluezQt::InitManagerJob *job);
Expand All @@ -61,9 +63,11 @@ class BluetoothAgent : public BluezQt::Agent

void usableAdapterChanged(BluezQt::AdapterPtr adapter);
void connectToDevice(BluezQt::PendingCall *call);
void updateConnectedStatus();

BluezQt::Manager *m_manager;
BluezQt::AdapterPtr m_usableAdapter;
bool m_connected;
};

#endif // BLUETOOTHAGENT_H
9 changes: 8 additions & 1 deletion src/qml/statusbar/BluetoothIndicator.qml
Expand Up @@ -8,11 +8,18 @@ StatusbarItem {
source: "/usr/share/lipstick-glacier-home-qt5/qml/theme/icon_bluetooth.png"
visible: bluetoothTechnology.powered

transparent: !bluetoothTechnology.connected
transparent: true


NetworkTechnology {
id: bluetoothTechnology
path: "/net/connman/technology/bluetooth"
}

Connections{
target: btAgent
onConnectedChanged: {
bluetoothIndicator.transparent = !btAgent.connected
}
}
}

0 comments on commit a4e942d

Please sign in to comment.