-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathProcessTreeView.vala
More file actions
197 lines (168 loc) · 7.46 KB
/
Copy pathProcessTreeView.vala
File metadata and controls
197 lines (168 loc) · 7.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2026 elementary, Inc. (https://elementary.io)
*/
public class Monitor.ProcessTreeView : Granite.Bin {
public ProcessTreeView (TreeViewModel model) {
var column_view = new Gtk.ColumnView (model.selection_model) {
name = "monitor-process-column-view",
reorderable = false,
hexpand = true,
vexpand = true
};
model.sorter = column_view.sorter;
var name_item_factory = new Gtk.SignalListItemFactory ();
name_item_factory.setup.connect (name_item_factory_setup);
name_item_factory.bind.connect (name_item_factory_bind);
name_item_factory.unbind.connect (name_item_factory_unbind);
var cpu_item_factory = new Gtk.SignalListItemFactory ();
cpu_item_factory.setup.connect (generic_item_factory_setup);
cpu_item_factory.bind.connect (cpu_item_factory_bind);
cpu_item_factory.unbind.connect (cpu_item_factory_unbind);
var memory_item_factory = new Gtk.SignalListItemFactory ();
memory_item_factory.setup.connect (generic_item_factory_setup);
memory_item_factory.bind.connect (memory_item_factory_bind);
memory_item_factory.unbind.connect (memory_item_factory_unbind);
var gpu_item_factory = new Gtk.SignalListItemFactory ();
gpu_item_factory.setup.connect (generic_item_factory_setup);
gpu_item_factory.bind.connect (gpu_item_factory_bind);
gpu_item_factory.unbind.connect (gpu_item_factory_unbind);
var pid_item_factory = new Gtk.SignalListItemFactory ();
pid_item_factory.setup.connect (generic_item_factory_setup);
pid_item_factory.bind.connect (pid_item_factory_bind);
pid_item_factory.unbind.connect (pid_item_factory_unbind);
var name_column = new Gtk.ColumnViewColumn (_("Process Name"), name_item_factory) {
sorter = model.str_sorter ("name"),
expand = true
};
column_view.append_column (name_column);
var cpu_column = new Gtk.ColumnViewColumn (_("CPU"), cpu_item_factory) {
sorter = model.num_sorter ("cpu"),
expand = false
};
column_view.append_column (cpu_column);
var mem_column = new Gtk.ColumnViewColumn (_("Memory"), memory_item_factory) {
sorter = model.num_sorter ("memory"),
expand = false
};
column_view.append_column (mem_column);
var gpu_column = new Gtk.ColumnViewColumn (_("GPU"), gpu_item_factory) {
sorter = model.num_sorter ("gpu"),
expand = false
};
column_view.append_column (gpu_column);
var pid_column = new Gtk.ColumnViewColumn (_("PID"), pid_item_factory) {
sorter = model.num_sorter ("pid"),
expand = false
};
column_view.append_column (pid_column);
var scrolled_window = new Gtk.ScrolledWindow () {
child = column_view
};
child = scrolled_window;
}
private void generic_item_factory_setup (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = new Gtk.Label (Utils.NO_DATA) {
hexpand = true,
halign = START
};
cell.child = label;
}
private void name_item_factory_setup (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var name_cell = new ProcessTreeViewNameCell ();
cell.child = name_cell;
}
private void name_item_factory_bind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var name_cell = (ProcessTreeViewNameCell) cell.child;
var label = name_cell.label;
var icon = name_cell.icon;
var item = (ProcessRowData) cell.item;
var binding_name = item.bind_property ("name", label, "label", SYNC_CREATE);
item.bindings.set ("name", binding_name);
var binding_icon = item.bind_property ("icon", icon, "gicon", SYNC_CREATE);
item.bindings.set ("icon", binding_icon);
}
private void name_item_factory_unbind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var name_cell = (ProcessTreeViewNameCell) cell.child;
var label = name_cell.label;
var icon = name_cell.icon;
label.label = null;
icon.gicon = null;
((ProcessRowData) cell.item).bindings["name"].unbind ();
((ProcessRowData) cell.item).bindings["icon"].unbind ();
}
private void cpu_item_factory_bind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_cpu = item.bind_property ("cpu", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
int percentage = from_val.get_int ();
to_val.set_string ("%.0f%%".printf (percentage));
return true;
});
item.bindings.set ("cpu", binding_cpu);
}
private void cpu_item_factory_unbind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
label.label = null;
item.bindings["cpu"].unbind ();
}
private void memory_item_factory_bind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_memory = item.bind_property ("memory", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
to_val.set_string (format_size (from_val.get_uint64 () * 1024, IEC_UNITS));
return true;
});
item.bindings.set ("memory", binding_memory);
}
private void memory_item_factory_unbind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
label.label = null;
item.bindings["memory"].unbind ();
}
private void gpu_item_factory_bind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_gpu = item.bind_property ("gpu", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
int percentage = from_val.get_int ();
to_val.set_string ("%.0f%%".printf (percentage));
return true;
});
item.bindings.set ("gpu", binding_gpu);
}
private void gpu_item_factory_unbind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
label.label = null;
item.bindings["gpu"].unbind ();
}
private void pid_item_factory_bind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
var binding_pid = item.bind_property ("pid", label, "label", SYNC_CREATE, (_, from_val, ref to_val) => {
to_val.set_string ("%d".printf (from_val.get_int ()));
return true;
});
item.bindings.set ("pid", binding_pid);
}
private void pid_item_factory_unbind (Object object) {
var cell = (Gtk.ColumnViewCell) object;
var label = (Gtk.Label) cell.child;
var item = (ProcessRowData) cell.item;
label.label = null;
item.bindings["pid"].unbind ();
}
}