mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2025-11-04 19:04:56 +11:00
service/upower: adopt bindable properties
This commit is contained in:
parent
d4deb11216
commit
ff55ac874b
4 changed files with 162 additions and 107 deletions
|
|
@ -21,7 +21,7 @@ class UPower: public QObject {
|
|||
public:
|
||||
[[nodiscard]] UPowerDevice* displayDevice();
|
||||
[[nodiscard]] ObjectModel<UPowerDevice>* devices();
|
||||
[[nodiscard]] bool onBattery() const;
|
||||
QS_BINDABLE_GETTER(bool, bOnBattery, onBattery, bindableOnBattery);
|
||||
|
||||
static UPower* instance();
|
||||
|
||||
|
|
@ -44,8 +44,10 @@ private:
|
|||
QHash<QString, UPowerDevice*> mDevices;
|
||||
ObjectModel<UPowerDevice> readyDevices {this};
|
||||
|
||||
dbus::DBusPropertyGroup serviceProperties;
|
||||
dbus::DBusProperty<bool> pOnBattery {this->serviceProperties, "OnBattery"};
|
||||
Q_OBJECT_BINDABLE_PROPERTY(UPower, bool, bOnBattery, &UPower::onBatteryChanged);
|
||||
|
||||
QS_DBUS_BINDABLE_PROPERTY_GROUP(UPower, serviceProperties);
|
||||
QS_DBUS_PROPERTY_BINDING(UPower, pOnBattery, bOnBattery, serviceProperties, "OnBattery");
|
||||
|
||||
DBusUPowerService* service = nullptr;
|
||||
};
|
||||
|
|
@ -64,7 +66,7 @@ class UPowerQml: public QObject {
|
|||
QSDOC_TYPE_OVERRIDE(ObjectModel<qs::service::upower::UPowerDevice>*);
|
||||
Q_PROPERTY(UntypedObjectModel* devices READ devices CONSTANT);
|
||||
/// If the system is currently running on battery power, or discharging.
|
||||
Q_PROPERTY(bool onBattery READ onBattery NOTIFY onBatteryChanged);
|
||||
Q_PROPERTY(bool onBattery READ onBattery NOTIFY onBatteryChanged BINDABLE bindableOnBattery);
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
|
|
@ -72,7 +74,11 @@ public:
|
|||
|
||||
[[nodiscard]] UPowerDevice* displayDevice();
|
||||
[[nodiscard]] ObjectModel<UPowerDevice>* devices();
|
||||
[[nodiscard]] static bool onBattery();
|
||||
[[nodiscard]] static bool onBattery() { return UPower::instance()->onBattery(); }
|
||||
|
||||
[[nodiscard]] static QBindable<bool> bindableOnBattery() {
|
||||
return UPower::instance()->bindableOnBattery();
|
||||
}
|
||||
|
||||
signals:
|
||||
void displayDeviceChanged();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue