2020-04-27 04:20:45 +10:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2020-05-12 20:09:07 +10:00
|
|
|
import Qt.labs.qmlmodels 1.0
|
2020-04-27 04:20:45 +10:00
|
|
|
import ".."
|
|
|
|
import "../Base"
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: roomList
|
2020-05-06 15:49:25 +10:00
|
|
|
model: ModelStore.get("all_rooms")
|
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
delegate: DelegateChooser {
|
|
|
|
role: "type"
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "Account"
|
2020-05-14 04:16:37 +10:00
|
|
|
Account {
|
|
|
|
width: roomList.width
|
|
|
|
filterActive: Boolean(filter)
|
2020-05-14 10:32:05 +10:00
|
|
|
isCurrent:
|
|
|
|
currentIndex !== -1 &&
|
|
|
|
(
|
|
|
|
roomList.model.get(currentIndex).for_account ||
|
|
|
|
roomList.model.get(currentIndex).id
|
|
|
|
) === model.id
|
2020-05-14 04:16:37 +10:00
|
|
|
}
|
2020-05-12 20:09:07 +10:00
|
|
|
}
|
2020-05-02 02:26:32 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
DelegateChoice {
|
|
|
|
roleValue: "Room"
|
|
|
|
Room {
|
|
|
|
width: roomList.width
|
|
|
|
onActivated: showItemAtIndex(model.index)
|
|
|
|
}
|
|
|
|
}
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-05-06 15:49:25 +10:00
|
|
|
onFilterChanged: py.callCoro("set_substring_filter", ["all_rooms", filter])
|
|
|
|
|
2020-04-28 12:10:10 +10:00
|
|
|
|
2020-05-06 15:49:25 +10:00
|
|
|
property string filter: ""
|
2020-05-12 20:09:07 +10:00
|
|
|
readonly property var accountIndice: {
|
|
|
|
const accounts = {}
|
2020-05-02 03:02:20 +10:00
|
|
|
|
2020-05-06 15:49:25 +10:00
|
|
|
for (let i = 0; i < model.count; i++) {
|
2020-05-12 20:09:07 +10:00
|
|
|
if (model.get(i).type === "Account")
|
|
|
|
accounts[model.get(i).id] = i
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
return accounts
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function goToAccount(userId) {
|
2020-05-12 20:09:07 +10:00
|
|
|
model.get(accountIndice[userId] + 1).type === "Room" ?
|
|
|
|
currentIndex = accountIndice[userId] + 1 :
|
|
|
|
currentIndex = accountIndice[userId]
|
|
|
|
|
|
|
|
showItemLimiter.restart()
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
function goToAccountNumber(num) {
|
2020-05-12 20:09:07 +10:00
|
|
|
const index = Object.values(accountIndice).sort()[num]
|
|
|
|
|
|
|
|
model.get(index + 1).type === "Room" ?
|
|
|
|
currentIndex = index + 1 :
|
|
|
|
currentIndex = index
|
|
|
|
|
|
|
|
showItemLimiter.restart()
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
function showItemAtIndex(index=currentIndex) {
|
2020-04-28 12:10:10 +10:00
|
|
|
if (index === -1) index = 0
|
2020-05-06 15:49:25 +10:00
|
|
|
index = Math.min(index, model.count - 1)
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
const item = model.get(index)
|
|
|
|
|
|
|
|
item.type === "Account" ?
|
|
|
|
pageLoader.showPage(
|
|
|
|
"AccountSettings/AccountSettings", { "userId": item.id }
|
|
|
|
) :
|
|
|
|
pageLoader.showRoom(item.for_account, item.id)
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
currentIndex = index
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function showAccountRoomAtIndex(index) {
|
2020-05-12 20:09:07 +10:00
|
|
|
const item = model.get(currentIndex === -1 ? 0 : currentIndex)
|
|
|
|
|
|
|
|
const currentUserId =
|
|
|
|
item.type === "Account" ? item.id : item.for_account
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-12 20:09:07 +10:00
|
|
|
showItemAtIndex(accountIndice[currentUserId] + 1 + index)
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
|
|
|
|
Timer {
|
2020-05-12 20:09:07 +10:00
|
|
|
id: showItemLimiter
|
2020-04-27 04:20:45 +10:00
|
|
|
interval: 200
|
2020-05-12 20:09:07 +10:00
|
|
|
onTriggered: showItemAtIndex()
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToPreviousRoom
|
2020-05-12 20:09:07 +10:00
|
|
|
onActivated: { decrementCurrentIndex(); showItemLimiter.restart() }
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToNextRoom
|
2020-05-12 20:09:07 +10:00
|
|
|
onActivated: { incrementCurrentIndex(); showItemLimiter.restart() }
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
model: Object.keys(window.settings.keys.focusRoomAtIndex)
|
|
|
|
|
|
|
|
Item {
|
|
|
|
HShortcut {
|
|
|
|
sequence: window.settings.keys.focusRoomAtIndex[modelData]
|
2020-04-30 04:00:02 +10:00
|
|
|
onActivated:
|
|
|
|
showAccountRoomAtIndex(parseInt(modelData - 1, 10))
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 13:49:36 +10:00
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
z: -100
|
2020-05-13 22:24:53 +10:00
|
|
|
color: theme.mainPane.listView.background
|
2020-04-28 13:49:36 +10:00
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|