Lomiri
Loading...
Searching...
No Matches
BatteryMonitor.h
1/*
2 * Copyright (C) 2023 UBports Foundation
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Muhammad
17 */
18
19#ifndef BATTERYMONITOR_H
20#define BATTERYMONITOR_H
21
22#include <QObject>
23#include <QDebug>
24#include <QtDBus/QtDBus>
25#include <QDBusInterface>
26#include <QDBusConnection>
27#include <QDBusObjectPath>
28
29#define GET "Get"
30#define UPOWER_PROPERTIES "org.freedesktop.UPower.Device"
31
32enum {
33 /* Status */
34 UNKNOWN = 0,
35 CHARGING,
36 DISCHARGING,
37 EMPTY,
38 FULLY_CHARGED = 4,
39
40 /* Type */
41 ON_LINEPOWER = 1,
42 ON_BATTERY = 2
43};
44
45class BatteryMonitor: public QObject {
46 Q_OBJECT
47 Q_PROPERTY(qint64 timeToFull READ timeToFull NOTIFY timeToFullChanged)
48 Q_PROPERTY(bool charging READ charging NOTIFY chargingChanged)
49 Q_PROPERTY(bool fullyCharged READ isFullyCharged NOTIFY fullyChargedChanged)
50
51public:
52 BatteryMonitor();
53
54 bool hasBattery();
55 bool charging();
56 bool isFullyCharged();
57 qint64 timeToFull();
58
59 Q_INVOKABLE uint state();
60
61 enum Error {
62 NO_BATTERY = -1,
63 NO_TIMETOFULL = -2
64 };
65 Q_ENUM(Error)
66
67public Q_SLOTS:
68 void propertiesChanged(QString string, QVariantMap map, QStringList list);
69
70Q_SIGNALS:
71 void chargingChanged();
72 void timeToFullChanged();
73 void fullyChargedChanged();
74
75private:
76 QDBusInterface *m_iface;
77 QDBusObjectPath m_displayPath;
78};
79
80#endif