File indexing completed on 2024-04-28 05:36:17

0001 /*
0002     SPDX-FileCopyrightText: 2023 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #ifndef POWERDEVIL_UPOWERDEVICE_H
0008 #define POWERDEVIL_UPOWERDEVICE_H
0009 
0010 #include <QObject>
0011 #include <QString>
0012 #include <QStringList>
0013 #include <QVariantMap>
0014 
0015 class UPowerDevice : public QObject
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     explicit UPowerDevice(const QString &dbusObjectPath);
0021     UPowerDevice() = delete;
0022     ~UPowerDevice() = default;
0023 
0024     enum class State {
0025         Unknown = 0,
0026         Charging = 1,
0027         Discharging = 2,
0028         FullyCharged = 4,
0029     };
0030     State state() const
0031     {
0032         return m_state;
0033     }
0034 
0035     enum class Type {
0036         Unknown = 0,
0037         Battery = 2,
0038         Ups = 3,
0039     };
0040     Type type() const
0041     {
0042         return m_type;
0043     }
0044     bool isPowerSupply() const
0045     {
0046         return m_isPowerSupply;
0047     }
0048     bool isPresent() const
0049     {
0050         return m_isPresent;
0051     }
0052 
0053     double energy() const
0054     {
0055         return m_energy;
0056     }
0057     double energyFull() const
0058     {
0059         return m_energyFull;
0060     }
0061 
0062     /**
0063      * Amount of energy being drained from the source, measured
0064      * in W. If positive, the source is being discharged, if
0065      * negative it's being charged.
0066      * @return positive value if discharging, negative value if charging, or 0 if unknown
0067      * @see org.freedesktop.UPower.Device.xml
0068      */
0069     double energyRate() const
0070     {
0071         return m_energyRate;
0072     }
0073     qulonglong updateTime() const
0074     {
0075         return m_updateTime;
0076     }
0077 
0078 private:
0079     State m_state = State::Unknown;
0080     Type m_type = Type::Unknown;
0081     bool m_isPowerSupply = false;
0082     bool m_isPresent = false;
0083 
0084     double m_energy = 0.0;
0085     double m_energyFull = 0.0;
0086     double m_energyRate = 0.0;
0087     qulonglong m_updateTime = 0;
0088 
0089 private Q_SLOTS:
0090     void onPropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps);
0091     bool updateProperties(const QVariantMap &properties);
0092 
0093 Q_SIGNALS:
0094     void propertiesChanged();
0095 };
0096 
0097 #endif