statusbar: fix hidden batteries from taking up space in the statusbar

I noticed at some point after updating my main phone, that non visible external device batteries started taking up extra space in the statusbar. This fixes the issue by filtering out external device batteries by using KSortFilterProxyModel.

Before (with external peripheral connected)

![Screenshot_20260303_124043](/uploads/a469eda41ff6d2a10b85c6a3de88785f/Screenshot_20260303_124043.png){width=399 height=28}

After

![Screenshot_20260303_123956](/uploads/521a7dc7bb16cf08ef026c3ef0655b93/Screenshot_20260303_123956.png){width=399 height=28}
This commit is contained in:
Micah Stanley 2026-03-06 01:13:34 +00:00 committed by Devin Lin
parent 90fce61b40
commit db98f2cd86
2 changed files with 11 additions and 3 deletions

View file

@ -162,6 +162,7 @@ target_link_libraries(mobileshellplugin
KF6::Service KF6::Service
KF6::Package KF6::Package
KF6::ConfigGui KF6::ConfigGui
KF6::ItemModels
LayerShellQt::Interface LayerShellQt::Interface
) )

View file

@ -10,6 +10,7 @@ import QtQuick 2.6
import QtQuick.Layouts 1.4 import QtQuick.Layouts 1.4
import org.kde.kirigami 2.20 as Kirigami import org.kde.kirigami 2.20 as Kirigami
import org.kde.kitemmodels
import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.workspace.components 2.0 as PW import org.kde.plasma.workspace.components 2.0 as PW
@ -26,7 +27,7 @@ RowLayout {
id: batteryRepeater id: batteryRepeater
spacing: 0 spacing: 0
model: MobileShell.BatteryInfo.batteries model: filterModel
orientation: ListView.Horizontal orientation: ListView.Horizontal
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
@ -34,6 +35,14 @@ RowLayout {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: false Layout.fillWidth: false
KSortFilterProxyModel {
id: filterModel
sourceModel: MobileShell.BatteryInfo.batteries
filterRoleName: "Type"
filterString: "Battery" // only show internal batteries
}
delegate: RowLayout { delegate: RowLayout {
id: batteryBase id: batteryBase
@ -42,8 +51,6 @@ RowLayout {
height: batteryRepeater.height height: batteryRepeater.height
visible: Type === "Battery" // only show the internal battery
PW.BatteryIcon { PW.BatteryIcon {
id: battery id: battery