Skip to content

Commit

Permalink
preferences: Add UI for disabling spice usb autoredir
Browse files Browse the repository at this point in the history
We already have a gconf key and command line option for this.
Drop the CLI option and add UI for it, we should have just done
that to begin with
  • Loading branch information
crobinso committed Mar 16, 2018
1 parent 30cc70c commit c9b2ec1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
4 changes: 0 additions & 4 deletions man/virt-manager.pod
Expand Up @@ -84,10 +84,6 @@ on the host.

=back

=item B<--spice-disable-auto-usbredir>

Auto USB redirection is supported by default. This option switches off it.

=back

Standard GTK options like --g-fatal-warnings are also accepted.
Expand Down
25 changes: 25 additions & 0 deletions ui/preferences.ui
Expand Up @@ -719,6 +719,31 @@ Redirection:</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">SPICE _USB Redirection:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">prefs-add-spice-usbredir</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="prefs-console-autoredir">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_prefs_console_autoredir_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
3 changes: 0 additions & 3 deletions virt-manager
Expand Up @@ -236,9 +236,6 @@ def main():
return


if options.usbredir and config.get_auto_redirection():
config.cli_usbredir = False

# Add our icon dir to icon theme
icon_theme = Gtk.IconTheme.get_default()
icon_theme.prepend_search_path(CLIConfig.icon_dir)
Expand Down
9 changes: 3 additions & 6 deletions virtManager/config.py
Expand Up @@ -200,7 +200,6 @@ def __init__(self, CLIConfig, test_first_run):
self.askpass_package = CLIConfig.askpass_package
self.default_graphics_from_config = CLIConfig.default_graphics
self.default_hvs = CLIConfig.default_hvs
self.cli_usbredir = None

if self.test_first_run:
# Populate some package defaults to simplify git testing
Expand Down Expand Up @@ -476,11 +475,9 @@ def get_console_resizeguest(self):
def set_console_resizeguest(self, pref):
self.conf.set("/console/resize-guest", pref)

def get_auto_redirection(self):
if self.cli_usbredir is not None:
return self.cli_usbredir
return self.conf.get("/console/auto-redirect")
def set_auto_redirection(self, state):
def get_auto_usbredir(self):
return bool(self.conf.get("/console/auto-redirect"))
def set_auto_usbredir(self, state):
self.conf.set("/console/auto-redirect", state)

# Show VM details toolbar
Expand Down
21 changes: 21 additions & 0 deletions virtManager/preferences.py
Expand Up @@ -53,6 +53,7 @@ def __init__(self):
self.refresh_console_accels()
self.refresh_console_scaling()
self.refresh_console_resizeguest()
self.refresh_console_autoredir()
self.refresh_new_vm_sound()
self.refresh_graphics_type()
self.refresh_add_spice_usbredir()
Expand Down Expand Up @@ -81,6 +82,7 @@ def __init__(self):
"on_prefs_console_accels_toggled": self.change_console_accels,
"on_prefs_console_scaling_changed": self.change_console_scaling,
"on_prefs_console_resizeguest_changed": self.change_console_resizeguest,
"on_prefs_console_autoredir_changed": self.change_console_autoredir,
"on_prefs_new_vm_sound_toggled": self.change_new_vm_sound,
"on_prefs_graphics_type_changed": self.change_graphics_type,
"on_prefs_add_spice_usbredir_changed": self.change_add_spice_usbredir,
Expand Down Expand Up @@ -142,6 +144,18 @@ def _init_ui(self):
combo.set_model(model)
uiutil.init_combo_text_column(combo, 1)

combo = self.widget("prefs-console-autoredir")
# [gsettings value, string]
model = Gtk.ListStore(bool, str)
vals = {
False: _("Manual redirect only"),
True: _("Auto redirect on USB attach"),
}
for key, val in vals.items():
model.append([key, val])
combo.set_model(model)
uiutil.init_combo_text_column(combo, 1)

combo = self.widget("prefs-graphics-type")
# [gsettings value, string]
model = Gtk.ListStore(str, str)
Expand Down Expand Up @@ -220,6 +234,10 @@ def refresh_console_resizeguest(self):
combo = self.widget("prefs-console-resizeguest")
val = self.config.get_console_resizeguest()
uiutil.set_list_selection(combo, val)
def refresh_console_autoredir(self):
combo = self.widget("prefs-console-autoredir")
val = self.config.get_auto_usbredir()
uiutil.set_list_selection(combo, val)

def refresh_new_vm_sound(self):
self.widget("prefs-new-vm-sound").set_active(
Expand Down Expand Up @@ -375,6 +393,9 @@ def change_console_scaling(self, box):
def change_console_resizeguest(self, box):
val = uiutil.get_list_selection(box)
self.config.set_console_resizeguest(val)
def change_console_autoredir(self, box):
val = uiutil.get_list_selection(box)
self.config.set_auto_usbredir(val)

def change_new_vm_sound(self, src):
self.config.set_new_vm_sound(src.get_active())
Expand Down
2 changes: 1 addition & 1 deletion virtManager/viewers.py
Expand Up @@ -548,7 +548,7 @@ def _create_spice_session(self):
self._usbdev_manager.connect("device-error",
self._usbdev_redirect_error)

autoredir = self.config.get_auto_redirection()
autoredir = self.config.get_auto_usbredir()
if autoredir:
gtk_session.set_property("auto-usbredir", True)
except Exception:
Expand Down

0 comments on commit c9b2ec1

Please sign in to comment.