Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
UPowerDevice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceUPower/phosphorserviceupower_export.h>
7
8#include <QObject>
9#include <QString>
10
11#include <memory>
12
13class QDBusConnection;
14
15namespace PhosphorServiceUPower {
16
17class PHOSPHORSERVICEUPOWER_EXPORT UPowerDevice : public QObject
18{
19 Q_OBJECT
20 Q_DISABLE_COPY_MOVE(UPowerDevice)
21
22 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
23 Q_PROPERTY(DeviceState state READ state NOTIFY stateChanged)
24 Q_PROPERTY(DeviceType type READ type NOTIFY typeChanged)
25 Q_PROPERTY(qreal timeToEmpty READ timeToEmpty NOTIFY timeToEmptyChanged)
26 Q_PROPERTY(qreal timeToFull READ timeToFull NOTIFY timeToFullChanged)
27 Q_PROPERTY(qreal energy READ energy NOTIFY energyChanged)
28 Q_PROPERTY(qreal energyCapacity READ energyCapacity NOTIFY energyCapacityChanged)
30 Q_PROPERTY(qreal energyRate READ energyRate NOTIFY energyRateChanged)
31 Q_PROPERTY(QString nativePath READ nativePath NOTIFY nativePathChanged)
32 Q_PROPERTY(QString model READ model NOTIFY modelChanged)
33 Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged)
34 Q_PROPERTY(bool powerSupply READ powerSupply NOTIFY powerSupplyChanged)
35 Q_PROPERTY(bool isPresent READ isPresent NOTIFY isPresentChanged)
36 Q_PROPERTY(bool isLaptopBattery READ isLaptopBattery NOTIFY isLaptopBatteryChanged)
38
39public:
49 Q_ENUM(DeviceState)
50
51 // Mirrors the full UPower 1.0 device-type range (see upower-glib
52 // up-types.h). Modern UPower exposes peripherals up through
53 // BluetoothGeneric=28; truncating the enum to MediaPlayer=9
54 // (the original phosphor-services subset) silently demotes any
55 // higher-numbered device to a bare integer that QML's
56 // `Phosphor.Service.UPower.UPowerDevice.Type.X` lookup can't
57 // resolve.
89 Q_ENUM(DeviceType)
90
91 explicit UPowerDevice(const QString& dbusPath, QObject* parent = nullptr);
92 UPowerDevice(const QString& dbusPath, const QDBusConnection& bus, const QString& service,
93 QObject* parent = nullptr);
94 ~UPowerDevice() override;
95
96 [[nodiscard]] QString dbusPath() const;
97 [[nodiscard]] qreal percentage() const;
98 [[nodiscard]] DeviceState state() const;
99 [[nodiscard]] DeviceType type() const;
100 [[nodiscard]] qreal timeToEmpty() const;
101 [[nodiscard]] qreal timeToFull() const;
102 [[nodiscard]] qreal energy() const;
103 [[nodiscard]] qreal energyCapacity() const;
104 [[nodiscard]] qreal energyFullDesign() const;
105 [[nodiscard]] qreal energyRate() const;
106 [[nodiscard]] QString nativePath() const;
107 [[nodiscard]] QString model() const;
108 [[nodiscard]] QString iconName() const;
109 [[nodiscard]] bool powerSupply() const;
110 [[nodiscard]] bool isPresent() const;
111 [[nodiscard]] bool isLaptopBattery() const;
112 [[nodiscard]] qreal healthPercentage() const;
113
114Q_SIGNALS:
131
132private Q_SLOTS:
133 void _q_onPropertiesChanged(const QString& iface, const QVariantMap& changed, const QStringList& invalidated);
134
135private:
136 class Private;
137 std::unique_ptr<Private> d;
138};
139
140} // namespace PhosphorServiceUPower
DeviceType
Definition UPowerDevice.h:58
@ Toy
Definition UPowerDevice.h:86
@ Speakers
Definition UPowerDevice.h:77
@ Monitor
Definition UPowerDevice.h:63
@ GamingInput
Definition UPowerDevice.h:71
@ Mouse
Definition UPowerDevice.h:64
@ Camera
Definition UPowerDevice.h:84
@ LinePower
Definition UPowerDevice.h:60
@ UnknownType
Definition UPowerDevice.h:59
@ Printer
Definition UPowerDevice.h:82
@ Headset
Definition UPowerDevice.h:76
@ Tablet
Definition UPowerDevice.h:69
@ MediaPlayer
Definition UPowerDevice.h:68
@ Pen
Definition UPowerDevice.h:72
@ Scanner
Definition UPowerDevice.h:83
@ Network
Definition UPowerDevice.h:75
@ OtherAudio
Definition UPowerDevice.h:80
@ Pda
Definition UPowerDevice.h:66
@ Ups
Definition UPowerDevice.h:62
@ Keyboard
Definition UPowerDevice.h:65
@ Battery
Definition UPowerDevice.h:61
@ Touchpad
Definition UPowerDevice.h:73
@ Wearable
Definition UPowerDevice.h:85
@ RemoteControl
Definition UPowerDevice.h:81
@ Video
Definition UPowerDevice.h:79
@ BluetoothGeneric
Definition UPowerDevice.h:87
@ Headphones
Definition UPowerDevice.h:78
@ Computer
Definition UPowerDevice.h:70
@ Modem
Definition UPowerDevice.h:74
@ Phone
Definition UPowerDevice.h:67
DeviceState
Definition UPowerDevice.h:40
@ Empty
Definition UPowerDevice.h:44
@ FullyCharged
Definition UPowerDevice.h:45
@ Discharging
Definition UPowerDevice.h:43
@ PendingCharge
Definition UPowerDevice.h:46
@ UnknownState
Definition UPowerDevice.h:41
@ Charging
Definition UPowerDevice.h:42
@ PendingDischarge
Definition UPowerDevice.h:47
UPowerDevice(const QString &dbusPath, QObject *parent=nullptr)
Definition QmlRegistration.h:8