Lomiri
Loading...
Searching...
No Matches
BatteryMonitor.h
1/*
2 * Copyright (C) 2023 Muhammad <muhammad23012009@hotmail.com>
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
17#ifndef BATTERYMONITOR_H
18#define BATTERYMONITOR_H
19
20#include <QObject>
21#include <QDebug>
22#include <QtDBus/QtDBus>
23#include <QDBusInterface>
24#include <QDBusConnection>
25#include <QDBusObjectPath>
26
27#define GET "Get"
28#define UPOWER_PROPERTIES "org.freedesktop.UPower.Device"
29
30enum {
31 /* Status */
32 UNKNOWN = 0,
33 CHARGING,
34 DISCHARGING,
35 EMPTY,
36 FULLY_CHARGED = 4,
37
38 /* Type */
39 ON_LINEPOWER = 1,
40 ON_BATTERY = 2
41};
42
43class BatteryMonitor: public QObject {
44 Q_OBJECT
45 Q_PROPERTY(qint64 timeToFull READ timeToFull NOTIFY timeToFullChanged)
46 Q_PROPERTY(bool charging READ charging NOTIFY chargingChanged)
47 Q_PROPERTY(bool fullyCharged READ isFullyCharged NOTIFY fullyChargedChanged)
48
49public:
50 BatteryMonitor();
51
52 bool hasBattery();
53 bool charging();
54 bool isFullyCharged();
55 qint64 timeToFull();
56
57 Q_INVOKABLE uint state();
58
59 enum Error {
60 NO_BATTERY = -1,
61 NO_TIMETOFULL = -2
62 };
63 Q_ENUM(Error)
64
65public Q_SLOTS:
66 void propertiesChanged(QString string, QVariantMap map, QStringList list);
67
68Q_SIGNALS:
69 void chargingChanged();
70 void timeToFullChanged();
71 void fullyChargedChanged();
72
73private:
74 QDBusInterface *m_iface;
75 QDBusObjectPath m_displayPath;
76};
77
78#endif