summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore 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
@@ -71,61 +71,85 @@ MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f )
71 71
72MemoryInfo::~MemoryInfo() 72MemoryInfo::~MemoryInfo()
73{ 73{
74 delete data; 74 delete data;
75} 75}
76 76
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 );
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 );
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
@@ -29,25 +29,24 @@ class GraphLegend;
29class QLabel; 29class QLabel;
30 30
31class MemoryInfo : public QWidget 31class MemoryInfo : public QWidget
32{ 32{
33 Q_OBJECT 33 Q_OBJECT
34public: 34public:
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
49private slots: 48private slots:
50 void updateData(); 49 void updateData();
51 50
52private: 51private:
53 QLabel *totalMem; 52 QLabel *totalMem;