Skip to content

Commit

Permalink
Add vm.icon property
Browse files Browse the repository at this point in the history
This is a property for handling vm icons that change depending on
vm type.
Depends on QubesOS/qubes-artwork#17

references QubesOS/qubes-issues#5767
  • Loading branch information
marmarta committed May 5, 2020
1 parent 8f0ec59 commit 9d1eb1b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
5 changes: 4 additions & 1 deletion qubes/tests/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ def init_volume(self, *args, **kwargs):
return TestVolume(self)

class TestApp(qubes.tests.TestEmitter):
labels = {1: qubes.Label(1, '0xcc0000', 'red')}
labels = {1: qubes.Label(1, '0xcc0000', 'red'),
2: qubes.Label(2, '0x00cc00', 'green'),
3: qubes.Label(3, '0x0000cc', 'blue'),
4: qubes.Label(4, '0xcccccc', 'black')}
check_updates_vm = False

def get_label(self, label):
Expand Down
37 changes: 31 additions & 6 deletions qubes/tests/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
import qubes.tests.vm

class TestApp(object):
labels = {1: qubes.Label(1, '0xcc0000', 'red')}
labels = {1: qubes.Label(1, '0xcc0000', 'red'),
2: qubes.Label(2, '0x00cc00', 'green'),
3: qubes.Label(3, '0x0000cc', 'blue'),
4: qubes.Label(4, '0xcccccc', 'black')}

def __init__(self):
self.domains = {}
Expand Down Expand Up @@ -394,24 +397,46 @@ def test_120_uuid(self):
with self.assertRaises(AttributeError):
vm.uuid = uuid.uuid4()

@unittest.skip('TODO: how to not fail on making an icon symlink here?')
def test_130_label(self):
@unittest.mock.patch("os.symlink")
def test_130_label(self, _):
vm = self.get_vm()
self.assertPropertyDefaultValue(vm, 'label')
self.assertPropertyValue(vm, 'label', self.app.labels[1],
self.app.labels[1], 'label-1')
self.app.labels[1], 'red')
del vm.label
self.assertPropertyDefaultValue(vm, 'label')
self.assertPropertyValue(vm, 'label', 'red',
self.app.labels[1], 'label-1')
self.app.labels[1], 'red')
self.assertPropertyValue(vm, 'label', 'label-1',
self.app.labels[1], 'label-1')
self.app.labels[1], 'red')

def test_131_label_invalid(self):
vm = self.get_vm()
self.assertPropertyInvalidValue(vm, 'label', 'invalid')
self.assertPropertyInvalidValue(vm, 'label', 123)

@unittest.mock.patch("os.symlink")
def test_135_icon(self, _):
vm = self.get_vm(cls=qubes.vm.appvm.AppVM)
vm.label = "red"
self.assertEqual(vm.icon, "appvm-red")

templatevm = self.get_vm(cls=qubes.vm.templatevm.TemplateVM)
templatevm.label = "blue"
self.assertEqual(templatevm.icon, "templatevm-blue")

vm.template_for_dispvms = True
dispvm = self.get_vm(cls=qubes.vm.dispvm.DispVM, template=vm,
dispid=10)
dispvm.label = "black"
self.assertEqual(dispvm.icon, "dispvm-black")

vm = self.get_vm()
vm.label = "green"
vm.features["servicevm"] = 1
self.assertEqual(vm.icon, "servicevm-green")


def test_160_memory(self):
vm = self.get_vm()
self.assertPropertyDefaultValue(vm, 'memory', 400)
Expand Down
13 changes: 13 additions & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,19 @@ def start_time(self):

return None

@qubes.stateless_property
def icon(self):
"""freedesktop icon name, suitable for use in
:py:meth:`PyQt4.QtGui.QIcon.fromTheme`"""
raw_icon_name = self.label.name
if self.klass == 'TemplateVM':
return 'templatevm-' + raw_icon_name
if self.klass == 'DispVM':
return 'dispvm-' + raw_icon_name
if self.features.get('servicevm', False):
return 'servicevm-' + raw_icon_name
return 'appvm-' + raw_icon_name

@property
def kernelopts_common(self):
"""Kernel options which should be used in addition to *kernelopts*
Expand Down

0 comments on commit 9d1eb1b

Please sign in to comment.