-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/graph.cpp | 183 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/graph.h | 89 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/load.cpp | 212 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/load.h | 60 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/memory.cpp | 165 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/memory.h | 63 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/memoryapplet.pro | 14 | ||||
-rw-r--r-- | noncore/applets/memoryapplet/swapfile.cpp | 15 |
9 files changed, 794 insertions, 8 deletions
@@ -3,16 +3,17 @@ | |||
3 | New Features | 3 | New Features |
4 | ------------ | 4 | ------------ |
5 | * Number of icon columns in Launcher is customizable through Launcher.conf (hrw,zecke,mickeyl) | 5 | * Number of icon columns in Launcher is customizable through Launcher.conf (hrw,zecke,mickeyl) |
6 | * Number of icon columns in Launcher is customizable through LauncherSettings (mickeyl) | 6 | * Number of icon columns in Launcher is customizable through LauncherSettings (mickeyl) |
7 | 7 | ||
8 | Fixed Bugs | 8 | Fixed Bugs |
9 | ---------- | 9 | ---------- |
10 | * #1501 - Fixed bug in todo sql backend (eilers) | 10 | * #1501 - Fixed bug in todo sql backend (eilers) |
11 | * #1505 - Added more Swap sizes in memoryapplet (mickeyl) | ||
11 | * #1525 - Hopefully fixed double alarms and not removing alarms set with the Clock application (zecke) | 12 | * #1525 - Hopefully fixed double alarms and not removing alarms set with the Clock application (zecke) |
12 | * #1533 - Security Owner Dialog (shown in case of unsuccessfull authentiacation) wasn't able to display information in non latin1 encoding (zecke) | 13 | * #1533 - Security Owner Dialog (shown in case of unsuccessfull authentiacation) wasn't able to display information in non latin1 encoding (zecke) |
13 | * n.a. - Removed hard coded font sizes in a couple of inputmethods (mickeyl) | 14 | * n.a. - Removed hard coded font sizes in a couple of inputmethods (mickeyl) |
14 | * n.a. - Removed MediumDlg appearing prior to FirstUsage wizard (i.e. calibration) (mickeyl) | 15 | * n.a. - Removed MediumDlg appearing prior to FirstUsage wizard (i.e. calibration) (mickeyl) |
15 | 16 | ||
16 | Internal | 17 | Internal |
17 | -------- | 18 | -------- |
18 | * Added the Qtopia 1.7 SDK macros for quick-apps to easa compilation of 3rd party apps against our headers (mickeyl) | 19 | * Added the Qtopia 1.7 SDK macros for quick-apps to easa compilation of 3rd party apps against our headers (mickeyl) |
diff --git a/noncore/applets/memoryapplet/graph.cpp b/noncore/applets/memoryapplet/graph.cpp new file mode 100644 index 0000000..0b02bf7 --- a/dev/null +++ b/noncore/applets/memoryapplet/graph.cpp | |||
@@ -0,0 +1,183 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qpainter.h> | ||
22 | #include <qpixmap.h> | ||
23 | #include "graph.h" | ||
24 | |||
25 | void GraphData::clear() | ||
26 | { | ||
27 | names.clear(); | ||
28 | values.resize(0); | ||
29 | } | ||
30 | |||
31 | void GraphData::addItem( const QString &name, int value ) | ||
32 | { | ||
33 | names.append( name ); | ||
34 | values.resize( values.size() + 1 ); | ||
35 | values[values.size()-1] = value; | ||
36 | } | ||
37 | |||
38 | Graph::Graph(QWidget *parent, const char *name, WFlags f ) | ||
39 | : QFrame( parent, name, f ) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | PieGraph::PieGraph(QWidget *parent, const char *name, WFlags f ) | ||
44 | : Graph( parent, name, f ) | ||
45 | { | ||
46 | } | ||
47 | |||
48 | void PieGraph::drawContents( QPainter *p ) | ||
49 | { | ||
50 | int size = QMIN( contentsRect().width(), contentsRect().height() ) - 1; | ||
51 | |||
52 | int total = 0; | ||
53 | for ( unsigned i = 0; i < data->count(); i++ ) | ||
54 | total += data->value(i); | ||
55 | |||
56 | int angle = 0; | ||
57 | for ( unsigned i = 0; i < data->count(); i++ ) { | ||
58 | int len; | ||
59 | if ( i == data->count() - 1 || !total ) | ||
60 | len = 5760 - angle; | ||
61 | else | ||
62 | len = data->value(i) * 5760 / total; | ||
63 | QColor col; | ||
64 | col.setHsv( i * 360 / data->count(), 255, 255 ); | ||
65 | p->setBrush( col ); | ||
66 | p->drawPie ( contentsRect().x(), contentsRect().y(), | ||
67 | size, size, angle, len+32 ); | ||
68 | angle += len; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | BarGraph::BarGraph(QWidget *parent, const char *name, WFlags f ) | ||
73 | : Graph( parent, name, f ) | ||
74 | { | ||
75 | setMinimumHeight( 10 ); | ||
76 | setMaximumHeight( 45 ); | ||
77 | } | ||
78 | |||
79 | void BarGraph::drawContents( QPainter *p ) | ||
80 | { | ||
81 | int h = contentsRect().height(); | ||
82 | int y = contentsRect().top(); | ||
83 | |||
84 | int total = 0; | ||
85 | for ( unsigned i = 0; i < data->count(); i++ ) | ||
86 | total += data->value(i); | ||
87 | |||
88 | int pos = 0; | ||
89 | for ( unsigned i = 0; i < data->count(); i++ ) { | ||
90 | int len; | ||
91 | if ( i == data->count() - 1 || !total ) | ||
92 | len = contentsRect().width() - pos; | ||
93 | else | ||
94 | len = data->value(i) * contentsRect().width() / total; | ||
95 | QColor col; | ||
96 | col.setHsv( i * 360 / data->count(), 255, 255 ); | ||
97 | drawSegment( p, QRect(contentsRect().x() + pos, y, len, h), col ); | ||
98 | pos += len; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | void BarGraph::drawSegment( QPainter *p, const QRect &r, const QColor &c ) | ||
103 | { | ||
104 | if ( QPixmap::defaultDepth() > 8 ) { | ||
105 | QColor topgrad = c.light(170); | ||
106 | QColor botgrad = c.dark(); | ||
107 | |||
108 | int h1, h2, s1, s2, v1, v2; | ||
109 | topgrad.hsv( &h1, &s1, &v1 ); | ||
110 | botgrad.hsv( &h2, &s2, &v2 ); | ||
111 | int ng = r.height(); | ||
112 | for ( int j =0; j < ng; j++ ) { | ||
113 | p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), | ||
114 | s1 + ((s2-s1)*j)/(ng-1), | ||
115 | v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); | ||
116 | p->drawLine( r.x(), r.top()+j, r.x()+r.width(), r.top()+j ); | ||
117 | } | ||
118 | } else { | ||
119 | p->fillRect( r.x(), r.top(), r.width(), r.height(), c ); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | |||
124 | GraphLegend::GraphLegend( QWidget *parent, const char *name, WFlags f ) | ||
125 | : QFrame( parent, name, f ) | ||
126 | { | ||
127 | horz = FALSE; | ||
128 | } | ||
129 | |||
130 | void GraphLegend::setOrientation(Orientation o) | ||
131 | { | ||
132 | horz = o == Horizontal; | ||
133 | } | ||
134 | |||
135 | void GraphLegend::drawContents( QPainter *p ) | ||
136 | { | ||
137 | int total = 0; | ||
138 | for ( unsigned i = 0; i < data->count(); i++ ) | ||
139 | total += data->value(i); | ||
140 | |||
141 | int tw = width()/data->count()-1; | ||
142 | int th = height()/(horz ? 1 : data->count()); | ||
143 | if ( th > p->fontMetrics().height() ) | ||
144 | th = p->fontMetrics().height(); | ||
145 | int x = 0; | ||
146 | int y = 0; | ||
147 | for ( unsigned i = 0; i < data->count(); i++ ) { | ||
148 | QColor col; | ||
149 | col.setHsv( i * 360 / data->count(), 255, 255 ); | ||
150 | p->setBrush( col ); | ||
151 | p->drawRect( x+1, y+1, th - 2, th - 2 ); | ||
152 | p->drawText( x+th + 1, y + p->fontMetrics().ascent()+1, data->name(i) ); | ||
153 | if ( horz ) { | ||
154 | x += tw; | ||
155 | } else { | ||
156 | y += th; | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | |||
161 | QSize GraphLegend::sizeHint() const | ||
162 | { | ||
163 | int th = fontMetrics().height() + 2; | ||
164 | int maxw = 0; | ||
165 | for ( unsigned i = 0; i < data->count(); i++ ) { | ||
166 | int w = fontMetrics().width( data->name(i) ); | ||
167 | if ( w > maxw ) | ||
168 | maxw = w; | ||
169 | } | ||
170 | if ( 0 && horz ) { | ||
171 | return QSize( maxw * data->count(), th ); | ||
172 | } else { | ||
173 | return QSize( maxw, th * data->count() ); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | void GraphLegend::setData( const GraphData *p ) | ||
178 | { | ||
179 | data = p; | ||
180 | int th = fontMetrics().height(); | ||
181 | setMinimumHeight( th * ( horz ? 1 : data->count() ) ); | ||
182 | updateGeometry(); | ||
183 | } | ||
diff --git a/noncore/applets/memoryapplet/graph.h b/noncore/applets/memoryapplet/graph.h new file mode 100644 index 0000000..5a65e79 --- a/dev/null +++ b/noncore/applets/memoryapplet/graph.h | |||
@@ -0,0 +1,89 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qframe.h> | ||
22 | #include <qarray.h> | ||
23 | #include <qstringlist.h> | ||
24 | |||
25 | class GraphData | ||
26 | { | ||
27 | public: | ||
28 | void clear(); | ||
29 | void addItem( const QString &name, int value ); | ||
30 | |||
31 | const QString &name( int i ) const { return names[i]; } | ||
32 | int value( int i ) const { return values[i]; } | ||
33 | unsigned count() const { return values.size(); } | ||
34 | |||
35 | private: | ||
36 | QStringList names; | ||
37 | QArray<int> values; | ||
38 | }; | ||
39 | |||
40 | class Graph : public QFrame | ||
41 | { | ||
42 | Q_OBJECT | ||
43 | public: | ||
44 | Graph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
45 | |||
46 | void setData( const GraphData *p ) { data = p; } | ||
47 | |||
48 | protected: | ||
49 | const GraphData *data; | ||
50 | }; | ||
51 | |||
52 | class PieGraph : public Graph | ||
53 | { | ||
54 | Q_OBJECT | ||
55 | public: | ||
56 | PieGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
57 | |||
58 | protected: | ||
59 | virtual void drawContents( QPainter *p ); | ||
60 | }; | ||
61 | |||
62 | class BarGraph : public Graph | ||
63 | { | ||
64 | Q_OBJECT | ||
65 | public: | ||
66 | BarGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
67 | |||
68 | protected: | ||
69 | virtual void drawContents( QPainter *p ); | ||
70 | void drawSegment( QPainter *p, const QRect &r, const QColor &c ); | ||
71 | }; | ||
72 | |||
73 | class GraphLegend : public QFrame | ||
74 | { | ||
75 | Q_OBJECT | ||
76 | public: | ||
77 | GraphLegend( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
78 | |||
79 | void setData( const GraphData *p ); | ||
80 | virtual QSize sizeHint() const; | ||
81 | void setOrientation(Orientation o); | ||
82 | |||
83 | protected: | ||
84 | virtual void drawContents( QPainter *p ); | ||
85 | |||
86 | private: | ||
87 | const GraphData *data; | ||
88 | bool horz; | ||
89 | }; | ||
diff --git a/noncore/applets/memoryapplet/load.cpp b/noncore/applets/memoryapplet/load.cpp new file mode 100644 index 0000000..d9d7a66 --- a/dev/null +++ b/noncore/applets/memoryapplet/load.cpp | |||
@@ -0,0 +1,212 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <stdio.h> | ||
22 | |||
23 | #include <qfile.h> | ||
24 | #include <qlayout.h> | ||
25 | #include <qlabel.h> | ||
26 | #include <qpainter.h> | ||
27 | #include <qpixmap.h> | ||
28 | #include <qtextstream.h> | ||
29 | #include <qtimer.h> | ||
30 | #include <qwhatsthis.h> | ||
31 | |||
32 | #include "load.h" | ||
33 | |||
34 | LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f ) | ||
35 | : QWidget( parent, name, f ) | ||
36 | { | ||
37 | QVBoxLayout *vb = new QVBoxLayout( this, 6 ); | ||
38 | |||
39 | QString cpuInfo = getCpuInfo(); | ||
40 | if ( !cpuInfo.isNull() ) | ||
41 | vb->addWidget( new QLabel( cpuInfo, this ) ); | ||
42 | vb->addWidget( new Load( this ), 100 ); | ||
43 | QLabel *l = new QLabel( this ); | ||
44 | l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) ); | ||
45 | vb->addWidget( l, 1 ); | ||
46 | l = new QLabel( this ); | ||
47 | l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) ); | ||
48 | vb->addWidget( l, 1 ); | ||
49 | vb->addStretch(50); | ||
50 | |||
51 | QWhatsThis::add( this, tr( "This page shows how much this device's processor is being used." ) ); | ||
52 | } | ||
53 | |||
54 | QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text ) | ||
55 | { | ||
56 | int h = fontMetrics().height(); | ||
57 | QPixmap pm( 20 + fontMetrics().width( text ), h ); | ||
58 | QPainter p( &pm ); | ||
59 | p.fillRect( pm.rect(), colorGroup().background() ); | ||
60 | p.fillRect( 0, h/2-4, 18, h/2+3, black ); | ||
61 | p.setPen( col ); | ||
62 | p.drawLine( 2, h/2, 15, h/2 ); | ||
63 | p.setPen( colorGroup().text() ); | ||
64 | p.drawText( 20, fontMetrics().ascent(), text ); | ||
65 | |||
66 | return pm; | ||
67 | } | ||
68 | |||
69 | QString LoadInfo::getCpuInfo() | ||
70 | { | ||
71 | bool haveInfo = FALSE; | ||
72 | QString info = tr("Type: "); | ||
73 | QFile f( "/proc/cpuinfo" ); | ||
74 | if ( f.open( IO_ReadOnly ) ) { | ||
75 | QTextStream ts( &f ); | ||
76 | |||
77 | while ( !ts.atEnd() ) { | ||
78 | QString s = ts.readLine(); | ||
79 | if ( s.find( "model name" ) == 0 ) { | ||
80 | info += s.mid( s.find( ':' ) + 2 ); | ||
81 | haveInfo = TRUE; | ||
82 | } else if ( s.find( "cpu MHz" ) == 0 ) { | ||
83 | double mhz = s.mid( s.find( ':' ) + 2 ).toDouble(); | ||
84 | info += " " + QString::number( mhz, 'f', 0 ); | ||
85 | info += "MHz"; | ||
86 | break; | ||
87 | } else if ( s.find( "Processor" ) == 0 ) { | ||
88 | info += s.mid( s.find( ':' ) + 2 ); | ||
89 | haveInfo = TRUE; | ||
90 | break; | ||
91 | #ifdef __MIPSEL__ | ||
92 | } else if ( s.find( "cpu model" ) == 0 ) { | ||
93 | info += " " + s.mid( s.find( ':' ) + 2 ); | ||
94 | break; | ||
95 | } else if ( s.find( "cpu" ) == 0 ) { | ||
96 | info += s.mid( s.find( ':' ) + 2 ); | ||
97 | haveInfo = TRUE; | ||
98 | #endif | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if ( !haveInfo ) | ||
104 | info = QString(); | ||
105 | |||
106 | return info; | ||
107 | } | ||
108 | |||
109 | Load::Load( QWidget *parent, const char *name, WFlags f ) | ||
110 | : QWidget( parent, name, f ) | ||
111 | { | ||
112 | setMinimumHeight( 30 ); | ||
113 | setBackgroundColor( black ); | ||
114 | points = 100; | ||
115 | setMinimumWidth( points ); | ||
116 | userLoad = new double [points]; | ||
117 | systemLoad = new double [points]; | ||
118 | for ( int i = 0; i < points; i++ ) { | ||
119 | userLoad[i] = 0.0; | ||
120 | systemLoad[i] = 0.0; | ||
121 | } | ||
122 | maxLoad = 1.3; | ||
123 | QTimer *timer = new QTimer( this ); | ||
124 | connect( timer, SIGNAL(timeout()), SLOT(timeout()) ); | ||
125 | timer->start( 2000 ); | ||
126 | gettimeofday( &last, 0 ); | ||
127 | first = TRUE; | ||
128 | timeout(); | ||
129 | } | ||
130 | |||
131 | void Load::paintEvent( QPaintEvent * ) | ||
132 | { | ||
133 | QPainter p( this ); | ||
134 | |||
135 | int h = height() - 5; | ||
136 | |||
137 | int mult = (int)(h / maxLoad); | ||
138 | |||
139 | p.setPen( gray ); | ||
140 | p.drawLine( 0, h - mult, width(), h - mult ); | ||
141 | p.drawText( 0, h - mult, "100" ); | ||
142 | p.drawText( 0, h, "0" ); | ||
143 | |||
144 | p.setPen( green ); | ||
145 | for ( int i = 1; i < points; i++ ) { | ||
146 | int x1 = (i - 1) * width() / points; | ||
147 | int x2 = i * width() / points; | ||
148 | p.drawLine( x1, h - systemLoad[i-1] * mult, | ||
149 | x2, h - systemLoad[i] * mult ); | ||
150 | } | ||
151 | |||
152 | p.setPen( red ); | ||
153 | for ( int i = 1; i < points; i++ ) { | ||
154 | int x1 = (i - 1) * width() / points; | ||
155 | int x2 = i * width() / points; | ||
156 | p.drawLine( x1, h - userLoad[i-1] * mult, | ||
157 | x2, h - userLoad[i] * mult ); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | void Load::timeout() | ||
162 | { | ||
163 | int user; | ||
164 | int usernice; | ||
165 | int sys; | ||
166 | int idle; | ||
167 | FILE *fp; | ||
168 | fp = fopen( "/proc/stat", "r" ); | ||
169 | fscanf( fp, "cpu %d %d %d %d", &user, &usernice, &sys, &idle ); | ||
170 | fclose( fp ); | ||
171 | struct timeval now; | ||
172 | gettimeofday( &now, 0 ); | ||
173 | int tdiff = now.tv_usec - last.tv_usec; | ||
174 | tdiff += (now.tv_sec - last.tv_sec) * 1000000; | ||
175 | tdiff /= 10000; | ||
176 | |||
177 | int udiff = user - lastUser; | ||
178 | int sdiff = sys - lastSys; | ||
179 | if ( tdiff > 0 ) { | ||
180 | double uload = (double)udiff / (double)tdiff; | ||
181 | double sload = (double)sdiff / (double)tdiff; | ||
182 | if ( !first ) { | ||
183 | for ( int i = 1; i < points; i++ ) { | ||
184 | userLoad[i-1] = userLoad[i]; | ||
185 | systemLoad[i-1] = systemLoad[i]; | ||
186 | } | ||
187 | userLoad[points-1] = uload; | ||
188 | systemLoad[points-1] = sload; | ||
189 | // scroll( -width()/points, 0, QRect( 0, 0, width() - width()/points + 1, height() ) ); | ||
190 | repaint( TRUE ); | ||
191 | double ml = 1.3; | ||
192 | /* | ||
193 | for ( int i = 0; i < points; i++ ) { | ||
194 | if ( userLoad[i] > ml ) | ||
195 | ml = userLoad[i]; | ||
196 | } | ||
197 | */ | ||
198 | if ( maxLoad != ml ) { | ||
199 | maxLoad = ml; | ||
200 | update(); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | last = now; | ||
205 | lastUser = user; | ||
206 | lastSys = sys; | ||
207 | first = FALSE; | ||
208 | } else if ( tdiff < 0 ) { | ||
209 | last = now; | ||
210 | } | ||
211 | } | ||
212 | |||
diff --git a/noncore/applets/memoryapplet/load.h b/noncore/applets/memoryapplet/load.h new file mode 100644 index 0000000..e7f5388 --- a/dev/null +++ b/noncore/applets/memoryapplet/load.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <sys/time.h> | ||
22 | #include <qwidget.h> | ||
23 | |||
24 | /* | ||
25 | Little load meter | ||
26 | */ | ||
27 | class Load : public QWidget { | ||
28 | Q_OBJECT | ||
29 | public: | ||
30 | Load( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
31 | |||
32 | protected: | ||
33 | void paintEvent( QPaintEvent *ev ); | ||
34 | |||
35 | private slots: | ||
36 | void timeout(); | ||
37 | |||
38 | private: | ||
39 | int points; | ||
40 | double *userLoad; | ||
41 | double *systemLoad; | ||
42 | double maxLoad; | ||
43 | struct timeval last; | ||
44 | int lastUser; | ||
45 | int lastUsernice; | ||
46 | int lastSys; | ||
47 | int lastIdle; | ||
48 | bool first; | ||
49 | }; | ||
50 | |||
51 | class LoadInfo : public QWidget | ||
52 | { | ||
53 | Q_OBJECT | ||
54 | public: | ||
55 | LoadInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
56 | |||
57 | private: | ||
58 | QPixmap makeLabel( const QColor &col, const QString &text ); | ||
59 | QString getCpuInfo(); | ||
60 | }; | ||
diff --git a/noncore/applets/memoryapplet/memory.cpp b/noncore/applets/memoryapplet/memory.cpp new file mode 100644 index 0000000..05349e4 --- a/dev/null +++ b/noncore/applets/memoryapplet/memory.cpp | |||
@@ -0,0 +1,165 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qlabel.h> | ||
22 | #include <qtimer.h> | ||
23 | #include <qfile.h> | ||
24 | #include <qtextstream.h> | ||
25 | #include <qlayout.h> | ||
26 | #include <qwhatsthis.h> | ||
27 | #include "graph.h" | ||
28 | #include "memory.h" | ||
29 | |||
30 | MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f ) | ||
31 | : QWidget( parent, name, f ) | ||
32 | { | ||
33 | QVBoxLayout *vb = new QVBoxLayout( this, 5 ); | ||
34 | |||
35 | totalMem = new QLabel( this ); | ||
36 | vb->addWidget( totalMem ); | ||
37 | |||
38 | data = new GraphData(); | ||
39 | graph = new BarGraph( this ); | ||
40 | graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
41 | vb->addWidget( graph, 1 ); | ||
42 | graph->setData( data ); | ||
43 | |||
44 | legend = new GraphLegend( this ); | ||
45 | vb->addWidget( legend ); | ||
46 | legend->setData( data ); | ||
47 | |||
48 | swapMem = new QLabel( this ); | ||
49 | vb->addWidget( swapMem ); | ||
50 | |||
51 | swapdata = new GraphData(); | ||
52 | swapgraph = new BarGraph( this ); | ||
53 | swapgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | ||
54 | vb->addWidget( swapgraph, 1 ); | ||
55 | swapgraph->setData( swapdata ); | ||
56 | |||
57 | swaplegend = new GraphLegend( this ); | ||
58 | vb->addWidget( swaplegend ); | ||
59 | swaplegend->setData( swapdata ); | ||
60 | |||
61 | vb->addStretch( 1 ); | ||
62 | updateData(); | ||
63 | |||
64 | QTimer *t = new QTimer( this ); | ||
65 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | ||
66 | t->start( 5000 ); | ||
67 | |||
68 | QWhatsThis::add( this, tr( "This page shows how memory (i.e. RAM) is being allocated on your device.\nMemory is categorized as follows:\n\n1. Used - memory used to by Opie and any running applications.\n2. Buffers - temporary storage used to improve performance\n3. Cached - information that has recently been used, but has not been freed yet.\n4. Free - memory not currently used by Opie or any running applications." ) ); | ||
69 | |||
70 | } | ||
71 | |||
72 | MemoryInfo::~MemoryInfo() | ||
73 | { | ||
74 | delete data; | ||
75 | } | ||
76 | |||
77 | void MemoryInfo::updateData() | ||
78 | { | ||
79 | QFile file( "/proc/meminfo" ); | ||
80 | |||
81 | if ( file.open( IO_ReadOnly ) ) | ||
82 | { | ||
83 | // local variables | ||
84 | QString line; | ||
85 | QString identifier; | ||
86 | QString value; | ||
87 | int position; | ||
88 | QTextStream t( &file ); | ||
89 | |||
90 | while ( !t.atEnd() ) | ||
91 | { | ||
92 | // read a line | ||
93 | line = t.readLine(); | ||
94 | |||
95 | // extract identifier and value from line | ||
96 | position = line.find( ":" ); | ||
97 | identifier = line.left( position ); | ||
98 | value = line.mid( position + 1, line.length() - position - 3 ); | ||
99 | value = value.stripWhiteSpace(); | ||
100 | |||
101 | // copy values in variables | ||
102 | if ( identifier == "MemTotal" ) | ||
103 | { | ||
104 | total = value.toULong(); | ||
105 | } else if ( identifier == "MemFree" ) | ||
106 | { | ||
107 | memfree = value.toULong(); | ||
108 | } else if ( identifier == "Buffers" ) | ||
109 | { | ||
110 | buffers = value.toULong(); | ||
111 | } else if ( identifier == "Cached" ) | ||
112 | { | ||
113 | cached = value.toULong(); | ||
114 | } else if ( identifier == "SwapCached" ) | ||
115 | { | ||
116 | } else if ( identifier == "SwapTotal" ) | ||
117 | { | ||
118 | swaptotal = value.toULong(); | ||
119 | } else if ( identifier == "SwapFree" ) | ||
120 | { | ||
121 | swapfree = value.toULong(); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | file.close(); | ||
126 | |||
127 | // calculate values | ||
128 | used = total - memfree; | ||
129 | swapused = swaptotal - swapfree; | ||
130 | realUsed = total - ( buffers + cached + memfree ); | ||
131 | |||
132 | // visualize values | ||
133 | totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) ); | ||
134 | data->clear(); | ||
135 | data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed ); | ||
136 | data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers ); | ||
137 | data->addItem( tr("Cached (%1 kB)").arg(cached), cached ); | ||
138 | data->addItem( tr("Free (%1 kB)").arg(memfree), memfree ); | ||
139 | |||
140 | graph->hide(); | ||
141 | graph->show(); | ||
142 | legend->update(); | ||
143 | |||
144 | if (swaptotal > 0) | ||
145 | { | ||
146 | swapMem->setText( tr( "Total Swap: %1 kB" ).arg( swaptotal ) ); | ||
147 | swapdata->clear(); | ||
148 | swapdata->addItem( tr("Used (%1 kB)").arg(swapused), swapused ); | ||
149 | swapdata->addItem( tr("Free (%1 kB)").arg(swapfree), swapfree ); | ||
150 | |||
151 | swapMem->show(); | ||
152 | swapgraph->show(); | ||
153 | swaplegend->show(); | ||
154 | |||
155 | swapgraph->repaint( FALSE ); | ||
156 | swaplegend->update(); | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | swapMem->hide(); | ||
161 | swapgraph->hide(); | ||
162 | swaplegend->hide(); | ||
163 | } | ||
164 | } | ||
165 | } | ||
diff --git a/noncore/applets/memoryapplet/memory.h b/noncore/applets/memoryapplet/memory.h new file mode 100644 index 0000000..f655604 --- a/dev/null +++ b/noncore/applets/memoryapplet/memory.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #ifndef MEMORY_H | ||
22 | #define MEMORY_H | ||
23 | |||
24 | #include <qwidget.h> | ||
25 | |||
26 | class GraphData; | ||
27 | class Graph; | ||
28 | class GraphLegend; | ||
29 | class QLabel; | ||
30 | |||
31 | class MemoryInfo : public QWidget | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | public: | ||
35 | MemoryInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | ||
36 | ~MemoryInfo(); | ||
37 | |||
38 | unsigned long total; | ||
39 | unsigned long used; | ||
40 | unsigned long memfree; | ||
41 | unsigned long buffers; | ||
42 | unsigned long cached; | ||
43 | unsigned long realUsed; | ||
44 | unsigned long swaptotal; | ||
45 | unsigned long swapused; | ||
46 | unsigned long swapfree; | ||
47 | |||
48 | private slots: | ||
49 | void updateData(); | ||
50 | |||
51 | private: | ||
52 | QLabel *totalMem; | ||
53 | GraphData *data; | ||
54 | Graph *graph; | ||
55 | GraphLegend *legend; | ||
56 | |||
57 | QLabel* swapMem; | ||
58 | GraphData *swapdata; | ||
59 | Graph *swapgraph; | ||
60 | GraphLegend *swaplegend; | ||
61 | }; | ||
62 | |||
63 | #endif | ||
diff --git a/noncore/applets/memoryapplet/memoryapplet.pro b/noncore/applets/memoryapplet/memoryapplet.pro index 57bb1c9..1dfc02f 100644 --- a/noncore/applets/memoryapplet/memoryapplet.pro +++ b/noncore/applets/memoryapplet/memoryapplet.pro | |||
@@ -1,22 +1,22 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on | 2 | CONFIG += qt plugin warn_on |
3 | HEADERS = ../../settings/sysinfo/graph.h \ | 3 | HEADERS = graph.h \ |
4 | ../../settings/sysinfo/load.h \ | 4 | load.h \ |
5 | ../../settings/sysinfo/memory.h \ | 5 | memory.h \ |
6 | memorymeter.h \ | 6 | memorymeter.h \ |
7 | memorystatus.h \ | 7 | memorystatus.h \ |
8 | swapfile.h | 8 | swapfile.h |
9 | SOURCES = ../../settings/sysinfo/graph.cpp \ | 9 | SOURCES = graph.cpp \ |
10 | ../../settings/sysinfo/load.cpp \ | 10 | load.cpp \ |
11 | ../../settings/sysinfo/memory.cpp \ | 11 | memory.cpp \ |
12 | memorymeter.cpp \ | 12 | memorymeter.cpp \ |
13 | memorystatus.cpp \ | 13 | memorystatus.cpp \ |
14 | swapfile.cpp | 14 | swapfile.cpp |
15 | TARGET = memoryapplet | 15 | TARGET = memoryapplet |
16 | DESTDIR = $(OPIEDIR)/plugins/applets | 16 | DESTDIR = $(OPIEDIR)/plugins/applets |
17 | INCLUDEPATH += $(OPIEDIR)/include | 17 | INCLUDEPATH += $(OPIEDIR)/include |
18 | DEPENDPATH += | 18 | DEPENDPATH += |
19 | VERSION = 1.0.0 | 19 | VERSION = 1.0.1 |
20 | LIBS += -lqpe -lopiecore2 -lopieui2 | 20 | LIBS += -lqpe -lopiecore2 -lopieui2 |
21 | 21 | ||
22 | include( $(OPIEDIR)/include.pro ) | 22 | include( $(OPIEDIR)/include.pro ) |
diff --git a/noncore/applets/memoryapplet/swapfile.cpp b/noncore/applets/memoryapplet/swapfile.cpp index 96010c8..4609c13 100644 --- a/noncore/applets/memoryapplet/swapfile.cpp +++ b/noncore/applets/memoryapplet/swapfile.cpp | |||
@@ -85,17 +85,17 @@ Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) | |||
85 | QHBox *hb2 = new QHBox(box1); | 85 | QHBox *hb2 = new QHBox(box1); |
86 | hb2->setSpacing(5); | 86 | hb2->setSpacing(5); |
87 | QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); | 87 | QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); |
88 | QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); | 88 | QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); |
89 | 89 | ||
90 | QHBox *hb3 = new QHBox(box1); | 90 | QHBox *hb3 = new QHBox(box1); |
91 | hb3->setSpacing(5); | 91 | hb3->setSpacing(5); |
92 | swapSize = new QComboBox(hb3); | 92 | swapSize = new QComboBox(hb3); |
93 | swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb"))); | 93 | swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb,16 Mb,32 Mb,64 Mb"))); |
94 | 94 | ||
95 | mkswapProgress = new QProgressBar(3, hb3); | 95 | mkswapProgress = new QProgressBar(3, hb3); |
96 | mkswapProgress->setCenterIndicator(true); | 96 | mkswapProgress->setCenterIndicator(true); |
97 | 97 | ||
98 | QHBox *hb4 = new QHBox(this); | 98 | QHBox *hb4 = new QHBox(this); |
99 | hb4->setSpacing(5); | 99 | hb4->setSpacing(5); |
100 | 100 | ||
101 | swapStatusIcon = new QLabel(hb4); | 101 | swapStatusIcon = new QLabel(hb4); |
@@ -338,16 +338,23 @@ void Swapfile::makeswapfile() | |||
338 | case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text())); | 338 | case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text())); |
339 | break; | 339 | break; |
340 | case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text())); | 340 | case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text())); |
341 | break; | 341 | break; |
342 | case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text())); | 342 | case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text())); |
343 | break; | 343 | break; |
344 | case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text())); | 344 | case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text())); |
345 | break; | 345 | break; |
346 | case 4: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=16384").arg(swapPath1->text())); | ||
347 | break; | ||
348 | case 5: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=32768").arg(swapPath1->text())); | ||
349 | break; | ||
350 | case 6: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=65536").arg(swapPath1->text())); | ||
351 | break; | ||
352 | |||
346 | } | 353 | } |
347 | if (rc != 0) { | 354 | if (rc != 0) { |
348 | setStatusMessage(tr("Failed to create swapfile."), true); | 355 | setStatusMessage(tr("Failed to create swapfile."), true); |
349 | } | 356 | } |
350 | 357 | ||
351 | mkswapProgress->setProgress(2); | 358 | mkswapProgress->setProgress(2); |
352 | rc=exec(QString("mkswap %1").arg(swapPath1->text())); | 359 | rc=exec(QString("mkswap %1").arg(swapPath1->text())); |
353 | if (rc != 0) { | 360 | if (rc != 0) { |
@@ -426,14 +433,20 @@ void Swapfile::status() | |||
426 | case 2: swapSize->setCurrentItem(0); | 433 | case 2: swapSize->setCurrentItem(0); |
427 | break; | 434 | break; |
428 | case 4: swapSize->setCurrentItem(1); | 435 | case 4: swapSize->setCurrentItem(1); |
429 | break; | 436 | break; |
430 | case 6: swapSize->setCurrentItem(2); | 437 | case 6: swapSize->setCurrentItem(2); |
431 | break; | 438 | break; |
432 | case 8: swapSize->setCurrentItem(3); | 439 | case 8: swapSize->setCurrentItem(3); |
433 | break; | 440 | break; |
441 | case 16: swapSize->setCurrentItem(4); | ||
442 | break; | ||
443 | case 32: swapSize->setCurrentItem(5); | ||
444 | break; | ||
445 | case 64: swapSize->setCurrentItem(6); | ||
446 | break; | ||
434 | } | 447 | } |
435 | 448 | ||
436 | 449 | ||
437 | } | 450 | } |
438 | 451 | ||
439 | 452 | ||