author | mickeyl <mickeyl> | 2005-01-29 09:35:52 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-01-29 09:35:52 (UTC) |
commit | d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a (patch) (side-by-side diff) | |
tree | c17be6e75e277c3fa0378f352f45766f75031cdb | |
parent | f85af28663814f3262f5ecfcd20a4b4f67c23067 (diff) | |
download | opie-d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a.zip opie-d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a.tar.gz opie-d4cf8c6020c46e5dc97b75f3a9781ddc15416b3a.tar.bz2 |
fix 1505 and suck sysinfo files into the tree instead of cross referencing
eventually we may find that graph and load are of universal usage, then
they should appear in some kind of library
-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
@@ -1,42 +1,43 @@ 2005-??-?? Opie 1.1.9 New Features ------------ * Number of icon columns in Launcher is customizable through Launcher.conf (hrw,zecke,mickeyl) * Number of icon columns in Launcher is customizable through LauncherSettings (mickeyl) Fixed Bugs ---------- * #1501 - Fixed bug in todo sql backend (eilers) + * #1505 - Added more Swap sizes in memoryapplet (mickeyl) * #1525 - Hopefully fixed double alarms and not removing alarms set with the Clock application (zecke) * #1533 - Security Owner Dialog (shown in case of unsuccessfull authentiacation) wasn't able to display information in non latin1 encoding (zecke) * n.a. - Removed hard coded font sizes in a couple of inputmethods (mickeyl) * n.a. - Removed MediumDlg appearing prior to FirstUsage wizard (i.e. calibration) (mickeyl) Internal -------- * Added the Qtopia 1.7 SDK macros for quick-apps to easa compilation of 3rd party apps against our headers (mickeyl) * You can now use the Opie build system in combination with a OpenEmbedded staging area which makes a nice cross development environment (mickeyl) * Made Opie compilable with Qt/Embedded 2.3.10 (ar) * Changed Launcher to get default orientation from ODevice w/ QWS_DISPLAY overriding (mickeyl) 2004-11-26 Opie 1.1.8 New Features ------------ * PackageManager supports installation of local ipkg files (drw) * PackageManager supports linking of applications to root (drw) * PackageManager supports src/gz feeds (drw,wimpie) * Added a syslog information tab to sysinfo (mickeyl) * Added new, more consistent, PIM icons + a GIMP teplate (ar) Fixed Bugs ---------- * #1017 - Tetrix doesn't display correctly for high resolution screens (drw) * #1269 - VCards were imported into personal area if it was activated (eilers) * #1464 - Packagemanager dont set active filter after install a package (drw) * #1479 - Improved VCard-Parser to import VCards created by Evolution 2 and Apple Addressbook (eilers) * #1493 - Fixed one column layout bug of the launcher (hrw) * n.a. - PackageManager - (Minor UI tweak) in filter dialog, when option is enabled, set focus to widget that corresponds to that option (drw) * n.a. - PackageManager - (Minor UI tweak) fix double entry in source feed configuration when adding a new feed (drw) * n.a. - Battery Applet - fix sizing of battery info popup (drw,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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include <qpainter.h> +#include <qpixmap.h> +#include "graph.h" + +void GraphData::clear() +{ + names.clear(); + values.resize(0); +} + +void GraphData::addItem( const QString &name, int value ) +{ + names.append( name ); + values.resize( values.size() + 1 ); + values[values.size()-1] = value; +} + +Graph::Graph(QWidget *parent, const char *name, WFlags f ) + : QFrame( parent, name, f ) +{ +} + +PieGraph::PieGraph(QWidget *parent, const char *name, WFlags f ) + : Graph( parent, name, f ) +{ +} + +void PieGraph::drawContents( QPainter *p ) +{ + int size = QMIN( contentsRect().width(), contentsRect().height() ) - 1; + + int total = 0; + for ( unsigned i = 0; i < data->count(); i++ ) + total += data->value(i); + + int angle = 0; + for ( unsigned i = 0; i < data->count(); i++ ) { + int len; + if ( i == data->count() - 1 || !total ) + len = 5760 - angle; + else + len = data->value(i) * 5760 / total; + QColor col; + col.setHsv( i * 360 / data->count(), 255, 255 ); + p->setBrush( col ); + p->drawPie ( contentsRect().x(), contentsRect().y(), + size, size, angle, len+32 ); + angle += len; + } +} + +BarGraph::BarGraph(QWidget *parent, const char *name, WFlags f ) + : Graph( parent, name, f ) +{ + setMinimumHeight( 10 ); + setMaximumHeight( 45 ); +} + +void BarGraph::drawContents( QPainter *p ) +{ + int h = contentsRect().height(); + int y = contentsRect().top(); + + int total = 0; + for ( unsigned i = 0; i < data->count(); i++ ) + total += data->value(i); + + int pos = 0; + for ( unsigned i = 0; i < data->count(); i++ ) { + int len; + if ( i == data->count() - 1 || !total ) + len = contentsRect().width() - pos; + else + len = data->value(i) * contentsRect().width() / total; + QColor col; + col.setHsv( i * 360 / data->count(), 255, 255 ); + drawSegment( p, QRect(contentsRect().x() + pos, y, len, h), col ); + pos += len; + } +} + +void BarGraph::drawSegment( QPainter *p, const QRect &r, const QColor &c ) +{ + if ( QPixmap::defaultDepth() > 8 ) { + QColor topgrad = c.light(170); + QColor botgrad = c.dark(); + + int h1, h2, s1, s2, v1, v2; + topgrad.hsv( &h1, &s1, &v1 ); + botgrad.hsv( &h2, &s2, &v2 ); + int ng = r.height(); + for ( int j =0; j < ng; j++ ) { + p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1), + s1 + ((s2-s1)*j)/(ng-1), + v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) ); + p->drawLine( r.x(), r.top()+j, r.x()+r.width(), r.top()+j ); + } + } else { + p->fillRect( r.x(), r.top(), r.width(), r.height(), c ); + } +} + + +GraphLegend::GraphLegend( QWidget *parent, const char *name, WFlags f ) + : QFrame( parent, name, f ) +{ + horz = FALSE; +} + +void GraphLegend::setOrientation(Orientation o) +{ + horz = o == Horizontal; +} + +void GraphLegend::drawContents( QPainter *p ) +{ + int total = 0; + for ( unsigned i = 0; i < data->count(); i++ ) + total += data->value(i); + + int tw = width()/data->count()-1; + int th = height()/(horz ? 1 : data->count()); + if ( th > p->fontMetrics().height() ) + th = p->fontMetrics().height(); + int x = 0; + int y = 0; + for ( unsigned i = 0; i < data->count(); i++ ) { + QColor col; + col.setHsv( i * 360 / data->count(), 255, 255 ); + p->setBrush( col ); + p->drawRect( x+1, y+1, th - 2, th - 2 ); + p->drawText( x+th + 1, y + p->fontMetrics().ascent()+1, data->name(i) ); + if ( horz ) { + x += tw; + } else { + y += th; + } + } +} + +QSize GraphLegend::sizeHint() const +{ + int th = fontMetrics().height() + 2; + int maxw = 0; + for ( unsigned i = 0; i < data->count(); i++ ) { + int w = fontMetrics().width( data->name(i) ); + if ( w > maxw ) + maxw = w; + } + if ( 0 && horz ) { + return QSize( maxw * data->count(), th ); + } else { + return QSize( maxw, th * data->count() ); + } +} + +void GraphLegend::setData( const GraphData *p ) +{ + data = p; + int th = fontMetrics().height(); + setMinimumHeight( th * ( horz ? 1 : data->count() ) ); + updateGeometry(); +} 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include <qframe.h> +#include <qarray.h> +#include <qstringlist.h> + +class GraphData +{ +public: + void clear(); + void addItem( const QString &name, int value ); + + const QString &name( int i ) const { return names[i]; } + int value( int i ) const { return values[i]; } + unsigned count() const { return values.size(); } + +private: + QStringList names; + QArray<int> values; +}; + +class Graph : public QFrame +{ + Q_OBJECT +public: + Graph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + + void setData( const GraphData *p ) { data = p; } + +protected: + const GraphData *data; +}; + +class PieGraph : public Graph +{ + Q_OBJECT +public: + PieGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + +protected: + virtual void drawContents( QPainter *p ); +}; + +class BarGraph : public Graph +{ + Q_OBJECT +public: + BarGraph( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + +protected: + virtual void drawContents( QPainter *p ); + void drawSegment( QPainter *p, const QRect &r, const QColor &c ); +}; + +class GraphLegend : public QFrame +{ + Q_OBJECT +public: + GraphLegend( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + + void setData( const GraphData *p ); + virtual QSize sizeHint() const; + void setOrientation(Orientation o); + +protected: + virtual void drawContents( QPainter *p ); + +private: + const GraphData *data; + bool horz; +}; 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include <stdio.h> + +#include <qfile.h> +#include <qlayout.h> +#include <qlabel.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qtextstream.h> +#include <qtimer.h> +#include <qwhatsthis.h> + +#include "load.h" + +LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f ) + : QWidget( parent, name, f ) +{ + QVBoxLayout *vb = new QVBoxLayout( this, 6 ); + + QString cpuInfo = getCpuInfo(); + if ( !cpuInfo.isNull() ) + vb->addWidget( new QLabel( cpuInfo, this ) ); + vb->addWidget( new Load( this ), 100 ); + QLabel *l = new QLabel( this ); + l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) ); + vb->addWidget( l, 1 ); + l = new QLabel( this ); + l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) ); + vb->addWidget( l, 1 ); + vb->addStretch(50); + + QWhatsThis::add( this, tr( "This page shows how much this device's processor is being used." ) ); +} + +QPixmap LoadInfo::makeLabel( const QColor &col, const QString &text ) +{ + int h = fontMetrics().height(); + QPixmap pm( 20 + fontMetrics().width( text ), h ); + QPainter p( &pm ); + p.fillRect( pm.rect(), colorGroup().background() ); + p.fillRect( 0, h/2-4, 18, h/2+3, black ); + p.setPen( col ); + p.drawLine( 2, h/2, 15, h/2 ); + p.setPen( colorGroup().text() ); + p.drawText( 20, fontMetrics().ascent(), text ); + + return pm; +} + +QString LoadInfo::getCpuInfo() +{ + bool haveInfo = FALSE; + QString info = tr("Type: "); + QFile f( "/proc/cpuinfo" ); + if ( f.open( IO_ReadOnly ) ) { + QTextStream ts( &f ); + + while ( !ts.atEnd() ) { + QString s = ts.readLine(); + if ( s.find( "model name" ) == 0 ) { + info += s.mid( s.find( ':' ) + 2 ); + haveInfo = TRUE; + } else if ( s.find( "cpu MHz" ) == 0 ) { + double mhz = s.mid( s.find( ':' ) + 2 ).toDouble(); + info += " " + QString::number( mhz, 'f', 0 ); + info += "MHz"; + break; + } else if ( s.find( "Processor" ) == 0 ) { + info += s.mid( s.find( ':' ) + 2 ); + haveInfo = TRUE; + break; +#ifdef __MIPSEL__ + } else if ( s.find( "cpu model" ) == 0 ) { + info += " " + s.mid( s.find( ':' ) + 2 ); + break; + } else if ( s.find( "cpu" ) == 0 ) { + info += s.mid( s.find( ':' ) + 2 ); + haveInfo = TRUE; +#endif + } + } + } + + if ( !haveInfo ) + info = QString(); + + return info; +} + +Load::Load( QWidget *parent, const char *name, WFlags f ) + : QWidget( parent, name, f ) +{ + setMinimumHeight( 30 ); + setBackgroundColor( black ); + points = 100; + setMinimumWidth( points ); + userLoad = new double [points]; + systemLoad = new double [points]; + for ( int i = 0; i < points; i++ ) { + userLoad[i] = 0.0; + systemLoad[i] = 0.0; + } + maxLoad = 1.3; + QTimer *timer = new QTimer( this ); + connect( timer, SIGNAL(timeout()), SLOT(timeout()) ); + timer->start( 2000 ); + gettimeofday( &last, 0 ); + first = TRUE; + timeout(); +} + +void Load::paintEvent( QPaintEvent * ) +{ + QPainter p( this ); + + int h = height() - 5; + + int mult = (int)(h / maxLoad); + + p.setPen( gray ); + p.drawLine( 0, h - mult, width(), h - mult ); + p.drawText( 0, h - mult, "100" ); + p.drawText( 0, h, "0" ); + + p.setPen( green ); + for ( int i = 1; i < points; i++ ) { + int x1 = (i - 1) * width() / points; + int x2 = i * width() / points; + p.drawLine( x1, h - systemLoad[i-1] * mult, + x2, h - systemLoad[i] * mult ); + } + + p.setPen( red ); + for ( int i = 1; i < points; i++ ) { + int x1 = (i - 1) * width() / points; + int x2 = i * width() / points; + p.drawLine( x1, h - userLoad[i-1] * mult, + x2, h - userLoad[i] * mult ); + } +} + +void Load::timeout() +{ + int user; + int usernice; + int sys; + int idle; + FILE *fp; + fp = fopen( "/proc/stat", "r" ); + fscanf( fp, "cpu %d %d %d %d", &user, &usernice, &sys, &idle ); + fclose( fp ); + struct timeval now; + gettimeofday( &now, 0 ); + int tdiff = now.tv_usec - last.tv_usec; + tdiff += (now.tv_sec - last.tv_sec) * 1000000; + tdiff /= 10000; + + int udiff = user - lastUser; + int sdiff = sys - lastSys; + if ( tdiff > 0 ) { + double uload = (double)udiff / (double)tdiff; + double sload = (double)sdiff / (double)tdiff; + if ( !first ) { + for ( int i = 1; i < points; i++ ) { + userLoad[i-1] = userLoad[i]; + systemLoad[i-1] = systemLoad[i]; + } + userLoad[points-1] = uload; + systemLoad[points-1] = sload; +// scroll( -width()/points, 0, QRect( 0, 0, width() - width()/points + 1, height() ) ); + repaint( TRUE ); + double ml = 1.3; + /* + for ( int i = 0; i < points; i++ ) { + if ( userLoad[i] > ml ) + ml = userLoad[i]; + } + */ + if ( maxLoad != ml ) { + maxLoad = ml; + update(); + } + } + + last = now; + lastUser = user; + lastSys = sys; + first = FALSE; + } else if ( tdiff < 0 ) { + last = now; + } +} + 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include <sys/time.h> +#include <qwidget.h> + +/* + Little load meter +*/ +class Load : public QWidget { + Q_OBJECT +public: + Load( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + +protected: + void paintEvent( QPaintEvent *ev ); + +private slots: + void timeout(); + +private: + int points; + double *userLoad; + double *systemLoad; + double maxLoad; + struct timeval last; + int lastUser; + int lastUsernice; + int lastSys; + int lastIdle; + bool first; +}; + +class LoadInfo : public QWidget +{ + Q_OBJECT +public: + LoadInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + +private: + QPixmap makeLabel( const QColor &col, const QString &text ); + QString getCpuInfo(); +}; 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include <qlabel.h> +#include <qtimer.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qlayout.h> +#include <qwhatsthis.h> +#include "graph.h" +#include "memory.h" + +MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f ) + : QWidget( parent, name, f ) +{ + QVBoxLayout *vb = new QVBoxLayout( this, 5 ); + + totalMem = new QLabel( this ); + vb->addWidget( totalMem ); + + data = new GraphData(); + graph = new BarGraph( this ); + graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + vb->addWidget( graph, 1 ); + graph->setData( data ); + + legend = new GraphLegend( this ); + vb->addWidget( legend ); + legend->setData( data ); + + swapMem = new QLabel( this ); + vb->addWidget( swapMem ); + + swapdata = new GraphData(); + swapgraph = new BarGraph( this ); + swapgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + vb->addWidget( swapgraph, 1 ); + swapgraph->setData( swapdata ); + + swaplegend = new GraphLegend( this ); + vb->addWidget( swaplegend ); + swaplegend->setData( swapdata ); + + vb->addStretch( 1 ); + updateData(); + + QTimer *t = new QTimer( this ); + connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); + t->start( 5000 ); + + 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." ) ); + +} + +MemoryInfo::~MemoryInfo() +{ + delete data; +} + +void MemoryInfo::updateData() +{ + QFile file( "/proc/meminfo" ); + + if ( file.open( IO_ReadOnly ) ) + { + // local variables + QString line; + QString identifier; + QString value; + int position; + QTextStream t( &file ); + + while ( !t.atEnd() ) + { + // read a line + line = t.readLine(); + + // extract identifier and value from line + position = line.find( ":" ); + identifier = line.left( position ); + value = line.mid( position + 1, line.length() - position - 3 ); + value = value.stripWhiteSpace(); + + // copy values in variables + if ( identifier == "MemTotal" ) + { + total = value.toULong(); + } else if ( identifier == "MemFree" ) + { + memfree = value.toULong(); + } else if ( identifier == "Buffers" ) + { + buffers = value.toULong(); + } else if ( identifier == "Cached" ) + { + cached = value.toULong(); + } else if ( identifier == "SwapCached" ) + { + } else if ( identifier == "SwapTotal" ) + { + swaptotal = value.toULong(); + } else if ( identifier == "SwapFree" ) + { + swapfree = value.toULong(); + } + } + + file.close(); + + // calculate values + used = total - memfree; + swapused = swaptotal - swapfree; + realUsed = total - ( buffers + cached + memfree ); + + // visualize values + totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) ); + data->clear(); + data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed ); + data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers ); + data->addItem( tr("Cached (%1 kB)").arg(cached), cached ); + data->addItem( tr("Free (%1 kB)").arg(memfree), memfree ); + + graph->hide(); + graph->show(); + legend->update(); + + if (swaptotal > 0) + { + swapMem->setText( tr( "Total Swap: %1 kB" ).arg( swaptotal ) ); + swapdata->clear(); + swapdata->addItem( tr("Used (%1 kB)").arg(swapused), swapused ); + swapdata->addItem( tr("Free (%1 kB)").arg(swapfree), swapfree ); + + swapMem->show(); + swapgraph->show(); + swaplegend->show(); + + swapgraph->repaint( FALSE ); + swaplegend->update(); + } + else + { + swapMem->hide(); + swapgraph->hide(); + swaplegend->hide(); + } + } +} 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 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef MEMORY_H +#define MEMORY_H + +#include <qwidget.h> + +class GraphData; +class Graph; +class GraphLegend; +class QLabel; + +class MemoryInfo : public QWidget +{ + Q_OBJECT +public: + MemoryInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); + ~MemoryInfo(); + + unsigned long total; + unsigned long used; + unsigned long memfree; + unsigned long buffers; + unsigned long cached; + unsigned long realUsed; + unsigned long swaptotal; + unsigned long swapused; + unsigned long swapfree; + +private slots: + void updateData(); + +private: + QLabel *totalMem; + GraphData *data; + Graph *graph; + GraphLegend *legend; + + QLabel* swapMem; + GraphData *swapdata; + Graph *swapgraph; + GraphLegend *swaplegend; +}; + +#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 @@ TEMPLATE = lib CONFIG += qt plugin warn_on -HEADERS = ../../settings/sysinfo/graph.h \ - ../../settings/sysinfo/load.h \ - ../../settings/sysinfo/memory.h \ +HEADERS = graph.h \ + load.h \ + memory.h \ memorymeter.h \ memorystatus.h \ swapfile.h -SOURCES = ../../settings/sysinfo/graph.cpp \ - ../../settings/sysinfo/load.cpp \ - ../../settings/sysinfo/memory.cpp \ +SOURCES = graph.cpp \ + load.cpp \ + memory.cpp \ memorymeter.cpp \ memorystatus.cpp \ swapfile.cpp TARGET = memoryapplet DESTDIR = $(OPIEDIR)/plugins/applets INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += -VERSION = 1.0.0 +VERSION = 1.0.1 LIBS += -lqpe -lopiecore2 -lopieui2 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 @@ -61,65 +61,65 @@ Swapfile::Swapfile( QWidget *parent, const char *name, WFlags f ) QVBoxLayout* vb = new QVBoxLayout(this, 5); QHButtonGroup* cfsdRBG = new QHButtonGroup(tr("Swapfile location"), this); cfsdRBG->setRadioButtonExclusive(true); vb->addWidget(cfsdRBG); ramRB = new QRadioButton(tr("RAM"), cfsdRBG); cfRB = new QRadioButton(tr("CF Card"), cfsdRBG); sdRB = new QRadioButton(tr("SD Card"), cfsdRBG); QHBox *hb1 = new QHBox(this); hb1->setSpacing(5); swapPath1 = new QLineEdit(hb1); swapPath1->setEnabled(false); QPushButton* swapOn = new QPushButton(tr(" On "), hb1); QPushButton* swapOff = new QPushButton(tr(" Off "), hb1); vb->addWidget(hb1); QVGroupBox* box1 = new QVGroupBox(tr("Manage Swapfile"), this); vb->addWidget(box1); QHBox *hb2 = new QHBox(box1); hb2->setSpacing(5); QPushButton* mkSwap = new QPushButton(tr("Generate"), hb2); QPushButton* rmSwap = new QPushButton(tr("Remove"), hb2); QHBox *hb3 = new QHBox(box1); hb3->setSpacing(5); swapSize = new QComboBox(hb3); - swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb"))); + swapSize->insertStringList(QStringList::split(",", tr("2 Mb,4 Mb,6 Mb,8 Mb,16 Mb,32 Mb,64 Mb"))); mkswapProgress = new QProgressBar(3, hb3); mkswapProgress->setCenterIndicator(true); QHBox *hb4 = new QHBox(this); hb4->setSpacing(5); swapStatusIcon = new QLabel(hb4); swapStatus = new QLabel("", hb4); hb4->setStretchFactor(swapStatus, 99); vb->addWidget(hb4); connect(swapOn, SIGNAL(clicked()), this, SLOT(swapon())); connect(swapOff, SIGNAL(clicked()), this, SLOT(swapoff())); connect(cfRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); connect(sdRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); connect(ramRB, SIGNAL(clicked()), this, SLOT(cfsdchecked())); connect(mkSwap, SIGNAL(clicked()), this, SLOT(makeswapfile())); connect(rmSwap, SIGNAL(clicked()), this, SLOT(removeswapfile())); cfRB->setEnabled(FALSE); sdRB->setEnabled(FALSE); QCopChannel *pcmciaChannel = new QCopChannel("QPE/Card", this); connect(pcmciaChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); QCopChannel *sdChannel = new QCopChannel("QPE/Card", this); connect(sdChannel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(cardnotify(const QCString&,const QByteArray&))); cardInPcmcia0 = FALSE; cardInPcmcia1 = FALSE; cardInSd = FALSE; @@ -314,64 +314,71 @@ void Swapfile::cfsdchecked() { /* Swapfile::swapPath->clear();*/ Swapfile::swapPath1->clear(); if (Swapfile::ramRB->isChecked() == TRUE) { Swapfile::swapPath1->insert("/home/swapfile"); } if (Swapfile::sdRB->isChecked() == TRUE) { Swapfile::swapPath1->insert("/mnt/card/swapfile"); } if (Swapfile::cfRB->isChecked() == TRUE) { Swapfile::swapPath1->insert("/mnt/cf/swapfile"); } /* Swapfile::swapPath->insert(Swapfile::swapPath1->text());*/ } void Swapfile::makeswapfile() { int i = swapSize->currentItem(); mkswapProgress->setProgress(1); switch ( i ) { case 0: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=2048").arg(swapPath1->text())); break; case 1: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=4096").arg(swapPath1->text())); break; case 2: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=6144").arg(swapPath1->text())); break; case 3: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=8192").arg(swapPath1->text())); break; + case 4: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=16384").arg(swapPath1->text())); + break; + case 5: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=32768").arg(swapPath1->text())); + break; + case 6: rc=exec(QString("dd if=/dev/zero of=%1 bs=1k count=65536").arg(swapPath1->text())); + break; + } if (rc != 0) { setStatusMessage(tr("Failed to create swapfile."), true); } mkswapProgress->setProgress(2); rc=exec(QString("mkswap %1").arg(swapPath1->text())); if (rc != 0) { setStatusMessage(tr("Failed to initialize swapfile."), true); } mkswapProgress->setProgress(3); mkswapProgress->reset(); setStatusMessage(tr("Swapfile created.")); } void Swapfile::removeswapfile() { exec(QString("swapoff %1").arg(swapPath1->text())); rc=exec(QString("rm -rf %1").arg(swapPath1->text())); if (rc != 0) { setStatusMessage(tr("Failed to remove swapfile."), true); } Swapfile::status(); Swapfile::cfsdchecked(); setStatusMessage(tr("Swapfile removed.")); } void Swapfile::status() { FILE *fp; char buffer[128], swapfile[128], temp[128]; int swapsize=2000, i=1; @@ -402,38 +409,44 @@ void Swapfile::status() if ( i == 0 ) { cfRB->setChecked(TRUE); /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ setStatusMessage(tr("Swapfile activated.")); } i=strcmp(swapfile, "/usr/mnt.rom/card/swapfile"); if ( i == 0 ) { sdRB->setChecked(TRUE); /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ setStatusMessage(tr("Swapfile activated.")); } i=strcmp(swapfile, "/mnt/card/swapfile"); if ( i == 0 ) { sdRB->setChecked(TRUE); /* QMessageBox::information(this, "Information", "Swapfile is active!"); */ setStatusMessage(tr("Swapfile activated.")); } Swapfile::cfsdchecked(); swapsize /=1000; switch ( swapsize ) { case 2: swapSize->setCurrentItem(0); break; case 4: swapSize->setCurrentItem(1); break; case 6: swapSize->setCurrentItem(2); break; case 8: swapSize->setCurrentItem(3); break; + case 16: swapSize->setCurrentItem(4); + break; + case 32: swapSize->setCurrentItem(5); + break; + case 64: swapSize->setCurrentItem(6); + break; } } |