summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2006-06-01 11:26:26 (UTC)
committer mickeyl <mickeyl>2006-06-01 11:26:26 (UTC)
commitdd618abb56ba6dec2f4c76548d264d2a68660e0d (patch) (unidiff)
tree528babbeff43924711d266c5cab078cfc88d3b37
parent4ec617a0fa1c44f5527ae7eff176cf8451d9973c (diff)
downloadopie-dd618abb56ba6dec2f4c76548d264d2a68660e0d.zip
opie-dd618abb56ba6dec2f4c76548d264d2a68660e0d.tar.gz
opie-dd618abb56ba6dec2f4c76548d264d2a68660e0d.tar.bz2
improve support for ipaqs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/batteryapplet/batterystatus.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/core/applets/batteryapplet/batterystatus.cpp b/core/applets/batteryapplet/batterystatus.cpp
index 08ddc85..9622726 100644
--- a/core/applets/batteryapplet/batterystatus.cpp
+++ b/core/applets/batteryapplet/batterystatus.cpp
@@ -21,133 +21,131 @@ BatteryStatus::BatteryStatus( const PowerStatus *p, QWidget *parent, WFlags f )
21} 21}
22 22
23BatteryStatus::~BatteryStatus() {} 23BatteryStatus::~BatteryStatus() {}
24 24
25void BatteryStatus::UpdateBatteryStatus() { 25void BatteryStatus::UpdateBatteryStatus() {
26 26
27 jackPercent = 0; 27 jackPercent = 0;
28 28
29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) { 29 if ( ODevice::inst ( )-> series ( ) == Model_iPAQ ) {
30 if ( ODevice::inst ( ) -> model() != Model_iPAQ_H191x ) 30 if ( ODevice::inst ( ) -> model() != Model_iPAQ_H191x )
31 getProcApmStatusIpaq(); 31 getProcApmStatusIpaq();
32 } 32 }
33 percent = ps->batteryPercentRemaining(); 33 percent = ps->batteryPercentRemaining();
34} 34}
35 35
36/* 36/*
37 * Make use of the advanced apm interface of the ipaq 37 * Make use of the advanced apm interface of the ipaq
38 */ 38 */
39bool BatteryStatus::getProcApmStatusIpaq() { 39bool BatteryStatus::getProcApmStatusIpaq() {
40 40
41 bat2 = false; 41 bat2 = false;
42 42
43 QFile procApmIpaq("/proc/hal/battery"); 43 QFile procApmIpaq("/proc/hal/battery");
44 44
45 if (procApmIpaq.open(IO_ReadOnly) ) { 45 if (procApmIpaq.open(IO_ReadOnly) ) {
46 QStringList list; 46 QStringList list;
47 // since it is /proc we _must_ use QTextStream 47 // since it is /proc we _must_ use QTextStream
48 QTextStream stream ( &procApmIpaq); 48 QTextStream stream ( &procApmIpaq);
49 QString streamIn; 49 QString streamIn;
50 streamIn = stream.read(); 50 streamIn = stream.read();
51 list = QStringList::split("\n", streamIn); 51 list = QStringList::split("\n", streamIn);
52 52
53 sec2 = sec1 = ""; 53 sec2 = sec1 = "";
54 54
55 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { 55 for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) {
56 // not nice, need a rewrite later 56 // not nice, need a rewrite later
57 if( (*line).startsWith(" Percentage") ) { 57 if( (*line).startsWith(" Percentage") ) {
58 if (bat2 == true) { 58 if (bat2 == true) {
59 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2); 59 perc2 = (*line).mid(((*line).find('(')) +1,(*line).find(')')-(*line).find('(')-2);
60 } else { 60 } else {
61 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2); 61 perc1 = (*line).mid(((*line).find('('))+1,(*line).find(')')-(*line).find('(')-2);
62 } 62 }
63 } else if( (*line).startsWith(" Life") ) { 63 } else if( (*line).startsWith(" Life") ) {
64 if (bat2 == true) { 64 if (bat2 == true) {
65 sec2 = (*line).mid(((*line).find(':')+2), 5 ); 65 sec2 = (*line).mid(((*line).find(':')+2), 5 );
66 } else { 66 } else {
67 sec1 = (*line).mid(((*line).find(':')+2), 5 ); 67 sec1 = (*line).mid(((*line).find(':')+2), 5 );
68 } 68 }
69 } else if( (*line).startsWith("Battery #1") ) { 69 } else if( (*line).startsWith("Battery #1") ) {
70 bat2 = true; 70 bat2 = true;
71 } else if( (*line).startsWith(" Status") ) { 71 } else if( (*line).startsWith(" Status") ) {
72 if (bat2 == true) { 72 if (bat2 == true) {
73 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 73 jackStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
74 } else { 74 } else {
75 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1); 75 ipaqStatus = (*line).mid((*line).find('(')+1, (*line).find(')')-(*line).find('(')-1);
76 } 76 }
77 } else if( (*line).startsWith(" Chemistry") ) { 77 } else if( (*line).startsWith(" Chemistry") ) {
78 if (bat2 == true) { 78 if (bat2 == true) {
79 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 79 jackChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
80 } else { 80 } else {
81 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1); 81 ipaqChem = (*line).mid((*line).find('('), (*line).find(')')-(*line).find('(')+1);
82 } 82 }
83 } 83 }
84 } 84 }
85 } else { 85 procApmIpaq.close();
86 QMessageBox::warning(this, tr("Failure"),tr("could not open file"));
87 } 86 }
88 87
89 procApmIpaq.close();
90 jackPercent = perc2.toInt(); 88 jackPercent = perc2.toInt();
91 ipaqPercent = perc1.toInt(); 89 ipaqPercent = perc1.toInt();
92 90
93 if (perc2.isEmpty() || perc2 == "unknow" ) { 91 if (perc2.isEmpty() || perc2 == "unknow" ) {
94 perc2 = tr("no data"); 92 perc2 = tr("no data");
95 } else { 93 } else {
96 perc2 += " %"; 94 perc2 += " %";
97 } 95 }
98 96
99 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) { 97 if (sec2 == "0" || sec2 == "" || sec2.isEmpty()) {
100 sec2 = tr("no data"); 98 sec2 = tr("no data");
101 } else { 99 } else {
102 sec2 += " min"; 100 sec2 += " min";
103 } 101 }
104 102
105 jackStatus.prepend( " ( " ); 103 jackStatus.prepend( " ( " );
106 jackStatus.append( " )" ); 104 jackStatus.append( " )" );
107 return true; 105 return true;
108} 106}
109 107
110 108
111void BatteryStatus::updatePercent( int pc ) { 109void BatteryStatus::updatePercent( int pc ) {
112 percent = pc; 110 percent = pc;
113 repaint(FALSE); 111 repaint(FALSE);
114} 112}
115 113
116void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { 114void 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; 115 int h1, h2, s1, s2, v1, v2, ng = r.height(), hy = ng*30/100, hh = hightlight_height;
118 topgrad.hsv( &h1, &s1, &v1 ); 116 topgrad.hsv( &h1, &s1, &v1 );
119 botgrad.hsv( &h2, &s2, &v2 ); 117 botgrad.hsv( &h2, &s2, &v2 );
120 for ( int j = 0; j < hy-2; j++ ) { 118 for ( int j = 0; j < hy-2; j++ ) {
121 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1), 119 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
122 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 120 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 ); 121 p->drawLine( r.x(), r.top()+hy-2-j, r.x()+r.width(), r.top()+hy-2-j );
124 } 122 }
125 for ( int j = 0; j < hh; j++ ) { 123 for ( int j = 0; j < hh; j++ ) {
126 p->setPen( highlight ); 124 p->setPen( highlight );
127 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j ); 125 p->drawLine( r.x(), r.top()+hy-2+j, r.x()+r.width(), r.top()+hy-2+j );
128 } 126 }
129 for ( int j = 0; j < ng-hy-hh; j++ ) { 127 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), 128 p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), s1 + ((s2-s1)*j)/(ng-1),
131 v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); 129 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 ); 130 p->drawLine( r.x(), r.top()+hy+hh-2+j, r.x()+r.width(), r.top()+hy+hh-2+j );
133 } 131 }
134} 132}
135 133
136QString BatteryStatus::statusText() const { 134QString BatteryStatus::statusText() const {
137 QString text; 135 QString text;
138 136
139 if ( ps->batteryStatus() == PowerStatus::Charging ) { 137 if ( ps->batteryStatus() == PowerStatus::Charging ) {
140 if (bat2) { 138 if (bat2) {
141 text = tr("Charging both devices"); 139 text = tr("Charging both devices");
142 } else { 140 } else {
143 text = tr("Charging"); 141 text = tr("Charging");
144 } 142 }
145 } else if ( ps->batteryPercentAccurate() ) { 143 } else if ( ps->batteryPercentAccurate() ) {
146 text = tr( "Remaining Power: %1%" ).arg( percent ); 144 text = tr( "Remaining Power: %1%" ).arg( percent );
147 //text.sprintf( tr("Remaining Power") + ": %i%%", percent ); 145 //text.sprintf( tr("Remaining Power") + ": %i%%", percent );
148 } else { 146 } else {
149 text = tr( "Battery status: " ); 147 text = tr( "Battery status: " );
150 switch ( ps->batteryStatus() ) { 148 switch ( ps->batteryStatus() ) {
151 case PowerStatus::High: 149 case PowerStatus::High:
152 text.append( tr( "Good" ) ); 150 text.append( tr( "Good" ) );
153 break; 151 break;