Github Issue #8583 - Support substring matching in qube name text fields
on Oct 9, 2023 johnnyboy-3 writes:
When using qvm-move/qvm-copy I prefer to use the keyboard instead of the mouse.
When using disposable VMs you have to deal with numbers.
Moving a file from one machine to another it would be nice that you can type in the number directly, instead of having to type “disp” first.
When typing “disp”:
When typing only the “disp-number”:
Typing the disp-number should automatically pre-select the proper disp-VM (or any other proper match).
In this case “disp3110” instead of none.
Diagnosis and Analysis
User if of course correct. A simple search shows that the logic for the above matching behaviour is decided within qrexec.tools.qrexec_policy_agent.apply_model function. String matching is NOT case sensitive and only matches the beginning of the VM Display Names with the user input. We could tweak that by defining our own Gtk.EntryCompletionMatchFunc function and change the behaviour as we desire.
Solution 1 - Relax & comfortable
Non-case-senstive matching. Anywhere of VM Display Name (what user wants)
Solution 2 - Restrictive. No room for mistakes
Replicating the current behaviour. Adding a match case of numbers for DispVMs. User should type 3, 31, 311 & 3110 to match with disp3110. Other cases such as 11 are ignored.
Here is the patch for solution 2
diff --git a/qrexec/tools/qrexec_policy_agent.py b/qrexec/tools/qrexec_policy_agent.py
index fb92a42..51d660b 100644
--- a/qrexec/tools/qrexec_policy_agent.py
+++ b/qrexec/tools/qrexec_policy_agent.py
@@ -184,11 +184,29 @@ class VMListModeler:
completion.set_inline_selection(True)
completion.set_inline_completion(True)
completion.set_popup_completion(True)
- completion.set_popup_single_match(False)
+ completion.set_popup_single_match(True)
completion.set_model(list_store)
completion.set_text_column(1)
entry_box.set_completion(completion)
+
+ def qube_matching_function(completion: Gtk.EntryCompletion,
+ key: str,
+ iter: Gtk.TreeIter,
+ user_data: object) -> bool:
+ modelstr = completion.get_model()[iter][1]
+ # Replicating the default algoritm which is not case-sensitive
+ if modelstr.lower().startswith(key.lower()):
+ return True
+ # Most restrictive scenario. Only matching DispVMs
+ elif modelstr.startswith('disp') and key.isnumeric() and \
+ modelstr.startswith(key, 4):
+ return True
+ else:
+ return False
+
+ completion.set_match_func(qube_matching_function, None)
+
if activation_trigger:
entry_box.connect(
"activate",
Collecting feedback
So what do you think. Should this be relax and comfortable approach? Or a restrictive approach with no room for mistakes?

