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