Skip to content

feat(bluetooth): add battery level display for bluetooth devices - #487

Open
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:fork-from-master-0728/story-41279
Open

feat(bluetooth): add battery level display for bluetooth devices#487
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:fork-from-master-0728/story-41279

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
  1. Added battery property (m_battery, setter, getter, batteryChanged signal) to Device class
  2. Parse Battery field from JSON in Adapter's addDevice, updateDevice, initDevicesList
  3. Connect batteryChanged signal to updatePluginStandardItem in BluetoothAdapterItem
  4. Added battery icon and percentage label widgets in PluginItemWidget
  5. Added 20 SVG battery icons (0-100%) for light and dark themes, updated qrc

Log: Add Bluetooth device battery level display in the dock tray
Influence: Bluetooth device battery shown in dock

feat(bluetooth): 添加蓝牙设备电量显示功能

  1. Device 类新增 battery 属性(m_battery、setter、getter、batteryChanged 信号)
  2. Adapter 的 addDevice、updateDevice、initDevicesList 中解析 Battery 字段
  3. BluetoothAdapterItem 连接 batteryChanged 信号更新显示
  4. PluginItemWidget 新增电量图标和百分比标签控件
  5. 新增 20 个 SVG 电量图标(0-100%)支持明暗主题,更新 qrc 资源文件

Log: 在任务栏中显示蓝牙设备电量
PMS: STORY-41279
Influence: 任务栏显示蓝牙设备电量

Summary by Sourcery

Add Bluetooth device battery level display in the dock and propagate battery data from the backend device model to the UI.

New Features:

  • Display Bluetooth device battery percentage and icon in the dock item when the device is connected.
  • Parse and store Bluetooth device battery level from adapter JSON into the Device model and plugin item state.
  • Provide theme-aware battery icon variants for both light and dark modes via new SVG resources.

Enhancements:

  • Update plugin item hover and state handling to toggle between connection controls and battery indicators as appropriate.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @MyLeeJiEun, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

Hi @MyLeeJiEun. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements end-to-end Bluetooth device battery display in the dock by adding a battery field to Device/PluginStandardItem, wiring it through Adapter and BluetoothDeviceItem, and rendering a themed icon plus percentage text in PluginItemWidget using new SVG resources.

Sequence diagram for Bluetooth device battery propagation to dock UI

sequenceDiagram
    participant Adapter
    participant Device
    participant BluetoothDeviceItem
    participant PluginStandardItem
    participant PluginItemWidget

    Adapter->>Device: setBattery(battery)
    Device-->>BluetoothDeviceItem: batteryChanged(battery)
    BluetoothDeviceItem->>PluginStandardItem: updateBattery(battery)
    PluginStandardItem-->>PluginItemWidget: batteryChanged(battery)
    PluginItemWidget->>PluginItemWidget: updateBatteryDisplay(battery)
Loading

File-Level Changes

Change Details Files
Propagate Bluetooth device battery value through the data model and item abstraction.
  • Add m_battery field, getter, setter, and batteryChanged signal to Device, initialized to 0
  • Parse Battery from device JSON in Adapter::addDevice, updateDevice, and initDevicesList, and call Device::setBattery
  • Extend PluginStandardItem with m_battery field, battery() accessor, updateBattery(), and batteryChanged signal
  • In BluetoothDeviceItem, initialize PluginStandardItem battery from Device and connect Device::batteryChanged to update the standard item
plugins/dde-dock/bluetooth/componments/device.h
plugins/dde-dock/bluetooth/componments/device.cpp
plugins/dde-dock/bluetooth/componments/adapter.cpp
plugins/dde-dock/bluetooth/componments/bluetoothadapteritem.cpp
plugins/dde-dock/common/pluginitemdelegate.h
plugins/dde-dock/common/pluginitemdelegate.cpp
Render a battery icon and percentage in the dock Bluetooth item, with theme-aware icons and hover/state-dependent visibility.
  • Add DLabel members m_batteryIcon and m_batteryPercent to PluginItemWidget, create/configure them in the constructor, and insert them into the layout before the right-side controls
  • Introduce PluginItemWidget::updateBatteryDisplay() that picks a battery icon name by percentage, appends -dark in light theme, sets icon and text, and shows/hides the labels based on connection state, hover, and battery value
  • Call updateBatteryDisplay() when item state changes and on enter/leave events, and connect PluginStandardItem::batteryChanged and themeTypeChanged to refresh the display
  • Add batteryIconName() helper mapping battery percentage bands (<=5,10,...,100) to icon names and include DFontSizeManager for sizing the percentage label
plugins/dde-dock/common/pluginitemdelegate.cpp
plugins/dde-dock/common/pluginitemdelegate.h
Add themed SVG battery icon resources for use in the Bluetooth dock plugin.
  • Add 10 battery SVG icons (0–100% in 10% steps) for default theme and 10 corresponding -dark variants for light theme
  • Register the new battery icon paths in the Bluetooth plugin QRC so they are available via QIcon::fromTheme
plugins/dde-dock/bluetooth/resources/bluetooth.qrc
plugins/dde-dock/bluetooth/resources/icons/battery-000-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-010-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-020-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-030-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-040-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-050-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-060-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-070-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-080-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-090-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-100-symbolic.svg
plugins/dde-dock/bluetooth/resources/icons/battery-000-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-010-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-020-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-030-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-040-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-050-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-060-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-070-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-080-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-090-symbolic-dark.svg
plugins/dde-dock/bluetooth/resources/icons/battery-100-symbolic-dark.svg

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, MyLeeJiEun

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1. Added battery property (m_battery, setter, getter, batteryChanged signal) to Device class
2. Parse Battery field from JSON in Adapter's addDevice, updateDevice, initDevicesList
3. Connect batteryChanged signal to updatePluginStandardItem in BluetoothAdapterItem
4. Added battery icon and percentage label widgets in PluginItemWidget
5. Added 20 SVG battery icons (0-100%) for light and dark themes, updated qrc

Log: Add Bluetooth device battery level display in the dock tray
Influence: Bluetooth device battery shown in dock

feat(bluetooth): 添加蓝牙设备电量显示功能

1. Device 类新增 battery 属性(m_battery、setter、getter、batteryChanged 信号)
2. Adapter 的 addDevice、updateDevice、initDevicesList 中解析 Battery 字段
3. BluetoothAdapterItem 连接 batteryChanged 信号更新显示
4. PluginItemWidget 新增电量图标和百分比标签控件
5. 新增 20 个 SVG 电量图标(0-100%)支持明暗主题,更新 qrc 资源文件

Log: 在任务栏中显示蓝牙设备电量
PMS: STORY-41279
Influence: 任务栏显示蓝牙设备电量
@mhduiy
mhduiy force-pushed the fork-from-master-0728/story-41279 branch from 2555681 to 86a8fa0 Compare July 29, 2026 03:33
<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,可以按照资源路径的方式去区分暗亮色,而不是图标命名的方式,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants