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-01 18:56:03 +10:00
|
|
|
import QtQml.Models 2.12
|
2020-04-27 04:20:45 +10:00
|
|
|
import ".."
|
|
|
|
import "../Base"
|
|
|
|
|
|
|
|
HListView {
|
|
|
|
id: roomList
|
2020-05-01 16:12:58 +10:00
|
|
|
add: null // See the XXX comment in HListView.qml
|
2020-05-01 06:37:03 +10:00
|
|
|
|
2020-05-01 14:27:02 +10:00
|
|
|
model: HStringFilterModel {
|
|
|
|
id: filterModel
|
|
|
|
sourceModel: ModelStore.get("every_room")
|
|
|
|
field: "display_name"
|
2020-05-01 16:12:58 +10:00
|
|
|
|
2020-05-01 06:37:03 +10:00
|
|
|
delegate: Room {
|
2020-05-01 16:12:58 +10:00
|
|
|
id: room
|
2020-05-01 06:37:03 +10:00
|
|
|
width: roomList.width
|
2020-05-01 18:56:03 +10:00
|
|
|
onActivated: showRoomAtIndex(DelegateModel.filteredIndex)
|
2020-05-01 16:12:58 +10:00
|
|
|
ListView.onAdd: ParallelAnimation {
|
|
|
|
HNumberAnimation {
|
|
|
|
target: room; property: "opacity"; from: 0; to: 1;
|
|
|
|
}
|
|
|
|
HNumberAnimation {
|
|
|
|
target: room; property: "scale"; from: 0; to: 1;
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 06:37:03 +10:00
|
|
|
}
|
|
|
|
}
|
2020-04-30 04:00:02 +10:00
|
|
|
|
|
|
|
section.property: "for_account"
|
|
|
|
section.labelPositioning:
|
|
|
|
ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
|
|
|
|
section.delegate: Account {
|
|
|
|
accountModel: ModelStore.get("accounts").find(section)
|
|
|
|
width: roomList.width
|
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-04-28 12:10:10 +10:00
|
|
|
|
2020-05-01 14:27:02 +10:00
|
|
|
property alias filter: filterModel.filter
|
2020-04-30 04:00:02 +10:00
|
|
|
readonly property var sectionIndice: {
|
|
|
|
const sections = {}
|
|
|
|
const accounts = ModelStore.get("accounts")
|
|
|
|
let total = 0
|
|
|
|
|
|
|
|
for (let i = 0; i < accounts.count; i++) {
|
|
|
|
const userId = accounts.get(i).id
|
|
|
|
sections[userId] = total
|
|
|
|
total += ModelStore.get(userId, "rooms").count
|
|
|
|
}
|
|
|
|
|
|
|
|
return sections
|
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function goToAccount(userId) {
|
|
|
|
currentIndex = sectionIndice[userId]
|
|
|
|
}
|
|
|
|
|
|
|
|
function goToAccountNumber(num) {
|
|
|
|
currentIndex = Object.values(sectionIndice).sort()[num]
|
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function showRoomAtIndex(index=currentIndex) {
|
2020-04-28 12:10:10 +10:00
|
|
|
if (index === -1) index = 0
|
2020-05-01 06:37:03 +10:00
|
|
|
index = Math.min(index, model.filtered.count - 1)
|
2020-04-30 04:00:02 +10:00
|
|
|
|
2020-05-01 06:37:03 +10:00
|
|
|
const room = model.filtered.get(index).model
|
2020-04-30 04:00:02 +10:00
|
|
|
pageLoader.showRoom(room.for_account, room.id)
|
2020-04-27 04:20:45 +10:00
|
|
|
currentIndex = index
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:00:02 +10:00
|
|
|
function showAccountRoomAtIndex(index) {
|
2020-05-01 06:37:03 +10:00
|
|
|
const userId = model.filtered.get(
|
|
|
|
currentIndex === -1 ? 0 : currentIndex
|
|
|
|
).model.for_account
|
2020-04-30 04:00:02 +10:00
|
|
|
|
|
|
|
const rooms = ModelStore.get(userId, "rooms")
|
|
|
|
if (! rooms.count) return
|
|
|
|
|
|
|
|
const room = rooms.get(utils.numberWrapAt(index, rooms.count))
|
2020-05-01 06:37:03 +10:00
|
|
|
showRoomAtIndex(model.filteredFindIndex(room.id))
|
2020-04-30 04:00:02 +10:00
|
|
|
}
|
|
|
|
|
2020-04-27 04:20:45 +10:00
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: showRoomLimiter
|
|
|
|
interval: 200
|
2020-04-30 04:00:02 +10:00
|
|
|
onTriggered: showRoomAtIndex()
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToPreviousRoom
|
|
|
|
onActivated: { decrementCurrentIndex(); showRoomLimiter.restart() }
|
|
|
|
}
|
|
|
|
|
|
|
|
HShortcut {
|
|
|
|
sequences: window.settings.keys.goToNextRoom
|
|
|
|
onActivated: { incrementCurrentIndex(); showRoomLimiter.restart() }
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
color: theme.accountView.roomList.background
|
|
|
|
}
|
2020-04-27 04:20:45 +10:00
|
|
|
}
|