2015-04-04 03:54:38 +03:00
# Copyright (C) 2006-2008, 2015 Red Hat, Inc.
2009-10-30 20:25:27 +03:00
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
2015-03-23 22:56:55 +03:00
# Copyright (C) 2010 Marc-Andre Lureau <marcandre.lureau@redhat.com>
2009-10-30 20:25:27 +03:00
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2009-10-30 20:25:27 +03:00
2012-05-14 17:24:56 +04:00
from gi . repository import Gtk
from gi . repository import Gdk
2010-02-11 17:32:05 +03:00
2019-06-17 04:12:39 +03:00
from virtinst import log
2014-09-21 21:36:28 +04:00
from . serialcon import vmmSerialConsole
2015-04-04 03:54:38 +03:00
from . sshtunnels import ConnectionInfo
2015-08-13 23:00:33 +03:00
from . viewers import SpiceViewer , VNCViewer , have_spice_gtk
2019-06-17 04:56:34 +03:00
from . . baseclass import vmmGObject , vmmGObjectUI
2020-08-26 16:03:09 +03:00
from . . lib . keyring import vmmKeyring
2019-06-17 04:56:34 +03:00
from . . vmwindow import DETAILS_PAGE_CONSOLE
2015-04-04 03:54:38 +03:00
2009-10-30 20:25:27 +03:00
2015-09-18 18:55:15 +03:00
# console-pages IDs
( _CONSOLE_PAGE_UNAVAILABLE ,
_CONSOLE_PAGE_AUTHENTICATE ,
_CONSOLE_PAGE_SERIAL ,
_CONSOLE_PAGE_VIEWER ) = range ( 4 )
2016-05-17 19:14:32 +03:00
class _TimedRevealer ( vmmGObject ) :
"""
Revealer for the fullscreen toolbar , with a bit of extra logic to
hide / show based on mouse over
"""
def __init__ ( self , toolbar ) :
vmmGObject . __init__ ( self )
self . _in_fullscreen = False
self . _timeout_id = None
self . _revealer = Gtk . Revealer ( )
self . _revealer . add ( toolbar )
# Adding the revealer to the eventbox seems to ensure the
# eventbox always has 1 invisible pixel showing at the top of the
# screen, which we can use to grab the pointer event to show
# the hidden toolbar.
self . _ebox = Gtk . EventBox ( )
self . _ebox . add ( self . _revealer )
self . _ebox . set_halign ( Gtk . Align . CENTER )
self . _ebox . set_valign ( Gtk . Align . START )
self . _ebox . show_all ( )
self . _ebox . connect ( " enter-notify-event " , self . _enter_notify )
self . _ebox . connect ( " leave-notify-event " , self . _enter_notify )
def _cleanup ( self ) :
self . _ebox . destroy ( )
self . _ebox = None
self . _revealer . destroy ( )
self . _revealer = None
self . _timeout_id = None
def _enter_notify ( self , ignore1 , ignore2 ) :
x , y = self . _ebox . get_pointer ( )
alloc = self . _ebox . get_allocation ( )
entered = bool ( x > = 0 and y > = 0 and
x < alloc . width and y < alloc . height )
if not self . _in_fullscreen :
return
# Pointer exited the toolbar, and toolbar is revealed. Schedule
# a timeout to close it, if one isn't already scheduled
if not entered and self . _revealer . get_reveal_child ( ) :
self . _schedule_unreveal_timeout ( 1000 )
return
self . _unregister_timeout ( )
if entered and not self . _revealer . get_reveal_child ( ) :
self . _revealer . set_reveal_child ( True )
def _schedule_unreveal_timeout ( self , timeout ) :
if self . _timeout_id :
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2016-05-17 19:14:32 +03:00
def cb ( ) :
self . _revealer . set_reveal_child ( False )
self . _timeout_id = None
self . _timeout_id = self . timeout_add ( timeout , cb )
def _unregister_timeout ( self ) :
if self . _timeout_id :
self . remove_gobject_timeout ( self . _timeout_id )
self . _timeout_id = None
def force_reveal ( self , val ) :
self . _unregister_timeout ( )
self . _in_fullscreen = val
self . _revealer . set_reveal_child ( val )
self . _schedule_unreveal_timeout ( 2000 )
def get_overlay_widget ( self ) :
return self . _ebox
2019-01-02 03:28:04 +03:00
def build_keycombo_menu ( on_send_key_fn ) :
menu = Gtk . Menu ( )
2020-07-14 10:41:55 +03:00
def make_item ( accel , combo ) :
name = Gtk . accelerator_get_label ( * Gtk . accelerator_parse ( accel ) )
item = Gtk . MenuItem ( name )
2019-01-02 03:28:04 +03:00
item . connect ( " activate " , on_send_key_fn , combo )
menu . add ( item )
2020-07-14 10:41:55 +03:00
make_item ( " <Control><Alt>BackSpace " , [ " Control_L " , " Alt_L " , " BackSpace " ] )
make_item ( " <Control><Alt>Delete " , [ " Control_L " , " Alt_L " , " Delete " ] )
2019-01-02 03:28:04 +03:00
menu . add ( Gtk . SeparatorMenuItem ( ) )
for i in range ( 1 , 13 ) :
2020-07-14 10:41:55 +03:00
make_item ( " <Control><Alt>F %d " % i , [ " Control_L " , " Alt_L " , " F %d " % i ] )
2019-01-02 03:28:04 +03:00
menu . add ( Gtk . SeparatorMenuItem ( ) )
2020-07-14 10:41:55 +03:00
make_item ( " Print " , [ " Print " ] )
2019-01-02 03:28:04 +03:00
menu . show_all ( )
return menu
class vmmOverlayToolbar :
2019-04-03 00:12:20 +03:00
def __init__ ( self , on_leave_fn , on_send_key_fn ) :
self . _send_key_button = None
self . _keycombo_menu = None
self . _toolbar = None
2019-01-02 03:28:04 +03:00
self . timed_revealer = None
2019-04-03 00:12:20 +03:00
self . _init_ui ( on_leave_fn , on_send_key_fn )
2019-01-02 03:28:04 +03:00
2019-04-03 00:12:20 +03:00
def _init_ui ( self , on_leave_fn , on_send_key_fn ) :
self . _keycombo_menu = build_keycombo_menu ( on_send_key_fn )
2019-01-02 03:28:04 +03:00
2019-04-03 00:12:20 +03:00
self . _toolbar = Gtk . Toolbar ( )
self . _toolbar . set_show_arrow ( False )
self . _toolbar . set_style ( Gtk . ToolbarStyle . BOTH_HORIZ )
self . _toolbar . get_accessible ( ) . set_name ( " Fullscreen Toolbar " )
2019-01-02 03:28:04 +03:00
2019-04-03 00:12:20 +03:00
# Exit button
2019-01-02 03:28:04 +03:00
button = Gtk . ToolButton . new_from_stock ( Gtk . STOCK_LEAVE_FULLSCREEN )
2019-04-03 00:12:20 +03:00
button . set_tooltip_text ( _ ( " Leave fullscreen " ) )
2019-01-02 03:28:04 +03:00
button . show ( )
2019-04-03 00:12:20 +03:00
button . get_accessible ( ) . set_name ( " Fullscreen Exit " )
self . _toolbar . add ( button )
2019-01-02 03:28:04 +03:00
button . connect ( " clicked " , on_leave_fn )
2019-04-03 00:12:20 +03:00
self . _send_key_button = Gtk . ToolButton ( )
self . _send_key_button . set_icon_name (
2019-01-02 03:28:04 +03:00
" preferences-desktop-keyboard-shortcuts " )
2019-04-03 00:12:20 +03:00
self . _send_key_button . set_tooltip_text ( _ ( " Send key combination " ) )
self . _send_key_button . show_all ( )
2019-04-03 00:15:08 +03:00
self . _send_key_button . connect ( " clicked " ,
self . _on_send_key_button_clicked_cb )
2019-04-03 00:12:20 +03:00
self . _send_key_button . get_accessible ( ) . set_name ( " Fullscreen Send Key " )
self . _toolbar . add ( self . _send_key_button )
2019-01-02 03:28:04 +03:00
2019-04-03 00:12:20 +03:00
self . timed_revealer = _TimedRevealer ( self . _toolbar )
2019-01-02 03:28:04 +03:00
2019-04-03 00:15:08 +03:00
def _on_send_key_button_clicked_cb ( self , src ) :
2019-04-03 00:22:37 +03:00
event = Gtk . get_current_event ( )
win = self . _toolbar . get_window ( )
rect = Gdk . Rectangle ( )
rect . y = win . get_height ( )
self . _keycombo_menu . popup_at_rect ( win , rect ,
Gdk . Gravity . NORTH_WEST , Gdk . Gravity . NORTH_WEST , event )
2019-04-03 00:15:08 +03:00
2019-01-02 03:28:04 +03:00
def cleanup ( self ) :
2019-04-03 00:12:20 +03:00
self . _keycombo_menu . destroy ( )
self . _keycombo_menu = None
self . _toolbar . destroy ( )
self . _toolbar = None
2019-01-02 03:28:04 +03:00
self . timed_revealer . cleanup ( )
self . timed_revealer = None
def set_sensitive ( self , can_sendkey ) :
2019-04-03 00:12:20 +03:00
self . _send_key_button . set_sensitive ( can_sendkey )
2019-01-02 03:28:04 +03:00
2020-09-09 14:44:17 +03:00
class _ConsoleMenu :
"""
Helper class for building the text / graphical console menu list
"""
################
# Internal API #
################
def _build_serial_menu_items ( self , vm ) :
devs = vmmSerialConsole . get_serialcon_devices ( vm )
if len ( devs ) == 0 :
return [ [ _ ( " No text console available " ) , None , None ] ]
ret = [ ]
for dev in devs :
if dev . DEVICE_TYPE == " console " :
label = _ ( " Text Console %d " ) % ( dev . get_xml_idx ( ) + 1 )
else :
label = _ ( " Serial %d " ) % ( dev . get_xml_idx ( ) + 1 )
tooltip = vmmSerialConsole . can_connect ( vm , dev )
ret . append ( [ label , dev , tooltip ] )
return ret
def _build_graphical_menu_items ( self , vm ) :
devs = vm . xmlobj . devices . graphics
if len ( devs ) == 0 :
return [ [ _ ( " No graphical console available " ) , None , None ] ]
from . . device . gfxdetails import vmmGraphicsDetails
ret = [ ]
for idx , dev in enumerate ( devs ) :
label = ( _ ( " Graphical Console " ) + " " +
vmmGraphicsDetails . graphics_pretty_type_simple ( dev . type ) )
tooltip = None
if idx > 0 :
label + = " %s " % ( idx + 1 )
tooltip = _ ( " virt-manager does not support more "
" than one graphical console " )
ret . append ( [ label , dev , tooltip ] )
return ret
##############
# Public API #
##############
def rebuild_menu ( self , vm , submenu , toggled_cb ) :
oldlabel = None
for child in submenu . get_children ( ) :
if hasattr ( child , ' get_active ' ) and child . get_active ( ) :
oldlabel = child . get_label ( )
submenu . remove ( child )
graphics = self . _build_graphical_menu_items ( vm )
serials = self . _build_serial_menu_items ( vm )
# Use label == None to tell the loop to add a separator
items = graphics + [ [ None , None , None ] ] + serials
last_item = None
for ( label , dev , tooltip ) in items :
if label is None :
submenu . add ( Gtk . SeparatorMenuItem ( ) )
continue
cb = toggled_cb
cbdata = dev
sensitive = dev and not tooltip
active = False
if oldlabel is None and sensitive :
# Select the first selectable option
oldlabel = label
if label == oldlabel :
active = True
item = Gtk . RadioMenuItem ( )
if last_item is None :
last_item = item
else :
item . join_group ( last_item )
item . set_label ( label )
item . set_active ( active and sensitive )
if cbdata and sensitive :
item . connect ( " toggled " , cb , cbdata )
item . set_sensitive ( sensitive )
item . set_tooltip_text ( tooltip or None )
submenu . add ( item )
submenu . show_all ( )
def activate_default ( self , menu ) :
for child in menu . get_children ( ) :
if child . get_sensitive ( ) and hasattr ( child , " toggled " ) :
child . toggled ( )
break
2015-04-04 03:54:38 +03:00
class vmmConsolePages ( vmmGObjectUI ) :
2015-04-04 01:03:58 +03:00
"""
2015-04-04 03:54:38 +03:00
Handles all the complex UI handling dictated by the spice / vnc widgets
2015-04-04 01:03:58 +03:00
"""
2013-02-16 22:31:46 +04:00
def __init__ ( self , vm , builder , topwin ) :
2013-06-09 03:25:36 +04:00
vmmGObjectUI . __init__ ( self , None , None , builder = builder , topwin = topwin )
2009-10-30 20:25:27 +03:00
self . vm = vm
2015-04-04 01:03:58 +03:00
self . _pointer_is_grabbed = False
self . _change_title ( )
2015-04-10 01:02:42 +03:00
self . vm . connect ( " state-changed " , self . _change_title )
2009-10-30 20:25:27 +03:00
# State for disabling modifiers when keyboard is grabbed
2015-04-04 04:34:03 +03:00
self . _accel_groups = Gtk . accel_groups_from_object ( self . topwin )
self . _gtk_settings_accel = None
self . _gtk_settings_mnemonic = None
2009-10-30 20:25:27 +03:00
# Initialize display widget
2015-04-04 01:03:58 +03:00
self . _viewer = None
2009-10-30 20:25:27 +03:00
2011-05-19 01:22:07 +04:00
# Fullscreen toolbar
2019-01-02 03:28:04 +03:00
self . _keycombo_menu = build_keycombo_menu ( self . _do_send_key )
2019-04-03 00:12:20 +03:00
self . _overlay_toolbar_fullscreen = vmmOverlayToolbar (
2019-01-02 03:28:04 +03:00
on_leave_fn = self . _leave_fullscreen ,
on_send_key_fn = self . _do_send_key )
2019-04-03 00:12:20 +03:00
self . widget ( " console-overlay " ) . add_overlay (
self . _overlay_toolbar_fullscreen . timed_revealer . get_overlay_widget ( ) )
2011-05-19 01:22:07 +04:00
2010-12-22 04:13:11 +03:00
# Make viewer widget background always be black
2012-05-14 17:24:56 +04:00
black = Gdk . Color ( 0 , 0 , 0 )
2013-04-21 20:10:14 +04:00
self . widget ( " console-gfx-viewport " ) . modify_bg ( Gtk . StateType . NORMAL ,
2011-07-14 21:13:13 +04:00
black )
2009-11-29 02:48:56 +03:00
2015-09-18 18:55:15 +03:00
self . widget ( " console-pages " ) . set_show_tabs ( False )
self . widget ( " serial-pages " ) . set_show_tabs ( False )
2020-09-09 14:44:17 +03:00
self . _consolemenu = _ConsoleMenu ( )
2015-09-18 18:55:15 +03:00
self . _serial_consoles = [ ]
2013-09-02 01:40:38 +04:00
self . _init_menus ( )
2019-05-05 23:25:35 +03:00
# Signals are added by vmmVMWindow. Don't use connect_signals here
2009-10-30 20:25:27 +03:00
# or it changes will be overwritten
2013-04-18 01:39:25 +04:00
2015-09-18 20:05:41 +03:00
self . widget ( " console-gfx-scroll " ) . connect ( " size-allocate " ,
self . _scroll_size_allocate )
self . _refresh_widget_states ( )
2015-04-04 04:34:03 +03:00
self . _refresh_scaling_from_settings ( )
2015-09-18 20:05:41 +03:00
2014-09-28 15:37:16 +04:00
self . add_gsettings_handle (
2014-01-31 04:15:02 +04:00
self . vm . on_console_scaling_changed (
2015-04-04 04:34:03 +03:00
self . _refresh_scaling_from_settings ) )
2015-04-04 01:03:58 +03:00
self . _refresh_resizeguest_from_settings ( )
2014-09-28 15:37:16 +04:00
self . add_gsettings_handle (
2014-01-31 18:13:53 +04:00
self . vm . on_console_resizeguest_changed (
2015-04-04 01:03:58 +03:00
self . _refresh_resizeguest_from_settings ) )
2009-10-30 20:25:27 +03:00
2014-01-27 02:09:07 +04:00
2011-07-24 05:16:54 +04:00
def _cleanup ( self ) :
2011-04-12 02:35:21 +04:00
self . vm = None
2011-05-19 01:36:08 +04:00
2015-04-04 01:03:58 +03:00
if self . _viewer :
self . _viewer . cleanup ( )
self . _viewer = None
2011-04-12 02:35:21 +04:00
2019-01-02 03:28:04 +03:00
self . _overlay_toolbar_fullscreen . cleanup ( )
2011-05-19 01:22:07 +04:00
2015-09-18 18:55:15 +03:00
for serial in self . _serial_consoles :
2013-09-02 01:40:38 +04:00
serial . cleanup ( )
2015-09-18 18:55:15 +03:00
self . _serial_consoles = [ ]
2013-09-02 01:40:38 +04:00
2009-10-30 20:25:27 +03:00
##########################
# Initialization helpers #
##########################
2011-05-19 01:22:07 +04:00
2013-09-02 01:40:38 +04:00
def _init_menus ( self ) :
# Serial list menu
smenu = Gtk . Menu ( )
2014-12-03 20:14:32 +03:00
smenu . connect ( " show " , self . _populate_serial_menu )
2020-09-09 14:44:17 +03:00
self . widget ( " details-menu-view-console-list " ) . set_submenu ( smenu )
2013-09-02 01:40:38 +04:00
2015-09-06 01:23:47 +03:00
# Keycombo menu (ctrl+alt+del etc.)
self . widget ( " details-menu-send-key " ) . set_submenu ( self . _keycombo_menu )
2015-04-04 04:34:03 +03:00
#################
# Internal APIs #
#################
2015-04-04 01:03:58 +03:00
def _change_title ( self , ignore1 = None ) :
2015-09-01 01:38:05 +03:00
title = ( _ ( " % (vm-name)s on % (connection-name)s " ) % {
" vm-name " : self . vm . get_name_or_title ( ) ,
" connection-name " : self . vm . conn . get_pretty_desc ( ) ,
} )
2011-03-23 23:56:12 +03:00
2015-04-04 01:03:58 +03:00
if self . _pointer_is_grabbed and self . _viewer :
keystr = self . _viewer . console_get_grab_keys ( )
2011-03-23 23:56:12 +03:00
keymsg = _ ( " Press %s to release pointer. " ) % keystr
title = keymsg + " " + title
self . topwin . set_title ( title )
2010-04-21 20:59:25 +04:00
def _disable_modifiers ( self ) :
2015-04-04 04:34:03 +03:00
if self . _gtk_settings_accel is not None :
2009-11-02 00:36:44 +03:00
return
2015-04-04 04:34:03 +03:00
for g in self . _accel_groups :
2009-10-30 20:25:27 +03:00
self . topwin . remove_accel_group ( g )
2009-10-30 21:36:17 +03:00
2012-05-14 17:24:56 +04:00
settings = Gtk . Settings . get_default ( )
2015-04-04 04:34:03 +03:00
self . _gtk_settings_accel = settings . get_property ( ' gtk-menu-bar-accel ' )
2009-10-30 20:25:27 +03:00
settings . set_property ( ' gtk-menu-bar-accel ' , None )
2015-04-04 04:34:03 +03:00
self . _gtk_settings_mnemonic = settings . get_property (
2015-03-26 20:10:38 +03:00
" gtk-enable-mnemonics " )
settings . set_property ( " gtk-enable-mnemonics " , False )
2009-10-30 21:36:17 +03:00
2010-04-21 20:59:25 +04:00
def _enable_modifiers ( self ) :
2015-04-04 04:34:03 +03:00
if self . _gtk_settings_accel is None :
2009-10-30 20:25:27 +03:00
return
2009-11-02 00:36:44 +03:00
2012-05-14 17:24:56 +04:00
settings = Gtk . Settings . get_default ( )
2015-04-04 04:34:03 +03:00
settings . set_property ( ' gtk-menu-bar-accel ' , self . _gtk_settings_accel )
self . _gtk_settings_accel = None
2009-10-30 21:36:17 +03:00
2015-04-04 04:34:03 +03:00
if self . _gtk_settings_mnemonic is not None :
2009-10-30 21:36:17 +03:00
settings . set_property ( " gtk-enable-mnemonics " ,
2015-04-04 04:34:03 +03:00
self . _gtk_settings_mnemonic )
2009-10-30 21:36:17 +03:00
2015-04-04 04:34:03 +03:00
for g in self . _accel_groups :
2009-10-30 20:25:27 +03:00
self . topwin . add_accel_group ( g )
2015-04-04 04:34:03 +03:00
def _do_send_key ( self , src , keys ) :
ignore = src
if keys is not None :
self . _viewer . console_send_keys ( keys )
###########################
# Resize and scaling APIs #
###########################
def _scroll_size_allocate ( self , src_ignore , req ) :
2016-05-20 01:27:35 +03:00
if not self . _viewer :
return
2020-08-29 20:32:37 +03:00
res = self . _viewer . console_get_desktop_resolution ( )
if res is None :
if not self . config . CLITestOptions . fake_console_resolution :
return
res = ( 800 , 600 )
2015-04-04 04:34:03 +03:00
scroll = self . widget ( " console-gfx-scroll " )
is_scale = self . _viewer . console_get_scaling ( )
is_resizeguest = self . _viewer . console_get_resizeguest ( )
dx = 0
dy = 0
align_ratio = float ( req . width ) / float ( req . height )
# pylint: disable=unpacking-non-sequence
2020-08-29 20:32:37 +03:00
desktop_w , desktop_h = res
2015-04-04 04:34:03 +03:00
desktop_ratio = float ( desktop_w ) / float ( desktop_h )
2016-05-20 01:27:35 +03:00
if is_scale :
2015-04-04 04:34:03 +03:00
# Make sure we never show scrollbars when scaling
scroll . set_policy ( Gtk . PolicyType . NEVER , Gtk . PolicyType . NEVER )
else :
scroll . set_policy ( Gtk . PolicyType . AUTOMATIC ,
Gtk . PolicyType . AUTOMATIC )
2016-05-20 01:27:35 +03:00
if is_resizeguest :
2015-04-04 04:34:03 +03:00
# With resize guest, we don't want to maintain aspect ratio,
# since the guest can resize to arbitrary resolutions.
2019-10-09 12:18:53 +03:00
viewer_alloc = Gdk . Rectangle ( )
viewer_alloc . width = req . width
viewer_alloc . height = req . height
self . _viewer . console_size_allocate ( viewer_alloc )
2015-04-04 04:34:03 +03:00
return
2016-05-20 01:27:35 +03:00
if not is_scale :
2015-04-04 04:34:03 +03:00
# Scaling disabled is easy, just force the VNC widget size. Since
# we are inside a scrollwindow, it shouldn't cause issues.
self . _viewer . console_set_size_request ( desktop_w , desktop_h )
return
# Make sure there is no hard size requirement so we can scale down
self . _viewer . console_set_size_request ( - 1 , - 1 )
# Make sure desktop aspect ratio is maintained
if align_ratio > desktop_ratio :
desktop_w = int ( req . height * desktop_ratio )
desktop_h = req . height
2017-10-11 14:35:55 +03:00
dx = ( req . width - desktop_w ) / / 2
2015-04-04 04:34:03 +03:00
else :
desktop_w = req . width
2017-10-11 14:35:55 +03:00
desktop_h = int ( req . width / / desktop_ratio )
dy = ( req . height - desktop_h ) / / 2
2015-04-04 04:34:03 +03:00
viewer_alloc = Gdk . Rectangle ( )
viewer_alloc . x = dx
viewer_alloc . y = dy
viewer_alloc . width = desktop_w
viewer_alloc . height = desktop_h
self . _viewer . console_size_allocate ( viewer_alloc )
2015-04-04 01:03:58 +03:00
def _refresh_resizeguest_from_settings ( self ) :
2014-01-31 18:13:53 +04:00
tooltip = " "
2015-04-04 01:03:58 +03:00
if self . _viewer :
if self . _viewer . viewer_type != " spice " :
2014-01-31 18:13:53 +04:00
tooltip = (
_ ( " Graphics type ' %s ' does not support auto resize. " ) %
2015-04-04 01:03:58 +03:00
self . _viewer . viewer_type )
elif not self . _viewer . console_has_agent ( ) :
2014-01-31 18:13:53 +04:00
tooltip = _ ( " Guest agent is not available. " )
val = self . vm . get_console_resizeguest ( )
widget = self . widget ( " details-menu-view-resizeguest " )
widget . set_tooltip_text ( tooltip )
widget . set_sensitive ( not bool ( tooltip ) )
if not tooltip :
self . widget ( " details-menu-view-resizeguest " ) . set_active ( bool ( val ) )
2015-04-04 04:34:03 +03:00
self . _sync_resizeguest_with_display ( )
2014-01-31 18:13:53 +04:00
2015-04-04 04:34:03 +03:00
def _sync_resizeguest_with_display ( self ) :
if not self . _viewer :
return
val = bool ( self . vm . get_console_resizeguest ( ) )
self . _viewer . console_set_resizeguest ( val )
self . widget ( " console-gfx-scroll " ) . queue_resize ( )
def _resizeguest_ui_changed_cb ( self , src ) :
2014-02-28 20:46:05 +04:00
if not src . get_sensitive ( ) :
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2014-01-31 18:13:53 +04:00
val = int ( self . widget ( " details-menu-view-resizeguest " ) . get_active ( ) )
self . vm . set_console_resizeguest ( val )
2015-04-04 04:34:03 +03:00
self . _sync_resizeguest_with_display ( )
2014-01-31 18:13:53 +04:00
2015-04-04 04:34:03 +03:00
def _do_size_to_vm ( self , src_ignore ) :
# Resize the console to best fit the VM resolution
2015-04-04 01:03:58 +03:00
if not self . _viewer :
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2015-04-04 04:34:03 +03:00
if not self . _viewer . console_get_desktop_resolution ( ) :
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2014-01-31 18:13:53 +04:00
2016-12-13 21:31:17 +03:00
top_w , top_h = self . topwin . get_size ( )
2016-05-20 01:27:35 +03:00
viewer_alloc = self . widget ( " console-gfx-scroll " ) . get_allocation ( )
desktop_w , desktop_h = self . _viewer . console_get_desktop_resolution ( )
2015-04-04 04:34:03 +03:00
self . topwin . unmaximize ( )
2016-05-20 01:27:35 +03:00
self . topwin . resize (
2016-12-13 21:31:17 +03:00
desktop_w + ( top_w - viewer_alloc . width ) ,
desktop_h + ( top_h - viewer_alloc . height ) )
2014-01-31 18:13:53 +04:00
2015-04-04 04:34:03 +03:00
################
# Scaling APIs #
################
def _refresh_scaling_from_settings ( self ) :
2014-01-31 04:15:02 +04:00
scale_type = self . vm . get_console_scaling ( )
2011-07-14 21:13:13 +04:00
self . widget ( " details-menu-view-scale-always " ) . set_active (
2014-01-31 04:15:02 +04:00
scale_type == self . config . CONSOLE_SCALE_ALWAYS )
2011-07-14 21:13:13 +04:00
self . widget ( " details-menu-view-scale-never " ) . set_active (
2014-01-31 04:15:02 +04:00
scale_type == self . config . CONSOLE_SCALE_NEVER )
2011-07-14 21:13:13 +04:00
self . widget ( " details-menu-view-scale-fullscreen " ) . set_active (
2014-01-31 04:15:02 +04:00
scale_type == self . config . CONSOLE_SCALE_FULLSCREEN )
2009-10-30 20:25:27 +03:00
2015-04-04 01:03:58 +03:00
self . _sync_scaling_with_display ( )
2009-10-30 20:25:27 +03:00
2015-04-04 04:34:03 +03:00
def _scaling_ui_changed_cb ( self , src ) :
2014-01-31 04:15:02 +04:00
# Called from details.py
2009-10-30 20:25:27 +03:00
if not src . get_active ( ) :
return
2014-01-31 04:15:02 +04:00
scale_type = 0
2011-07-14 21:13:13 +04:00
if src == self . widget ( " details-menu-view-scale-always " ) :
2014-01-31 04:15:02 +04:00
scale_type = self . config . CONSOLE_SCALE_ALWAYS
2011-07-14 21:13:13 +04:00
elif src == self . widget ( " details-menu-view-scale-fullscreen " ) :
2014-01-31 04:15:02 +04:00
scale_type = self . config . CONSOLE_SCALE_FULLSCREEN
2011-07-14 21:13:13 +04:00
elif src == self . widget ( " details-menu-view-scale-never " ) :
2014-01-31 04:15:02 +04:00
scale_type = self . config . CONSOLE_SCALE_NEVER
2009-10-30 20:25:27 +03:00
2014-01-31 04:15:02 +04:00
self . vm . set_console_scaling ( scale_type )
2015-04-04 01:03:58 +03:00
self . _sync_scaling_with_display ( )
2009-10-30 20:25:27 +03:00
2015-04-04 01:03:58 +03:00
def _sync_scaling_with_display ( self ) :
if not self . _viewer :
2010-12-22 04:13:11 +03:00
return
2015-04-04 01:03:58 +03:00
curscale = self . _viewer . console_get_scaling ( )
2011-07-14 21:13:13 +04:00
fs = self . widget ( " control-fullscreen " ) . get_active ( )
2014-01-31 04:15:02 +04:00
scale_type = self . vm . get_console_scaling ( )
2009-10-30 20:25:27 +03:00
2015-07-10 15:07:02 +03:00
if ( scale_type == self . config . CONSOLE_SCALE_NEVER and
curscale is True ) :
2015-04-04 01:03:58 +03:00
self . _viewer . console_set_scaling ( False )
2015-07-10 15:07:02 +03:00
elif ( scale_type == self . config . CONSOLE_SCALE_ALWAYS and
curscale is False ) :
2015-04-04 01:03:58 +03:00
self . _viewer . console_set_scaling ( True )
2015-07-10 15:07:02 +03:00
elif ( scale_type == self . config . CONSOLE_SCALE_FULLSCREEN and
curscale != fs ) :
2015-04-04 01:03:58 +03:00
self . _viewer . console_set_scaling ( fs )
2009-10-30 20:25:27 +03:00
2009-11-29 02:48:56 +03:00
# Refresh viewer size
2014-01-30 01:58:34 +04:00
self . widget ( " console-gfx-scroll " ) . queue_resize ( )
2009-11-29 02:48:56 +03:00
2009-10-30 20:25:27 +03:00
2015-04-04 04:34:03 +03:00
###################
# Fullscreen APIs #
###################
def _refresh_can_fullscreen ( self ) :
cpage = self . widget ( " console-pages " ) . get_current_page ( )
dpage = self . widget ( " details-pages " ) . get_current_page ( )
2015-11-25 02:23:36 +03:00
allow_fullscreen = bool ( dpage == DETAILS_PAGE_CONSOLE and
cpage == _CONSOLE_PAGE_VIEWER and
self . _viewer and self . _viewer . console_is_open ( ) )
2011-05-19 01:22:07 +04:00
2015-04-04 04:34:03 +03:00
self . widget ( " control-fullscreen " ) . set_sensitive ( allow_fullscreen )
self . widget ( " details-menu-view-fullscreen " ) . set_sensitive (
allow_fullscreen )
def _leave_fullscreen ( self , ignore = None ) :
2011-05-19 01:22:07 +04:00
self . _change_fullscreen ( False )
2009-11-23 00:39:38 +03:00
2011-05-19 01:22:07 +04:00
def _change_fullscreen ( self , do_fullscreen ) :
2011-07-14 21:13:13 +04:00
self . widget ( " control-fullscreen " ) . set_active ( do_fullscreen )
2009-11-23 00:39:38 +03:00
if do_fullscreen :
2009-10-30 20:25:27 +03:00
self . topwin . fullscreen ( )
2019-01-02 03:28:04 +03:00
self . _overlay_toolbar_fullscreen . timed_revealer . force_reveal ( True )
2011-07-14 21:13:13 +04:00
self . widget ( " toolbar-box " ) . hide ( )
self . widget ( " details-menubar " ) . hide ( )
2009-10-30 20:25:27 +03:00
else :
2019-01-02 03:28:04 +03:00
self . _overlay_toolbar_fullscreen . timed_revealer . force_reveal ( False )
2009-10-30 20:25:27 +03:00
self . topwin . unfullscreen ( )
2011-07-14 21:13:13 +04:00
if self . widget ( " details-menu-view-toolbar " ) . get_active ( ) :
self . widget ( " toolbar-box " ) . show ( )
self . widget ( " details-menubar " ) . show ( )
2009-10-30 20:25:27 +03:00
2015-04-04 01:03:58 +03:00
self . _sync_scaling_with_display ( )
2014-01-30 01:58:34 +04:00
2009-10-30 20:25:27 +03:00
##########################
# State tracking methods #
##########################
2015-04-12 17:24:35 +03:00
def _show_vm_status_unavailable ( self ) :
2020-08-29 20:32:37 +03:00
if self . vm . is_crashed ( ) : # pragma: no cover
2016-05-16 23:06:04 +03:00
self . _activate_unavailable_page ( _ ( " Guest has crashed. " ) )
2009-10-30 20:25:27 +03:00
else :
2016-05-16 23:06:04 +03:00
self . _activate_unavailable_page ( _ ( " Guest is not running. " ) )
2009-10-30 20:25:27 +03:00
2015-04-04 04:34:03 +03:00
def _close_viewer ( self ) :
2020-08-28 17:25:38 +03:00
self . _leave_fullscreen ( )
for serial in self . _serial_consoles :
serial . close ( )
2015-04-04 01:03:58 +03:00
if self . _viewer is None :
2011-01-14 19:34:51 +03:00
return
2015-04-12 17:33:41 +03:00
self . _viewer . console_remove_display_from_widget (
self . widget ( " console-gfx-viewport " ) )
self . _viewer . cleanup ( )
2015-04-04 01:03:58 +03:00
self . _viewer = None
2011-01-14 19:34:51 +03:00
2015-04-12 20:04:32 +03:00
def _update_vm_widget_states ( self ) :
2015-09-06 01:23:47 +03:00
page = self . widget ( " console-pages " ) . get_current_page ( )
2015-04-04 04:34:03 +03:00
2015-09-06 01:23:47 +03:00
if self . vm . is_runable ( ) :
2015-04-12 17:24:35 +03:00
self . _show_vm_status_unavailable ( )
2009-10-30 20:25:27 +03:00
2015-09-18 18:55:15 +03:00
elif ( page == _CONSOLE_PAGE_UNAVAILABLE or
page == _CONSOLE_PAGE_VIEWER ) :
2015-04-04 01:03:58 +03:00
if self . _viewer and self . _viewer . console_is_open ( ) :
2015-04-04 04:34:03 +03:00
self . _activate_viewer_page ( )
2009-10-30 20:25:27 +03:00
else :
2015-04-12 17:24:35 +03:00
self . _init_viewer ( )
2015-09-12 19:07:56 +03:00
# Update other state
2015-09-18 20:05:41 +03:00
self . _refresh_widget_states ( )
2009-10-30 20:25:27 +03:00
2013-09-02 01:40:38 +04:00
2009-10-30 20:25:27 +03:00
###################
# Page Navigation #
###################
2015-04-04 04:34:03 +03:00
def _activate_unavailable_page ( self , msg ) :
2011-06-21 03:09:31 +04:00
"""
This function is passed to serialcon . py at least , so change
with care
"""
2015-04-04 04:34:03 +03:00
self . _close_viewer ( )
self . widget ( " console-pages " ) . set_current_page (
2015-09-18 18:55:15 +03:00
_CONSOLE_PAGE_UNAVAILABLE )
2016-08-17 19:31:54 +03:00
if msg :
self . widget ( " console-unavailable " ) . set_label ( " <b> " + msg + " </b> " )
2009-10-30 20:25:27 +03:00
2015-04-04 04:34:03 +03:00
def _activate_auth_page ( self , withPassword , withUsername ) :
2020-08-26 16:03:09 +03:00
( pw , username ) = vmmKeyring . get_instance ( ) . get_console_password ( self . vm )
2009-10-30 20:25:27 +03:00
2013-09-02 01:40:38 +04:00
self . widget ( " console-auth-password " ) . set_visible ( withPassword )
self . widget ( " label-auth-password " ) . set_visible ( withPassword )
self . widget ( " console-auth-username " ) . set_visible ( withUsername )
self . widget ( " label-auth-username " ) . set_visible ( withUsername )
2009-10-30 20:25:27 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " console-auth-username " ) . set_text ( username )
self . widget ( " console-auth-password " ) . set_text ( pw )
2009-10-30 20:25:27 +03:00
2020-08-26 16:03:09 +03:00
has_keyring = vmmKeyring . get_instance ( ) . is_available ( )
remember = bool ( withPassword and pw ) or ( withUsername and username )
remember = has_keyring and remember
self . widget ( " console-auth-remember " ) . set_sensitive ( has_keyring )
self . widget ( " console-auth-remember " ) . set_active ( remember )
2013-09-02 01:40:38 +04:00
self . widget ( " console-pages " ) . set_current_page (
2015-09-18 18:55:15 +03:00
_CONSOLE_PAGE_AUTHENTICATE )
2009-10-30 20:25:27 +03:00
2015-04-12 19:43:29 +03:00
if withUsername :
self . widget ( " console-auth-username " ) . grab_focus ( )
else :
self . widget ( " console-auth-password " ) . grab_focus ( )
2015-04-04 04:34:03 +03:00
def _activate_viewer_page ( self ) :
2015-09-18 18:55:15 +03:00
self . widget ( " console-pages " ) . set_current_page ( _CONSOLE_PAGE_VIEWER )
2015-04-04 01:03:58 +03:00
if self . _viewer :
self . _viewer . console_grab_focus ( )
2009-10-30 20:25:27 +03:00
2015-09-18 20:05:41 +03:00
def _page_changed ( self , src , origpage , newpage ) :
ignore = src
ignore = origpage
# Hide the contents of all other pages, so they don't screw
# up window sizing
for i in range ( self . widget ( " console-pages " ) . get_n_pages ( ) ) :
self . widget ( " console-pages " ) . get_nth_page ( i ) . set_visible (
i == newpage )
2014-02-28 22:35:48 +04:00
2018-03-15 14:43:56 +03:00
# Dispatch the next bit in idle_add, so the UI size can change
2015-09-18 20:05:41 +03:00
self . idle_add ( self . _refresh_widget_states )
2014-02-28 22:35:48 +04:00
2015-09-18 20:05:41 +03:00
def _refresh_widget_states ( self ) :
2018-03-15 14:43:56 +03:00
if not self . vm :
# This is triggered via cleanup + idle_add, so vm might
# disappear and spam the logs
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2018-03-15 14:43:56 +03:00
2015-09-18 20:05:41 +03:00
pagenum = self . widget ( " console-pages " ) . get_current_page ( )
2015-09-06 01:23:47 +03:00
paused = self . vm . is_paused ( )
2017-03-29 19:07:02 +03:00
is_viewer = bool ( pagenum == _CONSOLE_PAGE_VIEWER and
2015-09-18 20:05:41 +03:00
self . _viewer and self . _viewer . console_is_open ( ) )
2015-09-06 01:23:47 +03:00
self . widget ( " details-menu-vm-screenshot " ) . set_sensitive ( is_viewer )
self . widget ( " details-menu-usb-redirection " ) . set_sensitive (
2015-09-12 19:07:56 +03:00
bool ( is_viewer and self . _viewer and
self . _viewer . console_has_usb_redirection ( ) and
self . vm . has_spicevmc_type_redirdev ( ) ) )
2015-09-06 01:23:47 +03:00
2015-09-18 20:05:41 +03:00
can_sendkey = ( is_viewer and not paused )
2015-09-06 01:23:47 +03:00
for c in self . _keycombo_menu . get_children ( ) :
2015-09-18 20:05:41 +03:00
c . set_sensitive ( can_sendkey )
2019-01-02 03:28:04 +03:00
self . _overlay_toolbar_fullscreen . set_sensitive ( can_sendkey )
2015-09-06 01:23:47 +03:00
2015-04-04 04:34:03 +03:00
self . _refresh_can_fullscreen ( )
2011-06-01 20:22:05 +04:00
2015-04-04 04:34:03 +03:00
#########################
# Viewer login attempts #
#########################
2011-06-01 20:22:05 +04:00
2015-04-12 17:24:35 +03:00
def _init_viewer ( self ) :
if self . _viewer or not self . is_visible ( ) :
2010-02-11 18:43:44 +03:00
# Don't try and login for these cases
2009-10-30 20:25:27 +03:00
return
2012-03-13 23:27:23 +04:00
ginfo = None
2010-01-11 18:30:40 +03:00
try :
2018-03-21 21:42:50 +03:00
gdevs = self . vm . xmlobj . devices . graphics
2012-03-13 23:27:23 +04:00
gdev = gdevs and gdevs [ 0 ] or None
if gdev :
2016-05-08 01:08:25 +03:00
ginfo = ConnectionInfo ( self . vm . conn , gdev )
2020-08-28 18:55:36 +03:00
except Exception as e : # pragma: no cover
2010-01-11 18:30:40 +03:00
# We can fail here if VM is destroyed: xen is a bit racy
# and can't handle domain lookups that soon after
2019-06-17 04:12:39 +03:00
log . exception ( " Getting graphics console failed: %s " , str ( e ) )
2010-01-11 18:30:40 +03:00
return
2012-03-13 23:27:23 +04:00
if ginfo is None :
2019-06-17 04:12:39 +03:00
log . debug ( " No graphics configured for guest " )
2015-04-04 04:34:03 +03:00
self . _activate_unavailable_page (
_ ( " Graphical console not configured for guest " ) )
2009-10-30 20:25:27 +03:00
return
2012-03-13 23:27:23 +04:00
if ginfo . gtype not in self . config . embeddable_graphics ( ) :
2019-06-17 04:12:39 +03:00
log . debug ( " Don ' t know how to show graphics type ' %s ' "
2012-03-13 23:27:23 +04:00
" disabling console page " , ginfo . gtype )
2011-01-07 22:59:31 +03:00
msg = ( _ ( " Cannot display graphical console type ' %s ' " )
2012-03-13 23:27:23 +04:00
% ginfo . gtype )
2011-01-07 22:59:31 +03:00
2015-04-04 04:34:03 +03:00
self . _activate_unavailable_page ( msg )
2009-10-30 20:25:27 +03:00
return
2015-04-04 04:34:03 +03:00
self . _activate_unavailable_page (
_ ( " Connecting to graphical console for guest " ) )
2010-02-11 18:43:44 +03:00
2019-06-17 04:12:39 +03:00
log . debug ( " Starting connect process for %s " , ginfo . logstring ( ) )
2009-10-30 20:25:27 +03:00
try :
2012-03-13 23:27:23 +04:00
if ginfo . gtype == " vnc " :
2015-04-04 01:03:58 +03:00
viewer_class = VNCViewer
2012-03-13 23:27:23 +04:00
elif ginfo . gtype == " spice " :
2020-08-28 18:55:36 +03:00
if not have_spice_gtk : # pragma: no cover
2015-08-13 23:00:33 +03:00
raise RuntimeError ( " Error opening Spice console, "
" SpiceClientGtk missing " )
2020-08-28 18:55:36 +03:00
viewer_class = SpiceViewer
2011-01-14 22:17:35 +03:00
2016-05-08 01:08:25 +03:00
self . _viewer = viewer_class ( self . vm , ginfo )
2015-04-04 01:03:58 +03:00
self . _connect_viewer_signals ( )
2011-01-14 22:17:35 +03:00
2015-04-12 04:39:24 +03:00
self . _viewer . console_open ( )
2017-05-05 19:47:21 +03:00
except Exception as e :
2019-06-17 04:12:39 +03:00
log . exception ( " Error connection to graphical console " )
2015-04-04 04:34:03 +03:00
self . _activate_unavailable_page (
2020-07-14 10:41:49 +03:00
_ ( " Error connecting to graphical console: \n %s " ) % e )
2009-10-30 20:25:27 +03:00
2015-04-04 04:34:03 +03:00
def _set_credentials ( self , src_ignore = None ) :
2011-07-14 21:13:13 +04:00
passwd = self . widget ( " console-auth-password " )
username = self . widget ( " console-auth-username " )
2015-04-04 01:03:58 +03:00
if passwd . get_visible ( ) :
self . _viewer . console_set_password ( passwd . get_text ( ) )
2012-05-14 17:24:56 +04:00
if username . get_visible ( ) :
2015-04-04 01:03:58 +03:00
self . _viewer . console_set_username ( username . get_text ( ) )
2009-10-30 20:25:27 +03:00
2011-07-14 21:13:13 +04:00
if self . widget ( " console-auth-remember " ) . get_active ( ) :
2020-08-26 16:03:09 +03:00
vmmKeyring . get_instance ( ) . set_console_password (
self . vm , passwd . get_text ( ) , username . get_text ( ) )
2016-06-07 16:25:55 +03:00
else :
2020-08-26 16:03:09 +03:00
vmmKeyring . get_instance ( ) . del_console_password ( self . vm )
2009-10-30 20:25:27 +03:00
2015-04-04 01:03:58 +03:00
##########################
# Viewer signal handling #
##########################
def _viewer_add_display ( self , ignore , display ) :
self . widget ( " console-gfx-viewport " ) . add ( display )
# Sync initial settings
self . _sync_scaling_with_display ( )
self . _refresh_resizeguest_from_settings ( )
def _pointer_grabbed ( self , ignore ) :
self . _pointer_is_grabbed = True
self . _change_title ( )
def _pointer_ungrabbed ( self , ignore ) :
self . _pointer_is_grabbed = False
self . _change_title ( )
def _viewer_allocate_cb ( self , src , ignore ) :
self . widget ( " console-gfx-scroll " ) . queue_resize ( )
2020-09-09 16:33:58 +03:00
def _viewer_keyboard_grab_cb ( self , src ) :
self . _viewer_sync_modifiers ( )
def _serial_focus_changed_cb ( self , src , event ) :
self . _viewer_sync_modifiers ( )
def _viewer_sync_modifiers ( self ) :
serial_has_focus = any ( [ s . has_focus ( ) for s in self . _serial_consoles ] )
viewer_keyboard_grab = ( self . _viewer and
self . _viewer . console_has_keyboard_grab ( ) )
if serial_has_focus or viewer_keyboard_grab :
2015-04-04 01:03:58 +03:00
self . _disable_modifiers ( )
else :
self . _enable_modifiers ( )
2015-04-12 20:04:32 +03:00
def _viewer_auth_error ( self , ignore , errmsg , viewer_will_disconnect ) :
errmsg = _ ( " Viewer authentication error: %s " ) % errmsg
self . err . val_err ( errmsg )
if viewer_will_disconnect :
# GtkVNC will disconnect after an auth error, so lets do it for
# them and re-init the viewer (which will be triggered by
# update_vm_widget_states if needed)
self . _activate_unavailable_page ( errmsg )
self . _update_vm_widget_states ( )
2015-04-04 01:03:58 +03:00
def _viewer_need_auth ( self , ignore , withPassword , withUsername ) :
2015-04-04 04:34:03 +03:00
self . _activate_auth_page ( withPassword , withUsername )
2015-04-04 01:03:58 +03:00
def _viewer_agent_connected ( self , ignore ) :
2020-08-29 20:32:37 +03:00
self . _refresh_resizeguest_from_settings ( ) # pragma: no cover
2015-04-04 01:03:58 +03:00
def _viewer_usb_redirect_error ( self , ignore , errstr ) :
2020-08-29 20:32:37 +03:00
self . err . show_err (
_ ( " USB redirection error " ) ,
text2 = str ( errstr ) , modal = True ) # pragma: no cover
2015-04-04 01:03:58 +03:00
2016-05-16 23:27:23 +03:00
def _viewer_disconnected_set_page ( self , errdetails , ssherr ) :
2020-08-29 20:32:37 +03:00
if self . vm . is_runable ( ) : # pragma: no cover
2016-05-16 23:16:13 +03:00
# Exit was probably for legitimate reasons
self . _show_vm_status_unavailable ( )
return
msg = _ ( " Viewer was disconnected. " )
2016-05-16 23:27:23 +03:00
if errdetails :
msg + = " \n " + errdetails
2016-05-16 23:16:13 +03:00
if ssherr :
2019-06-17 04:12:39 +03:00
log . debug ( " SSH tunnel error output: %s " , ssherr )
2016-05-16 23:16:13 +03:00
msg + = " \n \n "
msg + = _ ( " SSH tunnel error output: %s " ) % ssherr
2015-04-04 01:03:58 +03:00
2016-05-16 23:16:13 +03:00
self . _activate_unavailable_page ( msg )
2016-05-16 23:27:23 +03:00
def _viewer_disconnected ( self , ignore , errdetails , ssherr ) :
2016-08-17 19:31:54 +03:00
self . _activate_unavailable_page ( _ ( " Viewer disconnected. " ) )
2019-06-17 04:12:39 +03:00
log . debug ( " Viewer disconnected " )
2015-04-04 01:03:58 +03:00
# Make sure modifiers are set correctly
2020-09-09 16:33:58 +03:00
self . _viewer_sync_modifiers ( )
2015-04-04 01:03:58 +03:00
2016-05-16 23:27:23 +03:00
self . _viewer_disconnected_set_page ( errdetails , ssherr )
2015-04-04 01:03:58 +03:00
self . _refresh_resizeguest_from_settings ( )
def _viewer_connected ( self , ignore ) :
2019-06-17 04:12:39 +03:00
log . debug ( " Viewer connected " )
2015-04-04 04:34:03 +03:00
self . _activate_viewer_page ( )
2015-04-04 01:03:58 +03:00
# Make sure modifiers are set correctly
2020-09-09 16:33:58 +03:00
self . _viewer_sync_modifiers ( )
2015-04-04 01:03:58 +03:00
def _connect_viewer_signals ( self ) :
self . _viewer . connect ( " add-display-widget " , self . _viewer_add_display )
self . _viewer . connect ( " pointer-grab " , self . _pointer_grabbed )
self . _viewer . connect ( " pointer-ungrab " , self . _pointer_ungrabbed )
self . _viewer . connect ( " size-allocate " , self . _viewer_allocate_cb )
2020-09-09 16:33:58 +03:00
self . _viewer . connect ( " keyboard-grab " , self . _viewer_keyboard_grab_cb )
self . _viewer . connect ( " keyboard-ungrab " , self . _viewer_keyboard_grab_cb )
2015-04-04 01:03:58 +03:00
self . _viewer . connect ( " connected " , self . _viewer_connected )
self . _viewer . connect ( " disconnected " , self . _viewer_disconnected )
self . _viewer . connect ( " auth-error " , self . _viewer_auth_error )
self . _viewer . connect ( " need-auth " , self . _viewer_need_auth )
self . _viewer . connect ( " agent-connected " , self . _viewer_agent_connected )
self . _viewer . connect ( " usb-redirect-error " ,
self . _viewer_usb_redirect_error )
2013-09-02 01:40:38 +04:00
###########################
# Serial console handling #
###########################
2015-04-04 04:34:03 +03:00
def _activate_default_console_page ( self ) :
2015-09-18 18:55:15 +03:00
"""
2020-09-09 14:44:17 +03:00
Toggle default console page from the menu
2015-09-18 18:55:15 +03:00
"""
# We iterate through the 'console' menu and activate the first
2020-09-09 14:44:17 +03:00
# valid entry... hacky but it works
2014-12-03 20:14:32 +03:00
self . _populate_serial_menu ( )
2020-09-09 14:44:17 +03:00
menu = self . widget ( " details-menu-view-console-list " ) . get_submenu ( )
self . _consolemenu . activate_default ( menu )
2013-09-02 01:40:38 +04:00
2014-12-03 20:14:32 +03:00
def _console_menu_toggled ( self , src , dev ) :
2013-09-02 01:40:38 +04:00
self . widget ( " details-pages " ) . set_current_page ( DETAILS_PAGE_CONSOLE )
2014-12-03 20:14:32 +03:00
2020-09-09 14:44:17 +03:00
if dev and dev . DEVICE_TYPE == " graphics " :
2015-09-18 18:55:15 +03:00
self . widget ( " console-pages " ) . set_current_page ( _CONSOLE_PAGE_VIEWER )
2014-12-03 20:14:32 +03:00
return
2013-09-02 01:40:38 +04:00
2018-03-21 21:42:50 +03:00
target_port = dev . get_xml_idx ( )
2013-09-02 01:40:38 +04:00
serial = None
2015-09-18 18:55:15 +03:00
name = src . get_label ( )
for s in self . _serial_consoles :
2013-09-02 01:40:38 +04:00
if s . name == name :
serial = s
break
if not serial :
serial = vmmSerialConsole ( self . vm , target_port , name )
2020-09-09 16:33:58 +03:00
serial . set_focus_callbacks ( self . _serial_focus_changed_cb ,
self . _serial_focus_changed_cb )
2013-09-02 01:40:38 +04:00
title = Gtk . Label ( label = name )
2020-08-28 18:14:10 +03:00
self . widget ( " serial-pages " ) . append_page ( serial . get_box ( ) , title )
2015-09-18 18:55:15 +03:00
self . _serial_consoles . append ( serial )
2013-09-02 01:40:38 +04:00
2013-11-10 02:54:47 +04:00
serial . open_console ( )
2015-09-18 18:55:15 +03:00
page_idx = self . _serial_consoles . index ( serial )
self . widget ( " console-pages " ) . set_current_page ( _CONSOLE_PAGE_SERIAL )
self . widget ( " serial-pages " ) . set_current_page ( page_idx )
2013-09-02 01:40:38 +04:00
2014-12-03 20:14:32 +03:00
def _populate_serial_menu ( self , ignore = None ) :
2020-09-09 14:44:17 +03:00
submenu = self . widget ( " details-menu-view-console-list " ) . get_submenu ( )
self . _consolemenu . rebuild_menu (
self . vm , submenu , self . _console_menu_toggled )
2013-09-02 01:40:38 +04:00
2015-04-04 04:34:03 +03:00
2019-05-05 23:25:35 +03:00
###########################
# API used by vmmVMWindow #
###########################
2015-04-04 04:34:03 +03:00
def details_viewer_is_visible ( self ) :
return bool ( self . _viewer and self . _viewer . console_get_visible ( ) )
def details_viewer_has_usb_redirection ( self ) :
return bool ( self . _viewer and
self . _viewer . console_has_usb_redirection ( ) )
def details_viewer_get_usb_widget ( self ) :
return self . _viewer . console_get_usb_widget ( )
def details_viewer_get_pixbuf ( self ) :
return self . _viewer . console_get_pixbuf ( )
def details_close_viewer ( self ) :
2016-08-17 19:31:54 +03:00
return self . _activate_unavailable_page ( _ ( " Viewer disconnected. " ) )
2015-04-04 04:34:03 +03:00
def details_activate_default_console_page ( self ) :
return self . _activate_default_console_page ( )
2015-04-12 20:04:32 +03:00
def details_update_widget_states ( self ) :
return self . _update_vm_widget_states ( )
2015-04-04 04:34:03 +03:00
def details_refresh_can_fullscreen ( self ) :
return self . _refresh_can_fullscreen ( )
def details_resizeguest_ui_changed_cb ( self , * args , * * kwargs ) :
return self . _resizeguest_ui_changed_cb ( * args , * * kwargs )
def details_page_changed ( self , * args , * * kwargs ) :
return self . _page_changed ( * args , * * kwargs )
def details_scaling_ui_changed_cb ( self , * args , * * kwargs ) :
return self . _scaling_ui_changed_cb ( * args , * * kwargs )
def details_size_to_vm ( self , * args , * * kwargs ) :
return self . _do_size_to_vm ( * args , * * kwargs )
def details_toggle_fullscreen ( self , src ) :
do_fullscreen = src . get_active ( )
self . _change_fullscreen ( do_fullscreen )
def details_auth_login ( self , ignore ) :
self . _set_credentials ( )