SailTime/qml/harbour-sailtime.qml

135 lines
3.4 KiB
QML
Raw Permalink Normal View History

2013-12-15 21:08:15 +00:00
/*
* © Mikko Ahlroth 20132014
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
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"
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) {
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")
refreshTimer.start();
2013-12-12 21:08:36 +00:00
}
else {
2013-12-15 21:13:03 +00:00
//console.log("Stopping timer")
refreshTimer.stop();
2013-12-12 21:08:36 +00:00
}
}
onChangeInterval: {
2013-12-15 21:13:03 +00:00
//console.log("Timer interval: " + interval)
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!")
//console.log("Time is now " + new Date());
2013-12-12 21:08:36 +00:00
updateDisplay()
}
repeat: true
running: secondpage.timerEnable
}
function updateDisplay() {
Storage.db = Storage.connect();
var sysinfo = checker.fetchUptime();
var uptime_s = sysinfo.uptime;
var uptime_d = divideUptime(uptime_s);
var record = parseInt(Storage.readSetting(Storage.db, "record", 0));
var record_d = divideUptime(record);
2013-12-12 21:08:36 +00:00
var uptime = {
"days": uptime_d.days,
"hours": uptime_d.hours,
"minutes": uptime_d.minutes,
"load1": sysinfo.loads.avg_1,
"load5": sysinfo.loads.avg_5,
"load15": sysinfo.loads.avg_15,
"record": record,
"rDays": record_d.days,
"rHours": record_d.hours,
"rMinutes": record_d.minutes,
2013-12-12 21:08:36 +00:00
}
firstpage.updatePage(sysinfo, uptime);
2013-12-12 21:08:36 +00:00
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);
}
2013-12-12 21:08:36 +00:00
}
// Divide uptime to days, hours and minutes
function divideUptime(seconds) {
var days = Math.floor(seconds / 86400);
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
}