author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/settings/sysinfo/memory.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/settings/sysinfo/memory.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/memory.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/noncore/settings/sysinfo/memory.cpp b/noncore/settings/sysinfo/memory.cpp new file mode 100644 index 0000000..781f0df --- a/dev/null +++ b/noncore/settings/sysinfo/memory.cpp | |||
@@ -0,0 +1,94 @@ | |||
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 "graph.h" | ||
27 | #include "memory.h" | ||
28 | |||
29 | MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f ) | ||
30 | : QWidget( parent, name, f ) | ||
31 | { | ||
32 | QVBoxLayout *vb = new QVBoxLayout( this, 5 ); | ||
33 | |||
34 | totalMem = new QLabel( this ); | ||
35 | vb->addWidget( totalMem ); | ||
36 | |||
37 | data = new GraphData(); | ||
38 | // graph = new PieGraph( this ); | ||
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 | vb->addStretch( 1 ); | ||
49 | updateData(); | ||
50 | |||
51 | QTimer *t = new QTimer( this ); | ||
52 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | ||
53 | t->start( 5000 ); | ||
54 | } | ||
55 | |||
56 | MemoryInfo::~MemoryInfo() | ||
57 | { | ||
58 | delete data; | ||
59 | } | ||
60 | |||
61 | void MemoryInfo::updateData() | ||
62 | { | ||
63 | QFile file( "/proc/meminfo" ); | ||
64 | |||
65 | if ( file.open( IO_ReadOnly ) ) { | ||
66 | QTextStream t( &file ); | ||
67 | QString dummy = t.readLine();// title | ||
68 | t >> dummy; | ||
69 | int total, used, memfree, shared, buffers, cached; | ||
70 | t >> total; | ||
71 | total /= 1000; | ||
72 | t >> used; | ||
73 | used /= 1000; | ||
74 | t >> memfree; | ||
75 | memfree /= 1000; | ||
76 | t >> shared; | ||
77 | shared /= 1000; | ||
78 | t >> buffers; | ||
79 | buffers /= 1000; | ||
80 | t >> cached; | ||
81 | cached /= 1000; | ||
82 | int realUsed = total - ( buffers + cached + memfree ); | ||
83 | data->clear(); | ||
84 | data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed ); | ||
85 | data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers ); | ||
86 | data->addItem( tr("Cached (%1 kB)").arg(cached), cached ); | ||
87 | data->addItem( tr("Free (%1 kB)").arg(memfree), memfree ); | ||
88 | totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) ); | ||
89 | graph->repaint( FALSE ); | ||
90 | legend->update(); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | |||