Difetto: le scritte leggevano lo stato con funzioni per indice (phaseTextAt, remainTextAt, ...). In QML un binding che chiama una funzione non registra nessuna dipendenza, quindi veniva valutato una volta sola — all'apertura, prima che i dati arrivassero — e non si aggiornava mai: si vedevano i nomi delle macchine ma nessuno stato. Correzione: il client espone l'elenco come DATO (QVariantList di mappe, proprieta' devices con NOTIFY) piu' la mappa active per la copertina; le schermate leggono modelData.*, e ricevono devicesChanged ad ogni aggiornamento di stato. Verificato nel pacchetto: le chiavi nuove sono presenti, le funzioni rimosse non ci sono piu', MainPage legge modelData.
301 lines
12 KiB
QML
301 lines
12 KiB
QML
import QtQuick 2.2
|
|
import Sailfish.Silica 1.0
|
|
import "../js/status.js" as Status
|
|
|
|
// Prima schermata. Due volti:
|
|
// * senza chiave di accesso -> si chiede una volta sola (qui, non nelle
|
|
// impostazioni) e poi non se ne parla piu';
|
|
// * con la chiave -> l'elenco delle macchine, ognuna col suo stato.
|
|
//
|
|
// L'elenco arriva come DATO (api.devices), non con funzioni di lettura: solo
|
|
// cosi' le scritte si aggiornano quando lo stato cambia.
|
|
Page {
|
|
id: page
|
|
|
|
allowedOrientations: Orientation.All
|
|
|
|
// La macchina si aggiorna solo mentre la schermata e' in primo piano:
|
|
// niente ponte, niente servizio che gira di nascosto.
|
|
onStatusChanged: {
|
|
if (status === PageStatus.Active)
|
|
api.startPolling()
|
|
else
|
|
api.stopPolling()
|
|
}
|
|
|
|
SilicaFlickable {
|
|
anchors.fill: parent
|
|
contentHeight: column.height + Theme.paddingLarge
|
|
|
|
PullDownMenu {
|
|
MenuItem {
|
|
text: qsTr("Refresh")
|
|
enabled: api.configured
|
|
onClicked: api.refresh()
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Settings")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
|
}
|
|
}
|
|
|
|
Column {
|
|
id: column
|
|
width: parent.width
|
|
spacing: Theme.paddingMedium
|
|
|
|
PageHeader {
|
|
title: qsTr("My machines")
|
|
description: api.configured
|
|
? (api.busy ? qsTr("Updating…") : qsTr("%1 found").arg(api.deviceCount))
|
|
: qsTr("First setup")
|
|
}
|
|
|
|
// ---------------------------------------------------------------
|
|
// Primo avvio: le credenziali si chiedono qui, una volta sola.
|
|
// ---------------------------------------------------------------
|
|
Column {
|
|
width: parent.width
|
|
visible: !api.configured
|
|
spacing: Theme.paddingMedium
|
|
|
|
Label {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
wrapMode: Text.WordWrap
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
text: qsTr("The access token comes from connect-pat.lgthinq.com and stays on this phone only. If LG starts refusing it, paste a new one here.")
|
|
}
|
|
|
|
TextField {
|
|
id: setupToken
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
label: qsTr("Access token")
|
|
placeholderText: qsTr("paste the token")
|
|
echoMode: TextInput.Password
|
|
}
|
|
|
|
TextField {
|
|
id: setupCountry
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
label: qsTr("Country code")
|
|
placeholderText: "IT"
|
|
onTextChanged: appSettings.country = text
|
|
Component.onCompleted: text = appSettings.country
|
|
}
|
|
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
height: Theme.itemSizeMedium
|
|
enabled: setupToken.text.length > 0 && !api.busy
|
|
text: qsTr("Connect")
|
|
onClicked: {
|
|
appSettings.token = setupToken.text
|
|
api.reloadCredentials()
|
|
api.discover()
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------
|
|
// Ogni macchina dell'account, col suo stato e il suo comando.
|
|
// ---------------------------------------------------------------
|
|
Repeater {
|
|
model: api.devices
|
|
|
|
delegate: Column {
|
|
id: machine
|
|
width: column.width
|
|
spacing: Theme.paddingSmall
|
|
|
|
// Nome e fase: il tocco prolungato apre le azioni della
|
|
// macchina (stop ritardato, spegni, risveglia).
|
|
Item {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
height: Math.max(lamp.height, nameBox.height)
|
|
|
|
Rectangle {
|
|
id: lamp
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: Theme.itemSizeSmall / 2.2
|
|
height: width
|
|
radius: width / 2
|
|
color: Status.statusColor(modelData.level)
|
|
|
|
SequentialAnimation on opacity {
|
|
running: Status.isActive(modelData.level)
|
|
loops: Animation.Infinite
|
|
PropertyAnimation { to: 0.35; duration: 900 }
|
|
PropertyAnimation { to: 1.0; duration: 900 }
|
|
}
|
|
}
|
|
|
|
Column {
|
|
id: nameBox
|
|
anchors.left: lamp.right
|
|
anchors.leftMargin: Theme.paddingLarge
|
|
anchors.right: parent.right
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
spacing: Theme.paddingTiny
|
|
|
|
Label {
|
|
width: parent.width
|
|
truncationMode: TruncationMode.Fade
|
|
text: modelData.label
|
|
color: Theme.highlightColor
|
|
font.pixelSize: Theme.fontSizeMedium
|
|
}
|
|
|
|
Label {
|
|
width: parent.width
|
|
truncationMode: TruncationMode.Fade
|
|
text: modelData.offline ? qsTr("Not connected") : modelData.phase
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onPressAndHold: machineMenu.open(this)
|
|
}
|
|
}
|
|
|
|
Label {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
visible: modelData.hasState
|
|
text: modelData.remain.length > 0 ? modelData.remain : "--"
|
|
color: modelData.stale ? "orange" : Theme.primaryColor
|
|
font.pixelSize: Theme.fontSizeHuge
|
|
}
|
|
|
|
Label {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
visible: modelData.totalLine.length > 0
|
|
text: modelData.totalLine
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
}
|
|
|
|
// Se l'avvio a distanza e' spento sulla macchina, dirlo con
|
|
// le parole necessarie invece di lasciare un tasto che non
|
|
// funziona.
|
|
Label {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
wrapMode: Text.WordWrap
|
|
visible: modelData.hasState && !modelData.remote
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
text: qsTr("To send commands, switch remote start on from the machine panel.")
|
|
}
|
|
|
|
Label {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
wrapMode: Text.WordWrap
|
|
visible: modelData.offline
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
text: qsTr("The washing machine is not connected (switched off or offline)")
|
|
}
|
|
|
|
// UN comando per macchina, che cambia secondo il suo stato.
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
height: Theme.itemSizeMedium
|
|
visible: modelData.hasState
|
|
enabled: modelData.canCommand && !api.busy
|
|
text: modelData.action
|
|
onClicked: api.runPrimaryAt(index)
|
|
}
|
|
|
|
ContextMenu {
|
|
id: machineMenu
|
|
|
|
MenuItem {
|
|
text: qsTr("Delayed stop…")
|
|
enabled: modelData.canCommand
|
|
onClicked: pageStack.push(Qt.resolvedUrl("DelayDialog.qml"),
|
|
{ "deviceIndex": index,
|
|
"deviceLabel": modelData.label,
|
|
"enableAccept": modelData.canCommand })
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Switch off")
|
|
enabled: modelData.canCommand
|
|
onClicked: api.powerOffAt(index)
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Wake the display up")
|
|
enabled: modelData.canCommand
|
|
onClicked: api.wakeUpAt(index)
|
|
}
|
|
}
|
|
|
|
Separator {
|
|
width: parent.width
|
|
color: Theme.secondaryHighlightColor
|
|
}
|
|
}
|
|
}
|
|
|
|
// Chiave presente ma nessuna macchina: dirlo qui, non con una
|
|
// schermata vuota.
|
|
Label {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
wrapMode: Text.WordWrap
|
|
visible: api.configured && api.deviceCount === 0 && !api.busy
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
text: qsTr("No machine found yet. Pull down to search again.")
|
|
}
|
|
|
|
BusyIndicator {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
size: BusyIndicatorSize.Small
|
|
running: api.busy
|
|
}
|
|
|
|
Item { width: 1; height: Theme.paddingLarge }
|
|
}
|
|
|
|
VerticalScrollDecorator { }
|
|
}
|
|
|
|
// Banner dei messaggi: ancorato al bordo e di altezza fissa, cosi' non
|
|
// sposta ne' copre il contenuto.
|
|
Rectangle {
|
|
id: noticeBar
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.bottom: parent.bottom
|
|
height: api.notice.length > 0 ? Theme.itemSizeSmall : 0
|
|
color: api.noticeIsError ? "#b3261e" : "#2e5d3a"
|
|
visible: height > 0
|
|
|
|
Label {
|
|
anchors.fill: parent
|
|
anchors.leftMargin: Theme.horizontalPageMargin
|
|
anchors.rightMargin: Theme.horizontalPageMargin
|
|
verticalAlignment: Text.AlignVCenter
|
|
elide: Text.ElideRight
|
|
color: "white"
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
text: api.notice
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: api.clearNotice()
|
|
}
|
|
}
|
|
}
|