-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenFiles.cpp
More file actions
72 lines (57 loc) · 2.11 KB
/
Copy pathOpenFiles.cpp
File metadata and controls
72 lines (57 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "OpenFiles.h"
#include <QPushButton>
#include <QHeaderView>
// Assuming this is an external C function
extern "C" {
char* list_open_file(int pid);
}
extern char ** g_open_fds;
extern char ** g_open_types;
extern char ** g_open_paths;
extern int g_num_open_files;
OpenFilesWidget::OpenFilesWidget(QWidget *parent)
: QWidget(parent), layout(new QVBoxLayout(this)), table(new QTableWidget(this)) {
QPushButton *closeButton = new QPushButton("Close", this);
connect(closeButton, &QPushButton::clicked, this, &OpenFilesWidget::closeRequested);
// Call these methods on the 'table' object
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->setShowGrid(false);
layout->addWidget(table);
layout->addWidget(closeButton);
}
void OpenFilesWidget::setProcessPID(int pid) {
processPid = pid;
updateOpenFiles();
}
void OpenFilesWidget::clearContent() {
table->clearContents();
table->setRowCount(0);
}
void OpenFilesWidget::updateOpenFiles() {
clearContent();
table->setColumnCount(3);
QStringList headers;
headers << "FD" << "Type" << "Object";
table->setHorizontalHeaderLabels(headers);
char *lst = list_open_file(processPid);
int num_open = parse_list(lst); // Assuming this function populates the global arrays
for (int i = 0; i < num_open; i++) {
int row = table->rowCount();
table->insertRow(row);
table->setItem(row, 0, new QTableWidgetItem(QString::fromUtf8(g_open_fds[i])));
table->setItem(row, 1, new QTableWidgetItem(QString::fromUtf8(g_open_types[i])));
table->setItem(row, 2, new QTableWidgetItem(QString::fromUtf8(g_open_paths[i])));
// Free each string in the arrays
free(g_open_fds[i]);
free(g_open_types[i]);
free(g_open_paths[i]);
}
// Free the arrays themselves
free(g_open_fds);
free(g_open_types);
free(g_open_paths);
// Free the memory allocated by list_open_file
free(lst);
}