createvol: add xmleditor UI

This commit is contained in:
Cole Robinson 2019-05-04 15:42:54 -04:00
parent 68b3cb16e5
commit 0937c1e54b
2 changed files with 45 additions and 21 deletions

View File

@ -27,7 +27,6 @@
<object class="GtkWindow" id="vmm-create-vol"> <object class="GtkWindow" id="vmm-create-vol">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title" translatable="yes">Add a Storage Volume</property> <property name="title" translatable="yes">Add a Storage Volume</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<signal name="delete-event" handler="on_vmm_create_vol_delete_event" swapped="no"/> <signal name="delete-event" handler="on_vmm_create_vol_delete_event" swapped="no"/>
<child> <child>
@ -106,6 +105,8 @@
<property name="spacing">18</property> <property name="spacing">18</property>
<child> <child>
<object class="GtkAlignment" id="details-box-align"> <object class="GtkAlignment" id="details-box-align">
<property name="width_request">400</property>
<property name="height_request">400</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="right_padding">1</property> <property name="right_padding">1</property>
@ -542,7 +543,7 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>

View File

@ -12,8 +12,9 @@ from gi.repository import Gdk
from virtinst import StorageVolume from virtinst import StorageVolume
from . import uiutil from . import uiutil
from .baseclass import vmmGObjectUI
from .asyncjob import vmmAsyncJob from .asyncjob import vmmAsyncJob
from .baseclass import vmmGObjectUI
from .xmleditor import vmmXMLEditor
class vmmCreateVolume(vmmGObjectUI): class vmmCreateVolume(vmmGObjectUI):
@ -29,6 +30,12 @@ class vmmCreateVolume(vmmGObjectUI):
self._name_hint = None self._name_hint = None
self._storage_browser = None self._storage_browser = None
self._xmleditor = vmmXMLEditor(self.builder, self.topwin,
self.widget("details-box-align"),
self.widget("details-box"))
self._xmleditor.connect("xml-requested",
self._xmleditor_xml_requested_cb)
self.builder.connect_signals({ self.builder.connect_signals({
"on_vmm_create_vol_delete_event": self.close, "on_vmm_create_vol_delete_event": self.close,
"on_vol_cancel_clicked": self.close, "on_vol_cancel_clicked": self.close,
@ -74,6 +81,8 @@ class vmmCreateVolume(vmmGObjectUI):
def _cleanup(self): def _cleanup(self):
self.conn = None self.conn = None
self._parent_pool = None self._parent_pool = None
self._xmleditor.cleanup()
self._xmleditor = None
if self._storage_browser: if self._storage_browser:
self._storage_browser.cleanup() self._storage_browser.cleanup()
@ -111,6 +120,8 @@ class vmmCreateVolume(vmmGObjectUI):
format_model.append([fmt, fmt]) format_model.append([fmt, fmt])
def _reset_state(self): def _reset_state(self):
self._xmleditor.reset_state()
vol = self._make_stub_vol() vol = self._make_stub_vol()
hasformat = vol.supports_property("format") hasformat = vol.supports_property("format")
@ -231,20 +242,22 @@ class vmmCreateVolume(vmmGObjectUI):
def _show_err(self, info, details=None): def _show_err(self, info, details=None):
self.err.show_err(info, details, modal=self.topwin.get_modal()) self.err.show_err(info, details, modal=self.topwin.get_modal())
def _val_err(self, info, details):
return self.err.val_err(info, details, modal=self.topwin.get_modal())
################### ###################
# Object building # # Object building #
################### ###################
def _make_stub_vol(self): def _make_stub_vol(self, xml=None):
vol = StorageVolume(self.conn.get_backend()) vol = StorageVolume(self.conn.get_backend(), parsexml=xml)
vol.pool = self._parent_pool.get_backend() vol.pool = self._parent_pool.get_backend()
return vol return vol
def _build_xmlobj(self): def _build_xmlobj_from_xmleditor(self):
xml = self._xmleditor.get_xml()
logging.debug("Using XML from xmleditor:\n%s", xml)
return self._make_stub_vol(xml=xml)
def _build_xmlobj_from_ui(self):
name = self.widget("vol-name").get_text() name = self.widget("vol-name").get_text()
suffix = self.widget("vol-name-suffix").get_text() suffix = self.widget("vol-name-suffix").get_text()
volname = name + suffix volname = name + suffix
@ -257,7 +270,6 @@ class vmmCreateVolume(vmmGObjectUI):
if self._can_only_sparse(): if self._can_only_sparse():
alloc = 0 alloc = 0
try:
vol = self._make_stub_vol() vol = self._make_stub_vol()
vol.name = volname vol.name = volname
vol.capacity = (cap * 1024 * 1024 * 1024) vol.capacity = (cap * 1024 * 1024 * 1024)
@ -266,10 +278,17 @@ class vmmCreateVolume(vmmGObjectUI):
vol.backing_store = backing vol.backing_store = backing
if fmt: if fmt:
vol.format = fmt vol.format = fmt
except ValueError as e:
return self._val_err(_("Volume Parameter Error"), e)
return vol return vol
def _build_xmlobj(self, check_xmleditor):
try:
xmlobj = self._build_xmlobj_from_ui()
if check_xmleditor and self._xmleditor.is_xml_selected():
xmlobj = self._build_xmlobj_from_xmleditor()
return xmlobj
except Exception as e:
self.err.show_err(_("Error building XML: %s") % str(e))
################## ##################
# Object install # # Object install #
@ -291,7 +310,7 @@ class vmmCreateVolume(vmmGObjectUI):
self.close() self.close()
def _finish(self): def _finish(self):
vol = self._build_xmlobj() vol = self._build_xmlobj(check_xmleditor=True)
if not vol: if not vol:
return return
@ -326,6 +345,10 @@ class vmmCreateVolume(vmmGObjectUI):
# UI listeners # # UI listeners #
################ ################
def _xmleditor_xml_requested_cb(self, src):
xmlobj = self._build_xmlobj(check_xmleditor=False)
self._xmleditor.set_xml(xmlobj and xmlobj.get_xml() or "")
def _vol_format_changed_cb(self, src): def _vol_format_changed_cb(self, src):
self._show_alloc() self._show_alloc()
self._show_backing() self._show_backing()