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

*Updated formatting

*Updated version
*Added filtering process
*fixed some bugs
parent d5ad523d
......@@ -28,7 +28,6 @@ endif()
find_package(PkgConfig)
set(MODULES_TO_CHECK ${MODULES_TO_CHECK} libgtop)
set(MODULES_TO_CHECK ${MODULES_TO_CHECK} atk)
set(MODULES_TO_CHECK ${MODULES_TO_CHECK} cairo)
set(MODULES_TO_CHECK ${MODULES_TO_CHECK} gdk-3.0)
......
......@@ -15,8 +15,8 @@ make
sudo make install
```
##Version - WIP
Actual version is 0.0.1
##Version
Actual version is 0.0.2
#License
Code is under GNU GPLv3 license.
......
......@@ -5,9 +5,8 @@ project_name: gnome-usage
vala_binary: src/gnome-usage
*version: 0.0.1
*version: 0.0.2
*vala_vapi: vapis/glibtop.vapi
c_check_package: libgtop
*vala_package: posix
*vala_check_package: atk
*vala_check_package: cairo
......@@ -34,16 +33,16 @@ h_folder: /usr/include/libgtop-2.0
*po: po
*translate: vala src/system-monitor.vala
*translate: vala src/window.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/data-view.vala
*translate: vala src/view.vala
*translate: vala src/storage-view.vala
*translate: vala src/power-view.vala
*translate: vala src/performance-view.vala
*translate: vala src/window.vala
*translate: vala src/view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/process-list.vala
*translate: vala src/performance-view.vala
*translate: vala src/application.vala
*translate: vala src/gnome-usage.vala
*data: data/local
......
......@@ -7,13 +7,13 @@ set (GETTEXT_PACKAGE "gnome-usage")
set (RELEASE_NAME "gnome-usage")
set (CMAKE_C_FLAGS "")
set (PREFIX ${CMAKE_INSTALL_PREFIX})
set (VERSION "0.0.1")
set (VERSION "0.0.2")
set (TESTSRCDIR "${CMAKE_SOURCE_DIR}")
set (DOLLAR "$")
configure_file (${CMAKE_SOURCE_DIR}/src/Config.vala.cmake ${CMAKE_BINARY_DIR}/src/Config.vala)
add_definitions(-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\")
set (VERSION "0.0.1")
set (VERSION "0.0.2")
add_definitions (${DEPS_CFLAGS})
link_libraries ( ${DEPS_LIBRARIES} )
link_directories ( ${DEPS_LIBRARY_DIRS} )
......
using Gtk;
namespace Usage {
public class Application : Gtk.Application {
namespace Usage
{
public class Application : Gtk.Application
{
private Window window;
public SystemMonitor monitor;
public Application () {
public Application ()
{
application_id = "org.gnome.usage";
monitor = new SystemMonitor ();
monitor = new SystemMonitor();
}
public override void activate () {
window = new Window (this);
public override void activate()
{
window = new Window(this);
window.show_all();
}
}
......
namespace Usage {
public class DataView : View {
public DataView () {
namespace Usage
{
public class DataView : View
{
public DataView ()
{
name = "DATA";
title = _("Data");
var label1 = new Gtk.Label("Page 1 Content.");
add(label1);
var label1 = new Gtk.Label("Page Data Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover() {
public override Gtk.Box? getMenuPopover()
{
return null;
}
}
......
// project version=0.0.1
public static int main (string[] args) {
// project version=0.0.2
public static int main (string[] args)
{
Intl.bindtextdomain(Constants.GETTEXT_PACKAGE, Path.build_filename(Constants.DATADIR,"locale"));
Intl.setlocale (LocaleCategory.ALL, "");
Intl.setlocale(LocaleCategory.ALL, "");
Intl.textdomain(Constants.GETTEXT_PACKAGE);
Intl.bind_textdomain_codeset(Constants.GETTEXT_PACKAGE, "utf-8");
var application = new Usage.Application ();
return application.run (args);
var application = new Usage.Application();
return application.run(args);
}
namespace Usage {
namespace Usage
{
public class PerformanceView : View
{
ProcessList processListBox;
Gtk.Label CPULoadLabel;
List<ProcessRow> processRowList;
public class PerformanceView : View {
bool showActiveProcess = false;
ProcessList processListBox;
Gtk.Label CPULoadLabel;
public PerformanceView () {
name = "performance";
title = _("Performance");
public PerformanceView()
{
name = "performance";
title = _("Performance");
CPULoadLabel = new Gtk.Label(null);
var processorLabel = new Gtk.Label ("<b>" + _("Processor") + "</b>");
processorLabel.set_use_markup (true);
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.pack_start(processorLabel, true, true, 0);
processorTextBox.pack_start(CPULoadLabel, false, true, 0);
var CPUButton = new Gtk.Button.with_label("Processor");
var memoryButton = new Gtk.Button.with_label("Memory");
var diskButton = new Gtk.Button.with_label("Disk I/O");
var networkButton = new Gtk.Button.with_label("Network");
var panelBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
panelBox.pack_start(CPUButton, false, true, 0);
panelBox.pack_start(memoryButton, false, true, 0);
panelBox.pack_start(diskButton, false, true, 0);
panelBox.pack_start(networkButton, false, true, 0);
processListBox = new ProcessList();
var CPUBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var processListBoxFrame = new Gtk.Frame(null);
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);
var stack = new Gtk.Stack();
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN);
stack.set_transition_duration(700);
stack.add_named(scrolledWindowCPU, "CPU");
stack.add_named(new Gtk.Label("Memory"), "RAM");
stack.add_named(new Gtk.Label("Disk I/O"), "DISK");
stack.add_named(new Gtk.Label("Network"), "NETWORK");
CPUButton.clicked.connect (() => {
stack.set_visible_child_name("CPU");
});
memoryButton.clicked.connect (() => {
stack.set_visible_child_name("RAM");
});
diskButton.clicked.connect (() => {
stack.set_visible_child_name("DISK");
});
networkButton.clicked.connect (() => {
stack.set_visible_child_name("NETWORK");
});
var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
paned.add1(panelBox);
paned.add2(stack);
add(paned);
Timeout.add (1000, updateProcess);
processorTextBox.set_center_widget(processorLabel);
processorTextBox.pack_end(CPULoadLabel, false, true, 0);
processorTextBox.margin_top = 20;
var CPUButton = new Gtk.Button.with_label("Processor");
var memoryButton = new Gtk.Button.with_label("Memory");
var diskButton = new Gtk.Button.with_label("Disk I/O");
var networkButton = new Gtk.Button.with_label("Network");
var panelBox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
panelBox.pack_start(CPUButton, false, true, 0);
panelBox.pack_start(memoryButton, false, true, 0);
panelBox.pack_start(diskButton, false, true, 0);
panelBox.pack_start(networkButton, false, true, 0);
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);
var stack = new Gtk.Stack();
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN);
stack.set_transition_duration(700);
stack.add_named(scrolledWindowCPU, "CPU");
stack.add_named(new Gtk.Label("Memory"), "RAM");
stack.add_named(new Gtk.Label("Disk I/O"), "DISK");
stack.add_named(new Gtk.Label("Network"), "NETWORK");
CPUButton.clicked.connect(() => {
stack.set_visible_child_name("CPU");
});
memoryButton.clicked.connect(() => {
stack.set_visible_child_name("RAM");
});
diskButton.clicked.connect(() => {
stack.set_visible_child_name("DISK");
});
networkButton.clicked.connect(() => {
stack.set_visible_child_name("NETWORK");
});
var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
paned.add1(panelBox);
paned.add2(stack);
add(paned);
Timeout.add(1000, updateProcess);
}
public bool updateProcess()
{
processListBox.foreach ((widget) => { widget.destroy (); });
CPULoadLabel.set_text (((int)(monitor.cpu_load * 100)).to_string() + " %");
var processRowList = new List<ProcessRow>();
foreach (unowned Process process in monitor.get_processes ()) {
if(true)
{
stdout.printf ("procces name: " + process.cmdline + "\n");
var processRow = new ProcessRow (process.cmdline, (int) process.cpu_load * 100);
processRow.sortId = (int) (1000 * process.cpu_load);
processRowList.insert_sorted (processRow, (a, b) => {
return (b as ProcessRow).sortId - (a as ProcessRow).sortId;
});
}
}
for(int i = 0; i < processRowList.length(); i++) {
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;
}
processRowList =(owned) processRowList.next;
}
return true;
}
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;
});
}
public override Gtk.Box? getMenuPopover() {
var popoverBox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
public override Gtk.Box? getMenuPopover()
{
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.ACTIVE);
monitor.update();
var active = new Gtk.RadioButton.with_label_from_widget(null, _("Active process"));
popoverBox.pack_start(active, false, false, 0);
active.toggled.connect(() => {
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 (() => {
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();
});
all.set_active (true);
all.set_active(true);
var my = new Gtk.RadioButton.with_label_from_widget (active, "My process");
popoverBox.pack_start (my, false, false, 0);
my.toggled.connect (() => {
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 ();
popoverBox.show_all();
return popoverBox;
}
......
namespace Usage {
public class PowerView : View {
public PowerView () {
namespace Usage
{
public class PowerView : View
{
public PowerView()
{
name = "POWER";
title = _("Power");
var label1 = new Gtk.Label("Page 1 Content.");
add(label1);
var label1 = new Gtk.Label("Page Power Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover() {
return null;
public override Gtk.Box? getMenuPopover()
{
return null;
}
}
}
namespace Usage {
public class ProcessRow : Gtk.ListBoxRow {
private Gtk.Image icon;
namespace Usage
{
public class ProcessRow : Gtk.ListBoxRow
{
private Gtk.Image icon;
private Gtk.Label titleLabel;
private Gtk.Label loadLabel;
......@@ -10,14 +10,14 @@ namespace Usage {
public bool is_headline { get; private set; }
public ProcessRow (string title, int load) {
public ProcessRow(string title, int load)
{
var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
titleLabel = new Gtk.Label(title);
box.margin = 5;
titleLabel = new Gtk.Label(title);
loadLabel = 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);
//int margin = 5;
//loadLabel.set_size_request (50, -1);
box.pack_start(icon, false, false, 10);
box.pack_start(titleLabel, false, true, 5);
box.pack_end(loadLabel, false, true, 10);
......@@ -31,19 +31,21 @@ namespace Usage {
}
}
public class ProcessList : Gtk.ListBox {
public ProcessList () {
public class ProcessList : Gtk.ListBox
{
public ProcessList()
{
set_selection_mode (Gtk.SelectionMode.NONE);
set_header_func (update_header);
}
void update_header (Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row) {
if(before_row == null)
row.set_header(null);
else
{
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
void update_header(Gtk.ListBoxRow row, Gtk.ListBoxRow? before_row)
{
if(before_row == null)
row.set_header(null);
else
{
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
separator.show();
row.set_header(separator);
}
......
namespace Usage {
public class StorageView : View {
public StorageView () {
namespace Usage
{
public class StorageView : View
{
public StorageView ()
{
name = "STORAGE";
title = _("Storage");
var label1 = new Gtk.Label("Page 1 Content.");
var label1 = new Gtk.Label("Page Storage Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover() {
return null;
public override Gtk.Box? getMenuPopover()
{
return null;
}
}
}
using Posix;
namespace Usage {
namespace Usage
{
[Compact]
public class Process {
public class Process
{
internal uint pid;
internal string cmdline;
internal double cpu_load;
......@@ -13,7 +14,8 @@ namespace Usage {
internal bool alive;
}
public class SystemMonitor {
public class SystemMonitor
{
public double cpu_load { get; private set; }
public double mem_usage { get; private set; }
public double swap_usage { get; private set; }
......@@ -21,105 +23,112 @@ namespace Usage {
uint64 cpu_last_used = 0;
uint64 cpu_last_total = 0;
const int UPDATE_INTERVAL = 100;
const int UPDATE_INTERVAL = 1000;
HashTable<uint, Process> process_table;
private int processMode = GTop.KERN_PROC_ALL;
public enum ProcessMode {
ALL,
USER,
ACTIVE
public enum ProcessMode
{
ALL,
USER,
EXCLUDE_IDLE
}
public void setProcessMode(ProcessMode mode) {
switch(mode)
{
case ProcessMode.ALL:
processMode = GTop.KERN_PROC_ALL;
break;
public void setProcessMode(ProcessMode mode)
{
switch(mode)
{
case ProcessMode.ALL:
processMode = GTop.KERN_PROC_ALL;
break;
case ProcessMode.USER:
processMode = GTop.KERN_PROC_UID;
break;
case ProcessMode.ACTIVE:
processMode = GTop.EXCLUDE_IDLE;
break;
}
processMode = GTop.KERN_PROC_UID;
break;
case ProcessMode.EXCLUDE_IDLE:
processMode = GTop.EXCLUDE_IDLE;
break;
}
}
public bool update() {
/* CPU */
GTop.Cpu cpu_data;
GTop.get_cpu (out cpu_data);
var used = cpu_data.user + cpu_data.nice + cpu_data.sys;
cpu_load = ((double) (used - cpu_last_used)) / (cpu_data.total - cpu_last_total);
/* Memory */
GTop.Mem mem;
GTop.get_mem (out mem);
mem_usage = ((double) (mem.used - mem.buffer - mem.cached)) / mem.total;
/* Swap */
GTop.Swap swap;
GTop.get_swap (out swap);
swap_usage = (double) swap.used / swap.total;
foreach (unowned Process process in process_table.get_values ()) {
process.alive = false;
public bool update()