@@ -80,49 +80,83 @@ class UPowerDeviceType: public QObject {
8080 Q_INVOKABLE static QString toString (qs::service::upower::UPowerDeviceType::Enum type);
8181};
8282
83+ struct PowerPercentage ;
84+
85+ } // namespace qs::service::upower
86+
87+ namespace qs ::dbus {
88+
89+ template <>
90+ struct DBusDataTransform <qs::service::upower::UPowerDeviceState::Enum> {
91+ using Wire = quint32;
92+ using Data = qs::service::upower::UPowerDeviceState::Enum;
93+ static DBusResult<Data> fromWire (Wire wire);
94+ static Wire toWire (const Data& value);
95+ };
96+
97+ template <>
98+ struct DBusDataTransform <qs::service::upower::UPowerDeviceType::Enum> {
99+ using Wire = quint32;
100+ using Data = qs::service::upower::UPowerDeviceType::Enum;
101+ static DBusResult<Data> fromWire (Wire wire);
102+ static Wire toWire (const Data& value);
103+ };
104+
105+ template <>
106+ struct DBusDataTransform <qs::service::upower::PowerPercentage> {
107+ using Wire = qreal;
108+ using Data = qreal;
109+ static DBusResult<Data> fromWire (Wire wire);
110+ static Wire toWire (const Data& value);
111+ };
112+
113+ } // namespace qs::dbus
114+
115+ namespace qs ::service::upower {
116+
83117// /! A device exposed through the UPower system service.
84118class UPowerDevice : public QObject {
85119 Q_OBJECT;
86120 // clang-format off
87121 // / The type of device.
88- Q_PROPERTY (qs::service::upower::UPowerDeviceType::Enum type READ type NOTIFY typeChanged);
122+ Q_PROPERTY (qs::service::upower::UPowerDeviceType::Enum type READ type NOTIFY typeChanged BINDABLE bindableType );
89123 // / If the device is a power supply for your computer and can provide charge.
90- Q_PROPERTY (bool powerSupply READ powerSupply NOTIFY powerSupplyChanged);
124+ Q_PROPERTY (bool powerSupply READ powerSupply NOTIFY powerSupplyChanged BINDABLE bindablePowerSupply );
91125 // / Current energy level of the device in watt-hours.
92- Q_PROPERTY (qreal energy READ energy NOTIFY energyChanged);
126+ Q_PROPERTY (qreal energy READ energy NOTIFY energyChanged BINDABLE bindableEnergy );
93127 // / Maximum energy capacity of the device in watt-hours
94- Q_PROPERTY (qreal energyCapacity READ energyCapacity NOTIFY energyCapacityChanged);
128+ Q_PROPERTY (qreal energyCapacity READ energyCapacity NOTIFY energyCapacityChanged BINDABLE bindableEnergyCapacity );
95129 // / Rate of energy change in watts (positive when charging, negative when discharging).
96- Q_PROPERTY (qreal changeRate READ changeRate NOTIFY changeRateChanged);
130+ Q_PROPERTY (qreal changeRate READ changeRate NOTIFY changeRateChanged BINDABLE bindableChangeRate );
97131 // / Estimated time until the device is fully discharged, in seconds.
98132 // /
99133 // / Will be set to `0` if charging.
100- Q_PROPERTY (qreal timeToEmpty READ timeToEmpty NOTIFY timeToEmptyChanged);
134+ Q_PROPERTY (qreal timeToEmpty READ timeToEmpty NOTIFY timeToEmptyChanged BINDABLE bindableTimeToEmpty );
101135 // / Estimated time until the device is fully charged, in seconds.
102136 // /
103137 // / Will be set to `0` if discharging.
104- Q_PROPERTY (qreal timeToFull READ timeToFull NOTIFY timeToFullChanged);
138+ Q_PROPERTY (qreal timeToFull READ timeToFull NOTIFY timeToFullChanged BINDABLE bindableTimeToFull );
105139 // / Current charge level as a percentage.
106140 // /
107141 // / This would be equivalent to @@energy / @@energyCapacity.
108- Q_PROPERTY (qreal percentage READ percentage NOTIFY percentageChanged);
142+ Q_PROPERTY (qreal percentage READ percentage NOTIFY percentageChanged BINDABLE bindablePercentage );
109143 // / If the power source is present in the bay or slot, useful for hot-removable batteries.
110144 // /
111145 // / If the device `type` is not `Battery`, then the property will be invalid.
112- Q_PROPERTY (bool isPresent READ isPresent NOTIFY isPresentChanged);
146+ Q_PROPERTY (bool isPresent READ isPresent NOTIFY isPresentChanged BINDABLE bindableIsPresent );
113147 // / Current state of the device.
114- Q_PROPERTY (qs::service::upower::UPowerDeviceState::Enum state READ state NOTIFY stateChanged);
148+ Q_PROPERTY (qs::service::upower::UPowerDeviceState::Enum state READ state NOTIFY stateChanged BINDABLE bindableState );
115149 // / Health of the device as a percentage of its original health.
116- Q_PROPERTY (qreal healthPercentage READ healthPercentage NOTIFY healthPercentageChanged);
117- Q_PROPERTY (bool healthSupported READ healthSupported NOTIFY healthSupportedChanged);
150+ Q_PROPERTY (qreal healthPercentage READ healthPercentage NOTIFY healthPercentageChanged BINDABLE bindableHealthPercentage );
151+ Q_PROPERTY (bool healthSupported READ healthSupported NOTIFY healthSupportedChanged BINDABLE bindableHealthSupported );
118152 // / Name of the icon representing the current state of the device, or an empty string if not provided.
119- Q_PROPERTY (QString iconName READ iconName NOTIFY iconNameChanged);
153+ Q_PROPERTY (QString iconName READ iconName NOTIFY iconNameChanged BINDABLE bindableIconName );
120154 // / If the device is a laptop battery or not. Use this to check if your device is a valid battery.
121155 // /
122156 // / This will be equivalent to @@type == Battery && @@powerSupply == true.
123- Q_PROPERTY (bool isLaptopBattery READ isLaptopBattery NOTIFY isLaptopBatteryChanged);
157+ Q_PROPERTY (bool isLaptopBattery READ isLaptopBattery NOTIFY isLaptopBatteryChanged BINDABLE bindableIsLaptopBattery );
124158 // / Native path of the device specific to your OS.
125- Q_PROPERTY (QString nativePath READ nativePath NOTIFY nativePathChanged);
159+ Q_PROPERTY (QString nativePath READ nativePath NOTIFY nativePathChanged BINDABLE bindableNativePath );
126160 // clang-format on
127161 QML_ELEMENT;
128162 QML_UNCREATABLE (" UPowerDevices can only be acquired from UPower" );
@@ -134,21 +168,21 @@ class UPowerDevice: public QObject {
134168 [[nodiscard]] QString address () const ;
135169 [[nodiscard]] QString path () const ;
136170
137- [[nodiscard]] UPowerDeviceType::Enum type () const ;
138- [[nodiscard]] bool powerSupply () const ;
139- [[nodiscard]] qreal energy () const ;
140- [[nodiscard]] qreal energyCapacity () const ;
141- [[nodiscard]] qreal changeRate () const ;
142- [[nodiscard]] qlonglong timeToEmpty () const ;
143- [[nodiscard]] qlonglong timeToFull () const ;
144- [[nodiscard]] qreal percentage () const ;
145- [[nodiscard]] bool isPresent () const ;
146- [[nodiscard]] UPowerDeviceState::Enum state () const ;
147- [[nodiscard]] qreal healthPercentage () const ;
148- [[nodiscard]] bool healthSupported () const ;
149- [[nodiscard]] QString iconName () const ;
150- [[nodiscard]] bool isLaptopBattery () const ;
151- [[nodiscard]] QString nativePath () const ;
171+ QS_BINDABLE_GETTER ( UPowerDeviceType::Enum, bType, type, bindableType) ;
172+ QS_BINDABLE_GETTER ( bool , bPowerSupply, powerSupply, bindablePowerSupply) ;
173+ QS_BINDABLE_GETTER ( qreal, bEnergy, energy, bindableEnergy) ;
174+ QS_BINDABLE_GETTER ( qreal, bEnergyCapacity, energyCapacity, bindableEnergyCapacity) ;
175+ QS_BINDABLE_GETTER ( qreal, bChangeRate, changeRate, bindableChangeRate) ;
176+ QS_BINDABLE_GETTER ( qlonglong, bTimeToEmpty, timeToEmpty, bindableTimeToEmpty) ;
177+ QS_BINDABLE_GETTER ( qlonglong, bTimeToFull, timeToFull, bindableTimeToFull) ;
178+ QS_BINDABLE_GETTER ( qreal, bPercentage, percentage, bindablePercentage) ;
179+ QS_BINDABLE_GETTER ( bool , bIsPresent, isPresent, bindableIsPresent) ;
180+ QS_BINDABLE_GETTER ( UPowerDeviceState::Enum, bState, state, bindableState) ;
181+ QS_BINDABLE_GETTER ( qreal, bHealthPercentage, healthPercentage, bindableHealthPercentage) ;
182+ QS_BINDABLE_GETTER ( bool , bHealthSupported, healthSupported, bindableHealthSupported) ;
183+ QS_BINDABLE_GETTER ( QString, bIconName, iconName, bindableIconName) ;
184+ QS_BINDABLE_GETTER ( bool , bIsLaptopBattery, isLaptopBattery, bindableIsLaptopBattery) ;
185+ QS_BINDABLE_GETTER ( QString, bNativePath, nativePath, bindableNativePath) ;
152186
153187signals:
154188 QSDOC_HIDE void ready ();
@@ -170,20 +204,38 @@ class UPowerDevice: public QObject {
170204 void nativePathChanged ();
171205
172206private:
173- dbus::DBusPropertyGroup deviceProperties;
174- dbus::DBusProperty<quint32> pType {this ->deviceProperties , " Type" };
175- dbus::DBusProperty<bool > pPowerSupply {this ->deviceProperties , " PowerSupply" };
176- dbus::DBusProperty<qreal> pEnergy {this ->deviceProperties , " Energy" };
177- dbus::DBusProperty<qreal> pEnergyCapacity {this ->deviceProperties , " EnergyFull" };
178- dbus::DBusProperty<qreal> pChangeRate {this ->deviceProperties , " EnergyRate" };
179- dbus::DBusProperty<qlonglong> pTimeToEmpty {this ->deviceProperties , " TimeToEmpty" };
180- dbus::DBusProperty<qlonglong> pTimeToFull {this ->deviceProperties , " TimeToFull" };
181- dbus::DBusProperty<qreal> pPercentage {this ->deviceProperties , " Percentage" };
182- dbus::DBusProperty<bool > pIsPresent {this ->deviceProperties , " IsPresent" };
183- dbus::DBusProperty<quint32> pState {this ->deviceProperties , " State" };
184- dbus::DBusProperty<qreal> pHealthPercentage {this ->deviceProperties , " Capacity" };
185- dbus::DBusProperty<QString> pIconName {this ->deviceProperties , " IconName" };
186- dbus::DBusProperty<QString> pNativePath {this ->deviceProperties , " NativePath" };
207+ // clang-format off
208+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, UPowerDeviceType::Enum, bType, &UPowerDevice::typeChanged);
209+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, bool , bPowerSupply, &UPowerDevice::powerSupplyChanged);
210+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qreal, bEnergy, &UPowerDevice::energyChanged);
211+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qreal, bEnergyCapacity, &UPowerDevice::energyCapacityChanged);
212+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qreal, bChangeRate, &UPowerDevice::changeRateChanged);
213+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qlonglong, bTimeToEmpty, &UPowerDevice::timeToEmptyChanged);
214+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qlonglong, bTimeToFull, &UPowerDevice::timeToFullChanged);
215+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qreal, bPercentage, &UPowerDevice::percentageChanged);
216+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, bool , bIsPresent, &UPowerDevice::isPresentChanged);
217+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, UPowerDeviceState::Enum, bState, &UPowerDevice::stateChanged);
218+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, qreal, bHealthPercentage, &UPowerDevice::healthPercentageChanged);
219+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, bool , bHealthSupported, &UPowerDevice::healthSupportedChanged);
220+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, QString, bIconName, &UPowerDevice::iconNameChanged);
221+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, bool , bIsLaptopBattery, &UPowerDevice::isLaptopBatteryChanged);
222+ Q_OBJECT_BINDABLE_PROPERTY (UPowerDevice, QString, bNativePath, &UPowerDevice::nativePathChanged);
223+
224+ QS_DBUS_BINDABLE_PROPERTY_GROUP (UPowerDevice, deviceProperties);
225+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pType, bType, deviceProperties, " Type" );
226+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pPowerSupply, bPowerSupply, deviceProperties, " PowerSupply" );
227+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pEnergy, bEnergy, deviceProperties, " Energy" );
228+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pEnergyCapacity, bEnergyCapacity, deviceProperties, " EnergyFull" );
229+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pChangeRate, bChangeRate, deviceProperties, " EnergyRate" );
230+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pTimeToEmpty, bTimeToEmpty, deviceProperties, " TimeToEmpty" );
231+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pTimeToFull, bTimeToFull, deviceProperties, " TimeToFull" );
232+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, PowerPercentage, pPercentage, bPercentage, deviceProperties, " Percentage" , true );
233+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pIsPresent, bIsPresent, deviceProperties, " IsPresent" );
234+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pState, bState, deviceProperties, " State" );
235+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pHealthPercentage, bHealthPercentage, deviceProperties, " Capacity" );
236+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pIconName, bIconName, deviceProperties, " IconName" );
237+ QS_DBUS_PROPERTY_BINDING (UPowerDevice, pNativePath, bNativePath, deviceProperties, " NativePath" );
238+ // clang-format on
187239
188240 DBusUPowerDevice* device = nullptr ;
189241};
0 commit comments