Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qubes_config/global_config/basics_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __init__(
vm_filter: Optional[Callable] = None,
readable_name: Optional[str] = None,
additional_options: Dict[Any | str | None, str] | None = None,
show_internal: bool = False,
):
self.qapp = qapp
self.trait_holder = trait_holder
Expand All @@ -149,6 +150,7 @@ def __init__(
current_value=self.get_current_value(),
style_changes=True,
additional_options=additional_options,
show_internal=show_internal,
)

def get_readable_description(self) -> str:
Expand Down
22 changes: 21 additions & 1 deletion qubes_config/tests/test_gtk_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,33 @@ def test_vmmodeler_default_current(test_qapp):

def test_vmmodeler_filter(test_qapp):
combobox: Gtk.ComboBox = Gtk.ComboBox.new_with_entry()
vms = ["test-vm", "test-blue", "test-red"]
internal_vm = ["disp-mgmt"]
normal_vms = ["test-vm", "test-blue", "test-red"]
vms = internal_vm + normal_vms
_ = gtk_widgets.VMListModeler(
combobox=combobox,
qapp=test_qapp,
filter_function=lambda vm: str(vm) in vms,
)

selected_vms = []
model = combobox.get_model()
for item in model:
selected_vms.append(item[1])

assert sorted(selected_vms) == sorted(normal_vms)


def test_vmmodeler_filter_include_internal(test_qapp):
combobox: Gtk.ComboBox = Gtk.ComboBox.new_with_entry()
vms = ["disp-mgmt", "test-vm", "test-blue", "test-red"]
_ = gtk_widgets.VMListModeler(
combobox=combobox,
qapp=test_qapp,
filter_function=lambda vm: str(vm) in vms,
show_internal=True,
)

selected_vms = []
model = combobox.get_model()
for item in model:
Expand Down
22 changes: 20 additions & 2 deletions qubes_config/widgets/gtk_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import gettext

from ..widgets.utils import get_boolean_feature

t = gettext.translation("desktop-linux-manager", fallback=True)
_ = t.gettext

Expand Down Expand Up @@ -234,6 +236,7 @@ def __init__(
current_value: qubesadmin.vm.QubesVM | str | None = None,
style_changes: bool = False,
additional_options: dict[qubesadmin.vm.QubesVM | str | None, str] | None = None,
show_internal: bool = False,
):
"""
:param combobox: target ComboBox object
Expand All @@ -254,12 +257,14 @@ def __init__(
applied when combobox value changes
:param additional_options: Dictionary of token: readable name of
additonal options to be added to the combobox
:param show_internal: if True, show qubes with internal feature enabled
"""
self.qapp = qapp
self.combo = combobox
self.entry_box = self.combo.get_child()
self.change_function = event_callback
self.style_changes = style_changes
self.show_internal = show_internal

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

Expand Down Expand Up @@ -337,9 +342,23 @@ def _create_entries(
"vm": None,
}

found_current = False
if current_value and current_value in self.qapp.domains:
found_current = True
domain = self.qapp.domains[current_value]
icon = self._get_icon(domain.icon)
vm_name = domain.name
self._entries[vm_name] = {
"api_name": vm_name,
"icon": icon,
"vm": domain,
}

for domain in self.qapp.domains:
if filter_function and not filter_function(domain):
continue
if not self.show_internal and get_boolean_feature(domain, "internal"):
continue
vm_name = domain.name
icon = self._get_icon(domain.icon)
display_name = vm_name
Expand All @@ -353,8 +372,7 @@ def _create_entries(
"vm": domain,
}

if current_value:
found_current = False
if current_value and not found_current:
for value in self._entries.values():
if value["api_name"] == current_value:
found_current = True
Expand Down