Lomiri
BatteryMonitor.h
1 #ifndef BATTERYMONITOR_H
2 #define BATTERYMONITOR_H
3 
4 #include <QObject>
5 #include <QDebug>
6 #include <QtDBus/QtDBus>
7 #include <QDBusInterface>
8 #include <QDBusConnection>
9 #include <QDBusObjectPath>
10 
11 #define GET "Get"
12 #define UPOWER_PROPERTIES "org.freedesktop.UPower.Device"
13 
14 enum {
15  /* Status */
16  UNKNOWN = 0,
17  CHARGING,
18  DISCHARGING,
19  EMPTY,
20  FULLY_CHARGED = 4,
21 
22  /* Type */
23  ON_LINEPOWER = 1,
24  ON_BATTERY = 2
25 };
26 
27 class BatteryMonitor: public QObject {
28  Q_OBJECT
29  Q_PROPERTY(qint64 timeToFull READ timeToFull NOTIFY timeToFullChanged)
30  Q_PROPERTY(bool charging READ charging NOTIFY chargingChanged)
31  Q_PROPERTY(bool fullyCharged READ isFullyCharged NOTIFY fullyChargedChanged)
32 
33 public:
34  BatteryMonitor();
35 
36  bool hasBattery();
37  bool charging();
38  bool isFullyCharged();
39  qint64 timeToFull();
40 
41  Q_INVOKABLE uint state();
42 
43  enum Error {
44  NO_BATTERY = -1,
45  NO_TIMETOFULL = -2
46  };
47  Q_ENUM(Error)
48 
49 public Q_SLOTS:
50  void propertiesChanged(QString string, QVariantMap map, QStringList list);
51 
52 Q_SIGNALS:
53  void chargingChanged();
54  void timeToFullChanged();
55  void fullyChargedChanged();
56 
57 private:
58  QDBusInterface *m_iface;
59  QDBusObjectPath m_displayPath;
60 };
61 
62 #endif