2019-02-28 06:57:09 -03:00
|
|
|
#include "ProcessTableView.h"
|
2019-03-22 21:42:49 -03:00
|
|
|
#include "ProcessModel.h"
|
|
|
|
|
#include <LibGUI/GSortingProxyModel.h>
|
2019-03-09 09:33:52 -03:00
|
|
|
#include <stdio.h>
|
2019-02-28 06:57:09 -03:00
|
|
|
|
2019-10-02 15:26:19 -03:00
|
|
|
ProcessTableView::ProcessTableView(GWidget* parent)
|
2019-02-28 06:57:09 -03:00
|
|
|
: GTableView(parent)
|
|
|
|
|
{
|
2019-08-09 14:32:09 -03:00
|
|
|
set_size_columns_to_fit_content(true);
|
2019-10-02 15:26:19 -03:00
|
|
|
set_model(GSortingProxyModel::create(ProcessModel::create()));
|
2019-03-22 21:42:49 -03:00
|
|
|
model()->set_key_column_and_sort_order(ProcessModel::Column::CPU, GSortOrder::Descending);
|
2019-04-17 23:38:31 -03:00
|
|
|
refresh();
|
2019-07-27 04:37:26 -03:00
|
|
|
|
|
|
|
|
on_selection = [this](auto&) {
|
|
|
|
|
if (on_process_selected)
|
|
|
|
|
on_process_selected(selected_pid());
|
|
|
|
|
};
|
2019-02-28 06:57:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessTableView::~ProcessTableView()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 23:38:31 -03:00
|
|
|
void ProcessTableView::refresh()
|
2019-02-28 06:57:09 -03:00
|
|
|
{
|
2019-03-09 22:02:37 -03:00
|
|
|
model()->update();
|
2019-02-28 06:57:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pid_t ProcessTableView::selected_pid() const
|
|
|
|
|
{
|
2019-09-07 14:59:03 -03:00
|
|
|
if (selection().is_empty())
|
2019-03-09 22:02:37 -03:00
|
|
|
return -1;
|
2019-09-07 14:59:03 -03:00
|
|
|
return model()->data(model()->index(selection().first().row(), ProcessModel::Column::PID), GModel::Role::Sort).as_int();
|
2019-02-28 06:57:09 -03:00
|
|
|
}
|