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 <PhosphorServices/phosphorservices_export.h>
7
8#include <QObject>
9#include <QString>
10
11#include <memory>
12
13namespace PhosphorServices {
14
15class PHOSPHORSERVICES_EXPORT UPowerDevice : public QObject
16{
17 Q_OBJECT
18
19 Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
20 Q_PROPERTY(DeviceState state READ state NOTIFY stateChanged)
21 Q_PROPERTY(DeviceType type READ type NOTIFY typeChanged)
22 Q_PROPERTY(qreal timeToEmpty READ timeToEmpty NOTIFY timeToEmptyChanged)
23 Q_PROPERTY(qreal timeToFull READ timeToFull NOTIFY timeToFullChanged)
24 Q_PROPERTY(qreal energy READ energy NOTIFY energyChanged)
25 Q_PROPERTY(qreal energyCapacity READ energyCapacity NOTIFY energyCapacityChanged)
26 Q_PROPERTY(qreal energyFullDesign READ energyFullDesign NOTIFY energyFullDesignChanged)
27 Q_PROPERTY(qreal energyRate READ energyRate NOTIFY energyRateChanged)
28 Q_PROPERTY(QString nativePath READ nativePath NOTIFY nativePathChanged)
29 Q_PROPERTY(QString model READ model NOTIFY modelChanged)
30 Q_PROPERTY(QString iconName READ iconName NOTIFY iconNameChanged)
31 Q_PROPERTY(bool powerSupply READ powerSupply NOTIFY powerSupplyChanged)
32 Q_PROPERTY(bool isPresent READ isPresent NOTIFY isPresentChanged)
33 Q_PROPERTY(bool isLaptopBattery READ isLaptopBattery NOTIFY isLaptopBatteryChanged)
34 Q_PROPERTY(qreal healthPercentage READ healthPercentage NOTIFY healthPercentageChanged)
35
36public:
38 UnknownState = 0,
39 Charging = 1,
40 Discharging = 2,
41 Empty = 3,
42 FullyCharged = 4,
43 PendingCharge = 5,
44 PendingDischarge = 6,
45 };
46 Q_ENUM(DeviceState)
47
49 UnknownType = 0,
50 LinePower = 1,
51 Battery = 2,
52 Ups = 3,
53 Monitor = 4,
54 Mouse = 5,
55 Keyboard = 6,
56 Pda = 7,
57 Phone = 8,
58 MediaPlayer = 9,
59 };
60 Q_ENUM(DeviceType)
61
62 explicit UPowerDevice(const QString& dbusPath, QObject* parent = nullptr);
63 ~UPowerDevice() override;
64
65 [[nodiscard]] QString dbusPath() const;
66 [[nodiscard]] qreal percentage() const;
67 [[nodiscard]] DeviceState state() const;
68 [[nodiscard]] DeviceType type() const;
69 [[nodiscard]] qreal timeToEmpty() const;
70 [[nodiscard]] qreal timeToFull() const;
71 [[nodiscard]] qreal energy() const;
72 [[nodiscard]] qreal energyCapacity() const;
73 [[nodiscard]] qreal energyFullDesign() const;
74 [[nodiscard]] qreal energyRate() const;
75 [[nodiscard]] QString nativePath() const;
76 [[nodiscard]] QString model() const;
77 [[nodiscard]] QString iconName() const;
78 [[nodiscard]] bool powerSupply() const;
79 [[nodiscard]] bool isPresent() const;
80 [[nodiscard]] bool isLaptopBattery() const;
81 [[nodiscard]] qreal healthPercentage() const;
82
83Q_SIGNALS:
84 void percentageChanged();
85 void stateChanged();
86 void typeChanged();
87 void timeToEmptyChanged();
88 void timeToFullChanged();
89 void energyChanged();
90 void energyCapacityChanged();
91 void energyFullDesignChanged();
92 void energyRateChanged();
93 void nativePathChanged();
94 void modelChanged();
95 void iconNameChanged();
96 void powerSupplyChanged();
97 void isPresentChanged();
98 void isLaptopBatteryChanged();
99 void healthPercentageChanged();
100 void propertiesRefreshed();
101
102private Q_SLOTS:
103 void _q_onPropertiesChanged(const QString& iface, const QVariantMap& changed, const QStringList& invalidated);
104
105private:
106 class Private;
107 std::unique_ptr<Private> d;
108};
109
110} // namespace PhosphorServices
Definition UPowerDevice.h:16
DeviceState
Definition UPowerDevice.h:37
DeviceType
Definition UPowerDevice.h:48
Definition DBusMenuModel.h:15