introduce a RootItem as a layer to be manipulated by styling
This commit is contained in:
parent
be50036584
commit
772c1c7fa0
@ -13,7 +13,6 @@
|
||||
<file>ui/images/add.svg</file>
|
||||
<file>ui/images/back.svg</file>
|
||||
<file>ui/images/close.svg</file>
|
||||
<file>ui/MainPage.qml</file>
|
||||
<file>ui/images/info.svg</file>
|
||||
<file>ui/components/ColorPicker.qml</file>
|
||||
<file>ui/customviews/CustomViewBase.qml</file>
|
||||
@ -253,5 +252,7 @@
|
||||
<file>ui/devicelistpages/SensorsDeviceListPage.qml</file>
|
||||
<file>ui/devicelistpages/WeatherDeviceListPage.qml</file>
|
||||
<file>ui/devicelistpages/DeviceListPageBase.qml</file>
|
||||
<file>ui/MainPage.qml</file>
|
||||
<file>ui/RootItem.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@ -49,7 +49,7 @@ Page {
|
||||
anchors.fill: parent
|
||||
model: DevicesProxy {
|
||||
id: deviceProxy
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
groupByInterface: true
|
||||
}
|
||||
section.property: "baseInterface"
|
||||
|
||||
@ -43,161 +43,13 @@ ApplicationWindow {
|
||||
property int cloudEnvironment: 0
|
||||
}
|
||||
|
||||
property var engine: Engine {
|
||||
|
||||
}
|
||||
|
||||
Binding {
|
||||
target: engine.awsClient
|
||||
property: "config"
|
||||
value: settings.cloudEnvironment
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
setupPushNotifications();
|
||||
}
|
||||
Connections {
|
||||
target: PlatformHelper
|
||||
onHasPermissionsChanged: {
|
||||
setupPushNotifications(false)
|
||||
}
|
||||
}
|
||||
Connections {
|
||||
target: PushNotifications
|
||||
onTokenChanged: {
|
||||
setupPushNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: engine.awsClient
|
||||
onIsLoggedInChanged: {
|
||||
setupPushNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: engine.jsonRpcClient
|
||||
onConnectedChanged: {
|
||||
print("json client connected changed", engine.jsonRpcClient.connected)
|
||||
if (engine.jsonRpcClient.connected) {
|
||||
settings.lastConnectedHost = engine.connection.url
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
onAuthenticationRequiredChanged: {
|
||||
print("auth required changed")
|
||||
init();
|
||||
}
|
||||
onInitialSetupRequiredChanged: {
|
||||
print("setup required changed")
|
||||
init();
|
||||
}
|
||||
|
||||
onInvalidProtocolVersion: {
|
||||
var popup = invalidVersionComponent.createObject(app.contentItem);
|
||||
popup.actualVersion = actualVersion;
|
||||
popup.minimumVersion = minimumVersion
|
||||
popup.open()
|
||||
settings.lastConnectedHost = ""
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
print("calling init. Auth required:", engine.jsonRpcClient.authenticationRequired, "initial setup required:", engine.jsonRpcClient.initialSetupRequired, "jsonrpc connected:", engine.jsonRpcClient.connected)
|
||||
pageStack.clear()
|
||||
if (!engine.connection.connected) {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (engine.jsonRpcClient.authenticationRequired || engine.jsonRpcClient.initialSetupRequired) {
|
||||
if (engine.jsonRpcClient.pushButtonAuthAvailable) {
|
||||
print("opening push button auth")
|
||||
var page = pageStack.push(Qt.resolvedUrl("PushButtonAuthPage.qml"))
|
||||
page.backPressed.connect(function() {
|
||||
settings.lastConnectedHost = "";
|
||||
engine.connection.disconnect();
|
||||
init();
|
||||
})
|
||||
} else {
|
||||
var page = pageStack.push(Qt.resolvedUrl("LoginPage.qml"));
|
||||
page.backPressed.connect(function() {
|
||||
settings.lastConnectedHost = "";
|
||||
engine.connection.disconnect()
|
||||
init();
|
||||
})
|
||||
}
|
||||
} else if (engine.jsonRpcClient.connected) {
|
||||
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
|
||||
} else {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
}
|
||||
}
|
||||
|
||||
function setupPushNotifications(askForPermissions) {
|
||||
if (askForPermissions === undefined) {
|
||||
askForPermissions = true;
|
||||
}
|
||||
|
||||
if (!engine.awsClient.isLoggedIn) {
|
||||
print("AWS not logged in. Cannot register for push");
|
||||
return;
|
||||
}
|
||||
|
||||
if (PushNotifications.token.length === 0) {
|
||||
print("Don't have a token yet. Cannot register for push");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PlatformHelper.hasPermissions) {
|
||||
if (askForPermissions) {
|
||||
PlatformHelper.requestPermissions();
|
||||
}
|
||||
} else {
|
||||
engine.awsClient.registerPushNotificationEndpoint(PushNotifications.token, PlatformHelper.deviceManufacturer + " " + PlatformHelper.deviceModel, PlatformHelper.deviceSerial + "+io.guh.nymeaapp");
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround flickering on pageStack animations when the white background shines through
|
||||
Rectangle {
|
||||
RootItem {
|
||||
id: rootItem
|
||||
anchors.fill: parent
|
||||
color: Material.background
|
||||
}
|
||||
|
||||
StackView {
|
||||
id: pageStack
|
||||
objectName: "pageStack"
|
||||
anchors.fill: parent
|
||||
initialItem: Page {}
|
||||
// onDepthChanged: {
|
||||
// print("stackview depth changed", pageStack.depth)
|
||||
// }
|
||||
}
|
||||
|
||||
onClosing: {
|
||||
if (Qt.platform.os == "android") {
|
||||
// If we're connected, allow going back up to MainPage
|
||||
if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
|
||||
// if we're not connected, only allow using the back button in wizards
|
||||
|| (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
|
||||
close.accepted = false;
|
||||
pageStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Qt.application
|
||||
enabled: engine.jsonRpcClient.connected && settings.returnToHome
|
||||
onStateChanged: {
|
||||
print("App active state changed:", state)
|
||||
if (state !== Qt.ApplicationActive) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
rootItem.handleCloseEvent(close)
|
||||
}
|
||||
|
||||
property var supportedInterfaces: ["light", "weather", "sensor", "media", "garagegate", "extendedawning", "extendedshutter", "extendedblind", "button", "notifications", "inputtrigger", "outputtrigger", "gateway"]
|
||||
@ -392,44 +244,6 @@ ApplicationWindow {
|
||||
return s.substr(s.length-size);
|
||||
}
|
||||
|
||||
Component {
|
||||
id: invalidVersionComponent
|
||||
Popup {
|
||||
id: popup
|
||||
|
||||
property string actualVersion: "0.0"
|
||||
property string minimumVersion: "1.0"
|
||||
|
||||
width: app.width * .8
|
||||
height: col.childrenRect.height + app.margins * 2
|
||||
x: (app.width - width) / 2
|
||||
y: (app.height - height) / 2
|
||||
visible: false
|
||||
ColumnLayout {
|
||||
id: col
|
||||
anchors { left: parent.left; right: parent.right }
|
||||
spacing: app.margins
|
||||
Label {
|
||||
text: qsTr("Connection error")
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: app.largeFont
|
||||
}
|
||||
Label {
|
||||
text: qsTr("Sorry, the version of the %1 box you are trying to connect to is too old. This app requires at least version %2 but the %1 box only supports %3").arg(app.systemName).arg(popup.minimumVersion).arg(popup.actualVersion)
|
||||
wrapMode: Text.WordWrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Button {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("OK")
|
||||
onClicked: {
|
||||
engine.connection.disconnect();
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeyboardLoader {
|
||||
id: keyboardRect
|
||||
|
||||
210
nymea-app/ui/RootItem.qml
Normal file
210
nymea-app/ui/RootItem.qml
Normal file
@ -0,0 +1,210 @@
|
||||
import QtQuick 2.9
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Controls.Material 2.2
|
||||
import QtQuick.Layouts 1.3
|
||||
import Nymea 1.0
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
Engine {
|
||||
id: engine
|
||||
}
|
||||
// If you need to assign to a property "engine", `engine: engine` won't work, as a workaround, use `engine: _engine`
|
||||
// TODO: Improve this situation
|
||||
property alias _engine: engine
|
||||
|
||||
Binding {
|
||||
target: engine.awsClient
|
||||
property: "config"
|
||||
value: settings.cloudEnvironment
|
||||
}
|
||||
|
||||
// Workaround flickering on pageStack animations when the white background shines through
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Material.background
|
||||
}
|
||||
|
||||
StackView {
|
||||
id: pageStack
|
||||
objectName: "pageStack"
|
||||
anchors.fill: parent
|
||||
initialItem: Page {}
|
||||
// onDepthChanged: {
|
||||
// print("stackview depth changed", pageStack.depth)
|
||||
// }
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
setupPushNotifications();
|
||||
}
|
||||
|
||||
function init() {
|
||||
print("calling init. Auth required:", engine.jsonRpcClient.authenticationRequired, "initial setup required:", engine.jsonRpcClient.initialSetupRequired, "jsonrpc connected:", engine.jsonRpcClient.connected)
|
||||
pageStack.clear()
|
||||
if (!engine.connection.connected) {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
return;
|
||||
}
|
||||
|
||||
if (engine.jsonRpcClient.authenticationRequired || engine.jsonRpcClient.initialSetupRequired) {
|
||||
if (engine.jsonRpcClient.pushButtonAuthAvailable) {
|
||||
print("opening push button auth")
|
||||
var page = pageStack.push(Qt.resolvedUrl("PushButtonAuthPage.qml"))
|
||||
page.backPressed.connect(function() {
|
||||
settings.lastConnectedHost = "";
|
||||
engine.connection.disconnect();
|
||||
init();
|
||||
})
|
||||
} else {
|
||||
var page = pageStack.push(Qt.resolvedUrl("LoginPage.qml"));
|
||||
page.backPressed.connect(function() {
|
||||
settings.lastConnectedHost = "";
|
||||
engine.connection.disconnect()
|
||||
init();
|
||||
})
|
||||
}
|
||||
} else if (engine.jsonRpcClient.connected) {
|
||||
pageStack.push(Qt.resolvedUrl("MainPage.qml"))
|
||||
} else {
|
||||
pageStack.push(Qt.resolvedUrl("connection/ConnectPage.qml"))
|
||||
}
|
||||
}
|
||||
|
||||
function handleCloseEvent(close) {
|
||||
if (Qt.platform.os == "android") {
|
||||
// If we're connected, allow going back up to MainPage
|
||||
if ((engine.jsonRpcClient.connected && pageStack.depth > 1)
|
||||
// if we're not connected, only allow using the back button in wizards
|
||||
|| (!engine.jsonRpcClient.connected && pageStack.depth > 3)) {
|
||||
close.accepted = false;
|
||||
pageStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setupPushNotifications(askForPermissions) {
|
||||
if (askForPermissions === undefined) {
|
||||
askForPermissions = true;
|
||||
}
|
||||
|
||||
if (!engine.awsClient.isLoggedIn) {
|
||||
print("AWS not logged in. Cannot register for push");
|
||||
return;
|
||||
}
|
||||
|
||||
if (PushNotifications.token.length === 0) {
|
||||
print("Don't have a token yet. Cannot register for push");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PlatformHelper.hasPermissions) {
|
||||
if (askForPermissions) {
|
||||
PlatformHelper.requestPermissions();
|
||||
}
|
||||
} else {
|
||||
engine.awsClient.registerPushNotificationEndpoint(PushNotifications.token, PlatformHelper.deviceManufacturer + " " + PlatformHelper.deviceModel, PlatformHelper.deviceSerial + "+io.guh.nymeaapp");
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: engine.jsonRpcClient
|
||||
onConnectedChanged: {
|
||||
print("json client connected changed", engine.jsonRpcClient.connected)
|
||||
if (engine.jsonRpcClient.connected) {
|
||||
settings.lastConnectedHost = engine.connection.url
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
onAuthenticationRequiredChanged: {
|
||||
print("auth required changed")
|
||||
init();
|
||||
}
|
||||
onInitialSetupRequiredChanged: {
|
||||
print("setup required changed")
|
||||
init();
|
||||
}
|
||||
|
||||
onInvalidProtocolVersion: {
|
||||
var popup = invalidVersionComponent.createObject(app.contentItem);
|
||||
popup.actualVersion = actualVersion;
|
||||
popup.minimumVersion = minimumVersion
|
||||
popup.open()
|
||||
settings.lastConnectedHost = ""
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Qt.application
|
||||
enabled: engine.jsonRpcClient.connected && settings.returnToHome
|
||||
onStateChanged: {
|
||||
print("App active state changed:", state)
|
||||
if (state !== Qt.ApplicationActive) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: PlatformHelper
|
||||
onHasPermissionsChanged: {
|
||||
setupPushNotifications(false)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: PushNotifications
|
||||
onTokenChanged: {
|
||||
setupPushNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: engine.awsClient
|
||||
onIsLoggedInChanged: {
|
||||
setupPushNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: invalidVersionComponent
|
||||
Popup {
|
||||
id: popup
|
||||
|
||||
property string actualVersion: "0.0"
|
||||
property string minimumVersion: "1.0"
|
||||
|
||||
width: app.width * .8
|
||||
height: col.childrenRect.height + app.margins * 2
|
||||
x: (app.width - width) / 2
|
||||
y: (app.height - height) / 2
|
||||
visible: false
|
||||
ColumnLayout {
|
||||
id: col
|
||||
anchors { left: parent.left; right: parent.right }
|
||||
spacing: app.margins
|
||||
Label {
|
||||
text: qsTr("Connection error")
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: app.largeFont
|
||||
}
|
||||
Label {
|
||||
text: qsTr("Sorry, the version of the %1 box you are trying to connect to is too old. This app requires at least version %2 but the %1 box only supports %3").arg(app.systemName).arg(popup.minimumVersion).arg(popup.actualVersion)
|
||||
wrapMode: Text.WordWrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Button {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("OK")
|
||||
onClicked: {
|
||||
engine.connection.disconnect();
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ CustomViewBase {
|
||||
|
||||
ValueLogsProxyModel {
|
||||
id: logsModel
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
deviceId: root.device.id
|
||||
typeIds: [stateType.id]
|
||||
average: zoomTabBar.currentItem.avg
|
||||
|
||||
@ -32,6 +32,6 @@ Page {
|
||||
|
||||
DevicesProxy {
|
||||
id: devicesProxyInternal
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ GenericDevicePage {
|
||||
text: qsTr("This button has been pressed %1 times in the last %2 days.")
|
||||
|
||||
logsModel: LogsModel {
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
deviceId: root.device.id
|
||||
live: true
|
||||
typeIds: {
|
||||
|
||||
@ -13,7 +13,7 @@ GenericDevicePage {
|
||||
text: qsTr("This event has appeared %1 times in the last %2 days.")
|
||||
|
||||
logsModel: LogsModel {
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
deviceId: root.device.id
|
||||
live: true
|
||||
Component.onCompleted: update()
|
||||
|
||||
@ -28,7 +28,7 @@ Page {
|
||||
|
||||
LogsModel {
|
||||
id: logsModel
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
deviceId: root.device.id
|
||||
live: true
|
||||
Component.onCompleted: update()
|
||||
|
||||
@ -31,7 +31,7 @@ Page {
|
||||
|
||||
DevicesProxy {
|
||||
id: ifaceFilterModel
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
@ -252,7 +252,7 @@ Page {
|
||||
|
||||
model: DevicesProxy {
|
||||
id: lightsModel
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
shownInterfaces: ["light"]
|
||||
}
|
||||
delegate: CheckDelegate {
|
||||
@ -337,7 +337,7 @@ Page {
|
||||
|
||||
model: DevicesProxy {
|
||||
id: notificationsModel
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
shownInterfaces: ["notifications"]
|
||||
}
|
||||
delegate: CheckDelegate {
|
||||
|
||||
@ -34,7 +34,7 @@ Page {
|
||||
|
||||
DevicesProxy {
|
||||
id: devicesProxy
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
|
||||
@ -37,19 +37,19 @@ MainPageTile {
|
||||
|
||||
DevicesProxy {
|
||||
id: devicesProxy
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
shownInterfaces: [model.name]
|
||||
}
|
||||
|
||||
DevicesProxy {
|
||||
id: devicesSubProxyConnectables
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
parentProxy: devicesProxy
|
||||
filterDisconnected: true
|
||||
}
|
||||
DevicesProxy {
|
||||
id: devicesSubProxyBattery
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
parentProxy: devicesProxy
|
||||
filterBatteryCritical: true
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ Page {
|
||||
|
||||
LogsModel {
|
||||
id: logsModel
|
||||
engine: app.engine
|
||||
engine: _engine
|
||||
startTime: {
|
||||
var date = new Date();
|
||||
date.setHours(new Date().getHours() - 2);
|
||||
|
||||
Reference in New Issue
Block a user