SailTime/qml/harbour-sailtime.qml

106 lines
2.5 KiB
QML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Mikko Ahlroth 20132014
* 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 1.0
import "cover"
import "pages"
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
}
}
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() {
var uptime_str = checker.fetchUptime();
uptime_str = uptime_str.replace(/^\s+|\s+$/g, '');
var uptime_re = /\d+:\d\d:\d\d up\s+(?:(\d+) days?,\s+)?(?:(?:(\d+):(\d+))|(?:(\d?\d) min)),\s+(\d+) users?,\s+load average: (\d+).(\d\d), (\d+).(\d\d), (\d+).(\d\d)/;
var match = uptime_str.match(uptime_re)
//console.log(uptime_str)
var days = match[1]
if (days === undefined) {
days = 0
}
var hours = match[2]
if (hours === undefined) {
hours = 0
}
var minutes = match[3]
if (minutes === undefined) {
minutes = match[4]
}
var uptime = {
"days": days,
"hours": hours,
"minutes": minutes,
"users": match[5],
"load1": parseInt(match[6]) + match[7] / 100,
"load5": parseInt(match[8]) + match[9] / 100,
"load15": parseInt(match[10]) + match[11] / 100,
}
firstpage.updatePage(uptime);
coverpage.updateCover(uptime);
}
UptimeChecker {
id: checker
}
initialPage: firstpage
cover: coverpage
}