115 lines
2.8 KiB
QML
115 lines
2.8 KiB
QML
/*
|
||
* © Mikko Ahlroth 2013–2014
|
||
* SailTime is open source software. For licensing information, please check
|
||
* the LICENCE file.
|
||
*/
|
||
|
||
import QtQuick 2.0
|
||
import Sailfish.Silica 1.0
|
||
import harbour.sailtime.UptimeChecker 2.0
|
||
import harbour.sailtime.SysinfoC 1.0
|
||
import harbour.sailtime.Sysload 1.0
|
||
import "cover"
|
||
import "pages"
|
||
import "js/storage.js" as Storage
|
||
|
||
ApplicationWindow
|
||
{
|
||
id: window
|
||
|
||
// Refresh whenever app is activated
|
||
onApplicationActiveChanged: {
|
||
if (applicationActive) {
|
||
updateDisplay();
|
||
}
|
||
}
|
||
|
||
FirstPage {
|
||
id: firstpage
|
||
}
|
||
|
||
SecondPage {
|
||
id: secondpage
|
||
onChangeTimer: {
|
||
if (enabled) {
|
||
//console.log("Starting timer")
|
||
refreshTimer.start();
|
||
}
|
||
else {
|
||
//console.log("Stopping timer")
|
||
refreshTimer.stop();
|
||
}
|
||
}
|
||
|
||
onChangeInterval: {
|
||
//console.log("Timer interval: " + interval)
|
||
refreshTimer.interval = interval * 60 * 1000;
|
||
}
|
||
|
||
onChangeRecord: {
|
||
firstpage.setRecordEnabled(enabled);
|
||
}
|
||
}
|
||
|
||
CoverPage {
|
||
id: coverpage
|
||
}
|
||
|
||
Timer {
|
||
id: refreshTimer
|
||
interval: secondpage.refreshInterval * 60 * 1000
|
||
onTriggered: {
|
||
//console.log("Timer fired!")
|
||
//console.log("Time is now " + new Date());
|
||
updateDisplay()
|
||
}
|
||
repeat: true
|
||
running: secondpage.timerEnable
|
||
}
|
||
|
||
function updateDisplay() {
|
||
Storage.db = Storage.connect();
|
||
|
||
var sysinfo = checker.fetchUptime();
|
||
var uptime_s = sysinfo.uptime;
|
||
|
||
var days = Math.floor(uptime_s / 84600);
|
||
var hours = Math.floor(uptime_s / 3600 % 24);
|
||
var minutes = Math.floor(uptime_s / 60 % 60);
|
||
|
||
var record = parseInt(Storage.readSetting(Storage.db, "record", 0));
|
||
var rDays = Math.floor(record / 84600);
|
||
var rHours = Math.floor(record / 3600 % 24);
|
||
var rMinutes = Math.floor(record / 60 % 60);
|
||
|
||
var uptime = {
|
||
"days": days,
|
||
"hours": hours,
|
||
"minutes": minutes,
|
||
"load1": sysinfo.loads.avg_1,
|
||
"load5": sysinfo.loads.avg_5,
|
||
"load15": sysinfo.loads.avg_15,
|
||
"record": record,
|
||
"rDays": rDays,
|
||
"rHours": rHours,
|
||
"rMinutes": rMinutes,
|
||
}
|
||
|
||
firstpage.updatePage(sysinfo, uptime);
|
||
coverpage.updateCover(uptime);
|
||
|
||
var recordEnable = Storage.readSetting(Storage.db, "recordEnable", false);
|
||
|
||
// Update new record to db if feature is activated
|
||
if (recordEnable && (uptime_s >= record)) {
|
||
Storage.storeSetting(Storage.db, "record", uptime_s);
|
||
}
|
||
}
|
||
|
||
UptimeChecker {
|
||
id: checker
|
||
}
|
||
|
||
initialPage: firstpage
|
||
cover: coverpage
|
||
}
|