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

Cleaned header_bar code.

GraphStackSwithcer code cleaned.
parent 25328f84
......@@ -5,8 +5,8 @@ namespace Usage
public class Application : Gtk.Application
{
public Settings settings;
public Window window;
public SystemMonitor monitor;
private Window window;
private SystemMonitor monitor;
private const GLib.ActionEntry app_entries[] =
{
......@@ -21,6 +21,16 @@ namespace Usage
monitor = new SystemMonitor();
}
public SystemMonitor get_system_monitor()
{
return monitor;
}
public Window get_window()
{
return window;
}
public override void activate()
{
window = new Window(this);
......
......@@ -38,7 +38,7 @@ namespace Usage {
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
SystemMonitor monitor = (GLib.Application.get_default() as Application).get_system_monitor();
for (int i = 0; i < get_num_processors(); i++)
{
......@@ -92,7 +92,7 @@ namespace Usage {
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
SystemMonitor monitor = (GLib.Application.get_default() as Application).get_system_monitor();
double most_used_core = monitor.x_cpu_load[0];
for (int i = 1; i < get_num_processors(); i++)
......
......@@ -54,7 +54,7 @@ namespace Usage
**/
public class CpuGraphBig : Rg.Graph
{
private static CpuGraphTableComplex table;
private static CpuGraphTableComplex rg_table;
private LineRenderer[] renderers;
private Gdk.RGBA line_color_max;
private Gdk.RGBA line_color_normal;
......@@ -70,10 +70,10 @@ namespace Usage
line_color_normal.parse("rgba(74,144,217,1)");
get_style_context().add_class("big");
if(table == null)
table = new CpuGraphTableComplex();
if(rg_table == null)
rg_table = new CpuGraphTableComplex();
set_table(table);
set_table(rg_table);
renderers = new LineRenderer[get_num_processors()];
for(int i = 0; i < get_num_processors(); i++)
......@@ -85,12 +85,12 @@ namespace Usage
add_renderer(renderers[i]);
}
table.big_process_usage.connect ((column) => {
rg_table.big_process_usage.connect ((column) => {
renderers[column].stroke_color_rgba = line_color_max;
renderers[column].line_width = 2.5;
});
table.small_process_usage.connect ((column) => {
rg_table.small_process_usage.connect ((column) => {
renderers[column].stroke_color_rgba = line_color_normal;
renderers[column].line_width = 1.5;
});
......
......@@ -39,11 +39,5 @@ namespace Usage
add(scrolled_window);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -10,11 +10,5 @@ namespace Usage
var label = new Gtk.Label("Page Data Content.");
add(label);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -8,11 +8,5 @@ namespace Usage
var label = new Gtk.Label("What library we can use for disk I/O usage?");
this.add(label);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -5,10 +5,7 @@ namespace Usage
Gtk.Stack stack;
View[] sub_views;
Gtk.ToggleButton cpu_button;
Gtk.ToggleButton memory_button;
Gtk.ToggleButton disk_button;
Gtk.ToggleButton network_button;
Gtk.ToggleButton[] buttons;
bool can_change = true;
......@@ -24,114 +21,51 @@ namespace Usage
this.stack = stack;
this.sub_views = sub_views;
cpu_button = new GraphSwitcherButton.processor("Processor");
memory_button = new GraphSwitcherButton.memory("Memory");
disk_button = new GraphSwitcherButton.disk("Disk I/O");
network_button = new GraphSwitcherButton.network("Network");
buttons = {
new GraphSwitcherButton.processor("Processor"),
new GraphSwitcherButton.memory("Memory"),
new GraphSwitcherButton.disk("Disk I/O"),
new GraphSwitcherButton.network("Network"),
};
this.pack_start(cpu_button, false, true, 0);
this.pack_start(memory_button, false, true, 0);
this.pack_start(disk_button, false, true, 0);
this.pack_start(network_button, false, true, 0);
foreach(Gtk.ToggleButton button in buttons)
{
this.pack_start(button, false, true, 0);
}
cpu_button.set_active (true);
buttons[0].set_active (true);
cpu_button.clicked.connect (() => {
if(can_change)
{
if (cpu_button.active)
foreach(Gtk.ToggleButton button in buttons)
{
button.toggled.connect (() => {
if(can_change)
{
can_change = false;
memory_button.active = false;
disk_button.active = false;
network_button.active = false;
this.stack.set_visible_child_name(this.sub_views[0].name);
((View) this.stack.get_visible_child()).update_header_bar();
can_change = true;
} else
{
can_change = false;
cpu_button.active = true;
can_change = true;
}
}
});
memory_button.clicked.connect (() => {
if(can_change)
{
if (memory_button.active)
{
can_change = false;
cpu_button.active = false;
disk_button.active = false;
network_button.active = false;
this.stack.set_visible_child_name(this.sub_views[1].name);
((View) this.stack.get_visible_child()).update_header_bar();
can_change = true;
} else
{
can_change = false;
memory_button.active = true;
can_change = true;
}
}
});
disk_button.clicked.connect (() => {
if(can_change)
{
if (disk_button.active)
{
can_change = false;
cpu_button.active = false;
memory_button.active = false;
network_button.active = false;
this.stack.set_visible_child_name(this.sub_views[2].name);
((View) this.stack.get_visible_child()).update_header_bar();
can_change = true;
} else
{
can_change = false;
disk_button.active = true;
can_change = true;
}
}
});
network_button.clicked.connect (() => {
if(can_change)
{
if (network_button.active)
{
can_change = false;
cpu_button.active = false;
memory_button.active = false;
disk_button.active = false;
this.stack.set_visible_child_name(this.sub_views[3].name);
((View) this.stack.get_visible_child()).update_header_bar();
can_change = true;
} else
{
can_change = false;
network_button.active = true;
can_change = true;
if (button.active)
{
can_change = false;
int i = 0;
int button_number = 0;
foreach(Gtk.ToggleButton btn in buttons)
{
if(btn != button)
btn.active = false;
else
button_number = i;
i++;
}
this.stack.set_visible_child_name(this.sub_views[button_number].name);
can_change = true;
} else
{
can_change = false;
button.active = true;
can_change = true;
}
}
}
});
});
}
}
}
}
......@@ -11,39 +11,10 @@ namespace Usage
stack_switcher = new Gtk.StackSwitcher();
stack_switcher.halign = Gtk.Align.CENTER;
stack_switcher.set_stack(stack);
set_custom_title(stack_switcher);
menu_button = new Gtk.MenuButton();
menu_button.add(new Gtk.Image.from_icon_name("open-menu-symbolic", Gtk.IconSize.BUTTON));
}
public void set_menu_button(Gtk.Box? popover_box)
{
var popover = new Gtk.Popover(menu_button);
popover.add(popover_box);
menu_button.popover = popover;
}
public void show_menu_button()
{
pack_end(menu_button);
}
public void hide_menu_button()
{
remove(menu_button);
}
public void show_stack_switcher()
{
set_custom_title(stack_switcher);
}
public void clear()
{
set_custom_title(null);
var children = get_children ();
foreach (Gtk.Widget child in children)
remove(child);
show_all();
}
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ namespace Usage {
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
SystemMonitor monitor = (GLib.Application.get_default() as Application).get_system_monitor();
double ram_usage = monitor.ram_usage;
iter.set (column_ram_id, ram_usage, -1);
......
......@@ -39,11 +39,5 @@ namespace Usage
add(scrolled_window);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -27,7 +27,7 @@ namespace Usage {
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
SystemMonitor monitor = (GLib.Application.get_default() as Application).get_system_monitor();
double net_download = monitor.net_download;
double net_upload = monitor.net_upload;
......
......@@ -98,13 +98,12 @@ namespace Usage
void handle_thread_errors()
{
unowned ErrorCode[] errors = null;
uint32 num_errors = 0;
handle_error(netinfo.pop_thread_errors(out errors));
if(errors.length > 0)
{
handle_error(errors[0]);
}
handle_error(netinfo.free_thread_error_array(errors));
handle_error(NetInfo.free_thread_error_array(errors));
}
}
}
\ No newline at end of file
......@@ -39,11 +39,5 @@ namespace Usage
add(scrolled_window);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -33,11 +33,5 @@ namespace Usage
paned.add2(performance_stack);
add(paned);
}
public override void update_header_bar()
{
var visible_sub_view = (View) performance_stack.get_visible_child();
visible_sub_view.update_header_bar();
}
}
}
......@@ -10,11 +10,5 @@ namespace Usage
var label = new Gtk.Label("Page Power Content.");
add(label);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -14,7 +14,7 @@ namespace Usage
public ProcessDialog(pid_t pid, string name)
{
Object(use_header_bar: 1);
set_transient_for((GLib.Application.get_default() as Application).window);
set_transient_for((GLib.Application.get_default() as Application).get_window());
set_position(Gtk.WindowPosition.CENTER);
set_resizable(false);
this.pid = pid;
......@@ -56,7 +56,7 @@ namespace Usage
private bool update()
{
unowned SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
SystemMonitor monitor = (GLib.Application.get_default() as Application).get_system_monitor();
unowned Process data = monitor.get_process_by_pid(pid);
int app_cpu_load = 0;
......
......@@ -11,7 +11,6 @@ namespace Usage
public class ProcessListBoxNew : Gtk.ListBox
{
ListStore model;
string cmdline_opened_process;
ProcessRow? opened_row = null;
ProcessListBoxType type;
......@@ -59,15 +58,15 @@ namespace Usage
{
default:
case ProcessListBoxType.PROCESSOR:
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_cpu_processes())
foreach(unowned Process process in (GLib.Application.get_default() as Application).get_system_monitor().get_cpu_processes())
model.insert_sorted(process, sort);
break;
case ProcessListBoxType.MEMORY:
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_ram_processes())
foreach(unowned Process process in (GLib.Application.get_default() as Application).get_system_monitor().get_ram_processes())
model.insert_sorted(process, sort);
break;
case ProcessListBoxType.NETWORK:
foreach(unowned Process process in (GLib.Application.get_default() as Application).monitor.get_net_processes())
foreach(unowned Process process in (GLib.Application.get_default() as Application).get_system_monitor().get_net_processes())
model.insert_sorted(process, sort);
break;
}
......@@ -115,13 +114,10 @@ namespace Usage
default:
case ProcessListBoxType.PROCESSOR:
return (int) ((Process) b).cpu_load - (int) ((Process) a).cpu_load;
break;
case ProcessListBoxType.MEMORY:
return (int) ((Process) b).mem_usage - (int) ((Process) a).mem_usage;
break;
case ProcessListBoxType.NETWORK:
return (int) ((Process) b).net_all - (int) ((Process) a).net_all;
break;
}
}
}
......
......@@ -59,15 +59,9 @@ namespace Usage
show_details();
}
private Gtk.Widget on_subrow_created (Object item)
{
Process process = (Process) item;
var row = new SubProcessSubRow(process, type);
return row;
}
private void load_icon_and_name(out Gtk.Image icon, out string display_name)
{
icon = null;
AppInfo app_info = null;
foreach (AppInfo info in apps_info)
{
......@@ -103,33 +97,34 @@ namespace Usage
}
}
bool not_have_icon = false;
if(app_info != null)
{
display_name = app_info.get_display_name();
if(app_info.get_icon() == null)
not_have_icon = true;
else
if(app_info.get_icon() != null)
{
var icon_theme = new Gtk.IconTheme();
var icon_info = icon_theme.lookup_by_gicon_for_scale(app_info.get_icon(), 24, 1, Gtk.IconLookupFlags.FORCE_SIZE);
if(icon_info != null)
{
var pixbuf = icon_info.load_icon();
icon = new Gtk.Image.from_pixbuf(pixbuf);
try
{
var pixbuf = icon_info.load_icon();
icon = new Gtk.Image.from_pixbuf(pixbuf);
}
catch(Error e) {
GLib.stderr.printf ("Could not load icon for application %s: %s\n", display_name, e.message);
}
}
else
not_have_icon = true;
}
}
else
{
display_name = process.cmdline;
not_have_icon = true;
}
if(not_have_icon)
if(icon == null)
{
icon = new Gtk.Image.from_icon_name("system-run-symbolic", Gtk.IconSize.BUTTON);
icon.width_request = 24;
......@@ -230,7 +225,7 @@ namespace Usage
get_style_context().add_class("opened");
}
public void activate()
public new void activate()
{
if(process.sub_processes != null)
{
......
......@@ -10,11 +10,5 @@ namespace Usage
var label = new Gtk.Label("Page Storage Content.");
add(label);
}
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_stack_switcher();
}
}
}
......@@ -70,13 +70,10 @@ namespace Usage
default:
case ProcessListBoxType.PROCESSOR:
return (int) ((Process) b).cpu_load - (int) ((Process) a).cpu_load;
break;
case ProcessListBoxType.MEMORY:
return (int) ((Process) b).mem_usage - (int) ((Process) a).mem_usage;
break;
case ProcessListBoxType.NETWORK:
return (int) ((Process) b).net_all - (int) ((Process) a).net_all;
break;
}
}
}
......
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