summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp13
-rw-r--r--core/applets/batteryapplet/battery.h1
-rw-r--r--core/applets/batteryapplet/batteryapplet.pro6
-rw-r--r--core/applets/batteryapplet/batteryappletimpl.cpp65
-rw-r--r--core/applets/batteryapplet/batteryappletimpl.h43
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp5
6 files changed, 20 insertions, 113 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index 9a9ddf6..fed9b34 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -1,170 +1,183 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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#include "battery.h" 20#include "battery.h"
21#include "batterystatus.h" 21#include "batterystatus.h"
22 22
23/* OPIE */
24#include <opie2/otaskbarapplet.h>
23#include <qpe/applnk.h> 25#include <qpe/applnk.h>
24#include <qpe/config.h> 26#include <qpe/config.h>
25#include <qpe/power.h> 27#include <qpe/power.h>
26#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
27 29
30/* QT */
28#include <qpainter.h> 31#include <qpainter.h>
29#include <qtimer.h> 32#include <qtimer.h>
30 33
31 34
32BatteryMeter::BatteryMeter( QWidget *parent ) 35BatteryMeter::BatteryMeter( QWidget *parent )
33 : QWidget( parent ), charging(false) 36 : QWidget( parent ), charging(false)
34{ 37{
35 ps = new PowerStatus; 38 ps = new PowerStatus;
36 startTimer( 10000 ); 39 startTimer( 10000 );
37 40
38 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 41 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
39 setFixedHeight( AppLnk::smallIconSize() ); 42 setFixedHeight( AppLnk::smallIconSize() );
40 43
41 chargeTimer = new QTimer( this ); 44 chargeTimer = new QTimer( this );
42 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 45 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
43 timerEvent(0); 46 timerEvent(0);
44 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 47 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
45 Config c( "qpe" ); 48 Config c( "qpe" );
46 c.setGroup( "Battery" ); 49 c.setGroup( "Battery" );
47 style = c.readNumEntry( "Style", 0 ); 50 style = c.readNumEntry( "Style", 0 );
48} 51}
49 52
50BatteryMeter::~BatteryMeter() 53BatteryMeter::~BatteryMeter()
51{ 54{
52 delete ps; 55 delete ps;
53} 56}
54 57
55QSize BatteryMeter::sizeHint() const 58QSize BatteryMeter::sizeHint() const
56{ 59{
57 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 60 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
58} 61}
59 62
60void BatteryMeter::mousePressEvent( QMouseEvent* e ) 63void BatteryMeter::mousePressEvent( QMouseEvent* e )
61{ 64{
62 if ( e->button() == RightButton ) 65 if ( e->button() == RightButton )
63 { 66 {
64 style = 1-style; 67 style = 1-style;
65 Config c( "qpe" ); 68 Config c( "qpe" );
66 c.setGroup( "Battery" ); 69 c.setGroup( "Battery" );
67 c.writeEntry( "Style", style ); 70 c.writeEntry( "Style", style );
68 repaint( true ); 71 repaint( true );
69 } 72 }
70 QWidget::mousePressEvent( e ); 73 QWidget::mousePressEvent( e );
71} 74}
72 75
73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) 76void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ )
74{ 77{
75 if ( batteryView && batteryView->isVisible() ) { 78 if ( batteryView && batteryView->isVisible() ) {
76 delete (QWidget *) batteryView; 79 delete (QWidget *) batteryView;
77 } else { 80 } else {
78 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 81 if ( !batteryView ) batteryView = new BatteryStatus( ps );
79 QPEApplication::showWidget( batteryView ); 82 QPEApplication::showWidget( batteryView );
80 batteryView->raise(); 83 batteryView->raise();
81 batteryView->show(); 84 batteryView->show();
82 } 85 }
83} 86}
84 87
85void BatteryMeter::timerEvent( QTimerEvent * ) 88void BatteryMeter::timerEvent( QTimerEvent * )
86{ 89{
87 PowerStatus prev = *ps; 90 PowerStatus prev = *ps;
88 91
89 *ps = PowerStatusManager::readStatus(); 92 *ps = PowerStatusManager::readStatus();
90 93
91 if ( prev != *ps ) { 94 if ( prev != *ps ) {
92 percent = ps->batteryPercentRemaining(); 95 percent = ps->batteryPercentRemaining();
93 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 96 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
94 percent = 0; 97 percent = 0;
95 charging = true; 98 charging = true;
96 chargeTimer->start( 500 ); 99 chargeTimer->start( 500 );
97 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 100 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
98 charging = false; 101 charging = false;
99 chargeTimer->stop(); 102 chargeTimer->stop();
100 if ( batteryView ) 103 if ( batteryView )
101 batteryView->updatePercent( percent ); 104 batteryView->updatePercent( percent );
102 } 105 }
103 repaint( style != 0 ); 106 repaint( style != 0 );
104 if ( batteryView ) 107 if ( batteryView )
105 batteryView->repaint(); 108 batteryView->repaint();
106 } 109 }
107} 110}
108 111
109void BatteryMeter::chargeTimeout() 112void BatteryMeter::chargeTimeout()
110{ 113{
111 percent += 20; 114 percent += 20;
112 if ( percent > 100 ) 115 if ( percent > 100 )
113 percent = 0; 116 percent = 0;
114 117
115 repaint(FALSE); 118 repaint(FALSE);
116 if ( batteryView ) 119 if ( batteryView )
117 batteryView->updatePercent( percent ); 120 batteryView->updatePercent( percent );
118} 121}
119 122
120void BatteryMeter::paintEvent( QPaintEvent* ) 123void BatteryMeter::paintEvent( QPaintEvent* )
121{ 124{
122 125
123 if ( style == 1 ) 126 if ( style == 1 )
124 { 127 {
125 QPainter p(this); 128 QPainter p(this);
126 QFont f( "Fixed", AppLnk::smallIconSize()/2 ); 129 QFont f( "Fixed", AppLnk::smallIconSize()/2 );
127 QFontMetrics fm( f ); 130 QFontMetrics fm( f );
128 p.setFont( f ); 131 p.setFont( f );
129 p.drawText( 0, height()/2, QString::number( percent ) ); 132 p.drawText( 0, height()/2, QString::number( percent ) );
130 p.drawText( width()/4, height(), "%" ); 133 p.drawText( width()/4, height(), "%" );
131 return; 134 return;
132 } 135 }
133 136
134 QPainter p(this); 137 QPainter p(this);
135 QColor color; 138 QColor color;
136 QColor g = gray.light( 160 ); 139 QColor g = gray.light( 160 );
137 switch ( ps->acStatus() ) 140 switch ( ps->acStatus() )
138 { 141 {
139 case PowerStatus::Offline: color = blue.light( 150 ); break; 142 case PowerStatus::Offline: color = blue.light( 150 ); break;
140 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 143 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break;
141 default: color = red.light( 160 ); 144 default: color = red.light( 160 );
142 } 145 }
143 146
144 int w = height() / 2; 147 int w = height() / 2;
145 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 148 if ( !(w%2) ) w--; // should have an odd value to get a real middle line
146 int h = height() - 4; 149 int h = height() - 4;
147 int pix = (percent * h) / 100; 150 int pix = (percent * h) / 100;
148 int y2 = height() -2; 151 int y2 = height() -2;
149 int y = y2 - pix; 152 int y = y2 - pix;
150 int x1 = (width() - w ) / 2; 153 int x1 = (width() - w ) / 2;
151 154
152 p.setPen(QColor(80,80,80)); 155 p.setPen(QColor(80,80,80));
153 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header 156 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header
154 p.drawRect(x1,1,w,height()-1); // corpus 157 p.drawRect(x1,1,w,height()-1); // corpus
155 p.setBrush(color); 158 p.setBrush(color);
156 159
157 //int extra = ((percent * h) % 100)/(100/4); 160 //int extra = ((percent * h) % 100)/(100/4);
158 161
159 int middle = w/2; 162 int middle = w/2;
160 for ( int i = 0; i < middle; i++ ) 163 for ( int i = 0; i < middle; i++ )
161 { 164 {
162 p.setPen( gray.dark( 100+i*20 ) ); 165 p.setPen( gray.dark( 100+i*20 ) );
163 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 166 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
164 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 167 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
165 p.setPen( color.dark( 100+i*20 ) ); 168 p.setPen( color.dark( 100+i*20 ) );
166 p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); 169 p.drawLine( x1+middle-i, y, x1+middle-i, y2 );
167 p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); 170 p.drawLine( x1+middle+i, y, x1+middle+i, y2 );
168 } 171 }
169} 172}
170 173
174int BatteryMeter::position()
175{
176 return 8;
177}
178
179Q_EXPORT_INTERFACE()
180{
181 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<BatteryMeter> );
182}
183
diff --git a/core/applets/batteryapplet/battery.h b/core/applets/batteryapplet/battery.h
index c2d1216..622c083 100644
--- a/core/applets/batteryapplet/battery.h
+++ b/core/applets/batteryapplet/battery.h
@@ -1,57 +1,58 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
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_H 20#ifndef BATTERY_H
21#define BATTERY_H 21#define BATTERY_H
22 22
23#include <qwidget.h> 23#include <qwidget.h>
24#include <qguardedptr.h> 24#include <qguardedptr.h>
25 25
26class PowerStatus; 26class PowerStatus;
27class BatteryStatus; 27class BatteryStatus;
28class QTimer; 28class QTimer;
29 29
30class BatteryMeter : public QWidget 30class BatteryMeter : public QWidget
31{ 31{
32 Q_OBJECT 32 Q_OBJECT
33 public: 33 public:
34 BatteryMeter( QWidget *parent = 0 ); 34 BatteryMeter( QWidget *parent = 0 );
35 ~BatteryMeter(); 35 ~BatteryMeter();
36 36
37 QSize sizeHint() const; 37 QSize sizeHint() const;
38 static int position();
38 39
39 protected: 40 protected:
40 void timerEvent( QTimerEvent* ); 41 void timerEvent( QTimerEvent* );
41 void paintEvent( QPaintEvent* ); 42 void paintEvent( QPaintEvent* );
42 void mousePressEvent( QMouseEvent* ); 43 void mousePressEvent( QMouseEvent* );
43 void mouseReleaseEvent( QMouseEvent* ); 44 void mouseReleaseEvent( QMouseEvent* );
44 45
45 protected slots: 46 protected slots:
46 void chargeTimeout(); 47 void chargeTimeout();
47 48
48 protected: 49 protected:
49 QGuardedPtr<BatteryStatus> batteryView; 50 QGuardedPtr<BatteryStatus> batteryView;
50 PowerStatus *ps; 51 PowerStatus *ps;
51 QTimer *chargeTimer; 52 QTimer *chargeTimer;
52 int percent; 53 int percent;
53 bool charging; 54 bool charging;
54 int style; 55 int style;
55}; 56};
56 57
57#endif 58#endif
diff --git a/core/applets/batteryapplet/batteryapplet.pro b/core/applets/batteryapplet/batteryapplet.pro
index 2076987..d956aa0 100644
--- a/core/applets/batteryapplet/batteryapplet.pro
+++ b/core/applets/batteryapplet/batteryapplet.pro
@@ -1,13 +1,13 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt plugin warn_on release 2 CONFIG += qt plugin warn_on release
3 HEADERS= battery.h batterystatus.h batteryappletimpl.h 3 HEADERS= battery.h batterystatus.h
4 SOURCES= battery.cpp batterystatus.cpp batteryappletimpl.cpp 4 SOURCES= battery.cpp batterystatus.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 -lopie 9LIBS += -lqpe -lopiecore2
10 VERSION = 1.0.0 10 VERSION = 1.0.0
11 11
12include ( $(OPIEDIR)/include.pro ) 12include ( $(OPIEDIR)/include.pro )
13target.path = $$prefix/plugins/applets 13target.path = $$prefix/plugins/applets
diff --git a/core/applets/batteryapplet/batteryappletimpl.cpp b/core/applets/batteryapplet/batteryappletimpl.cpp
deleted file mode 100644
index 7cc5f50..0000000
--- a/core/applets/batteryapplet/batteryappletimpl.cpp
+++ b/dev/null
@@ -1,65 +0,0 @@
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 "battery.h"
21#include "batteryappletimpl.h"
22
23
24BatteryAppletImpl::BatteryAppletImpl()
25 : battery(0)
26{
27}
28
29BatteryAppletImpl::~BatteryAppletImpl()
30{
31 delete battery;
32}
33
34QWidget *BatteryAppletImpl::applet( QWidget *parent )
35{
36 if ( !battery )
37 battery = new BatteryMeter( parent );
38 return battery;
39}
40
41int BatteryAppletImpl::position() const
42{
43 return 8;
44}
45
46QRESULT BatteryAppletImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
47{
48 *iface = 0;
49 if ( uuid == IID_QUnknown )
50 *iface = this;
51 else if ( uuid == IID_TaskbarApplet )
52 *iface = this;
53 else
54 return QS_FALSE;
55
56 if ( *iface )
57 (*iface)->addRef();
58 return QS_OK;
59}
60
61Q_EXPORT_INTERFACE()
62{
63 Q_CREATE_INSTANCE( BatteryAppletImpl )
64}
65
diff --git a/core/applets/batteryapplet/batteryappletimpl.h b/core/applets/batteryapplet/batteryappletimpl.h
deleted file mode 100644
index 99654e3..0000000
--- a/core/applets/batteryapplet/batteryappletimpl.h
+++ b/dev/null
@@ -1,43 +0,0 @@
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#ifndef BATTERYAPPLETIMPL_H
21#define BATTERYAPPLETIMPL_H
22
23#include <qpe/taskbarappletinterface.h>
24
25class BatteryMeter;
26
27class BatteryAppletImpl : public TaskbarAppletInterface
28{
29public:
30 BatteryAppletImpl();
31 virtual ~BatteryAppletImpl();
32
33 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
34 Q_REFCOUNT
35
36 virtual QWidget *applet( QWidget *parent );
37 virtual int position() const;
38
39private:
40 BatteryMeter *battery;
41};
42
43#endif
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index 86b20e8..b9ca7b5 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,135 +1,136 @@
1 1
2#include "batterystatus.h" 2#include "batterystatus.h"
3 3
4/* OPIE */
5#include <opie2/odevice.h>
4#include <qpe/power.h> 6#include <qpe/power.h>
5 7
6#include <opie/odevice.h> 8/* QT */
7
8#include <qpainter.h> 9#include <qpainter.h>
9#include <qpushbutton.h> 10#include <qpushbutton.h>
10#include <qdrawutil.h> 11#include <qdrawutil.h>
11#include <qfile.h> 12#include <qfile.h>
12#include <qlayout.h> 13#include <qlayout.h>
13#include <qtextstream.h> 14#include <qtextstream.h>
14#include <qapplication.h> 15#include <qapplication.h>
15#include <qmessagebox.h> 16#include <qmessagebox.h>
16 17
17using namespace Opie; 18using namespace Opie;
18 19
19BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 20BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
20 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { 21 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) {
21 setCaption( tr("Battery status") ); 22 setCaption( tr("Battery status") );
22 setMinimumSize( 150, 200 ); 23 setMinimumSize( 150, 200 );
23 24
24 QPushButton *pb = new QPushButton( tr("Close"), this ); 25 QPushButton *pb = new QPushButton( tr("Close"), this );
25 QVBoxLayout *layout = new QVBoxLayout ( this ); 26 QVBoxLayout *layout = new QVBoxLayout ( this );
26 27
27 jackPercent = 0; 28 jackPercent = 0;
28 29
29 pb->setMaximumSize( 120, 40 ); 30 pb->setMaximumSize( 120, 40 );
30 31
31 pb->show(); 32 pb->show();
32 33
33 layout->addStretch(); 34 layout->addStretch();
34 layout->addWidget( pb ); 35 layout->addWidget( pb );
35 36
36 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 37 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
37 getProcApmStatusIpaq(); 38 getProcApmStatusIpaq();
38 } 39 }
39 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) ); 40 connect( pb, SIGNAL( clicked() ), this, SLOT( close() ) );
40 percent = ps->batteryPercentRemaining(); 41 percent = ps->batteryPercentRemaining();
41 show(); 42 show();
42} 43}
43 44
44BatteryStatus::~BatteryStatus() 45BatteryStatus::~BatteryStatus()
45{ 46{
46} 47}
47 48
48/* 49/*
49 * Make use of the advanced apm interface of the ipaq 50 * Make use of the advanced apm interface of the ipaq
50 */ 51 */
51bool BatteryStatus::getProcApmStatusIpaq() { 52bool BatteryStatus::getProcApmStatusIpaq() {
52 53
53 bat2 = false; 54 bat2 = false;
54 55
55 QFile procApmIpaq("/proc/hal/battery"); 56 QFile procApmIpaq("/proc/hal/battery");
56 57
57 if (procApmIpaq.open(IO_ReadOnly) ) { 58 if (procApmIpaq.open(IO_ReadOnly) ) {
58 QStringList list; 59 QStringList list;
59 // since it is /proc we _must_ use QTextStream 60 // since it is /proc we _must_ use QTextStream
60 QTextStream stream ( &procApmIpaq); 61 QTextStream stream ( &procApmIpaq);
61 QString streamIn; 62 QString streamIn;
62 streamIn = stream.read(); 63 streamIn = stream.read();
63 list = QStringList::split("\n", streamIn); 64 list = QStringList::split("\n", streamIn);
64 65
65 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 66 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
66 // not nice, need a rewrite later 67 // not nice, need a rewrite later
67 if( (*line).startsWith(" Percentage") ){ 68 if( (*line).startsWith(" Percentage") ){
68 if (bat2 == true) { 69 if (bat2 == true) {
69 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 70 perc2 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
70 } else { 71 } else {
71 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 72 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
72 } 73 }
73 }else if( (*line).startsWith(" Life") ){ 74 }else if( (*line).startsWith(" Life") ){
74 if (bat2 == true) { 75 if (bat2 == true) {
75 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 76 sec2 = (*line).mid(((*line).find(':')+2), 5 );
76 } else { 77 } else {
77 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 78 sec1 = (*line).mid(((*line).find(':')+2), 5 );
78 } 79 }
79 }else if( (*line).startsWith("Battery #1") ){ 80 }else if( (*line).startsWith("Battery #1") ){
80 bat2 = true; 81 bat2 = true;
81 }else if( (*line).startsWith(" Status") ){ 82 }else if( (*line).startsWith(" Status") ){
82 if (bat2 == true) { 83 if (bat2 == true) {
83 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 84 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
84 } else { 85 } else {
85 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 86 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
86 } 87 }
87 }else if( (*line).startsWith(" Chemistry") ) { 88 }else if( (*line).startsWith(" Chemistry") ) {
88 if (bat2 == true) { 89 if (bat2 == true) {
89 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 90 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
90 } else { 91 } else {
91 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 92 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
92 } 93 }
93 } 94 }
94 } 95 }
95 } else { 96 } else {
96 QMessageBox::warning(this, tr("Failure"),tr("could not open file")); 97 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
97 } 98 }
98 99
99 procApmIpaq.close(); 100 procApmIpaq.close();
100 101
101 jackPercent = perc2.toInt(); 102 jackPercent = perc2.toInt();
102 ipaqPercent = perc1.toInt(); 103 ipaqPercent = perc1.toInt();
103 104
104 if (perc2.isEmpty()) { 105 if (perc2.isEmpty()) {
105 perc2 = tr("no data"); 106 perc2 = tr("no data");
106 } else { 107 } else {
107 perc2 += " %"; 108 perc2 += " %";
108 } 109 }
109 110
110 111
111 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 112 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
112 sec2 = tr("no data"); 113 sec2 = tr("no data");
113 } else { 114 } else {
114 sec2 += " min"; 115 sec2 += " min";
115 } 116 }
116 117
117 jackStatus == (" ( " + jackStatus + " )"); 118 jackStatus == (" ( " + jackStatus + " )");
118 119
119 return true; 120 return true;
120} 121}
121 122
122 123
123void BatteryStatus::updatePercent( int pc ) { 124void BatteryStatus::updatePercent( int pc ) {
124 percent = pc; 125 percent = pc;
125 repaint(FALSE); 126 repaint(FALSE);
126} 127}
127 128
128void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 129void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) {
129 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height; 130 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
130 topgrad.hsv( &h1, &s1, &v1 ); 131 topgrad.hsv( &h1, &s1, &v1 );
131 botgrad.hsv( &h2, &s2, &v2 ); 132 botgrad.hsv( &h2, &s2, &v2 );
132 for ( int j = 0; j < hy-2; j++ ) { 133 for ( int j = 0; j < hy-2; j++ ) {
133 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 134 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
134 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 135 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
135 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j ); 136 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );