summaryrefslogtreecommitdiff
path: root/noncore
authorar <ar>2004-03-28 21:01:03 (UTC)
committer ar <ar>2004-03-28 21:01:03 (UTC)
commit05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f (patch) (unidiff)
tree6c6a291b25cdf4bd265ab8da8c8c4058758d46c3 /noncore
parentb4c5da4a6cf51753e8d2da505197326e05323d73 (diff)
downloadopie-05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f.zip
opie-05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f.tar.gz
opie-05a5f3a0cfbb5f882d03bf1c7700cdc608b97a2f.tar.bz2
- better parse of /proc/meminfo
- delete useless variable declaration
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/sysinfo/memory.cpp70
-rw-r--r--noncore/settings/sysinfo/memory.h1
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
@@ -77,49 +77,73 @@ MemoryInfo::~MemoryInfo()
77void MemoryInfo::updateData() 77void 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 );
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
@@ -35,13 +35,12 @@ 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;