author | mickeyl <mickeyl> | 2006-06-01 11:26:26 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2006-06-01 11:26:26 (UTC) |
commit | dd618abb56ba6dec2f4c76548d264d2a68660e0d (patch) (unidiff) | |
tree | 528babbeff43924711d266c5cab078cfc88d3b37 | |
parent | 4ec617a0fa1c44f5527ae7eff176cf8451d9973c (diff) | |
download | opie-dd618abb56ba6dec2f4c76548d264d2a68660e0d.zip opie-dd618abb56ba6dec2f4c76548d264d2a68660e0d.tar.gz opie-dd618abb56ba6dec2f4c76548d264d2a68660e0d.tar.bz2 |
improve support for ipaqs
-rw-r--r-- | core/applets/batteryapplet/batterystatus.cpp | 4 |
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 | |||
@@ -37,101 +37,99 @@ void BatteryStatus::UpdateBatteryStatus() { | |||
37 | * Make use of the advanced apm interface of the ipaq | 37 | * Make use of the advanced apm interface of the ipaq |
38 | */ | 38 | */ |
39 | bool BatteryStatus::getProcApmStatusIpaq() { | 39 | bool 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 | ||
111 | void BatteryStatus::updatePercent( int pc ) { | 109 | void BatteryStatus::updatePercent( int pc ) { |
112 | percent = pc; | 110 | percent = pc; |
113 | repaint(FALSE); | 111 | repaint(FALSE); |
114 | } | 112 | } |
115 | 113 | ||
116 | void BatteryStatus::drawSegment( QPainter *p, const QRect &r, const QColor &topgrad, const QColor &botgrad, const QColor &highlight, int hightlight_height ) { | 114 | void 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 | ||
136 | QString BatteryStatus::statusText() const { | 134 | QString BatteryStatus::statusText() const { |
137 | QString text; | 135 | QString text; |