From ab390704eb07aa203fca99f206c1e3be45b70c97 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 19 Aug 2020 04:38:29 -0400 Subject: [PATCH] Use homeserver URL field also as a filter field --- TODO.md | 5 ++- src/backend/backend.py | 2 ++ src/backend/models/model_store.py | 6 +++- src/backend/models/special_models.py | 11 ++++++ src/gui/Pages/AddAccount/ServerBrowser.qml | 40 +++++++++++++++------- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/TODO.md b/TODO.md index b17392d6..a121002c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,10 +1,13 @@ # TODO +- server list sorting method / explain what the % number is (stability) +- server list: make it more obvious that it can be scrolled +- server list: make current item highlight more visible +- support (shift+)tab in filter fields - clicking cancel on SSO "waiting" box doesn't do anything the first time - spam alt+shift+a when starting app on server browser → segfault - remove items.Device - register tab for sso servers? -- sever list - cursor shape in HBox/HTabbedBox pages over fields - login with account already added → infinite spinner in room list - verify onKeyboardAccept/Cancel things respect button enabled state diff --git a/src/backend/backend.py b/src/backend/backend.py index 8c939f39..683d12cf 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -84,6 +84,8 @@ class Backend: - `("", "", "filtered_members")`: See `models.special_models.FilteredMembers` docstring + - `("filtered_homeservers")`: + See `models.special_models.FilteredHomeservers` docstring clients: A `{user_id: MatrixClient}` dict for the logged-in clients we managed. Every client is logged to one matrix account. diff --git a/src/backend/models/model_store.py b/src/backend/models/model_store.py index a65aa60e..4996af94 100644 --- a/src/backend/models/model_store.py +++ b/src/backend/models/model_store.py @@ -6,7 +6,9 @@ from typing import Dict from . import SyncId from .model import Model -from .special_models import AllRooms, FilteredMembers, MatchingAccounts +from .special_models import ( + AllRooms, FilteredMembers, FilteredHomeservers, MatchingAccounts, +) @dataclass(frozen=True) @@ -36,6 +38,8 @@ class ModelStore(UserDict): model = AllRooms(self["accounts"]) elif key == "matching_accounts": model = MatchingAccounts(self["all_rooms"]) + elif key == "filtered_homeservers": + model = FilteredHomeservers() elif is_tuple and len(key) == 3 and key[2] == "filtered_members": model = FilteredMembers(user_id=key[0], room_id=key[1]) else: diff --git a/src/backend/models/special_models.py b/src/backend/models/special_models.py index 5eb24374..d1b320f7 100644 --- a/src/backend/models/special_models.py +++ b/src/backend/models/special_models.py @@ -115,3 +115,14 @@ class FilteredMembers(FieldSubstringFilter): def accept_source(self, source: Model) -> bool: return source.sync_id == (self.user_id, self.room_id, "members") + + +class FilteredHomeservers(FieldSubstringFilter): + """Filtered list of public Matrix homeservers.""" + + def __init__(self) -> None: + super().__init__(sync_id="filtered_homeservers", fields=("id",)) + + + def accept_source(self, source: Model) -> bool: + return source.sync_id == "homeservers" diff --git a/src/gui/Pages/AddAccount/ServerBrowser.qml b/src/gui/Pages/AddAccount/ServerBrowser.qml index 230859bc..6fb71466 100644 --- a/src/gui/Pages/AddAccount/ServerBrowser.qml +++ b/src/gui/Pages/AddAccount/ServerBrowser.qml @@ -86,13 +86,7 @@ HBox { padding: 0 implicitWidth: theme.controls.box.defaultWidth * 1.25 - contentHeight: Math.min( - window.height, - Math.max( - serverList.contentHeight, - // busyIndicatorLoader.height + theme.spacing * 2, TODO - ) - ) + contentHeight: window.height header: HLabel { text: qsTr( @@ -138,8 +132,23 @@ HBox { ) placeholderText: "example.org" + onTextEdited: py.callCoro( + "set_substring_filter", ["filtered_homeservers", text], + ) + Layout.fillWidth: true Layout.fillHeight: true + + Keys.onBacktabPressed: ev => Keys.onUpPressed(ev) + Keys.onTabPressed: ev => Keys.onDownPressed(ev) + Keys.onUpPressed: { + serverList.decrementCurrentIndex() + serverList.setFieldText(serverList.currentIndex) + } + Keys.onDownPressed: { + serverList.incrementCurrentIndex() + serverList.setFieldText(serverList.currentIndex) + } } HButton { @@ -177,7 +186,10 @@ HBox { Timer { interval: 1000 - running: fetchServersFuture === null && serverList.count === 0 + running: + fetchServersFuture === null && + ModelStore.get("homeservers").count === 0 + repeat: true triggeredOnStart: true onTriggered: box.fetchServers() @@ -197,16 +209,20 @@ HBox { HListView { id: serverList + + function setFieldText(fromItemIndex) { + serverField.item.field.text = + model.get(fromItemIndex).id.replace(/^https:\/\//, "") + } + clip: true - model: ModelStore.get("homeservers") + model: ModelStore.get("filtered_homeservers") delegate: ServerDelegate { width: serverList.width loadingIconStep: box.loadingIconStep onClicked: { - serverField.item.field.text = - model.id.replace(/^https:\/\//, "") - + setFieldText(model.index) serverField.item.apply.clicked() } }