summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-01-10 22:18:06 (UTC)
committer harlekin <harlekin>2003-01-10 22:18:06 (UTC)
commit2b407d0aae3c40c6f1caa356b53fb24cf1bff707 (patch) (unidiff)
treeb7e4c80f66ef5d0dd9f8d28f4d56971eb357f285
parent5199ee62d5478bbf5a8eb898c148352704f288e7 (diff)
downloadopie-2b407d0aae3c40c6f1caa356b53fb24cf1bff707.zip
opie-2b407d0aae3c40c6f1caa356b53fb24cf1bff707.tar.gz
opie-2b407d0aae3c40c6f1caa356b53fb24cf1bff707.tar.bz2
merged ipaq stuff in, one step closer to kill batteryapplet ipaq
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/batteryapplet.pro2
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp328
-rw-r--r--core/applets/batteryapplet/batterystatus.h14
3 files changed, 226 insertions, 118 deletions
diff --git a/core/applets/batteryapplet/batteryapplet.pro b/core/applets/batteryapplet/batteryapplet.pro
index a947ca6..d7e0a92 100644
--- a/core/applets/batteryapplet/batteryapplet.pro
+++ b/core/applets/batteryapplet/batteryapplet.pro
@@ -1,27 +1,27 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt warn_on release 2 CONFIG += qt warn_on release
3 HEADERS= battery.h batterystatus.h batteryappletimpl.h 3 HEADERS= battery.h batterystatus.h batteryappletimpl.h
4 SOURCES= battery.cpp batterystatus.cpp batteryappletimpl.cpp 4 SOURCES= battery.cpp batterystatus.cpp batteryappletimpl.cpp
5 TARGET = batteryapplet 5 TARGET = batteryapplet
6 DESTDIR = $(OPIEDIR)/plugins/applets 6 DESTDIR = $(OPIEDIR)/plugins/applets
7INCLUDEPATH += $(OPIEDIR)/include 7INCLUDEPATH += $(OPIEDIR)/include
8DEPENDPATH += ../$(OPIEDIR)/include .. 8DEPENDPATH += ../$(OPIEDIR)/include ..
9LIBS += -lqpe 9LIBS += -lqpe -lopie
10 VERSION = 1.0.0 10 VERSION = 1.0.0
11 11
12TRANSLATIONS = ../../../i18n/de/libbatteryapplet.ts \ 12TRANSLATIONS = ../../../i18n/de/libbatteryapplet.ts \
13 ../../../i18n/da/libbatteryapplet.ts \ 13 ../../../i18n/da/libbatteryapplet.ts \
14 ../../../i18n/xx/libbatteryapplet.ts \ 14 ../../../i18n/xx/libbatteryapplet.ts \
15 ../../../i18n/en/libbatteryapplet.ts \ 15 ../../../i18n/en/libbatteryapplet.ts \
16 ../../../i18n/es/libbatteryapplet.ts \ 16 ../../../i18n/es/libbatteryapplet.ts \
17 ../../../i18n/fr/libbatteryapplet.ts \ 17 ../../../i18n/fr/libbatteryapplet.ts \
18 ../../../i18n/hu/libbatteryapplet.ts \ 18 ../../../i18n/hu/libbatteryapplet.ts \
19 ../../../i18n/ja/libbatteryapplet.ts \ 19 ../../../i18n/ja/libbatteryapplet.ts \
20 ../../../i18n/ko/libbatteryapplet.ts \ 20 ../../../i18n/ko/libbatteryapplet.ts \
21 ../../../i18n/no/libbatteryapplet.ts \ 21 ../../../i18n/no/libbatteryapplet.ts \
22 ../../../i18n/pl/libbatteryapplet.ts \ 22 ../../../i18n/pl/libbatteryapplet.ts \
23 ../../../i18n/pt/libbatteryapplet.ts \ 23 ../../../i18n/pt/libbatteryapplet.ts \
24 ../../../i18n/pt_BR/libbatteryapplet.ts \ 24 ../../../i18n/pt_BR/libbatteryapplet.ts \
25 ../../../i18n/sl/libbatteryapplet.ts \ 25 ../../../i18n/sl/libbatteryapplet.ts \
26 ../../../i18n/zh_CN/libbatteryapplet.ts \ 26 ../../../i18n/zh_CN/libbatteryapplet.ts \
27 ../../../i18n/zh_TW/libbatteryapplet.ts 27 ../../../i18n/zh_TW/libbatteryapplet.ts
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index d18b6c9..2af3e99 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,140 +1,236 @@
1/********************************************************************** 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#include "batterystatus.h" 2#include "batterystatus.h"
21 3
22#include <qpe/power.h> 4#include <qpe/power.h>
23 5
6#include <opie/odevice.h>
7
24#include <qpainter.h> 8#include <qpainter.h>
25#include <qpushbutton.h> 9#include <qpushbutton.h>
26#include <qdrawutil.h> 10#include <qdrawutil.h>
11#include <qfile.h>
12#include <qtextstream.h>
13#include <qmessagebox.h>
27 14
15using namespace Opie;
28 16
29BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
30 : QWidget( parent, 0, WDestructiveClose), ps(p) 18 : QWidget( parent, 0, WDestructiveClose), ps(p) {
31{ 19 setCaption( tr("Battery status for Ipaq") );
32 setCaption( tr("Battery Status") ); 20 QPushButton *pb = new QPushButton( tr("Close"), this );
33 QPushButton *pb = new QPushButton( tr("Close"), this ); 21 pb->move( 70, 250 );
34 pb->move( 70, 220 ); 22 pb->setMaximumHeight(20);
35 pb->show(); 23 pb->show();
36 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); 24 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
37 percent = ps->batteryPercentRemaining(); 25 getProcApmStatusIpaq();
38 show(); 26 }
27 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
28 percent = ps->batteryPercentRemaining();
29 show();
39} 30}
40 31
41BatteryStatus::~BatteryStatus() 32BatteryStatus::~BatteryStatus()
42{ 33{
43} 34}
44 35
45void BatteryStatus::updatePercent( int pc ) 36/*
46{ 37 * Make use of the advanced apm interface of the ipaq
47 percent = pc; 38 */
48 repaint(FALSE); 39bool BatteryStatus::getProcApmStatusIpaq() {
49}
50 40
51void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) 41 bat2 = false;
52{ 42
53 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 43 QFile procApmIpaq("/proc/hal/battery");
54 topgrad.hsv( &h1, &s1, &v1 ); 44
55 botgrad.hsv( &h2, &s2, &v2 ); 45 if (procApmIpaq.open(IO_ReadOnly) ) {
56 for ( int j = 0; j < hy-2; j++ ) { 46 QStringList list;
57 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 47 // since it is /proc we _must_ use QTextStream
58 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 48 QTextStream stream ( &procApmIpaq);
59 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 49 QString streamIn;
60 } 50 streamIn = stream.read();
61 for ( int j = 0; j < hh; j++ ) { 51 list = QStringList::split("\n", streamIn);
62 p->setPen( highlight ); 52
63 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 53 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
54 // not nice, need a rewrite later
55 if( (*line).startsWith(" Percentage") ){
56 if (bat2 == true) {
57 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
58 } else {
59 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
60 }
61 }else if( (*line).startsWith(" Life") ){
62 if (bat2 == true) {
63 sec2 = (*line).mid(((*line).find(':')+2), 5 );
64 } else {
65 sec1 = (*line).mid(((*line).find(':')+2), 5 );
66 }
67 }else if( (*line).startsWith("Battery #1") ){
68 bat2 = true;
69 }else if( (*line).startsWith(" Status") ){
70 if (bat2 == true) {
71 jackStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1);
72 } else {
73 ipaqStatus = (*line).mid((*line).find('(')+1., (*line).find(')')-(*line).find('(')-1);
74 }
75 }else if( (*line).startsWith(" Chemistry") ) {
76 if (bat2 == true) {
77 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
78 } else {
79 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
80 }
81 }
64 } 82 }
65 for ( int j = 0; j < ng-hy-hh; j++ ) { 83 } else {
66 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 84 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
67 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 85 }
68 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j ); 86
87 procApmIpaq.close();
88
89 jackPercent = perc2.toInt();
90 ipaqPercent = perc1.toInt();
91
92 if (perc2.isEmpty()) {
93 perc2 = "no data";
94 } else {
95 perc2 += " %";
96 }
97
98
99 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
100 sec2 = "no data";
101 } else {
102 sec2 += " min";
103 }
104
105 jackStatus == (" ( " + jackStatus + " )");
106
107 return true;
108}
109
110
111void BatteryStatus::updatePercent( int pc ) {
112 percent = pc;
113 repaint(FALSE);
114}
115
116void 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;
118 topgrad.hsv( &h1, &s1, &v1 );
119 botgrad.hsv( &h2, &s2, &v2 );
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),
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 );
124 }
125 for ( int j = 0; j < hh; j++ ) {
126 p->setPen( highlight );
127 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
69 } 128 }
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),
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 );
133 }
70} 134}
71 135
72void BatteryStatus::paintEvent( QPaintEvent * ) 136void BatteryStatus::paintEvent( QPaintEvent * ) {
73{ 137
74 QPainter p(this); 138 QPainter p(this);
75 QString text; 139 QString text;
76 if ( ps->batteryStatus() == PowerStatus::Charging ) { 140 if ( ps->batteryStatus() == PowerStatus::Charging ) {
77 text = tr("Charging"); 141 if (bat2) {
78 } else if ( ps->batteryPercentAccurate() ) { 142 text = tr("Charging both devices");
79 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent ); 143 } else {
80 } else { 144 text = tr("Charging");
81 text = tr("Battery status: ");
82 switch ( ps->batteryStatus() ) {
83 case PowerStatus::High:
84 text += tr("Good");
85 break;
86 case PowerStatus::Low:
87 text += tr("Low");
88 break;
89 case PowerStatus::VeryLow:
90 text += tr("Very Low");
91 break;
92 case PowerStatus::Critical:
93 text += tr("Critical");
94 break;
95 default: // NotPresent, etc.
96 text += tr("Unknown");
97 } 145 }
146 } else if ( ps->batteryPercentAccurate() ) {
147 text.sprintf( tr("Percentage battery remaining") + ": %i%%", percent );
148 } else {
149 text = tr("Battery status: ");
150 switch ( ps->batteryStatus() ) {
151 case PowerStatus::High:
152 text += tr("Good");
153 break;
154 case PowerStatus::Low:
155 text += tr("Low");
156 break;
157 case PowerStatus::VeryLow:
158 text += tr("Very Low");
159 break;
160 case PowerStatus::Critical:
161 text += tr("Critical");
162 break;
163 default: // NotPresent, etc.
164 text += tr("Unknown");
98 } 165 }
99 p.drawText( 10, 120, text ); 166 }
100 if ( ps->acStatus() == PowerStatus::Backup ) 167 p.drawText( 10, 90, text );
101 p.drawText( 10, 150, tr("On backup power") ); 168
102 else if ( ps->acStatus() == PowerStatus::Online ) 169 if ( ps->acStatus() == PowerStatus::Backup )
103 p.drawText( 10, 150, tr("Power on-line") ); 170 p.drawText( 10, 110, tr("On backup power") );
104 else if ( ps->acStatus() == PowerStatus::Offline ) 171 else if ( ps->acStatus() == PowerStatus::Online )
105 p.drawText( 10, 150, tr("External power disconnected") ); 172 p.drawText( 10, 110, tr("Power on-line") );
106 173 else if ( ps->acStatus() == PowerStatus::Offline )
107 if ( ps->batteryTimeRemaining() >= 0 ) { 174 p.drawText( 10, 110, tr("External power disconnected") );
108 text.sprintf( tr("Battery time remaining") + ": %im %02is", 175
109 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 ); 176 if ( ps->batteryTimeRemaining() >= 0 ) {
110 p.drawText( 10, 180, text ); 177 text.sprintf( tr("Battery time remaining") + ": %im %02is",
111 } 178 ps->batteryTimeRemaining() / 60, ps->batteryTimeRemaining() % 60 );
179 p.drawText( 10, 130, text );
180 }
181
182 QColor c;
183 QColor darkc;
184 QColor lightc;
185 if ( ps->acStatus() == PowerStatus::Offline ) {
186 c = blue.light(120);
187 darkc = c.dark(280);
188 lightc = c.light(145);
189 } else if ( ps->acStatus() == PowerStatus::Online ) {
190 c = green.dark(130);
191 darkc = c.dark(200);
192 lightc = c.light(220);
193 } else {
194 c = red;
195 darkc = c.dark(280);
196 lightc = c.light(140);
197 }
198 if ( percent < 0 )
199 return;
200
201 int percent2 = percent * 2;
202 p.setPen( black );
203 qDrawShadePanel( &p, 9, 30, 204, 39, 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 );
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 );
208 p.setPen( black);
209
210
211 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
212
213 p.drawText(15, 50, tr ("Ipaq " + ipaqChem));
214
215 QString jacketMsg;
216 if (bat2) {
217 p.setPen(black);
218 p.drawText(10,220, tr("Percentage battery remaining: ") + perc2 + " " + jackStatus);
219 p.drawText(10,240, tr("Battery time remaining: ") + sec2);
220 jacketMsg = tr("Jacket " + jackChem);
221 } else {
222 jackPercent = 0;
223 jacketMsg = tr("No jacket with battery inserted");
224 }
225
226 qDrawShadePanel( &p, 9, 160, 204, 39, 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 );
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 );
231 p.setPen( black );
232 p.drawText(15, 180, jacketMsg);
233 }
112 234
113 QColor c;
114 QColor darkc;
115 QColor lightc;
116 if ( ps->acStatus() == PowerStatus::Offline ) {
117 c = blue.light(120);
118 darkc = c.dark(280);
119 lightc = c.light(145);
120 } else if ( ps->acStatus() == PowerStatus::Online ) {
121 c = green.dark(130);
122 darkc = c.dark(200);
123 lightc = c.light(220);
124 } else {
125 c = red;
126 darkc = c.dark(280);
127 lightc = c.light(140);
128 }
129 if ( percent < 0 )
130 return;
131
132 int percent2 = percent * 2;
133 p.setPen( black );
134 qDrawShadePanel( &p, 9, 30, 204, 39, colorGroup(), TRUE, 1, NULL);
135 qDrawShadePanel( &p, 212, 37, 12, 24, colorGroup(), TRUE, 1, NULL);
136 drawSegment( &p, QRect( 10, 30, percent2, 40 ), lightc, darkc, lightc.light(115), 6 );
137 drawSegment( &p, QRect( 11 + percent2, 30, 200 - percent2, 40 ), white.light(80), black, white.light(90), 6 );
138 drawSegment( &p, QRect( 212, 37, 10, 25 ), white.light(80), black, white.light(90), 2 );
139} 235}
140 236
diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h
index 0dc25af..18c2943 100644
--- a/core/applets/batteryapplet/batterystatus.h
+++ b/core/applets/batteryapplet/batterystatus.h
@@ -15,32 +15,44 @@
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef BATTERY_STATUS_H 20#ifndef BATTERY_STATUS_H
21#define BATTERY_STATUS_H 21#define BATTERY_STATUS_H
22 22
23#include <qwidget.h> 23#include <qwidget.h>
24 24
25class PowerStatus; 25class PowerStatus;
26 26
27class BatteryStatus : public QWidget 27class BatteryStatus : public QWidget
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 BatteryStatus( const PowerStatus *s, QWidget *parent=0 ); 31 BatteryStatus( const PowerStatus *s, QWidget *parent=0 );
32 ~BatteryStatus(); 32 ~BatteryStatus();
33 33
34 void updatePercent( int ); 34 void updatePercent( int );
35 35
36protected: 36protected:
37 void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ); 37 void drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height );
38 void paintEvent( QPaintEvent *pe ); 38 void paintEvent( QPaintEvent *pe );
39 39 bool BatteryStatus::getProcApmStatusIpaq();
40private: 40private:
41 const PowerStatus *ps; 41 const PowerStatus *ps;
42 int percent; 42 int percent;
43 int ipaqPercent;
44 int jackPercent;
45 int jackMinutes;
46 QString perc1;
47 QString sec1;
48 QString perc2;
49 QString sec2;
50 QString ipaqStatus;
51 QString jackStatus;
52 QString ipaqChem;
53 QString jackChem;
54 bool bat2;
43}; 55};
44 56
45#endif 57#endif
46 58