From 70c7748011c704f16a47647eae7ae0c41b695b16 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Tue, 2 Sep 2008 12:09:39 -0400 Subject: [PATCH] Add support for adding audio devices when creating guests. Preferences are global, not per install. Can be seen via edit->preferences --- src/virt-manager.schemas.in | 25 ++++ src/virtManager/config.py | 11 ++ src/virtManager/create.py | 17 ++- src/virtManager/preferences.py | 14 ++ src/vmm-create.glade | 86 +++++++++++- src/vmm-preferences.glade | 237 +++++++++++++++++++++++++-------- 6 files changed, 331 insertions(+), 59 deletions(-) diff --git a/src/virt-manager.schemas.in b/src/virt-manager.schemas.in index 96b454b93..3fa24236e 100644 --- a/src/virt-manager.schemas.in +++ b/src/virt-manager.schemas.in @@ -169,5 +169,30 @@ + + /schemas/apps/::PACKAGE::/new-vm/local-sound + /apps/::PACKAGE::/new-vm/local-sound + ::PACKAGE:: + bool + 1 + + + Install sound device for local VM + Whether to install a sound device for local VMs or not + + + + + /schemas/apps/::PACKAGE::/new-vm/remote-sound + /apps/::PACKAGE::/new-vm/remote-sound + ::PACKAGE:: + bool + 0 + + + Install sound device for remote VM + Whether to install a sound device for remote VMs or not + + diff --git a/src/virtManager/config.py b/src/virtManager/config.py index e9b56d87e..95edaf1d1 100644 --- a/src/virtManager/config.py +++ b/src/virtManager/config.py @@ -219,6 +219,17 @@ class vmmConfig: def set_console_grab_notify(self, state): self.conf.set_bool(self.conf_dir + "/console/grab-notify", state) + def get_local_sound(self): + return self.conf.get_bool(self.conf_dir + "/new-vm/local-sound") + + def get_remote_sound(self): + return self.conf.get_bool(self.conf_dir + "/new-vm/remote-sound") + + def set_local_sound(self, state): + self.conf.set_bool(self.conf_dir + "/new-vm/local-sound", state) + + def set_remote_sound(self, state): + self.conf.set_bool(self.conf_dir + "/new-vm/remote-sound", state) def get_secret_name(self, vm): return "vm-console-" + vm.get_uuid() diff --git a/src/virtManager/create.py b/src/virtManager/create.py index 7d9d863b4..769e6b2be 100644 --- a/src/virtManager/create.py +++ b/src/virtManager/create.py @@ -476,6 +476,11 @@ class vmmCreate(gobject.GObject): return type.get_model().get_value(type.get_active_iter(), 1) return "N/A" + def get_config_sound(self): + if self.connection.is_remote(): + return self.config.get_remote_sound() + return self.config.get_local_sound() + def page_changed(self, notebook, page, page_number): # would you like some spaghetti with your salad, sir? @@ -553,6 +558,7 @@ class vmmCreate(gobject.GObject): self.window.get_widget("summary-mac-address").set_text(macaddr) else: self.window.get_widget("summary-mac-address").set_text("-") + self.window.get_widget("summary-audio").set_text(str(self.get_config_sound())) self.window.get_widget("create-forward").hide() self.window.get_widget("create-finish").show() @@ -602,6 +608,14 @@ class vmmCreate(gobject.GObject): "".join(traceback.format_exc())) return False + try: + if self.get_config_sound(): + guest.sound_devs.append(virtinst.VirtualAudio(model="es1370")) + except Exception, e: + self.err.show_err(_("Error setting up sound device:") + str(e), + "".join(traceback.format_exc())) + return False + logging.debug("Creating a VM " + guest.name + \ "\n Type: " + guest.type + \ "\n UUID: " + guest.uuid + \ @@ -613,7 +627,8 @@ class vmmCreate(gobject.GObject): "\n # VCPUs: " + str(guest.vcpus) + \ "\n Filesize: " + str(self._disk.size) + \ "\n Disk image: " + str(self.get_config_disk_image()) +\ - "\n Non-sparse file: " + str(self.non_sparse)) + "\n Non-sparse file: " + str(self.non_sparse) + \ + "\n Audio?: " + self.config_get_sound()) #let's go diff --git a/src/virtManager/preferences.py b/src/virtManager/preferences.py index 1bc856cc6..0a6734d24 100644 --- a/src/virtManager/preferences.py +++ b/src/virtManager/preferences.py @@ -41,6 +41,7 @@ class vmmPreferences(gobject.GObject): self.refresh_history_length() self.refresh_console_popup() self.refresh_console_keygrab() + self.refresh_sound_options() self.window.signal_autoconnect({ "on_stats_update_interval_changed": self.change_update_interval, @@ -50,6 +51,8 @@ class vmmPreferences(gobject.GObject): "on_close_clicked": self.close, "on_vmm_preferences_delete_event": self.close, "on_preferences_help_clicked": self.show_help, + "on_local_sound_toggled": self.change_local_sound, + "on_remote_sound_toggled": self.change_remote_sound, }) def close(self,ignore1=None,ignore2=None): @@ -73,6 +76,11 @@ class vmmPreferences(gobject.GObject): def refresh_console_keygrab(self,ignore1=None,ignore2=None,ignore3=None,ignore4=None): self.window.get_widget("console-keygrab").set_active(self.config.get_console_keygrab()) + def refresh_sound_options(self, ignore1=None, ignore2=None, ignore=None, + ignore4=None): + self.window.get_widget("local-sound").set_active(self.config.get_local_sound()) + self.window.get_widget("remote-sound").set_active(self.config.get_remote_sound()) + def change_update_interval(self, src): self.config.set_stats_update_interval(src.get_value_as_int()) @@ -85,6 +93,12 @@ class vmmPreferences(gobject.GObject): def change_console_keygrab(self, box): self.config.set_console_keygrab(box.get_active()) + def change_local_sound(self, src): + self.config.set_local_sound(not self.config.get_local_sound()) + + def change_remote_sound(self, src): + self.config.set_remote_sound(not self.config.get_remote_sound()) + def show_help(self, src): # From the Preferences window, show the help document from the Preferences page self.emit("action-show-help", "virt-manager-preferences-window") diff --git a/src/vmm-create.glade b/src/vmm-create.glade index 6cffe8982..f6a0bc311 100644 --- a/src/vmm-create.glade +++ b/src/vmm-create.glade @@ -4760,7 +4760,7 @@ 6 True - 18 + 20 3 False 3 @@ -5685,6 +5685,90 @@ + + + + True + <b>Sound</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 3 + 18 + 19 + fill + + + + + + + True + Enable Audio: + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 2 + 19 + 20 + fill + + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 2 + 3 + 19 + 20 + fill + + + diff --git a/src/vmm-preferences.glade b/src/vmm-preferences.glade index ab640fc75..d4031b03a 100644 --- a/src/vmm-preferences.glade +++ b/src/vmm-preferences.glade @@ -106,6 +106,32 @@ 3 3 + + + True + True + 1 + 0 + True + GTK_UPDATE_IF_VALID + False + False + 5 1 60 1 5 5 + + Status Interval + + + + + 1 + 2 + 0 + 1 + fill + + + + True @@ -131,7 +157,6 @@ 1 0 1 - fill @@ -159,60 +184,6 @@ 1 1 2 - fill - - - - - - - True - True - 1 - 0 - True - GTK_UPDATE_IF_VALID - False - False - 5 1 60 1 5 5 - - Status Interval - - - - - 1 - 2 - 0 - 1 - fill - - - - - - - True - seconds - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 2 - 3 - 0 - 1 @@ -240,7 +211,33 @@ 3 1 2 - fill + + + + + + + True + seconds + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 2 + 3 + 0 + 1 @@ -329,7 +326,7 @@ True 4 - 2 + 1 False 0 0 @@ -470,6 +467,132 @@ For all domains True + + + + 3 + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + 3 + True + False + 3 + + + + True + Install Audio Device: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + True + Local VM + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + True + False + + + + + + True + True + Remote VM + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + + + + + + + + + True + <b>New VM Preferences</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + True + True + + 0