Skip to content

Commit d56bb9e

Browse files
committed
Merge remote-tracking branch 'origin/pr/291'
* origin/pr/291: Hide internal qubes from list modeler by default
2 parents 6a1bb69 + 4c5b368 commit d56bb9e

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

qubes_config/global_config/basics_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def __init__(
135135
vm_filter: Optional[Callable] = None,
136136
readable_name: Optional[str] = None,
137137
additional_options: Dict[Any | str | None, str] | None = None,
138+
show_internal: bool = False,
138139
):
139140
self.qapp = qapp
140141
self.trait_holder = trait_holder
@@ -149,6 +150,7 @@ def __init__(
149150
current_value=self.get_current_value(),
150151
style_changes=True,
151152
additional_options=additional_options,
153+
show_internal=show_internal,
152154
)
153155

154156
def get_readable_description(self) -> str:

qubes_config/tests/test_gtk_widgets.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,33 @@ def test_vmmodeler_default_current(test_qapp):
351351

352352
def test_vmmodeler_filter(test_qapp):
353353
combobox: Gtk.ComboBox = Gtk.ComboBox.new_with_entry()
354-
vms = ["test-vm", "test-blue", "test-red"]
354+
internal_vm = ["disp-mgmt"]
355+
normal_vms = ["test-vm", "test-blue", "test-red"]
356+
vms = internal_vm + normal_vms
355357
_ = gtk_widgets.VMListModeler(
356358
combobox=combobox,
357359
qapp=test_qapp,
358360
filter_function=lambda vm: str(vm) in vms,
359361
)
360362

363+
selected_vms = []
364+
model = combobox.get_model()
365+
for item in model:
366+
selected_vms.append(item[1])
367+
368+
assert sorted(selected_vms) == sorted(normal_vms)
369+
370+
371+
def test_vmmodeler_filter_include_internal(test_qapp):
372+
combobox: Gtk.ComboBox = Gtk.ComboBox.new_with_entry()
373+
vms = ["disp-mgmt", "test-vm", "test-blue", "test-red"]
374+
_ = gtk_widgets.VMListModeler(
375+
combobox=combobox,
376+
qapp=test_qapp,
377+
filter_function=lambda vm: str(vm) in vms,
378+
show_internal=True,
379+
)
380+
361381
selected_vms = []
362382
model = combobox.get_model()
363383
for item in model:

qubes_config/widgets/gtk_widgets.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import gettext
3737

38+
from ..widgets.utils import get_boolean_feature
39+
3840
t = gettext.translation("desktop-linux-manager", fallback=True)
3941
_ = t.gettext
4042

@@ -234,6 +236,7 @@ def __init__(
234236
current_value: qubesadmin.vm.QubesVM | str | None = None,
235237
style_changes: bool = False,
236238
additional_options: dict[qubesadmin.vm.QubesVM | str | None, str] | None = None,
239+
show_internal: bool = False,
237240
):
238241
"""
239242
:param combobox: target ComboBox object
@@ -254,12 +257,14 @@ def __init__(
254257
applied when combobox value changes
255258
:param additional_options: Dictionary of token: readable name of
256259
additonal options to be added to the combobox
260+
:param show_internal: if True, show qubes with internal feature enabled
257261
"""
258262
self.qapp = qapp
259263
self.combo = combobox
260264
self.entry_box = self.combo.get_child()
261265
self.change_function = event_callback
262266
self.style_changes = style_changes
267+
self.show_internal = show_internal
263268

264269
self._entries: dict[str, dict[str, Any]] = {}
265270

@@ -337,9 +342,23 @@ def _create_entries(
337342
"vm": None,
338343
}
339344

345+
found_current = False
346+
if current_value and current_value in self.qapp.domains:
347+
found_current = True
348+
domain = self.qapp.domains[current_value]
349+
icon = self._get_icon(domain.icon)
350+
vm_name = domain.name
351+
self._entries[vm_name] = {
352+
"api_name": vm_name,
353+
"icon": icon,
354+
"vm": domain,
355+
}
356+
340357
for domain in self.qapp.domains:
341358
if filter_function and not filter_function(domain):
342359
continue
360+
if not self.show_internal and get_boolean_feature(domain, "internal"):
361+
continue
343362
vm_name = domain.name
344363
icon = self._get_icon(domain.icon)
345364
display_name = vm_name
@@ -353,8 +372,7 @@ def _create_entries(
353372
"vm": domain,
354373
}
355374

356-
if current_value:
357-
found_current = False
375+
if current_value and not found_current:
358376
for value in self._entries.values():
359377
if value["api_name"] == current_value:
360378
found_current = True

0 commit comments

Comments
 (0)