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

Added first version of MenuButton and filtering process by user, or only active or all.

parent 48db1369
......@@ -8,8 +8,8 @@ https://raw.githubusercontent.com/gnome-design-team/gnome-mockups/master/usage/u
##Compilation:
```
autovala update
mkdir install
cd install
mkdir build
cd build
cmake ..
make
sudo make install
......
### CMakeLists automatically created with AutoVala
### Do not edit
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/window.ui DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/gnome-usage/ )
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/process-menu.ui DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/gnome-usage/ )
......@@ -25,6 +25,7 @@ c_library: gtop-2.0
*vala_source: gnome-usage.vala
*vala_source: performance-view.vala
*vala_source: power-view.vala
*vala_source: process-list.vala
*vala_source: storage-view.vala
*vala_source: system-monitor.vala
*vala_source: view.vala
......@@ -33,15 +34,16 @@ h_folder: /usr/include/libgtop-2.0
*po: po
*translate: vala src/storage-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/window.vala
*translate: vala src/performance-view.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/process-list.vala
*translate: vala src/application.vala
*translate: vala src/data-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/view.vala
*data: data/local
......
......@@ -3,6 +3,7 @@ src/data-view.vala
src/gnome-usage.vala
src/performance-view.vala
src/power-view.vala
src/process-list.vala
src/storage-view.vala
src/system-monitor.vala
src/view.vala
......
......@@ -22,18 +22,44 @@ include (ValaVersion)
ensure_vala_version ("0.32" MINIMUM)
include (ValaPrecompile)
set (VALA_PACKAGES ${VALA_PACKAGES} posix)
set (VALA_PACKAGES ${VALA_PACKAGES} atk)
set (VALA_PACKAGES ${VALA_PACKAGES} cairo)
set (VALA_PACKAGES ${VALA_PACKAGES} gdk-3.0)
set (VALA_PACKAGES ${VALA_PACKAGES} gdk-pixbuf-2.0)
set (VALA_PACKAGES ${VALA_PACKAGES} gio-2.0)
set (VALA_PACKAGES ${VALA_PACKAGES} glib-2.0)
set (VALA_PACKAGES ${VALA_PACKAGES} gobject-2.0)
set (VALA_PACKAGES ${VALA_PACKAGES} gtk+-3.0)
set (VALA_PACKAGES ${VALA_PACKAGES} pango)
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} data-view.vala)
set (APP_SOURCES ${APP_SOURCES} gnome-usage.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} storage-view.vala)
set (APP_SOURCES ${APP_SOURCES} system-monitor.vala)
set (APP_SOURCES ${APP_SOURCES} view.vala)
set (APP_SOURCES ${APP_SOURCES} window.vala)
set (CUSTOM_VAPIS_LIST ${CUSTOM_VAPIS_LIST} ${CMAKE_SOURCE_DIR}/src/vapis/glibtop.vapi)
include_directories (AFTER /usr/include/libgtop-2.0 )
vala_precompile(VALA_C gnome-usage
${APP_SOURCES}
PACKAGES
${VALA_PACKAGES}
CUSTOM_VAPIS
${CUSTOM_VAPIS_LIST}
)
add_executable(gnome-usage ${VALA_C})
target_link_libraries( gnome-usage gtop-2.0 )
install(TARGETS
......
......@@ -9,5 +9,9 @@ namespace Usage {
var label1 = new Gtk.Label("Page 1 Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover() {
return null;
}
}
}
......@@ -2,33 +2,131 @@ namespace Usage {
public class PerformanceView : View {
ProcessList processListBox;
Gtk.Label CPULoadLabel;
public PerformanceView () {
name = "performance";
title = _("Performance");
var label1 = new Gtk.Label("Page 1 Content.");
var label2 = new Gtk.Label("Page 2 Content.");
string processList = "";
CPULoadLabel = new Gtk.Label(null);
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(label1);
paned.add2(label2);
paned.add1(panelBox);
paned.add2(stack);
add(paned);
Timeout.add (1000, () => {
label1.set_text ("%d%%".printf ((int) (monitor.cpu_load * 100)));
Timeout.add (1000, updateProcess);
}
public bool updateProcess()
{
processListBox.foreach ((widget) => { widget.destroy (); });
CPULoadLabel.set_text (((int)(monitor.cpu_load * 100)).to_string() + " %");
processList = "";
var processRowList = new List<ProcessRow>();
foreach (unowned Process process in monitor.get_processes ()) {
var load = process.cpu_load * 100;
if(load > 0)
processList += "\n" + process.cmdline + "\t" + load.to_string();
label2.set_text(processList);
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.add(processRowList.data);
processRowList = (owned) processRowList.next;
}
return true;
});
}
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();
updateProcess();
});
var all = new Gtk.RadioButton.with_label_from_widget (active, "All process");
popoverBox.pack_start (all, false, false, 0);
all.toggled.connect (() => {
monitor.setProcessMode(SystemMonitor.ProcessMode.ALL);
monitor.update();
updateProcess();
});
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 (() => {
monitor.setProcessMode(SystemMonitor.ProcessMode.USER);
monitor.update();
updateProcess();
});
popoverBox.show_all ();
return popoverBox;
}
}
}
......@@ -9,5 +9,9 @@ namespace Usage {
var label1 = new Gtk.Label("Page 1 Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover() {
return null;
}
}
}
namespace Usage {
public class ProcessRow : Gtk.ListBoxRow {
private Gtk.Image icon;
private Gtk.Label titleLabel;
private Gtk.Label loadLabel;
public int sortId;
public bool is_headline { get; private set; }
public ProcessRow (string title, int load) {
var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
titleLabel = new Gtk.Label(title);
loadLabel = new Gtk.Label(load.to_string() + " %");
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);
add(box);
titleLabel.show();
loadLabel.show();
icon.show();
box.show();
show();
}
}
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);
separator.show();
row.set_header(separator);
}
}
}
}
......@@ -9,5 +9,9 @@ namespace Usage {
var label1 = new Gtk.Label("Page 1 Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover() {
return null;
}
}
}
......@@ -24,17 +24,31 @@ namespace Usage {
const int UPDATE_INTERVAL = 100;
HashTable<uint, Process> process_table;
public List<unowned Process> get_processes () {
return process_table.get_values ();
}
public SystemMonitor () {
GTop.init ();
process_table = new HashTable<uint, Process> (direct_hash, direct_equal);
Timeout.add (UPDATE_INTERVAL, () => {
/* CPU */
private int processMode = GTop.KERN_PROC_ALL;
public enum ProcessMode {
ALL,
USER,
ACTIVE
}
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;
}
}
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;
......@@ -56,7 +70,7 @@ namespace Usage {
var uid = Posix.getuid ();
GTop.Proclist proclist;
var pids = GTop.get_proclist (out proclist, GTop.KERN_PROC_UID, uid);
var pids = GTop.get_proclist (out proclist, processMode, uid);
for (int i = 0; i < proclist.number; i++) {
GTop.ProcState proc_state;
GTop.ProcTime proc_time;
......@@ -94,7 +108,18 @@ namespace Usage {
cpu_last_total = cpu_data.total;
return true;
});
}
public List<unowned Process> get_processes () {
return process_table.get_values ();
}
public SystemMonitor () {
GTop.init ();
process_table = new HashTable<uint, Process> (direct_hash, direct_equal);
Timeout.add (UPDATE_INTERVAL, update);
}
}
}
......@@ -14,6 +14,8 @@ namespace Usage {
monitor = (GLib.Application.get_default () as Application).monitor;
visible = true;
}
public abstract Gtk.Box? getMenuPopover();
}
}
......@@ -41,8 +41,12 @@ namespace Usage
views[UIView.STORAGE] = new StorageView ();
views[UIView.POWER] = new PowerView ();
var menuButton = new Gtk.MenuButton();
var popover = new Gtk.Popover (menuButton);
foreach (var view in UIView.all ()) {
stack.add_titled (views[view], views[view].name, views[view].title);
stack.add_titled (views[view], views[view].name, views[view].title);
popover.add (views[view].getMenuPopover()); //TODO fix it!!!
/*views[view].mode_changed.connect ((title) => {
if (title == null) {
header_bar.custom_title = stack_switcher;
......@@ -55,31 +59,19 @@ namespace Usage
});*/
};
/*
var label1 = new Gtk.Label("Page 1 Content.");
var label5 = new Gtk.Label("Page 5 Content.");
var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
paned.add1(label1);
paned.add2(label5);
stack.add_titled(paned, "page-1", "Performance");
var label2 = new Gtk.Label("Page 2 Content.");
stack.add_titled(label2, "page-2", "Data");
var label3 = new Gtk.Label("Page 3 Content.");
stack.add_titled(label3, "page-3", "Storage");
var label4 = new Gtk.Label("Page 4 Content.");
stack.add_titled(label4, "page-4", "Power");
*/
var stack_switcher = new Gtk.StackSwitcher();
stack_switcher.halign = Gtk.Align.CENTER;
stack_switcher.stack = stack;
stack_switcher.set_stack(stack);
var stackSwitcher = new Gtk.StackSwitcher();
stackSwitcher.halign = Gtk.Align.CENTER;
stackSwitcher.stack = stack;
stackSwitcher.set_stack(stack);
var headerbar = new Gtk.HeaderBar();
headerbar.show_close_button = true;
headerbar.set_custom_title(stack_switcher);
set_titlebar(headerbar);
headerbar.set_custom_title(stackSwitcher);
menuButton.popover = popover;
headerbar.pack_end(menuButton);
set_titlebar(headerbar);
this.add(stack);
}
}
......
Supports Markdown
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