From 9a5ab50b51499d9b8e982de2d7a827074c481d22 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 21 Sep 2020 21:14:35 -0400 Subject: [PATCH] gfxdetails: Use a single 'changed' signal And absord device building from addhardware. This moves all the knowledge to gfxdetails, which saves sprinkling it around in other places Signed-off-by: Cole Robinson --- tests/uitests/test_details.py | 4 +- ui/gfxdetails.ui | 1 + virtManager/addhardware.py | 18 +--- virtManager/details/details.py | 38 +------- virtManager/device/gfxdetails.py | 155 ++++++++++++++++++------------- virtManager/object/domain.py | 9 +- 6 files changed, 106 insertions(+), 119 deletions(-) diff --git a/tests/uitests/test_details.py b/tests/uitests/test_details.py index 0090697d6..8a912577a 100644 --- a/tests/uitests/test_details.py +++ b/tests/uitests/test_details.py @@ -509,10 +509,10 @@ def testDetailsEditDevices1(app): tab.find("Model:", "text").set_text("ac97") appl.click() lib.utils.check(lambda: not appl.sensitive) - # Test non-disk removal - win.find("config-remove").click() cell = win.find("Sound ac97", "table cell") oldtext = cell.text + # Test non-disk removal + win.find("config-remove").click() app.click_alert_button("Are you sure", "No") lib.utils.check(lambda: cell.state_selected) cell.click(button=3) diff --git a/ui/gfxdetails.ui b/ui/gfxdetails.ui index b55c7202d..def392e0e 100644 --- a/ui/gfxdetails.ui +++ b/ui/gfxdetails.ui @@ -160,6 +160,7 @@ True False + start 6 diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index 8d814eab2..eaf27248b 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -9,7 +9,7 @@ import traceback from gi.repository import Gtk from virtinst import (DeviceChannel, DeviceConsole, - DeviceController, DeviceDisk, DeviceGraphics, DeviceHostdev, + DeviceController, DeviceDisk, DeviceHostdev, DeviceInput, DeviceInterface, DevicePanic, DeviceParallel, DeviceRedirdev, DeviceRng, DeviceSerial, DeviceSmartcard, DeviceSound, DeviceTpm, DeviceVideo, DeviceVsock, DeviceWatchdog) @@ -1481,21 +1481,7 @@ class vmmAddHardware(vmmGObjectUI): return dev def _build_graphics(self): - (gtype, port, listen, - addr, passwd, gl, rendernode) = self._gfxdetails.get_values() - dev = DeviceGraphics(self.conn.get_backend()) - dev.type = gtype - dev.passwd = passwd - dev.gl = gl - dev.rendernode = rendernode - - if not listen or listen == "none": - dev.listen = "none" - else: - dev.listen = addr - dev.port = port - - return dev + return self._gfxdetails.build_device() def _build_sound(self): smodel = uiutil.get_list_selection(self.widget("sound-model")) diff --git a/virtManager/details/details.py b/virtManager/details/details.py index 2de7e810c..43961bc70 100644 --- a/virtManager/details/details.py +++ b/virtManager/details/details.py @@ -65,13 +65,7 @@ from ..delete import vmmDeleteStorage EDIT_NET_MAC, EDIT_NET_LINKSTATE, - EDIT_GFX_PASSWD, - EDIT_GFX_TYPE, - EDIT_GFX_LISTEN, - EDIT_GFX_ADDRESS, - EDIT_GFX_PORT, - EDIT_GFX_OPENGL, - EDIT_GFX_RENDERNODE, + EDIT_GFX, EDIT_VIDEO_MODEL, EDIT_VIDEO_3D, @@ -89,7 +83,7 @@ from ..delete import vmmDeleteStorage EDIT_FS, - EDIT_HOSTDEV_ROMBAR) = range(1, 44) + EDIT_HOSTDEV_ROMBAR) = range(1, 38) # Columns in hw list model @@ -383,13 +377,7 @@ class vmmDetails(vmmGObjectUI): self.gfxdetails = vmmGraphicsDetails( self.vm, self.builder, self.topwin) self.widget("graphics-align").add(self.gfxdetails.top_box) - self.gfxdetails.connect("changed-type", _e(EDIT_GFX_TYPE)) - self.gfxdetails.connect("changed-port", _e(EDIT_GFX_PORT)) - self.gfxdetails.connect("changed-opengl", _e(EDIT_GFX_OPENGL)) - self.gfxdetails.connect("changed-rendernode", _e(EDIT_GFX_RENDERNODE)) - self.gfxdetails.connect("changed-listen", _e(EDIT_GFX_LISTEN)) - self.gfxdetails.connect("changed-address", _e(EDIT_GFX_ADDRESS)) - self.gfxdetails.connect("changed-password", _e(EDIT_GFX_PASSWD)) + self.gfxdetails.connect("changed", _e(EDIT_GFX)) self.netlist = vmmNetworkList(self.conn, self.builder, self.topwin) self.widget("network-source-label-align").add(self.netlist.top_label) @@ -1604,25 +1592,9 @@ class vmmDetails(vmmGObjectUI): devobj=devobj) def _apply_graphics(self, devobj): - (gtype, port, listen, - addr, passwd, gl, rendernode) = self.gfxdetails.get_values() - kwargs = {} - - if self._edited(EDIT_GFX_PASSWD): - kwargs["passwd"] = passwd - if self._edited(EDIT_GFX_LISTEN): - kwargs["listen"] = listen - if self._edited(EDIT_GFX_ADDRESS) or self._edited(EDIT_GFX_LISTEN): - kwargs["addr"] = addr - if self._edited(EDIT_GFX_PORT) or self._edited(EDIT_GFX_LISTEN): - kwargs["port"] = port - if self._edited(EDIT_GFX_OPENGL): - kwargs["gl"] = gl - if self._edited(EDIT_GFX_RENDERNODE): - kwargs["rendernode"] = rendernode - if self._edited(EDIT_GFX_TYPE): - kwargs["gtype"] = gtype + if self._edited(EDIT_GFX): + kwargs = self.gfxdetails.get_values() return vmmAddHardware.change_config_helper(self.vm.define_graphics, kwargs, self.vm, self.err, diff --git a/virtManager/device/gfxdetails.py b/virtManager/device/gfxdetails.py index 9f88eab9a..78967c0e9 100644 --- a/virtManager/device/gfxdetails.py +++ b/virtManager/device/gfxdetails.py @@ -12,16 +12,19 @@ import virtinst from ..lib import uiutil from ..baseclass import vmmGObjectUI +_EDIT_GFX_ENUM = range(1, 6) +( + _EDIT_GFX_TYPE, + _EDIT_GFX_LISTEN, + _EDIT_GFX_PORT, + _EDIT_GFX_OPENGL, + _EDIT_GFX_PASSWD, +) = _EDIT_GFX_ENUM + class vmmGraphicsDetails(vmmGObjectUI): __gsignals__ = { - "changed-password": (vmmGObjectUI.RUN_FIRST, None, []), - "changed-port": (vmmGObjectUI.RUN_FIRST, None, []), - "changed-type": (vmmGObjectUI.RUN_FIRST, None, []), - "changed-listen": (vmmGObjectUI.RUN_FIRST, None, []), - "changed-address": (vmmGObjectUI.RUN_FIRST, None, []), - "changed-opengl": (vmmGObjectUI.RUN_FIRST, None, []), - "changed-rendernode": (vmmGObjectUI.RUN_FIRST, None, []), + "changed": (vmmGObjectUI.RUN_FIRST, None, []), } def __init__(self, vm, builder, topwin): @@ -30,18 +33,24 @@ class vmmGraphicsDetails(vmmGObjectUI): self.vm = vm self.conn = vm.conn - self.builder.connect_signals({ - "on_graphics_type_changed": self._change_graphics_type, - "on_graphics_port_auto_toggled": self._change_port_auto, - "on_graphics_use_password": self._change_password_cb, - "on_graphics_show_password": self._show_password_cb, + self._active_edits = [] - "on_graphics_listen_type_changed": self._change_graphics_listen, - "on_graphics_password_changed": lambda ignore: self.emit("changed-password"), - "on_graphics_address_changed": lambda ignore: self.emit("changed-address"), - "on_graphics_port_changed": lambda ignore: self.emit("changed-port"), - "on_graphics_opengl_toggled": self._change_opengl, - "on_graphics_rendernode_changed": lambda ignore: self.emit("changed-rendernode") + def _e(edittype): + def signal_cb(*args): + self._change_cb(edittype) + return signal_cb + + self.builder.connect_signals({ + "on_graphics_show_password": self._show_password_cb, + "on_graphics_port_auto_toggled": self._change_port_auto, + "on_graphics_opengl_toggled": _e(_EDIT_GFX_OPENGL), + "on_graphics_type_changed": _e(_EDIT_GFX_TYPE), + "on_graphics_use_password": _e(_EDIT_GFX_PASSWD), + "on_graphics_listen_type_changed": _e(_EDIT_GFX_LISTEN), + "on_graphics_password_changed": _e(_EDIT_GFX_PASSWD), + "on_graphics_address_changed": _e(_EDIT_GFX_LISTEN), + "on_graphics_port_changed": _e(_EDIT_GFX_PORT), + "on_graphics_rendernode_changed": _e(_EDIT_GFX_OPENGL), }) self._init_ui() @@ -108,11 +117,6 @@ class vmmGraphicsDetails(vmmGObjectUI): rendernode = drm.get_devnode().path model.append([rendernode, i.pretty_name()]) - def _get_config_graphics_ports(self): - port = uiutil.spin_get_helper(self.widget("graphics-port")) - if self.widget("graphics-port-auto").get_active(): - port = -1 - return port ############## # UI syncing # @@ -197,30 +201,10 @@ class vmmGraphicsDetails(vmmGObjectUI): self.widget("graphics-password-chk").set_active(False) self.widget("graphics-opengl").set_active(False) self._sync_ui() - - def get_values(self): - gtype = uiutil.get_list_selection(self.widget("graphics-type")) - port = self._get_config_graphics_ports() - listen = uiutil.get_list_selection(self.widget("graphics-listen-type")) - addr = uiutil.get_list_selection(self.widget("graphics-address")) - - passwd = self.widget("graphics-password").get_text() - if not self.widget("graphics-password-chk").get_active(): - passwd = None - - glval = self.widget("graphics-opengl").get_active() - if not self.widget("graphics-opengl").is_visible(): - glval = None - - rendernode = uiutil.get_list_selection(self.widget("graphics-rendernode")) - if not self.widget("graphics-rendernode").is_visible(): - rendernode = None - - return gtype, port, listen, addr, passwd, glval, rendernode + self._active_edits = [] def set_dev(self, gfx): self.reset_state() - portval = gfx.port portautolabel = _("A_uto") @@ -244,8 +228,8 @@ class vmmGraphicsDetails(vmmGObjectUI): uiutil.set_list_selection(self.widget("graphics-type"), gtype) use_passwd = gfx.passwd is not None - self.widget("graphics-password").set_text(gfx.passwd or "") self.widget("graphics-password-chk").set_active(use_passwd) + self.widget("graphics-password").set_text(gfx.passwd or "") listentype = gfx.get_first_listen_type() uiutil.set_list_selection( @@ -264,32 +248,79 @@ class vmmGraphicsDetails(vmmGObjectUI): uiutil.set_list_selection( self.widget("graphics-rendernode"), renderval) + # This comes last + self._active_edits = [] + + def get_values(self): + ret = {} + + glval = self.widget("graphics-opengl").get_active() + if not self.widget("graphics-opengl").is_visible(): + glval = None + + rendernode = uiutil.get_list_selection(self.widget("graphics-rendernode")) + if not self.widget("graphics-rendernode").is_visible(): + rendernode = None + + passwd = self.widget("graphics-password").get_text() + if not self.widget("graphics-password-chk").get_active(): + passwd = None + + port = uiutil.spin_get_helper(self.widget("graphics-port")) + if self.widget("graphics-port-auto").get_active(): + port = -1 + + listen = uiutil.get_list_selection(self.widget("graphics-listen-type")) + addr = uiutil.get_list_selection(self.widget("graphics-address")) + if listen and listen != "none": + listen = addr + else: + port = None + + gtype = uiutil.get_list_selection(self.widget("graphics-type")) + + if _EDIT_GFX_TYPE in self._active_edits: + ret["gtype"] = gtype + if _EDIT_GFX_PORT in self._active_edits: + ret["port"] = port + if _EDIT_GFX_LISTEN in self._active_edits: + ret["listen"] = listen + if _EDIT_GFX_PASSWD in self._active_edits: + ret["passwd"] = passwd + if _EDIT_GFX_OPENGL in self._active_edits: + ret["gl"] = glval + ret["rendernode"] = rendernode + + return ret + + def build_device(self): + self._active_edits = _EDIT_GFX_ENUM[:] + values = self.get_values() + dev = virtinst.DeviceGraphics(self.conn.get_backend()) + + dev.type = values["gtype"] + dev.passwd = values["passwd"] + dev.gl = values["gl"] + dev.rendernode = values["rendernode"] + dev.listen = values["listen"] + dev.port = values["port"] + + return dev + ############# # Listeners # ############# - def _change_graphics_type(self, ignore): + def _change_cb(self, edittype): self._sync_ui() - self.emit("changed-type") - - def _change_graphics_listen(self, ignore): - self._sync_ui() - self.emit("changed-listen") - - def _change_opengl(self, ignore): - self._sync_ui() - self.emit("changed-opengl") - self.emit("changed-rendernode") + if edittype not in self._active_edits: + self._active_edits.append(edittype) + self.emit("changed") def _change_port_auto(self, ignore): self.widget("graphics-port-auto").set_inconsistent(False) - self._sync_ui() - self.emit("changed-port") - - def _change_password_cb(self, src): - self._sync_ui() - self.emit("changed-password") + self._change_cb(_EDIT_GFX_PORT) def _show_password_cb(self, src): self._sync_ui() diff --git a/virtManager/object/domain.py b/virtManager/object/domain.py index c0a0f6eae..2f4a4fd0a 100644 --- a/virtManager/object/domain.py +++ b/virtManager/object/domain.py @@ -792,7 +792,7 @@ class vmmDomain(vmmLibvirtObject): self._process_device_define(editdev, xmlobj, do_hotplug) def define_graphics(self, devobj, do_hotplug, - listen=_SENTINEL, addr=_SENTINEL, port=_SENTINEL, + listen=_SENTINEL, port=_SENTINEL, passwd=_SENTINEL, gtype=_SENTINEL, gl=_SENTINEL, rendernode=_SENTINEL): xmlobj = self._make_xmlobj_to_define() @@ -800,11 +800,8 @@ class vmmDomain(vmmLibvirtObject): if not editdev: return # pragma: no cover - if addr != _SENTINEL or listen != _SENTINEL: - if listen == "none": - editdev.listen = listen - else: - editdev.listen = addr + if listen != _SENTINEL: + editdev.listen = listen if port != _SENTINEL: editdev.port = port if passwd != _SENTINEL: