1 /*
2  * Copyright Johannes Sixt
3  * This file is licensed under the GNU General Public License Version 2.
4  * See the file COPYING in the toplevel directory of the source directory.
5  */
6 
7 #ifndef ProcAttach_included
8 #define ProcAttach_included
9 
10 #include "ui_procattachbase.h"
11 #include <QByteArray>
12 #include <QDialog>
13 #include <QLabel>
14 #include <QLineEdit>
15 #include <QPushButton>
16 #include <QVBoxLayout>
17 #include <QHBoxLayout>
18 #include <vector>
19 
20 
21 class QProcess;
22 
23 /*
24  * This is the full-featured version of the dialog. It is used when the
25  * system features a suitable ps command.
26  */
27 
28 class ProcAttachPS : public QDialog, private Ui::ProcAttachBase
29 {
30     Q_OBJECT
31 public:
32     ProcAttachPS(QWidget* parent);
33     ~ProcAttachPS();
34 
setFilterText(const QString & text)35     void setFilterText(const QString& text) { filterEdit->setText(text); }
36     QString text() const;
37 
38 protected:
39     void runPS();
40 
41 protected slots:
42     void on_buttonRefresh_clicked();
43     void on_filterEdit_textChanged(const QString& text);
44     void on_processList_currentItemChanged();
45     void slotTextReceived();
46     void slotPSDone();
47 
48 protected:
49     void pushLine();
50     bool setVisibility(QTreeWidgetItem* i, const QString& text);
51 
52     QProcess* m_ps;
53     // parse state
54     int m_pidCol;	//!< The PID column in the ps output
55     int m_ppidCol;	//!< The parent-PID column in the ps output
56     QByteArray m_token;
57     std::vector<QString> m_line;
58 };
59 
60 
61 /*
62  * This is an extremely stripped down version of the dialog. It is used
63  * when there is no suitable ps command.
64  */
65 
66 class ProcAttach : public QDialog
67 {
68 public:
69     ProcAttach(QWidget* parent);
70     virtual ~ProcAttach();
71 
setText(const QString & text)72     void setText(const QString& text) { m_processId.setText(text); }
text()73     QString text() const { return m_processId.text(); }
74 
75 protected:
76     QLabel m_label;
77     QLineEdit m_processId;
78     QPushButton m_buttonOK;
79     QPushButton m_buttonCancel;
80     QVBoxLayout m_layout;
81     QHBoxLayout m_buttons;
82 };
83 
84 #endif // ProcAttach_included
85