add more spacing
[personal-kdebase.git] / workspace / libs / ksysguard / processui / ksysguardprocesslist.h
blob8f5118a5dd9d97878c7161f35da3d452a657de56
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 _KSysGuardProcessList_h_
25 #define _KSysGuardProcessList_h_
27 #include <QtGui/QWidget>
28 #include <kapplication.h>
29 #include "ProcessModel.h"
30 #include "ProcessFilter.h"
31 #include "processes.h"
33 class QShowEvent;
34 class QHideEvent;
35 class QLineEdit;
36 class QTreeView;
37 struct KSysGuardProcessListPrivate;
38 extern KApplication* Kapp;
40 /**
41 * This widget implements a process list page. Besides the process
42 * list which is implemented as a ProcessList, it contains two
43 * comboxes and two buttons. The combo boxes are used to set the
44 * update rate and the process filter. The buttons are used to force
45 * an immediate update and to kill a process.
47 class KDE_EXPORT KSysGuardProcessList : public QWidget
49 Q_OBJECT
50 Q_PROPERTY( bool showTotalsInTree READ showTotals WRITE setShowTotals )
51 Q_PROPERTY( ProcessFilter::State state READ state WRITE setState )
52 Q_PROPERTY( int updateIntervalMSecs READ updateIntervalMSecs WRITE setUpdateIntervalMSecs )
53 Q_PROPERTY( ProcessModel::Units units READ units WRITE setUnits )
54 Q_ENUMS( ProcessFilter::State )
55 Q_ENUMS( ProcessModel::Units )
57 public:
58 KSysGuardProcessList(QWidget* parent, const QString &hostName = QString());
59 virtual ~KSysGuardProcessList();
61 QLineEdit *filterLineEdit() const;
62 QTreeView *treeView() const;
64 /** Returns which processes we are currently filtering for and the way in which we show them.
65 * @see setState()
67 ProcessFilter::State state() const;
69 /** Returns the number of milliseconds that have to elapse before updating the list of processes */
70 int updateIntervalMSecs() const;
72 /** Whether the widget will show child totals for CPU and Memory etc usage */
73 bool showTotals() const;
75 /** The units to display memory sizes etc in. E.g. kb/mb/gb */
76 ProcessModel::Units units() const;
78 /** Returns a list of the processes that have been selected by the user. */
79 QList<KSysGuard::Process *> selectedProcesses() const;
81 /** Save the current state of the widget to the given config group
83 * @param[in] cg Config group to add these settings to
84 * */
85 void saveSettings(KConfigGroup &cg);
87 /** Load the saved state of the widget from the given config group */
88 void loadSettings(const KConfigGroup &cg);
90 /** Returns the process model used. Use with caution. */
91 ProcessModel *processModel();
93 /** Restore the headings to the given state. */
94 void restoreHeaderState(const QByteArray & state);
96 public Q_SLOTS:
97 /** Inform the view that the user has changed the selection */
98 void selectionChanged();
100 /** Send a kill signal to all the processes that the user has selected. Pops up a dialog box to confirm with the user */
101 void killSelectedProcesses();
103 /** Send a signal to a list of given processes.
104 * @p pids A list of PIDs that should be sent the signal
105 * @p sig The signal to send.
106 * @return Whether the kill went ahead. True if successful or user cancelled. False if there was a problem
108 bool killProcesses(const QList< long long> &pids, int sig);
110 /** Renice all the processes that the user has selected. Pops up a dialog box to ask for the nice value and confirm */
111 void reniceSelectedProcesses();
113 /** Change the CPU scheduler for the given of processes to the given scheduler, with the given scheduler priority.
114 * If the scheduler is Other or Batch, @p newCpuSchedPriority is ignored.
115 * @return Whether the cpu scheduler changing went ahead. True if successful or user cancelled. False if there was a problem
117 bool changeCpuScheduler(const QList< long long> &pids, KSysGuard::Process::Scheduler newCpuSched, int newCpuSchedPriority);
119 /** Change the I/O scheduler for the given of processes to the given scheduler, with the given scheduler priority.
120 * If the scheduler is Other or Batch, @p newCpuSchedPriority is ignored.
121 * @return Whether the cpu scheduler changing went ahead. True if successful or user cancelled. False if there was a problem
123 bool changeIoScheduler(const QList< long long> &pids, KSysGuard::Process::IoPriorityClass newIoSched, int newIoSchedPriority);
124 /** Renice the processes given to the given niceValue.
125 * @return Whether the kill went ahead. True if successful or user cancelled. False if there was a problem
126 * */
127 bool reniceProcesses(const QList<long long> &pids, int niceValue);
129 /** Fetch new process information and redraw the display */
130 void updateList();
132 /** Set which processes we are currently filtering for and the way in which we show them. */
133 void setState(ProcessFilter::State state);
135 /** Set the number of milliseconds that have to elapse before updating the list of processes */
136 void setUpdateIntervalMSecs(int intervalMSecs);
138 /** Set whether to show child totals for CPU and Memory etc usage */
139 void setShowTotals(bool showTotals);
141 /** Focus on a particular process, and select it */
142 void selectAndJumpToProcess(int pid);
144 /** The units to display memory sizes etc in. */
145 void setUnits(ProcessModel::Units unit);
147 /** Row was just inserted in the filter model */
148 void rowsInserted ( const QModelIndex & parent, int start, int end );
150 private Q_SLOTS:
152 /** Expand all the children, recursively, of the node given. Pass an empty QModelIndex to expand all the top level children */
153 void expandAllChildren(const QModelIndex &parent);
155 /** Expand init to show its children, but not the sub children processes. */
156 void expandInit();
158 /** Display a context menu for the column headings allowing the user to show or hide columns. */
159 void showColumnContextMenu(const QPoint &point);
161 /** Display a context menu for the given process allowing the user to kill etc the process */
162 void showProcessContextMenu(const QModelIndex &index);
163 /** Display a context menu for the selected processes allowing the user to kill etc the process */
164 void showProcessContextMenu(const QPoint &point);
166 /** Handle the situation where killing a process has failed - usually due to insufficent rights */
167 void killFailed();
169 /** Handle the situation where renicing a process has failed - usually due to insufficent rights */
170 void reniceFailed();
172 /** Handle the situation where ionice'ing a process has failed - usually due to insufficent rights */
173 void ioniceFailed();
175 /** Set state from combo box int value */
176 void setStateInt(int state);
178 /** Called when the text in the gui filter text box has changed */
179 void filterTextChanged(const QString &newText);
181 /** Called when one of the actions (kill, renice etc) is clicked etc */
182 void actionTriggered(QObject *object);
183 protected:
184 /** Inherit QWidget::showEvent(QShowEvent *) to enable the timer, for updates, when visible */
185 virtual void showEvent(QShowEvent*);
187 /** Inherit QWidget::hideEvent(QShowEvent *) to disable the timer, for updates, when not visible */
188 virtual void hideEvent(QHideEvent*);
190 /** Capture any change events sent to this widget. In particular QEvent::LanguageChange */
191 virtual void changeEvent ( QEvent * event );
193 bool eventFilter(QObject *obj, QEvent *event);
195 /** Retranslate the Ui as needed */
196 void retranslateUi();
198 private:
199 KSysGuardProcessListPrivate* const d;
202 #endif