File indexing completed on 2024-05-05 09:51:28
0001 /* 0002 KSysGuard, the KDE System Guard 0003 0004 SPDX-FileCopyrightText: 1999, 2000 Chris Schlaeger <cs@kde.org> 0005 SPDX-FileCopyrightText: 2006 John Tapsell <john.tapsell@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 0009 */ 0010 0011 #ifndef _KSysGuardProcessList_h_ 0012 #define _KSysGuardProcessList_h_ 0013 0014 #include <QMetaType> 0015 #include <QWidget> 0016 0017 #include <KConfigGroup> 0018 0019 #include "ProcessFilter.h" 0020 #include "ProcessModel.h" 0021 #include <processcore/processes.h> 0022 0023 #include "processui_export.h" 0024 0025 class QShowEvent; 0026 class QHideEvent; 0027 class QLineEdit; 0028 class QTreeView; 0029 struct KSysGuardProcessListPrivate; 0030 0031 /** 0032 * This widget implements a process list page. Besides the process 0033 * list which is implemented as a ProcessList, it contains two 0034 * combo boxes and two buttons. The combo boxes are used to set the 0035 * update rate and the process filter. The buttons are used to force 0036 * an immediate update and to kill a process. 0037 */ 0038 class PROCESSUI_EXPORT KSysGuardProcessList : public QWidget 0039 { 0040 Q_OBJECT 0041 Q_PROPERTY(bool showTotalsInTree READ showTotals WRITE setShowTotals) 0042 Q_PROPERTY(ProcessFilter::State state READ state WRITE setState) 0043 Q_PROPERTY(int updateIntervalMSecs READ updateIntervalMSecs WRITE setUpdateIntervalMSecs) 0044 Q_PROPERTY(ProcessModel::Units units READ units WRITE setUnits) 0045 Q_PROPERTY(bool killButtonVisible READ isKillButtonVisible WRITE setKillButtonVisible) 0046 Q_PROPERTY(bool scriptingEnabled READ scriptingEnabled WRITE setScriptingEnabled) 0047 Q_ENUMS(ProcessFilter::State) 0048 Q_ENUMS(ProcessModel::Units) 0049 0050 public: 0051 explicit KSysGuardProcessList(QWidget *parent = nullptr, const QString &hostName = QString()); 0052 ~KSysGuardProcessList() override; 0053 0054 QLineEdit *filterLineEdit() const; 0055 QTreeView *treeView() const; 0056 0057 /** Returns which processes we are currently filtering for and the way in which we show them. 0058 * @see setState() 0059 */ 0060 ProcessFilter::State state() const; 0061 0062 /** Returns the number of milliseconds that have to elapse before updating the list of processes. 0063 * If this is 0, the processes will not be automatically updated. */ 0064 int updateIntervalMSecs() const; 0065 0066 /** Whether the widget will show child totals for CPU and Memory etc usage */ 0067 bool showTotals() const; 0068 0069 /** The units to display memory sizes etc in. E.g. kb/mb/gb */ 0070 ProcessModel::Units units() const; 0071 0072 /** Returns a list of the processes that have been selected by the user. */ 0073 QList<KSysGuard::Process *> selectedProcesses() const; 0074 0075 /** Returns the number of processes currently being displayed 0076 * 0077 * To get the total number processes, visible or not, use processModel()-> 0078 * */ 0079 int visibleProcessesCount() const; 0080 0081 /** Save the current state of the widget to the given config group 0082 * 0083 * @param[in] cg Config group to add these settings to 0084 * */ 0085 void saveSettings(KConfigGroup &cg); 0086 0087 /** Load the saved state of the widget from the given config group */ 0088 void loadSettings(const KConfigGroup &cg); 0089 0090 /** Returns the process model used. Use with caution. */ 0091 ProcessModel *processModel(); 0092 0093 /** Restore the headings to the given state. */ 0094 void restoreHeaderState(const QByteArray &state); 0095 0096 /** @returns whether the Kill Process button is visible. */ 0097 bool isKillButtonVisible() const; 0098 0099 /** @param visible defines whether the Kill Process button is shown or not. */ 0100 void setKillButtonVisible(bool visible); 0101 0102 /** Whether scripting support is enabled. 0103 * 0104 * Default is false. */ 0105 bool scriptingEnabled() const; 0106 /** Set whether scripting support is enabled. 0107 * 0108 * Default is false. */ 0109 void setScriptingEnabled(bool enabled); 0110 0111 Q_SIGNALS: 0112 /** Emitted when the display has been updated */ 0113 void updated(); 0114 void processListChanged(); 0115 0116 public Q_SLOTS: 0117 /** Inform the view that the user has changed the selection */ 0118 void selectionChanged(); 0119 0120 /** Send a kill signal to all the processes that the user has selected. Pops up a dialog box to confirm with the user */ 0121 void killSelectedProcesses(); 0122 0123 /** Send a signal to all the processes that the user has selected. 0124 * @p confirm - If true, pops up a dialog box to confirm with the user 0125 */ 0126 void sendSignalToSelectedProcesses(int sig, bool confirm); 0127 0128 /** Send a signal to a list of given processes. 0129 * @p pids A list of PIDs that should be sent the signal 0130 * @p sig The signal to send. 0131 * @return Whether the kill went ahead. True if successful or user cancelled. False if there was a problem 0132 */ 0133 bool killProcesses(const QList<long long> &pids, int sig); 0134 0135 /** Renice all the processes that the user has selected. Pops up a dialog box to ask for the nice value and confirm */ 0136 void reniceSelectedProcesses(); 0137 0138 /** Change the CPU scheduler for the given of processes to the given scheduler, with the given scheduler priority. 0139 * If the scheduler is Other or Batch, @p newCpuSchedPriority is ignored. 0140 * @return Whether the cpu scheduler changing went ahead. True if successful or user cancelled. False if there was a problem 0141 */ 0142 bool changeCpuScheduler(const QList<long long> &pids, KSysGuard::Process::Scheduler newCpuSched, int newCpuSchedPriority); 0143 0144 /** Change the I/O scheduler for the given of processes to the given scheduler, with the given scheduler priority. 0145 * If the scheduler is Other or Batch, @p newCpuSchedPriority is ignored. 0146 * @return Whether the cpu scheduler changing went ahead. True if successful or user cancelled. False if there was a problem 0147 */ 0148 bool changeIoScheduler(const QList<long long> &pids, KSysGuard::Process::IoPriorityClass newIoSched, int newIoSchedPriority); 0149 /** Renice the processes given to the given niceValue. 0150 * @return Whether the kill went ahead. True if successful or user cancelled. False if there was a problem 0151 * */ 0152 bool reniceProcesses(const QList<long long> &pids, int niceValue); 0153 0154 /** Fetch new process information and redraw the display */ 0155 void updateList(); 0156 0157 /** Set which processes we are currently filtering for and the way in which we show them. */ 0158 void setState(ProcessFilter::State state); 0159 0160 /** Set the number of milliseconds that have to elapse before updating the list of processes. 0161 * If this is set to 0, the process list will not be automatically updated and the owner can call 0162 * updateList() manually. */ 0163 void setUpdateIntervalMSecs(int intervalMSecs); 0164 0165 /** Set whether to show child totals for CPU and Memory etc usage */ 0166 void setShowTotals(bool showTotals); 0167 0168 /** Focus on a particular process, and select it */ 0169 void selectAndJumpToProcess(int pid); 0170 0171 /** The units to display memory sizes etc in. */ 0172 void setUnits(ProcessModel::Units unit); 0173 0174 /** Row was just inserted in the filter model */ 0175 void rowsInserted(const QModelIndex &parent, int start, int end); 0176 0177 private Q_SLOTS: 0178 /** Expand all the children, recursively, of the node given. Pass an empty QModelIndex to expand all the top level children */ 0179 void expandAllChildren(const QModelIndex &parent); 0180 0181 /** Expand init to show its children, but not the sub children processes. */ 0182 void expandInit(); 0183 0184 /** Display a context menu for the column headings allowing the user to show or hide columns. */ 0185 void showColumnContextMenu(const QPoint &point); 0186 0187 /** Display a context menu for the given process allowing the user to kill etc the process */ 0188 void showProcessContextMenu(const QModelIndex &index); 0189 0190 /** Display a context menu for the selected processes allowing the user to kill etc the process */ 0191 void showProcessContextMenu(const QPoint &point); 0192 0193 /** Set state from combo box int value */ 0194 void setStateInt(int state); 0195 0196 /** Called when the text in the gui filter text box has changed */ 0197 void filterTextChanged(const QString &newText); 0198 0199 /** Called when one of the actions (kill, renice etc) is clicked etc */ 0200 void actionTriggered(QObject *object); 0201 0202 protected: 0203 /** Inherit QWidget::showEvent(QShowEvent *) to enable the timer, for updates, when visible */ 0204 void showEvent(QShowEvent *) override; 0205 0206 /** Inherit QWidget::hideEvent(QShowEvent *) to disable the timer, for updates, when not visible */ 0207 void hideEvent(QHideEvent *) override; 0208 0209 /** Capture any change events sent to this widget. In particular QEvent::LanguageChange */ 0210 void changeEvent(QEvent *event) override; 0211 0212 bool eventFilter(QObject *obj, QEvent *event) override; 0213 0214 /** Retranslate the Ui as needed */ 0215 void retranslateUi(); 0216 0217 private: 0218 KSysGuardProcessListPrivate *const d; 0219 }; 0220 0221 Q_DECLARE_METATYPE(long long) 0222 Q_DECLARE_METATYPE(QList<long long>) 0223 0224 #endif