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

Implemented API for settings.

parent 4e1bb2de
No preview for this file type
......@@ -38,6 +38,7 @@ c_library: gtop-2.0 ${CMAKE_SOURCE_DIR}/external/rg/librg.a ${CMAKE_SOURCE_DIR}/
*vala_source: performance-view.vala
*vala_source: power-view.vala
*vala_source: process-list.vala
*vala_source: settings.vala
*vala_source: storage-view.vala
*vala_source: system-monitor.vala
*vala_source: view.vala
......@@ -48,26 +49,27 @@ h_folder: /usr/include/libgtop-2.0
*po: po
*translate: vala src/cpu-sub-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/performance-view.vala
*translate: vala src/process-list.vala
*translate: vala src/header-bar.vala
*translate: vala src/memory-graph-table.vala
*translate: vala src/cpu-sub-view.vala
*translate: vala src/network-sub-view.vala
*translate: vala src/cpu-graph.vala
*translate: vala src/performance-view.vala
*translate: vala src/graph-stack-switcher.vala
*translate: vala src/memory-graph-table.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/window.vala
*translate: vala src/view.vala
*translate: vala src/graph-switcher-button.vala
*translate: vala src/disk-sub-view.vala
*translate: vala src/memory-sub-view.vala
*translate: vala src/disk-sub-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/graph-stack-switcher.vala
*translate: vala src/cpu-graph-table.vala
*translate: vala src/settings.vala
*translate: vala src/graph-switcher-button.vala
*translate: vala src/application.vala
*translate: vala src/memory-graph.vala
*translate: vala src/storage-view.vala
*translate: vala src/power-view.vala
*translate: vala src/application.vala
*translate: vala src/data-view.vala
*data: data/local
......
......@@ -15,6 +15,7 @@ src/network-sub-view.vala
src/performance-view.vala
src/power-view.vala
src/process-list.vala
src/settings.vala
src/storage-view.vala
src/system-monitor.vala
src/view.vala
......
......@@ -52,6 +52,7 @@ set (APP_SOURCES ${APP_SOURCES} network-sub-view.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} settings.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,13 +4,15 @@ namespace Usage
{
public class Application : Gtk.Application
{
public Settings settings;
public Window window;
public SystemMonitor monitor;
public Application ()
{
application_id = "org.gnome.usage";
monitor = new SystemMonitor(1000);
settings = new Settings();
monitor = new SystemMonitor();
}
public override void activate()
......
......@@ -6,11 +6,12 @@ namespace Usage {
{
bool multi;
public CpuGraphTable (uint timespan, uint max_samples, bool multi = false)
public CpuGraphTable (bool multi = false)
{
this.multi = multi;
set_timespan (timespan * 1000);
set_max_samples (max_samples);
var settings = (GLib.Application.get_default() as Application).settings;
set_timespan (settings.graph_timespan * 1000);
set_max_samples (settings.graph_max_samples);
if(multi)
{
......@@ -26,13 +27,7 @@ namespace Usage {
add_column(column);
}
var interval = timespan / (max_samples - 1);
var monitor = (GLib.Application.get_default() as Application).monitor;
//TODO change and move to settings
if(interval < monitor.get_update_graph_interval())
monitor.set_update_graph_interval(interval);
Timeout.add(timespan / (max_samples - 1), update_data);
Timeout.add(settings.graph_update_interval, update_data);
}
bool update_data()
......
......@@ -6,11 +6,11 @@ namespace Usage
{
private static CpuGraphTable table;
public CpuGraphSingle (uint timespan, uint max_samples)
public CpuGraphSingle ()
{
if(table == null)
{
table = new CpuGraphTable(timespan, max_samples, false);
table = new CpuGraphTable(false);
set_table(table);
}
else
......@@ -39,11 +39,11 @@ namespace Usage
private static CpuGraphTable table;
public CpuGraphMulti (uint timespan, uint max_samples)
public CpuGraphMulti ()
{
if(table == null)
{
table = new CpuGraphTable(timespan, max_samples, true);
table = new CpuGraphTable(true);
set_table(table);
}
else
......
......@@ -25,7 +25,7 @@ namespace Usage
process_list_box = new ProcessList();
var cpu_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var cpu_graph = new CpuGraphMulti(60000, 60);
var cpu_graph = new CpuGraphMulti();
var cpu_graph_frame = new Gtk.Frame(null);
cpu_graph_frame.height_request = 200;
cpu_graph_frame.margin_start = margin_side;
......
......@@ -4,28 +4,28 @@ namespace Usage
{
public GraphSwitcherButton.processor(string label)
{
Rg.Graph processor_graph = new CpuGraphSingle(60000, 60);
Rg.Graph processor_graph = new CpuGraphSingle();
child = createContent(processor_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
public GraphSwitcherButton.memory(string label)
{
Rg.Graph memory_graph = new MemoryGraph(60000, 60);
Rg.Graph memory_graph = new MemoryGraph();
child = createContent(memory_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
public GraphSwitcherButton.disk(string label)
{
Rg.Graph disk_graph = new CpuGraphSingle(60000, 60);
Rg.Graph disk_graph = new CpuGraphSingle();
child = createContent(disk_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
public GraphSwitcherButton.network(string label)
{
Rg.Graph network_graph = new CpuGraphSingle(60000, 60);
Rg.Graph network_graph = new CpuGraphSingle();
child = createContent(network_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
......
......@@ -7,23 +7,19 @@ namespace Usage {
public const int column_ram_id = 0;
public const int column_swap_id = 1;
public MemoryGraphTable (uint timespan, uint max_samples)
public MemoryGraphTable ()
{
set_timespan (timespan * 1000);
set_max_samples (max_samples);
var settings = (GLib.Application.get_default() as Application).settings;
set_timespan (settings.graph_timespan * 1000);
set_max_samples (settings.graph_max_samples);
var column_ram = new Rg.Column("RAM", Type.from_name("gdouble"));
add_column(column_ram);
var column_swap = new Rg.Column("SWAP", Type.from_name("gdouble"));
add_column(column_swap);
var interval = timespan / (max_samples - 1);
var monitor = (GLib.Application.get_default() as Application).monitor;
//TODO change and move to settings
if(interval < monitor.get_update_graph_interval())
monitor.set_update_graph_interval(interval);
Timeout.add(timespan / (max_samples - 1), update_data);
Timeout.add(settings.graph_update_interval, update_data);
}
bool update_data()
......
......@@ -6,11 +6,11 @@ namespace Usage
{
private static MemoryGraphTable table;
public MemoryGraph (uint timespan, uint max_samples)
public MemoryGraph ()
{
if(table == null)
{
table = new MemoryGraphTable(timespan, max_samples);
table = new MemoryGraphTable();
set_table(table);
}
else
......
......@@ -24,7 +24,7 @@ namespace Usage
process_list_box = new ProcessList();
var memory_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var memory_graph = new MemoryGraph(60000, 60);
var memory_graph = new MemoryGraph();
var memory_graph_frame = new Gtk.Frame(null);
memory_graph_frame.height_request = 200;
memory_graph_frame.margin_start = margin_side;
......
using Gtk;
namespace Usage {
public class Settings : Object{
public uint graph_timespan { get; set; default = 60000;}
public uint graph_max_samples { get; set; default = 60; }
public uint graph_update_interval { get { return graph_timespan / (graph_max_samples - 1); }}
public uint list_update_interval { get; set; default = 1000; }
}
}
......@@ -25,9 +25,6 @@ namespace Usage
public double swap_usage { get; private set; }
public double swap_usage_graph { get; private set; }
uint update_graph_interval = 0;
uint update_interval = 0;
uint64 cpu_last_used = 0;
uint64 cpu_last_used_graph = 0;
uint64 cpu_last_total = 0;
......@@ -38,7 +35,6 @@ namespace Usage
uint64[] x_cpu_last_total;
uint64[] x_cpu_last_total_graph;
bool change_graph_timeout = false;
bool change_timeout = false;
HashTable<uint, Process> process_table;
......@@ -143,9 +139,10 @@ namespace Usage
x_cpu_last_used = x_cpu_used;
x_cpu_last_total = cpu_data.xcpu_total;
if(change_graph_timeout)
if(change_timeout)
{
Timeout.add(update_interval, update_data);
change_timeout = false;
Timeout.add((GLib.Application.get_default() as Application).settings.list_update_interval, update_data);
return false;
}
......@@ -183,16 +180,18 @@ namespace Usage
x_cpu_last_used_graph = x_cpu_used;
x_cpu_last_total_graph = cpu_data.xcpu_total;
if(change_graph_timeout)
if(change_timeout)
{
Timeout.add(update_graph_interval, update_graph_data);
change_timeout = false;
Timeout.add((GLib.Application.get_default() as Application).settings.graph_update_interval, update_graph_data);
return false;
}
return true;
}
public void set_update_graph_interval(uint miliseconds)
/*public void set_update_graph_interval(uint miliseconds)
{
change_graph_timeout = true;
update_graph_interval = miliseconds;
......@@ -212,14 +211,14 @@ namespace Usage
public uint get_update_interval()
{
return update_interval;
}
}*/
public List<unowned Process> get_processes()
{
return process_table.get_values();
}
public SystemMonitor(int update_interval)
public SystemMonitor()
{
GTop.init();
......@@ -230,9 +229,15 @@ namespace Usage
x_cpu_last_total = new uint64[get_num_processors()];
x_cpu_last_total_graph = new uint64[get_num_processors()];
process_table = new HashTable<uint, Process>(direct_hash, direct_equal);
this.update_interval = update_interval;
Timeout.add(update_interval, update_data);
Timeout.add(100, update_graph_data);
var settings = (GLib.Application.get_default() as Application).settings;
settings.notify.connect(() => {
change_timeout = true;
});
Timeout.add(settings.list_update_interval, update_data);
Timeout.add(settings.graph_update_interval, update_graph_data);
}
}
}
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