2
KSysGuard, the KDE System Guard
4
Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
5
Copyright (c) 2006 John Tapsell <john.tapsell@kde.org>
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.
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.
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.
24
#ifndef PROCESSMODEL_H_
25
#define PROCESSMODEL_H_
27
#include <QtCore/QAbstractItemModel>
29
#include <kdemacros.h>
30
#include "processes.h"
37
class ProcessModelPrivate;
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
44
#define KSYSGUARD_EXPORT KDE_EXPORT
47
class KSYSGUARD_EXPORT ProcessModel : public QAbstractItemModel
53
ProcessModel(QObject* parent = 0, const QString &host = QString() );
54
virtual ~ProcessModel();
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;
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;
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;
73
/* Functions for setting the model */
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.
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
87
QString getStringForProcess(KSysGuard::Process *process) const;
88
KSysGuard::Process *getProcess(qlonglong pid);
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;
93
/** Returns whether this user can log in or not.
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
100
void setSimpleMode(bool simple);
101
/** In simple mode, everything is flat, with no icons, few if any colors, no xres etc
103
bool isSimpleMode() const;
105
/** Returns the total amount of physical memory in the machine. */
106
qlonglong totalMemory() const;
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.
111
QModelIndex getQModelIndex ( KSysGuard::Process *process, int column) const;
113
/** Whether this is showing the processes for the current machine
115
bool isLocalhost() const;
117
/** The host name that this widget is showing the processes of */
118
QString hostName() const;
120
/** Whether this process has a GUI window */
121
bool hasGUIWindow(qlonglong pid) const;
123
/** Returns for process controller pointer for this model */
124
KSysGuard::Processes *processController() const; //The processes instance
126
/** Convenience function to get the number of processes.
128
* Equivalent to processController->processCount() */
129
int processCount() const { return processController()->processCount(); }
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
136
#define PROCESSHEADERVERSION 5
137
enum { HeadingName=0, HeadingUser, HeadingPid, HeadingTty, HeadingNiceness, HeadingCPUUsage, HeadingCPUTime, HeadingIoRead, HeadingIoWrite, HeadingVmSize, HeadingMemory, HeadingSharedMemory, HeadingCommand, HeadingXMemory, HeadingXTitle };
139
enum { UidRole = Qt::UserRole, SortingValueRole, WindowIdRole, PlainValueRole, PercentageRole };
141
bool showTotals() const;
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 */
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;
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;
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);
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);
176
/** Retranslate the GUI, for when the system language changes */
177
void retranslateUi();
180
/** Whether to show the total cpu for the process plus all of its children */
181
void setShowTotals(bool showTotals);
184
ProcessModelPrivate* const d;
185
friend class ProcessModelPrivate;