Newer
Older
Import / projects / LGN-IP3870 / t / orig / configuration.py
# -*- coding: utf-8 -*-

import baseui, ui, config, uiconfig, os #########ka...wizard YesNoStage
from basemodel import Stage, EntryStage, NotifyStage, GaugeStage, ListStage, YesNoStage, SymbolSelectionStage
from phonesetting import AutoRegisteringStage
from model import IdleStage
import runtime
from setting import setting
from vdcisetting import vdci_setting

import time, ntptime, status, utils
from roxiadebug import *

from profile import profile, lan_profile, wifi_profile, dns_profile

dspg = runtime.dspg



class ConfigAssistantStage(ListStage):
	icon = uiconfig.profile_icon
	name = 'config assistant'
	profile_setting = 0 # default=Ethernet
	def __init__(self):
		self.title = _('CONFIG ASSISTANT')
		self.choice = (_('Service config'), _('Connection config'))
		ListStage.__init__(self)
		
	def activate(self, index):
		if index == 0:
			stage = ServiceConfigStage
		elif index == 1:
			stage = ConnectionSelectStage
		else:
			pass
			#assert False
		runtime.manager.stack_stage(stage)






class InitDirectionStage(Stage):
	name = "InitDirectionStage"
	def __init__(self):
		roxia_event('InitDirectionStage.__init__()')
#		font = uiconfig.calllog_details_font
#		self.ui = baseui.RichTextUI( _('OK'), _('BACK'), '',  _('Config Assistant'), text_font = font)
		msg1 = _('Welcome to the Assistant of configuration.')+'\n'
		msg2 = _('If you don\'t have Videotelephony Service,')+' '
		msg3 = _('please get in touch with Telefonica')+': '+ _('call to 1004')+ '\n'
		msg = msg1 + msg2 + msg3
# ka...wizard ---long sentance overlapping solution
#		msgtr = runtime.evas.text(text = msg)
#		msgtr1 = msgtr.text_get()
#		self.ui.set_text(msgtr1)		

		self.ui = baseui.LargeWindowMessageUI(_('OK'),  _('EXIT'),  _('CONFIG ASSISTANT'), msg,  '')


	def handle_key(self, key):
		if key == config.Menu2:
			def cancel():
				runtime.manager.back_stage()
			stage = NotifyStage(_('Configuration assistant cancelled.'), uiconfig.baloon_setting_voip_icon, cb=cancel)
			runtime.manager.change_stage(stage)
			return True
		elif key == config.Menu1:
			runtime.manager.change_stage(ServiceConfigStage)
#			return self.ui.handle_key(key)
		else:	
			return False


class ServiceConfigStage(Stage):
	name = "serviceconfig start"
	def __init__(self):
		roxia_event('ServiceConfigStage.__init__()')
		msg = _('This assistant will help you to make the configuration of Videotelephony Service')
		self.ui = baseui.LargeWindowMessageUI(_('OK'),  _('EXIT'),  _('SERVICE CONFIG'), msg,  '')
		self.depth = 0

	def handle_key(self, key):
	#ka...wizard 2007.04.16
		from vdcisetting import vdci_setting
		from menu import VoIPEditor
		
		if key == config.Menu2:
			self.depth -= 1
			runtime.manager.back_stage()
			return True
		elif key == config.Menu1 and self.depth == 0:
			self.depth += 1
			tel_num = vdci_setting.tel_num
			stage = VoIPEditor(_('TELEPHONE NUMBER'), _('Telephone num.'), self.telephonenumber_cb, text=tel_num, textmax=50)
			runtime.manager.stack_stage(stage)
		elif  key == config.Menu1 and self.depth == 1:
			self.depth += 1
			auth_pwd = vdci_setting.auth_pwd
			stage = VoIPEditor(_('AUTHENTICATION'), _('Auth. pwd'), self.authpwd_cb, text=auth_pwd, textmax=50)
			runtime.manager.stack_stage(stage)
		else:	
			return False


	def telephonenumber_cb(self, ui):
		from vdcisetting import vdci_setting
		from menu import VoIPSettingNotifyStage

		text = ui.get_text()
		if len(text) == 0:
			runtime.manager.stack_stage(VoIPSettingNotifyStage(_('No text inserted.')))
		else:
#			check_voip_change(vdci_setting.tel_num, text)
			vdci_setting.set_tel_num(text)
			runtime.manager.stack_stage(VoIPSettingNotifyStage(_('Telephone number set'), self.cb1))

	def cb1(self):
		from menu import VoIPEditor
		from vdcisetting import vdci_setting
		auth_pwd = vdci_setting.auth_pwd
		stage = VoIPEditor(_('AUTHENTICATION'), _('Auth. pwd'), self.authpwd_cb, text=auth_pwd, textmax=50)
		runtime.manager.change_stage(stage)


	def authpwd_cb(self, ui):
		from vdcisetting import vdci_setting
		from menu import VoIPSettingNotifyStage
		text = ui.get_text()
	#	check_voip_change(vdci_setting.auth_pwd, text)
		vdci_setting.set_auth_pwd(text)

		if len(text) == 0:
			runtime.manager.change_stage(VoIPSettingNotifyStage(_('Authentication pwd deleted')))
		else:
			runtime.manager.stack_stage(VoIPSettingNotifyStage(_('Authentication pwd set'), self.cb2))

	def cb2(self):
		runtime.manager.change_stage(ServiceConfig2Stage)

	def show(self):
		Stage.show(self)
		self.depth = 0
		

class ServiceConfig2Stage(Stage):
	name = "serviceconfig end"
	def __init__(self):
		roxia_event('ServiceConfig2Stage.__init__()')
#		font = uiconfig.calllog_details_font
#		self.ui = baseui.RichTextUI( _('OK'), _('BACK'), '',  _('Config Assistant'), text_font = font)
		msg1 = _('The configuration of the Videotelephony Service has finished successfully.')+'\n'
		msg2 = _('If you want to the Videophone connection,')+' '
		msg3 = _('press OK.')
		msg = msg1 + msg2 + msg3
# ka...wizard ---long sentance overlapping solution
#		msgtr = runtime.evas.text(text = msg)
#		msgtr1 = msgtr.text_get()
#		self.ui.set_text(msgtr1)		

		self.ui = baseui.LargeWindowMessageUI(_('OK'),  _('FINISH'),  _('SERVICE CONFIG'), msg,  '')


	def handle_key(self, key):
		# 메뉴에서 실행한 Service config는 여기서 종료
		if key in (config.Menu1, config.Menu2, config.Red):
			if runtime.manager.find_stage('config assistant'):
				runtime.manager.back_stage('config assistant')
				return
		if key == config.Menu2:
			runtime.manager.change_stage(IdleStage)
			return True
		elif key == config.Menu1:
			runtime.manager.change_stage(ConnectionSelectStage, True)
		else:	
			return False


	'''
class ConnectionConfigStage(Stage):
	name = "connection config"
	def __init__(self):
		roxia_event('ConnectionConfigStage.__init__()')
		msg = _('You can connect your videophone to the TELEFONICA NETWORK by means of Ethernet or WiFi.')
		self.ui = baseui.LargeWindowMessageUI(_('OK'),  _('EXIT'),  _('Connection Config'), msg,  '')

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.stack_stage(ConnectionSelectStage)
		elif key == config.Menu2:
			runtime.manager.back_stage()
		else:	
			return False
	'''


# ka...wizard connection config Start !!!
class ConnectionSelectStage(Stage):
	name = "connection select"
	def __init__(self):
		roxia_event('ConnectionSelectStage.__init__()')
		msg = _('You can connect your videophone to the TELEFONICA NETWORK by means of Ethernet or WiFi.')
		self.ui = baseui.LargeWindowMessageUI(_('OK'),  _('EXIT'),  _('CONNECTION CONFIG'), msg,  '')

	def handle_key(self, key):
		if key == config.Menu2:
			def cancel():
				runtime.manager.back_stage()
			stage = NotifyStage(_('Configuration assistant cancelled.'), uiconfig.baloon_setting_voip_icon, cb=cancel)
			runtime.manager.change_stage(stage)
			return True
		elif key == config.Menu1:
			runtime.manager.stack_stage(SelectProfileStage)
			return True
		else:	
			return False


class SelectProfileStage(ListStage):
	icon = uiconfig.profile_icon
	name = 'select profile'
	profile_setting = 0 # default=Ethernet

	
	def __init__(self):
		self.title = _('PROFILE')
		self.choice = (_('Wired(Ethernet)'), _('Wireless(WiFi)'))
		from profile import profile
		ListStage.__init__(self)
		profile_setting = profile.get_profile()-1
		self.ui.set_focus(profile_setting) # update to setting.profile
		
	def activate(self, index):
		from profile import profile
		self.profile_setting = profile.get_profile()-1
		old_profile_name = ( _('LAN'), _('WiFi'))[self.profile_setting]
		new_profile_name = (_('LAN'), _('WiFi'))[index]
		roxia_tracef('old_profile=%s, new_profile=%s', old_profile_name, new_profile_name)
		self.profile = index+1
		self.old_profile_name = old_profile_name
		self.profile_name  = new_profile_name
		
		if old_profile_name != new_profile_name:
			runtime.manager.change_stage(NotifyStage(_('Profile changing...'), uiconfig.baloon_profile_setting_icon,isred=False)) 
			runtime.evas.render_now()
			self.change_profile_cb()
		else:
			self.next_stage()

#ka...3800 2007.03.26
	def next_stage(self):
		
		if self.profile == 1: # LAN
			profile.set_profile(1)
			stage = ConfigPicture1Stage
		else: #self.profile == 2: # WiFi
			profile.set_profile(2)
			stage = ConfigPicture3Stage
			
		runtime.manager.change_stage(stage)


	def change_profile_cb(self):
		status.telnum = '' # profile변경을 시작하면 무조건 번호초기화함
		profile.set_profile(self.profile)

		global cur_profile
		if self.profile_name == _('LAN'):
			cur_profile = lan_profile
			message = _('LAN profile enabled.')
			runtime.manager.show_lan_disconnected = False
		else:
			cur_profile = wifi_profile
			message = _('WiFi profile enabled.')
			runtime.manager.show_lan_disconnected = False

		status.profile_detail_changed = False
		runtime.manager.dhcp_timer_kill()
		
########################
######################## eicho 06.07.04 

		#runtime.manager.kill_check_dhcp_res()

		if self.profile == 1: # change LAN profile..
			status.profile_detail_changed = False
			# WiFi -> LAN
			runtime.manager.vdci_deregister_kill()
			status.set_regstatus(0)
			os.system('wlstop')
			roxia_trace( '### profile change: WiFi --> LAN ###')

			#runtime.manager.start_dhcpclient_LAN()  -> 이거 자동 register하므로 사용 안하고,,,
			time.sleep(2)
			os.system('eth0_start')	#dhcp enable이면 돌고 disable인 경우 안돈다. 

			stage = NotifyStage(message, uiconfig.baloon_profile_setting_icon, self.next_stage, isred=False)
			runtime.manager.change_stage(stage)
#			runtime.evas.render_now()
	
				
		elif self.profile == 2: # change WiFi profile..
			#runtime.manager.change_stage(NotifyStage(_('Profile changing...'), uiconfig.baloon_profile_setting_icon, isred=False))
			# LAN -> WiFi
			roxia_trace('> chaging profile: LAN to WiFi -----  STOP LAN')
			runtime.manager.vdci_deregister_kill()
			status.set_regstatus(0)
			os.system('eth0_stop')
			time.sleep(4)
			os.system('wlstart NODHCP') # ka...3800 ESSID가 없으면 dhcpcd돌지 않는다. 
							 		# ESSID 가 존재하더라도 dhcpcd돌지 않도록 !!
#Roxia Begin smyook 06.07.06
#			if wifi_profile.essid == '':
#				runtime.manager.run_scanning_AP()
#				return

#ka...3800 DHCP는 ESSID를 선택하지 않은 상태에선 하지 않도록
#			if wifi_profile.dhcp == 'yes':
#				if os.path.exists('/tmp/dhcpcd-wlan0.info') == False:
#					import phonesetting
#					runtime.manager.dhcp_timer = utils.Timer(config.dhcp_min, phonesetting.dhcp_client2)
#				else:
#					roxia_trace('## dhcp==yes/ call ifconfig_run(wifi)')
#					runtime.manager.ifconfig_run('wifi')
#					dns_profile.dhcp_save()
#					#07.09 runtime.manager.start_vdciapp()
#			else:
#				roxia_trace('## dhcp==NO : call dns_profile.save')
#				dns_profile.save()
#				runtime.manager.start_vdciapp()

#		stage = NotifyStage(message, uiconfig.baloon_profile_setting_icon, cb=do_autoregister, isred=False)
		stage = NotifyStage(message, uiconfig.baloon_profile_setting_icon, self.next_stage, isred=False)
		runtime.manager.change_stage(stage)
#		runtime.evas.render_now()
		

class ConfigPicture1Stage(Stage):
	name = 'config picture1'
	def __init__(self):
		self.ui = ui.ConfigPictureUI(_('OK'), _('BACK'), _('CONNECTION CONFIG'), image_num=0)
#		pos = uiconfig.connection_pos
#		self.bar = utils.put_image(uiconfig.connection_config_1, pos)
#		self.posx = pos[0]
#		self.posy = pos[1]
#		self.add(self.bar)

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.stack_stage(ConfigPicture2Stage)
		elif key == config.Menu2:
			runtime.manager.back_stage()
		else:	
			return False
		return True


class ConfigPicture2Stage(Stage):
	name = 'config picture2'
	def __init__(self):
		self.ui = ui.ConfigPictureUI(_('OK'), _('BACK'), _('CONNECTION CONFIG'), image_num=1)

	def success_cb(self):
		# registering
		self.check_dhcp()
#		stage = ConfigSuccessStage
#		runtime.manager.change_stage(stage, True)

	def fail_cb(self):
		stage = ConfigRetryStage
		runtime.manager.change_stage(stage)

	def cb(self):
		roxia_trace('Check link status...')
		runtime.check_lanlink() # 부팅시 lan link 체크와 동일하게 한다. 실제 profilechange의 경우 무조건 진행하는 반면,,, 
# 1. physical connection check
# 2-1. dhcp success check
# 2-2. static ip check

		if status.LanConnected == True:
			if lan_profile.dhcp == 'yes':
				if os.path.exists('/tmp/dhcpcd-eth0.info') == True:
					stage = NotifyStage(_('Wired (Ethernet) connection set'), uiconfig.baloon_setting_voip_icon, self.success_cb)
					runtime.manager.change_stage(stage)
					return True
				else:
					print 'ka.............dhcp fail'
			else:
				stage = NotifyStage(_('Wired (Ethernet) connection set'), uiconfig.baloon_setting_voip_icon, self.success_cb)
				runtime.manager.change_stage(stage)
				return True
		else:
			print 'ka.............Lan Link down'
			
		stage = NotifyStage(_('Wired (Ethernet) connection failure'), uiconfig.baloon_setting_voip_icon, self.fail_cb)
		runtime.manager.change_stage(stage)
		return True

	def handle_key(self, key):
		if key == config.Menu1:
			stage = NotifyStage(_('Please wait, the connection is being established...'), uiconfig.baloon_setting_voip_icon, self.cb)
			runtime.manager.change_stage(stage)

		elif key == config.Menu2:
			runtime.manager.back_stage()
		else:	
			return False
			
		return True

	def check_dhcp(self):
		if lan_profile.dhcp == 'yes':
			##############################ALREAY DHCP SUCCESS
			#runtime.manager.kill_check_dhcp_res()
			runtime.manager.dhcp_timer_kill()
			#runtime.manager.ifconfig_run()
			dns_profile.dhcp_save()
			runtime.manager.network_initialized = True
			status.LanConnected = True	# for change icon.
			#self.after_dhcp_succ()
			self.registering()
		else:
			dns_profile.save()
			runtime.manager.network_initialized = True
			status.LanConnected = True	# for change icon.
			#self.after_dhcp_succ()
			self.registering()
			
		#runtime.manager.dhcp_check_count = 0
		return False


	def registering(self):
#		from vdcisetting import vdci_setting
#		runtime.manager.register_in_boot()				
#		stage = RegisteringIdleStage()
#		runtime.manager.stack_stage(stage)
		runtime.manager.change_stage(ConfigAutoRegisteringStage, True)

## start download process...
		if config.enable_sac3 :
			runtime.manager.start_sac3_timer()

# eicho 06.07.04
		if config.NTP_CODE_ENABLE and runtime.manager.network_initialized:
			runtime.manager.ntp_run()
			
		#runtime.manager.boot_start_processor = False


#phonesetting.AutoRegisteringStage
class ConfigAutoRegisteringStage(Stage):
	name = "config autoregistering"
	def __init__(self, dereg_first=True):
		status.supervision_not_allowed = 1
		import ui
		from vdcisetting import vdci_setting

		self.try_register = True
		self.reg_message = _('Registering.')+'\n'+_('Please wait for a moment.')

		prof_current = profile.get_profile()
		if  prof_current == 1:
## eicho 06.07.10
			roxia_trace( '#### before check_lanlink status.LanConnected -', status.LanConnected)
			# start shchun: remove status.on_profile_changing
			#if not status.on_profile_changing:
			#	runtime.check_lanlink()
			runtime.check_lanlink()
			roxia_trace( '#### after check_lanlink status.LanConnected -', status.LanConnected)
				
		if not vdci_setting.tel_num:
			self.try_register = False
			self.reg_message = _('The telephone number of VoIP is not formed.')
		elif (prof_current == 1 and status.LanConnected == False) or \
			(prof_current == 2 and ui.check_wifi_connection() == False):
			self.try_register = False
			self.reg_message = _('Check network connection')

		status.set_register_mode(status.Registering)
		
		self.ui = ui.VideoCallRegisteringUI(False, reg=self.try_register, msg=self.reg_message)
		self.tag_register = None
		self.back_timer = None
		status.videocall_dimension = setting.video_dimension
		if dereg_first:
			self.request_autoregister()
		else:
			self.automatic_register()

	def handle_key(self, key):
		if key == config.Menu2:
			if self.try_register == False:
				return False
			if status.get_register_mode() != status.Registering:
				return False

			self.deregister_cancel()
			return True
		elif key == config.OnHook:
			if status.get_register_mode() != status.Registering:
				return False

			if status.modem_audio_state == status.HS:
				self.deregister_cancel()
			else:
				pass

		elif key == config.Red:
			if self.try_register == False:
				return False
			#if status.registered_status != status.Registering:
			#	return False

			if status.modem_audio_state == status.SPK:
				self.deregister_cancel()
			else:
				pass

		return False


	# automatic register..  after de-registered
	def automatic_register(self):
		roxia_trace('[R] configautomatic register. after de-registered')
		self.tag_register = None

		if self.try_register == False:
			vdci_reload()
			def back_stage():
				runtime.manager.back_stage()
				return True
			self.back_timer = utils.Timer(2000, back_stage)
			return

		runtime.manager.change_stage(RegisteringStage)

	def request_autoregister(self):
		if runtime.vdciapp:
			runtime.vdciapp.req_deregister()
		self.tag_register = utils.Timer(config.timeoutDeregister, self.deregister_failed)
		return False

	def deregister_sucessed(self):
		roxia_trace('[R] ConfigAutoRegisteringStage.deregister_sucessed()')
		self.tag_register = None
		
		status.set_register_mode(status.NotRegistered)
		status.set_regstatus(0)
		self.automatic_register()

	def register_sucessed(self):
		roxia_trace('[R] ConfigAutoRegisteringStage.register_sucessed()')
		self.tag_register = None
		
		status.set_register_mode(status.Registered)
		if profile.get_profile() == 1: # lan
			status.LanConnected = True

		status.set_regstatus(1)

		message = _('Registration succeeded')
		def cb():
			print 'ka....................cb'
			stage = ConfigSuccessStage
			runtime.manager.change_stage(stage)
		import menu
		print 'ka.......................succ'
		from menu import VoIPSettingNotifyStage
		stage = VoIPSettingNotifyStage(message, cb)
		runtime.manager.change_stage(stage)

	def deregister_failed(self):
		roxia_trace('[R] ConfigAutoRegisteringStage.deregister_failed()')
		self.tag_register = None

		if status.get_register_mode() != status.Registering:
			return

		status.set_register_mode(status.NotRegistered)
		status.set_regstatus(0)
		self.automatic_register()

	def deregister_cancel(self):
		roxia_trace('[R] ConfigAutoRegisteringStage.deregister_cancel()')
		self.tag_register = None

		if status.get_register_mode() != status.Registering:
			return

		message = _('Registration cancelled')
		from menu import VoIPSettingNotifyStage
		stage = VoIPSettingNotifyStage(message)
		runtime.manager.change_stage(stage)

	def deregister_error(self):
		roxia_trace('[R] ConfigAutoRegisteringStage.deregister_error()')
		temp_mode = status.get_register_mode()
		self.tag_register = None

		status.set_register_mode(status.NotRegistered)
		status.set_regstatus(0)

		if temp_mode != status.Registering:
			return

		message = _('Registration failed')

		from menu import VoIPSettingNotifyStage
		stage = VoIPSettingNotifyStage(message)
		runtime.manager.change_stage(stage)

	def destroy(self):
		self.tag_register = None
		Stage.destroy(self)
		status.supervision_not_allowed = 0


class RegisteringStage(Stage):
	name = "configregistering"
	def __init__(self):
		status.supervision_not_allowed = 1
		status.set_register_mode(status.Registering)
		
		import ui
		self.ui = ui.VideoCallRegisteringUI(False)
		self.tag_register = None
		status.videocall_dimension = setting.video_dimension

		def do_reload():
			import phonesetting
			phonesetting.vdci_reload()
			return False

		self.reload_tag = utils.Timer(500, do_reload)

		self.tag_register = utils.Timer(config.timeoutRegister, self.register_failed)

	def handle_key(self, key):
		if key == config.Menu2:
			if status.get_register_mode() != status.Registering:
			
				roxia_trace('** ignore END key while registering.. **')
				return False

			self.register_cancel()
			return True

		elif key == config.OnHook:
			if status.get_register_mode() != status.Registering:
				return False

			if status.modem_audio_state == status.HS:
				self.register_cancel()
			else:
				pass

		elif key == config.Red:
			#if status.registered_status != status.Registering:
			if status.get_register_mode() != status.Registering:
			
				return False

			if status.modem_audio_state == status.SPK:
				self.register_cancel()
			else:
				pass

		return False

	def register_sucessed(self):
		roxia_trace('RegisteringStage.register_sucessed()')
		self.tag_register = None
		status.set_register_mode(status.Registered)

		import profile
		if profile.profile.get_profile() == 1: # lan
			status.LanConnected = True
		message = _('Registration succeeded')
		
		status.set_regstatus(1)

		def cb():
			print 'ka..........3..........cb'
			stage = ConfigSuccessStage
			runtime.manager.change_stage(stage)
			return

		from menu import VoIPSettingNotifyStage
		print 'ka....................3...succ'
		stage = VoIPSettingNotifyStage(message, cb)

		runtime.manager.change_stage(stage)


	def register_failed(self, msg=None):
		roxia_trace('************ config register_failed() *********')
		self.tag_register = None

		status.set_register_mode(status.NotRegistered)
		status.set_regstatus(0)
		#RegistrationStage.ch_choice
		if not msg:
			msg = _('Registration failed')
#Roxia Begin smyook 06.03.16
		status.critical_entered = True
		
		def cb():
			runtime.manager.change_stage(IdleStage, True)
			return
	
		from menu import VoIPSettingNotifyStage
		stage = VoIPSettingNotifyStage(msg, cb)
#Roixa End smyook
		runtime.manager.change_stage(stage)

	def register_cancel(self):
		roxia_trace('************ config register_calcel() **********')
		self.tag_register = None
		
		status.set_register_mode(status.NotRegistered)
		message = _('Registration cancelled')
		from menu import VoIPSettingNotifyStage
		stage = VoIPSettingNotifyStage(message)
		runtime.manager.change_stage(stage)

	def register_error(self):
		roxia_trace('************ config register_error() **********')
		temp_mode = status.get_register_mode()

		status.set_register_mode(status.NotRegistered)
		self.tag_register = None

		if temp_mode != status.Registering:
			return

		message = _('register failed')
		from menu import VoIPSettingNotifyStage
		stage = VoIPSettingNotifyStage(message)
		runtime.manager.change_stage(stage)

	def destroy(self):
		self.tag_register = None
		Stage.destroy(self)
		status.supervision_not_allowed = 0



class ConfigSuccessStage(Stage):
	name = "connection success"
	def __init__(self):
		msg1 = _('Your videophone has been configured successfully.')+'\n'
		msg2 = _('You can make video calls and audio calls whenever you wish.')
		msg = msg1 + msg2

		self.ui = baseui.LargeWindowMessageUI(_('OK'), '',  _('CONNECTION CONFIG'), msg,  '')


	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.change_stage(IdleStage)
		else:	
			return False


	def registering(self):
#		from vdcisetting import vdci_setting
#		runtime.manager.register_in_boot()				
#		stage = RegisteringIdleStage()
#		runtime.manager.stack_stage(stage)
		runtime.manager.change_stage(AutoRegisteringStage, True)

## start download process...
		if config.enable_sac3 :
			runtime.manager.start_sac3_timer()

# eicho 06.07.04
		if config.NTP_CODE_ENABLE and runtime.manager.network_initialized:
			runtime.manager.ntp_run()
			
		#runtime.manager.boot_start_processor = False


class ConfigRetryStage(Stage):
	name = "connection retry"
	def __init__(self):
		icon = uiconfig.baloon_setting_voip_icon
		msg1 = _('Please, check your Ethernet Cable connection properly and Modem Router is switched on.')+'\n'
		msg2 = _('If the problem persists, verify that the DHCP of your router is enabled.')
		msg = msg1 + msg2
		self.ui = baseui.LargeWindowMessageUI(_('RETRY'), _('BACK'),  _('CONNECTION CONFIG'), msg,  '')

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.back_stage('config picture1')
		elif key == config.Menu2:
			runtime.manager.back_stage('select profile')	
		else:	
			return False



#ka...wizard wifi connetion config
class ConfigPicture3Stage(Stage):
	name = 'config picture3'
	def __init__(self):
		self.ui = ui.ConfigPictureUI(_('OK'), _('BACK'), _('CONNECTION CONFIG'), image_num=2)

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.stack_stage(ConfigWiFiStage)
		elif key == config.Menu2:
			runtime.manager.back_stage()
		else:	
			return False
		return True


class ConfigWiFiStage(Stage):
	name = "wifi choice"
	def __init__(self):
		msg1 = _('You can identify the access point where you want to connect by two ways')+':'+'\n'
		msg2 = '1. ' + _('Make an automatic search') + '\n'
		msg3 = '2. ' + _('Introduce manually the data of the access point')
		msg = msg1 + msg2 + msg3

		self.ui = baseui.LargeWindowMessageUI(_('FIND'), _('MANUAL'),  _('CONNECTION CONFIG'), msg,  '')
	

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.evas.timeout_add(1000, self.run_scanning_AP)
		elif key == config.Menu2:
			runtime.manager.stack_stage(WifiManualStage)
		else:	
			return False

	def run_scanning_AP(self):
		#runtime.evas.timeout_add(500, self.run_scanning_AP)
		# ESSID가 없으면 scanning 화면으로 넘어간다.					
#		if profile.wifi_profile.essid == '' :				
		def cb():
			runtime.manager.change_stage(ConfigWfScan())
		import uiconfig
		stage = NotifyStage(_('Please wait, searching for wireless network.'), uiconfig.baloon_wifi_icon, cb, 500)
		runtime.manager.stack_stage(stage)	

	def destroy(self):
		if os.path.exists('/tmp/console_scan_inuse'):
			os.unlink('/tmp/console_scan_inuse')
		Stage.destroy(self)

	

class WifiManualStage(Stage):
	name = 'wifi manual'
	def __init__(self):
		msg1 = _('Introduce the name of the desired access point through the alphanumeric keyboard.')+'\n'
		msg2 = _('Pressing the key # you can change the key input mode') + '\n'
		msg = msg1 + msg2

		self.ui = baseui.LargeWindowMessageUI(_('OK'), _('BACK'),  _('CONNECTION CONFIG'), msg,  '')
	

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.stack_stage(SetESSIDStage)
		elif key == config.Menu2:
			runtime.manager.back_stage()
		else:	
			return False



class SetESSIDStage(EntryStage):
	def __init__(self):
		EntryStage.__init__(self, _('ESSID'), _('ESSID'))
		self.ui.set_automata('multitap', 'lower')
		self.ui.set_max(32)


		if wifi_profile.essid:
			self.ui.set_text(wifi_profile.essid)


	def success_cb(self):
		#go to next stage -- securtity check

		# ESSID 만 가지고 Registering??
		# security 선택으로 Go
		stage = QuestionSecurityStage
		runtime.manager.change_stage(stage)
	
	def activate_menu1(self):
		old_essid = wifi_profile.essid
		str_domain = self.ui.get_text()
		wifi_profile.set_essid(str_domain)
		if str_domain:
			message = _('ESSID set')
			stage = NotifyStage(message, uiconfig.baloon_wifi_icon, self.success_cb)
			runtime.manager.change_stage(stage)
		else:
			wifi_profile.set_essid('Telefonica')
			message = _('ESSID empty')
			stage = NotifyStage(message, uiconfig.baloon_wifi_icon)
			runtime.manager.change_stage(stage)
#		if old_essid != str_domain:
#			status.profile_detail_changed = True
		return True
########################################




class QuestionSecurityStage(YesNoStage):
	name = "question security"
	def __init__(self):
		icon = uiconfig.baloon_setting_voip_icon
		msg = _('Do you want to use security?')
		YesNoStage.__init__(self, msg, self.yes_cb, self.no_cb, _('CONNECTION CONFIG'), icon)

	def yes_cb(self):
		# Security사용
		runtime.manager.change_stage(SecuritySelectStage)
		
	def no_cb(self):
		# Security를 사용하지 않는다고 판단 Registering

		#def activate(self):
		#wifi_profile.get_wifi()

		def cb2():
			try_register = True
			message = _('WiFi profile enabled.')

			if wifi_profile.dhcp == 'yes':
				if os.path.exists('/tmp/dhcpcd-wlan0.info') == False:
					runtime.manager.vdci_deregister_kill()
					runtime.manager.dhcp_timer_kill()
					import phonesetting
					#runtime.manager.dhcp_timer = utils.Timer(config.dhcp_min, phonesetting.dhcp_client2)
					message = _('IP determining failed')
					try_register = False
				else:
					#runtime.manager.ifconfig_run('wifi')
					runtime.manager.start_vdciapp()
					dns_profile.dhcp_save()
			else:
				dns_profile.save()
				runtime.manager.start_vdciapp()

#ka...2007.04.10 history 에 X면....
			if runtime.manager.find_stage('wifiprofile setting'):
				runtime.manager.back_stage('wifiprofile setting')
			elif runtime.manager.find_stage('wifisetting menu'):
				runtime.manager.back_stage('wifisetting menu')
			else:
				import model
				runtime.manager.change_stage(model.IdleStage, True)
				
			if try_register:
				def register():
					stage = ConfigAutoRegisteringStage
					runtime.manager.change_stage(stage)
				stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=register, isred=False)
			else:
				def IPfail():
					stage = WiFiIPFailStage
					runtime.manager.change_stage(stage)
				# ka....Ip detarming fail 일경우 Noti
				stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=IPfail)
			runtime.manager.stack_stage(stage)

		def cb():
			os.system('wlstop')
			os.system('wlstart')
			cb2()

		runtime.manager.dhcp_timer_kill()
		runtime.manager.change_stage(NotifyStage(_('Determining IP information...'), uiconfig.baloon_wifi_icon, cb, 500))

# ka...malaga 2007.04.11 added
class SecuritySelectStage(ListStage):
	name = 'security select'
	icon = uiconfig.wifi_icon

	def __init__(self):
		self.title = _('ENCRYPTION TYPE')
		self.choice = (_('WEP 64 bits'), _('WEP 128 bits'), _('WPA'))

		ListStage.__init__(self, self.choice, self.title)

	def show(self):
		ListStage.show(self)

	def activate(self, index):
		if index == 0:
			wifi_profile.encryption = 'WEP64BIT'
		elif index == 1:
			wifi_profile.encryption = 'WEP128BIT'
		else:
			wifi_profile.authentication = "WPA-PSK"
			runtime.manager.change_stage(ConfigAuthenticationInputStage(wifi_info=''))
			return 

		runtime.manager.stack_stage(DiscripEncryptionStage(index))

	def handle_key(self, key):
		if key == config.Menu2 or key == config.Red:
			if wifi_profile.encryption == 'NONE':
				def back_cb():
					runtime.manager.back_stage()
					return True
				runtime.manager.change_stage(NotifyStage(_('Encryption is disabled.'), uiconfig.baloon_wifi_icon, back_cb))
				return True
				
		return ListStage.handle_key(self, key)


#ka..malaga 2007.04.10
class ConfigAuthenticationInputStage(Stage):
	def __init__(self, wifi_info):
		self.wifi_info = wifi_info
		self.ui = baseui.EntryUI( _('OK'), _('BACK'), _('WPA-PSK(TKIP)'), _('Enter passphrase'))
		self.ui.set_max(63)
		self.ui.set_automata('multitap', 'lower')
#Roxia Begin smyook 06.06.09
		if wifi_profile.wpa_psk_tkip:
			self.ui.set_text(wifi_profile.wpa_psk_tkip)
#Roxia End smyook

	def show(self):
		status.password_style = True
		Stage.show(self)

	def hide(self):
		status.password_style = False
		Stage.hide(self)

	def destroy(self):
		status.password_style = False
		Stage.destroy(self)

	def activate_menu1(self):
		text = self.ui.get_text()
		if len(text)>=8 and len(text)<=63:
#ka... 3800 wifi 2007.04.25
			wifi_profile.wpa_psk_tkip = text
			status.profile_detail_changed = True
			import phonesetting
			runtime.manager.change_stage(NotifyStage(_('Passphrase set'), uiconfig.baloon_wifi_icon, phonesetting.Backstage_cb))

#		if wifi_profile.essid != self.wifi_info[1] or wifi_profile.channelid != self.wifi_info[2] or wifi_profile.security != self.wifi_info[3] or wifi_profile.signallevel != self.wifi_info[4] or wifi_profile.bitrate != self.wifi_info[5]:
#			status.profile_detail_changed = True
#ka...wifi wizard 2007.04.28

			if self.wifi_info != '':
				wifi_profile.set_scaninfo(self.wifi_info)
				
#ka... 3800 wifi 2007.05.04
			WiFiInfoApply()
			'''
			def cb2():
				try_register = True
				message = _('WiFi profile enabled.')

				if wifi_profile.dhcp == 'yes':
					if os.path.exists('/tmp/dhcpcd-wlan0.info') == False:
						runtime.manager.vdci_deregister_kill()
						runtime.manager.dhcp_timer_kill()
						import phonesetting
						#runtime.manager.dhcp_timer = utils.Timer(config.dhcp_min, phonesetting.dhcp_client2)
						message = _('IP determining failed')
						try_register = False
					else:
						runtime.manager.ifconfig_run('wifi')
						runtime.manager.start_vdciapp()
						dns_profile.dhcp_save()
				else:
					dns_profile.save()
					runtime.manager.start_vdciapp()

#ka...2007.04.10 history 에 X면....
				if runtime.manager.find_stage('wifiprofile setting'):
					runtime.manager.back_stage('wifiprofile setting')
				elif runtime.manager.find_stage('wifisetting menu'):
					runtime.manager.back_stage('wifisetting menu')
				else:
					import model
					runtime.manager.change_stage(model.IdleStage, True)
					
				if try_register:
					def register():
						stage = ConfigAutoRegisteringStage
						runtime.manager.change_stage(stage)
					stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=register, isred=False)
				else:
					def IPfail():
						stage = WiFiIPFailStage
						runtime.manager.change_stage(stage)
					# ka....Ip detarming fail 일경우 Noti
					stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=IPfail)
				runtime.manager.stack_stage(stage)

			def cb():
				os.system('wlstop')
				os.system('wlstart')
				cb2()

			runtime.manager.dhcp_timer_kill()
			runtime.manager.change_stage(NotifyStage(_('Determining IP information...'), uiconfig.baloon_wifi_icon, cb, 500))
			'''
			
	def insert_symbol(self, s):
		self.ui.insert_text(s)
		runtime.manager.back_stage()

	def handle_key(self, key):
		if key in '1234567890*' and self.ui.entry.full() and not self.ui.entry._automata._last_ch:
			runtime.manager.stack_stage(NotifyStage(_('Maximum Passphrase Size is 63.'), uiconfig.baloon_wifi_icon))
		elif key == config.Menu1:	#options Menu(left key)
			self.ui.reset_automata()
			self.activate_menu1()
		elif key == config.Menu2:
			if self.ui.handle_key(key):
				return True
			runtime.manager.back_stage()

		elif key == '#':
			self.automata_idx = utils.get_automata_idx(*self.ui.automata)
			self.automata_idx += 1
			if self.automata_idx >= len(config.automata_list):
				self.automata_idx = 3
			name, casemode = config.automata_list[self.automata_idx]
			self.ui.set_automata(name, casemode)

		elif key == '*':
			self.ui.reset_automata()
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
		else:
			return self.ui.handle_key(key)
		return True


def ConfigWfScan(num = 1):
	def info_get(fname):
		wifi_info = []
		info = ['','','1','','','','']
		firstget = True
		
#ka...3800 wifi 2007.04.25
		for tline in fname: #.readlines():
			maxc = 0
#SSID	# For seperate BSSID
			if tline.find('SSID') >= 0 and tline.find('\"') >= 0:	
				if firstget == False:
					if info[6] == '':
						info.pop()
					wifi_info.append(info)
				firstget = False
				info = ['','','1','','','','']
				a,b = tline.split(':')
				b = b.strip()
				info[1] = b[1:len(b)-1]
			elif tline.find('Mode') >= 0:
#RSSI
				if tline.find('RSSI'):
					ti = tline.find('RSSI')
					info[3] = (tline[ti+6:tline.find('dBm')])
#Channel
				if tline.find('Channel') >= 0:
					ti = tline.find('Channel')
					info[2] = (tline[ti+9:].strip())

#BSSID --> MAC
			elif tline.find('BSSID') >= 0:
				info[0] = tline[tline.find(':')+2:24].strip()
#Capability
				if tline.find('WEP') >= 0:
					encryption = 'on'
				else:
					encryption = 'off'
				info[4] = encryption
#Bit rate
			elif tline.find('Supported Rates') >= 0:
				ti = tline.find(']')
				if tline[ti-2] == ')': # b-mode: 11(b)
					rate = (tline[ti-6:ti-4])
				else:
					rate = (tline[ti-3:ti-1])
				if len(info) == 6: ######### 이건 모지,,,
					info.pop()
				info[5] = (str(rate)+'Mbps')
#WPA
			elif tline.find('WPA') >= 0:
				info[6] = 'wpa_ie'

		else:
			if info[6] == '':
				info.pop()
			wifi_info.append(info)

		length = len(wifi_info) -1
		for z in range(length,-1,-1):
			if wifi_info[z] == []:
				del wifi_info[z]
			elif wifi_info[z][1].strip() == '':
				del wifi_info[z]

		return wifi_info

	try:
		if profile.profile != 'WIRELESS':
			return NotifyStage(_('WiFi profile is not enabled.'), uiconfig.baloon_wifi_icon)
#		if not num in (1,6):
#		os.system('wlstop')
#		os.system('wlstart')

#ka...3800 wifi 2007.04.25
#		os.system('iwlist wlan0 scan > /tmp/wifiscan.tmp')
		os.system('wlscan')
		fp = open('/tmp/wifiscan.tmp')
		scan_info = info_get(fp)

		if scan_info != []:
			cwifi = len(scan_info)
			lists = []
			for z in range(cwifi):
				if len(scan_info[z]) == 7:
					list_value = scan_info[z][1] + '('+_('Channel')+': ' + scan_info[z][2] + ', ' + _('WPA-PSK') + ')'
				elif scan_info[z][4] == 'on':
					list_value = scan_info[z][1] + '('+_('Channel')+': ' + scan_info[z][2] + ', ' + _('Encrypted') + ')'
				else:
					list_value = scan_info[z][1] + '('+_('Channel')+': ' + scan_info[z][2] + ')'

				lists.append(list_value)
			return ConfigWiFiInfoStage(lists, scan_info)
		else:
			return NoApStage()

	except:
		return NotifyStage(_('WiFi profile is not enabled.'), uiconfig.baloon_wifi_icon)


class NoApStage(Stage):
	name = 'no AP'
	def __init__(self):
		msg1 = _('No wireless networks found.')+'\n'
		msg2 = _('If the problem persists, please refer to the user guide.') + '\n'
		msg = msg1 + msg2

		self.ui = baseui.LargeWindowMessageUI(_('RETRY'), _('BACK'),  _('CONNECTION CONFIG'), msg,  '')
	

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.back_stage('wifi choice')
		elif key == config.Menu2:
			runtime.manager.back_stage('config picture3')
		else:	
			return False



class  ConfigWiFiInfoStage(ListStage):
	icon = uiconfig.wifi_icon
	def __init__(self, lists, wifi_info):
		self.title = _('wifi info')
		ListStage.__init__(self, lists, left=_('SELECT'), right=_('BACK'))
		self.wifi_info = wifi_info

	def destroy(self):
# dwcho 06.07.03
		'''
		if os.path.exists('/tmp/dhcpcd-wlan0.info') == True:
			runtime.manager.ifconfig_run('wifi')
			from profile import dns_profile
			dns_profile.dhcp_save()
		'''
# dwcho end.

		ListStage.destroy(self)

	def activate(self, index):
		stage = WiFiInfoShowStage(self.wifi_info[index])
		runtime.manager.stack_stage(stage)


	def handle_key(self, key):
		if key == config.Menu2:
			runtime.manager.back_stage('config picture3')
			return True
		return ListStage.handle_key(self, key)




class WiFiInfoShowStage(Stage):
	def __init__(self, lists, mode = 0):
		self.ui = baseui.InfoUI(lists, mode)
		self.wifi_info = lists
		self.mode = mode


	def activate(self):
		if wifi_profile.essid != self.wifi_info[1] or wifi_profile.channelid != self.wifi_info[2] or wifi_profile.security != self.wifi_info[3] or wifi_profile.signallevel != self.wifi_info[4] or wifi_profile.bitrate != self.wifi_info[5]:
			status.profile_detail_changed = True
		wifi_profile.set_scaninfo(self.wifi_info)

		WiFiInfoApply()

#ka...malaga 2007.04.06
	def changing_cb1(self):
		#AP(off)SET(on)-Authentication
		wifi_profile.authentication = 'NONE'
		self.activate()
	def changing_cb2(self):
		#AP(off)SET(on)-Encryption
		wifi_profile.encryption = 'NONE'
		self.activate()
	def changing_cb3(self):
		#AP(on)SET(on/off)-Authentication
		wifi_profile.encryption = 'NONE'
		wifi_profile.authentication = 'WPA-PSK'
		 #Temporay
		runtime.manager.change_stage(ConfigAuthenticationInputStage(self.wifi_info))
	def changing_cb4(self, notify=True):
		# AP(on)SET(on/off) -Encryption
		wifi_profile.authentication = 'NONE'
		runtime.manager.change_stage(ConfigEncryptionSelectStage(self.wifi_info, notify))
	def changing_cb5(self):
		# AP(off)SET(off)
		wifi_profile.authentication = 'NONE'
		wifi_profile.encryption = 'NONE'
		self.activate()


	def handle_key(self, key):
		if key == config.Menu1 and self.mode == 0:
			if wifi_profile.authentication != 'NONE' and len(self.wifi_info) != 7:
# Case 1. AP(off)SET(on)-Authentication
#				runtime.manager.stack_stage(NotifyStage(_('WPA-PSK is not enabled.'), uiconfig.baloon_wifi_icon))
				if self.wifi_info[4] != 'on':
					runtime.manager.stack_stage(NotifyStage(_('WPA-PSK is disabled.'), uiconfig.baloon_wifi_icon, self.changing_cb1))
				else:
					runtime.manager.stack_stage(NotifyStage(_('WPA-PSK is disabled.')+'\n'+_('Encryption is enabled.'), uiconfig.baloon_wifi_icon, self.changing_cb4))
			elif wifi_profile.encryption != 'NONE' and self.wifi_info[4] != 'on':
# Case 2. AP(off)SET(on)-Encryption
#				runtime.manager.stack_stage(NotifyStage(_('Encryption is not enabled.'), uiconfig.baloon_wifi_icon))
				runtime.manager.stack_stage(NotifyStage(_('Encryption is disabled.'), uiconfig.baloon_wifi_icon, self.changing_cb2))
			elif len(self.wifi_info) == 7:
				if wifi_profile.authentication == 'NONE':
# Case 3. AP(on)SET(off)-Authentication
					runtime.manager.stack_stage(NotifyStage(_('This AP is using WPA-PSK.')+'\n'+_('WPA-PSK is enabled.'), uiconfig.baloon_wifi_icon, self.changing_cb3))
				else:
# Case 4. AP(on)SET(on)-Authentication
#					self.activate()
					self.changing_cb3()
			elif self.wifi_info[4] == 'on':
				if wifi_profile.encryption == 'NONE':
# Case5. AP(on)SET(off)-Encryption
#					runtime.manager.stack_stage(NotifyStage(_('This AP is using Encryption.')+'\n'+_('Configure encryption option first.'), uiconfig.baloon_wifi_icon))
					runtime.manager.stack_stage(NotifyStage(_('This AP is using Encryption.')+'\n'+_('Encryption is enabled.'), uiconfig.baloon_wifi_icon, self.changing_cb4))
				else:		
# Case6. AP(on)SET(on)-Encryption
#					self.activate()
					self.changing_cb4(notify=False)
			else:
# Case7. OFF OFF
#				self.activate()
				self.changing_cb5()

		elif key == config.Menu2 or key == config.Red:
			runtime.manager.back_stage()
		else:
			return False
		return True






# ka...malaga 2007.04.11 added
class ConfigEncryptionSelectStage(ListStage):
	name = 'config encryption select'
	icon = uiconfig.wifi_icon

	def __init__(self, wifi_info, notify):
		self.title = _('ENCRYPTION TYPE')
		self.choice = (_('WEP 64 bits'), _('WEP 128 bits'))

		self.wifi_info = wifi_info
		self.notify = notify
		ListStage.__init__(self, self.choice, self.title)

	def show(self):
		ListStage.show(self)
		if wifi_profile.encryption == 'WEP128BIT':
			self.ui.set_focus(1)
		else:
			self.ui.set_focus(0)

	def activate(self, index):
		if index == 0:
			wifi_profile.encryption = 'WEP64BIT'
		else:
			wifi_profile.encryption = 'WEP128BIT'
		runtime.manager.stack_stage(DiscripEncryptionStage(index, self.wifi_info))

	def handle_key(self, key):
		if key == config.Menu2 or key == config.Red:
			if wifi_profile.encryption == 'NONE':
				def back_cb():
					runtime.manager.back_stage()
					return True
				runtime.manager.change_stage(NotifyStage(_('Encryption is disabled.'), uiconfig.baloon_wifi_icon, back_cb))
				return True
				
		return ListStage.handle_key(self, key)


class DiscripEncryptionStage(Stage):
	name = 'encryption 64'
	def __init__(self, mode, wifi_info=''):
		self.mode=mode
		self.wifi_info=wifi_info
		if self.mode == 0:
			msg2 = _('This key has 10-hexadecimal or 5-alphanumeric.') + '\n'
		else:
			msg2 = _('This key has 26-hexadecimal or 13-alphanumeric.') + '\n'
			
		msg1 = _('The key is written in a label of your Modem Router')+'\n'
		msg3 = _('Pressing the key # you can change the key input mode.') + '\n'

		msg = msg1 + msg2 + msg3

		self.ui = baseui.LargeWindowMessageUI(_('OK'), _('BACK'),  _('CONNECTION CONFIG'), msg,  '')
	

	def handle_key(self, key):
		if key == config.Menu1:
			runtime.manager.stack_stage(ConfigEncryptionInputStage(self.mode, self.wifi_info))
		elif key == config.Menu2:
			runtime.manager.back_stage()
		else:	
			return False
		return True



#ka...3800 wifi malaga 2007.04.06 added
class ConfigEncryptionInputStage(Stage):
	def __init__(self, mode, wifi_info=''):
		self.mode = mode
		self.wifi_info = wifi_info

		if self.mode == 0:
			_title = _('WEP 64 BITS')
		else:
			_title = _('WEP 128 BITS')

		self.ui = baseui.EntryUI( _('OK'), _('BACK'), _title, _('Enter wireless key'))
		self.ui.set_automata('multitap', 'lower') #*utils.get_def_automata())			#입력 방식 설정

		if self.mode == 0:
			if wifi_profile.wepkey1_64:
				#ka...3800 wifi 2007.05.01
				keyvalue = wifi_profile.wepkey1_64
				if len(keyvalue) > 5:
					keyvalue = keyvalue[2:]
				self.ui.set_max(10)
				#keyvalue = wifi_profile.wepkey1_64.replace('-','')
				self.ui.set_text(keyvalue)
		else:
			if wifi_profile.wepkey1_128:
				#ka...3800 wifi 2007.05.01
				keyvalue = wifi_profile.wepkey1_128
				if len(keyvalue) > 13:
					keyvalue = keyvalue[2:]
				self.ui.set_max(26)
				#keyvalue = wifi_profile.wepkey1_128.replace('-','')
				self.ui.set_text(keyvalue)
		
	def show(self):
		status.password_style = True
		Stage.show(self)

	def hide(self):
		status.password_style = False
		Stage.hide(self)

	def destroy(self):
		status.password_style = False
		Stage.destroy(self)

	def activate(self):
#ka...wifi wizard
		if self.wifi_info != '':
			if wifi_profile.essid != self.wifi_info[1] or wifi_profile.channelid != self.wifi_info[2] or wifi_profile.security != self.wifi_info[3] or wifi_profile.signallevel != self.wifi_info[4] or wifi_profile.bitrate != self.wifi_info[5]:
				status.profile_detail_changed = True
			wifi_profile.set_scaninfo(self.wifi_info)
			
		WiFiInfoApply()		
		'''
		def cb2():
			try_register = True
			message = _('WiFi profile enabled.')

			if wifi_profile.dhcp == 'yes':
				if os.path.exists('/tmp/dhcpcd-wlan0.info') == False:
					runtime.manager.vdci_deregister_kill()
					runtime.manager.dhcp_timer_kill()
					import phonesetting
					#runtime.manager.dhcp_timer = utils.Timer(config.dhcp_min, phonesetting.dhcp_client2)
					message = _('IP determining failed')
					try_register = False
				else:
					runtime.manager.ifconfig_run('wifi')
					runtime.manager.start_vdciapp()
					dns_profile.dhcp_save()
			else:
				dns_profile.save()
				runtime.manager.start_vdciapp()

#ka...2007.04.10 history 에 X면....
			if runtime.manager.find_stage('wifiprofile setting'):
				runtime.manager.back_stage('wifiprofile setting')
			elif runtime.manager.find_stage('wifisetting menu'):
				runtime.manager.back_stage('wifisetting menu')
			else:
				import model
				runtime.manager.change_stage(model.IdleStage, True)
				
			if try_register:
				def register():
					stage = ConfigAutoRegisteringStage
					runtime.manager.change_stage(stage)
				stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=register, isred=False)
			else:
				def IPfail():
					stage = WiFiIPFailStage
					runtime.manager.change_stage(stage)
				# ka....Ip detarming fail 일경우 Noti
				stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=IPfail)
			runtime.manager.stack_stage(stage)

		def cb():
			os.system('wlstop')
			os.system('wlstart')
			cb2()

		runtime.manager.dhcp_timer_kill()
		runtime.manager.change_stage(NotifyStage(_('Determining IP information...'), uiconfig.baloon_wifi_icon, cb, 500))
		'''


	def activate_menu1(self):
		text = self.ui.get_text()
		if self.mode == 0:
			if len(text) == 5 or len(text) == 10 or len(text) == 12:
				if len(text) == 10 or len(text) == 12:
					for i in text:
						if '0123456789abcdefABCDEF'.find(i) == -1:
							runtime.manager.stack_stage(NotifyStage(_('Invalid input value.')+'\n'+_('Please use hexadecimal input value.'), uiconfig.baloon_wifi_icon))
							return
				if len(text) == 12:
					if text[:2].lower() != '0x':
						runtime.manager.stack_stage(NotifyStage(_('Input valid characters'), uiconfig.baloon_wifi_icon))
						return
#ka...3800 wifi 2007.05.01
				if len(text) == 5:
					wifi_profile.wepkey1_64 = text
				else:
					wifi_profile.wepkey1_64 =  '0x' + text
#				if self.key == 1:
				#wifi_profile.wepkey1_64 = text
				# 07.08 wifi_profile.save()
				status.profile_detail_changed = True
#				runtime.manager.change_stage(NotifyStage(_('Key 1 saved'), uiconfig.baloon_wifi_icon))	
#				InfoShowStage.activate(num2=0)
				self.activate()

			else:
				runtime.manager.stack_stage(NotifyStage(_('Input valid characters'), uiconfig.baloon_wifi_icon))
				return
		elif self.mode == 1:
			if len(text) == 28 or len(text) == 13 or len(text) == 26:
				if len(text) == 26 or len(text) == 28:
					for i in text:
						if '0123456789abcdefABCDEF'.find(i) == -1:
							runtime.manager.stack_stage(NotifyStage(_('Invalid input value.')+'\n'+_('Please use hexadecimal input value.'), uiconfig.baloon_wifi_icon))
							return
				if len(text) == 28:
					if text[:2].lower() != '0x':
						runtime.manager.stack_stage(NotifyStage(_('Input valid characters'), uiconfig.baloon_wifi_icon))
						return
# eicho modify to fix wording problem. 06.06.22
#				if self.key == 1:
#ka...3800 wifi 2007.05.01
				if len(text) == 13:
					wifi_profile.wepkey1_128 = text
				else:
					wifi_profile.wepkey1_128 =  '0x' + text
				#wifi_profile.wepkey1_128 = text
				# 07.08 wifi_profile.save()
				status.profile_detail_changed = True
#				runtime.manager.change_stage(NotifyStage(_('Key 1 saved'), uiconfig.baloon_wifi_icon))				
#				InfoShowStage.activate(num2=0)
				self.activate()
			else:
				runtime.manager.stack_stage(NotifyStage(_('Input valid characters'), uiconfig.baloon_wifi_icon))
				return

	def insert_symbol(self, s):
		before_text = self.ui.get_text()
		self.ui.insert_text(s)
		after_text = self.ui.get_text()
		if before_text == after_text:
			runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()

	def handle_key(self, key):
		if key == config.Menu1:	#options Menu(left key)
			self.ui.reset_automata()
			self.activate_menu1()
		elif key == config.Menu2:
			if self.ui.handle_key(key):
				return True
			runtime.manager.back_stage()
		elif key == '#':
			self.automata_idx = utils.get_automata_idx(*self.ui.automata)
			self.automata_idx += 1
			if self.automata_idx >= len(config.automata_list):
				self.automata_idx = 3
			name, casemode = config.automata_list[self.automata_idx]
			self.ui.set_automata(name, casemode)
		elif key == '*':
			self.ui.reset_automata()
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))

		else:
			return self.ui.handle_key(key)
		return True



class WiFiIPFailStage(Stage):
	name = 'wifi fail'
	def __init__(self):

		msg1 = _('Make sure that Modem Router is switch on.') + '\n'
		msg2 = _('If the problem persists, verify that the DHCP of your Router Modem is enabled.')+'\n'
#ka...0501 라인이 너무 길어서 임시로 막음 
#		msg3 = _('And check that you selected the security option and that you have introduced the key perperly.') + '\n'
		msg = msg1 + msg2

		self.ui = baseui.LargeWindowMessageUI(_('OK'), '',  _('CONNECTION CONFIG'), msg,  '')
	

	def handle_key(self, key):
		if key in (config.Menu1, config.Menu2, config.Red):
			runtime.manager.change_stage(IdleStage, True)
		else:	
			return False



def WiFiInfoApply():
#	icon = uiconfig.wifi_icon
	icon = uiconfig.baloon_setting_system_network_wireless_icon
# ka...3800 2007.05.03 profile change 후 Apply
	status.profile_detail_changed = False
	os.system('wlstop')

	if wifi_profile.dhcp == 'yes':
		message = _('Determining IP information...')
		runtime.manager.change_stage(NotifyStage(message, icon, isred=False))
		runtime.evas.render_now()
		
	runtime.manager.vdci_deregister_kill()
	runtime.manager.release_change_profile_tmr()
	# WIFI 에서는 필요없다. 
	# status.on_profile_changing = True	#아래 wlstart에 의해 발생한 LINK_UP 이벤트 무시하기 위해서.
	
	os.system('wlstart')
	if wifi_profile.dhcp == 'yes':
		if os.path.exists('/tmp/dhcpcd-wlan0.info') == False:
			status.profile_changing = True
			import phonesetting
#			runtime.manager.dhcp_timer = utils.Timer(config.dhcp_min, phonesetting.dhcp_client2)
			message = _('IP determining failed')
			runtime.manager.show_lan_disconnected = True

			def IPfail():
				runtime.manager.change_stage(WiFiIPFailStage)
			# ka....Ip detarming fail 일경우 Noti
			stage = NotifyStage(message, uiconfig.baloon_wifi_icon, cb=IPfail)
			runtime.manager.stack_stage(stage)
			return
		else:
			#runtime.manager.ifconfig_run('wifi')
			dns_profile.dhcp_save()
	else:
		dns_profile.save()
		#runtime.manager.start_vdciapp()
		#0707 ka runtime.manager.start_vdciapp()
	

	stage = ConfigAutoRegisteringStage
	runtime.manager.change_stage(stage)