Skip to content

Commit

Permalink
feat: support show battery percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 16, 2023
1 parent 93bfd55 commit 2c4f0a6
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/plugin-bluetooth/operation/bluetoothadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void BluetoothAdapter::inflateDevice(BluetoothDevice *device, const QJsonObject
const BluetoothDevice::State state = BluetoothDevice::State(deviceObj["State"].toInt());
const bool connectState = deviceObj["ConnectState"].toBool();
const QString icon = deviceObj["Icon"].toString();
const int battery = deviceObj["Battery"].toInt();

// if (icon == "audio-card") {
// m_connectingAudioDevice = (BluetoothDevice::StateAvailable == state);
Expand All @@ -165,6 +166,7 @@ void BluetoothAdapter::inflateDevice(BluetoothDevice *device, const QJsonObject
device->setPaired(paired);
device->setState(state, connectState);
device->setDeviceType(icon);
device->setBattery(battery);
}

void BluetoothAdapter::onGetDevices(QString replyStr)
Expand Down
1 change: 1 addition & 0 deletions src/plugin-bluetooth/operation/bluetoothadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class BluetoothAdapter : public QObject

void inflate(const QJsonObject &obj);
void inflateDevice(BluetoothDevice *device, const QJsonObject &deviceObj);

public Q_SLOTS:
void addDevice(const BluetoothDevice *device);
void removeDevice(const QString &deviceId);
Expand Down
7 changes: 7 additions & 0 deletions src/plugin-bluetooth/operation/bluetoothdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ void BluetoothDevice::setConnecting(bool connecting)
}
}

void BluetoothDevice::setBattery(int battery) {
if (m_battery != battery) {
m_battery = battery;
Q_EMIT batteryChanged(battery);
}
}

void BluetoothDevice::setDeviceType(const QString &deviceType)
{
m_deviceType = deviceType;
Expand Down
6 changes: 6 additions & 0 deletions src/plugin-bluetooth/operation/bluetoothdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class BluetoothDevice : public QObject

void setId(const QString &id);

inline int battery() const { return m_battery; }

void setBattery(const int battery);

inline QString address() const { return m_address; }

void setAddress(const QString &addr);
Expand Down Expand Up @@ -73,6 +77,7 @@ class BluetoothDevice : public QObject
void stateChanged(const State &state, bool paired) const;
void trustedChanged(const bool trusted) const;
void connectingChanged(const bool &connecting) const;
void batteryChanged(const int battery) const;

private:
QString m_id;
Expand All @@ -85,6 +90,7 @@ class BluetoothDevice : public QObject
bool m_connecting;
bool m_connectState;
State m_state;
int m_battery = 0;
};

QDebug &operator<<(QDebug &stream, const BluetoothDevice *device);
Expand Down
2 changes: 2 additions & 0 deletions src/plugin-bluetooth/operation/bluetoothworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void BluetoothWorker::addDevice(const QString &json)
QJsonObject obj = doc.object();
const QString adapterId = obj["AdapterPath"].toString();
const QString id = obj["Path"].toString();
const int battery = obj["Battery"].toInt();

const BluetoothAdapter *result = m_model->adapterById(adapterId);
BluetoothAdapter *adapter = const_cast<BluetoothAdapter *>(result);
Expand All @@ -243,6 +244,7 @@ void BluetoothWorker::addDevice(const QString &json)
BluetoothDevice *device = const_cast<BluetoothDevice *>(result1);
if (!device)
device = new BluetoothDevice(adapter);
device->setBattery(battery);
adapter->inflateDevice(device, obj);
adapter->addDevice(device);
}
Expand Down
24 changes: 24 additions & 0 deletions src/plugin-bluetooth/operation/qrc/bluetooth.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,29 @@
<file>texts/bluetooth_other_16px.svg</file>
<file>texts/dcc_edit_12px.svg</file>
<file>texts/dcc_refresh_12px.svg</file>
<file>dark/icons/battery-000-symbolic_20px.svg</file>
<file>dark/icons/battery-010-symbolic_20px.svg</file>
<file>dark/icons/battery-020-symbolic_20px.svg</file>
<file>dark/icons/battery-030-symbolic_20px.svg</file>
<file>dark/icons/battery-040-symbolic_20px.svg</file>
<file>dark/icons/battery-050-symbolic_20px.svg</file>
<file>dark/icons/battery-060-symbolic_20px.svg</file>
<file>dark/icons/battery-070-symbolic_20px.svg</file>
<file>dark/icons/battery-080-symbolic_20px.svg</file>
<file>dark/icons/battery-090-symbolic_20px.svg</file>
<file>dark/icons/battery-100-symbolic_20px.svg</file>
<file>dark/icons/battery-unknow-symbolic_20px.svg</file>
<file>light/icons/battery-000-symbolic_20px.svg</file>
<file>light/icons/battery-010-symbolic_20px.svg</file>
<file>light/icons/battery-020-symbolic_20px.svg</file>
<file>light/icons/battery-030-symbolic_20px.svg</file>
<file>light/icons/battery-040-symbolic_20px.svg</file>
<file>light/icons/battery-050-symbolic_20px.svg</file>
<file>light/icons/battery-060-symbolic_20px.svg</file>
<file>light/icons/battery-070-symbolic_20px.svg</file>
<file>light/icons/battery-080-symbolic_20px.svg</file>
<file>light/icons/battery-090-symbolic_20px.svg</file>
<file>light/icons/battery-100-symbolic_20px.svg</file>
<file>light/icons/battery-unknow-symbolic_20px.svg</file>
</qresource>
</RCC>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2c4f0a6

Please sign in to comment.