2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-10 22:28:48 +03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-08-03 09:26:04 +03:00
|
|
|
#include "ProcessFileDescriptorMapWidget.h"
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/JsonArrayModel.h>
|
2020-09-22 01:40:57 +03:00
|
|
|
#include <LibGUI/SortingProxyModel.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/TableView.h>
|
2019-08-03 09:26:04 +03:00
|
|
|
|
2020-02-23 14:07:13 +03:00
|
|
|
ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget()
|
2019-08-03 09:26:04 +03:00
|
|
|
{
|
2020-03-04 11:43:54 +03:00
|
|
|
set_layout<GUI::VerticalBoxLayout>();
|
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
2021-08-17 03:11:38 +03:00
|
|
|
layout()->set_margins(4);
|
2020-02-23 14:07:13 +03:00
|
|
|
m_table_view = add<GUI::TableView>();
|
2019-08-10 12:07:55 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
Vector<GUI::JsonArrayModel::FieldSpec> pid_fds_fields;
|
2020-02-06 13:56:38 +03:00
|
|
|
pid_fds_fields.empend("fd", "FD", Gfx::TextAlignment::CenterRight);
|
|
|
|
pid_fds_fields.empend("class", "Class", Gfx::TextAlignment::CenterLeft);
|
|
|
|
pid_fds_fields.empend("offset", "Offset", Gfx::TextAlignment::CenterRight);
|
|
|
|
pid_fds_fields.empend("absolute_path", "Path", Gfx::TextAlignment::CenterLeft);
|
|
|
|
pid_fds_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2019-08-10 16:06:29 +03:00
|
|
|
return object.get("seekable").to_bool() ? "Seekable" : "Sequential";
|
2019-08-10 12:07:55 +03:00
|
|
|
});
|
2020-02-06 13:56:38 +03:00
|
|
|
pid_fds_fields.empend("Blocking", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2019-09-28 23:01:10 +03:00
|
|
|
return object.get("blocking").to_bool() ? "Blocking" : "Nonblocking";
|
|
|
|
});
|
2020-02-06 13:56:38 +03:00
|
|
|
pid_fds_fields.empend("On exec", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2019-09-28 23:01:10 +03:00
|
|
|
return object.get("cloexec").to_bool() ? "Close" : "Keep";
|
|
|
|
});
|
2020-02-06 13:56:38 +03:00
|
|
|
pid_fds_fields.empend("Can read", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2019-11-10 00:15:35 +03:00
|
|
|
return object.get("can_read").to_bool() ? "Yes" : "No";
|
|
|
|
});
|
2020-02-06 13:56:38 +03:00
|
|
|
pid_fds_fields.empend("Can write", Gfx::TextAlignment::CenterLeft, [](auto& object) {
|
2019-11-10 00:15:35 +03:00
|
|
|
return object.get("can_write").to_bool() ? "Yes" : "No";
|
|
|
|
});
|
2019-08-10 12:07:55 +03:00
|
|
|
|
2020-09-22 01:40:57 +03:00
|
|
|
m_model = GUI::JsonArrayModel::create({}, move(pid_fds_fields));
|
2021-12-24 15:12:04 +03:00
|
|
|
m_table_view->set_model(MUST(GUI::SortingProxyModel::create(*m_model)));
|
2019-08-03 09:26:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessFileDescriptorMapWidget::set_pid(pid_t pid)
|
|
|
|
{
|
|
|
|
if (m_pid == pid)
|
|
|
|
return;
|
|
|
|
m_pid = pid;
|
2020-10-06 19:04:36 +03:00
|
|
|
m_model->set_json_path(String::formatted("/proc/{}/fds", m_pid));
|
2019-08-03 09:26:04 +03:00
|
|
|
}
|