Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugins/dde-dock/bluetooth/componments/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
const Device::State state = Device::State(deviceObj["State"].toInt());
const bool connectState = deviceObj["ConnectState"].toBool();
const QString bluetoothDeviceType = deviceObj["Icon"].toString();
const int battery = deviceObj["Battery"].toInt();

removeDevice(id);

Expand All @@ -52,6 +53,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
device->setRssi(rssi);
device->setAdapterId(m_id);
device->setDeviceType(bluetoothDeviceType);
device->setBattery(battery);

m_devices[id] = device;

Expand Down Expand Up @@ -79,6 +81,7 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
const Device::State state = Device::State(dviceJson["State"].toInt());
const bool connectState = dviceJson["ConnectState"].toBool();
const QString bluetoothDeviceType = dviceJson["Icon"].toString();
const int battery = dviceJson["Battery"].toInt();

// FIXME: Solve the problem that the device name in the Bluetooth list is blank
if (name.isEmpty() && alias.isEmpty())
Expand All @@ -96,6 +99,7 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
device->setConnectState(connectState);
device->setState(state);
device->setDeviceType(bluetoothDeviceType);
device->setBattery(battery);
emit deviceNameUpdated(device);
}
}
Expand All @@ -122,6 +126,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
const Device::State state = Device::State(deviceObj["State"].toInt());
const bool connectState = deviceObj["ConnectState"].toBool();
const QString bluetoothDeviceType = deviceObj["Icon"].toString();
const int battery = deviceObj["Battery"].toInt();

auto device = new Device(this);
device->setId(id);
Expand All @@ -133,6 +138,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
device->setRssi(rssi);
device->setAdapterId(adapterId);
device->setDeviceType(bluetoothDeviceType);
device->setBattery(battery);

m_devices[id] = device;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ BluetoothDeviceItem::BluetoothDeviceItem(QStyle *style, const Device *device, Pl
updateDeviceState(m_device->state());

initConnect();

m_standardItem->updateBattery(m_device->battery());
connect(m_device, &Device::batteryChanged, this, [this](int battery) {
m_standardItem->updateBattery(battery);
});
}

BluetoothDeviceItem::~BluetoothDeviceItem()
Expand Down
9 changes: 9 additions & 0 deletions plugins/dde-dock/bluetooth/componments/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Device::Device(QObject *parent)
, m_rssi(0)
, m_state(StateUnavailable)
, m_connectState(false)
, m_battery(0)
{
}

Expand Down Expand Up @@ -101,6 +102,14 @@ void Device::setRssi(int rssi)
}
}

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

void Device::setDeviceType(const QString &deviceType)
{
m_deviceType = deviceType2Icon[deviceType];
Expand Down
5 changes: 5 additions & 0 deletions plugins/dde-dock/bluetooth/componments/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@
void setRssi(int rssi);

inline void setAdapterId(const QString &id) { m_adapterId = id; }
inline const QString &getAdapterId() const { return m_adapterId; }

Check warning on line 56 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getAdapterId' is never used.

inline int battery() const { return m_battery; }

Check warning on line 58 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'battery' is never used.
void setBattery(const int battery);

inline QString deviceType() const { return m_deviceType; }

Check warning on line 61 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'deviceType' is never used.
void setDeviceType(const QString &deviceType);

Q_SIGNALS:
void nameChanged(const QString &name) const;
void aliasChanged(const QString &alias) const;
void pairedChanged(const bool paired) const;
void stateChanged(const State state) const;

Check warning on line 68 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'stateChanged' shadows outer function
void connectStateChanged(const bool connectState) const;

Check warning on line 69 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'connectStateChanged' shadows outer function
void rssiChanged(const int rssi) const;

Check warning on line 70 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'rssiChanged' shadows outer function
void batteryChanged(const int battery) const;

Check warning on line 71 in plugins/dde-dock/bluetooth/componments/device.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'batteryChanged' shadows outer function

private:
QString m_id;
Expand All @@ -76,6 +80,7 @@
int m_rssi;
State m_state;
bool m_connectState;
int m_battery;
QString m_adapterId;
QString m_deviceType;
};
Expand Down
22 changes: 22 additions & 0 deletions plugins/dde-dock/bluetooth/resources/bluetooth.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,27 @@
<file>texts/plugin_item_select_16px.svg</file>
<file>texts/refresh_16px.svg</file>
<file>texts/arrow-up_12px.svg</file>
<file>icons/battery-000-symbolic.svg</file>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种buildin的icon,可以按照资源路径的方式去区分暗亮色,而不是图标命名的方式,

<file>icons/battery-010-symbolic.svg</file>
<file>icons/battery-020-symbolic.svg</file>
<file>icons/battery-030-symbolic.svg</file>
<file>icons/battery-040-symbolic.svg</file>
<file>icons/battery-050-symbolic.svg</file>
<file>icons/battery-060-symbolic.svg</file>
<file>icons/battery-070-symbolic.svg</file>
<file>icons/battery-080-symbolic.svg</file>
<file>icons/battery-090-symbolic.svg</file>
<file>icons/battery-100-symbolic.svg</file>
<file>icons/battery-000-symbolic-dark.svg</file>
<file>icons/battery-010-symbolic-dark.svg</file>
<file>icons/battery-020-symbolic-dark.svg</file>
<file>icons/battery-030-symbolic-dark.svg</file>
<file>icons/battery-040-symbolic-dark.svg</file>
<file>icons/battery-050-symbolic-dark.svg</file>
<file>icons/battery-060-symbolic-dark.svg</file>
<file>icons/battery-070-symbolic-dark.svg</file>
<file>icons/battery-080-symbolic-dark.svg</file>
<file>icons/battery-090-symbolic-dark.svg</file>
<file>icons/battery-100-symbolic-dark.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
Loading