Cleanup connection handling in QML
Consistently pass connection objects to files that need them instead of randomly using Controller.activeConnection in some of them
This commit is contained in:
committed by
Carl Schwan
parent
6439fa48f9
commit
5e80715898
@@ -17,6 +17,8 @@ Kirigami.ScrollablePage {
|
||||
|
||||
signal chosen(string roomId)
|
||||
|
||||
required property NeoChatConnection connection
|
||||
|
||||
header: Kirigami.SearchField {
|
||||
onTextChanged: sortModel.filterText = text
|
||||
}
|
||||
@@ -25,7 +27,7 @@ Kirigami.ScrollablePage {
|
||||
model: SortFilterRoomListModel {
|
||||
id: sortModel
|
||||
sourceModel: RoomListModel {
|
||||
connection: Controller.activeConnection
|
||||
connection: root.connection
|
||||
}
|
||||
}
|
||||
delegate: RoomDelegate {
|
||||
@@ -34,6 +36,7 @@ Kirigami.ScrollablePage {
|
||||
onClicked: {
|
||||
root.chosen(roomDelegate.currentRoom.id)
|
||||
}
|
||||
connection: root.connection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ FormCard.FormCardPage {
|
||||
id: root
|
||||
|
||||
property NeoChatRoom room
|
||||
required property NeoChatConnection connection
|
||||
|
||||
title: i18n("Developer Tools")
|
||||
|
||||
@@ -37,7 +38,10 @@ FormCard.FormCardPage {
|
||||
|
||||
RoomData {
|
||||
room: root.room
|
||||
connection: root.connection
|
||||
}
|
||||
ServerData {
|
||||
connection: root.connection
|
||||
}
|
||||
ServerData {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,6 @@ Kirigami.ScrollablePage {
|
||||
publicRoomListModel.next();
|
||||
}
|
||||
delegate: ExplorerDelegate {
|
||||
connection: root.connection
|
||||
onRoomSelected: (roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
|
||||
root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined);
|
||||
root.closeDialog();
|
||||
|
||||
@@ -12,13 +12,16 @@ import '../Dialog' as Dialog
|
||||
|
||||
QQC2.Menu {
|
||||
id: root
|
||||
|
||||
required property NeoChatConnection connection
|
||||
|
||||
margins: Kirigami.Units.smallSpacing
|
||||
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Edit this account")
|
||||
icon.name: "document-edit"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/AccountEditorPage.qml", {
|
||||
connection: Controller.activeConnection
|
||||
connection: root.connection
|
||||
}, {
|
||||
title: i18n("Account editor")
|
||||
});
|
||||
@@ -28,7 +31,7 @@ QQC2.Menu {
|
||||
icon.name: "notifications"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {
|
||||
defaultPage: "notifications",
|
||||
connection: Controller.activeConnection,
|
||||
connection: root.connection,
|
||||
}, {
|
||||
title: i18n("Configure")
|
||||
});
|
||||
@@ -38,7 +41,7 @@ QQC2.Menu {
|
||||
icon.name: "computer-symbolic"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {
|
||||
defaultPage: "devices",
|
||||
connection: Controller.activeConnection,
|
||||
connection: root.connection,
|
||||
}, {
|
||||
title: i18n("Configure")
|
||||
})
|
||||
@@ -52,7 +55,7 @@ QQC2.Menu {
|
||||
Component {
|
||||
id: confirmLogoutDialogComponent
|
||||
Dialog.ConfirmLogout {
|
||||
connection: Controller.activeConnection
|
||||
connection: root.connection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@ import org.kde.neochat 1.0
|
||||
*/
|
||||
Loader {
|
||||
id: root
|
||||
|
||||
property NeoChatRoom room
|
||||
required property NeoChatConnection connection
|
||||
|
||||
signal closed()
|
||||
|
||||
Component {
|
||||
@@ -116,7 +119,7 @@ Loader {
|
||||
QQC2.MenuItem {
|
||||
text: i18n("Room Settings")
|
||||
icon.name: "configure"
|
||||
onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Room Settings") })
|
||||
onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room, connection: connection}, { title: i18n("Room Settings") })
|
||||
}
|
||||
|
||||
QQC2.MenuSeparator {}
|
||||
@@ -183,7 +186,7 @@ Loader {
|
||||
QQC2.ToolButton {
|
||||
icon.name: 'settings-configure'
|
||||
onClicked: {
|
||||
QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Room Settings") })
|
||||
QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room, connection: root.connection}, { title: i18n("Room Settings") })
|
||||
drawer.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ RowLayout {
|
||||
text: i18n("Explore rooms")
|
||||
icon.name: "compass"
|
||||
onTriggered: {
|
||||
let dialog = pageStack.pushDialogLayer("qrc:/JoinRoomPage.qml", {connection: Controller.activeConnection}, {title: i18nc("@title", "Explore Rooms")})
|
||||
let dialog = pageStack.pushDialogLayer("qrc:/JoinRoomPage.qml", {connection: root.connection}, {title: i18nc("@title", "Explore Rooms")})
|
||||
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
|
||||
if (isJoined) {
|
||||
RoomManager.enterRoom(Controller.activeConnection.room(roomId))
|
||||
RoomManager.enterRoom(root.connection.room(roomId))
|
||||
} else {
|
||||
Controller.joinRoom(roomId)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ RowLayout {
|
||||
property Kirigami.Action chatAction: Kirigami.Action {
|
||||
text: i18n("Start a Chat")
|
||||
icon.name: "list-add-user"
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/StartChatPage.qml", {connection: Controller.activeConnection}, {title: i18nc("@title", "Start a Chat")})
|
||||
onTriggered: pageStack.pushDialogLayer("qrc:/StartChatPage.qml", {connection: root.connection}, {title: i18nc("@title", "Start a Chat")})
|
||||
}
|
||||
property Kirigami.Action roomAction: Kirigami.Action {
|
||||
text: i18n("Create a Room")
|
||||
|
||||
@@ -102,6 +102,8 @@ Kirigami.Page {
|
||||
id: spaceDrawer
|
||||
Layout.preferredWidth: spaceDrawer.enabled ? Kirigami.Units.gridUnit * 3 : 0
|
||||
Layout.fillHeight: true
|
||||
|
||||
connection: root.connection
|
||||
}
|
||||
|
||||
Kirigami.Separator {
|
||||
@@ -161,14 +163,14 @@ Kirigami.Page {
|
||||
text: sortFilterRoomListModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms")
|
||||
onTriggered: {
|
||||
let dialog = pageStack.layers.push("qrc:/JoinRoomPage.qml", {
|
||||
connection: Controller.activeConnection,
|
||||
connection: root.connection,
|
||||
keyword: sortFilterRoomListModel.filterText
|
||||
}, {
|
||||
title: i18nc("@title", "Explore Rooms")
|
||||
})
|
||||
dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
|
||||
if (isJoined) {
|
||||
RoomManager.enterRoom(Controller.activeConnection.room(roomId))
|
||||
RoomManager.enterRoom(root.connection.room(roomId))
|
||||
} else {
|
||||
Controller.joinRoom(roomId)
|
||||
}
|
||||
@@ -265,6 +267,8 @@ Kirigami.Page {
|
||||
RoomList.RoomDelegate {
|
||||
filterText: sortFilterRoomListModel.filterText
|
||||
|
||||
connection: root.connection
|
||||
|
||||
height: visible ? implicitHeight : 0
|
||||
|
||||
visible: categoryVisible || filterText.length > 0 || Config.mergeRoomList
|
||||
@@ -282,6 +286,7 @@ Kirigami.Page {
|
||||
footer: UserInfo {
|
||||
width: parent.width
|
||||
visible: !root.collapsed
|
||||
connection: root.connection
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
|
||||
@@ -22,6 +22,7 @@ Delegates.RoundedItemDelegate {
|
||||
required property int notificationCount
|
||||
required property int highlightCount
|
||||
required property NeoChatRoom currentRoom
|
||||
required property NeoChatConnection connection
|
||||
required property bool categoryVisible
|
||||
required property string filterText
|
||||
required property string avatar
|
||||
@@ -138,6 +139,7 @@ Delegates.RoundedItemDelegate {
|
||||
const component = Qt.createComponent(Qt.resolvedUrl("./ContextMenu.qml"))
|
||||
const menu = component.createObject(root, {
|
||||
room: root.currentRoom,
|
||||
connection: root.connection,
|
||||
});
|
||||
if (!Kirigami.Settings.isMobile && !Config.compactRoomList) {
|
||||
configButton.visible = true;
|
||||
|
||||
@@ -17,6 +17,8 @@ QQC2.Control {
|
||||
readonly property real pinnedWidth: Kirigami.Units.gridUnit * 6
|
||||
property bool drawerEnabled: true
|
||||
|
||||
required property NeoChatConnection connection
|
||||
|
||||
leftPadding: 0
|
||||
rightPadding: 0
|
||||
topPadding: 0
|
||||
@@ -73,12 +75,12 @@ QQC2.Control {
|
||||
Repeater {
|
||||
model: SortFilterSpaceListModel {
|
||||
sourceModel: RoomListModel {
|
||||
connection: Controller.activeConnection
|
||||
connection: root.connection
|
||||
}
|
||||
}
|
||||
onCountChanged: {
|
||||
root.enabled = count > 0
|
||||
if (!Controller.activeConnection.room(root.selectedSpaceId)) {
|
||||
if (!root.connection.room(root.selectedSpaceId)) {
|
||||
root.selectedSpaceId = ""
|
||||
}
|
||||
}
|
||||
@@ -111,7 +113,8 @@ QQC2.Control {
|
||||
|
||||
function createContextMenu(room) {
|
||||
let context = spaceListContextMenu.createObject(root, {
|
||||
room: room
|
||||
room: room,
|
||||
connection: root.connection
|
||||
});
|
||||
context.open()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,10 @@ import org.kde.neochat 1.0
|
||||
*/
|
||||
Loader {
|
||||
id: root
|
||||
|
||||
property NeoChatRoom room
|
||||
required property NeoChatConnection connection
|
||||
|
||||
signal closed()
|
||||
|
||||
Component {
|
||||
@@ -41,7 +44,7 @@ Loader {
|
||||
QQC2.MenuItem {
|
||||
text: i18nc("'Space' is a matrix space", "Space Settings")
|
||||
icon.name: 'settings-configure'
|
||||
onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Space Settings") })
|
||||
onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room, connection: connection}, { title: i18n("Space Settings") })
|
||||
}
|
||||
|
||||
QQC2.MenuSeparator {}
|
||||
@@ -99,7 +102,7 @@ Loader {
|
||||
|
||||
QQC2.ToolButton {
|
||||
icon.name: 'settings-configure'
|
||||
onClicked: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room}, { title: i18n("Space Settings") })
|
||||
onClicked: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/Categories.qml', {room: room, connection: root.connection}, { title: i18n("Space Settings") })
|
||||
}
|
||||
}
|
||||
Kirigami.BasicListItem {
|
||||
|
||||
@@ -15,6 +15,8 @@ QQC2.ToolBar {
|
||||
|
||||
padding: 0
|
||||
|
||||
required property NeoChatConnection connection
|
||||
|
||||
property var addAccount
|
||||
|
||||
contentItem: ColumnLayout {
|
||||
@@ -126,7 +128,7 @@ QQC2.ToolBar {
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
Controller.activeConnection = userDelegate.connection
|
||||
root.connection = userDelegate.connection
|
||||
if (switchUserButton.checked) {
|
||||
switchUserButton.checked = false
|
||||
}
|
||||
@@ -164,7 +166,7 @@ QQC2.ToolBar {
|
||||
accountMenu.open();
|
||||
} else {
|
||||
pageStack.pushDialogLayer(Qt.resolvedUrl('qrc:/AccountEditorPage.qml'), {
|
||||
connection: Controller.activeConnection
|
||||
connection: root.connection
|
||||
}, {
|
||||
title: i18n("Account editor")
|
||||
});
|
||||
@@ -175,10 +177,10 @@ QQC2.ToolBar {
|
||||
text: i18n("Edit this account")
|
||||
|
||||
contentItem: KirigamiComponents.Avatar {
|
||||
readonly property string mediaId: Controller.activeConnection.localUser.avatarMediaId
|
||||
readonly property string mediaId: root.connection.localUser.avatarMediaId
|
||||
|
||||
source: mediaId ? ("image://mxc/" + mediaId) : ""
|
||||
name: Controller.activeConnection.localUser.displayName ?? Controller.activeConnection.localUser.id
|
||||
name: root.connection.localUser.displayName ?? root.connection.localUser.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,13 +189,13 @@ QQC2.ToolBar {
|
||||
spacing: 0
|
||||
QQC2.Label {
|
||||
id: displayNameLabel
|
||||
text: Controller.activeConnection.localUser.displayName
|
||||
text: root.connection.localUser.displayName
|
||||
textFormat: Text.PlainText
|
||||
elide: Text.ElideRight
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
QQC2.Label {
|
||||
text: (Controller.activeConnection.label.length > 0 ? (Controller.activeConnection.label + " ") : "") + Controller.activeConnection.localUser.id
|
||||
text: (root.connection.label.length > 0 ? (root.connection.label + " ") : "") + root.connection.localUser.id
|
||||
font.pointSize: displayNameLabel.font.pointSize * 0.8
|
||||
opacity: 0.7
|
||||
textFormat: Text.PlainText
|
||||
@@ -232,7 +234,7 @@ QQC2.ToolBar {
|
||||
}
|
||||
QQC2.ToolButton {
|
||||
icon.name: "settings-configure"
|
||||
onClicked: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {connection: Controller.activeConnection}, { title: i18n("Configure") })
|
||||
onClicked: pageStack.pushDialogLayer("qrc:/SettingsPage.qml", {connection: root.connection}, { title: i18n("Configure") })
|
||||
text: i18n("Open Settings")
|
||||
display: QQC2.AbstractButton.IconOnly
|
||||
Layout.minimumWidth: Layout.preferredWidth
|
||||
@@ -249,6 +251,7 @@ QQC2.ToolBar {
|
||||
AccountMenu {
|
||||
id: accountMenu
|
||||
y: -height
|
||||
connection: root.connection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ Kirigami.Page {
|
||||
|
||||
/// Not readonly because of the separate window view.
|
||||
property NeoChatRoom currentRoom: RoomManager.currentRoom
|
||||
|
||||
required property NeoChatConnection connection
|
||||
property bool loading: !root.currentRoom || (root.currentRoom.timelineSize === 0 && !root.currentRoom.allHistoryLoaded)
|
||||
|
||||
/// Disable cancel shortcut. Used by the separate window since it provides its own cancel implementation.
|
||||
@@ -109,6 +111,7 @@ Kirigami.Page {
|
||||
id: chatBox
|
||||
width: parent.width
|
||||
currentRoom: root.currentRoom
|
||||
connection: root.connection
|
||||
onMessageSent: {
|
||||
if (!timelineViewLoader.item.atYEnd) {
|
||||
timelineViewLoader.item.goToLastMessage();
|
||||
@@ -153,7 +156,7 @@ Kirigami.Page {
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Controller.activeConnection
|
||||
target: root.connection
|
||||
function onJoinedRoom(room, invited) {
|
||||
if(root.currentRoom.id === invited.id) {
|
||||
RoomManager.enterRoom(room);
|
||||
|
||||
@@ -13,6 +13,8 @@ Kirigami.ApplicationWindow {
|
||||
id: root
|
||||
|
||||
required property NeoChatRoom currentRoom
|
||||
required property NeoChatConnection connection
|
||||
|
||||
minimumWidth: Kirigami.Units.gridUnit * 10
|
||||
minimumHeight: Kirigami.Units.gridUnit * 15
|
||||
|
||||
@@ -24,6 +26,7 @@ Kirigami.ApplicationWindow {
|
||||
visible: true
|
||||
currentRoom: root.currentRoom
|
||||
disableCancelShortcut: true
|
||||
connection: root.connection
|
||||
}
|
||||
|
||||
onCurrentRoomChanged: if (!currentRoom) {
|
||||
|
||||
@@ -13,6 +13,7 @@ Kirigami.ScrollablePage {
|
||||
id: root
|
||||
|
||||
property NeoChatRoom currentRoom
|
||||
required property NeoChatConnection connection
|
||||
|
||||
title: i18nc("@action:title", "Search Messages")
|
||||
|
||||
@@ -20,7 +21,7 @@ Kirigami.ScrollablePage {
|
||||
|
||||
SearchModel {
|
||||
id: searchModel
|
||||
connection: Controller.activeConnection
|
||||
connection: root.connection
|
||||
searchText: searchField.text
|
||||
room: root.currentRoom
|
||||
}
|
||||
@@ -71,6 +72,8 @@ Kirigami.ScrollablePage {
|
||||
}
|
||||
|
||||
model: searchModel
|
||||
delegate: EventDelegate {}
|
||||
delegate: EventDelegate {
|
||||
connection: root.connection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user