Only process updates when the view is visible
parent
a5ba4c9161
commit
3e9e4208ce
|
@ -123,6 +123,9 @@ ApplicationWindow {
|
|||
onClicked: {
|
||||
processSelection.select(index, ItemSelectionModel.ToggleCurrent);
|
||||
}
|
||||
Component.onCompleted: {
|
||||
processes.active = Qt.binding(function() { return visible; });
|
||||
}
|
||||
width: parent.width
|
||||
anchors.top: processFilterInput.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
|
@ -138,12 +141,12 @@ ApplicationWindow {
|
|||
role: "name"
|
||||
}
|
||||
TableViewColumn {
|
||||
title: "pid"
|
||||
role: "pid"
|
||||
title: "cpu"
|
||||
role: "cpuUsage"
|
||||
}
|
||||
TableViewColumn {
|
||||
title: "cpu"
|
||||
role: "cpu"
|
||||
title: "memory"
|
||||
role: "memory"
|
||||
}
|
||||
onSortIndicatorColumnChanged: sort()
|
||||
onSortIndicatorOrderChanged: sort()
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
"Processes": {
|
||||
"type": "UniformTree",
|
||||
"properties": {
|
||||
"active": {
|
||||
"type": "bool",
|
||||
"write": true
|
||||
}
|
||||
},
|
||||
"itemProperties": {
|
||||
"pid": {
|
||||
|
|
|
@ -22,7 +22,8 @@ pub struct Processes {
|
|||
emit: ProcessesEmitter,
|
||||
model: ProcessesUniformTree,
|
||||
p: ProcessTree,
|
||||
incoming: Arc<Mutex<Option<ProcessTree>>>
|
||||
incoming: Arc<Mutex<Option<ProcessTree>>>,
|
||||
active: bool
|
||||
}
|
||||
|
||||
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t,Process>) {
|
||||
|
@ -250,7 +251,8 @@ impl ProcessesTrait for Processes {
|
|||
emit: emit.clone(),
|
||||
model: model,
|
||||
p: ProcessTree::default(),
|
||||
incoming: Arc::new(Mutex::new(None))
|
||||
incoming: Arc::new(Mutex::new(None)),
|
||||
active: true
|
||||
};
|
||||
update_thread(emit, p.incoming.clone());
|
||||
p
|
||||
|
@ -276,7 +278,7 @@ impl ProcessesTrait for Processes {
|
|||
self.get(item).process.parent.map(|pid| pid as usize)
|
||||
}
|
||||
fn can_fetch_more(&self, item: Option<usize>) -> bool {
|
||||
if item.is_some() {
|
||||
if item.is_some() || !self.active {
|
||||
return false;
|
||||
}
|
||||
if let Ok(ref incoming) = self.incoming.try_lock() {
|
||||
|
@ -286,7 +288,7 @@ impl ProcessesTrait for Processes {
|
|||
}
|
||||
}
|
||||
fn fetch_more(&mut self, item: Option<usize>) {
|
||||
if item.is_some() {
|
||||
if item.is_some() || !self.active {
|
||||
return;
|
||||
}
|
||||
let new = if let Ok(ref mut incoming) = self.incoming.try_lock() {
|
||||
|
@ -334,4 +336,10 @@ impl ProcessesTrait for Processes {
|
|||
fn cmd(&self, item: usize) -> String {
|
||||
self.process(item).cmd.join(" ")
|
||||
}
|
||||
fn get_active(&self) -> bool {
|
||||
self.active
|
||||
}
|
||||
fn set_active(&mut self, active: bool) {
|
||||
self.active = active
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ pub struct ProcessesQObject {}
|
|||
#[derive (Clone)]
|
||||
pub struct ProcessesEmitter {
|
||||
qobject: Arc<Mutex<*const ProcessesQObject>>,
|
||||
active_changed: fn(*const ProcessesQObject),
|
||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
||||
}
|
||||
|
||||
|
@ -88,6 +89,12 @@ impl ProcessesEmitter {
|
|||
fn clear(&self) {
|
||||
*self.qobject.lock().unwrap() = null();
|
||||
}
|
||||
pub fn active_changed(&self) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.active_changed)(ptr);
|
||||
}
|
||||
}
|
||||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
|
@ -134,6 +141,8 @@ impl ProcessesUniformTree {
|
|||
pub trait ProcessesTrait {
|
||||
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self;
|
||||
fn emit(&self) -> &ProcessesEmitter;
|
||||
fn get_active(&self) -> bool;
|
||||
fn set_active(&mut self, value: bool);
|
||||
fn row_count(&self, Option<usize>) -> usize;
|
||||
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
||||
fn fetch_more(&mut self, Option<usize>) {}
|
||||
|
@ -152,6 +161,7 @@ pub trait ProcessesTrait {
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn processes_new(processes: *mut ProcessesQObject,
|
||||
active_changed: fn(*const ProcessesQObject),
|
||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
||||
data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||
begin_reset_model: fn(*const ProcessesQObject),
|
||||
|
@ -167,6 +177,7 @@ pub extern "C" fn processes_new(processes: *mut ProcessesQObject,
|
|||
-> *mut Processes {
|
||||
let processes_emit = ProcessesEmitter {
|
||||
qobject: Arc::new(Mutex::new(processes)),
|
||||
active_changed: active_changed,
|
||||
new_data_ready: new_data_ready,
|
||||
};
|
||||
let model = ProcessesUniformTree {
|
||||
|
@ -188,6 +199,16 @@ pub unsafe extern "C" fn processes_free(ptr: *mut Processes) {
|
|||
Box::from_raw(ptr).emit().clear();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_active_get(ptr: *const Processes) -> bool {
|
||||
(&*ptr).get_active()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_active_set(ptr: *mut Processes, v: bool) {
|
||||
(&mut *ptr).set_active(v);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_row_count(ptr: *const Processes, item: usize, valid: bool) -> c_int {
|
||||
if valid {
|
||||
|
|
|
@ -44,6 +44,10 @@ namespace {
|
|||
int row;
|
||||
quintptr id;
|
||||
};
|
||||
inline void processesActiveChanged(Processes* o)
|
||||
{
|
||||
emit o->activeChanged();
|
||||
}
|
||||
|
||||
}
|
||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||
|
@ -210,7 +214,7 @@ bool Processes::setData(const QModelIndex &index, const QVariant &value, int rol
|
|||
return set;
|
||||
}
|
||||
extern "C" {
|
||||
Processes::Private* processes_new(Processes*,
|
||||
Processes::Private* processes_new(Processes*, void (*)(Processes*),
|
||||
void (*)(const Processes*, quintptr, bool),
|
||||
void (*)(Processes*, quintptr, quintptr),
|
||||
void (*)(Processes*),
|
||||
|
@ -220,6 +224,8 @@ extern "C" {
|
|||
void (*)(Processes*, option<quintptr>, int, int),
|
||||
void (*)(Processes*));
|
||||
void processes_free(Processes::Private*);
|
||||
bool processes_active_get(const Processes::Private*);
|
||||
void processes_active_set(Processes::Private*, bool);
|
||||
};
|
||||
|
||||
Processes::Processes(bool /*owned*/, QObject *parent):
|
||||
|
@ -232,6 +238,7 @@ Processes::Processes(bool /*owned*/, QObject *parent):
|
|||
Processes::Processes(QObject *parent):
|
||||
QAbstractItemModel(parent),
|
||||
m_d(processes_new(this,
|
||||
processesActiveChanged,
|
||||
[](const Processes* o, quintptr id, bool valid) {
|
||||
if (valid) {
|
||||
int row = processes_row(o->m_d, id);
|
||||
|
@ -287,3 +294,10 @@ Processes::~Processes() {
|
|||
processes_free(m_d);
|
||||
}
|
||||
}
|
||||
bool Processes::active() const
|
||||
{
|
||||
return processes_active_get(m_d);
|
||||
}
|
||||
void Processes::setActive(bool v) {
|
||||
processes_active_set(m_d, v);
|
||||
}
|
||||
|
|
|
@ -15,10 +15,13 @@ public:
|
|||
private:
|
||||
Private * m_d;
|
||||
bool m_ownsPrivate;
|
||||
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
|
||||
explicit Processes(bool owned, QObject *parent);
|
||||
public:
|
||||
explicit Processes(QObject *parent = nullptr);
|
||||
~Processes();
|
||||
bool active() const;
|
||||
void setActive(bool v);
|
||||
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
@ -36,5 +39,6 @@ signals:
|
|||
// new data is ready to be made available to the model with fetchMore()
|
||||
void newDataReady(const QModelIndex &parent) const;
|
||||
signals:
|
||||
void activeChanged();
|
||||
};
|
||||
#endif // PROCESSES_H
|
||||
|
|
Loading…
Reference in New Issue