SailTime/qml/harbour-sailtime.qml
Mikko Ahlroth da24e0ca95 Preparing SailTime for harbour deployment.
Runs in the emulator now but probably won't deploy or pass harbour compliance
yet.
2013-12-12 23:31:24 +02:00

101 lines
2.3 KiB
QML

/**/
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!")
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
}