-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 | |||
@@ -82,19 +82,52 @@ void MemoryInfo::updateData() | |||
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 ) ); |
@@ -110,11 +143,2 @@ void MemoryInfo::updateData() | |||
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) |
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 | |||
@@ -40,3 +40,2 @@ public: | |||
40 | unsigned long memfree; | 40 | unsigned long memfree; |
41 | unsigned long shared; | ||
42 | unsigned long buffers; | 41 | unsigned long buffers; |