2013-12-15 21:08:15 +00:00
|
|
|
|
/*
|
2014-01-27 14:24:16 +00:00
|
|
|
|
* © Mikko Ahlroth 2013–2014
|
2013-12-15 21:08:15 +00:00
|
|
|
|
* SailTime is open source software. For licensing information, please check
|
|
|
|
|
* the LICENCE file.
|
|
|
|
|
*/
|
2013-12-12 21:08:36 +00:00
|
|
|
|
|
|
|
|
|
import QtQuick 2.0
|
|
|
|
|
import Sailfish.Silica 1.0
|
2014-02-01 18:22:34 +00:00
|
|
|
|
import harbour.sailtime.UptimeChecker 2.0
|
|
|
|
|
import harbour.sailtime.SysinfoC 1.0
|
|
|
|
|
import harbour.sailtime.Sysload 1.0
|
2013-12-12 21:08:36 +00:00
|
|
|
|
import "cover"
|
|
|
|
|
import "pages"
|
2014-02-06 21:18:54 +00:00
|
|
|
|
import "js/storage.js" as Storage
|
2013-12-12 21:08:36 +00:00
|
|
|
|
|
|
|
|
|
ApplicationWindow
|
|
|
|
|
{
|
|
|
|
|
id: window
|
|
|
|
|
|
|
|
|
|
// Refresh whenever app is activated
|
|
|
|
|
onApplicationActiveChanged: {
|
|
|
|
|
if (applicationActive) {
|
2014-02-06 21:18:54 +00:00
|
|
|
|
updateDisplay();
|
2013-12-12 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FirstPage {
|
|
|
|
|
id: firstpage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SecondPage {
|
|
|
|
|
id: secondpage
|
|
|
|
|
onChangeTimer: {
|
|
|
|
|
if (enabled) {
|
2013-12-15 21:13:03 +00:00
|
|
|
|
//console.log("Starting timer")
|
2014-02-06 21:18:54 +00:00
|
|
|
|
refreshTimer.start();
|
2013-12-12 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-12-15 21:13:03 +00:00
|
|
|
|
//console.log("Stopping timer")
|
2014-02-06 21:18:54 +00:00
|
|
|
|
refreshTimer.stop();
|
2013-12-12 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChangeInterval: {
|
2013-12-15 21:13:03 +00:00
|
|
|
|
//console.log("Timer interval: " + interval)
|
2014-02-06 21:18:54 +00:00
|
|
|
|
refreshTimer.interval = interval * 60 * 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChangeRecord: {
|
|
|
|
|
firstpage.setRecordEnabled(enabled);
|
2013-12-12 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CoverPage {
|
|
|
|
|
id: coverpage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
|
id: refreshTimer
|
|
|
|
|
interval: secondpage.refreshInterval * 60 * 1000
|
|
|
|
|
onTriggered: {
|
2013-12-15 21:13:03 +00:00
|
|
|
|
//console.log("Timer fired!")
|
2014-01-27 14:24:16 +00:00
|
|
|
|
//console.log("Time is now " + new Date());
|
2013-12-12 21:08:36 +00:00
|
|
|
|
updateDisplay()
|
|
|
|
|
}
|
|
|
|
|
repeat: true
|
|
|
|
|
running: secondpage.timerEnable
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateDisplay() {
|
2014-02-06 21:18:54 +00:00
|
|
|
|
Storage.db = Storage.connect();
|
|
|
|
|
|
2014-02-01 18:22:34 +00:00
|
|
|
|
var sysinfo = checker.fetchUptime();
|
|
|
|
|
var uptime_s = sysinfo.uptime;
|
2014-02-11 14:13:57 +00:00
|
|
|
|
var uptime_d = divideUptime(uptime_s);
|
2014-02-06 21:18:54 +00:00
|
|
|
|
|
2014-02-06 21:34:54 +00:00
|
|
|
|
var record = parseInt(Storage.readSetting(Storage.db, "record", 0));
|
2014-02-11 14:13:57 +00:00
|
|
|
|
var record_d = divideUptime(record);
|
2013-12-12 21:08:36 +00:00
|
|
|
|
|
|
|
|
|
var uptime = {
|
2014-02-11 14:13:57 +00:00
|
|
|
|
"days": uptime_d.days,
|
|
|
|
|
"hours": uptime_d.hours,
|
|
|
|
|
"minutes": uptime_d.minutes,
|
2014-02-01 18:22:34 +00:00
|
|
|
|
"load1": sysinfo.loads.avg_1,
|
|
|
|
|
"load5": sysinfo.loads.avg_5,
|
|
|
|
|
"load15": sysinfo.loads.avg_15,
|
2014-02-06 21:18:54 +00:00
|
|
|
|
"record": record,
|
2014-02-11 14:13:57 +00:00
|
|
|
|
"rDays": record_d.days,
|
|
|
|
|
"rHours": record_d.hours,
|
|
|
|
|
"rMinutes": record_d.minutes,
|
2013-12-12 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-05 20:33:34 +00:00
|
|
|
|
firstpage.updatePage(sysinfo, uptime);
|
2013-12-12 21:08:36 +00:00
|
|
|
|
coverpage.updateCover(uptime);
|
2014-02-06 21:18:54 +00:00
|
|
|
|
|
2014-02-06 21:34:54 +00:00
|
|
|
|
var recordEnable = Storage.readSetting(Storage.db, "recordEnable", false);
|
|
|
|
|
|
2014-02-06 21:18:54 +00:00
|
|
|
|
// Update new record to db if feature is activated
|
2014-02-06 21:34:54 +00:00
|
|
|
|
if (recordEnable && (uptime_s >= record)) {
|
2014-02-06 21:18:54 +00:00
|
|
|
|
Storage.storeSetting(Storage.db, "record", uptime_s);
|
|
|
|
|
}
|
2013-12-12 21:08:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 14:13:57 +00:00
|
|
|
|
// Divide uptime to days, hours and minutes
|
|
|
|
|
function divideUptime(seconds) {
|
2014-02-24 12:49:38 +00:00
|
|
|
|
var days = Math.floor(seconds / 86400);
|
2014-02-11 14:13:57 +00:00
|
|
|
|
var hours = Math.floor(seconds / 3600 % 24);
|
|
|
|
|
var minutes = Math.floor(seconds / 60 % 60);
|
|
|
|
|
return {
|
|
|
|
|
"days": days,
|
|
|
|
|
"hours": hours,
|
|
|
|
|
"minutes": minutes
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return formatted language strings with plural forms
|
|
|
|
|
function formatUptime(days, hours, minutes) {
|
|
|
|
|
var days_str = days + " day" + ((days !== 1)? "s" : "");
|
|
|
|
|
var hours_str = hours + " h";
|
|
|
|
|
var minutes_str = minutes + " min";
|
|
|
|
|
return {
|
|
|
|
|
"days": days_str,
|
|
|
|
|
"hours": hours_str,
|
|
|
|
|
"minutes": minutes_str
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-12 21:08:36 +00:00
|
|
|
|
UptimeChecker {
|
|
|
|
|
id: checker
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialPage: firstpage
|
|
|
|
|
cover: coverpage
|
|
|
|
|
}
|