summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index a32a3a6..092a48d 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,255 +1,255 @@
1 1
2#include "batterystatus.h" 2#include "batterystatus.h"
3 3
4#include <qpe/power.h> 4#include <qpe/power.h>
5 5
6#include <opie/odevice.h> 6#include <opie/odevice.h>
7 7
8#include <qpainter.h> 8#include <qpainter.h>
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 <qlayout.h> 12#include <qlayout.h>
13#include <qtextstream.h> 13#include <qtextstream.h>
14#include <qapplication.h> 14#include <qapplication.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16 16
17using namespace Opie; 17using namespace Opie;
18 18
19BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 19BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
20 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { 20 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) {
21 setCaption( tr("Battery status") ); 21 setCaption( tr("Battery status") );
22 QPushButton *pb = new QPushButton( tr("Close"), this ); 22 QPushButton *pb = new QPushButton( tr("Close"), this );
23 QVBoxLayout *layout = new QVBoxLayout ( this ); 23 QVBoxLayout *layout = new QVBoxLayout ( this );
24 24
25 jackPercent = 0; 25 jackPercent = 0;
26 26
27 pb->setMaximumHeight(40); 27 pb->setMaximumHeight(40);
28 pb->setMaximumWidth( 120 ); 28 pb->setMaximumWidth( 120 );
29 29
30 pb->show(); 30 pb->show();
31 31
32 layout->addStretch( 0 ); 32 layout->addStretch( 0 );
33 layout->addWidget( pb ); 33 layout->addWidget( pb );
34 34
35 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 35 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
36 getProcApmStatusIpaq(); 36 getProcApmStatusIpaq();
37 } 37 }
38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); 38 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
39 percent = ps->batteryPercentRemaining(); 39 percent = ps->batteryPercentRemaining();
40 show(); 40 show();
41} 41}
42 42
43BatteryStatus::~BatteryStatus() 43BatteryStatus::~BatteryStatus()
44{ 44{
45} 45}
46 46
47/* 47/*
48 * Make use of the advanced apm interface of the ipaq 48 * Make use of the advanced apm interface of the ipaq
49 */ 49 */
50bool BatteryStatus::getProcApmStatusIpaq() { 50bool BatteryStatus::getProcApmStatusIpaq() {
51 51
52 bat2 = false; 52 bat2 = false;
53 53
54 QFile procApmIpaq("/proc/hal/battery"); 54 QFile procApmIpaq("/proc/hal/battery");
55 55
56 if (procApmIpaq.open(IO_ReadOnly) ) { 56 if (procApmIpaq.open(IO_ReadOnly) ) {
57 QStringList list; 57 QStringList list;
58 // since it is /proc we _must_ use QTextStream 58 // since it is /proc we _must_ use QTextStream
59 QTextStream stream ( &procApmIpaq); 59 QTextStream stream ( &procApmIpaq);
60 QString streamIn; 60 QString streamIn;
61 streamIn = stream.read(); 61 streamIn = stream.read();
62 list = QStringList::split("\n", streamIn); 62 list = QStringList::split("\n", streamIn);
63 63
64 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 64 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
65 // not nice, need a rewrite later 65 // not nice, need a rewrite later
66 if( (*line).startsWith(" Percentage") ){ 66 if( (*line).startsWith(" Percentage") ){
67 if (bat2 == true) { 67 if (bat2 == true) {
68 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 68 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
69 } else { 69 } else {
70 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 70 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
71 } 71 }
72 }else if( (*line).startsWith(" Life") ){ 72 }else if( (*line).startsWith(" Life") ){
73 if (bat2 == true) { 73 if (bat2 == true) {
74 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 74 sec2 = (*line).mid(((*line).find(':')+2), 5 );
75 } else { 75 } else {
76 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 76 sec1 = (*line).mid(((*line).find(':')+2), 5 );
77 } 77 }
78 }else if( (*line).startsWith("Battery #1") ){ 78 }else if( (*line).startsWith("Battery #1") ){
79 bat2 = true; 79 bat2 = true;
80 }else if( (*line).startsWith(" Status") ){ 80 }else if( (*line).startsWith(" Status") ){
81 if (bat2 == true) { 81 if (bat2 == true) {
82 jackStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1); 82 jackStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1);
83 } else { 83 } else {
84 ipaqStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1); 84 ipaqStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1);
85 } 85 }
86 }else if( (*line).startsWith(" Chemistry") ) { 86 }else if( (*line).startsWith(" Chemistry") ) {
87 if (bat2 == true) { 87 if (bat2 == true) {
88 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 88 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
89 } else { 89 } else {
90 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 90 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
91 } 91 }
92 } 92 }
93 } 93 }
94 } else { 94 } else {
95 QMessageBox::warning(this, tr("Failure"),tr("could not open file")); 95 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
96 } 96 }
97 97
98 procApmIpaq.close(); 98 procApmIpaq.close();
99 99
100 jackPercent = perc2.toInt(); 100 jackPercent = perc2.toInt();
101 ipaqPercent = perc1.toInt(); 101 ipaqPercent = perc1.toInt();
102 102
103 if (perc2.isEmpty()) { 103 if (perc2.isEmpty()) {
104 perc2 = "no data"; 104 perc2 = "no data";
105 } else { 105 } else {
106 perc2 += " %"; 106 perc2 += " %";
107 } 107 }
108 108
109 109
110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 110 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
111 sec2 = "no data"; 111 sec2 = "no data";
112 } else { 112 } else {
113 sec2 += " min"; 113 sec2 += " min";
114 } 114 }
115 115
116 jackStatus == (" ( " + jackStatus + " )"); 116 jackStatus == (" ( " + jackStatus + " )");
117 117
118 return true; 118 return true;
119} 119}
120 120
121 121
122void BatteryStatus::updatePercent( int pc ) { 122void BatteryStatus::updatePercent( int pc ) {
123 percent = pc; 123 percent = pc;
124 repaint(FALSE); 124 repaint(FALSE);
125} 125}
126 126
127void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 127void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
128 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 128 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
129 topgrad.hsv( &h1, &s1, &v1 ); 129 topgrad.hsv( &h1, &s1, &v1 );
130 botgrad.hsv( &h2, &s2, &v2 ); 130 botgrad.hsv( &h2, &s2, &v2 );
131 for ( int j = 0; j < hy-2; j++ ) { 131 for ( int j = 0; j < hy-2; j++ ) {
132 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 132 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
133 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 133 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
134 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 134 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
135 } 135 }
136 for ( int j = 0; j < hh; j++ ) { 136 for ( int j = 0; j < hh; j++ ) {
137 p->setPen( highlight ); 137 p->setPen( highlight );
138 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 138 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
139 } 139 }
140 for ( int j = 0; j < ng-hy-hh; j++ ) { 140 for ( int j = 0; j < ng-hy-hh; j++ ) {
141 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 141 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
142 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 142 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
143 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); 143 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
144 } 144 }
145} 145}
146 146
147void BatteryStatus::paintEvent( QPaintEvent * ) { 147void BatteryStatus::paintEvent( QPaintEvent * ) {
148 148
149 149
150 int screenWidth = qApp->desktop()->width(); 150 int screenWidth = qApp->desktop()->width();
151 int screenHeight = qApp->desktop()->height(); 151 int screenHeight = qApp->desktop()->height();
152 152
153 QPainter p(this); 153 QPainter p(this);
154 QString text; 154 QString text;
155 if ( ps->batteryStatus() == PowerStatus::Charging ) { 155 if ( ps->batteryStatus() == PowerStatus::Charging ) {
156 if (bat2) { 156 if (bat2) {
157 text = tr("Charging both devices"); 157 text = tr("Charging both devices");
158 } else { 158 } else {
159 text = tr("Charging"); 159 text = tr("Charging");
160 } 160 }
161 } else if ( ps->batteryPercentAccurate() ) { 161 } else if ( ps->batteryPercentAccurate() ) {
162 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); 162 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent );
163 } else { 163 } else {
164 text = tr("Battery status: "); 164 text = tr("Battery status: ");
165 switch ( ps->batteryStatus() ) { 165 switch ( ps->batteryStatus() ) {
166 case PowerStatus::High: 166 case PowerStatus::High:
167 text += tr("Good"); 167 text += tr("Good");
168 break; 168 break;
169 case PowerStatus::Low: 169 case PowerStatus::Low:
170 text += tr("Low"); 170 text += tr("Low");
171 break; 171 break;
172 case PowerStatus::VeryLow: 172 case PowerStatus::VeryLow:
173 text += tr("Very Low"); 173 text += tr("Very Low");
174 break; 174 break;
175 case PowerStatus::Critical: 175 case PowerStatus::Critical:
176 text += tr("Critical"); 176 text += tr("Critical");
177 break; 177 break;
178 default: // NotPresent, etc. 178 default: // NotPresent, etc.
179 text += tr("Unknown"); 179 text += tr("Unknown");
180 } 180 }
181 } 181 }
182 p.drawText( 10, 90, text ); 182 p.drawText( 10, 90, text );
183 183
184 if ( ps->acStatus() == PowerStatus::Backup ) 184 if ( ps->acStatus() == PowerStatus::Backup )
185 p.drawText( 10, 110, tr("On backup power") ); 185 p.drawText( 10, 110, tr("On backup power") );
186 else if ( ps->acStatus() == PowerStatus::Online ) 186 else if ( ps->acStatus() == PowerStatus::Online )
187 p.drawText( 10, 110, tr("Power on-line") ); 187 p.drawText( 10, 110, tr("Power on-line") );
188 else if ( ps->acStatus() == PowerStatus::Offline ) 188 else if ( ps->acStatus() == PowerStatus::Offline )
189 p.drawText( 10, 110, tr("External power disconnected") ); 189 p.drawText( 10, 110, tr("External power disconnected") );
190 190
191 if ( ps->batteryTimeRemaining() >= 0 ) { 191 if ( ps->batteryTimeRemaining() >= 0 ) {
192 text.sprintf( tr("Battery time remaining") + ": %im %02is", 192 text.sprintf( tr("Battery time remaining") + ": %im %02is",
193 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); 193 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
194 p.drawText( 10, 130, text ); 194 p.drawText( 10, 130, text );
195 } 195 }
196 196
197 QColor c; 197 QColor c;
198 QColor darkc; 198 QColor darkc;
199 QColor lightc; 199 QColor lightc;
200 if ( ps->acStatus() == PowerStatus::Offline ) { 200 if ( ps->acStatus() == PowerStatus::Offline ) {
201 c = blue.light(120); 201 c = blue.light(120);
202 darkc = c.dark(280); 202 darkc = c.dark(280);
203 lightc = c.light(145); 203 lightc = c.light(145);
204 } else if ( ps->acStatus() == PowerStatus::Online ) { 204 } else if ( ps->acStatus() == PowerStatus::Online ) {
205 c = green.dark(130); 205 c = green.dark(130);
206 darkc = c.dark(200); 206 darkc = c.dark(200);
207 lightc = c.light(220); 207 lightc = c.light(220);
208 } else { 208 } else {
209 c = red; 209 c = red;
210 darkc = c.dark(280); 210 darkc = c.dark(280);
211 lightc = c.light(140); 211 lightc = c.light(140);
212 } 212 }
213 if ( percent < 0 ) 213 if ( percent < 0 )
214 return; 214 return;
215 215
216 int rightEnd1 = screenWidth - 47; 216 int rightEnd1 = screenWidth - 47;
217 int rightEnd2 = screenWidth - 35; 217 int rightEnd2 = screenWidth - 35;
218 int percent2 = ( percent / 100.0 ) * rightEnd1 ; 218 int percent2 = ( percent / 100.0 ) * rightEnd1 ;
219 p.setPen( black ); 219 p.setPen( black );
220 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL); 220 qDrawShadePanel( &p, 9, 30, rightEnd1 , 39, colorGroup(), TRUE, 1, NULL);
221 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL); 221 qDrawShadePanel( &p, rightEnd2, 37, 12, 24, colorGroup(), TRUE, 1, NULL);
222 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 ); 222 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
223 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 ); 223 drawSegment( &p, QRect( 11 + percent2, 30, rightEnd1 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
224 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 ); 224 drawSegment( &p, QRect( rightEnd2, 37, 10, 25 ), white.light(80), black, white.light(90), 2 );
225 p.setPen( black); 225 p.setPen( black);
226 226
227 227
228 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 228 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
229 229
230 p.drawText(15, 50, tr ("Ipaq " + ipaqChem)); 230 p.drawText(15, 50, tr ("Ipaq " + ipaqChem));
231 231
232 QString jacketMsg; 232 QString jacketMsg;
233 if (bat2) { 233 if (bat2) {
234 p.setPen(black); 234 p.setPen(black);
235 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus); 235 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus);
236 p.drawText(10,240, tr("Battery time remaining: ") + sec2); 236 p.drawText(10,240, tr("Battery time remaining: ") + sec2);
237 jacketMsg = tr("Jacket " + jackChem); 237 jacketMsg = tr("Jacket " + jackChem);
238 } else { 238 } else {
239 jackPercent = 0; 239 jackPercent = 0;
240 jacketMsg = tr("No jacket with battery inserted"); 240 jacketMsg = tr("No jacket with battery inserted");
241 } 241 }
242 242
243 int jackPerc = ( jackPercent / 100 ) * screenWidth - 47; 243 int jackPerc = ( jackPercent / 100.0 ) * screenWidth - 47;
244 244
245 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL); 245 qDrawShadePanel( &p, 9, 160, rightEnd1, 39, colorGroup(), TRUE, 1, NULL);
246 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL); 246 qDrawShadePanel( &p, rightEnd2, 167, 12, 24, colorGroup(), TRUE, 1, NULL);
247 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 ); 247 drawSegment( &p, QRect( 10, 160, jackPerc, 40 ), lightc, darkc, lightc.light(115), 6 );
248 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 ); 248 drawSegment( &p, QRect( 11 + jackPerc, 160, rightEnd1 - jackPerc, 40 ), white.light(80), black, white.light(90), 6 );
249 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 ); 249 drawSegment( &p, QRect( rightEnd2, 167, 10, 25 ), white.light(80), black, white.light(90), 2 );
250 p.setPen( black ); 250 p.setPen( black );
251 p.drawText(15, 180, jacketMsg); 251 p.drawText(15, 180, jacketMsg);
252 } 252 }
253 253
254} 254}
255 255