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. 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.configured ? api.deviceCount : 0 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(api.statusLevelAt(index)) SequentialAnimation on opacity { running: Status.isActive(api.statusLevelAt(index)) 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: api.labelAt(index) color: Theme.highlightColor font.pixelSize: Theme.fontSizeMedium } Label { width: parent.width truncationMode: TruncationMode.Fade text: api.offlineAt(index) ? qsTr("Not connected") : api.phaseTextAt(index) color: Theme.secondaryColor font.pixelSize: Theme.fontSizeSmall } } MouseArea { anchors.fill: parent onPressAndHold: machineMenu.open(this) } } Label { anchors.horizontalCenter: parent.horizontalCenter visible: api.hasStateAt(index) text: api.remainTextAt(index).length > 0 ? api.remainTextAt(index) : "--" color: api.staleAt(index) ? "orange" : Theme.primaryColor font.pixelSize: Theme.fontSizeHuge } Label { anchors.horizontalCenter: parent.horizontalCenter visible: api.totalLineAt(index).length > 0 text: api.totalLineAt(index) color: Theme.secondaryColor font.pixelSize: Theme.fontSizeSmall } // Se la macchina non risponde o ha l'avvio a distanza // spento, 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: api.hasStateAt(index) && !api.remoteEnabledAt(index) 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: api.offlineAt(index) 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: api.hasStateAt(index) enabled: api.canCommandAt(index) && !api.busy text: api.primaryLabelAt(index) onClicked: api.runPrimaryAt(index) } ContextMenu { id: machineMenu MenuItem { text: qsTr("Delayed stop…") enabled: api.canCommandAt(index) onClicked: pageStack.push(Qt.resolvedUrl("DelayDialog.qml"), { "deviceIndex": index }) } MenuItem { text: qsTr("Switch off") enabled: api.canCommandAt(index) onClicked: api.powerOffAt(index) } MenuItem { text: qsTr("Wake the display up") enabled: api.canCommandAt(index) 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() } } }