2007-09-22 00:28:31 +04:00
#
# Copyright (C) 2006 Red Hat, Inc.
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
2007-11-20 19:12:20 +03:00
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2007-09-22 00:28:31 +04:00
#
2011-04-12 02:35:21 +04:00
2013-04-12 01:16:33 +04:00
# pylint: disable=E0611
2012-05-14 17:24:56 +04:00
from gi . repository import GObject
2013-04-12 01:16:33 +04:00
# pylint: enable=E0611
2012-05-14 17:24:56 +04:00
2012-02-01 04:07:32 +04:00
import logging
2009-12-01 00:21:04 +03:00
import virtManager . uihelpers as uihelpers
2010-12-09 01:26:19 +03:00
from virtManager . baseclass import vmmGObjectUI
2009-12-14 22:52:52 +03:00
from virtManager . mediadev import MEDIA_FLOPPY
2009-06-18 18:40:37 +04:00
from virtManager . storagebrowse import vmmStorageBrowser
2007-09-22 00:28:31 +04:00
2013-04-13 22:34:52 +04:00
2010-12-09 01:26:19 +03:00
class vmmChooseCD ( vmmGObjectUI ) :
2012-05-14 17:24:56 +04:00
__gsignals__ = {
" cdrom-chosen " : ( GObject . SignalFlags . RUN_FIRST , None , [ object , str ] )
}
2011-07-22 20:17:19 +04:00
def __init__ ( self , vm , disk ) :
2012-02-02 02:26:46 +04:00
vmmGObjectUI . __init__ ( self , " vmm-choose-cd.ui " , " vmm-choose-cd " )
2009-06-18 18:40:37 +04:00
2011-07-22 20:17:19 +04:00
self . vm = vm
2011-07-23 00:43:26 +04:00
self . conn = self . vm . conn
2011-07-22 20:17:19 +04:00
self . disk = disk
2009-06-18 18:40:37 +04:00
self . storage_browser = None
2011-07-22 20:17:19 +04:00
self . media_type = disk . device
2007-09-22 00:28:31 +04:00
2013-02-16 22:31:46 +04:00
self . builder . connect_signals ( {
2007-09-22 00:28:31 +04:00
" on_media_toggled " : self . media_toggled ,
" on_fv_iso_location_browse_clicked " : self . browse_fv_iso_location ,
" on_cd_path_changed " : self . change_cd_path ,
" on_ok_clicked " : self . ok ,
2011-03-21 18:01:39 +03:00
" on_vmm_choose_cd_delete_event " : self . close ,
" on_cancel_clicked " : self . close ,
2011-04-12 02:35:21 +04:00
} )
2007-09-22 00:28:31 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " iso-image " ) . set_active ( True )
2007-09-22 00:28:31 +04:00
2009-07-02 20:43:08 +04:00
self . initialize_opt_media ( )
2008-09-09 15:35:20 +04:00
self . reset_state ( )
2007-09-22 00:28:31 +04:00
2010-11-29 22:06:43 +03:00
def close ( self , ignore1 = None , ignore2 = None ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Closing media chooser " )
2010-12-09 01:26:19 +03:00
self . topwin . hide ( )
2011-04-12 02:35:21 +04:00
if self . storage_browser :
self . storage_browser . close ( )
2007-09-22 00:28:31 +04:00
return 1
2011-04-14 16:47:42 +04:00
def show ( self , parent ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing media chooser " )
2008-09-09 15:35:20 +04:00
self . reset_state ( )
2011-04-14 16:47:42 +04:00
self . topwin . set_transient_for ( parent )
2012-01-25 19:38:42 +04:00
self . topwin . present ( )
2013-07-07 19:06:15 +04:00
self . conn . schedule_priority_tick ( pollnodedev = True , pollmedia = True )
2007-09-22 00:28:31 +04:00
2011-07-24 05:16:54 +04:00
def _cleanup ( self ) :
self . vm = None
self . conn = None
self . disk = None
2011-04-12 02:35:21 +04:00
2011-07-24 05:16:54 +04:00
if self . storage_browser :
self . storage_browser . cleanup ( )
self . storage_browser = None
2011-04-12 02:35:21 +04:00
2008-09-09 15:35:20 +04:00
def reset_state ( self ) :
2011-07-14 21:13:13 +04:00
cd_path = self . widget ( " cd-path " )
2009-11-30 20:51:25 +03:00
use_cdrom = ( cd_path . get_active ( ) > - 1 )
if use_cdrom :
2011-07-14 21:13:13 +04:00
self . widget ( " physical-media " ) . set_active ( True )
2008-09-09 15:35:20 +04:00
else :
2011-07-14 21:13:13 +04:00
self . widget ( " iso-image " ) . set_active ( True )
2008-09-09 15:35:20 +04:00
2010-11-29 22:06:43 +03:00
def ok ( self , ignore1 = None , ignore2 = None ) :
2009-07-02 20:43:08 +04:00
path = None
2011-07-14 21:13:13 +04:00
if self . widget ( " iso-image " ) . get_active ( ) :
path = self . widget ( " iso-path " ) . get_text ( )
2007-09-22 00:28:31 +04:00
else :
2011-07-14 21:13:13 +04:00
cd = self . widget ( " cd-path " )
2009-07-02 20:43:08 +04:00
idx = cd . get_active ( )
2007-09-22 00:28:31 +04:00
model = cd . get_model ( )
2009-07-02 20:43:08 +04:00
if idx != - 1 :
2009-12-01 00:25:39 +03:00
path = model [ idx ] [ uihelpers . OPTICAL_DEV_PATH ]
2007-11-29 01:58:19 +03:00
2012-11-08 17:15:02 +04:00
if path == " " or path is None :
2009-07-02 20:43:08 +04:00
return self . err . val_err ( _ ( " Invalid Media Path " ) ,
2008-03-14 20:18:44 +03:00
_ ( " A media path must be specified. " ) )
2007-11-29 01:58:19 +03:00
try :
2011-07-22 20:17:19 +04:00
self . disk . path = path
2007-11-29 01:58:19 +03:00
except Exception , e :
2011-08-30 22:50:50 +04:00
return self . err . val_err ( _ ( " Invalid Media Path " ) , e )
2009-07-02 20:43:08 +04:00
2013-07-09 17:20:43 +04:00
uihelpers . check_path_search_for_qemu ( self . err , self . conn , path )
2009-12-01 20:35:04 +03:00
2011-07-22 20:17:19 +04:00
self . emit ( " cdrom-chosen " , self . disk , path )
2011-03-21 18:01:39 +03:00
self . close ( )
2007-09-22 00:28:31 +04:00
def media_toggled ( self , ignore1 = None , ignore2 = None ) :
2011-07-14 21:13:13 +04:00
if self . widget ( " physical-media " ) . get_active ( ) :
self . widget ( " cd-path " ) . set_sensitive ( True )
self . widget ( " iso-path " ) . set_sensitive ( False )
self . widget ( " iso-file-chooser " ) . set_sensitive ( False )
2007-09-22 00:28:31 +04:00
else :
2011-07-14 21:13:13 +04:00
self . widget ( " cd-path " ) . set_sensitive ( False )
self . widget ( " iso-path " ) . set_sensitive ( True )
self . widget ( " iso-file-chooser " ) . set_sensitive ( True )
2007-09-22 00:28:31 +04:00
def change_cd_path ( self , ignore1 = None , ignore2 = None ) :
pass
def browse_fv_iso_location ( self , ignore1 = None , ignore2 = None ) :
2009-11-10 22:30:51 +03:00
self . _browse_file ( )
2007-09-22 00:28:31 +04:00
2009-07-02 20:43:08 +04:00
def initialize_opt_media ( self ) :
2011-07-14 21:13:13 +04:00
widget = self . widget ( " cd-path " )
warn = self . widget ( " cd-path-warn " )
2009-11-30 20:51:25 +03:00
2009-12-11 04:04:26 +03:00
error = self . conn . mediadev_error
uihelpers . init_mediadev_combo ( widget )
2009-12-14 22:52:52 +03:00
uihelpers . populate_mediadev_combo ( self . conn , widget , self . media_type )
2009-11-30 20:51:25 +03:00
if error :
warn . show ( )
2012-05-14 17:24:56 +04:00
warn . set_tooltip_text ( error )
2009-11-30 20:51:25 +03:00
else :
warn . hide ( )
2011-07-14 21:13:13 +04:00
self . widget ( " physical-media " ) . set_sensitive ( not bool ( error ) )
2008-09-09 15:35:20 +04:00
2009-12-14 22:52:52 +03:00
if self . media_type == MEDIA_FLOPPY :
2011-07-14 21:13:13 +04:00
self . widget ( " physical-media " ) . set_label ( _ ( " Floppy D_rive " ) )
self . widget ( " iso-image " ) . set_label ( _ ( " Floppy _Image " ) )
2009-12-14 22:52:52 +03:00
2010-12-09 19:22:35 +03:00
def set_storage_path ( self , src_ignore , path ) :
2011-07-14 21:13:13 +04:00
self . widget ( " iso-path " ) . set_text ( path )
2009-06-18 18:40:37 +04:00
2009-11-10 22:30:51 +03:00
def _browse_file ( self ) :
2012-11-08 17:15:02 +04:00
if self . storage_browser is None :
2010-12-09 01:26:19 +03:00
self . storage_browser = vmmStorageBrowser ( self . conn )
2009-06-18 18:40:37 +04:00
self . storage_browser . connect ( " storage-browse-finish " ,
self . set_storage_path )
2009-11-10 22:30:51 +03:00
2011-07-22 21:13:26 +04:00
rhel6 = self . vm . rhel6_defaults ( )
self . storage_browser . rhel6_defaults = rhel6
2011-07-22 20:22:09 +04:00
2011-07-23 03:12:48 +04:00
if self . media_type == MEDIA_FLOPPY :
self . storage_browser . set_browse_reason (
self . config . CONFIG_DIR_FLOPPY_MEDIA )
else :
self . storage_browser . set_browse_reason (
self . config . CONFIG_DIR_ISO_MEDIA )
2011-04-14 16:47:42 +04:00
self . storage_browser . show ( self . topwin , self . conn )