summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index 08ddc85..9622726 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,185 +1,183 @@
1 1
2#include "batterystatus.h" 2#include "batterystatus.h"
3 3
4/* OPIE */ 4/* OPIE */
5#include <opie2/odevice.h> 5#include <opie2/odevice.h>
6#include <qpe/power.h> 6#include <qpe/power.h>
7 7
8/* QT */ 8/* QT */
9#include <qpushbutton.h> 9#include <qpushbutton.h>
10#include <qdrawutil.h> 10#include <qdrawutil.h>
11#include <qfile.h> 11#include <qfile.h>
12#include <qtextstream.h> 12#include <qtextstream.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14 14
15using namespace Opie::Core; 15using namespace Opie::Core;
16 16
17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f ) 17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f )
18: QFrame( parent, 0, f), ps(p), bat2(false) { 18: QFrame( parent, 0, f), ps(p), bat2(false) {
19 19
20 UpdateBatteryStatus(); 20 UpdateBatteryStatus();
21} 21}
22 22
23BatteryStatus::~BatteryStatus() {} 23BatteryStatus::~BatteryStatus() {}
24 24
25void BatteryStatus::UpdateBatteryStatus() { 25void BatteryStatus::UpdateBatteryStatus() {
26 26
27 jackPercent = 0; 27 jackPercent = 0;
28 28
29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
30 if ( ODevice::inst ( ) -> model() != Model_iPAQ_H191x ) 30 if ( ODevice::inst ( ) -> model() != Model_iPAQ_H191x )
31 getProcApmStatusIpaq(); 31 getProcApmStatusIpaq();
32 } 32 }
33 percent = ps->batteryPercentRemaining(); 33 percent = ps->batteryPercentRemaining();
34} 34}
35 35
36/* 36/*
37 * Make use of the advanced apm interface of the ipaq 37 * Make use of the advanced apm interface of the ipaq
38 */ 38 */
39bool BatteryStatus::getProcApmStatusIpaq() { 39bool BatteryStatus::getProcApmStatusIpaq() {
40 40
41 bat2 = false; 41 bat2 = false;
42 42
43 QFile procApmIpaq("/proc/hal/battery"); 43 QFile procApmIpaq("/proc/hal/battery");
44 44
45 if (procApmIpaq.open(IO_ReadOnly) ) { 45 if (procApmIpaq.open(IO_ReadOnly) ) {
46 QStringList list; 46 QStringList list;
47 // since it is /proc we _must_ use QTextStream 47 // since it is /proc we _must_ use QTextStream
48 QTextStream stream ( &procApmIpaq); 48 QTextStream stream ( &procApmIpaq);
49 QString streamIn; 49 QString streamIn;
50 streamIn = stream.read(); 50 streamIn = stream.read();
51 list = QStringList::split("\n", streamIn); 51 list = QStringList::split("\n", streamIn);
52 52
53 sec2 = sec1 = ""; 53 sec2 = sec1 = "";
54 54
55 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 55 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
56 // not nice, need a rewrite later 56 // not nice, need a rewrite later
57 if( (*line).startsWith(" Percentage") ) { 57 if( (*line).startsWith(" Percentage") ) {
58 if (bat2 == true) { 58 if (bat2 == true) {
59 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2); 59 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
60 } else { 60 } else {
61 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 61 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
62 } 62 }
63 } else if( (*line).startsWith(" Life") ) { 63 } else if( (*line).startsWith(" Life") ) {
64 if (bat2 == true) { 64 if (bat2 == true) {
65 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 65 sec2 = (*line).mid(((*line).find(':')+2), 5 );
66 } else { 66 } else {
67 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 67 sec1 = (*line).mid(((*line).find(':')+2), 5 );
68 } 68 }
69 } else if( (*line).startsWith("Battery #1") ) { 69 } else if( (*line).startsWith("Battery #1") ) {
70 bat2 = true; 70 bat2 = true;
71 } else if( (*line).startsWith(" Status") ) { 71 } else if( (*line).startsWith(" Status") ) {
72 if (bat2 == true) { 72 if (bat2 == true) {
73 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 73 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
74 } else { 74 } else {
75 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 75 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
76 } 76 }
77 } else if( (*line).startsWith(" Chemistry") ) { 77 } else if( (*line).startsWith(" Chemistry") ) {
78 if (bat2 == true) { 78 if (bat2 == true) {
79 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 79 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
80 } else { 80 } else {
81 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 81 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
82 } 82 }
83 } 83 }
84 } 84 }
85 } else { 85 procApmIpaq.close();
86 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
87 } 86 }
88 87
89 procApmIpaq.close();
90 jackPercent = perc2.toInt(); 88 jackPercent = perc2.toInt();
91 ipaqPercent = perc1.toInt(); 89 ipaqPercent = perc1.toInt();
92 90
93 if (perc2.isEmpty() || perc2 == "unknow" ) { 91 if (perc2.isEmpty() || perc2 == "unknow" ) {
94 perc2 = tr("no data"); 92 perc2 = tr("no data");
95 } else { 93 } else {
96 perc2 += " %"; 94 perc2 += " %";
97 } 95 }
98 96
99 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 97 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
100 sec2 = tr("no data"); 98 sec2 = tr("no data");
101 } else { 99 } else {
102 sec2 += " min"; 100 sec2 += " min";
103 } 101 }
104 102
105 jackStatus.prepend( " ( " ); 103 jackStatus.prepend( " ( " );
106 jackStatus.append( " )" ); 104 jackStatus.append( " )" );
107 return true; 105 return true;
108} 106}
109 107
110 108
111void BatteryStatus::updatePercent( int pc ) { 109void BatteryStatus::updatePercent( int pc ) {
112 percent = pc; 110 percent = pc;
113 repaint(FALSE); 111 repaint(FALSE);
114} 112}
115 113
116void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 114void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
117 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 115 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
118 topgrad.hsv( &h1, &s1, &v1 ); 116 topgrad.hsv( &h1, &s1, &v1 );
119 botgrad.hsv( &h2, &s2, &v2 ); 117 botgrad.hsv( &h2, &s2, &v2 );
120 for ( int j = 0; j < hy-2; j++ ) { 118 for ( int j = 0; j < hy-2; j++ ) {
121 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 119 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
122 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 120 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
123 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 121 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
124 } 122 }
125 for ( int j = 0; j < hh; j++ ) { 123 for ( int j = 0; j < hh; j++ ) {
126 p->setPen( highlight ); 124 p->setPen( highlight );
127 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 125 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
128 } 126 }
129 for ( int j = 0; j < ng-hy-hh; j++ ) { 127 for ( int j = 0; j < ng-hy-hh; j++ ) {
130 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 128 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
131 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 129 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
132 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); 130 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
133 } 131 }
134} 132}
135 133
136QString BatteryStatus::statusText() const { 134QString BatteryStatus::statusText() const {
137 QString text; 135 QString text;
138 136
139 if ( ps->batteryStatus() == PowerStatus::Charging ) { 137 if ( ps->batteryStatus() == PowerStatus::Charging ) {
140 if (bat2) { 138 if (bat2) {
141 text = tr("Charging both devices"); 139 text = tr("Charging both devices");
142 } else { 140 } else {
143 text = tr("Charging"); 141 text = tr("Charging");
144 } 142 }
145 } else if ( ps->batteryPercentAccurate() ) { 143 } else if ( ps->batteryPercentAccurate() ) {
146 text = tr( "Remaining Power: %1%" ).arg( percent ); 144 text = tr( "Remaining Power: %1%" ).arg( percent );
147 //text.sprintf( tr("Remaining Power") + ": %i%%", percent ); 145 //text.sprintf( tr("Remaining Power") + ": %i%%", percent );
148 } else { 146 } else {
149 text = tr( "Battery status: " ); 147 text = tr( "Battery status: " );
150 switch ( ps->batteryStatus() ) { 148 switch ( ps->batteryStatus() ) {
151 case PowerStatus::High: 149 case PowerStatus::High:
152 text.append( tr( "Good" ) ); 150 text.append( tr( "Good" ) );
153 break; 151 break;
154 case PowerStatus::Low: 152 case PowerStatus::Low:
155 text.append( tr( "Low" ) ); 153 text.append( tr( "Low" ) );
156 break; 154 break;
157 case PowerStatus::VeryLow: 155 case PowerStatus::VeryLow:
158 text.append( tr( "Very Low" ) ); 156 text.append( tr( "Very Low" ) );
159 break; 157 break;
160 case PowerStatus::Critical: 158 case PowerStatus::Critical:
161 text.append( tr( "Critical" ) ); 159 text.append( tr( "Critical" ) );
162 break; 160 break;
163 default: // NotPresent, etc. 161 default: // NotPresent, etc.
164 text.append( tr( "Unknown" ) ); 162 text.append( tr( "Unknown" ) );
165 } 163 }
166 } 164 }
167 165
168 if ( ps->acStatus() == PowerStatus::Backup ) 166 if ( ps->acStatus() == PowerStatus::Backup )
169 { 167 {
170 text.append( '\n' ); 168 text.append( '\n' );
171 text.append( tr( "On backup power" ) ); 169 text.append( tr( "On backup power" ) );
172 } 170 }
173 else if ( ps->acStatus() == PowerStatus::Online ) 171 else if ( ps->acStatus() == PowerStatus::Online )
174 { 172 {
175 text.append( '\n' ); 173 text.append( '\n' );
176 text.append( tr( "Power on-line" ) ); 174 text.append( tr( "Power on-line" ) );
177 } 175 }
178 else if ( ps->acStatus() == PowerStatus::Offline ) 176 else if ( ps->acStatus() == PowerStatus::Offline )
179 { 177 {
180 text.append( '\n' ); 178 text.append( '\n' );
181 text.append( tr( "External power disconnected" ) ); 179 text.append( tr( "External power disconnected" ) );
182 } 180 }
183 181
184 if ( ps->batteryTimeRemaining() >= 0 ) 182 if ( ps->batteryTimeRemaining() >= 0 )
185 { 183 {