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

« back to all changes in this revision

Viewing changes to libs/ksysguard/processui/ProcessModel.h

  • 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
    KSysGuard, the KDE System Guard
 
3
 
 
4
        Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
 
5
        Copyright (c) 2006 John Tapsell <john.tapsell@kde.org>
 
6
 
 
7
    This library is free software; you can redistribute it and/or
 
8
    modify it under the terms of the GNU Library General Public
 
9
    License as published by the Free Software Foundation; either
 
10
    version 2 of the License, or (at your option) any later version.
 
11
 
 
12
    This library 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 GNU
 
15
    Library General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Library General Public License
 
18
    along with this library; see the file COPYING.LIB.  If not, write to
 
19
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
20
    Boston, MA 02110-1301, USA.
 
21
 
 
22
*/
 
23
 
 
24
#ifndef PROCESSMODEL_H_
 
25
#define PROCESSMODEL_H_
 
26
 
 
27
#include <QtCore/QAbstractItemModel>
 
28
 
 
29
#include <kdemacros.h>
 
30
#include "processes.h"
 
31
 
 
32
namespace KSysGuard {
 
33
        class Processes;
 
34
        class Process;
 
35
}
 
36
 
 
37
class ProcessModelPrivate;
 
38
 
 
39
#ifdef Q_CC_MSVC
 
40
// this workaround is needed to make krunner link under msvc
 
41
// please keep it this way even if you port this library to have a _export.h header file
 
42
#define KSYSGUARD_EXPORT
 
43
#else
 
44
#define KSYSGUARD_EXPORT KDE_EXPORT
 
45
#endif
 
46
 
 
47
class KSYSGUARD_EXPORT ProcessModel : public QAbstractItemModel
 
48
{
 
49
    Q_OBJECT
 
50
    Q_ENUMS(Units)
 
51
 
 
52
    public:
 
53
        ProcessModel(QObject* parent = 0, const QString &host = QString() );
 
54
        virtual ~ProcessModel();
 
55
 
 
56
        /* Functions for our Model for QAbstractItemModel*/
 
57
        int rowCount(const QModelIndex &parent = QModelIndex()) const;
 
58
        int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
 
59
        QVariant data(const QModelIndex &index, int role) const;
 
60
        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
61
        QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
 
62
        QModelIndex parent ( const QModelIndex & index ) const;
 
63
 
 
64
        bool hasChildren ( const QModelIndex & parent) const;
 
65
        /** Returns if (left < right), used by the sort-filter proxy model to sort the columns */
 
66
        bool lessThan( const QModelIndex & left, const QModelIndex & right) const;
 
67
 
 
68
        /* Functions for drag and drop and copying to clipboard, inherited from QAbstractItemModel */
 
69
        QStringList mimeTypes() const;
 
70
        QMimeData *mimeData(const QModelIndexList &indexes) const;
 
71
        Qt::ItemFlags flags(const QModelIndex &index) const;
 
72
 
 
73
        /* Functions for setting the model */
 
74
 
 
75
        /** Setup the column headings by inserting the appropriate headings into the model.
 
76
         *  Can be called more than once to retranslate the headings if the system language changes.
 
77
         */
 
78
        void setupHeader();
 
79
 
 
80
        /** Update data.  You can pass in the time between updates to only update if there hasn't
 
81
         *  been an update within the last @p updateDurationMSecs milliseconds.  0 indicate to update
 
82
         *  regardless of when the last update was.
 
83
         *  The updateFlags indicates what to additional update, as well as the usual details. */
 
84
        void update(long updateDurationMSecs = 0, KSysGuard::Processes::UpdateFlags updateFlags = KSysGuard::Processes::IOStatistics);
 
85
        /** Return a string with the pid of the process and the name of the process.  E.g.  13343: ksysguard
 
86
        */
 
87
        QString getStringForProcess(KSysGuard::Process *process) const;
 
88
        KSysGuard::Process *getProcess(qlonglong pid);
 
89
 
 
90
        /** This is used from ProcessFilter to get the process at a given index when in flat mode */
 
91
        KSysGuard::Process *getProcessAtIndex(int index) const;
 
92
 
 
93
        /** Returns whether this user can log in or not.
 
94
         *  @see mUidCanLogin
 
95
         */
 
96
        bool canUserLogin(long uid) const;
 
97
        /** In simple mode, everything is flat, with no icons, few if any colors, no xres etc.
 
98
         *  This can be changed at any time.  It is a fairly quick operation.  Basically it resets the model
 
99
         */
 
100
        void setSimpleMode(bool simple);
 
101
        /** In simple mode, everything is flat, with no icons, few if any colors, no xres etc
 
102
        */
 
103
        bool isSimpleMode() const;
 
104
 
 
105
        /** Returns the total amount of physical memory in the machine. */
 
106
        qlonglong totalMemory() const;
 
107
 
 
108
        /** This returns a QModelIndex for the given process.  It has to look up the parent for this pid, find the offset this
 
109
         *  pid is from the parent, and return that.  It's not that slow, but does involve a couple of hash table lookups.
 
110
         */
 
111
        QModelIndex getQModelIndex ( KSysGuard::Process *process, int column) const;
 
112
 
 
113
        /** Whether this is showing the processes for the current machine
 
114
        */
 
115
        bool isLocalhost() const;
 
116
 
 
117
        /** The host name that this widget is showing the processes of */
 
118
        QString hostName() const;
 
119
 
 
120
        /** Whether this process has a GUI window */
 
121
        bool hasGUIWindow(qlonglong pid) const;
 
122
 
 
123
        /** Returns for process controller pointer for this model */
 
124
        KSysGuard::Processes *processController() const;   //The processes instance
 
125
 
 
126
        /** Convenience function to get the number of processes.
 
127
         *
 
128
         *  Equivalent to processController->processCount() */
 
129
        int processCount() const { return processController()->processCount(); }
 
130
 
 
131
        /** The headings in the model.  The order here is the order that they are shown
 
132
         *  in.  If you change this, make sure you also change the
 
133
         *  setup header function, and make sure you increase PROCESSHEADERVERSION.  This will ensure
 
134
         *  that old saved settings won't be used
 
135
         */
 
136
#define PROCESSHEADERVERSION 5
 
137
        enum { HeadingName=0, HeadingUser, HeadingPid, HeadingTty, HeadingNiceness, HeadingCPUUsage, HeadingCPUTime, HeadingIoRead, HeadingIoWrite, HeadingVmSize, HeadingMemory, HeadingSharedMemory, HeadingCommand, HeadingXMemory, HeadingXTitle };
 
138
 
 
139
        enum { UidRole = Qt::UserRole, SortingValueRole, WindowIdRole, PlainValueRole, PercentageRole };
 
140
 
 
141
        bool showTotals() const;
 
142
 
 
143
        /** When displaying memory sizes, this is the units it should be displayed in */
 
144
        enum Units { UnitsAuto, UnitsKB, UnitsMB, UnitsGB, UnitsTB, UnitsPB, UnitsPercentage  };
 
145
        /** Set the units memory sizes etc should be displayed in */
 
146
        void setUnits(Units units);
 
147
        /** The units memory sizes etc should be displayed in */
 
148
        Units units() const;
 
149
        /** Set the I/O units sizes etc should be displayed in */
 
150
        void setIoUnits(Units units);
 
151
        /** The units I/O sizes etc should be displayed in */
 
152
        Units ioUnits() const;
 
153
 
 
154
        enum IoInformation { Bytes, Syscalls, ActualBytes, BytesRate, SyscallsRate, ActualBytesRate };
 
155
        /** Set the information to show in the Io Read and Io Write columns */
 
156
        void setIoInformation( IoInformation ioInformation );
 
157
        /** The information to show in the Io Read and Io Write columns */
 
158
        IoInformation ioInformation() const;
 
159
 
 
160
        /** Take an amount in kb, and return a string in the units set by setUnits() */
 
161
        QString formatMemoryInfo(qlonglong amountInKB, Units units, bool returnEmptyIfValueIsZero = false) const;
 
162
        /** Whether to show the command line options in the process name column */
 
163
        bool isShowCommandLineOptions() const;
 
164
        /** Set whether to show the command line options in the process name column */
 
165
        void setShowCommandLineOptions(bool showCommandLineOptions);
 
166
 
 
167
        /** Whether to show tooltips when the mouse hovers over a process */
 
168
        bool isShowingTooltips() const;
 
169
        /** Set whether to show tooltips when the mouse hovers over a process */
 
170
        void setShowingTooltips(bool showTooltips);
 
171
        /** Whether to divide CPU usage by the number of CPUs */
 
172
        bool isNormalizedCPUUsage() const;
 
173
        /** Set whether to divide CPU usage by the number of CPUs */
 
174
        void setNormalizedCPUUsage(bool normalizeCPUUsage);
 
175
 
 
176
        /** Retranslate the GUI, for when the system language changes */
 
177
        void retranslateUi();
 
178
 
 
179
    public Q_SLOTS:
 
180
        /** Whether to show the total cpu for the process plus all of its children */
 
181
        void setShowTotals(bool showTotals);
 
182
 
 
183
    private:
 
184
        ProcessModelPrivate*  const d;
 
185
        friend class ProcessModelPrivate;
 
186
};
 
187
 
 
188
#endif
 
189