summaryrefslogtreecommitdiff
path: root/library/power.h
Unidiff
Diffstat (limited to 'library/power.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/power.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/library/power.h b/library/power.h
new file mode 100644
index 0000000..99d3595
--- a/dev/null
+++ b/library/power.h
@@ -0,0 +1,85 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef POWER_H
22#define POWER_H
23
24#include <qobject.h>
25
26class PowerStatus
27{
28public:
29 PowerStatus() {
30 ac = Offline;
31 bs = NotPresent;
32 bbs = NotPresent;
33 percentRemain = -1;
34 secsRemain = -1;
35 }
36
37 enum ACStatus { Offline, Online, Backup };
38 ACStatus acStatus() const { return ac; }
39
40 enum BatteryStatus { High=0x01, Low=0x02, VeryLow=0x04, Critical=0x08,
41 Charging=0x10, NotPresent=0x20 };
42 BatteryStatus batteryStatus() const { return bs; }
43 BatteryStatus backupBatteryStatus() const { return bbs; }
44
45 bool batteryPercentAccurate() const { return percentAccurate; }
46 int batteryPercentRemaining() const { return percentRemain; }
47 int batteryTimeRemaining() const { return secsRemain; }
48
49 bool operator!=( const PowerStatus &ps ) {
50 return (ps.ac != ac) || (ps.bs != bs) || (ps.bbs != bbs) ||
51 (ps.percentRemain != percentRemain) ||
52 (ps.secsRemain != secsRemain );
53 }
54
55private:
56 ACStatus ac;
57 BatteryStatus bs;
58 BatteryStatus bbs;
59 int percentRemain;
60 int secsRemain;
61 bool percentAccurate;
62
63 friend class PowerStatusManager;
64};
65
66
67class PowerStatusManager
68{
69public:
70 PowerStatusManager();
71
72 static const PowerStatus &readStatus();
73
74protected:
75 bool getProcApmStatus( int &ac, int &bs, int &bf, int &pc, int &sec );
76 void getStatus();
77
78private:
79 static PowerStatus *ps;
80 static PowerStatusManager *powerManager;
81};
82
83
84#endif
85