author | ar <ar> | 2004-03-28 21:01:03 (UTC) |
---|---|---|
committer | ar <ar> | 2004-03-28 21:01:03 (UTC) |
commit | 05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f (patch) (unidiff) | |
tree | 6c6a291b25cdf4bd265ab8da8c8c4058758d46c3 | |
parent | b4c5da4a6cf51753e8d2da505197326e05323d73 (diff) | |
download | opie-05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f.zip opie-05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f.tar.gz opie-05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f.tar.bz2 |
- better parse of /proc/meminfo
- delete useless variable declaration
-rw-r--r-- | noncore/settings/sysinfo/memory.cpp | 70 | ||||
-rw-r--r-- | noncore/settings/sysinfo/memory.h | 1 |
2 files changed, 47 insertions, 24 deletions
diff --git a/noncore/settings/sysinfo/memory.cpp b/noncore/settings/sysinfo/memory.cpp index 23dd8bd..05349e4 100644 --- a/noncore/settings/sysinfo/memory.cpp +++ b/noncore/settings/sysinfo/memory.cpp | |||
@@ -1,141 +1,165 @@ | |||
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 <qlabel.h> | 21 | #include <qlabel.h> |
22 | #include <qtimer.h> | 22 | #include <qtimer.h> |
23 | #include <qfile.h> | 23 | #include <qfile.h> |
24 | #include <qtextstream.h> | 24 | #include <qtextstream.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qwhatsthis.h> | 26 | #include <qwhatsthis.h> |
27 | #include "graph.h" | 27 | #include "graph.h" |
28 | #include "memory.h" | 28 | #include "memory.h" |
29 | 29 | ||
30 | MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f ) | 30 | MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f ) |
31 | : QWidget( parent, name, f ) | 31 | : QWidget( parent, name, f ) |
32 | { | 32 | { |
33 | QVBoxLayout *vb = new QVBoxLayout( this, 5 ); | 33 | QVBoxLayout *vb = new QVBoxLayout( this, 5 ); |
34 | 34 | ||
35 | totalMem = new QLabel( this ); | 35 | totalMem = new QLabel( this ); |
36 | vb->addWidget( totalMem ); | 36 | vb->addWidget( totalMem ); |
37 | 37 | ||
38 | data = new GraphData(); | 38 | data = new GraphData(); |
39 | graph = new BarGraph( this ); | 39 | graph = new BarGraph( this ); |
40 | graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 40 | graph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
41 | vb->addWidget( graph, 1 ); | 41 | vb->addWidget( graph, 1 ); |
42 | graph->setData( data ); | 42 | graph->setData( data ); |
43 | 43 | ||
44 | legend = new GraphLegend( this ); | 44 | legend = new GraphLegend( this ); |
45 | vb->addWidget( legend ); | 45 | vb->addWidget( legend ); |
46 | legend->setData( data ); | 46 | legend->setData( data ); |
47 | 47 | ||
48 | swapMem = new QLabel( this ); | 48 | swapMem = new QLabel( this ); |
49 | vb->addWidget( swapMem ); | 49 | vb->addWidget( swapMem ); |
50 | 50 | ||
51 | swapdata = new GraphData(); | 51 | swapdata = new GraphData(); |
52 | swapgraph = new BarGraph( this ); | 52 | swapgraph = new BarGraph( this ); |
53 | swapgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 53 | swapgraph->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
54 | vb->addWidget( swapgraph, 1 ); | 54 | vb->addWidget( swapgraph, 1 ); |
55 | swapgraph->setData( swapdata ); | 55 | swapgraph->setData( swapdata ); |
56 | 56 | ||
57 | swaplegend = new GraphLegend( this ); | 57 | swaplegend = new GraphLegend( this ); |
58 | vb->addWidget( swaplegend ); | 58 | vb->addWidget( swaplegend ); |
59 | swaplegend->setData( swapdata ); | 59 | swaplegend->setData( swapdata ); |
60 | 60 | ||
61 | vb->addStretch( 1 ); | 61 | vb->addStretch( 1 ); |
62 | updateData(); | 62 | updateData(); |
63 | 63 | ||
64 | QTimer *t = new QTimer( this ); | 64 | QTimer *t = new QTimer( this ); |
65 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | 65 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); |
66 | t->start( 5000 ); | 66 | t->start( 5000 ); |
67 | 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." ) ); | 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 | 69 | ||
70 | } | 70 | } |
71 | 71 | ||
72 | MemoryInfo::~MemoryInfo() | 72 | MemoryInfo::~MemoryInfo() |
73 | { | 73 | { |
74 | delete data; | 74 | delete data; |
75 | } | 75 | } |
76 | 76 | ||
77 | void MemoryInfo::updateData() | 77 | void MemoryInfo::updateData() |
78 | { | 78 | { |
79 | QFile file( "/proc/meminfo" ); | 79 | QFile file( "/proc/meminfo" ); |
80 | 80 | ||
81 | if ( file.open( IO_ReadOnly ) ) | 81 | if ( file.open( IO_ReadOnly ) ) |
82 | { | 82 | { |
83 | // local variables | ||
84 | QString line; | ||
85 | QString identifier; | ||
86 | QString value; | ||
87 | int position; | ||
83 | QTextStream t( &file ); | 88 | QTextStream t( &file ); |
84 | QString dummy = t.readLine(); // title | 89 | |
85 | t >> dummy; | 90 | while ( !t.atEnd() ) |
86 | t >> total; | 91 | { |
87 | total /= 1000; | 92 | // read a line |
88 | t >> used; | 93 | line = t.readLine(); |
89 | used /= 1000; | 94 | |
90 | t >> memfree; | 95 | // extract identifier and value from line |
91 | memfree /= 1000; | 96 | position = line.find( ":" ); |
92 | t >> shared; | 97 | identifier = line.left( position ); |
93 | shared /= 1000; | 98 | value = line.mid( position + 1, line.length() - position - 3 ); |
94 | t >> buffers; | 99 | value = value.stripWhiteSpace(); |
95 | buffers /= 1000; | 100 | |
96 | t >> cached; | 101 | // copy values in variables |
97 | cached /= 1000; | 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; | ||
98 | realUsed = total - ( buffers + cached + memfree ); | 130 | realUsed = total - ( buffers + cached + memfree ); |
99 | 131 | ||
132 | // visualize values | ||
100 | totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) ); | 133 | totalMem->setText( tr( "Total Memory: %1 kB" ).arg( total ) ); |
101 | data->clear(); | 134 | data->clear(); |
102 | data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed ); | 135 | data->addItem( tr("Used (%1 kB)").arg(realUsed), realUsed ); |
103 | data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers ); | 136 | data->addItem( tr("Buffers (%1 kB)").arg(buffers), buffers ); |
104 | data->addItem( tr("Cached (%1 kB)").arg(cached), cached ); | 137 | data->addItem( tr("Cached (%1 kB)").arg(cached), cached ); |
105 | data->addItem( tr("Free (%1 kB)").arg(memfree), memfree ); | 138 | data->addItem( tr("Free (%1 kB)").arg(memfree), memfree ); |
106 | 139 | ||
107 | graph->hide(); | 140 | graph->hide(); |
108 | graph->show(); | 141 | graph->show(); |
109 | legend->update(); | 142 | legend->update(); |
110 | 143 | ||
111 | // swapfile | ||
112 | t >> dummy; | ||
113 | t >> swaptotal; | ||
114 | swaptotal /= 1000; | ||
115 | t >> swapused; | ||
116 | swapused /= 1000; | ||
117 | t >> swapfree; | ||
118 | swapfree /= 1000; | ||
119 | |||
120 | if (swaptotal > 0) | 144 | if (swaptotal > 0) |
121 | { | 145 | { |
122 | swapMem->setText( tr( "Total Swap: %1 kB" ).arg( swaptotal ) ); | 146 | swapMem->setText( tr( "Total Swap: %1 kB" ).arg( swaptotal ) ); |
123 | swapdata->clear(); | 147 | swapdata->clear(); |
124 | swapdata->addItem( tr("Used (%1 kB)").arg(swapused), swapused ); | 148 | swapdata->addItem( tr("Used (%1 kB)").arg(swapused), swapused ); |
125 | swapdata->addItem( tr("Free (%1 kB)").arg(swapfree), swapfree ); | 149 | swapdata->addItem( tr("Free (%1 kB)").arg(swapfree), swapfree ); |
126 | 150 | ||
127 | swapMem->show(); | 151 | swapMem->show(); |
128 | swapgraph->show(); | 152 | swapgraph->show(); |
129 | swaplegend->show(); | 153 | swaplegend->show(); |
130 | 154 | ||
131 | swapgraph->repaint( FALSE ); | 155 | swapgraph->repaint( FALSE ); |
132 | swaplegend->update(); | 156 | swaplegend->update(); |
133 | } | 157 | } |
134 | else | 158 | else |
135 | { | 159 | { |
136 | swapMem->hide(); | 160 | swapMem->hide(); |
137 | swapgraph->hide(); | 161 | swapgraph->hide(); |
138 | swaplegend->hide(); | 162 | swaplegend->hide(); |
139 | } | 163 | } |
140 | } | 164 | } |
141 | } | 165 | } |
diff --git a/noncore/settings/sysinfo/memory.h b/noncore/settings/sysinfo/memory.h index c2af948..f655604 100644 --- a/noncore/settings/sysinfo/memory.h +++ b/noncore/settings/sysinfo/memory.h | |||
@@ -1,64 +1,63 @@ | |||
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 | #ifndef MEMORY_H | 21 | #ifndef MEMORY_H |
22 | #define MEMORY_H | 22 | #define MEMORY_H |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | 25 | ||
26 | class GraphData; | 26 | class GraphData; |
27 | class Graph; | 27 | class Graph; |
28 | class GraphLegend; | 28 | class GraphLegend; |
29 | class QLabel; | 29 | class QLabel; |
30 | 30 | ||
31 | class MemoryInfo : public QWidget | 31 | class MemoryInfo : public QWidget |
32 | { | 32 | { |
33 | Q_OBJECT | 33 | Q_OBJECT |
34 | public: | 34 | public: |
35 | MemoryInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 35 | MemoryInfo( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
36 | ~MemoryInfo(); | 36 | ~MemoryInfo(); |
37 | 37 | ||
38 | unsigned long total; | 38 | unsigned long total; |
39 | unsigned long used; | 39 | unsigned long used; |
40 | unsigned long memfree; | 40 | unsigned long memfree; |
41 | unsigned long shared; | ||
42 | unsigned long buffers; | 41 | unsigned long buffers; |
43 | unsigned long cached; | 42 | unsigned long cached; |
44 | unsigned long realUsed; | 43 | unsigned long realUsed; |
45 | unsigned long swaptotal; | 44 | unsigned long swaptotal; |
46 | unsigned long swapused; | 45 | unsigned long swapused; |
47 | unsigned long swapfree; | 46 | unsigned long swapfree; |
48 | 47 | ||
49 | private slots: | 48 | private slots: |
50 | void updateData(); | 49 | void updateData(); |
51 | 50 | ||
52 | private: | 51 | private: |
53 | QLabel *totalMem; | 52 | QLabel *totalMem; |
54 | GraphData *data; | 53 | GraphData *data; |
55 | Graph *graph; | 54 | Graph *graph; |
56 | GraphLegend *legend; | 55 | GraphLegend *legend; |
57 | 56 | ||
58 | QLabel* swapMem; | 57 | QLabel* swapMem; |
59 | GraphData *swapdata; | 58 | GraphData *swapdata; |
60 | Graph *swapgraph; | 59 | Graph *swapgraph; |
61 | GraphLegend *swaplegend; | 60 | GraphLegend *swaplegend; |
62 | }; | 61 | }; |
63 | 62 | ||
64 | #endif | 63 | #endif |