5
* Copyright (C) 2008 Ivo Anjo <knuckles@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include <QStringList>
31
#include <QVBoxLayout>
32
#include <QHBoxLayout>
33
#include <QLinearGradient>
34
#include <QTreeWidget>
36
#include <kaboutdata.h>
40
#include <sys/param.h> /* for BSD */
45
#include <KPluginFactory>
46
#include <KPluginLoader>
48
#include "chartWidget.h"
50
#include "physicalMemoryChart.h"
51
#include "totalMemoryChart.h"
52
#include "swapMemoryChart.h"
55
all fetchValues()-functions should put either
56
their results _OR_ the value NO_MEMORY_INFO into memoryInfos[]
58
static t_memsize memoryInfos[MEM_LAST_ENTRY];
64
static QLabel *memorySizeLabels[MEM_LAST_ENTRY][2];
67
K_PLUGIN_FACTORY(KCMMemoryFactory,
68
registerPlugin<KCMMemory>();
70
K_EXPORT_PLUGIN(KCMMemoryFactory("kcm_memory"))
72
KCMMemory::KCMMemory(QWidget *parent, const QVariantList &) :
73
KCModule(KCMMemoryFactory::componentData(), parent) {
75
KAboutData *about = new KAboutData(I18N_NOOP("kcm_memory"), 0,
76
ki18n("KDE Panel Memory Information Control Module"),
77
0, KLocalizedString(), KAboutData::License_GPL,
78
ki18n("(c) 1998 - 2002 Helge Deller"));
80
about->addAuthor(ki18n("Helge Deller"), KLocalizedString(), "deller@gmx.de");
83
QString title, initial_str;
87
QVBoxLayout *top = new QVBoxLayout(this);
91
QGroupBox* informationGroup = initializeText();
92
top->addWidget(informationGroup, 1);
95
QGroupBox* graphicsGroup = initializeCharts();
96
top->addWidget(graphicsGroup, 2);
98
timer = new QTimer(this);
101
connect(timer, SIGNAL(timeout()), this, SLOT(updateDatas()));
106
KCMMemory::~KCMMemory() {
111
QString KCMMemory::quickHelp() const {
112
return i18n("This display shows you the current memory usage of your system."
113
" The values are updated on a regular basis and give you an"
114
" overview of the physical and virtual memory being used.");
117
QGroupBox* KCMMemory::initializeText() {
118
QGroupBox* informationGroup = new QGroupBox(i18n("Memory"));
120
QHBoxLayout *hbox = new QHBoxLayout(informationGroup);
122
/* stretch the left side */
127
//TODO Use the more smart QGridLayout !!!
129
/* first create the Informationtext-Widget */
130
QVBoxLayout *vbox = new QVBoxLayout();
131
hbox->addLayout(vbox);
133
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
136
title = i18n("Total physical memory:");
139
title = i18n("Free physical memory:");
141
#if !defined(__svr4__) || !defined(sun)
142
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
144
title = i18n("Shared memory:");
147
title = i18n("Disk buffers:");
151
title = i18n("Active memory:");
154
title = i18n("Inactive memory:");
159
title = i18n("Disk cache:");
162
vbox->addSpacing(SPACING);
163
title = i18n("Total swap memory:");
166
title = i18n("Free swap memory:");
172
QLabel* labelWidget = new QLabel(title, this);
173
labelWidget->setAlignment(Qt::AlignLeft);
174
vbox->addWidget(labelWidget);
179
/* then the memory-content-widgets */
180
for (int j = 0; j < 2; j++) {
181
vbox = new QVBoxLayout();
182
hbox->addLayout(vbox);
184
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
186
vbox->addSpacing(SPACING);
187
QLabel* labelWidget = new QLabel(this);
188
labelWidget->setAlignment(Qt::AlignRight);
189
memorySizeLabels[i][j] = labelWidget;
190
vbox->addWidget(labelWidget);
197
/* stretch the right side */
200
return informationGroup;
204
QGroupBox* KCMMemory::initializeCharts() {
205
QGroupBox* chartsGroup = new QGroupBox(i18n("Charts"));
207
QHBoxLayout* chartsLayout = new QHBoxLayout(chartsGroup);
208
chartsLayout->setSpacing(1);
209
chartsLayout->setMargin(1);
211
//chartsLayout->addStretch(1);
215
totalMemory = new ChartWidget(i18n("Total Memory"),
216
i18n("This graph gives you an overview of the "
217
"<b>total sum of physical and virtual memory</b> "
219
new TotalMemoryChart(this), this);
221
chartsLayout->addWidget(totalMemory);
222
chartsLayout->addSpacing(SPACING);
225
physicalMemory = new ChartWidget(i18n("Physical Memory"),
226
i18n("This graph gives you an overview of "
227
"the <b>usage of physical memory</b> in your system."
228
"<p>Most operating systems (including Linux) "
229
"will use as much of the available physical "
230
"memory as possible as disk cache, "
231
"to speed up the system performance.</p>"
232
"<p>This means that if you have a small amount "
233
"of <b>Free Physical Memory</b> and a large amount of "
234
"<b>Disk Cache Memory</b>, your system is well "
236
new PhysicalMemoryChart(this), this);
238
chartsLayout->addWidget(physicalMemory);
239
chartsLayout->addSpacing(SPACING);
241
swapMemory = new ChartWidget(i18n("Swap Space"),
242
i18n("<p>The swap space is the <b>virtual memory</b> "
243
"available to the system.</p> "
244
"<p>It will be used on demand and is provided "
245
"through one or more swap partitions and/or swap files.</p>"),
246
new SwapMemoryChart(this), this);
249
chartsLayout->addWidget(swapMemory);
251
//chartsLayout->addStretch(1);
256
void KCMMemory::updateDatas() {
258
/* get the Information from memory_linux, memory_fbsd */
262
updateMemoryGraphics();
266
void KCMMemory::updateMemoryText() {
267
/* update the byte-strings */
268
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
269
QLabel* label = memorySizeLabels[i][0];
270
if (memoryInfos[i] == NO_MEMORY_INFO)
273
label->setText(i18np("1 byte =", "%1 bytes =", memoryInfos[i]));
276
/* update the MB-strings */
277
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
278
QLabel* label = memorySizeLabels[i][1];
279
label->setText((memoryInfos[i] != NO_MEMORY_INFO) ? Chart::formattedUnit(memoryInfos[i]) : i18n("Not available."));
284
void KCMMemory::updateMemoryGraphics() {
285
totalMemory->setMemoryInfos(memoryInfos);
286
totalMemory->refresh();
288
physicalMemory->setMemoryInfos(memoryInfos);
289
physicalMemory->refresh();
291
swapMemory->setMemoryInfos(memoryInfos);
292
swapMemory->refresh();
296
/* Include system-specific code */
299
#include "memory_linux.cpp"
300
#elif defined(__APPLE__)
301
#include "memory_osx.cpp"
302
#elif defined(sgi) && sgi
303
#include "memory_sgi.cpp"
304
#elif defined(__svr4__) && defined(sun)
305
#include "memory_solaris.cpp"
306
#elif defined(__FreeBSD__) || defined(__DragonFly__)
307
#include "memory_fbsd.cpp"
308
#elif defined(__hpux)
309
#include "memory_hpux.cpp"
310
#elif defined(__NetBSD__) || defined(__OpenBSD__)
311
#include "memory_netbsd.cpp"
312
#elif defined(__osf__)
313
#include "memory_tru64.cpp"
316
/* Default for unsupported systems */
317
void KCMMemory::fetchValues() {
319
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
320
memoryInfos[i] = NO_MEMORY_INFO;
326
#include "memory.moc"