Commit 613b6c61 authored by Petr Štětka's avatar Petr Štětka
Browse files

Added testing dropdown of subprocess, but without real process, only as example.

parent 22b55348
......@@ -2,8 +2,8 @@ namespace Usage
{
public class ProcessorSubView : View
{
ProcessList process_list_box;
List<ProcessRow> process_row_list;
ProcessListBox process_list_box;
List<ProcessListBoxRow> process_row_list;
bool show_active_process = true;
public ProcessorSubView()
......@@ -15,7 +15,7 @@ namespace Usage
label.margin_top = 20;
label.margin_bottom = 15;
process_list_box = new ProcessList();
process_list_box = new ProcessListBox();
var cpu_graph = new CpuGraphAllCores();
var cpu_graph_frame = new Gtk.Frame(null);
......@@ -47,7 +47,7 @@ namespace Usage
add(scrolled_window);
Timeout.add(1000, update_process);
Timeout.add((GLib.Application.get_default() as Application).settings.list_update_interval, update_process);
}
//TODO better management
......@@ -55,7 +55,7 @@ namespace Usage
{
process_list_box.foreach((widget) => { widget.destroy(); });
process_row_list = new List<ProcessRow>();
process_row_list = new List<ProcessListBoxRow>();
foreach(unowned Process process in monitor.get_processes())
{
if(show_active_process)
......@@ -75,10 +75,10 @@ namespace Usage
private void insert_process_row(Process process)
{
var process_row = new ProcessRow(process.cmdline,(int) process.cpu_load);
var process_row = new ProcessListBoxRow(process.cmdline,(int) process.cpu_load);
process_row.sort_id =(int)(10 * process.cpu_load);
process_row_list.insert_sorted(process_row,(a, b) => {
return(b as ProcessRow).sort_id -(a as ProcessRow).sort_id;
return(b as ProcessListBoxRow).sort_id -(a as ProcessListBoxRow).sort_id;
});
}
......
......@@ -3,9 +3,9 @@ namespace Usage
{
public class MemorySubView : View
{
ProcessList process_list_box;
ProcessListBox process_list_box;
Gtk.Label memory_load_label;
List<ProcessRow> process_row_list;
List<ProcessListBoxRow> process_row_list;
bool show_active_process = true;
public MemorySubView()
......@@ -18,7 +18,7 @@ namespace Usage
label.margin_top = 20;
label.margin_bottom = 15;
process_list_box = new ProcessList();
process_list_box = new ProcessListBox();
var memory_graph = new MemoryGraph();
var memory_graph_frame = new Gtk.Frame(null);
......@@ -57,7 +57,7 @@ namespace Usage
process_list_box.foreach((widget) => { widget.destroy(); });
memory_load_label.set_text(((int) monitor.mem_usage).to_string() + " %");
process_row_list = new List<ProcessRow>();
process_row_list = new List<ProcessListBoxRow>();
foreach(unowned Process process in monitor.get_processes())
{
if(show_active_process)
......@@ -77,10 +77,10 @@ namespace Usage
private void insert_process_row(Process process)
{
var process_row = new ProcessRow(process.cmdline,(int) process.mem_usage);
var process_row = new ProcessListBoxRow(process.cmdline,(int) process.mem_usage);
process_row.sort_id =(int)(10 * process.mem_usage);
process_row_list.insert_sorted(process_row,(a, b) => {
return(b as ProcessRow).sort_id -(a as ProcessRow).sort_id;
return(b as ProcessListBoxRow).sort_id -(a as ProcessListBoxRow).sort_id;
});
}
......
namespace Usage
{
public class ProcessRow : Gtk.ListBoxRow
public class ProcessListBoxRow : Gtk.ListBoxRow
{
private Gtk.Image icon;
private Gtk.Label title_label;
private Gtk.Label load_label;
Gtk.Image icon;
Gtk.Label title_label;
Gtk.Label load_label;
Gtk.Revealer revealer;
Gtk.EventBox event_box;
ProcessListBox sub_process_list_box;
public int sort_id;
public bool is_headline { get; private set; }
public bool showing_details { get; private set; }
public ProcessRow(string title, int load)
public ProcessListBoxRow(string title, int load)
{
var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
box.margin = 10;
var main_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
var box_vertical = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
main_box.margin = 10;
title_label = new Gtk.Label(title);
load_label = new Gtk.Label(load.to_string() + " %");
icon = new Gtk.Image.from_icon_name("dialog-error", Gtk.IconSize.BUTTON);
icon = new Gtk.Image.from_icon_name("dialog-error", Gtk.IconSize.BUTTON); //TODO implement give icon
box.pack_start(icon, false, false, 10);
box.pack_start(title_label, false, true, 5);
box.pack_end(load_label, false, true, 10);
add(box);
main_box.pack_start(icon, false, false, 10);
main_box.pack_start(title_label, false, true, 5);
main_box.pack_end(load_label, false, true, 10);
sub_process_list_box = new ProcessListBox();
for(int i = 4; i > 0; i--)
{
var row = new ProcessDetailListBoxRow("Title " + i.to_string(), 50); //TODO realy values
sub_process_list_box.insert(row, 0);
}
revealer = new Gtk.Revealer();
revealer.add(sub_process_list_box);
event_box = new Gtk.EventBox();
event_box.add(main_box);
event_box.button_press_event.connect ((event) => {
switch_details();
return true;
});
box_vertical.pack_start(event_box, false, true, 0);
box_vertical.pack_end(revealer, false, true, 0);
add(box_vertical);
show_all();
}
private void hide_details()
{
showing_details = false;
revealer.set_reveal_child(false);
}
private void show_details()
{
showing_details = true;
revealer.set_reveal_child(true);
//TODO change color of main_box
}
private void switch_details()
{
if(showing_details)
hide_details();
else
show_details();
}
}
public class ProcessList : Gtk.ListBox
public class ProcessListBox : Gtk.ListBox
{
public ProcessList()
public ProcessListBox()
{
set_selection_mode (Gtk.SelectionMode.NONE);
set_header_func (update_header);
}
void update_header(Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row)
private void update_header(Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row)
{
if(before_row == null)
row.set_header(null);
......@@ -47,4 +93,31 @@ namespace Usage
}
}
}
public class ProcessDetailListBoxRow : Gtk.ListBoxRow
{
private Gtk.Image icon;
private Gtk.Label title_label;
private Gtk.Label load_label;
public int sort_id;
public bool is_headline { get; private set; }
public ProcessDetailListBoxRow(string title, int load)
{
var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
box.margin = 10;
title_label = new Gtk.Label(title);
load_label = new Gtk.Label(load.to_string() + " %");
icon = new Gtk.Image.from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON);
box.pack_start(icon, false, false, 10);
box.pack_start(title_label, false, true, 5);
box.pack_end(load_label, false, true, 10);
add(box);
show_all();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment