Warning, file /plasma/libksysguard/processui/ksysguardprocesslist.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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