From 28ed6b936d1af49d9a2859700db7e27d7c3b0d5e Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sat, 5 Jan 2019 22:02:01 +0200 Subject: [PATCH] Check battery level automatically every minute and play sound when necessary --- harbour-batterybuddy.pro | 12 ++++++------ qml/pages/MainPage.qml | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/harbour-batterybuddy.pro b/harbour-batterybuddy.pro index 74a5cba..7e71d02 100644 --- a/harbour-batterybuddy.pro +++ b/harbour-batterybuddy.pro @@ -31,15 +31,15 @@ DISTFILES += qml/harbour-batterybuddy.qml \ # Begin: include sound files -OTHER_FILES += sounds/upperLimit.ogg \ - sounds/lowerLimit.ogg \ +#OTHER_FILES += sounds/upperLimit.ogg \ +# sounds/lowerLimit.ogg \ -DEPLOYMENT_PATH = /usr/share/$${TARGET} +#DEPLOYMENT_PATH = /usr/share/$${TARGET} -sounds.files = sounds -sounds.path = $${DEPLOYMENT_PATH} +#sounds.files = sounds +#sounds.path = $${DEPLOYMENT_PATH} -INSTALLS += sounds +#INSTALLS += sounds # End: include sound files diff --git a/qml/pages/MainPage.qml b/qml/pages/MainPage.qml index 389fe56..aa566d4 100644 --- a/qml/pages/MainPage.qml +++ b/qml/pages/MainPage.qml @@ -1,4 +1,5 @@ import QtQuick 2.0 +import QtMultimedia 5.6 import Sailfish.Silica 1.0 Page { @@ -7,6 +8,32 @@ Page { // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All + MediaPlayer { + id: alertLow + audioRole: MediaPlayer.NotificationRole + autoLoad: true + source: settings.lowAlertFile + } + + MediaPlayer { + id: alertHigh + audioRole: MediaPlayer.NotificationRole + autoLoad: true + source: settings.highAlertFile + } + + Timer { + interval: 60000 + running: true + repeat: true + onTriggered: { + if(battery.charge <= settings.lowerLimit && battery.charging === false) + alertLow.play() + else if(battery.charge >= settings.upperLimit && battery.charging === true) + alertLow.play() + } + } + // To enable PullDownMenu, place our content in a SilicaFlickable SilicaFlickable { anchors.fill: parent