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.
26
#include <sys/types.h>
32
#include "ProcessModel.h"
33
#include "ProcessModel_p.h"
34
#include "ProcessFilter.h"
36
bool ProcessFilter::filterAcceptsRow( int source_row, const QModelIndex & source_parent ) const
38
if( (mFilter == AllProcesses || mFilter == AllProcessesInTreeForm)
39
&& filterRegExp().isEmpty()) return true; //Shortcut for common case
41
ProcessModel *model = static_cast<ProcessModel *>(sourceModel());
42
const KSysGuard::Process *process;
43
if(model->isSimpleMode()) {
44
if(source_parent.isValid()) {
45
kDebug() << "Serious error with data. In simple mode, there should be no children";
48
process = model->getProcessAtIndex(source_row);
50
KSysGuard::Process *parent_process = NULL;
51
if(source_parent.isValid()) {
52
parent_process = reinterpret_cast<KSysGuard::Process *>(source_parent.internalPointer());
53
Q_ASSERT(parent_process);
55
//if(!model->isSimpleMode()) {
56
parent_process = model->getProcess(-1); //Get our 'special' process which should have the root init child
57
Q_ASSERT(parent_process);
60
if(!model->isSimpleMode() && source_row >= parent_process->children.size()) {
61
kDebug() << "Serious error with data. Source row requested for a non existent row. Requested " << source_row << " of " << parent_process->children.size() << " for " << parent_process->pid;
65
process = parent_process->children.at(source_row);
68
long uid = process->uid;
69
long euid = process->euid;
74
case AllProcessesInTreeForm:
77
if( uid >= 100 && model->canUserLogin(uid))
81
if( (uid < 100 || !model->canUserLogin(uid)) && (euid < 100 || !model->canUserLogin(euid)))
85
long ownuid = getuid();
86
if(uid != ownuid && process->suid != ownuid && process->fsuid != ownuid && euid != ownuid)
91
if(process->tty.isEmpty()) {
92
if(!model->hasGUIWindow(process->pid))
95
// login and getty kinda _are_ the tty, so I do not really count them as 'programs'. So make a special case and hide them
96
// Their ppid are 1 (init) so by checking we try to avoid false matches, and speed up checking overall
97
QString name = process->name.section(' ', 0,0);
98
if(process->parent_pid == 1 && (name == "login" || name.endsWith("getty")))
107
if(filterRegExp().isEmpty()) return true;
109
//Allow the user to search by PID
110
if(QString::number(process->pid).contains(filterRegExp())) return true;
112
//None of our tests have rejected it. Pass it on to qsortfilterproxymodel's filter
113
if(QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent))
118
//We did not accept this row at all.
120
//If we are in flat mode, then give up now
121
if(mFilter != AllProcessesInTreeForm)
124
//one of our children might be accepted, so accept this row if our children are accepted.
125
QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
126
for(int i = 0 ; i < sourceModel()->rowCount(source_index); i++) {
127
if(filterAcceptsRow(i, source_index)) return true;
132
bool ProcessFilter::lessThan(const QModelIndex &left, const QModelIndex &right) const
134
if(right.isValid() && left.isValid()) {
135
Q_ASSERT(left.model());
136
Q_ASSERT(right.model());
137
const ProcessModel *model = static_cast<const ProcessModel *>(left.model());
138
return model->lessThan(left, right);
140
return QSortFilterProxyModel::lessThan(left,right);
144
void ProcessFilter::setFilter(State filter) {
146
filterChanged();//Tell the proxy view to refresh all its information
148
#include "ProcessFilter.moc"