[app] Rework device page

To achive the proper scrolling behaviour it needs to be a ScrollablePage. In order to do that correctly the listview needs to be the direct content item of the page. Therefore we need to get rid of the loader and the various placeholder messages are parented to the listview.
This commit is contained in:
Nicolas Fella 2020-07-05 22:48:17 +02:00
parent 0c32010a28
commit 151f829308
2 changed files with 116 additions and 153 deletions

View file

@ -25,172 +25,135 @@ import QtQuick.Dialogs 1.0
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kdeconnect 1.0
Kirigami.Page
Kirigami.ScrollablePage
{
id: deviceView
id: root
property QtObject currentDevice
title: currentDevice.name
actions.contextualActions: deviceLoader.item.actions
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
Loader {
id: deviceLoader
anchors.fill: parent
sourceComponent: {
if (deviceView.currentDevice.hasPairingRequests) {
return pairDevice;
actions.contextualActions: [
Kirigami.Action {
iconName:"network-disconnect"
onTriggered: root.currentDevice.unpair()
text: i18nd("kdeconnect-app", "Unpair")
visible: root.currentDevice.isTrusted
},
Kirigami.Action {
iconName:"hands-free"
text: i18nd("kdeconnect-app", "Send Ping")
visible: root.currentDevice.isTrusted && root.currentDevice.isReachable
onTriggered: {
root.currentDevice.pluginCall("ping", "sendPing");
}
}
]
if (deviceView.currentDevice.isReachable) {
if (deviceView.currentDevice.isTrusted) {
return trustedDevice;
} else {
return untrustedDevice;
ListView {
model: plugins
delegate: Kirigami.BasicListItem {
label: name
icon: iconName
highlighted: false
iconColor: "transparent"
visible: loaded
onClicked: onClick()
}
property list<QtObject> plugins : [
PluginItem {
name: i18nd("kdeconnect-app", "Multimedia control")
interfaceFactory: MprisDbusInterfaceFactory
component: "qrc:/qml/mpris.qml"
pluginName: "mprisremote"
device: root.currentDevice
},
PluginItem {
name: i18nd("kdeconnect-app", "Remote input")
interfaceFactory: RemoteControlDbusInterfaceFactory
component: "qrc:/qml/mousepad.qml"
pluginName: "remotecontrol"
device: root.currentDevice
},
PluginItem {
name: i18nd("kdeconnect-app", "Presentation Remote")
interfaceFactory: RemoteKeyboardDbusInterfaceFactory
component: "qrc:/qml/presentationRemote.qml"
pluginName: "remotecontrol"
device: root.currentDevice
},
PluginItem {
readonly property var lockIface: LockDeviceDbusInterfaceFactory.create(root.currentDevice.id())
pluginName: "lockdevice"
name: lockIface.isLocked ? i18nd("kdeconnect-app", "Unlock") : i18nd("kdeconnect-app", "Lock")
onClick: () => lockIface.isLocked = !lockIface.isLocked;
device: root.currentDevice
},
PluginItem {
readonly property var findmyphoneIface: FindMyPhoneDbusInterfaceFactory.create(root.currentDevice.id())
pluginName: "findmyphone"
name: i18nd("kdeconnect-app", "Find Device")
onClick: () => findmyphoneIface.ring()
device: root.currentDevice
},
PluginItem {
name: i18nd("kdeconnect-app", "Run command")
interfaceFactory: RemoteCommandsDbusInterfaceFactory
component: "qrc:/qml/runcommand.qml"
pluginName: "remotecommands"
device: root.currentDevice
},
PluginItem {
readonly property var shareIface: ShareDbusInterfaceFactory.create(root.currentDevice.id())
pluginName: "share"
name: i18nd("kdeconnect-app", "Share File")
onClick: () => {
fileDialog.open()
shareIface.shareUrl(fileDialog.fileUrl)
}
} else {
return notReachableDevice;
device: root.currentDevice
},
PluginItem {
name: i18nd("kdeconnect-app", "Volume control")
interfaceFactory: RemoteSystemVolumeDbusInterfaceFactory
component: "qrc:/qml/volume.qml"
pluginName: "remotesystemvolume"
device: root.currentDevice
}
]
Kirigami.PlaceholderMessage {
text: i18nd("kdeconnect-app", "This device is not paired")
anchors.centerIn: parent
visible: root.currentDevice.isReachable && !root.currentDevice.isTrusted && !root.currentDevice.hasPairingRequests
helpfulAction: Kirigami.Action {
text: i18nd("kdeconnect-app", "Pair")
icon.name:"network-connect"
onTriggered: root.currentDevice.requestPair()
}
}
Component {
id: trustedDevice
ListView {
property list<QtObject> actions: [
Kirigami.Action {
iconName:"network-disconnect"
onTriggered: deviceView.currentDevice.unpair()
text: i18nd("kdeconnect-app", "Unpair")
},
Kirigami.Action {
iconName:"hands-free"
text: i18nd("kdeconnect-app", "Send Ping")
onTriggered: {
deviceView.currentDevice.pluginCall("ping", "sendPing");
}
}
]
id: trustedView
Layout.fillWidth: true
model: plugins
delegate: Kirigami.BasicListItem {
label: name
icon: iconName
highlighted: false
iconColor: "transparent"
visible: loaded
onClicked: onClick()
}
property list<QtObject> plugins : [
PluginItem {
name: i18nd("kdeconnect-app", "Multimedia control")
interfaceFactory: MprisDbusInterfaceFactory
component: "qrc:/qml/mpris.qml"
pluginName: "mprisremote"
},
PluginItem {
name: i18nd("kdeconnect-app", "Remote input")
interfaceFactory: RemoteControlDbusInterfaceFactory
component: "qrc:/qml/mousepad.qml"
pluginName: "remotecontrol"
},
PluginItem {
name: i18nd("kdeconnect-app", "Presentation Remote")
interfaceFactory: RemoteKeyboardDbusInterfaceFactory
component: "qrc:/qml/presentationRemote.qml"
pluginName: "remotecontrol"
},
PluginItem {
readonly property var lockIface: LockDeviceDbusInterfaceFactory.create(deviceView.currentDevice.id())
pluginName: "lockdevice"
name: lockIface.isLocked ? i18nd("kdeconnect-app", "Unlock") : i18nd("kdeconnect-app", "Lock")
onClick: function() {
lockIface.isLocked = !lockIface.isLocked;
}
},
PluginItem {
readonly property var findmyphoneIface: FindMyPhoneDbusInterfaceFactory.create(deviceView.currentDevice.id())
pluginName: "findmyphone"
name: i18nd("kdeconnect-app", "Find Device")
onClick: function() {
findmyphoneIface.ring()
}
},
PluginItem {
name: i18nd("kdeconnect-app", "Run command")
interfaceFactory: RemoteCommandsDbusInterfaceFactory
component: "qrc:/qml/runcommand.qml"
pluginName: "remotecommands"
},
PluginItem {
readonly property var shareIface: ShareDbusInterfaceFactory.create(deviceView.currentDevice.id())
pluginName: "share"
name: i18nd("kdeconnect-app", "Share File")
onClick: function() {
fileDialog.open()
shareIface.shareUrl(fileDialog.fileUrl)
}
},
PluginItem {
name: i18nd("kdeconnect-app", "Volume control")
interfaceFactory: RemoteSystemVolumeDbusInterfaceFactory
component: "qrc:/qml/volume.qml"
pluginName: "remotesystemvolume"
}
]
RowLayout {
visible: root.currentDevice.hasPairingRequests
anchors.centerIn: parent
Button {
text: i18nd("kdeconnect-app", "Accept")
icon.name:"dialog-ok"
onClicked: root.currentDevice.acceptPairing()
}
}
Component {
id: untrustedDevice
Item {
readonly property var actions: []
Kirigami.PlaceholderMessage {
text: i18nd("kdeconnect-app", "This device is not paired")
anchors.centerIn: parent
helpfulAction: Kirigami.Action {
text: i18nd("kdeconnect-app", "Pair")
icon.name:"network-connect"
onTriggered: deviceView.currentDevice.requestPair()
}
}
}
}
Component {
id: pairDevice
Item {
readonly property var actions: []
RowLayout {
anchors.centerIn: parent
Button {
text: i18nd("kdeconnect-app", "Accept")
icon.name:"dialog-ok"
onClicked: deviceView.currentDevice.acceptPairing()
}
Button {
text: i18nd("kdeconnect-app", "Reject")
icon.name:"dialog-cancel"
onClicked: deviceView.currentDevice.rejectPairing()
}
}
Button {
text: i18nd("kdeconnect-app", "Reject")
icon.name:"dialog-cancel"
onClicked: root.currentDevice.rejectPairing()
}
}
Component {
id: notReachableDevice
Kirigami.PlaceholderMessage {
text: i18nd("kdeconnect-app", "This device is not reachable")
anchors.centerIn: parent
}
Kirigami.PlaceholderMessage {
visible: !root.currentDevice.isReachable
text: i18nd("kdeconnect-app", "This device is not reachable")
anchors.centerIn: parent
}
}

View file

@ -29,15 +29,15 @@ QtObject
property alias pluginName: checker.pluginName
property alias iconName: checker.iconName
property alias loaded: checker.available
property alias device: checker.device
property var interfaceFactory
property var component
property var name
readonly property var checker: PluginChecker {
id: checker
device: deviceView.currentDevice
}
property var onClick: function() {
property var onClick: () => {
if (component === "" || !interfaceFactory)
return;