Module | VirtP2V::UI::Connect |
In: |
lib/virt-p2v/ui/connect.rb
lib/virt-p2v/ui/connect.rb |
UI_STATE_INVALID | = | 0 |
UI_STATE_VALID | = | 1 |
UI_STATE_ACTIVATING | = | 2 |
UI_STATE_COMPLETE | = | 3 |
EV_HOSTNAME | = | 0 |
EV_USERNAME | = | 1 |
EV_PASSWORD | = | 2 |
EV_BUTTON | = | 3 |
EV_ACTIVATION | = | 4 |
UI_STATE_INVALID | = | 0 |
UI_STATE_VALID | = | 1 |
UI_STATE_ACTIVATING | = | 2 |
UI_STATE_COMPLETE | = | 3 |
EV_HOSTNAME | = | 0 |
EV_USERNAME | = | 1 |
EV_PASSWORD | = | 2 |
EV_BUTTON | = | 3 |
EV_ACTIVATION | = | 4 |
# File lib/virt-p2v/ui/connect.rb, line 142 142: def self.connect_button_clicked 143: event(EV_BUTTON, true) 144: 145: hostname = @hostname_ui.text.strip 146: username = @username_ui.text.strip 147: password = @password_ui.text 148: connection = VirtP2V::Connection.new(hostname, username, password) \ 149: { |result| 150: case result 151: when true 152: @converter.connection = connection 153: connection.connect { |result| 154: case result 155: when true 156: event(EV_ACTIVATION, true) 157: when VirtP2V::Connection::RemoteError 158: @connect_error.text = _('Failed to start ' + 159: 'virt-p2v-server on remote ' + 160: 'server') 161: event(EV_ACTIVATION, false) 162: else 163: @connect_error.text = result.message 164: event(EV_ACTIVATION, false) 165: end 166: } 167: when VirtP2V::Connection::InvalidHostnameError 168: @connect_error.text = _"Unable to connect to #{hostname}" 169: event(EV_ACTIVATION, false) 170: when VirtP2V::Connection::InvalidCredentialsError 171: @connect_error.text = _"Invalid username/password" 172: event(EV_ACTIVATION, false) 173: else 174: raise result 175: end 176: } 177: end
# File lib/virt-p2v/ui/connect.rb, line 142 142: def self.connect_button_clicked 143: event(EV_BUTTON, true) 144: 145: hostname = @hostname_ui.text.strip 146: username = @username_ui.text.strip 147: password = @password_ui.text 148: connection = VirtP2V::Connection.new(hostname, username, password) \ 149: { |result| 150: case result 151: when true 152: @converter.connection = connection 153: connection.connect { |result| 154: case result 155: when true 156: event(EV_ACTIVATION, true) 157: when VirtP2V::Connection::RemoteError 158: @connect_error.text = _('Failed to start ' + 159: 'virt-p2v-server on remote ' + 160: 'server') 161: event(EV_ACTIVATION, false) 162: else 163: @connect_error.text = result.message 164: event(EV_ACTIVATION, false) 165: end 166: } 167: when VirtP2V::Connection::InvalidHostnameError 168: @connect_error.text = _"Unable to connect to #{hostname}" 169: event(EV_ACTIVATION, false) 170: when VirtP2V::Connection::InvalidCredentialsError 171: @connect_error.text = _"Invalid username/password" 172: event(EV_ACTIVATION, false) 173: else 174: raise result 175: end 176: } 177: end
# File lib/virt-p2v/ui/connect.rb, line 36 36: def self.event(event, status) 37: case event 38: when EV_HOSTNAME 39: @hostname = status 40: when EV_USERNAME 41: @username = status 42: when EV_PASSWORD 43: @password = status 44: when EV_BUTTON, EV_ACTIVATION 45: # Persistent state not required 46: else 47: raise "Unexpected event: #{event}" 48: end 49: 50: valid = @hostname && @username && @password 51: 52: case @state 53: when UI_STATE_INVALID 54: set_state(UI_STATE_VALID) if valid 55: when UI_STATE_VALID 56: if !valid then 57: set_state(UI_STATE_INVALID) 58: elsif event == EV_BUTTON 59: set_state(UI_STATE_ACTIVATING) 60: end 61: when UI_STATE_ACTIVATING 62: # UI is disabled, so we shouldn't be getting any events other than 63: # EV_ACTIVATION 64: raise "Unexpected event: #{event}" unless event == EV_ACTIVATION 65: 66: set_state(status ? UI_STATE_COMPLETE : UI_STATE_VALID) 67: else 68: raise "Unexpected UI state: #{@state}" 69: end 70: end
# File lib/virt-p2v/ui/connect.rb, line 36 36: def self.event(event, status) 37: case event 38: when EV_HOSTNAME 39: @hostname = status 40: when EV_USERNAME 41: @username = status 42: when EV_PASSWORD 43: @password = status 44: when EV_BUTTON, EV_ACTIVATION 45: # Persistent state not required 46: else 47: raise "Unexpected event: #{event}" 48: end 49: 50: valid = @hostname && @username && @password 51: 52: case @state 53: when UI_STATE_INVALID 54: set_state(UI_STATE_VALID) if valid 55: when UI_STATE_VALID 56: if !valid then 57: set_state(UI_STATE_INVALID) 58: elsif event == EV_BUTTON 59: set_state(UI_STATE_ACTIVATING) 60: end 61: when UI_STATE_ACTIVATING 62: # UI is disabled, so we shouldn't be getting any events other than 63: # EV_ACTIVATION 64: raise "Unexpected event: #{event}" unless event == EV_ACTIVATION 65: 66: set_state(status ? UI_STATE_COMPLETE : UI_STATE_VALID) 67: else 68: raise "Unexpected UI state: #{@state}" 69: end 70: end
# File lib/virt-p2v/ui/connect.rb, line 72 72: def self.init(ui, converter) 73: @hostname_ui = ui.get_object('server_hostname') 74: @username_ui = ui.get_object('server_username') 75: @password_ui = ui.get_object('server_password') 76: @connect_frame = ui.get_object('connect_frame') 77: @connect_button = ui.get_object('connect_button') 78: @connect_error = ui.get_object('connect_error') 79: 80: ui.register_handler('server_hostname_changed', 81: method(:server_hostname_changed)) 82: ui.register_handler('server_username_changed', 83: method(:server_username_changed)) 84: ui.register_handler('server_password_changed', 85: method(:server_password_changed)) 86: ui.register_handler('connect_button_clicked', 87: method(:connect_button_clicked)) 88: 89: @hostname = @hostname_ui.text.strip.length > 0 90: @username = @username_ui.text.strip.length > 0 91: @password = @password_ui.text.length > 0 # Allow spaces in passwords 92: @state = UI_STATE_INVALID 93: 94: @ui = ui 95: @converter = converter 96: end
# File lib/virt-p2v/ui/connect.rb, line 72 72: def self.init(ui, converter) 73: @hostname_ui = ui.get_object('server_hostname') 74: @username_ui = ui.get_object('server_username') 75: @password_ui = ui.get_object('server_password') 76: @connect_frame = ui.get_object('connect_frame') 77: @connect_button = ui.get_object('connect_button') 78: @connect_error = ui.get_object('connect_error') 79: 80: ui.register_handler('server_hostname_changed', 81: method(:server_hostname_changed)) 82: ui.register_handler('server_username_changed', 83: method(:server_username_changed)) 84: ui.register_handler('server_password_changed', 85: method(:server_password_changed)) 86: ui.register_handler('connect_button_clicked', 87: method(:connect_button_clicked)) 88: 89: @hostname = @hostname_ui.text.strip.length > 0 90: @username = @username_ui.text.strip.length > 0 91: @password = @password_ui.text.length > 0 # Allow spaces in passwords 92: @state = UI_STATE_INVALID 93: 94: @ui = ui 95: @converter = converter 96: end
# File lib/virt-p2v/ui/connect.rb, line 130 130: def self.server_hostname_changed 131: event(EV_HOSTNAME, @hostname_ui.text.strip.length > 0) 132: end
# File lib/virt-p2v/ui/connect.rb, line 130 130: def self.server_hostname_changed 131: event(EV_HOSTNAME, @hostname_ui.text.strip.length > 0) 132: end
# File lib/virt-p2v/ui/connect.rb, line 138 138: def self.server_password_changed 139: event(EV_PASSWORD, @password_ui.text.length > 0) 140: end
# File lib/virt-p2v/ui/connect.rb, line 138 138: def self.server_password_changed 139: event(EV_PASSWORD, @password_ui.text.length > 0) 140: end
# File lib/virt-p2v/ui/connect.rb, line 134 134: def self.server_username_changed 135: event(EV_USERNAME, @username_ui.text.strip.length > 0) 136: end
# File lib/virt-p2v/ui/connect.rb, line 134 134: def self.server_username_changed 135: event(EV_USERNAME, @username_ui.text.strip.length > 0) 136: end
# File lib/virt-p2v/ui/connect.rb, line 98 98: def self.set_state(state) 99: # Don't do anything if state hasn't changed 100: return if state == @state 101: 102: case state 103: when UI_STATE_INVALID 104: @connect_frame.sensitive = true 105: @connect_button.sensitive = false 106: 107: @state = UI_STATE_INVALID 108: when UI_STATE_VALID 109: @connect_frame.sensitive = true 110: @connect_button.sensitive = true 111: 112: @state = UI_STATE_VALID 113: when UI_STATE_ACTIVATING 114: @connect_frame.sensitive = false 115: @connect_button.sensitive = false 116: @connect_error.text = '' 117: 118: @state = UI_STATE_ACTIVATING 119: when UI_STATE_COMPLETE 120: # Activate the next page 121: @ui.active_page = 'conversion_win' 122: 123: # ... then leave this one as we hope to find it if we come back here 124: set_state(UI_STATE_VALID) 125: else 126: raise "Attempt to set unexpected UI state: #{@state}" 127: end 128: end
# File lib/virt-p2v/ui/connect.rb, line 98 98: def self.set_state(state) 99: # Don't do anything if state hasn't changed 100: return if state == @state 101: 102: case state 103: when UI_STATE_INVALID 104: @connect_frame.sensitive = true 105: @connect_button.sensitive = false 106: 107: @state = UI_STATE_INVALID 108: when UI_STATE_VALID 109: @connect_frame.sensitive = true 110: @connect_button.sensitive = true 111: 112: @state = UI_STATE_VALID 113: when UI_STATE_ACTIVATING 114: @connect_frame.sensitive = false 115: @connect_button.sensitive = false 116: @connect_error.text = '' 117: 118: @state = UI_STATE_ACTIVATING 119: when UI_STATE_COMPLETE 120: # Activate the next page 121: @ui.active_page = 'conversion_win' 122: 123: # ... then leave this one as we hope to find it if we come back here 124: set_state(UI_STATE_VALID) 125: else 126: raise "Attempt to set unexpected UI state: #{@state}" 127: end 128: end