Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / kinfocenter / memory / totalMemoryChart.cpp
blob566cc666d626f3832bcd37e9588aa7666dfa4196
1 /***************************************************************************
2 * KT list view item task implementation. *
3 * -------------------------------------------------------------------- *
4 * Copyright (C) 1999, Gary Meyer <gary@meyer.net> *
5 * -------------------------------------------------------------------- *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
12 #include "totalMemoryChart.h"
14 #include <klocale.h>
15 #include <kdebug.h>
17 #include "base.h"
20 TotalMemoryChart::TotalMemoryChart(QWidget* parent) :
21 Chart(parent) {
23 colorsInitialized = false;
26 void TotalMemoryChart::paintEvent(QPaintEvent* /*event*/) {
27 // RAM + SWAP usage:
28 if (memoryInfos[SWAP_MEM] == NO_MEMORY_INFO || memoryInfos[FREESWAP_MEM] == NO_MEMORY_INFO)
29 memoryInfos[SWAP_MEM] = memoryInfos[FREESWAP_MEM] = 0;
31 t_memsize usedSwap = memoryInfos[SWAP_MEM] - memoryInfos[FREESWAP_MEM];
32 t_memsize totalFree = memoryInfos[FREE_MEM] + memoryInfos[FREESWAP_MEM];
33 t_memsize usedPhysical = (memoryInfos[TOTAL_MEM]+memoryInfos[SWAP_MEM])-usedSwap-totalFree;
35 QList<t_memsize> used;
37 used.append(totalFree);
38 used.append(usedSwap);
39 used.append(usedPhysical);
41 if (!colorsInitialized) {
42 colorsInitialized = true;
43 texts.append(i18n("Total Free Memory"));
44 colors.append(COLOR_FREE_MEMORY); // free ram+swap
45 texts.append(i18n("Used Swap"));
46 colors.append(COLOR_USED_SWAP); // used swap
47 texts.append(i18n("Used Physical Memory"));
48 colors.append(COLOR_USED_MEMORY); // used ram
51 drawChart(memoryInfos[TOTAL_MEM] + memoryInfos[SWAP_MEM], used, colors, texts);