2018-12-14 16:34:18 +02:00
# Copyright (C) 2018 VMware, Inc.
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
2019-06-16 22:19:17 -04:00
from . . lib import uiutil
2019-06-16 21:45:19 -04:00
from . . baseclass import vmmGObjectUI
2018-12-14 16:34:18 +02:00
class vmmVsockDetails ( vmmGObjectUI ) :
__gsignals__ = {
" changed-auto-cid " : ( vmmGObjectUI . RUN_FIRST , None , [ ] ) ,
" changed-cid " : ( vmmGObjectUI . RUN_FIRST , None , [ ] ) ,
}
MIN_GUEST_CID = 3
def __init__ ( self , vm , builder , topwin ) :
super ( ) . __init__ ( " vsockdetails.ui " , None ,
builder = builder , topwin = topwin )
self . vm = vm
self . conn = vm . conn
self . builder . connect_signals ( {
" on_vsock_auto_toggled " : self . _vsock_auto_toggled ,
" on_vsock_cid_changed " : lambda ignore : self . emit ( " changed-cid " ) ,
} )
self . top_box = self . widget ( " vsock-box " )
def _cleanup ( self ) :
self . vm = None
self . conn = None
##############
# Public API #
##############
def reset_state ( self ) :
self . widget ( " vsock-auto " ) . set_active ( True )
self . widget ( " vsock-cid " ) . set_value ( self . MIN_GUEST_CID )
self . widget ( " vsock-cid " ) . set_visible ( False )
def get_values ( self ) :
auto_cid = self . widget ( " vsock-auto " ) . get_active ( )
cid = uiutil . spin_get_helper ( self . widget ( " vsock-cid " ) )
return auto_cid , cid
def set_dev ( self , dev ) :
self . reset_state ( )
is_auto = bool ( dev . auto_cid )
2020-08-22 14:21:49 -04:00
cid = int ( dev . cid or self . MIN_GUEST_CID )
2018-12-14 16:34:18 +02:00
2019-01-21 16:30:54 +08:00
label = self . widget ( " vsock-auto " ) . get_label ( ) . split ( " ( " ) [ 0 ]
if is_auto and self . vm . is_active ( ) :
label + = " ( %s %s ) " % ( _ ( " CID " ) , cid )
self . widget ( " vsock-auto " ) . set_label ( label )
2018-12-14 16:34:18 +02:00
self . widget ( " vsock-auto " ) . set_active ( is_auto )
self . widget ( " vsock-cid " ) . set_value ( cid )
self . widget ( " vsock-cid " ) . set_visible ( not is_auto )
#############
# Listeners #
#############
def _vsock_auto_toggled ( self , ignore ) :
is_auto = self . widget ( " vsock-auto " ) . get_active ( )
self . widget ( " vsock-cid " ) . set_visible ( not is_auto )
self . emit ( " changed-auto-cid " )