mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
mediadev: Associate media-added/removed signals
Rather than have these come from halhelper, push them to users via mediadev, since this will be useful for non-hal backeneds (libvirt)
This commit is contained in:
parent
8ab60836a0
commit
30dbbcda56
@ -36,7 +36,7 @@ class vmmHalHelper(gobject.GObject):
|
|||||||
"optical-added" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
"optical-added" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
[object]),
|
[object]),
|
||||||
"optical-media-added" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
"optical-media-added" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
[object]),
|
[str, str, str]),
|
||||||
"device-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
"device-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
[str]),
|
[str]),
|
||||||
}
|
}
|
||||||
@ -129,13 +129,9 @@ class vmmHalHelper(gobject.GObject):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
devnode, media_label, media_hal_path = self._fetch_cdrom_info(path)
|
devnode, media_label, media_hal_path = self._fetch_cdrom_info(path)
|
||||||
obj = vmmMediaDevice(str(devnode), str(path), media_label,
|
self.add_optical_dev(str(devnode), str(path), media_label,
|
||||||
media_hal_path)
|
media_hal_path)
|
||||||
|
|
||||||
optical_info[str(devnode)] = obj
|
|
||||||
|
|
||||||
for obj in optical_info.values():
|
|
||||||
self.emit("optical-added", obj)
|
|
||||||
|
|
||||||
def populate_netdevs(self):
|
def populate_netdevs(self):
|
||||||
bondMasters = get_bonding_masters()
|
bondMasters = get_bonding_masters()
|
||||||
@ -169,19 +165,19 @@ class vmmHalHelper(gobject.GObject):
|
|||||||
def _device_removed(self, path):
|
def _device_removed(self, path):
|
||||||
self.emit("device-removed", str(path))
|
self.emit("device-removed", str(path))
|
||||||
|
|
||||||
|
def add_optical_dev(self, devpath, halpath, media_label, media_hal_path):
|
||||||
|
obj = vmmMediaDevice(devpath, halpath, media_label, media_hal_path)
|
||||||
|
obj.set_hal_media_signals(self)
|
||||||
|
self.emit("optical-added", obj)
|
||||||
|
|
||||||
def _optical_added(self, halpath):
|
def _optical_added(self, halpath):
|
||||||
devpath, media_label, media_hal_path = self._fetch_cdrom_info(halpath)
|
devpath, media_label, media_hal_path = self._fetch_cdrom_info(halpath)
|
||||||
|
self.add_optical_dev(devpath, halpath, media_label, media_hal_path)
|
||||||
|
|
||||||
obj = vmmMediaDevice(devpath, halpath, media_label, media_hal_path)
|
def _optical_media_added(self, media_hal_path):
|
||||||
self.emit("optical-added", obj)
|
media_label, devpath = self._fetch_media_info(media_hal_path)
|
||||||
|
|
||||||
def _optical_media_added(self, halpath):
|
self.emit("optical-media-added", devpath, media_label, media_hal_path)
|
||||||
media_hal_path = halpath
|
|
||||||
media_label, devpath = self._fetch_media_info(halpath)
|
|
||||||
|
|
||||||
obj = vmmMediaDevice(devpath, halpath, media_label, media_hal_path)
|
|
||||||
self.emit("optical-media-added", obj)
|
|
||||||
|
|
||||||
def _net_phys_device_added(self, halpath):
|
def _net_phys_device_added(self, halpath):
|
||||||
dbusobj = self.dbus_dev_lookup(halpath)
|
dbusobj = self.dbus_dev_lookup(halpath)
|
||||||
|
@ -21,7 +21,17 @@
|
|||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
class vmmMediaDevice(gobject.GObject):
|
class vmmMediaDevice(gobject.GObject):
|
||||||
__gsignals__ = {}
|
__gsignals__ = {
|
||||||
|
"media-added" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
|
[]),
|
||||||
|
"media-removed" : (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
gobject.TYPE_NONE, []),
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__gobject_init__()
|
||||||
|
|
||||||
|
self.bus = None
|
||||||
|
|
||||||
def __init__(self, path, key, media_label, media_key):
|
def __init__(self, path, key, media_label, media_key):
|
||||||
self.__gobject_init__()
|
self.__gobject_init__()
|
||||||
@ -49,8 +59,7 @@ class vmmMediaDevice(gobject.GObject):
|
|||||||
self.media_label = media_label
|
self.media_label = media_label
|
||||||
self.media_key = media_key
|
self.media_key = media_key
|
||||||
def clear_media(self):
|
def clear_media(self):
|
||||||
self.media_label = None
|
self.set_media(None, None)
|
||||||
self.media_key = None
|
|
||||||
|
|
||||||
def pretty_label(self):
|
def pretty_label(self):
|
||||||
media_label = self.get_media_label()
|
media_label = self.get_media_label()
|
||||||
@ -58,4 +67,28 @@ class vmmMediaDevice(gobject.GObject):
|
|||||||
media_label = _("No media present")
|
media_label = _("No media present")
|
||||||
return "%s (%s)" % (media_label, self.get_path())
|
return "%s (%s)" % (media_label, self.get_path())
|
||||||
|
|
||||||
|
|
||||||
|
############################
|
||||||
|
# HAL media signal helpers #
|
||||||
|
############################
|
||||||
|
|
||||||
|
def set_hal_media_signals(self, halhelper):
|
||||||
|
halhelper.connect("optical-media-added", self.hal_media_added)
|
||||||
|
halhelper.connect("device-removed", self.hal_media_removed)
|
||||||
|
|
||||||
|
def hal_media_added(self, ignore, devpath, media_label, media_key):
|
||||||
|
if devpath != self.get_path():
|
||||||
|
return
|
||||||
|
|
||||||
|
self.set_media(media_label, media_key)
|
||||||
|
self.emit("media-added")
|
||||||
|
|
||||||
|
def hal_media_removed(self, ignore, media_hal_path):
|
||||||
|
if media_hal_path != self.get_media_key():
|
||||||
|
return
|
||||||
|
|
||||||
|
self.clear_media()
|
||||||
|
self.emit("media-removed")
|
||||||
|
|
||||||
|
|
||||||
gobject.type_register(vmmMediaDevice)
|
gobject.type_register(vmmMediaDevice)
|
||||||
|
@ -266,7 +266,6 @@ def init_optical_combo(widget, empty_sensitive=False):
|
|||||||
|
|
||||||
helper = vmmHalHelper()
|
helper = vmmHalHelper()
|
||||||
helper.connect("optical-added", optical_added, widget)
|
helper.connect("optical-added", optical_added, widget)
|
||||||
helper.connect("optical-media-added", optical_media_added, widget)
|
|
||||||
helper.connect("device-removed", optical_removed, widget)
|
helper.connect("device-removed", optical_removed, widget)
|
||||||
|
|
||||||
widget.set_active(-1)
|
widget.set_active(-1)
|
||||||
@ -285,17 +284,8 @@ def optical_removed(ignore_helper, key, widget):
|
|||||||
active = widget.get_active()
|
active = widget.get_active()
|
||||||
idx = 0
|
idx = 0
|
||||||
|
|
||||||
# Search for the row containing matching media key and update
|
|
||||||
# (clear) it, de-activating it if its currently selected
|
|
||||||
for row in model:
|
for row in model:
|
||||||
if row[OPTICAL_MEDIA_KEY] == key:
|
if row[OPTICAL_DEV_KEY] == key:
|
||||||
row[OPTICAL_MEDIADEV].clear_media()
|
|
||||||
set_row_from_object(row)
|
|
||||||
|
|
||||||
if idx == active:
|
|
||||||
widget.set_active(-1)
|
|
||||||
|
|
||||||
elif row[OPTICAL_DEV_KEY] == key:
|
|
||||||
# Whole device removed
|
# Whole device removed
|
||||||
del(model[idx])
|
del(model[idx])
|
||||||
widget.set_active(-1)
|
widget.set_active(-1)
|
||||||
@ -307,12 +297,15 @@ def optical_removed(ignore_helper, key, widget):
|
|||||||
def optical_added(ignore_helper, newobj, widget):
|
def optical_added(ignore_helper, newobj, widget):
|
||||||
model = widget.get_model()
|
model = widget.get_model()
|
||||||
|
|
||||||
|
newobj.connect("media-added", optical_media_changed, widget)
|
||||||
|
newobj.connect("media-removed", optical_media_changed, widget)
|
||||||
|
|
||||||
# Brand new device
|
# Brand new device
|
||||||
row = [None, None, None, None, None, newobj]
|
row = [None, None, None, None, None, newobj]
|
||||||
set_row_from_object(row)
|
set_row_from_object(row)
|
||||||
model.append(row)
|
model.append(row)
|
||||||
|
|
||||||
def optical_media_added(ignore_helper, newobj, widget):
|
def optical_media_changed(newobj, widget):
|
||||||
model = widget.get_model()
|
model = widget.get_model()
|
||||||
active = widget.get_active()
|
active = widget.get_active()
|
||||||
idx = 0
|
idx = 0
|
||||||
@ -322,11 +315,13 @@ def optical_media_added(ignore_helper, newobj, widget):
|
|||||||
# selection, select the new media.
|
# selection, select the new media.
|
||||||
for row in model:
|
for row in model:
|
||||||
if row[OPTICAL_DEV_PATH] == newobj.get_path():
|
if row[OPTICAL_DEV_PATH] == newobj.get_path():
|
||||||
row[OPTICAL_MEDIADEV] = newobj
|
|
||||||
set_row_from_object(row)
|
set_row_from_object(row)
|
||||||
|
has_media = row[OPTICAL_IS_MEDIA_PRESENT]
|
||||||
|
|
||||||
if active == -1:
|
if has_media and active == -1:
|
||||||
widget.set_active(idx)
|
widget.set_active(idx)
|
||||||
|
elif not has_media and active == idx:
|
||||||
|
widget.set_active(-1)
|
||||||
|
|
||||||
idx = idx + 1
|
idx = idx + 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user