mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Break out helper for prompting user before performing an op
This commit is contained in:
parent
a29c25bcce
commit
28e2677944
@ -1961,18 +1961,11 @@ class vmmDetails(vmmGObjectUI):
|
||||
# Device removal
|
||||
def remove_device(self, dev_type, dev_id_info):
|
||||
logging.debug("Removing device: %s %s" % (dev_type, dev_id_info))
|
||||
do_prompt = self.config.get_confirm_removedev()
|
||||
|
||||
if do_prompt:
|
||||
res = self.err.warn_chkbox(
|
||||
text1=(_("Are you sure you want to remove this device?")),
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
if util.chkbox_helper(self, self.config.get_confirm_removedev,
|
||||
self.config.set_confirm_removedev,
|
||||
text1=(_("Are you sure you want to remove this device?"))):
|
||||
return
|
||||
self.config.set_confirm_removedev(not skip_prompt)
|
||||
|
||||
# Define the change
|
||||
try:
|
||||
|
@ -856,7 +856,6 @@ class vmmEngine(vmmGObject):
|
||||
conn = self._lookup_connection(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
managed = bool(vm.managedsave_supported)
|
||||
do_prompt = self.config.get_confirm_poweroff()
|
||||
|
||||
if not managed and conn.is_remote():
|
||||
src.err.val_err(_("Saving virtual machines over remote "
|
||||
@ -864,17 +863,10 @@ class vmmEngine(vmmGObject):
|
||||
"libvirt version or hypervisor."))
|
||||
return
|
||||
|
||||
if do_prompt:
|
||||
res = src.err.warn_chkbox(
|
||||
text1=_("Are you sure you want to save "
|
||||
"'%s'?" % vm.get_name()),
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
if util.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
self.config.set_confirm_poweroff,
|
||||
text1=_("Are you sure you want to save '%s'?" % vm.get_name())):
|
||||
return
|
||||
self.config.set_confirm_poweroff(not skip_prompt)
|
||||
|
||||
path = None
|
||||
if not managed:
|
||||
@ -964,21 +956,14 @@ class vmmEngine(vmmGObject):
|
||||
def _do_destroy_domain(self, src, uri, uuid):
|
||||
conn = self._lookup_connection(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
do_prompt = self.config.get_confirm_forcepoweroff()
|
||||
|
||||
if do_prompt:
|
||||
res = src.err.warn_chkbox(
|
||||
text1=(_("Are you sure you want to force poweroff '%s'?") %
|
||||
if util.chkbox_helper(src, self.config.get_confirm_forcepoweroff,
|
||||
self.config.set_confirm_forcepoweroff,
|
||||
text1=_("Are you sure you want to force poweroff '%s'?" %
|
||||
vm.get_name()),
|
||||
text2=_("This will immediately poweroff the VM without "
|
||||
"shutting down the OS and may cause data loss."),
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
"shutting down the OS and may cause data loss.")):
|
||||
return
|
||||
self.config.set_confirm_forcepoweroff(not skip_prompt)
|
||||
|
||||
logging.debug("Destroying vm '%s'." % vm.get_name())
|
||||
try:
|
||||
@ -989,19 +974,12 @@ class vmmEngine(vmmGObject):
|
||||
def _do_suspend_domain(self, src, uri, uuid):
|
||||
conn = self._lookup_connection(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
do_prompt = self.config.get_confirm_pause()
|
||||
|
||||
if do_prompt:
|
||||
res = src.err.warn_chkbox(
|
||||
text1=_("Are you sure you want to pause "
|
||||
"'%s'?" % vm.get_name()),
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
if util.chkbox_helper(src, self.config.get_confirm_pause,
|
||||
self.config.set_confirm_pause,
|
||||
text1=_("Are you sure you want to pause '%s'?" %
|
||||
vm.get_name())):
|
||||
return
|
||||
self.config.set_confirm_pause(not skip_prompt)
|
||||
|
||||
logging.debug("Pausing vm '%s'." % vm.get_name())
|
||||
try:
|
||||
@ -1043,19 +1021,12 @@ class vmmEngine(vmmGObject):
|
||||
def _do_shutdown_domain(self, src, uri, uuid):
|
||||
conn = self._lookup_connection(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
do_prompt = self.config.get_confirm_poweroff()
|
||||
|
||||
if do_prompt:
|
||||
res = src.err.warn_chkbox(
|
||||
text1=_("Are you sure you want to poweroff "
|
||||
"'%s'?" % vm.get_name()),
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
if util.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
self.config.set_confirm_poweroff,
|
||||
text1=_("Are you sure you want to poweroff '%s'?" %
|
||||
vm.get_name())):
|
||||
return
|
||||
self.config.set_confirm_poweroff(not skip_prompt)
|
||||
|
||||
logging.debug("Shutting down vm '%s'." % vm.get_name())
|
||||
try:
|
||||
@ -1066,19 +1037,12 @@ class vmmEngine(vmmGObject):
|
||||
def _do_reboot_domain(self, src, uri, uuid):
|
||||
conn = self._lookup_connection(uri)
|
||||
vm = conn.get_vm(uuid)
|
||||
do_prompt = self.config.get_confirm_poweroff()
|
||||
|
||||
if do_prompt:
|
||||
res = src.err.warn_chkbox(
|
||||
text1=_("Are you sure you want to reboot "
|
||||
"'%s'?" % vm.get_name()),
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
if util.chkbox_helper(src, self.config.get_confirm_poweroff,
|
||||
self.config.set_confirm_poweroff,
|
||||
text1=_("Are you sure you want to reboot '%s'?" %
|
||||
vm.get_name())):
|
||||
return
|
||||
self.config.set_confirm_poweroff(not skip_prompt)
|
||||
|
||||
logging.debug("Rebooting vm '%s'." % vm.get_name())
|
||||
no_support = False
|
||||
|
@ -906,19 +906,11 @@ class vmmHost(vmmGObjectUI):
|
||||
if interface is None:
|
||||
return
|
||||
|
||||
do_prompt = self.config.get_confirm_interface()
|
||||
|
||||
if do_prompt:
|
||||
res = self.err.warn_chkbox(
|
||||
if util.chkbox_helper(self, self.config.get_confirm_interface,
|
||||
self.config.set_confirm_interface,
|
||||
text1=_("Are you sure you want to stop the interface "
|
||||
"'%s'?" % interface.get_name()),
|
||||
chktext=_("Don't ask me again for interface start/stop."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
"'%s'?" % interface.get_name())):
|
||||
return
|
||||
self.config.set_confirm_interface(not skip_prompt)
|
||||
|
||||
logging.debug("Stopping interface '%s'" % interface.get_name())
|
||||
try:
|
||||
@ -932,19 +924,11 @@ class vmmHost(vmmGObjectUI):
|
||||
if interface is None:
|
||||
return
|
||||
|
||||
do_prompt = self.config.get_confirm_interface()
|
||||
|
||||
if do_prompt:
|
||||
res = self.err.warn_chkbox(
|
||||
if util.chkbox_helper(self, self.config.get_confirm_interface,
|
||||
self.config.set_confirm_interface,
|
||||
text1=_("Are you sure you want to start the interface "
|
||||
"'%s'?" % interface.get_name()),
|
||||
chktext=_("Don't ask me again for interface start/stop."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
"'%s'?" % interface.get_name())):
|
||||
return
|
||||
self.config.set_confirm_interface(not skip_prompt)
|
||||
|
||||
logging.debug("Starting interface '%s'" % interface.get_name())
|
||||
try:
|
||||
|
@ -416,3 +416,22 @@ def pretty_bytes(val):
|
||||
return "%2.2f MB" % (val / (1024.0 * 1024.0))
|
||||
|
||||
xpath = virtinst.util.get_xml_path
|
||||
|
||||
def chkbox_helper(src, getcb, setcb, text1, text2=None):
|
||||
"""
|
||||
Helper to prompt user about proceeding with an operation
|
||||
Returns True if operation should be cancelled
|
||||
"""
|
||||
do_prompt = getcb()
|
||||
if not do_prompt:
|
||||
return False
|
||||
|
||||
res = src.err.warn_chkbox(text1=text1, text2=text2,
|
||||
chktext=_("Don't ask me again."),
|
||||
buttons=gtk.BUTTONS_YES_NO)
|
||||
response, skip_prompt = res
|
||||
if not response:
|
||||
return True
|
||||
|
||||
setcb(not skip_prompt)
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user