Implement uptime record feature and setting to toggle it.

This commit is contained in:
Mikko Ahlroth 2014-02-06 23:18:54 +02:00
parent 37567a777a
commit a1a559ba3f
5 changed files with 113 additions and 33 deletions

View file

@ -11,6 +11,7 @@ import harbour.sailtime.SysinfoC 1.0
import harbour.sailtime.Sysload 1.0 import harbour.sailtime.Sysload 1.0
import "cover" import "cover"
import "pages" import "pages"
import "js/storage.js" as Storage
ApplicationWindow ApplicationWindow
{ {
@ -19,7 +20,7 @@ ApplicationWindow
// Refresh whenever app is activated // Refresh whenever app is activated
onApplicationActiveChanged: { onApplicationActiveChanged: {
if (applicationActive) { if (applicationActive) {
updateDisplay() updateDisplay();
} }
} }
@ -32,17 +33,21 @@ ApplicationWindow
onChangeTimer: { onChangeTimer: {
if (enabled) { if (enabled) {
//console.log("Starting timer") //console.log("Starting timer")
refreshTimer.start() refreshTimer.start();
} }
else { else {
//console.log("Stopping timer") //console.log("Stopping timer")
refreshTimer.stop() refreshTimer.stop();
} }
} }
onChangeInterval: { onChangeInterval: {
//console.log("Timer interval: " + interval) //console.log("Timer interval: " + interval)
refreshTimer.interval = interval * 60 * 1000 refreshTimer.interval = interval * 60 * 1000;
}
onChangeRecord: {
firstpage.setRecordEnabled(enabled);
} }
} }
@ -63,13 +68,19 @@ ApplicationWindow
} }
function updateDisplay() { function updateDisplay() {
Storage.db = Storage.connect();
var sysinfo = checker.fetchUptime(); var sysinfo = checker.fetchUptime();
var uptime_s = sysinfo.uptime; var uptime_s = sysinfo.uptime;
var days = Math.floor(uptime_s / 84600); var days = Math.floor(uptime_s / 84600);
var hours = Math.floor(uptime_s / 3600 % 24); var hours = Math.floor(uptime_s / 3600 % 24);
var minutes = Math.floor(uptime_s / 60 % 60); var minutes = Math.floor(uptime_s / 60 % 60);
var seconds = Math.floor(uptime_s % 60);
var record = 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 = { var uptime = {
"days": days, "days": days,
@ -78,10 +89,19 @@ ApplicationWindow
"load1": sysinfo.loads.avg_1, "load1": sysinfo.loads.avg_1,
"load5": sysinfo.loads.avg_5, "load5": sysinfo.loads.avg_5,
"load15": sysinfo.loads.avg_15, "load15": sysinfo.loads.avg_15,
"record": record,
"rDays": rDays,
"rHours": rHours,
"rMinutes": rMinutes,
} }
firstpage.updatePage(sysinfo, uptime); firstpage.updatePage(sysinfo, uptime);
coverpage.updateCover(uptime); coverpage.updateCover(uptime);
// Update new record to db if feature is activated
if (Storage.readSetting(Storage.db, "recordEnable", false) && uptime_s >= record) {
Storage.storeSetting(Storage.db, "record", uptime_s);
}
} }
UptimeChecker { UptimeChecker {

View file

@ -23,6 +23,15 @@ Page {
function updatePage(sysinfo, uptime) { function updatePage(sysinfo, uptime) {
days.text = uptime.days + " days"; days.text = uptime.days + " days";
time.text = uptime.hours + " h " + uptime.minutes + " min"; time.text = uptime.hours + " h " + uptime.minutes + " min";
if (sysinfo.uptime >= uptime.record) {
recordLabel.text = "Making new record!";
}
else {
recordLabel.text = "Record: " + uptime.rDays + " days " + uptime.rHours + " h " + uptime.rMinutes + " min";
}
load1.text = uptime.load1.toFixed(2); load1.text = uptime.load1.toFixed(2);
load5.text = uptime.load5.toFixed(2); load5.text = uptime.load5.toFixed(2);
load15.text = uptime.load15.toFixed(2); load15.text = uptime.load15.toFixed(2);
@ -60,9 +69,16 @@ Page {
// Processes amount // Processes amount
procs.text = sysinfo.procs + " processes"; procs.text = sysinfo.procs + " processes + threads";
} }
function setRecordEnabled(enable)
{
recordLabel.visible = enable;
}
// Scale memory sizes to human readable bytes according to mem_unit // Scale memory sizes to human readable bytes according to mem_unit
// Return memory size in bytes and prefix // Return memory size in bytes and prefix
function scaleMem(mem, mem_unit) { function scaleMem(mem, mem_unit) {
@ -138,6 +154,16 @@ Page {
font.pixelSize: Theme.fontSizeLarge font.pixelSize: Theme.fontSizeLarge
} }
Label {
id: recordLabel
anchors.horizontalCenter: parent.horizontalCenter
text: ""
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeMedium
visible: false
}
PageHeader { PageHeader {
title: "Load averages" title: "Load averages"
} }

View file

@ -14,6 +14,7 @@ Dialog {
signal changeTimer(bool enabled) signal changeTimer(bool enabled)
signal changeInterval(int interval) signal changeInterval(int interval)
signal changeRecord(bool enabled)
property alias timerEnable : timerEnable property alias timerEnable : timerEnable
property alias refreshInterval : intervalSlider property alias refreshInterval : intervalSlider
@ -29,7 +30,10 @@ Dialog {
} }
timerEnable.checked = Storage.readSetting(Storage.db, timerEnable.checked = Storage.readSetting(Storage.db,
"timerEnable", false) "timerEnable", false);
recordEnable.checked = Storage.readSetting(Storage.db,
"recordEnable", false);
} }
// Load values when app is started to start timers if needed // Load values when app is started to start timers if needed
@ -37,6 +41,7 @@ Dialog {
getSettings(); getSettings();
changeTimer(timerEnable.checked); changeTimer(timerEnable.checked);
changeInterval(intervalSlider.value); changeInterval(intervalSlider.value);
changeRecord(recordEnable.checked);
} }
onOpened: { onOpened: {
@ -46,13 +51,18 @@ Dialog {
onAccepted: { onAccepted: {
Storage.storeSetting(Storage.db, Storage.storeSetting(Storage.db,
"timerEnable", "timerEnable",
timerEnable.checked) timerEnable.checked);
changeTimer(timerEnable.checked) changeTimer(timerEnable.checked);
Storage.storeSetting(Storage.db, Storage.storeSetting(Storage.db,
"interval", "interval",
intervalSlider.value) intervalSlider.value);
changeInterval(intervalSlider.value) changeInterval(intervalSlider.value);
Storage.storeSetting(Storage.db,
"recordEnable",
recordEnable.checked);
changeRecord(recordEnable.checked);
} }
SilicaFlickable { SilicaFlickable {
@ -65,8 +75,8 @@ Dialog {
spacing: Theme.paddingLarge spacing: Theme.paddingLarge
DialogHeader { DialogHeader {
title: "Settings" title: "Save"
acceptText: "Save" acceptText: "Settings"
} }
TextSwitch { TextSwitch {
@ -85,6 +95,30 @@ Dialog {
valueText: value + " min" valueText: value + " min"
width: parent.width - Theme.paddingLarge * 2 width: parent.width - Theme.paddingLarge * 2
} }
Label {
font.pixelSize: Theme.fontSizeSmall
color: Theme.secondaryColor
text: "Note that due to the power saving features of Sailfish OS, the update may not occur at the specified interval when the device is locked."
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - Theme.paddingLarge * 2
wrapMode: Text.WordWrap
}
TextSwitch {
id: recordEnable
checked: false
text: "Store uptime record"
}
Label {
font.pixelSize: Theme.fontSizeSmall
color: Theme.secondaryColor
text: "Record is stored whenever the uptime is updated."
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - Theme.paddingLarge * 2
wrapMode: Text.WordWrap
}
} }
} }
} }

View file

@ -21,10 +21,10 @@ URL: http://example.org/
Source0: %{name}-%{version}.tar.bz2 Source0: %{name}-%{version}.tar.bz2
Source100: harbour-sailtime.yaml Source100: harbour-sailtime.yaml
Requires: sailfishsilica-qt5 >= 0.10.9 Requires: sailfishsilica-qt5 >= 0.10.9
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(sailfishapp) >= 0.0.10 BuildRequires: pkgconfig(sailfishapp) >= 0.0.10
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: desktop-file-utils BuildRequires: desktop-file-utils
%description %description
@ -64,13 +64,13 @@ desktop-file-install --delete-original \
%files %files
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_bindir}
%{_datadir}/%{name}/qml
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/86x86/apps/%{name}.png
/usr/bin
/usr/share/harbour-sailtime
/usr/share/applications
/usr/share/icons/hicolor/86x86/apps /usr/share/icons/hicolor/86x86/apps
/usr/share/applications
/usr/share/harbour-sailtime
/usr/bin
%{_datadir}/icons/hicolor/86x86/apps/%{name}.png
%{_datadir}/applications/%{name}.desktop
%{_datadir}/%{name}/qml
%{_bindir}
# >> files # >> files
# << files # << files

View file

@ -14,19 +14,19 @@ Description: |-
Configure: none Configure: none
Builder: qtc5 Builder: qtc5
PkgConfigBR: PkgConfigBR:
- Qt5Quick
- Qt5Qml
- Qt5Core
- sailfishapp >= 0.0.10 - sailfishapp >= 0.0.10
- Qt5Core
- Qt5Qml
- Qt5Quick
Requires: Requires:
- sailfishsilica-qt5 >= 0.10.9 - sailfishsilica-qt5 >= 0.10.9
Files: Files:
- '%{_bindir}'
- '%{_datadir}/%{name}/qml'
- '%{_datadir}/applications/%{name}.desktop'
- '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png'
- /usr/bin
- /usr/share/harbour-sailtime
- /usr/share/applications
- /usr/share/icons/hicolor/86x86/apps - /usr/share/icons/hicolor/86x86/apps
- /usr/share/applications
- /usr/share/harbour-sailtime
- /usr/bin
- '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png'
- '%{_datadir}/applications/%{name}.desktop'
- '%{_datadir}/%{name}/qml'
- '%{_bindir}'
PkgBR: [] PkgBR: []