summaryrefslogtreecommitdiff
authorbrad <brad>2004-06-24 09:13:31 (UTC)
committer brad <brad>2004-06-24 09:13:31 (UTC)
commitbc5c0b3549d43f7e04a06049578c5413dbf0c00b (patch) (unidiff)
treeddc7318c4c40812ac562e0691dc99253e0fb9669
parent9c471976e750812f0af3b443964954d4b5a5ed20 (diff)
downloadopie-bc5c0b3549d43f7e04a06049578c5413dbf0c00b.zip
opie-bc5c0b3549d43f7e04a06049578c5413dbf0c00b.tar.gz
opie-bc5c0b3549d43f7e04a06049578c5413dbf0c00b.tar.bz2
Battery status panel was only updating once when it was created, after this
it was being hidden and re-shown without updating the data. Now it is updated every time it is shown.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/battery.cpp1
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp17
-rw-r--r--core/applets/batteryapplet/batterystatus.h2
3 files changed, 13 insertions, 7 deletions
diff --git a/core/applets/batteryapplet/battery.cpp b/core/applets/batteryapplet/battery.cpp
index 0d3d190..e85a9da 100644
--- a/core/applets/batteryapplet/battery.cpp
+++ b/core/applets/batteryapplet/battery.cpp
@@ -34,96 +34,97 @@
34 34
35 35
36using namespace Opie::Ui; 36using namespace Opie::Ui;
37BatteryMeter::BatteryMeter( QWidget *parent ) 37BatteryMeter::BatteryMeter( QWidget *parent )
38: QWidget( parent ), charging(false) { 38: QWidget( parent ), charging(false) {
39 ps = new PowerStatus; 39 ps = new PowerStatus;
40 startTimer( 10000 ); 40 startTimer( 10000 );
41 41
42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) ); 42 setFixedWidth( QMAX(AppLnk::smallIconSize()*3/4, 6) );
43 setFixedHeight( AppLnk::smallIconSize() ); 43 setFixedHeight( AppLnk::smallIconSize() );
44 44
45 chargeTimer = new QTimer( this ); 45 chargeTimer = new QTimer( this );
46 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) ); 46 connect( chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimeout()) );
47 timerEvent(0); 47 timerEvent(0);
48 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 48 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
49 Config c( "qpe" ); 49 Config c( "qpe" );
50 c.setGroup( "Battery" ); 50 c.setGroup( "Battery" );
51 style = c.readNumEntry( "Style", 0 ); 51 style = c.readNumEntry( "Style", 0 );
52} 52}
53 53
54BatteryMeter::~BatteryMeter() { 54BatteryMeter::~BatteryMeter() {
55 delete ps; 55 delete ps;
56} 56}
57 57
58QSize BatteryMeter::sizeHint() const { 58QSize BatteryMeter::sizeHint() const {
59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() ); 59 return QSize(QMAX(AppLnk::smallIconSize()*3/4, 6), height() );
60} 60}
61 61
62void BatteryMeter::mousePressEvent( QMouseEvent* e ) { 62void BatteryMeter::mousePressEvent( QMouseEvent* e ) {
63 if ( e->button() == RightButton ) { 63 if ( e->button() == RightButton ) {
64 style = 1-style; 64 style = 1-style;
65 Config c( "qpe" ); 65 Config c( "qpe" );
66 c.setGroup( "Battery" ); 66 c.setGroup( "Battery" );
67 c.writeEntry( "Style", style ); 67 c.writeEntry( "Style", style );
68 repaint( true ); 68 repaint( true );
69 } 69 }
70 QWidget::mousePressEvent( e ); 70 QWidget::mousePressEvent( e );
71} 71}
72 72
73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) { 73void BatteryMeter::mouseReleaseEvent( QMouseEvent* /*e*/ ) {
74 if ( batteryView && batteryView->isVisible() ) { 74 if ( batteryView && batteryView->isVisible() ) {
75 batteryView->hide(); 75 batteryView->hide();
76 } else { 76 } else {
77 if ( !batteryView ) { 77 if ( !batteryView ) {
78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup ); 78 batteryView = new BatteryStatus( ps, 0, WStyle_StaysOnTop | WType_Popup );
79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); 79 batteryView->setFrameStyle( QFrame::PopupPanel | QFrame::Raised );
80 } 80 }
81 81
82 batteryView->UpdateBatteryStatus();
82 QRect r(batteryView->pos(),batteryView->sizeHint()); 83 QRect r(batteryView->pos(),batteryView->sizeHint());
83 QPoint curPos = this->mapToGlobal ( rect().topLeft() ); 84 QPoint curPos = this->mapToGlobal ( rect().topLeft() );
84 85
85 int lp = qApp->desktop()->width() - batteryView->sizeHint().width(); 86 int lp = qApp->desktop()->width() - batteryView->sizeHint().width();
86 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) ); 87 r.moveTopLeft( QPoint(lp, curPos.y()-batteryView->sizeHint().height()-1) );
87 batteryView->setGeometry(r); 88 batteryView->setGeometry(r);
88 89
89 batteryView->raise(); 90 batteryView->raise();
90 batteryView->show(); 91 batteryView->show();
91 } 92 }
92} 93}
93 94
94 95
95void BatteryMeter::timerEvent( QTimerEvent * ) { 96void BatteryMeter::timerEvent( QTimerEvent * ) {
96 PowerStatus prev = *ps; 97 PowerStatus prev = *ps;
97 98
98 *ps = PowerStatusManager::readStatus(); 99 *ps = PowerStatusManager::readStatus();
99 100
100 if ( prev != *ps ) { 101 if ( prev != *ps ) {
101 percent = ps->batteryPercentRemaining(); 102 percent = ps->batteryPercentRemaining();
102 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) { 103 if ( !charging && ps->batteryStatus() == PowerStatus::Charging ) {
103 percent = 0; 104 percent = 0;
104 charging = true; 105 charging = true;
105 chargeTimer->start( 500 ); 106 chargeTimer->start( 500 );
106 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) { 107 } else if ( charging && ps->batteryStatus() != PowerStatus::Charging ) {
107 charging = false; 108 charging = false;
108 chargeTimer->stop(); 109 chargeTimer->stop();
109 if ( batteryView ) 110 if ( batteryView )
110 batteryView->updatePercent( percent ); 111 batteryView->updatePercent( percent );
111 } 112 }
112 repaint( style != 0 ); 113 repaint( style != 0 );
113 if ( batteryView ) 114 if ( batteryView )
114 batteryView->repaint(); 115 batteryView->repaint();
115 } 116 }
116} 117}
117 118
118void BatteryMeter::chargeTimeout() { 119void BatteryMeter::chargeTimeout() {
119 percent += 20; 120 percent += 20;
120 if ( percent > 100 ) 121 if ( percent > 100 )
121 percent = 0; 122 percent = 0;
122 123
123 repaint(FALSE); 124 repaint(FALSE);
124 if ( batteryView ) 125 if ( batteryView )
125 batteryView->updatePercent( percent ); 126 batteryView->updatePercent( percent );
126} 127}
127 128
128void BatteryMeter::paintEvent( QPaintEvent* ) { 129void BatteryMeter::paintEvent( QPaintEvent* ) {
129 130
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index 5a24b94..860db64 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -1,77 +1,82 @@
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 <qtextstream.h> 12#include <qtextstream.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14 14
15using namespace Opie::Core; 15using namespace Opie::Core;
16 16
17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f ) 17BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f )
18: QFrame( parent, 0, f), ps(p), bat2(false) { 18: QFrame( parent, 0, f), ps(p), bat2(false) {
19 19
20 jackPercent = 0; 20 UpdateBatteryStatus();
21
22 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
23 getProcApmStatusIpaq();
24 }
25 percent = ps->batteryPercentRemaining();
26} 21}
27 22
28BatteryStatus::~BatteryStatus() {} 23BatteryStatus::~BatteryStatus() {}
29 24
25void BatteryStatus::UpdateBatteryStatus() {
26
27 jackPercent = 0;
28
29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
30 getProcApmStatusIpaq();
31 }
32 percent = ps->batteryPercentRemaining();
33}
34
30/* 35/*
31 * Make use of the advanced apm interface of the ipaq 36 * Make use of the advanced apm interface of the ipaq
32 */ 37 */
33bool BatteryStatus::getProcApmStatusIpaq() { 38bool BatteryStatus::getProcApmStatusIpaq() {
34 39
35 bat2 = false; 40 bat2 = false;
36 41
37 QFile procApmIpaq("/proc/hal/battery"); 42 QFile procApmIpaq("/proc/hal/battery");
38 43
39 if (procApmIpaq.open(IO_ReadOnly) ) { 44 if (procApmIpaq.open(IO_ReadOnly) ) {
40 QStringList list; 45 QStringList list;
41 // since it is /proc we _must_ use QTextStream 46 // since it is /proc we _must_ use QTextStream
42 QTextStream stream ( &procApmIpaq); 47 QTextStream stream ( &procApmIpaq);
43 QString streamIn; 48 QString streamIn;
44 streamIn = stream.read(); 49 streamIn = stream.read();
45 list = QStringList::split("\n", streamIn); 50 list = QStringList::split("\n", streamIn);
46 51
47 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 52 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
48 // not nice, need a rewrite later 53 // not nice, need a rewrite later
49 if( (*line).startsWith(" Percentage") ) { 54 if( (*line).startsWith(" Percentage") ) {
50 if (bat2 == true) { 55 if (bat2 == true) {
51 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2); 56 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
52 } else { 57 } else {
53 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 58 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
54 } 59 }
55 } else if( (*line).startsWith(" Life") ) { 60 } else if( (*line).startsWith(" Life") ) {
56 if (bat2 == true) { 61 if (bat2 == true) {
57 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 62 sec2 = (*line).mid(((*line).find(':')+2), 5 );
58 } else { 63 } else {
59 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 64 sec1 = (*line).mid(((*line).find(':')+2), 5 );
60 } 65 }
61 } else if( (*line).startsWith("Battery #1") ) { 66 } else if( (*line).startsWith("Battery #1") ) {
62 bat2 = true; 67 bat2 = true;
63 } else if( (*line).startsWith(" Status") ) { 68 } else if( (*line).startsWith(" Status") ) {
64 if (bat2 == true) { 69 if (bat2 == true) {
65 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 70 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
66 } else { 71 } else {
67 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 72 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
68 } 73 }
69 } else if( (*line).startsWith(" Chemistry") ) { 74 } else if( (*line).startsWith(" Chemistry") ) {
70 if (bat2 == true) { 75 if (bat2 == true) {
71 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 76 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
72 } else { 77 } else {
73 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 78 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
74 } 79 }
75 } 80 }
76 } 81 }
77 } else { 82 } else {
diff --git a/core/applets/batteryapplet/batterystatus.h b/core/applets/batteryapplet/batterystatus.h
index bb95ece..4da446d 100644
--- a/core/applets/batteryapplet/batterystatus.h
+++ b/core/applets/batteryapplet/batterystatus.h
@@ -1,64 +1,64 @@
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_STATUS_H 20#ifndef BATTERY_STATUS_H
21#define BATTERY_STATUS_H 21#define BATTERY_STATUS_H
22 22
23#include <qframe.h> 23#include <qframe.h>
24 24
25class PowerStatus; 25class PowerStatus;
26 26
27class BatteryStatus : public QFrame 27class BatteryStatus : public QFrame
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 BatteryStatus( const PowerStatus *s, QWidget *parent=0, WFlags f = 0 ); 31 BatteryStatus( const PowerStatus *s, QWidget *parent=0, WFlags f = 0 );
32 ~BatteryStatus(); 32 ~BatteryStatus();
33 33 void BatteryStatus::UpdateBatteryStatus();
34 void updatePercent( int ); 34 void updatePercent( int );
35 QSize sizeHint() const; 35 QSize sizeHint() const;
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 bool BatteryStatus::getProcApmStatusIpaq(); 39 bool BatteryStatus::getProcApmStatusIpaq();
40 40
41private: 41private:
42 QString statusText() const; 42 QString statusText() const;
43 QString statusTextIpaq() const; 43 QString statusTextIpaq() const;
44 const PowerStatus *ps; 44 const PowerStatus *ps;
45 int percent; 45 int percent;
46 int ipaqPercent; 46 int ipaqPercent;
47 int jackPercent; 47 int jackPercent;
48 int jackMinutes; 48 int jackMinutes;
49 QString perc1; 49 QString perc1;
50 QString sec1; 50 QString sec1;
51 QString perc2; 51 QString perc2;
52 QString sec2; 52 QString sec2;
53 QString ipaqStatus; 53 QString ipaqStatus;
54 QString jackStatus; 54 QString jackStatus;
55 QString ipaqChem; 55 QString ipaqChem;
56 QString jackChem; 56 QString jackChem;
57 bool bat2; 57 bool bat2;
58 bool bat2inserted; 58 bool bat2inserted;
59 int screenWidth; 59 int screenWidth;
60 int screenHeight; 60 int screenHeight;
61}; 61};
62 62
63#endif 63#endif
64 64