summaryrefslogtreecommitdiff
path: root/noncore/settings/sysinfo/load.cpp
Unidiff
Diffstat (limited to 'noncore/settings/sysinfo/load.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/load.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/noncore/settings/sysinfo/load.cpp b/noncore/settings/sysinfo/load.cpp
index 0fcfa6b..900b3d3 100644
--- a/noncore/settings/sysinfo/load.cpp
+++ b/noncore/settings/sysinfo/load.cpp
@@ -1,94 +1,99 @@
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 20
21#include <stdio.h> 21#include <stdio.h>
22
23#include <qfile.h>
22#include <qlayout.h> 24#include <qlayout.h>
23#include <qlabel.h> 25#include <qlabel.h>
24#include <qpainter.h> 26#include <qpainter.h>
25#include <qpixmap.h> 27#include <qpixmap.h>
26#include <qtimer.h>
27#include <qfile.h>
28#include <qtextstream.h> 28#include <qtextstream.h>
29#include <qtimer.h>
30#include <qwhatsthis.h>
31
29#include "load.h" 32#include "load.h"
30 33
31LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f ) 34LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f )
32 : QWidget( parent, name, f ) 35 : QWidget( parent, name, f )
33{ 36{
34 QVBoxLayout *vb = new QVBoxLayout( this, 6 ); 37 QVBoxLayout *vb = new QVBoxLayout( this, 6 );
35 38
36 QString cpuInfo = getCpuInfo(); 39 QString cpuInfo = getCpuInfo();
37 if ( !cpuInfo.isNull() ) 40 if ( !cpuInfo.isNull() )
38 vb->addWidget( new QLabel( cpuInfo, this ) ); 41 vb->addWidget( new QLabel( cpuInfo, this ) );
39 vb->addWidget( new Load( this ), 100 ); 42 vb->addWidget( new Load( this ), 100 );
40 QLabel *l = new QLabel( this ); 43 QLabel *l = new QLabel( this );
41 l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) ); 44 l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) );
42 vb->addWidget( l, 1 ); 45 vb->addWidget( l, 1 );
43 l = new QLabel( this ); 46 l = new QLabel( this );
44 l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) ); 47 l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) );
45 vb->addWidget( l, 1 ); 48 vb->addWidget( l, 1 );
46 vb->addStretch(50); 49 vb->addStretch(50);
50
51 QWhatsThis::add( this, tr( "This page shows how much this device's processor is being used." ) );
47} 52}
48 53
49QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text ) 54QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text )
50{ 55{
51 int h = fontMetrics().height(); 56 int h = fontMetrics().height();
52 QPixmap pm( 20 + fontMetrics().width( text ), h ); 57 QPixmap pm( 20 + fontMetrics().width( text ), h );
53 QPainter p( &pm ); 58 QPainter p( &pm );
54 p.fillRect( pm.rect(), colorGroup().background() ); 59 p.fillRect( pm.rect(), colorGroup().background() );
55 p.fillRect( 0, h/2-4, 18, h/2+3, black ); 60 p.fillRect( 0, h/2-4, 18, h/2+3, black );
56 p.setPen( col ); 61 p.setPen( col );
57 p.drawLine( 2, h/2, 15, h/2 ); 62 p.drawLine( 2, h/2, 15, h/2 );
58 p.setPen( colorGroup().text() ); 63 p.setPen( colorGroup().text() );
59 p.drawText( 20, fontMetrics().ascent(), text ); 64 p.drawText( 20, fontMetrics().ascent(), text );
60 65
61 return pm; 66 return pm;
62} 67}
63 68
64QString LoadInfo::getCpuInfo() 69QString LoadInfo::getCpuInfo()
65{ 70{
66 bool haveInfo = FALSE; 71 bool haveInfo = FALSE;
67 QString info = tr("Type: "); 72 QString info = tr("Type: ");
68 QFile f( "/proc/cpuinfo" ); 73 QFile f( "/proc/cpuinfo" );
69 if ( f.open( IO_ReadOnly ) ) { 74 if ( f.open( IO_ReadOnly ) ) {
70 QTextStream ts( &f ); 75 QTextStream ts( &f );
71 76
72 while ( !ts.atEnd() ) { 77 while ( !ts.atEnd() ) {
73 QString s = ts.readLine(); 78 QString s = ts.readLine();
74 if ( s.find( "model name" ) == 0 ) { 79 if ( s.find( "model name" ) == 0 ) {
75 info += s.mid( s.find( ':' ) + 2 ); 80 info += s.mid( s.find( ':' ) + 2 );
76 haveInfo = TRUE; 81 haveInfo = TRUE;
77 } else if ( s.find( "cpu MHz" ) == 0 ) { 82 } else if ( s.find( "cpu MHz" ) == 0 ) {
78 double mhz = s.mid( s.find( ':' ) + 2 ).toDouble(); 83 double mhz = s.mid( s.find( ':' ) + 2 ).toDouble();
79 info += " " + QString::number( mhz, 'f', 0 ); 84 info += " " + QString::number( mhz, 'f', 0 );
80 info += "MHz"; 85 info += "MHz";
81 break; 86 break;
82 } else if ( s.find( "Processor" ) == 0 ) { 87 } else if ( s.find( "Processor" ) == 0 ) {
83 info += s.mid( s.find( ':' ) + 2 ); 88 info += s.mid( s.find( ':' ) + 2 );
84 haveInfo = TRUE; 89 haveInfo = TRUE;
85 break; 90 break;
86#ifdef __MIPSEL__ 91#ifdef __MIPSEL__
87 } else if ( s.find( "cpu model" ) == 0 ) { 92 } else if ( s.find( "cpu model" ) == 0 ) {
88 info += " " + s.mid( s.find( ':' ) + 2 ); 93 info += " " + s.mid( s.find( ':' ) + 2 );
89 break; 94 break;
90 } else if ( s.find( "cpu" ) == 0 ) { 95 } else if ( s.find( "cpu" ) == 0 ) {
91 info += s.mid( s.find( ':' ) + 2 ); 96 info += s.mid( s.find( ':' ) + 2 );
92 haveInfo = TRUE; 97 haveInfo = TRUE;
93#endif 98#endif
94 } 99 }