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 class BatteryMonitor: public QObject {
15  Q_OBJECT
16  Q_PROPERTY(qint64 timeToFull READ timeToFull NOTIFY timeToFullChanged)
17  Q_PROPERTY(bool charging READ charging NOTIFY chargingChanged)
18 
19 public:
20  BatteryMonitor();
21 
22  bool hasBattery();
23  bool charging();
24  qint64 timeToFull();
25 
26  Q_INVOKABLE uint state();
27 
28  enum State {
29  /* Status */
30  UNKNOWN = 0,
31  CHARGING,
32  DISCHARGING,
33  EMPTY,
34  FULLY_CHARGED = 4,
35 
36  /* Type */
37  ON_LINEPOWER = 1,
38  ON_BATTERY = 2
39  };
40  Q_ENUM(State)
41 
42 public Q_SLOTS:
43  void propertiesChanged(QString string, QVariantMap map, QStringList list);
44 
45 Q_SIGNALS:
46  void chargingChanged();
47  void timeToFullChanged();
48 
49 private:
50  QDBusInterface *m_iface;
51  QDBusObjectPath m_displayPath;
52 };
53 
54 #endif