summaryrefslogtreecommitdiff
path: root/core/applets/batteryapplet
Unidiff
Diffstat (limited to 'core/applets/batteryapplet') (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp8
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp2
-rw-r--r--core/applets/batteryapplet/config.in2
3 files changed, 6 insertions, 6 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index b2cef55..18e368e 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -1,81 +1,84 @@
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 */ 23/* OPIE */
24#include <opie2/otaskbarapplet.h> 24#include <opie2/otaskbarapplet.h>
25
26#include <qpe/qpeapplication.h>
25#include <qpe/applnk.h> 27#include <qpe/applnk.h>
26#include <qpe/config.h> 28#include <qpe/config.h>
27#include <qpe/power.h> 29#include <qpe/power.h>
28 30
29/* QT */ 31/* QT */
30#include <qpainter.h> 32#include <qpainter.h>
31#include <qtimer.h> 33#include <qtimer.h>
32 34
33 35
36using namespace Opie::Ui;
34BatteryMeter::BatteryMeter( QWidget *parent ) 37BatteryMeter::BatteryMeter( QWidget *parent )
35 : QWidget( parent ), charging(false) 38 : QWidget( parent ), charging(false)
36{ 39{
37 ps = new PowerStatus; 40 ps = new PowerStatus;
38 startTimer( 10000 ); 41 startTimer( 10000 );
39 42
40 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 43 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
41 setFixedHeight( AppLnk::smallIconSize() ); 44 setFixedHeight( AppLnk::smallIconSize() );
42 45
43 chargeTimer = new QTimer( this ); 46 chargeTimer = new QTimer( this );
44 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 47 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
45 timerEvent(0); 48 timerEvent(0);
46 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 49 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
47 Config c( "qpe" ); 50 Config c( "qpe" );
48 c.setGroup( "Battery" ); 51 c.setGroup( "Battery" );
49 style = c.readNumEntry( "Style", 0 ); 52 style = c.readNumEntry( "Style", 0 );
50} 53}
51 54
52BatteryMeter::~BatteryMeter() 55BatteryMeter::~BatteryMeter()
53{ 56{
54 delete ps; 57 delete ps;
55} 58}
56 59
57QSize BatteryMeter::sizeHint() const 60QSize BatteryMeter::sizeHint() const
58{ 61{
59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 62 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
60} 63}
61 64
62void BatteryMeter::mousePressEvent( QMouseEvent* e ) 65void BatteryMeter::mousePressEvent( QMouseEvent* e )
63{ 66{
64 if ( e->button() == RightButton ) 67 if ( e->button() == RightButton )
65 { 68 {
66 style = 1-style; 69 style = 1-style;
67 Config c( "qpe" ); 70 Config c( "qpe" );
68 c.setGroup( "Battery" ); 71 c.setGroup( "Battery" );
69 c.writeEntry( "Style", style ); 72 c.writeEntry( "Style", style );
70 repaint( true ); 73 repaint( true );
71 } 74 }
72 QWidget::mousePressEvent( e ); 75 QWidget::mousePressEvent( e );
73} 76}
74 77
75void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) 78void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ )
76{ 79{
77 if ( batteryView && batteryView->isVisible() ) { 80 if ( batteryView && batteryView->isVisible() ) {
78 delete (QWidget *) batteryView; 81 delete (QWidget *) batteryView;
79 } else { 82 } else {
80 if ( !batteryView ) batteryView = new BatteryStatus( ps ); 83 if ( !batteryView ) batteryView = new BatteryStatus( ps );
81 QPEApplication::showWidget( batteryView ); 84 QPEApplication::showWidget( batteryView );
@@ -130,53 +133,50 @@ void BatteryMeter::paintEvent( QPaintEvent* )
130 p.setFont( f ); 133 p.setFont( f );
131 p.drawText( 0, height()/2, QString::number( percent ) ); 134 p.drawText( 0, height()/2, QString::number( percent ) );
132 p.drawText( width()/4, height(), "%" ); 135 p.drawText( width()/4, height(), "%" );
133 return; 136 return;
134 } 137 }
135 138
136 QPainter p(this); 139 QPainter p(this);
137 QColor color; 140 QColor color;
138 QColor g = gray.light( 160 ); 141 QColor g = gray.light( 160 );
139 switch ( ps->acStatus() ) 142 switch ( ps->acStatus() )
140 { 143 {
141 case PowerStatus::Offline: color = blue.light( 150 ); break; 144 case PowerStatus::Offline: color = blue.light( 150 ); break;
142 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break; 145 case PowerStatus::Online: color = green.dark( 130 ).light( 180 ); break;
143 default: color = red.light( 160 ); 146 default: color = red.light( 160 );
144 } 147 }
145 148
146 int w = height() / 2; 149 int w = height() / 2;
147 if ( !(w%2) ) w--; // should have an odd value to get a real middle line 150 if ( !(w%2) ) w--; // should have an odd value to get a real middle line
148 int h = height() - 4; 151 int h = height() - 4;
149 int pix = (percent * h) / 100; 152 int pix = (percent * h) / 100;
150 int y2 = height() -2; 153 int y2 = height() -2;
151 int y = y2 - pix; 154 int y = y2 - pix;
152 int x1 = (width() - w ) / 2; 155 int x1 = (width() - w ) / 2;
153 156
154 p.setPen(QColor(80,80,80)); 157 p.setPen(QColor(80,80,80));
155 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header 158 p.drawLine(x1+w/4,0,x1+w/4+w/2+1,0); // header
156 p.drawRect(x1,1,w,height()-1); // corpus 159 p.drawRect(x1,1,w,height()-1); // corpus
157 p.setBrush(color); 160 p.setBrush(color);
158 161
159 //int extra = ((percent * h) % 100)/(100/4); 162 //int extra = ((percent * h) % 100)/(100/4);
160 163
161 int middle = w/2; 164 int middle = w/2;
162 for ( int i = 0; i < middle; i++ ) 165 for ( int i = 0; i < middle; i++ )
163 { 166 {
164 p.setPen( gray.dark( 100+i*20 ) ); 167 p.setPen( gray.dark( 100+i*20 ) );
165 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 ); 168 p.drawLine( x1+middle-i, 2, x1+middle-i, y-1 );
166 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 ); 169 p.drawLine( x1+middle+i, 2, x1+middle+i, y-1 );
167 p.setPen( color.dark( 100+i*20 ) ); 170 p.setPen( color.dark( 100+i*20 ) );
168 p.drawLine( x1+middle-i, y, x1+middle-i, y2 ); 171 p.drawLine( x1+middle-i, y, x1+middle-i, y2 );
169 p.drawLine( x1+middle+i, y, x1+middle+i, y2 ); 172 p.drawLine( x1+middle+i, y, x1+middle+i, y2 );
170 } 173 }
171} 174}
172 175
173int BatteryMeter::position() 176int BatteryMeter::position()
174{ 177{
175 return 8; 178 return 8;
176} 179}
177 180
178Q_EXPORT_INTERFACE() 181EXPORT_OPIE_APPLET_v1( BatteryMeter )
179{
180 Q_CREATE_INSTANCE( OTaskbarAppletWrapper<BatteryMeter> );
181}
182 182
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index ea11495..bd86f77 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,64 +1,64 @@
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 <qlayout.h> 12#include <qlayout.h>
13#include <qtextstream.h> 13#include <qtextstream.h>
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15 15
16using namespace Opie; 16using namespace Opie::Core;
17 17
18BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent ) 18BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent )
19 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) { 19 : QWidget( parent, 0, WDestructiveClose), ps(p), bat2(false) {
20 setCaption( tr("Battery status") ); 20 setCaption( tr("Battery status") );
21 setMinimumSize( 150, 200 ); 21 setMinimumSize( 150, 200 );
22 22
23 QPushButton *pb = new QPushButton( tr("Close"), this ); 23 QPushButton *pb = new QPushButton( tr("Close"), this );
24 QVBoxLayout *layout = new QVBoxLayout ( this ); 24 QVBoxLayout *layout = new QVBoxLayout ( this );
25 25
26 jackPercent = 0; 26 jackPercent = 0;
27 27
28 pb->setMaximumSize( 120, 40 ); 28 pb->setMaximumSize( 120, 40 );
29 29
30 pb->show(); 30 pb->show();
31 31
32 layout->addStretch(); 32 layout->addStretch();
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++) {
diff --git a/core/applets/batteryapplet/config.in b/core/applets/batteryapplet/config.in
index 3067317..eca07e3 100644
--- a/core/applets/batteryapplet/config.in
+++ b/core/applets/batteryapplet/config.in
@@ -1,4 +1,4 @@
1 config BATTERYAPPLET 1 config BATTERYAPPLET
2 boolean "opie-batteryapplet (Applet to monitor battery status)" 2 boolean "opie-batteryapplet (Applet to monitor battery status)"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIECORE2