diff --git a/src/models/publicroomlistmodel.cpp b/src/models/publicroomlistmodel.cpp index d0dba9030..2cf585b2c 100644 --- a/src/models/publicroomlistmodel.cpp +++ b/src/models/publicroomlistmodel.cpp @@ -124,6 +124,15 @@ void PublicRoomListModel::setShowOnlySpaces(bool showOnlySpaces) } m_showOnlySpaces = showOnlySpaces; Q_EMIT showOnlySpacesChanged(); + + nextBatch = QString(); + attempted = false; + + if (job) { + job->abandon(); + job = nullptr; + Q_EMIT searchingChanged(); + } } void PublicRoomListModel::search(int limit) @@ -243,6 +252,9 @@ QVariant PublicRoomListModel::data(const QModelIndex &index, int role) const return m_connection->room(room.roomId, JoinState::Join) != nullptr; } + if (role == IsSpaceRole) { + return room.roomType == QLatin1String("m.space"); + } return {}; } @@ -259,6 +271,7 @@ QHash PublicRoomListModel::roleNames() const roles[AllowGuestsRole] = "allowGuests"; roles[WorldReadableRole] = "worldReadable"; roles[IsJoinedRole] = "isJoined"; + roles[IsSpaceRole] = "isSpace"; roles[AliasRole] = "alias"; return roles; diff --git a/src/models/publicroomlistmodel.h b/src/models/publicroomlistmodel.h index e2c81ea10..7d077adeb 100644 --- a/src/models/publicroomlistmodel.h +++ b/src/models/publicroomlistmodel.h @@ -69,6 +69,7 @@ public: AllowGuestsRole, /**< Whether the room allows guest users. */ WorldReadableRole, /**< Whether the room events can be seen by non-members. */ IsJoinedRole, /**< Whether the local user has joined the room. */ + IsSpaceRole, /**< Whether the room is a space. */ }; explicit PublicRoomListModel(QObject *parent = nullptr); diff --git a/src/qml/ExploreRoomsPage.qml b/src/qml/ExploreRoomsPage.qml index 43ea0783e..f31f0f1bd 100644 --- a/src/qml/ExploreRoomsPage.qml +++ b/src/qml/ExploreRoomsPage.qml @@ -32,7 +32,13 @@ SearchPage { /** * @brief Whether results should only includes spaces. */ - property bool showOnlySpaces: false + property bool showOnlySpaces: spacesOnlyButton.checked + onShowOnlySpacesChanged: updateSearch() + + /** + * @brief Whetherthe button to toggle the showOnlySpaces state should be shown. + */ + property bool showOnlySpacesButton: true /** * @brief Signal emitted when a room is selected. @@ -47,9 +53,22 @@ SearchPage { Component.onCompleted: focusSearch() - headerTrailing: ServerComboBox { - id: serverComboBox - connection: root.connection + headerTrailing: RowLayout { + QQC2.Button { + id: spacesOnlyButton + icon.name: "globe" + display: QQC2.Button.IconOnly + checkable: true + text: i18nc("@action:button", "Only show spaces") + + QQC2.ToolTip.visible: hovered + QQC2.ToolTip.text: text + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay + } + ServerComboBox { + id: serverComboBox + connection: root.connection + } } model: PublicRoomListModel { diff --git a/src/qml/ExplorerDelegate.qml b/src/qml/ExplorerDelegate.qml index c097d7270..01e52bd6a 100644 --- a/src/qml/ExplorerDelegate.qml +++ b/src/qml/ExplorerDelegate.qml @@ -21,6 +21,7 @@ Delegates.RoundedItemDelegate { required property string topic required property int memberCount required property bool isJoined + required property bool isSpace property bool justJoined: false /** @@ -56,7 +57,7 @@ Delegates.RoundedItemDelegate { RowLayout { Layout.fillWidth: true Kirigami.Heading { - Layout.fillWidth: true + Layout.fillWidth: !spaceLabel.visible level: 4 text: root.displayName font.bold: true @@ -64,6 +65,13 @@ Delegates.RoundedItemDelegate { elide: Text.ElideRight wrapMode: Text.NoWrap } + QQC2.Label { + id: spaceLabel + Layout.fillWidth: true + visible: root.isSpace + text: i18nc("@info:label A matrix space", "Space") + color: Kirigami.Theme.linkColor + } QQC2.Label { visible: root.isJoined || root.justJoined text: i18n("Joined") diff --git a/src/qml/SearchPage.qml b/src/qml/SearchPage.qml index 87a4cf7ed..e80f04587 100644 --- a/src/qml/SearchPage.qml +++ b/src/qml/SearchPage.qml @@ -82,6 +82,13 @@ Kirigami.ScrollablePage { searchField.forceActiveFocus(); } + /** + * @brief Force the search to be updated if the model has a valid search function. + */ + function updateSearch() { + searchTimer.restart(); + } + header: QQC2.Control { padding: Kirigami.Units.largeSpacing @@ -119,11 +126,18 @@ Kirigami.ScrollablePage { QQC2.Button { id: searchButton icon.name: "search" + display: QQC2.Button.IconOnly + text: i18nc("@action:button", "Search") + onClicked: { if (typeof model.search === 'function') { model.search(); } } + + QQC2.ToolTip.visible: hovered + QQC2.ToolTip.text: text + QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay } Timer { id: searchTimer diff --git a/src/qml/SelectParentDialog.qml b/src/qml/SelectParentDialog.qml index 075b738e4..985136e7a 100644 --- a/src/qml/SelectParentDialog.qml +++ b/src/qml/SelectParentDialog.qml @@ -51,7 +51,8 @@ Kirigami.Dialog { onClicked: { let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), { connection: root.room.connection, - showOnlySpaces: true + showOnlySpaces: true, + showOnlySpacesButton: false }, { title: i18nc("@title", "Choose Parent Space") }); @@ -135,7 +136,8 @@ Kirigami.Dialog { onClicked: { let dialog = pageStack.pushDialogLayer(Qt.createComponent('org.kde.neochat', 'ExploreRoomsPage.qml'), { connection: root.room.connection, - showOnlySpaces: true + showOnlySpaces: true, + showOnlySpacesButton: false }, { title: i18nc("@title", "Explore Rooms") });