2020-09-21 05:41:02 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import "../.."
|
|
|
|
import "../../Base"
|
|
|
|
import "../../Base/Buttons"
|
|
|
|
import "../../PythonBridge"
|
|
|
|
import "../../ShortcutBundles"
|
|
|
|
|
|
|
|
HColumnPage {
|
|
|
|
id: page
|
|
|
|
|
|
|
|
property string userId
|
|
|
|
|
|
|
|
property bool enableFlickShortcuts:
|
|
|
|
SwipeView ? SwipeView.isCurrentItem : true
|
|
|
|
|
2020-10-31 00:14:40 +11:00
|
|
|
property string loadFutureId: ""
|
2020-09-21 05:41:02 +10:00
|
|
|
|
2020-09-21 06:01:02 +10:00
|
|
|
readonly property QtObject account: ModelStore.get("accounts").find(userId)
|
|
|
|
readonly property bool offline: ! account || account.presence === "offline"
|
|
|
|
|
2020-09-21 05:41:02 +10:00
|
|
|
function takeFocus() {
|
|
|
|
deviceList.headerItem.exportButton.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadDevices() {
|
2020-10-31 00:14:40 +11:00
|
|
|
loadFutureId = py.callClientCoro(userId, "devices_info", [], devs => {
|
2020-09-21 05:41:02 +10:00
|
|
|
deviceList.uncheckAll()
|
|
|
|
deviceList.model.clear()
|
|
|
|
|
2020-10-31 00:14:40 +11:00
|
|
|
for (const device of devs)
|
2020-09-21 05:41:02 +10:00
|
|
|
deviceList.model.append(device)
|
|
|
|
|
2020-10-31 00:14:40 +11:00
|
|
|
loadFutureId = ""
|
2020-09-21 05:41:02 +10:00
|
|
|
deviceList.sectionItemCounts = getSectionItemCounts()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function renameDevice(index, name) {
|
|
|
|
const device = deviceList.model.get(index)
|
|
|
|
|
|
|
|
device.display_name = name
|
|
|
|
|
|
|
|
py.callClientCoro(userId, "rename_device", [device.id, name], ok => {
|
|
|
|
if (! ok) deviceList.model.remove(index) // 404 happened
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteDevices(...indice) {
|
|
|
|
if (indice.length === 1 && indice[0] === 0) {
|
|
|
|
window.makePopup("Popups/SignOutPopup.qml", {userId: page.userId})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const deviceIds = []
|
|
|
|
let deleteOwnDevice = false
|
|
|
|
|
|
|
|
for (const i of indice.sort()) {
|
|
|
|
i === 0 ?
|
|
|
|
deleteOwnDevice = true :
|
|
|
|
deviceIds.push(deviceList.model.get(i).id)
|
|
|
|
}
|
|
|
|
|
|
|
|
window.makePopup(
|
|
|
|
"Popups/DeleteDevicesPopup.qml",
|
|
|
|
{
|
|
|
|
userId: page.userId,
|
|
|
|
deviceIds,
|
|
|
|
deletedCallback: () => {
|
|
|
|
deleteOwnDevice ?
|
|
|
|
window.makePopup(
|
|
|
|
"Popups/SignOutPopup.qml", { userId: page.userId },
|
|
|
|
) :
|
|
|
|
page.loadDevices()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSectionItemCounts() {
|
|
|
|
const counts = {}
|
|
|
|
|
|
|
|
for (let i = 0; i < deviceList.model.count; i++) {
|
|
|
|
const section = deviceList.model.get(i).type
|
|
|
|
section in counts ? counts[section] += 1 : counts[section] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return counts
|
|
|
|
}
|
|
|
|
|
2020-09-21 06:01:02 +10:00
|
|
|
function focusListController(top=true) {
|
|
|
|
deviceList.currentIndex = top ? 0 : deviceList.count - 1
|
|
|
|
listController.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
2020-09-21 05:41:02 +10:00
|
|
|
|
|
|
|
contentHeight: Math.min(
|
|
|
|
window.height,
|
2020-09-21 06:07:42 +10:00
|
|
|
deviceList.contentHeight + deviceList.bottomMargin,
|
2020-09-21 05:41:02 +10:00
|
|
|
)
|
|
|
|
|
|
|
|
Keys.forwardTo: [deviceList]
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: deviceList
|
|
|
|
|
|
|
|
// Don't bind directly to getSectionItemCounts(), laggy with big list
|
|
|
|
property var sectionItemCounts: ({})
|
|
|
|
|
|
|
|
bottomMargin: theme.spacing
|
|
|
|
clip: true
|
|
|
|
keyNavigationEnabled: false
|
|
|
|
|
|
|
|
model: ListModel {}
|
|
|
|
|
|
|
|
header: HColumnLayout {
|
|
|
|
readonly property alias exportButton: exportButton
|
2020-09-21 06:01:02 +10:00
|
|
|
readonly property alias importButton: importButton
|
2020-09-21 05:41:02 +10:00
|
|
|
readonly property alias signOutCheckedButton: signOutCheckedButton
|
|
|
|
|
|
|
|
spacing: theme.spacing
|
|
|
|
x: spacing
|
|
|
|
width: deviceList.width - x * 2
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: qsTr("Decryption keys")
|
|
|
|
font.pixelSize: theme.fontSize.big
|
|
|
|
wrapMode: HLabel.Wrap
|
|
|
|
topPadding: parent.spacing
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: qsTr(
|
|
|
|
"The decryption keys for messages received in encrypted " +
|
|
|
|
"rooms <b>until present time</b> can be exported " +
|
|
|
|
"to a passphrase-protected file.<br><br>" +
|
|
|
|
|
|
|
|
"You can then import this file on any Matrix account or " +
|
|
|
|
"application, in order to decrypt these messages again."
|
|
|
|
)
|
|
|
|
textFormat: Text.StyledText
|
|
|
|
wrapMode: HLabel.Wrap
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoDirectionLayout {
|
|
|
|
GroupButton {
|
|
|
|
id: exportButton
|
|
|
|
text: qsTr("Export")
|
|
|
|
icon.name: "export-keys"
|
|
|
|
|
|
|
|
onClicked: utils.makeObject(
|
|
|
|
"Dialogs/ExportKeys.qml",
|
|
|
|
page,
|
|
|
|
{ userId: page.userId },
|
|
|
|
obj => {
|
|
|
|
loading = Qt.binding(() => obj.exporting)
|
|
|
|
obj.dialog.open()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-09-21 06:01:02 +10:00
|
|
|
Keys.onBacktabPressed: page.focusListController(false)
|
2020-09-21 05:41:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
GroupButton {
|
2020-09-21 06:01:02 +10:00
|
|
|
id: importButton
|
2020-09-21 05:41:02 +10:00
|
|
|
text: qsTr("Import")
|
|
|
|
icon.name: "import-keys"
|
|
|
|
|
|
|
|
onClicked: utils.makeObject(
|
|
|
|
"Dialogs/ImportKeys.qml",
|
|
|
|
page,
|
|
|
|
{ userId: page.userId },
|
|
|
|
obj => { obj.dialog.open() }
|
|
|
|
)
|
2020-09-21 06:01:02 +10:00
|
|
|
|
|
|
|
Keys.onTabPressed:
|
|
|
|
signOutCheckedButton.enabled ?
|
|
|
|
refreshButton.forceActiveFocus() :
|
|
|
|
page.focusListController()
|
2020-09-21 05:41:02 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: qsTr("Sessions")
|
|
|
|
font.pixelSize: theme.fontSize.big
|
|
|
|
wrapMode: HLabel.Wrap
|
|
|
|
topPadding: parent.spacing / 2
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
text: qsTr(
|
|
|
|
"New sessions are created the first time you sign in " +
|
|
|
|
"from a different device or application."
|
|
|
|
)
|
|
|
|
wrapMode: HLabel.Wrap
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoDirectionLayout {
|
2020-09-21 06:01:02 +10:00
|
|
|
enabled: ! page.offline
|
|
|
|
|
2020-09-21 05:41:02 +10:00
|
|
|
GroupButton {
|
|
|
|
id: refreshButton
|
|
|
|
text: qsTr("Refresh")
|
2020-10-31 00:14:40 +11:00
|
|
|
loading: page.loadFutureId !== ""
|
2020-09-21 05:41:02 +10:00
|
|
|
icon.name: "device-refresh-list"
|
|
|
|
onClicked: page.loadDevices()
|
|
|
|
}
|
|
|
|
|
|
|
|
NegativeButton {
|
|
|
|
id: signOutCheckedButton
|
|
|
|
enabled: deviceList.model.count > 0
|
|
|
|
text:
|
|
|
|
deviceList.selectedCount === 0 ?
|
|
|
|
qsTr("Sign out others") :
|
|
|
|
qsTr("Sign out checked")
|
|
|
|
|
|
|
|
icon.name: "device-delete-checked"
|
|
|
|
onClicked:
|
|
|
|
deviceList.selectedCount ?
|
|
|
|
page.deleteDevices(...deviceList.checkedIndice) :
|
|
|
|
page.deleteDevices(
|
|
|
|
...utils.range(1, deviceList.count - 1),
|
|
|
|
)
|
|
|
|
|
2020-09-21 06:01:02 +10:00
|
|
|
Keys.onTabPressed: page.focusListController()
|
2020-09-21 05:41:02 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: DeviceDelegate {
|
|
|
|
width: deviceList.width
|
|
|
|
view: deviceList
|
|
|
|
userId: page.userId
|
2020-09-21 06:01:02 +10:00
|
|
|
offline: page.offline
|
2020-09-21 05:41:02 +10:00
|
|
|
onVerified: page.loadDevices()
|
|
|
|
onBlacklisted: page.loadDevices()
|
|
|
|
onRenameRequest: name => page.renameDevice(model.index, name)
|
|
|
|
onDeleteRequest: page.deleteDevices(model.index)
|
|
|
|
}
|
|
|
|
|
|
|
|
section.property: "type"
|
|
|
|
section.delegate: DeviceSection {
|
|
|
|
width: deviceList.width
|
|
|
|
view: deviceList
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: page.loadDevices()
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
Keys.onEscapePressed: uncheckAll()
|
|
|
|
Keys.onSpacePressed: if (currentItem) toggleCheck(currentIndex)
|
|
|
|
Keys.onEnterPressed: if (currentItem) currentItem.openMenu(false)
|
|
|
|
Keys.onReturnPressed: Keys.onEnterPressed(event)
|
|
|
|
Keys.onMenuPressed: Keys.onEnterPressed(event)
|
|
|
|
|
2020-09-21 06:01:02 +10:00
|
|
|
Keys.onUpPressed: page.focusListController(false)
|
|
|
|
Keys.onDownPressed: page.focusListController()
|
2020-09-21 05:41:02 +10:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: listController
|
|
|
|
|
|
|
|
Keys.onBacktabPressed: {
|
|
|
|
if (parent.currentIndex === 0) {
|
|
|
|
parent.currentIndex = -1
|
2020-09-21 06:01:02 +10:00
|
|
|
|
|
|
|
parent.headerItem.signOutCheckedButton.enabled ?
|
|
|
|
parent.headerItem.signOutCheckedButton.forceActiveFocus() :
|
|
|
|
parent.headerItem.importButton.forceActiveFocus()
|
|
|
|
|
2020-09-21 05:41:02 +10:00
|
|
|
return
|
|
|
|
}
|
|
|
|
parent.decrementCurrentIndex()
|
|
|
|
forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
Keys.onTabPressed: {
|
|
|
|
if (parent.currentIndex === parent.count - 1) {
|
|
|
|
utils.flickToTop(deviceList)
|
|
|
|
parent.currentIndex = -1
|
|
|
|
parent.headerItem.exportButton.forceActiveFocus()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
parent.incrementCurrentIndex()
|
|
|
|
forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
Keys.onUpPressed: ev => Keys.onBacktabPressed(ev)
|
|
|
|
Keys.onDownPressed: ev => Keys.onTabPressed(ev)
|
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.refreshDevices
|
|
|
|
onActivated: refreshButton.clicked()
|
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.signOutCheckedOrAllDevices
|
|
|
|
onActivated: signOutCheckedButton.clicked()
|
|
|
|
}
|
|
|
|
|
|
|
|
FlickShortcuts {
|
|
|
|
flickable: deviceList
|
|
|
|
active:
|
|
|
|
! mainUI.debugConsole.visible && page.enableFlickShortcuts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|