mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:07:34 +00:00
SystemMonitor: Remove "Devices" tab
This was crowding up the GUI without providing anything useful.
This commit is contained in:
parent
a401a0f8fe
commit
9994b81931
4 changed files with 0 additions and 252 deletions
|
@ -5,7 +5,6 @@ serenity_component(
|
|||
)
|
||||
|
||||
set(SOURCES
|
||||
DevicesModel.cpp
|
||||
GraphWidget.cpp
|
||||
InterruptsWidget.cpp
|
||||
main.cpp
|
||||
|
|
|
@ -1,177 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "DevicesModel.h"
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
NonnullRefPtr<DevicesModel> DevicesModel::create()
|
||||
{
|
||||
return adopt_ref(*new DevicesModel);
|
||||
}
|
||||
|
||||
DevicesModel::DevicesModel()
|
||||
{
|
||||
}
|
||||
|
||||
DevicesModel::~DevicesModel()
|
||||
{
|
||||
}
|
||||
|
||||
int DevicesModel::row_count(const GUI::ModelIndex&) const
|
||||
{
|
||||
return m_devices.size();
|
||||
}
|
||||
|
||||
int DevicesModel::column_count(const GUI::ModelIndex&) const
|
||||
{
|
||||
return Column::__Count;
|
||||
}
|
||||
|
||||
String DevicesModel::column_name(int column) const
|
||||
{
|
||||
switch (column) {
|
||||
case Column::Device:
|
||||
return "Device";
|
||||
case Column::Major:
|
||||
return "Major";
|
||||
case Column::Minor:
|
||||
return "Minor";
|
||||
case Column::ClassName:
|
||||
return "Class";
|
||||
case Column::Type:
|
||||
return "Type";
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
VERIFY(is_within_range(index));
|
||||
|
||||
if (role == GUI::ModelRole::TextAlignment) {
|
||||
switch (index.column()) {
|
||||
case Column::Device:
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
case Column::Major:
|
||||
return Gfx::TextAlignment::CenterRight;
|
||||
case Column::Minor:
|
||||
return Gfx::TextAlignment::CenterRight;
|
||||
case Column::ClassName:
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
case Column::Type:
|
||||
return Gfx::TextAlignment::CenterLeft;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
if (role == GUI::ModelRole::Sort) {
|
||||
const DeviceInfo& device = m_devices[index.row()];
|
||||
switch (index.column()) {
|
||||
case Column::Device:
|
||||
return device.path;
|
||||
case Column::Major:
|
||||
return device.major;
|
||||
case Column::Minor:
|
||||
return device.minor;
|
||||
case Column::ClassName:
|
||||
return device.class_name;
|
||||
case Column::Type:
|
||||
return device.type;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
const DeviceInfo& device = m_devices[index.row()];
|
||||
switch (index.column()) {
|
||||
case Column::Device:
|
||||
return device.path;
|
||||
case Column::Major:
|
||||
return device.major;
|
||||
case Column::Minor:
|
||||
return device.minor;
|
||||
case Column::ClassName:
|
||||
return device.class_name;
|
||||
case Column::Type:
|
||||
switch (device.type) {
|
||||
case DeviceInfo::Type::Block:
|
||||
return "Block";
|
||||
case DeviceInfo::Type::Character:
|
||||
return "Character";
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void DevicesModel::invalidate()
|
||||
{
|
||||
// FIXME: granularly update this.
|
||||
auto proc_devices = Core::File::construct("/proc/devices");
|
||||
if (!proc_devices->open(Core::OpenMode::ReadOnly))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto json = JsonValue::from_string(proc_devices->read_all());
|
||||
VERIFY(json.has_value());
|
||||
|
||||
m_devices.clear();
|
||||
json.value().as_array().for_each([this](auto& value) {
|
||||
JsonObject device = value.as_object();
|
||||
DeviceInfo device_info;
|
||||
|
||||
device_info.major = device.get("major").to_uint();
|
||||
device_info.minor = device.get("minor").to_uint();
|
||||
device_info.class_name = device.get("class_name").to_string();
|
||||
|
||||
String type_str = device.get("type").to_string();
|
||||
if (type_str == "block")
|
||||
device_info.type = DeviceInfo::Type::Block;
|
||||
else if (type_str == "character")
|
||||
device_info.type = DeviceInfo::Type::Character;
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
m_devices.append(move(device_info));
|
||||
});
|
||||
|
||||
auto fill_in_paths_from_dir = [this](const String& dir) {
|
||||
Core::DirIterator dir_iter { dir, Core::DirIterator::Flags::SkipDots };
|
||||
while (dir_iter.has_next()) {
|
||||
auto path = dir_iter.next_full_path();
|
||||
struct stat statbuf;
|
||||
if (lstat(path.characters(), &statbuf) != 0) {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
if (!S_ISBLK(statbuf.st_mode) && !S_ISCHR(statbuf.st_mode))
|
||||
continue;
|
||||
unsigned _major = major(statbuf.st_rdev);
|
||||
unsigned _minor = minor(statbuf.st_rdev);
|
||||
|
||||
auto it = m_devices.find_if([_major, _minor](const auto& device_info) {
|
||||
return device_info.major == _major && device_info.minor == _minor;
|
||||
});
|
||||
if (it != m_devices.end()) {
|
||||
(*it).path = move(path);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fill_in_paths_from_dir("/dev");
|
||||
fill_in_paths_from_dir("/dev/pts");
|
||||
|
||||
Model::invalidate();
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Model.h>
|
||||
|
||||
class DevicesModel final : public GUI::Model {
|
||||
public:
|
||||
enum Column {
|
||||
Device = 0,
|
||||
Major,
|
||||
Minor,
|
||||
ClassName,
|
||||
Type,
|
||||
__Count
|
||||
};
|
||||
|
||||
virtual ~DevicesModel() override;
|
||||
static NonnullRefPtr<DevicesModel> create();
|
||||
|
||||
virtual int row_count(const GUI::ModelIndex&) const override;
|
||||
virtual int column_count(const GUI::ModelIndex&) const override;
|
||||
virtual String column_name(int column) const override;
|
||||
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
|
||||
|
||||
// FIXME: This should be moved to granularly updating itself.
|
||||
virtual void invalidate() override;
|
||||
|
||||
private:
|
||||
DevicesModel();
|
||||
|
||||
struct DeviceInfo {
|
||||
String path;
|
||||
unsigned major;
|
||||
unsigned minor;
|
||||
String class_name;
|
||||
enum Type {
|
||||
Block,
|
||||
Character
|
||||
};
|
||||
Type type;
|
||||
};
|
||||
|
||||
Vector<DeviceInfo> m_devices;
|
||||
};
|
|
@ -4,7 +4,6 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "DevicesModel.h"
|
||||
#include "GraphWidget.h"
|
||||
#include "InterruptsWidget.h"
|
||||
#include "MemoryStatsWidget.h"
|
||||
|
@ -51,7 +50,6 @@
|
|||
static NonnullRefPtr<GUI::Window> build_process_window(pid_t);
|
||||
static NonnullRefPtr<GUI::Widget> build_file_systems_tab();
|
||||
static NonnullRefPtr<GUI::Widget> build_pci_devices_tab();
|
||||
static NonnullRefPtr<GUI::Widget> build_devices_tab();
|
||||
static NonnullRefPtr<GUI::Widget> build_graphs_tab();
|
||||
static NonnullRefPtr<GUI::Widget> build_processors_tab();
|
||||
|
||||
|
@ -201,9 +199,6 @@ int main(int argc, char** argv)
|
|||
auto pci_devices_widget = build_pci_devices_tab();
|
||||
tabwidget.add_widget("PCI devices", pci_devices_widget);
|
||||
|
||||
auto devices_widget = build_devices_tab();
|
||||
tabwidget.add_widget("Devices", devices_widget);
|
||||
|
||||
auto network_stats_widget = NetworkStatisticsWidget::construct();
|
||||
tabwidget.add_widget("Network", network_stats_widget);
|
||||
|
||||
|
@ -391,8 +386,6 @@ int main(int argc, char** argv)
|
|||
tabwidget.set_active_widget(file_systems_widget);
|
||||
else if (args_tab_view == "pci")
|
||||
tabwidget.set_active_widget(pci_devices_widget);
|
||||
else if (args_tab_view == "devices")
|
||||
tabwidget.set_active_widget(devices_widget);
|
||||
else if (args_tab_view == "network")
|
||||
tabwidget.set_active_widget(network_stats_widget);
|
||||
else if (args_tab_view == "processors")
|
||||
|
@ -642,22 +635,6 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab()
|
|||
return pci_widget;
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Widget> build_devices_tab()
|
||||
{
|
||||
auto devices_widget = GUI::LazyWidget::construct();
|
||||
|
||||
devices_widget->on_first_show = [](GUI::LazyWidget& self) {
|
||||
self.set_layout<GUI::VerticalBoxLayout>();
|
||||
self.layout()->set_margins(4);
|
||||
|
||||
auto& devices_table_view = self.add<GUI::TableView>();
|
||||
devices_table_view.set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
|
||||
devices_table_view.model()->invalidate();
|
||||
};
|
||||
|
||||
return devices_widget;
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Widget> build_graphs_tab()
|
||||
{
|
||||
auto graphs_container = GUI::Widget::construct();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue