-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 | |||
@@ -59,83 +59,107 @@ MemoryInfo::MemoryInfo( QWidget *parent, const char *name, WFlags f ) | |||
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 | |||
@@ -17,48 +17,47 @@ | |||
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 |