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

*Updates all structure app and views

parent b63bb193
......@@ -20,12 +20,14 @@ vala_binary: src/gnome-usage
*vala_check_package: x11
c_library: gtop-2.0
*vala_source: application.vala
*vala_source: cpu-subview.vala
*vala_source: data-view.vala
*vala_source: gnome-usage.vala
*vala_source: headerbar.vala
*vala_source: performance-view.vala
*vala_source: power-view.vala
*vala_source: process-list.vala
*vala_source: ram-subview.vala
*vala_source: storage-view.vala
*vala_source: system-monitor.vala
*vala_source: view.vala
......@@ -34,17 +36,19 @@ h_folder: /usr/include/libgtop-2.0
*po: po
*translate: vala src/storage-view.vala
*translate: vala src/view.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/process-list.vala
*translate: vala src/view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/storage-view.vala
*translate: vala src/cpu-subview.vala
*translate: vala src/data-view.vala
*translate: vala src/power-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/headerbar.vala
*translate: vala src/application.vala
*translate: vala src/window.vala
*translate: vala src/performance-view.vala
*translate: vala src/power-view.vala
*translate: vala src/application.vala
*translate: vala src/ram-subview.vala
*data: data/local
......
src/application.vala
src/cpu-subview.vala
src/data-view.vala
src/gnome-usage.vala
src/headerbar.vala
src/performance-view.vala
src/power-view.vala
src/process-list.vala
src/ram-subview.vala
src/storage-view.vala
src/system-monitor.vala
src/view.vala
......
......@@ -36,12 +36,14 @@ set (VALA_PACKAGES ${VALA_PACKAGES} x11)
set (APP_SOURCES ${APP_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/Config.vala)
set (APP_SOURCES ${APP_SOURCES} application.vala)
set (APP_SOURCES ${APP_SOURCES} cpu-subview.vala)
set (APP_SOURCES ${APP_SOURCES} data-view.vala)
set (APP_SOURCES ${APP_SOURCES} gnome-usage.vala)
set (APP_SOURCES ${APP_SOURCES} headerbar.vala)
set (APP_SOURCES ${APP_SOURCES} performance-view.vala)
set (APP_SOURCES ${APP_SOURCES} power-view.vala)
set (APP_SOURCES ${APP_SOURCES} process-list.vala)
set (APP_SOURCES ${APP_SOURCES} ram-subview.vala)
set (APP_SOURCES ${APP_SOURCES} storage-view.vala)
set (APP_SOURCES ${APP_SOURCES} system-monitor.vala)
set (APP_SOURCES ${APP_SOURCES} view.vala)
......
......@@ -4,7 +4,7 @@ namespace Usage
{
public class Application : Gtk.Application
{
private Window window;
public Window window;
public SystemMonitor monitor;
public Application ()
......
namespace Usage
{
public class CPUsubView : View
{
ProcessList processListBox;
Gtk.Label CPULoadLabel;
List<ProcessRow> processRowList;
bool showActiveProcess = true;
public CPUsubView ()
{
name = ("CPU");
CPULoadLabel = new Gtk.Label(null);
CPULoadLabel.margin_right = 100;
var processorLabel = new Gtk.Label("<b>" + _("Processor") + "</b>");
processorLabel.set_use_markup(true);
var processorTextBox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
processorTextBox.set_center_widget(processorLabel);
processorTextBox.pack_end(CPULoadLabel, false, true, 0);
processorTextBox.margin_top = 20;
processListBox = new ProcessList();
var CPUBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var processListBoxFrame = new Gtk.Frame(null);
processListBoxFrame.margin_start = 100;
processListBoxFrame.margin_end = 100;
processListBoxFrame.margin_bottom = 20;
processListBoxFrame.add(processListBox);
CPUBox.pack_start(processorTextBox, false, false, 0);
CPUBox.pack_start(processListBoxFrame, true, false, 0);
var scrolledWindowCPU = new Gtk.ScrolledWindow(null, null);
scrolledWindowCPU.add(CPUBox);
scrolledWindowCPU.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
constructMenuButton();
add(scrolledWindowCPU);
Timeout.add(1000, updateProcess);
}
public bool updateProcess()
{
processListBox.foreach((widget) => { widget.destroy(); });
CPULoadLabel.set_text(((int) monitor.cpu_load).to_string() + " %");
processRowList = new List<ProcessRow>();
foreach(unowned Process process in monitor.get_processes()) {
if(showActiveProcess)
{
if((int) process.cpu_load > 0)
insertProcessRow(process);
} else
insertProcessRow(process);
}
for(int i = 0; i < processRowList.length(); i++)
{
processListBox.add(processRowList.data);
processRowList =(owned) processRowList.next;
}
return true;
}
public void insertProcessRow(Process process)
{
var processRow = new ProcessRow(process.cmdline,(int) process.cpu_load);
processRow.sortId =(int)(10 * process.cpu_load);
processRowList.insert_sorted(processRow,(a, b) => {
return(b as ProcessRow).sortId -(a as ProcessRow).sortId;
});
}
private void constructMenuButton()
{
var popoverBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
popoverBox.margin = 5;
var active = new Gtk.RadioButton.with_label_from_widget(null, _("Active process"));
popoverBox.pack_start(active, false, false, 0);
active.toggled.connect(() => {
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
showActiveProcess = true;
updateProcess();
});
var all = new Gtk.RadioButton.with_label_from_widget(active, _("All process"));
popoverBox.pack_start(all, false, false, 0);
all.toggled.connect(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
monitor.update();
updateProcess();
});
var my = new Gtk.RadioButton.with_label_from_widget(active, _("My process"));
popoverBox.pack_start(my, false, false, 0);
my.toggled.connect(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.USER);
monitor.update();
updateProcess();
});
popoverBox.show_all();
headerBar.setMenuButton(popoverBox);
}
public override void updateHeaderBar()
{
headerBar.clear();
headerBar.showMenuButton();
headerBar.showStackSwitcher();
}
}
}
......@@ -2,10 +2,8 @@ namespace Usage
{
public class DataView : View
{
public DataView (Usage.HeaderBar headerBar)
public DataView ()
{
base(headerBar);
name = ("DATA");
title = _("Data");
......
......@@ -2,27 +2,28 @@ namespace Usage
{
public class PerformanceView : View
{
ProcessList processListBox;
/*ProcessList processListBox;
Gtk.Label CPULoadLabel;
List<ProcessRow> processRowList;
bool showActiveProcess = true;
bool showActiveProcess = true;*/
Gtk.Stack performanceStack;
public PerformanceView(Usage.HeaderBar headerBar)
{
base(headerBar);
public PerformanceView()
{
name = "PERFORMANCE";
title = _("Performance");
CPULoadLabel = new Gtk.Label(null);
/*CPULoadLabel = new Gtk.Label(null);
CPULoadLabel.margin_right = 100;
var processorLabel = new Gtk.Label("<b>" + _("Processor") + "</b>");
processorLabel.set_use_markup(true);
var processorTextBox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
processorTextBox.set_center_widget(processorLabel);
processorTextBox.pack_end(CPULoadLabel, false, true, 0);
processorTextBox.margin_top = 20;
processorTextBox.margin_top = 20;*/
var CPUButton = new Gtk.Button.with_label("Processor");
var memoryButton = new Gtk.Button.with_label("Memory");
......@@ -35,7 +36,7 @@ namespace Usage
panelBox.pack_start(diskButton, false, true, 0);
panelBox.pack_start(networkButton, false, true, 0);
processListBox = new ProcessList();
/*processListBox = new ProcessList();
var CPUBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var processListBoxFrame = new Gtk.Frame(null);
......@@ -44,122 +45,57 @@ namespace Usage
processListBoxFrame.margin_bottom = 20;
processListBoxFrame.add(processListBox);
CPUBox.pack_start(processorTextBox, false, false, 0);
CPUBox.pack_start(processListBoxFrame, true, false, 0);
CPUBox.pack_start(processListBoxFrame, true, false, 0);*/
var scrolledWindowCPU = new Gtk.ScrolledWindow(null, null);
/*var scrolledWindowCPU = new Gtk.ScrolledWindow(null, null);
scrolledWindowCPU.add(CPUBox);
scrolledWindowCPU.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
scrolledWindowCPU.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);*/
var performanceStack = new Gtk.Stack();
performanceStack = new Gtk.Stack();
performanceStack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN);
performanceStack.set_transition_duration(700);
performanceStack.add_named(scrolledWindowCPU, "CPU");
/*performanceStack.add_named(scrolledWindowCPU, "CPU");
performanceStack.add_named(new Gtk.Label("Memory"), "RAM");
performanceStack.add_named(new Gtk.Label("Disk I/O"), "DISK");
performanceStack.add_named(new Gtk.Label("Network"), "NETWORK");
performanceStack.add_named(new Gtk.Label("Network"), "NETWORK");*/
var subViews = new View[]
{
new CPUsubView(),
new RAMsubView()
};
foreach(var subView in subViews)
performanceStack.add_named(subView, subView.name);
CPUButton.clicked.connect(() => {
performanceStack.set_visible_child_name("CPU");
constructMenuButtonForCPU();
headerBar.showMenuButton();
performanceStack.set_visible_child_name(subViews[0].name);
((View) performanceStack.get_visible_child()).updateHeaderBar();
});
memoryButton.clicked.connect(() => {
performanceStack.set_visible_child_name("RAM");
headerBar.hideMenuButton();
performanceStack.set_visible_child_name(subViews[1].name);
((View) performanceStack.get_visible_child()).updateHeaderBar();
});
diskButton.clicked.connect(() => {
performanceStack.set_visible_child_name("DISK");
headerBar.hideMenuButton();
});
networkButton.clicked.connect(() => {
performanceStack.set_visible_child_name("NETWORK");
performanceStack.set_visible_child_name("NETcpu-subview.valaWORK");
headerBar.hideMenuButton();
});
constructMenuButtonForCPU();
var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
paned.add1(panelBox);
paned.add2(performanceStack);
add(paned);
Timeout.add(1000, updateProcess);
}
public bool updateProcess()
{
processListBox.foreach((widget) => { widget.destroy(); });
CPULoadLabel.set_text(((int) monitor.cpu_load).to_string() + " %");
processRowList = new List<ProcessRow>();
foreach(unowned Process process in monitor.get_processes()) {
if(showActiveProcess)
{
if((int) process.cpu_load > 0)
insertProcessRow(process);
} else
insertProcessRow(process);
}
for(int i = 0; i < processRowList.length(); i++)
{
processListBox.add(processRowList.data);
processRowList =(owned) processRowList.next;
}
return true;
}
public void insertProcessRow(Process process)
{
var processRow = new ProcessRow(process.cmdline,(int) process.cpu_load);
processRow.sortId =(int)(10 * process.cpu_load);
processRowList.insert_sorted(processRow,(a, b) => {
return(b as ProcessRow).sortId -(a as ProcessRow).sortId;
});
}
private void constructMenuButtonForCPU()
{
var popoverBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
popoverBox.margin = 5;
var active = new Gtk.RadioButton.with_label_from_widget(null, _("Active process"));
popoverBox.pack_start(active, false, false, 0);
active.toggled.connect(() => {
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
showActiveProcess = true;
updateProcess();
});
var all = new Gtk.RadioButton.with_label_from_widget(active, _("All process"));
popoverBox.pack_start(all, false, false, 0);
all.toggled.connect(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
monitor.update();
updateProcess();
});
var my = new Gtk.RadioButton.with_label_from_widget(active, _("My process"));
popoverBox.pack_start(my, false, false, 0);
my.toggled.connect(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.USER);
monitor.update();
updateProcess();
});
popoverBox.show_all();
headerBar.setMenuButton(popoverBox);
}
public override void updateHeaderBar()
{
headerBar.clear();
headerBar.showMenuButton();
headerBar.showStackSwitcher();
var visibleSubView = (View) performanceStack.get_visible_child();
visibleSubView.updateHeaderBar();
}
}
}
......@@ -2,10 +2,8 @@ namespace Usage
{
public class PowerView : View
{
public PowerView(Usage.HeaderBar headerBar)
public PowerView()
{
base(headerBar);
name = "POWER";
title = _("Power");
......
namespace Usage
{
public class RAMsubView : View
{
ProcessList processListBox;
Gtk.Label CPULoadLabel;
List<ProcessRow> processRowList;
bool showActiveProcess = true;
public RAMsubView ()
{
name = ("RAM");
CPULoadLabel = new Gtk.Label(null);
CPULoadLabel.margin_right = 100;
var processorLabel = new Gtk.Label("<b>" + _("Processor") + "</b>");
processorLabel.set_use_markup(true);
var processorTextBox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
processorTextBox.set_center_widget(processorLabel);
processorTextBox.pack_end(CPULoadLabel, false, true, 0);
processorTextBox.margin_top = 20;
processListBox = new ProcessList();
var CPUBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var processListBoxFrame = new Gtk.Frame(null);
processListBoxFrame.margin_start = 100;
processListBoxFrame.margin_end = 100;
processListBoxFrame.margin_bottom = 20;
processListBoxFrame.add(processListBox);
CPUBox.pack_start(processorTextBox, false, false, 0);
CPUBox.pack_start(processListBoxFrame, true, false, 0);
var scrolledWindowCPU = new Gtk.ScrolledWindow(null, null);
scrolledWindowCPU.add(CPUBox);
scrolledWindowCPU.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
//constructMenuButton();
add(scrolledWindowCPU);
Timeout.add(1000, updateProcess);
}
public bool updateProcess()
{
processListBox.foreach((widget) => { widget.destroy(); });
CPULoadLabel.set_text(((int) monitor.cpu_load).to_string() + " %");
processRowList = new List<ProcessRow>();
foreach(unowned Process process in monitor.get_processes()) {
if(showActiveProcess)
{
if((int) process.cpu_load > 0)
insertProcessRow(process);
} else
insertProcessRow(process);
}
for(int i = 0; i < processRowList.length(); i++)
{
processListBox.add(processRowList.data);
processRowList =(owned) processRowList.next;
}
return true;
}
public void insertProcessRow(Process process)
{
var processRow = new ProcessRow(process.cmdline,(int) process.cpu_load);
processRow.sortId =(int)(10 * process.cpu_load);
processRowList.insert_sorted(processRow,(a, b) => {
return(b as ProcessRow).sortId -(a as ProcessRow).sortId;
});
}
private void constructMenuButton()
{
var popoverBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
popoverBox.margin = 5;
var active = new Gtk.RadioButton.with_label_from_widget(null, _("Active process"));
popoverBox.pack_start(active, false, false, 0);
active.toggled.connect(() => {
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
showActiveProcess = true;
updateProcess();
});
var all = new Gtk.RadioButton.with_label_from_widget(active, _("All process"));
popoverBox.pack_start(all, false, false, 0);
all.toggled.connect(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
monitor.update();
updateProcess();
});
var my = new Gtk.RadioButton.with_label_from_widget(active, _("My process"));
popoverBox.pack_start(my, false, false, 0);
my.toggled.connect(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.USER);
monitor.update();
updateProcess();
});
popoverBox.show_all();
headerBar.setMenuButton(popoverBox);
}
public override void updateHeaderBar()
{
headerBar.clear();
//headerBar.showMenuButton();
headerBar.showStackSwitcher();
}
}
}
......@@ -2,10 +2,8 @@ namespace Usage
{
public class StorageView : View
{
public StorageView (Usage.HeaderBar headerBar)
public StorageView ()
{
base(headerBar);
name = "STORAGE";
title = _("Storage");
......
......@@ -6,13 +6,14 @@ namespace Usage
public string title;
protected Usage.HeaderBar headerBar;
public View (Usage.HeaderBar headerBar)
public View ()
{
monitor = (GLib.Application.get_default() as Application).monitor;
headerBar = (GLib.Application.get_default() as Application).window.headerBar;
visible = true;
this.headerBar = headerBar;
}
public abstract void updateHeaderBar();
}
}
......@@ -2,8 +2,8 @@ namespace Usage
{
public class Window : Gtk.ApplicationWindow
{
Gtk.Stack stack;
Usage.HeaderBar headerBar;
public static Gtk.Stack stack;
public static Usage.HeaderBar headerBar;
public Window(Gtk.Application application)
{
......@@ -19,17 +19,17 @@ namespace Usage
var views = new View[]
{
new PerformanceView(headerBar),
new DataView(headerBar),
new StorageView(headerBar),
new PowerView(headerBar)
new PerformanceView(),
new DataView(),
new StorageView(),
new PowerView()
};
foreach(var view in views)
stack.add_titled(view, view.name, view.title);
stack.notify["visible-child"].connect (() => {
View visibleView = (View) stack.get_visible_child();
var visibleView = (View) stack.get_visible_child();
visibleView.updateHeaderBar();
});
......
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