diff --git a/Modules/energy/batterymodel.h b/Modules/energy/batterymodel.h --- a/Modules/energy/batterymodel.h +++ b/Modules/energy/batterymodel.h @@ -38,10 +38,14 @@ enum Roles { BatteryRole = Qt::UserRole, - UdiRole + UdiRole, + VendorRole, + ProductRole }; Q_INVOKABLE Solid::Battery *get(int index) const; + Q_INVOKABLE QString vendor(int index) const; + Q_INVOKABLE QString product(int index) const; Q_INVOKABLE QString udi(int index) const; QVariant data(const QModelIndex &index, int role) const override; diff --git a/Modules/energy/batterymodel.cpp b/Modules/energy/batterymodel.cpp --- a/Modules/energy/batterymodel.cpp +++ b/Modules/energy/batterymodel.cpp @@ -86,14 +86,38 @@ return m_batteries.at(index).udi(); } +QString BatteryModel::vendor(int index) const { + + if (index < 0 || index >= m_batteries.count()) { + return QString(); + } + const Solid::Device device = m_batteries.value(index); + return device.vendor(); +} + +QString BatteryModel::product(int index) const { + + if (index < 0 || index >= m_batteries.count()) { + return QString(); + } + const Solid::Device device = m_batteries.value(index); + return device.product(); +} + QVariant BatteryModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_batteries.count()) { return QVariant(); } if (role == BatteryRole) { return QVariant::fromValue(m_batteries.value(index.row()).as()); + } else if (role == ProductRole) { + const Solid::Device device = m_batteries.value(index.row()); + return device.product(); + } else if (role == VendorRole) { + const Solid::Device device = m_batteries.value(index.row()); + return device.vendor(); } else if (role == UdiRole) { return m_batteries.at(index.row()).udi(); } @@ -111,6 +135,8 @@ { return { {BatteryRole, "battery"}, + {VendorRole, "vendor"}, + {ProductRole, "product"}, {UdiRole, "udi"} }; } diff --git a/Modules/energy/package/contents/ui/main.qml b/Modules/energy/package/contents/ui/main.qml --- a/Modules/energy/package/contents/ui/main.qml +++ b/Modules/energy/package/contents/ui/main.qml @@ -37,11 +37,15 @@ property QtObject currentBattery: null property string currentUdi: "" + property string currentVendor: "" + property string currentProduct: "" property bool compact: (root.width / units.gridUnit) < 25 onCurrentBatteryChanged: { if (!currentBattery) { - currentBattery = kcm.batteries.get(0) + currentBattery = kcm.batteries.battery(0) + currentVendor = kcm.batteries.vendor(0) + currentProduct = kcm.batteries.product(0) currentUdi = kcm.batteries.udi(0) } } @@ -55,7 +59,11 @@ data: [ {label: i18n("Rechargeable"), value: "rechargeable"}, {label: i18n("Charge state"), value: "chargeState", modifier: "chargeState"}, - {label: i18n("Capacity degradation"), value: "capacity", unit: i18n("%"), precision: 0} + {label: i18n("Current charge"), value: "chargePercent", unit: i18n("%"), precision: 0}, + {label: i18n("Capacity degradation"), value: "capacity", unit: i18n("%"), precision: 0}, + {label: i18n("Vendor"), value: "vendor", source:"Vendor"}, + {label: i18n("Model"), value: "model", source:"Product"}, + {label: i18n("Serial Number"), value: "serial"} ] }, { @@ -74,14 +82,6 @@ {label: i18n("Temperature"), value: "temperature", unit: i18nc("Degree Celsius", "°C"), precision: 2} ] }, - { - title: i18n("Manufacturer"), - data: [ - {label: i18n("Vendor"), value: "vendor"}, - {label: i18n("Model"), value: "model"}, - {label: i18n("Serial Number"), value: "serial"} - ] - } ] function modifier_chargeState(value) { @@ -95,6 +95,8 @@ Component.onCompleted: { currentBattery = kcm.batteries.get(0) + currentVendor = kcm.batteries.vendor(0) + currentProduct = kcm.batteries.product(0) currentUdi = kcm.batteries.udi(0) } @@ -126,7 +128,10 @@ checkable: true onClicked: { root.currentUdi = model.udi + root.currentVendor = model.vendor + root.currentProduct = model.product root.currentBattery = model.battery + // override checked property checked = Qt.binding(function() { return model.battery == root.currentBattery @@ -422,7 +427,12 @@ id: valueLabel Kirigami.FormData.label: i18n("%1:", modelData.label) text: { - var value = currentBattery[modelData.value] + var value; + if (modelData.source) { + value = root["current" + modelData.source]; + } else { + value = currentBattery[modelData.value] + } // There's no "degradation" value we can look up, so // instead, process the capacity value to produce it