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

*Added HeaderBar class

parent d2e14a96
......@@ -22,6 +22,7 @@ c_library: gtop-2.0
*vala_source: application.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
......@@ -33,15 +34,16 @@ h_folder: /usr/include/libgtop-2.0
*po: po
*translate: vala src/performance-view.vala
*translate: vala src/storage-view.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/process-list.vala
*translate: vala src/power-view.vala
*translate: vala src/window.vala
*translate: vala src/view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/storage-view.vala
*translate: vala src/data-view.vala
*translate: vala src/headerbar.vala
*translate: vala src/window.vala
*translate: vala src/performance-view.vala
*translate: vala src/power-view.vala
*translate: vala src/application.vala
*data: data/local
......
src/application.vala
src/data-view.vala
src/gnome-usage.vala
src/headerbar.vala
src/performance-view.vala
src/power-view.vala
src/process-list.vala
......
......@@ -38,6 +38,7 @@ 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} 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)
......
......@@ -2,18 +2,21 @@ namespace Usage
{
public class DataView : View
{
public DataView ()
public DataView (Usage.HeaderBar headerBar)
{
name = "DATA";
base(headerBar);
name = ("DATA");
title = _("Data");
var label1 = new Gtk.Label("Page Data Content.");
add(label1);
}
public override Gtk.Box? getMenuPopover()
public override void updateHeaderBar()
{
return null;
headerBar.clear();
headerBar.showStackSwitcher();
}
}
}
namespace Usage
{
public class HeaderBar : Gtk.HeaderBar
{
private Gtk.StackSwitcher stackSwitcher;
private Gtk.MenuButton menuButton;
public HeaderBar(Gtk.Stack stack)
{
show_close_button = true;
stackSwitcher = new Gtk.StackSwitcher();
stackSwitcher.halign = Gtk.Align.CENTER;
stackSwitcher.set_stack(stack);
menuButton = new Gtk.MenuButton();
menuButton.add(new Gtk.Image.from_icon_name("open-menu-symbolic", Gtk.IconSize.BUTTON));
}
public void setMenuButton(Gtk.Box? popoverBox)
{
var popover = new Gtk.Popover(menuButton);
popover.add(popoverBox);
menuButton.popover = popover;
}
public void showMenuButton()
{
pack_end(menuButton);
}
public void hideMenuButton()
{
remove(menuButton);
}
public void showStackSwitcher()
{
set_custom_title(stackSwitcher);
}
public void clear()
{
set_custom_title(null);
var children = get_children ();
foreach (Gtk.Widget child in children)
remove(child);
}
}
}
\ No newline at end of file
......@@ -8,9 +8,11 @@ namespace Usage
bool showActiveProcess = true;
public PerformanceView()
public PerformanceView(Usage.HeaderBar headerBar)
{
name = "performance";
base(headerBar);
name = "PERFORMANCE";
title = _("Performance");
CPULoadLabel = new Gtk.Label(null);
......@@ -48,30 +50,37 @@ namespace Usage
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");
var 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(new Gtk.Label("Memory"), "RAM");
performanceStack.add_named(new Gtk.Label("Disk I/O"), "DISK");
performanceStack.add_named(new Gtk.Label("Network"), "NETWORK");
CPUButton.clicked.connect(() => {
stack.set_visible_child_name("CPU");
performanceStack.set_visible_child_name("CPU");
constructMenuButtonForCPU();
headerBar.showMenuButton();
});
memoryButton.clicked.connect(() => {
stack.set_visible_child_name("RAM");
performanceStack.set_visible_child_name("RAM");
headerBar.hideMenuButton();
});
diskButton.clicked.connect(() => {
stack.set_visible_child_name("DISK");
performanceStack.set_visible_child_name("DISK");
headerBar.hideMenuButton();
});
networkButton.clicked.connect(() => {
stack.set_visible_child_name("NETWORK");
performanceStack.set_visible_child_name("NETWORK");
headerBar.hideMenuButton();
});
constructMenuButtonForCPU();
var paned = new Gtk.Paned(Gtk.Orientation.HORIZONTAL);
paned.add1(panelBox);
paned.add2(stack);
paned.add2(performanceStack);
add(paned);
Timeout.add(1000, updateProcess);
......@@ -111,41 +120,46 @@ namespace Usage
});
}
public override Gtk.Box? getMenuPopover()
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()
{
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();
});
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(() => {
showActiveProcess = false;
monitor.setProcessMode(SystemMonitor.ProcessMode.USER);
monitor.update();
updateProcess();
});
popoverBox.show_all();
return popoverBox;
headerBar.clear();
headerBar.showMenuButton();
headerBar.showStackSwitcher();
}
}
}
......@@ -2,8 +2,10 @@ namespace Usage
{
public class PowerView : View
{
public PowerView()
public PowerView(Usage.HeaderBar headerBar)
{
base(headerBar);
name = "POWER";
title = _("Power");
......@@ -11,9 +13,10 @@ namespace Usage
add(label1);
}
public override Gtk.Box? getMenuPopover()
public override void updateHeaderBar()
{
return null;
headerBar.clear();
headerBar.showStackSwitcher();
}
}
}
......@@ -2,8 +2,10 @@ namespace Usage
{
public class StorageView : View
{
public StorageView ()
public StorageView (Usage.HeaderBar headerBar)
{
base(headerBar);
name = "STORAGE";
title = _("Storage");
......@@ -11,9 +13,10 @@ namespace Usage
add(label1);
}
public override Gtk.Box? getMenuPopover()
public override void updateHeaderBar()
{
return null;
headerBar.clear();
headerBar.showStackSwitcher();
}
}
}
......@@ -4,13 +4,15 @@ namespace Usage
{
protected SystemMonitor monitor;
public string title;
protected Usage.HeaderBar headerBar;
public View ()
public View (Usage.HeaderBar headerBar)
{
monitor = (GLib.Application.get_default() as Application).monitor;
visible = true;
this.headerBar = headerBar;
}
public abstract Gtk.Box? getMenuPopover();
public abstract void updateHeaderBar();
}
}
namespace Usage
{
public enum UIView
{
/*CPU,
MEMORY,
DISK,
NETWORK,*/
PERFORMANCE,
DATA,
STORAGE,
POWER,
N_VIEWS;
public static UIView[] all()
{
return { PERFORMANCE, DATA, STORAGE, POWER }; /*CPU, MEMORY, DISK, NETWORK,*/
}
}
public class Window : Gtk.ApplicationWindow
{
Gtk.Stack stack;
Usage.HeaderBar headerBar;
public Window(Gtk.Application application)
{
GLib.Object(application : application);
......@@ -28,49 +13,28 @@ namespace Usage
this.set_default_size(800, 500);
this.window_position = Gtk.WindowPosition.CENTER;
var stack = new Gtk.Stack();
var views = new View[UIView.N_VIEWS];
/*views[UIView.CPU] = new CPUView();
views[UIView.MEMORY] = new MemoryView();
views[UIView.DISK] = new DiskView();
views[UIView.NETWORK] = new NetworkView();*/
views[UIView.PERFORMANCE] = new PerformanceView();
views[UIView.DATA] = new DataView();
views[UIView.STORAGE] = new StorageView();
views[UIView.POWER] = new PowerView();
var menuButton = new Gtk.MenuButton();
menuButton.add(new Gtk.Image.from_icon_name("open-menu-symbolic", Gtk.IconSize.BUTTON));
var popover = new Gtk.Popover(menuButton);
stack = new Gtk.Stack();
headerBar = new Usage.HeaderBar(stack);
headerBar.show_close_button = true;
foreach(var view in UIView.all()) {
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;
back_button.hide();
} else {
header_bar.custom_title = null;
header_bar.title = title;
back_button.show();
}
});*/
var views = new View[]
{
new PerformanceView(headerBar),
new DataView(headerBar),
new StorageView(headerBar),
new PowerView(headerBar)
};
var stackSwitcher = new Gtk.StackSwitcher();
stackSwitcher.halign = Gtk.Align.CENTER;
stackSwitcher.stack = stack;
stackSwitcher.set_stack(stack);
foreach(var view in views)
stack.add_titled(view, view.name, view.title);
var headerbar = new Gtk.HeaderBar();
headerbar.show_close_button = true;
headerbar.set_custom_title(stackSwitcher);
menuButton.popover = popover;
headerbar.pack_end(menuButton);
stack.notify["visible-child"].connect (() => {
View visibleView = (View) stack.get_visible_child();
visibleView.updateHeaderBar();
});
set_titlebar(headerbar);
views[0].updateHeaderBar();
set_titlebar(headerBar);
this.add(stack);
}
}
......
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