~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/memory/physicalMemoryChart.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 ***************************************************************************/
 
11
 
 
12
#include "physicalMemoryChart.h"
 
13
 
 
14
#include <klocale.h>
 
15
#include <kdebug.h>
 
16
 
 
17
#include "base.h"
 
18
 
 
19
 
 
20
PhysicalMemoryChart::PhysicalMemoryChart(QWidget* parent) :
 
21
        Chart(parent) {
 
22
 
 
23
        colorsInitialized = false;
 
24
}
 
25
 
 
26
void PhysicalMemoryChart::paintEvent(QPaintEvent* /*event*/) {
 
27
        /* RAM usage: */
 
28
        /* don't rely on the SHARED_MEM value since it may refer to
 
29
         * the size of the System V sharedmem in 2.4.x. Calculate instead! */
 
30
 
 
31
        t_memsize bufferMemory;
 
32
        
 
33
        bufferMemory = 0;
 
34
#if !defined(__svr4__) || !defined(sun)
 
35
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
 
36
        bufferMemory = ZERO_IF_NO_INFO(memoryInfos[BUFFER_MEM]);
 
37
#endif
 
38
#endif
 
39
        t_memsize cachedMemory = ZERO_IF_NO_INFO(memoryInfos[CACHED_MEM]);
 
40
        t_memsize freeMemory = ZERO_IF_NO_INFO(memoryInfos[FREE_MEM]);
 
41
        t_memsize totalMemory = ZERO_IF_NO_INFO(memoryInfos[TOTAL_MEM]) - bufferMemory - cachedMemory - freeMemory;
 
42
        
 
43
        QList<t_memsize> used;
 
44
        used.append(freeMemory);
 
45
        used.append(cachedMemory);
 
46
        used.append(bufferMemory);
 
47
        used.append(totalMemory);
 
48
        
 
49
        if (!colorsInitialized) {
 
50
                colorsInitialized = true;
 
51
                texts.append(i18n("Free Physical Memory"));
 
52
                colors.append(COLOR_FREE_MEMORY); // free 
 
53
                texts.append(i18n("Disk Cache"));
 
54
                colors.append(QColor(88, 176, 36)); // cached 
 
55
                texts.append(i18n("Disk Buffers"));
 
56
                colors.append(QColor(118, 237, 49)); // buffer
 
57
                texts.append(i18n("Application Data"));
 
58
                colors.append(COLOR_USED_MEMORY); // used+shared
 
59
        }
 
60
        
 
61
        drawChart(memoryInfos[TOTAL_MEM], used, colors, texts);
 
62
 
 
63
}