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

Fixed process list box.

Added process dialog.
parent a1a6f0ad
......@@ -39,6 +39,7 @@ c_library: gtop-2.0 ${CMAKE_SOURCE_DIR}/external/rg/librg.a ${CMAKE_SOURCE_DIR}/
*vala_source: network-sub-view.vala
*vala_source: performance-view.vala
*vala_source: power-view.vala
*vala_source: process-dialog.vala
*vala_source: process-list-box.vala
*vala_source: process-row.vala
*vala_source: settings.vala
......@@ -59,7 +60,7 @@ h_folder: /usr/include/libgtop-2.0
translate: c src/better-box.c
*translate: vala src/cpu-graph-table.vala
*translate: vala src/process-row.vala
*translate: vala src/process-dialog.vala
*translate: vala src/application.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/header-bar.vala
......@@ -78,9 +79,10 @@ translate: c src/better-box.c
*translate: vala src/sub-process-list-box.vala
*translate: vala src/memory-graph.vala
*translate: vala src/process-list-box.vala
*translate: vala src/sub-process-sub-row.vala
*translate: vala src/process-row.vala
*translate: vala src/settings.vala
*translate: vala src/storage-view.vala
*translate: vala src/sub-process-sub-row.vala
*translate: vala src/power-view.vala
*translate: vala src/data-view.vala
......
......@@ -14,6 +14,7 @@ src/memory-sub-view.vala
src/network-sub-view.vala
src/performance-view.vala
src/power-view.vala
src/process-dialog.vala
src/process-list-box.vala
src/process-row.vala
src/settings.vala
......
......@@ -52,6 +52,7 @@ set (APP_SOURCES ${APP_SOURCES} memory-sub-view.vala)
set (APP_SOURCES ${APP_SOURCES} network-sub-view.vala)
set (APP_SOURCES ${APP_SOURCES} performance-view.vala)
set (APP_SOURCES ${APP_SOURCES} power-view.vala)
set (APP_SOURCES ${APP_SOURCES} process-dialog.vala)
set (APP_SOURCES ${APP_SOURCES} process-list-box.vala)
set (APP_SOURCES ${APP_SOURCES} process-row.vala)
set (APP_SOURCES ${APP_SOURCES} settings.vala)
......
namespace Usage
{
public class ProcessDialog : Gtk.Dialog
{
private Gtk.Widget kill_button;
public ProcessDialog()
{
Object(use_header_bar: 1);
this.title = "Process";
this.border_width = 5;
set_default_size (350, 100);
create_widgets();
connect_signals();
}
private void create_widgets()
{
Gtk.Box content = get_content_area() as Gtk.Box;
content.spacing = 10;
add_button (_("Stop"), Gtk.ResponseType.HELP).get_style_context().add_class ("destructive-action");
}
private void connect_signals()
{
this.response.connect (on_response);
}
private void on_response(Gtk.Dialog source, int response_id)
{
switch(response_id)
{
case Gtk.ResponseType.HELP:
destroy();
break;
case Gtk.ResponseType.CLOSE:
destroy();
break;
}
}
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@ namespace Usage
public class ProcessListBox : Gtk.Box
{
private Gee.ArrayList<ProcessRow> rows;
HashTable<string, ProcessRow> process_rows_table;
public ProcessListBox()
......@@ -28,7 +27,6 @@ namespace Usage
row.pre_update();
var duplicates = new HashSet<string>();
int stress = 0;
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_processes())
{
......
......@@ -49,6 +49,12 @@ namespace Usage
event_box.button_press_event.connect ((event) => {
if(group)
switch_details();
else
{
var dialog = new ProcessDialog();
dialog.show_all ();
}
return false;
});
......@@ -142,18 +148,25 @@ namespace Usage
return value;
}
public void set_value(uint pid, int value)//TODO rename to set_value?
public void set_value(uint pid, int value)
{
alive = true;
if(!group)
this.value = int.min(value, 100);
if(sub_process_list_box.is_in_table(pid))
sub_process_list_box.update_sub_row(pid, value);
else
{
if(sub_process_list_box.is_in_table(pid))
sub_process_list_box.update_sub_row(pid, value);
if(group)
sub_process_list_box.add_sub_row(pid, value, name);
else
sub_process_list_box.add_sub_row(pid, value, this.name);
}
{
if(pid == this.pid)
this.value = int.min(value, 100);
else
{
this.pid = pid;
this.value = int.min(value, 100);
}
}
}
private void update()
......
......@@ -3,113 +3,107 @@ using Gee;
namespace Usage
{
public class SubProcessListBox : Gtk.Box
{
private Gee.ArrayList<SubProcessSubRow> sub_rows;
HashTable<uint, SubProcessSubRow> process_sub_rows_table;
public SubProcessListBox()
{
orientation = Gtk.Orientation.VERTICAL;
sub_rows = new Gee.ArrayList<SubProcessSubRow>();
process_sub_rows_table = new HashTable<uint, SubProcessSubRow>(direct_hash, direct_equal);
}
public string get_first_name()
{
return sub_rows[0].get_name();
}
public uint get_first_pid()
{
return sub_rows[0].get_pid();
}
public int get_first_value()
{
return sub_rows[0].get_value();
}
public uint get_sub_rows_count()
{
return sub_rows.size;
}
public bool is_in_table(uint pid)
{
return (pid in process_sub_rows_table);
}
public void pre_update()
{
foreach(SubProcessSubRow sub_row in sub_rows)
sub_row.set_alive(false);
}
public void post_update()
{
sort();
this.forall ((element) => this.remove (element)); //clear box
foreach(unowned SubProcessSubRow sub_row in process_sub_rows_table.get_values())
{
sub_row.update();
if(sub_row.get_alive() == false)
{
process_sub_rows_table.remove(sub_row.get_pid());
sub_rows.remove(sub_row);
}
}
for(int i = 0; i < sub_rows.size; i++)
if(sub_rows[i].get_alive())
this.add(sub_rows[i]);
}
public void add_sub_row(uint pid, int value, string name)
{
SubProcessSubRow sub_row = new SubProcessSubRow(pid, value, name);
sub_rows.add(sub_row);
process_sub_rows_table.insert (pid, sub_row);
}
public void update_sub_row(uint pid, int value)
{
unowned SubProcessSubRow sub_row = process_sub_rows_table[pid];
sub_row.set_value(value);
}
public void remove_all()
{
this.forall ((element) => this.remove (element)); //clear box
process_sub_rows_table.remove_all();
sub_rows.clear();
}
public Gee.ArrayList<int> get_values()
{
var list = new Gee.ArrayList<int>();
foreach(SubProcessSubRow sub_row in sub_rows)
list.add(sub_row.get_value());
return list;
}
public int get_values_sum()
{
int sum = 0;
foreach(SubProcessSubRow sub_row in sub_rows)
sum += sub_row.get_value();
return sum;
}
private void sort()
{
sub_rows.sort((a, b) => {
return(b as SubProcessSubRow).get_value() - ( a as SubProcessSubRow).get_value();
});
}
}
{
HashTable<int?, SubProcessSubRow> process_sub_rows_table;
public SubProcessListBox()
{
orientation = Gtk.Orientation.VERTICAL;
process_sub_rows_table = new HashTable<int?, SubProcessSubRow>(int_hash, int_equal);
}
public string get_first_name()
{
return process_sub_rows_table.get_values().nth_data(0).get_name();
}
public uint get_first_pid()
{
return process_sub_rows_table.get_values().nth_data(0).get_pid();
}
public int get_first_value()
{
return process_sub_rows_table.get_values().nth_data(0).get_value();
}
public uint get_sub_rows_count()
{
return process_sub_rows_table.length;
}
public bool is_in_table(uint pid)
{
return ((int) pid in process_sub_rows_table);
}
public void pre_update()
{
foreach(unowned SubProcessSubRow sub_row in process_sub_rows_table.get_values())
sub_row.set_alive(false);
}
public void post_update()
{
this.forall ((element) => this.remove (element)); //clear box
var sub_rows_sorted = new Gee.ArrayList<unowned SubProcessSubRow>();
foreach(unowned SubProcessSubRow sub_row in process_sub_rows_table.get_values())
{
sub_row.update();
if(sub_row.get_alive() == false)
process_sub_rows_table.remove((int) sub_row.get_pid());
else
sub_rows_sorted.add(sub_row);
}
sort(sub_rows_sorted);
foreach(unowned SubProcessSubRow sub_row in sub_rows_sorted)
this.add(sub_row);
}
public void add_sub_row(uint pid, int value, string name)
{
SubProcessSubRow sub_row = new SubProcessSubRow((int) pid, value, name);
process_sub_rows_table.insert ((int) pid, (owned) sub_row);
}
public void update_sub_row(uint pid, int value)
{
unowned SubProcessSubRow sub_row = process_sub_rows_table[(int) pid];
sub_row.set_value(value);
}
public void remove_all()
{
this.forall ((element) => this.remove (element)); //clear box
process_sub_rows_table.remove_all();
}
public Gee.ArrayList<int> get_values()
{
var list = new Gee.ArrayList<int>();
foreach(unowned SubProcessSubRow sub_row in process_sub_rows_table.get_values())
list.add(sub_row.get_value());
return list;
}
public int get_values_sum()
{
int sum = 0;
foreach(unowned SubProcessSubRow sub_row in process_sub_rows_table.get_values())
sum += sub_row.get_value();
return sum;
}
private void sort(Gee.ArrayList<unowned SubProcessSubRow> sub_rows)
{
sub_rows.sort((a, b) => {
return a.get_value() - b.get_value();
});
}
}
}
namespace Usage
{
/*public class subProcessSubRow : Gtk.ListBoxRow
{
Gtk.Image icon;
Gtk.Label title_label;
Gtk.Label load_label;
uint pid;
int value;
string name;
private bool alive = true;
public bool max_usage { get; private set; }
public subProcessSubRow(uint pid, int value, string name)
{
this.name = name;
this.pid = pid;
set_can_focus(true);
this.get_style_context().add_class("processDetailListBoxRow");
var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
box.margin = 12;
title_label = new Gtk.Label(name);
load_label = new Gtk.Label(value.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);
set_value(value);
add(box);
show_all();
}
public string get_name()
{
return name;
}
public uint get_pid()
{
return pid;
}
public int get_value()
{
return value;
}
public bool get_alive()
{
return alive;
}
public bool set_alive(bool alive)
{
return this.alive = alive;
}
public void set_value(int value)
{
this.value = int.min(value, 100);
alive = true;
update();
}
private void update()
{
if(value >= 90)
max_usage = true;
else
max_usage = false;
load_label.set_label(value.to_string() + "%");
}
}*/
public class SubProcessSubRow : Gtk.Box
{
Gtk.Image icon;
......@@ -94,6 +17,9 @@ namespace Usage
public SubProcessSubRow(uint pid, int value, string name)
{
this.name = name;
this.pid = pid;
this.margin = 0;
this.orientation = Gtk.Orientation.VERTICAL;
var main_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
......@@ -111,6 +37,8 @@ namespace Usage
event_box.add(main_box);
event_box.button_press_event.connect ((event) => {
var dialog = new ProcessDialog();
dialog.show_all ();
return false;
});
......
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