Skip to content

Commit

Permalink
Add missing info to devices widget
Browse files Browse the repository at this point in the history
When integration with new device api happens, this will look better,
but this is just to avoid issues reported in the meanwhile

fixes QubesOS/qubes-issues#9164
  • Loading branch information
marmarta committed May 9, 2024
1 parent a442f92 commit 5252262
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
35 changes: 23 additions & 12 deletions qui/devices/actionable_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Use generate_wrapper_widget to get a wrapped widget.
"""
import pathlib
from typing import Iterable, Callable, List, Optional
from typing import Iterable, Callable, Optional
import qubesadmin
import qubesadmin.devices
import qubesadmin.vm
Expand Down Expand Up @@ -115,12 +115,24 @@ def toggle_icon(self):


class VMWithIcon(Gtk.Box):
def __init__(self, vm: backend.VM, size: int = 18, variant: str = 'dark'):
def __init__(self, vm: backend.VM, size: int = 18, variant: str = 'dark',
name_extension: Optional[str] = None):
"""
Icon with VM name and optional text name extension in parentheses.
:param vm: VM object
:param size: icon size
:param variant: light / dark string
:param name_extension: optional text to be added after vm name
after colon
"""
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)
self.backend_icon = VariantIcon(vm.icon_name, variant, size)

self.backend_label = Gtk.Label(xalign=0)
self.backend_label.set_markup(vm.name)
backend_label: str = vm.name
if name_extension:
backend_label += ": " + name_extension
self.backend_label.set_markup(backend_label)

self.pack_start(self.backend_icon, False, False, 4)
self.pack_start(self.backend_label, False, False, 0)
Expand All @@ -131,15 +143,17 @@ def __init__(self, vm: backend.VM, size: int = 18, variant: str = 'dark'):
class VMAttachmentDiagram(Gtk.Box):
"""
Device attachment scheme, in the following form:
backend_vm [-> frontend_vm[, other_frontend+]]
backend_vm (device name) [-> frontend_vm[, other_frontend+]]
"""
def __init__(self, backend_vm: backend.VM,
frontend_vms: Optional[List[backend.VM]],
def __init__(self, device: backend.Device,
variant: str = 'dark'):
super().__init__(orientation=Gtk.Orientation.HORIZONTAL)

backend_vm = device.backend_domain
frontend_vms = list(device.attachments)
# backend is always there
backend_vm_icon = VMWithIcon(backend_vm)
backend_vm_icon = VMWithIcon(backend_vm,
name_extension=device.id_string)
backend_vm_icon.get_style_context().add_class('main_device_vm')
self.pack_start(backend_vm_icon, False, False, 4)

Expand Down Expand Up @@ -359,8 +373,7 @@ def __init__(self, device: backend.Device, variant: str = 'dark'):
self.device_label.set_xalign(Gtk.Align.CENTER)
self.device_label.set_halign(Gtk.Align.CENTER)

self.diagram = VMAttachmentDiagram(device.backend_domain,
list(device.attachments), variant)
self.diagram = VMAttachmentDiagram(device, variant)
self.diagram.set_halign(Gtk.Align.CENTER)

self.add(self.device_label)
Expand Down Expand Up @@ -399,9 +412,7 @@ def __init__(self, device: backend.Device, variant: str = 'dark'):
self.attach(self.device_icon, 0, 0, 1, 1)
self.attach(self.device_label, 1, 0, 3, 1)

self.vm_diagram = VMAttachmentDiagram(device.backend_domain,
list(device.attachments),
self.variant)
self.vm_diagram = VMAttachmentDiagram(device, self.variant)
self.attach(self.vm_diagram, 1, 1, 3, 1)

def get_child_widgets(self, vms, disp_vm_templates) -> \
Expand Down
5 changes: 5 additions & 0 deletions qui/devices/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import qubesadmin.exc
import qubesadmin.devices
import qubesadmin.vm
from qubesadmin.utils import size_to_human

import gi
gi.require_version('Gtk', '3.0') # isort:skip
Expand Down Expand Up @@ -99,7 +100,11 @@ def __init__(self, dev: qubesadmin.devices.DeviceInfo,
self._dev: qubesadmin.devices.DeviceInfo = dev
self.__hash = hash(dev)
self._port: str = ''

self._dev_name: str = getattr(dev, 'description', 'unknown')
if dev.devclass == 'block' and 'size' in dev.data:
self._dev_name += " (" + size_to_human(int(dev.data['size'])) + ")"

self._ident: str = getattr(dev, 'ident', 'unknown')
self._description: str = getattr(dev, 'description', 'unknown')
self._devclass: str = getattr(dev, 'devclass', 'unknown')
Expand Down

0 comments on commit 5252262

Please sign in to comment.