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
@@ -58,48 +58,49 @@ BatteryMeter::~BatteryMeter() {
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 );
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,53 +1,58 @@
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);
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
@@ -9,49 +9,49 @@
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;