Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / libs / ksysguard / processui / ProcessModel_p.h
blob9b457914aec7011e54c3b6d1d7d3a4f17f7a8024
1 /*
2 KSysGuard, the KDE System Guard
4 Copyright (c) 2006-2007 John Tapsell <john.tapsell@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #ifndef PROCESSMODEL_P_H_
23 #define PROCESSMODEL_P_H_
25 #include <kapplication.h>
26 #include <kuser.h>
27 #include <QPixmap>
28 #include <QObject>
29 #include <QList>
30 #include <QVariant>
31 #include <QHash>
32 #include <QSet>
33 #include <QTime>
36 #ifdef Q_WS_X11
37 #include <kwindowsystem.h>
38 #include <netwm.h>
39 #include <QtGui/QX11Info>
40 #include <X11/Xatom.h>
41 #include <kxerrorhandler.h>
42 #endif
44 #include "processcore/process.h"
47 #ifdef Q_WS_X11
48 struct WindowInfo {
49 QPixmap icon;
50 WId wid;
51 NETWinInfo *netWinInfo;
54 #endif
57 class ProcessModel;
58 class ProcessModelPrivate : public QObject
60 Q_OBJECT
61 public:
62 ProcessModelPrivate();
63 ~ProcessModelPrivate();
64 public slots:
66 #ifdef Q_WS_X11
67 /** When an X window is changed, this is called */
68 void windowChanged(WId wid, unsigned int properties);
69 /** When an X window is created, this is called
71 void windowAdded(WId wid);
72 /** When an X window is closed, this is called
74 void windowRemoved(WId wid);
75 #endif
77 /** Change the data for a process. This is called from KSysGuard::Processes
78 * if @p onlyCpuOrMem is set, only the total cpu usuage is updated.
79 * process->changes contains a bitfield of what has been changed
81 void processChanged(KSysGuard::Process *process, bool onlyCpuOrMem);
82 /** Called from KSysGuard::Processes
83 * This indicates we are about to insert a process in the model. Emit the appropriate signals
85 void beginInsertRow( KSysGuard::Process *parent);
86 /** Called from KSysGuard::Processes
87 * We have finished inserting a process
89 void endInsertRow();
90 /** Called from KSysGuard::Processes
91 * This indicates we are about to remove a process in the model. Emit the appropriate signals
93 void beginRemoveRow( KSysGuard::Process *process);
94 /** Called from KSysGuard::Processes
95 * We have finished removing a process
97 void endRemoveRow();
98 /** Called from KSysGuard::Processes
99 * This indicates we are about to move a process in the model from one parent process to another. Emit the appropriate signals
101 void beginMoveProcess(KSysGuard::Process *process, KSysGuard::Process *new_parent);
102 /** Called from KSysGuard::Processes
103 * We have finished moving a process
105 void endMoveRow();
107 public:
108 /** On X11 system, connects to the signals emitted when windows are created/destroyed */
109 void setupWindows();
110 /** Connects to the host */
111 void setupProcesses();
112 /** A mapping of running,stopped,etc to a friendly description like 'Stopped, either by a job control signal or because it is being traced.'*/
113 QString getStatusDescription(KSysGuard::Process::ProcessStatus status) const;
115 /** Return a qt markup tooltip string for a local user. It will have their full name etc.
116 * This will be slow the first time, as it practically indirectly reads the whole of /etc/passwd
117 * But the second time will be as fast as hash lookup as we cache the result
119 inline QString getTooltipForUser(const KSysGuard::Process *process) const;
121 /** Return a username for a local user if it can, otherwise just their uid.
122 * This may have been given from the result of "ps" (but not necessarily). If it's not found, then it
123 * needs to find out the username from the uid. This will be slow the first time, as it practically indirectly reads the whole of /etc/passwd
124 * But the second time will be as fast as hash lookup as we cache the result
126 * If withuid is set, and the username is found, return: "username (Uid: uid)"
128 inline QString getUsernameForUser(long long uid, bool withuid) const;
130 /** Return the groupname for a given gid. This is in the form of "gid" if not known, or
131 * "groupname (Uid: gid)" if known.
133 inline QString getGroupnameForGroup(long long gid) const;
134 /** @see setIsLocalhost */
135 bool mIsLocalhost;
137 /** A caching hash for tooltips for a user.
138 * @see getTooltipForUser */
139 mutable QHash<long long,QString> mUserTooltips;
141 /** A caching hash for username for a user uid, or just their uid if it can't be found (as a long long)
142 * @see getUsernameForUser */
143 mutable QHash<long long, QString> mUserUsername;
145 /** A mapping of a user id to whether this user can log in. We have to guess based on the shell. All are set to true to non localhost.
146 * It is set to:
147 * 0 if the user cannot login
148 * 1 is the user can login
149 * The reason for using an int and not a bool is so that we can do mUidCanLogin.value(uid,-1) and thus we get a tristate for whether
150 * they are logged in, not logged in, or not known yet.
151 * */
152 mutable QHash<long long, int> mUidCanLogin;
155 /** A translated list of headings (column titles) in the order we want to display them. Used in headerData() */
156 QStringList mHeadings;
158 QMultiHash< long long, WindowInfo> mPidToWindowInfo; ///Map a process pid to X window info if available
159 QHash< WId, long long> mWIdToPid; ///Map an X window id to a process pid
162 bool mShowChildTotals; ///If set to true, a parent will return the CPU usage of all its children recursively
164 bool mSimple; ///In simple mode, the model returns everything as flat, with no icons, etc. This is set by changing cmbFilter
166 QTime mLastUpdated; ///Time that we last updated the processes.
168 long long mMemTotal; /// the total amount of physical memory in kb in the machine. We can used this to determine the percentage of memory an app is using
169 int mNumProcessorCores; /// The number of (enabled) processor cores in the this machine
171 KSysGuard::Processes *mProcesses; ///The processes instance
173 bool mIsChangingLayout;
175 QPixmap mBlankPixmap; ///Used to pad out process names which don't have an icon
177 /** When displaying memory sizes, this is the units it should be displayed in */
178 int mUnits;
180 /** The hostname */
181 QString mHostName;
183 ProcessModel* q;
186 #endif