mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-02 09:47:16 +03:00
opticalhelper: Display same combo label for initial and add/remove cdrom devs.
This commit is contained in:
parent
e20f2b71bf
commit
a5687e0408
@ -32,64 +32,66 @@ class vmmOpticalDriveHelper(gobject.GObject):
|
||||
# Get a connection to the SYSTEM bus
|
||||
self.bus = dbus.SystemBus()
|
||||
# Get a handle to the HAL service
|
||||
hal_object = self.bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
|
||||
self.hal_iface = dbus.Interface(hal_object, 'org.freedesktop.Hal.Manager')
|
||||
hal_object = self.bus.get_object('org.freedesktop.Hal',
|
||||
'/org/freedesktop/Hal/Manager')
|
||||
self.hal_iface = dbus.Interface(hal_object,
|
||||
'org.freedesktop.Hal.Manager')
|
||||
self.populate_opt_media()
|
||||
except Exception, e:
|
||||
logging.error("Unable to connect to HAL to list cdrom volumes: '%s'", e)
|
||||
logging.error("Unable to connect to HAL to list cdrom "
|
||||
"volumes: '%s'", e)
|
||||
self.bus = None
|
||||
self.hal_iface = None
|
||||
raise
|
||||
|
||||
def populate_opt_media(self):
|
||||
# get a list of optical devices with data discs in, for FV installs
|
||||
vollabel = {}
|
||||
volpath = {}
|
||||
volinfo = {}
|
||||
self.model.clear()
|
||||
# Track device add/removes so we can detect newly inserted CD media
|
||||
self.hal_iface.connect_to_signal("DeviceAdded", self._device_added)
|
||||
self.hal_iface.connect_to_signal("DeviceRemoved", self._device_removed)
|
||||
|
||||
# Find info about all current present media
|
||||
for d in self.hal_iface.FindDeviceByCapability("volume"):
|
||||
vol = self.bus.get_object("org.freedesktop.Hal", d)
|
||||
volif = dbus.Interface(vol, "org.freedesktop.Hal.Device")
|
||||
if volif.GetPropertyBoolean("volume.is_disc") and \
|
||||
volif.GetPropertyBoolean("volume.disc.has_data"):
|
||||
devnode = volif.GetProperty("block.device")
|
||||
label = volif.GetProperty("volume.label")
|
||||
if label == None or len(label) == 0:
|
||||
label = devnode
|
||||
vollabel[devnode] = label
|
||||
volpath[devnode] = d
|
||||
for path in self.hal_iface.FindDeviceByCapability("volume"):
|
||||
label, devnode = self._fetch_device_info(path)
|
||||
|
||||
for d in self.hal_iface.FindDeviceByCapability("storage.cdrom"):
|
||||
dev = self.bus.get_object("org.freedesktop.Hal", d)
|
||||
if not devnode:
|
||||
# Not an applicable device
|
||||
continue
|
||||
|
||||
volinfo[devnode] = (label, path)
|
||||
|
||||
for path in self.hal_iface.FindDeviceByCapability("storage.cdrom"):
|
||||
# Make sure we only populate CDROM devs
|
||||
dev = self.bus.get_object("org.freedesktop.Hal", path)
|
||||
devif = dbus.Interface(dev, "org.freedesktop.Hal.Device")
|
||||
devnode = devif.GetProperty("block.device")
|
||||
if vollabel.has_key(devnode):
|
||||
self.model.append([devnode, "%s (%s)" % (vollabel[devnode], devnode), True, volpath[devnode]])
|
||||
|
||||
if volinfo.has_key(devnode):
|
||||
label, path = volinfo[devnode]
|
||||
present = True
|
||||
else:
|
||||
self.model.append([devnode, "%s (%s)" % (_("No media present"), devnode), False, None])
|
||||
label, path = None, None
|
||||
present = False
|
||||
|
||||
self.model.append([devnode, self._display_label(devnode, label),
|
||||
present, path])
|
||||
|
||||
def _device_added(self, path):
|
||||
vol = self.bus.get_object("org.freedesktop.Hal", path)
|
||||
volif = dbus.Interface(vol, "org.freedesktop.Hal.Device")
|
||||
if volif.QueryCapability("volume"):
|
||||
if volif.GetPropertyBoolean("volume.is_disc") and \
|
||||
volif.GetPropertyBoolean("volume.disc.has_data"):
|
||||
devnode = volif.GetProperty("block.device")
|
||||
label = volif.GetProperty("volume.label")
|
||||
if label == None or len(label) == 0:
|
||||
label = devnode
|
||||
label, devnode = self._fetch_device_info(path)
|
||||
|
||||
# Search for the row with matching device node and
|
||||
# fill in info about inserted media
|
||||
for row in self.model:
|
||||
if row[0] == devnode:
|
||||
row[1] = label
|
||||
row[2] = True
|
||||
row[3] = path
|
||||
if not devnode:
|
||||
# Not an applicable device
|
||||
return
|
||||
|
||||
# Search for the row with matching device node and
|
||||
# fill in info about inserted media
|
||||
for row in self.model:
|
||||
if row[0] == devnode:
|
||||
row[1] = self._display_label(devnode, label)
|
||||
row[2] = True
|
||||
row[3] = path
|
||||
|
||||
def _device_removed(self, path):
|
||||
active = self.widget.get_active()
|
||||
@ -99,12 +101,34 @@ class vmmOpticalDriveHelper(gobject.GObject):
|
||||
# selected
|
||||
for row in self.model:
|
||||
if row[3] == path:
|
||||
row[1] = _("No media present")
|
||||
row[1] = self._display_label(row[0], None)
|
||||
row[2] = False
|
||||
row[3] = None
|
||||
if idx == active:
|
||||
self.widget.set_active(-1)
|
||||
idx = idx + 1
|
||||
|
||||
|
||||
def _display_label(self, devnode, label):
|
||||
if not label:
|
||||
label = _("No media present")
|
||||
return "%s (%s)" % (label, devnode)
|
||||
|
||||
def _fetch_device_info(self, path):
|
||||
label = None
|
||||
devnode = None
|
||||
|
||||
vol = self.bus.get_object("org.freedesktop.Hal", path)
|
||||
volif = dbus.Interface(vol, "org.freedesktop.Hal.Device")
|
||||
if volif.QueryCapability("volume"):
|
||||
|
||||
if (volif.GetPropertyBoolean("volume.is_disc") and
|
||||
volif.GetPropertyBoolean("volume.disc.has_data")):
|
||||
|
||||
devnode = volif.GetProperty("block.device")
|
||||
label = volif.GetProperty("volume.label")
|
||||
if label == None or len(label) == 0:
|
||||
label = devnode
|
||||
|
||||
return (label, devnode)
|
||||
|
||||
gobject.type_register(vmmOpticalDriveHelper)
|
||||
|
Loading…
x
Reference in New Issue
Block a user