not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / libs / ksysguard / processui / ProcessModel.h
blob496b45a532aded7c50d2d1639d9bc7e74ad8451f
1 /*
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>
31 namespace KSysGuard {
32 class Processes;
33 class Process;
36 class ProcessModelPrivate;
38 #ifdef Q_CC_MSVC
39 // this workaround is needed to make krunner link under msvc
40 // please keep it this way even if you port this library to have a _export.h header file
41 #define KSYSGUARD_EXPORT
42 #else
43 #define KSYSGUARD_EXPORT KDE_EXPORT
44 #endif
46 class KSYSGUARD_EXPORT ProcessModel : public QAbstractItemModel
48 Q_OBJECT
49 Q_ENUMS(Units)
51 public:
52 ProcessModel(QObject* parent = 0, const QString &host = QString() );
53 virtual ~ProcessModel();
55 /* Functions for our Model for QAbstractItemModel*/
56 int rowCount(const QModelIndex &parent = QModelIndex()) const;
57 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
58 QVariant data(const QModelIndex &index, int role) const;
59 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
60 QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
61 QModelIndex parent ( const QModelIndex & index ) const;
63 bool hasChildren ( const QModelIndex & parent) const;
65 /* Functions for drag and drop and copying to clipboard, inherited from QAbstractItemModel */
66 QStringList mimeTypes() const;
67 QMimeData *mimeData(const QModelIndexList &indexes) const;
68 Qt::ItemFlags flags(const QModelIndex &index) const;
70 /* Functions for setting the model */
72 /** Setup the column headings by inserting the appropriate headings into the model.
73 * Can be called more than once to retranslate the headings if the system language changes.
75 void setupHeader();
77 /** Update data. You can pass in the time between updates to only update if there hasn't
78 * been an update within the last @p updateDurationMSecs milliseconds */
79 void update(int updateDurationMSecs = 0);
81 /** Return a string with the pid of the process and the name of the process. E.g. 13343: ksyguard
83 QString getStringForProcess(KSysGuard::Process *process) const;
84 KSysGuard::Process *getProcess(long long pid);
86 /** This is used from ProcessFilter to get the process at a given index when in flat mode */
87 KSysGuard::Process *getProcessAtIndex(int index) const;
89 /** Returns whether this user can log in or not.
90 * @see mUidCanLogin
92 bool canUserLogin(long long uid) const;
93 /** In simple mode, everything is flat, with no icons, few if any colors, no xres etc.
94 * This can be changed at any time. It is a fairly quick operation. Basically it resets the model
95 */
96 void setSimpleMode(bool simple);
97 /** In simple mode, everything is flat, with no icons, few if any colors, no xres etc
99 bool isSimpleMode() const;
101 /** Returns the total amount of physical memory in the machine. */
102 long long totalMemory() const;
104 /** This returns a QModelIndex for the given process. It has to look up the parent for this pid, find the offset this
105 * pid is from the parent, and return that. It's not that slow, but does involve a couple of hash table lookups.
107 QModelIndex getQModelIndex ( KSysGuard::Process *process, int column) const;
109 /** Whether this is showing the processes for the current machine
111 bool isLocalhost() const;
113 /** The host name that this widget is showing the processes of */
114 QString hostName() const;
116 /** Whether this process has a GUI window */
117 bool hasGUIWindow(long long pid) const;
119 /** Returns for process controller pointer for this model
121 KSysGuard::Processes *processController(); ///The processes instance
123 /** The headings in the model. The order here is the order that they are shown
124 * in. If you change this, make sure you also change the
125 * setup header function, and make sure you increase PROCESSHEADERVERSION. This will ensure
126 * that old saved settings won't be used
128 #define PROCESSHEADERVERSION 1
129 enum { HeadingName=0, HeadingUser, HeadingPid, HeadingTty, HeadingNiceness, HeadingCPUUsage, HeadingVmSize, HeadingMemory, HeadingSharedMemory, HeadingCommand, HeadingXTitle };
130 enum { UidRole = Qt::UserRole, SortingValueRole, WindowIdRole, TotalMemoryRole, NumberOfProcessorsRole, PlainValueRole };
132 bool showTotals() const;
134 /** When displaying memory sizes, this is the units it should be displayed in */
135 enum Units { UnitsKB, UnitsMB, UnitsGB };
136 /** Set the units memory sizes etc should be displayed in */
137 void setUnits(Units units);
138 /** The units memory sizes etc should be displayed in */
139 Units units() const;
140 /** Take an amount in kb, and return a string in the units set by setUnits() */
141 QString formatMemoryInfo(long amountInKB) const;
143 /** Retranslate the GUI, for when the system language changes */
144 void retranslateUi();
146 public Q_SLOTS:
148 /** Whether to show the total cpu for the process plus all of its children */
149 void setShowTotals(bool showTotals);
151 private:
152 ProcessModelPrivate* const d;
153 friend class ProcessModelPrivate;
156 #endif