Move the various room models into RoomManager

Move the various room models into RoomManager. This means the same room models are always used and is a base from which further logic can be moved from QML to cpp.
This commit is contained in:
James Graham
2024-03-31 12:56:27 +00:00
parent 78ae14ab2f
commit 053ca6bed8
17 changed files with 155 additions and 95 deletions

View File

@@ -18,16 +18,11 @@ Kirigami.ScrollablePage {
required property NeoChatConnection connection
header: Kirigami.SearchField {
onTextChanged: sortModel.filterText = text
onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text
}
ListView {
model: SortFilterRoomListModel {
id: sortModel
sourceModel: RoomListModel {
connection: root.connection
}
}
model: RoomManager.sortFilterRoomListModel
delegate: RoomDelegate {
id: roomDelegate
onClicked: {

View File

@@ -25,13 +25,8 @@ QQC2.Popup {
root.open();
}
RoomListModel {
id: roomListModel
connection: root.connection
}
Component.onCompleted: {
chatDocumentHandler.completionModel.roomListModel = roomListModel;
chatDocumentHandler.completionModel.roomListModel = RoomManager.roomListModel;
}
function incrementIndex() {

View File

@@ -66,6 +66,7 @@ QQC2.Dialog {
root.close();
}
focusSequence: ""
onTextChanged: RoomManager.sortFilterRoomListModel.filterText = text
}
QQC2.ScrollView {
@@ -81,13 +82,7 @@ QQC2.Dialog {
highlightMoveDuration: 200
Keys.forwardTo: searchField
keyNavigationEnabled: true
model: SortFilterRoomListModel {
filterText: searchField.text
sourceModel: RoomListModel {
id: roomListModel
connection: root.connection
}
}
model: RoomManager.sortFilterRoomListModel
delegate: RoomDelegate {
connection: root.connection

View File

@@ -25,14 +25,11 @@ ColumnLayout {
text: i18n("Room")
textRole: "escapedDisplayName"
valueRole: "roomId"
displayText: roomListModel.data(roomListModel.index(currentIndex, 0), RoomListModel.DisplayNameRole)
model: RoomListModel {
id: roomListModel
connection: root.connection
}
displayText: RoomManager.roomListModel.data(RoomManager.roomListModel.index(currentIndex, 0), RoomListModel.DisplayNameRole)
model: RoomManager.roomListModel
currentIndex: 0
Component.onCompleted: currentIndex = roomListModel.rowForRoom(root.room)
onCurrentValueChanged: root.room = roomListModel.roomByAliasOrId(roomComboBox.currentValue)
Component.onCompleted: currentIndex = RoomManager.roomListModel.rowForRoom(root.room)
onCurrentValueChanged: root.room = RoomManager.roomListModel.roomByAliasOrId(roomComboBox.currentValue)
}
FormCard.FormTextDelegate {
text: i18n("Room Id: %1", root.room.id)

View File

@@ -29,10 +29,6 @@ Kirigami.Page {
required property NeoChatConnection connection
readonly property RoomTreeModel roomTreeModel: RoomTreeModel {
connection: root.connection
}
readonly property bool collapsed: Config.collapsed
onCurrentWidthChanged: pageStack.defaultColumnWidth = root.currentWidth
@@ -41,7 +37,7 @@ Kirigami.Page {
onCollapsedChanged: {
if (collapsed) {
sortFilterRoomTreeModel.filterText = "";
RoomManager.sortFilterRoomTreeModel.filterText = "";
}
}
@@ -107,8 +103,6 @@ Kirigami.Page {
Layout.fillHeight: true
connection: root.connection
onSpacesUpdated: sortFilterRoomTreeModel.invalidate()
}
Kirigami.Separator {
@@ -136,15 +130,7 @@ Kirigami.Page {
clip: true
reuseItems: false
model: SortFilterRoomTreeModel {
id: sortFilterRoomTreeModel
sourceModel: root.roomTreeModel
activeSpaceId: RoomManager.currentSpace
mode: RoomManager.currentSpace === "DM" ? SortFilterRoomTreeModel.DirectChats : SortFilterRoomTreeModel.Rooms
onRowsInserted: (index, first, last) => treeView.expandTo(index)
onDataChanged: treeView.expandRecursively()
}
model: RoomManager.sortFilterRoomTreeModel
selectionModel: ItemSelectionModel {}
@@ -217,7 +203,7 @@ Kirigami.Page {
anchors.horizontalCenterOffset: (spaceDrawer.width + 1) / 2
width: scrollView.width - Kirigami.Units.largeSpacing * 4
visible: treeView.rows == 0
text: if (sortFilterRoomTreeModel.filterText.length > 0) {
text: if (RoomManager.sortFilterRoomTreeModel.filterText.length > 0) {
return spaceDrawer.showDirectChats ? i18n("No friends found") : i18n("No rooms found");
} else {
return spaceDrawer.showDirectChats ? i18n("You haven't added any of your friends yet, click below to search for them.") : i18n("Join some rooms to get started");
@@ -226,12 +212,12 @@ Kirigami.Page {
Kirigami.Action {
id: exploreRoomAction
icon.name: sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms")
icon.name: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms")
onTriggered: {
let dialog = pageStack.layers.push(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), {
connection: root.connection,
keyword: sortFilterRoomTreeModel.filterText
keyword: RoomManager.sortFilterRoomTreeModel.filterText
}, {
title: i18nc("@title", "Explore Rooms")
});
@@ -243,8 +229,8 @@ Kirigami.Page {
Kirigami.Action {
id: userSearchAction
icon.name: sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in friend directory") : i18n("Find your friends")
icon.name: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? "search" : "list-add"
text: RoomManager.sortFilterRoomTreeModel.filterText.length > 0 ? i18n("Search in friend directory") : i18n("Find your friends")
onTriggered: pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'UserSearchPage.qml'), {
connection: root.connection
}, {
@@ -325,7 +311,7 @@ Kirigami.Page {
connection: root.connection
onTextChanged: newText => {
sortFilterRoomTreeModel.filterText = newText;
RoomManager.sortFilterRoomTreeModel.filterText = newText;
treeView.expandRecursively();
}
}
@@ -337,7 +323,7 @@ Kirigami.Page {
connection: root.connection
onTextChanged: newText => {
sortFilterRoomTreeModel.filterText = newText;
RoomManager.sortFilterRoomTreeModel.filterText = newText;
}
}
}

View File

@@ -21,8 +21,6 @@ QQC2.Control {
topPadding: 0
bottomPadding: 0
signal spacesUpdated
contentItem: Loader {
id: sidebarColumn
z: 0
@@ -169,12 +167,7 @@ QQC2.Control {
}
Repeater {
model: SortFilterSpaceListModel {
sourceModel: RoomListModel {
connection: root.connection
}
onLayoutChanged: root.spacesUpdated()
}
model: RoomManager.sortFilterSpaceListModel
delegate: AvatarTabButton {
id: spaceDelegate
@@ -194,7 +187,6 @@ QQC2.Control {
onSelected: {
RoomManager.resolveResource(spaceDelegate.roomId);
RoomManager.currentSpace = spaceDelegate.roomId;
root.selectionChanged();
}
checked: RoomManager.currentSpace === roomId
onContextMenuRequested: root.createContextMenu(currentRoom)