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

#
# by shchun : add new profile scheme. 
#              KT requested just before golden week of May, 2008.
#
#		(May-16) policy changed: after profile change ==> reboot 
import runtime, uiconfig, config, baseui, utils, model, ui, time, controls, entry
from basemodel import ListStage, Stage, NotifyStage, YesNoStage, EntryStage, ListCalendarStage
from baseui import SmallWindowUI
from setting import setting
from vdcisetting import vdci_setting
from phonebook import PhoneBookStage
import status
import phonesetting
import os
from roxiadebug import *

from profile import wifi_profile_general, wifi_profile_kt_default, wifi_profile, lan_profile, dns_profile, profile

reset_timer = None

def wlAvailable():
	if len(os.popen('lsmod | grep wl').read()) > 0:
		return True
	return False

def reset_cb_1():
	global reset_timer
	debugLogN('Newprof.reset_cb_1: unsubscribe')	
	runtime.manager.linkmonitor.stop_net_monitor()		
	if runtime.vdciapp and status.get_register_mode() == status.Registered:
		if runtime.vdciapp.subscriber_success:
			runtime.vdciapp.req_desubscriber()
	reset_timer = utils.Timer(config.a_moment, reset_cb_2)
	
def reset_cb_2():
	global reset_timer
	debugLogN('Newprof.reset_cb_2: unregister')	
	if runtime.vdciapp and status.get_register_mode() == status.Registered:
		runtime.vdciapp.req_deregister()
	reset_timer = utils.Timer(config.a_moment, reset_cb_3)
	
def reset_cb_3():
	global reset_timer
	debugLogN('Newprof.reset_cb_3: release dhcp')	
	utils.releaseDhcp()
	reset_timer = utils.Timer(config.a_moment, reset_cb_4)
	
def reset_cb_4():
	debugLogN('Newprof.reset_cb_4')	
#MMW 2008.06.25 when reboot is called, reset vega and DCP related GPIO pin				
	utils.vega_reset_together()
#end of MMW	
#MMW	2008.07.07	when reboot send disassoc to AP and then unload the driver
	os.system('wlstop')
#end of MMW
	os.system('/usr/local/bin/reboot')

class NewProfNotifyStage(NotifyStage):
	agenda_forbidden = True
	domonitor_forbidden = True
	def __init__(self, message, icon=None, cb=None, duration=0, isred=True, noexit=False):
		NotifyStage.__init__(self, message, icon, cb, duration, isred)
		self.noexit = noexit
	def handle_key(self, key):
		if self.noexit:
			if key in (config.Red, config.Green, config.OffHook, config.OnHook, config.Video):
				print 'Ignore key(1) - ', key
				return True
		
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		return NotifyStage.handle_key(self, key)
	
class  PrevProfileListStage(NotifyStage):
	domonitor_forbidden = True
	duration = 500
	def __init__(self):
		prof = profile.get_profile()
		if prof == 1: # LAN
			#message = _('Currently, you are using Wired profile')			
			message = uiconifg.WD_0234 

		else: #prof == 2: # Wi-Fi
			#message = _('Currently, you are using Wireless profile')
			message = uiconifg.WD_0235
		
		NotifyStage.__init__(self, message, uiconfig.baloon_phone_setting_icon, cb = self.next_cb, duration=1000)
		
	def next_cb(self):
		stage = ProfileListStage
		runtime.manager.change_stage(stage)

def save_callback():
	debugLogC('!!!PROFLE SAVE ROLLBACK!!!')

	if status.profile_detail_changed == True:
		lan_profile.except_apply(True)
		wifi_profile_general.except_apply(True)
		dns_profile.except_apply(True)
		setting.megaAPEnabled = setting._megaAPEnabled
		setting.save()
		#return (_('Changed settings will be cancelled'), uiconfig.baloon_profile_setting_icon)
		return (uiconifg.WD_0236, uiconfig.baloon_profile_setting_icon)

	else:
		return None, None

def rollback_profile_changes():
	debugLogC('!!!ROLLBACK PROFILE CHANGES!!!')
	lan_profile.except_apply(True)
	wifi_profile_general.except_apply(True)
	dns_profile.except_apply(True)
	setting.megaAPEnabled = setting._megaAPEnabled

		
class ProfileListStage(ListStage):
	domonitor_forbidden = True
	# spec p2
	#choice = _('Wired profile'), _('Wireless profile')
	#titleimage=uiconfig.title_network_profile_setting

	icon= uiconfig.network_setting_icon
	def __init__(self):
		self.title = _('PROFILE LIST')
		if status.wifi_test:
			self.choice = _('Wired profile'), _('Wireless profile')
		else:
			self.choice = _('Wired profile'),
		ListStage.__init__(self)
		self.prev_prof = profile.get_profile()
		profile_setting = self.prev_prof-1
		self.ui.set_focus(profile_setting) # update to setting.profile	
		status.profile_detail_changed = False
		status.save_callback_other = save_callback

		lan_profile.copy_old_values()
		wifi_profile_general.copy_old_values()
		dns_profile.copy_old_values()
		setting._megaAPEnabled = setting.megaAPEnabled
		
	def destroy(self):
		status.save_callback_other = None
		ListStage.destroy(self)		

	def activate(self, index):
		if index == 0:
			# Jump to step 6
			if self.prev_prof == 2: 
				status.profile_detail_changed = True
			stage = IPSettingStage(wireless=False, manual=False)
			runtime.manager.stack_stage(stage)
		else:
			if self.prev_prof == 1: 
				status.profile_detail_changed = True
			stage = WirelessConnListStage
			runtime.manager.stack_stage(stage)

	def handle_key(self, key):
		if key == config.Menu3:
			# for debug purpose, you can access old profile stages.
			import phonesetting
			stage = phonesetting.ProfileStage
			runtime.manager.change_stage(stage)
			return True
		elif key in (config.Menu4,  config.CLEAR):
			rollback_profile_changes()
			runtime.manager.back_stage() 
			return True
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		ListStage.handle_key(self,key)

class ProfileRollbackYesNoStage(YesNoStage):
	domonitor_forbidden = True
	def __init__(self):
		#message = _('Do you want delete custom profile?')
		message = ('Discard change and restore original setting?')
		YesNoStage.__init__(self, message, self.yes_cb, self.no_cb, '', uiconfig.baloon_phone_setting_icon)
		self.ui.set_menu3(_('CANCEL'))
	def yes_cb(self):
		lan_profile.except_apply(True)
		wifi_profile_general.except_apply(True)
		dns_profile.except_apply(True)
		setting.megaAPEnabled = setting._megaAPEnabled
		setting.save()
		runtime.manager.back_stage() 
		runtime.manager.back_stage() 	
	def no_cb(self):
		runtime.manager.back_stage() 
		
class WirelessConnListStage(ListStage):
	domonitor_forbidden = True

	icon= uiconfig.wireless_profile_icon

	def __init__(self):
		self.choice = _('Profile'), _('Searching wireless AP'),  _('Connection detail')
		self.title = _('WIRELESS PROFILE')
	
		ListStage.__init__(self)
	def activate(self, index):
		if index == 0:
			stage = WirelessProfileStage
			runtime.manager.stack_stage(stage)
		elif index == 1:
			stage=WirelessScanWaitStage
			runtime.manager.stack_stage(stage)
#		elif index == 2:
#			# shchun NOTE: in manual mode you cannot enable mac-mode, because mac-mode requires mac address input but it is nonsense to user.
#			#stage=ManualSettingStage
#			stage=ManualESSIDStage
#			runtime.manager.stack_stage(stage)
		else: # index == 2
			#stage = ConnectionDetailStage
			
			import profile
			if profile.profile.get_profile() != 2:
				stage = NewProfNotifyStage(_('Wired profile is used'), uiconfig.baloon_setting_system_reset_icon)
				runtime.manager.stack_stage(stage)
				return

			if not status.wifi_connected:
				stage = NewProfNotifyStage(_('Wireless connection disconected, please check setting.'), uiconfig.baloon_setting_system_reset_icon)
				runtime.manager.stack_stage(stage)
				return
			
			is_kt_ap = False
			print '###' ,profile.wifi_profile._name, profile.wifi_profile.essid
			#if profile.wifi_profile.essid == 'KT_SoIP':
			if profile.wifi_profile._name == 'MegaAP':
				is_kt_ap = True
			stage = DynInfoShowStage(profile.wifi_profile.get_wifi(), is_kt_ap=is_kt_ap)
			runtime.manager.stack_stage(stage)
			
	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True			
		return ListStage.handle_key(self, key)	
class WirelessProfileStage(ListStage):
	domonitor_forbidden = True
		
	icon= uiconfig.wireless_profile_icon
	def __init__(self):
		#choice = _('Mega Ap'), _('Custom profile')
		if config.KT_profile_enable == True :	# KT
			self.choice = _('KT profile'), _('User profile')
		else :
			self.choice = (_('User profile'),)
		self.title = _('WIRELESS PROFILE')
	
		ListStage.__init__(self, self.choice)
		if config.KT_profile_enable == True :	# KT	
			if setting.megaAPEnabled ==1:
				self.ui.set_focus(0)
			else:
				self.ui.set_focus(1)
		else :		
			self.ui.set_focus(0)
		self.update_soft()
	def update_soft(self):
		index = self.ui.get_focus()
		if config.KT_profile_enable == True :	# KT
			if index == 0:
				self.ui.set_left(_('CONNECT'))
				self.ui.set_right('')
				self.ui.set_menu3('')
				self.ui.set_menu4(_('BACK'))
			else:
				self.ui.set_left(_('CONNECT'))
				self.ui.set_right(_('EDIT'))
				self.ui.set_menu3(_('DELETE'))
				self.ui.set_menu4(_('BACK'))
		else	 :
			self.ui.set_left(_('CONNECT'))
			self.ui.set_right(_('EDIT'))
			self.ui.set_menu3(_('DELETE'))
			self.ui.set_menu4(_('BACK'))

		
	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False

		#elif key in (config.Red, config.Green, config.Video):
		elif key in (config.Green, config.Video):
			print 'skip key'
			return True

		if key == '1':
			index = 0
		elif key == '2':
			index = 1
		else:
			index = self.ui.get_focus()
		if config.KT_profile_enable == True :		# KT	
			if index == 0:
				if key in (config.Menu1, 'OK', '1' ):
			 		setting.megaAPEnabled = 1
			 		setting._save()

					profile.set_profile(2) # wifi profile.
					phonesetting.cur_profile = wifi_profile
					stage = NewProfNotifyStage(_('System rebooting, then reconnect with new setting values'), uiconfig.baloon_setting_system_reset_icon, reset_cb_1, noexit=True)
					runtime.manager.stack_stage(stage)
				elif key == config.Menu4:
					runtime.manager.back_stage()
				else:
					ret =  ListStage.handle_key(self, key)
					self.update_soft()
					return ret
			else:
				if key in (config.Menu1, 'OK', '2' ):

					if len(wifi_profile_general.essid) == 0:
						stage = NewProfNotifyStage(_('Setting first'), uiconfig.wireless_profile_icon)
						runtime.manager.stack_stage(stage)
						return True
			 		setting.megaAPEnabled = 0
			 		setting._save()

					# commit changes up to now...
					profile.set_profile(2)
					wifi_profile_general.save()	# commit
					dns_profile.save()
					profile.save()

					stage = NewProfNotifyStage(_('System rebooting, then reconnect with new setting values'), uiconfig.baloon_setting_system_reset_icon, reset_cb_1, noexit=True)
					runtime.manager.stack_stage(stage)

					# by default : wireless.cfg refers custom setting.
					os.system('cp /usr/etc/wireless_general.cfg /usr/etc/wireless.cfg')	

					#stage=ApplyNetworkSettingStage(wireless=True)
					#runtime.manager.stack_stage(stage)
					#stage = NewProfNotifyStage(_('connecting to Custom profile...'), uiconfig.baloon_setting_system_reset_icon, next_cb)
					#runtime.manager.stack_stage(stage)		
				elif key == config.Menu2:
					stage = WiFiStage
					runtime.manager.stack_stage(stage)		
				elif key == config.Menu3:
					stage = WirelessCustomProfileRemoveYesNoStage
					runtime.manager.stack_stage(stage)		
				elif key == config.Menu4:
					#rollback_profile_changes()
					runtime.manager.back_stage() 
					return True
				elif key == config.CLEAR:
					runtime.manager.back_stage() 
					return True
				else:
					ret =  ListStage.handle_key(self, key)
					self.update_soft()
					return ret
		else : # telio profile			
			if key in (config.Menu1, 'OK', '1' ):

				if len(wifi_profile_general.essid) == 0:
					stage = NewProfNotifyStage(_('Setting first'), uiconfig.wireless_profile_icon)
					runtime.manager.stack_stage(stage)
					return True
		 		setting.megaAPEnabled = 0
		 		setting._save()

				# commit changes up to now...
				profile.set_profile(2)
				wifi_profile_general.save()	# commit
				dns_profile.save()
				profile.save()

				stage = NewProfNotifyStage(_('System rebooting, then reconnect with new setting values'), uiconfig.baloon_setting_system_reset_icon, reset_cb_1, noexit=True)
				runtime.manager.stack_stage(stage)

				# by default : wireless.cfg refers custom setting.
				os.system('cp /usr/etc/wireless_general.cfg /usr/etc/wireless.cfg')	

				#stage=ApplyNetworkSettingStage(wireless=True)
				#runtime.manager.stack_stage(stage)
				#stage = NewProfNotifyStage(_('connecting to Custom profile...'), uiconfig.baloon_setting_system_reset_icon, next_cb)
				#runtime.manager.stack_stage(stage)		
			elif key == config.Menu2:
				stage = WiFiStage
				runtime.manager.stack_stage(stage)		
			elif key == config.Menu3:
				stage = WirelessCustomProfileRemoveYesNoStage
				runtime.manager.stack_stage(stage)		
			elif key == config.Menu4:
				#rollback_profile_changes()
				runtime.manager.back_stage() 
				return True
			elif key == config.CLEAR:
				runtime.manager.back_stage() 
				return True
			else:
				ret =  ListStage.handle_key(self, key)
				self.update_soft()
				return ret

		
	def activate(self, index):
		pass
		

class WiFiStage(ListStage):
	domonitor_forbidden = True
	name = 'wireless manual config'
	
	#titleimage=uiconfig.title_wireless_profile_setting
	icon = uiconfig.wifi_icon

	def __init__(self):
		self.title = _('WIRELESS PROFILE')
		self.choice = _('SSID'),  _('Data security'),  _('IP setting')
	
		ListStage.__init__(self, self.choice, self.title)
		
	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			#rollback_profile_changes()
			runtime.manager.back_stage() 
			return True			
		return ListStage.handle_key(self, key)
		
	def activate(self, index):
		#stage = (IPSettingStage, ManualESSIDStage, ManualSecurityListStage, ManualBSSIDStage, ManualMacModeStage, ManualWMMStage)[index]
#		stage = (ManualESSIDStage, ManualBSSIDMacModeStage, ManualSecurityListStage, IPSettingStage )[index]
		stage = (ManualESSIDStage, ManualSecurityListStage, IPSettingStage )[index]
		
		runtime.manager.stack_stage(stage)
		
class WirelessCustomProfileRemoveYesNoStage(YesNoStage):
	domonitor_forbidden = True
	def __init__(self):
		#message = _('Do you want delete custom profile?')
		message = _('Do you want delete User profile?')
		YesNoStage.__init__(self, message, self.yes_cb, self.no_cb, '', uiconfig.baloon_phone_setting_icon)

	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			rollback_profile_changes()
			runtime.manager.back_stage() 
			return True			
		return YesNoStage.handle_key(self, key)	
		
	def yes_cb(self):
		wifi_profile_general.reset()

		if config.KT_profile_enable == True :	# KT
			setting.megaAPEnabled = 1
		else :
			setting.megaAPEnabled = 0
		setting._save()
		 		

 		#stage = NewProfNotifyStage('custom profile deleted..', uiconfig.baloon_setting_system_reset_icon)
		stage = NewProfNotifyStage(_('User profile deleted'), uiconfig.baloon_setting_system_reset_icon)
		
		runtime.manager.change_stage(stage)		

	def no_cb(self):
		runtime.manager.back_stage() 	
		
class  WirelessScanWaitStage(NotifyStage):
	domonitor_forbidden = True
	# finishing wireless configuration and going next step(IP setting)
	def __init__(self):
#		NotifyStage.__init__(self, _('Please wait...'), uiconfig.baloon_wifi_icon, duration = config.a_moment, cb = self.next_cb)
		NotifyStage.__init__(self, _('Please wait...'), uiconfig.baloon_wifi_icon, duration = config.a_moment, cb = self.next_cb)

	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			#rollback_profile_changes()
			runtime.manager.back_stage() 
			return True			
		return NotifyStage.handle_key(self, key)	
		
	def next_cb(self):
		if not wlAvailable():
			#os.system('wlstart')
			#cmd =  'ifconfig wlan0 down'
			#os.system(cmd)
			cmd = 'wifi_driver_loading'
			os.system(cmd)
		stage=SearchingAp
		runtime.manager.back_stage()
		runtime.manager.stack_stage(stage)
		
class EntryUI2(SmallWindowUI):
	def __init__(self, left, right, title, subtitle, ismms=False, menu3='', menu4='', need_hangul=True):
		self.ismms = ismms
		self.need_hangul = need_hangul

		print 'NEED HANGUL', self.need_hangul
		SmallWindowUI.__init__(self, left, right, title, subtitle, menu3, menu4)
		width, height = uiconfig.entry_size
		import entry
		self.entry = entry.Entry(pos = uiconfig.entry_pos, size=uiconfig.entry_size)
		self.entry.add_callback(self.entry.AutomataChanged, self.update_automata_icon)

		# shchun: Korean version doesn't need euro alphabet.
		#		in order to prevent euc-kr encodings...
		self.entry.ascii_mode_case0 = True	
		self.add(self.entry)

		pos = uiconfig.entry_info_pos
		font = uiconfig.entry_info_font
		color = uiconfig.entry_info_color
		self.einfo = widget.OutlineLabel('', font, pos, color, align=uiconfig.ALIGN_RIGHT)
		self.add(self.einfo)

		self.t9mode = False
		self.automata_icon = None
		self.automata_idx = 1
		#if setting.lang == 'Korean':	
		#	self.automata = config.automata_list_hangul[self.automata_idx]		
		#else:	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]	

		self.def_left = left
		self.def_right = right
		self.fixed_automata = False

		self.symbol_stage_timer = None
		
		self.set_fixed_automata( '123', 'lower')

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		SmallWindowUI.destroy(self)
		self.symbol_stage_timer = None

	def show(self):	
		if self.automata_icon: self.automata_icon.show()
		SmallWindowUI.show(self)

		self.automata_idx = 0
		#if setting.lang == 'Korean':	
		#	self.automata = config.automata_list_hangul[self.automata_idx]		
		#else:	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]	

		if self.entry.length() == 0:
			self.set_right('')
		else:
			self.set_right(_('DEL'))

	def hide(self):
		if self.automata_icon: self.automata_icon.hide()
		SmallWindowUI.hide(self)

	def set_subtitle(self, text):
		self.subtitle.text = text

	def set_max(self, max=-1):
		self.entry.set_max(max)
		self.update_entry_info()

	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			#self.set_right(_(right_field))
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata())

	def set_automata(self, name, casemode='lower'):
		self.automata = name, casemode
		self.entry.set_automata(name, casemode)
		if name == 't9':
			self.t9mode = True
		else:
			self.t9mode = False
			
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)


	def update_automata_icon(self):
		name = self.entry._automata.name()		
		casemode = self.entry._automata.case_mode()
		self.automata = name, casemode
		if config.mmi_debug: 
			print 'UserInfo:name=',name,',casemode=',casemode
		print '####update_automata_icon UserInfo:name=',name,',casemode=',casemode	
		menu3 = ''
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'symbol':	menu3 = _('SYMBOL')
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
		if name =='symbol': # 'CHECKME:  when it runs
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
		print '#### UPDATE AUTOMATA ICON', self.automata_idx, self.automata 		
	def get_text(self):
		return self.entry.get_text()

	def set_text(self, text):
		self.entry.set_text(text)
		self.update_entry_info()

	def insert_text(self, text):
	
		self.entry.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry._automata.check_start_of_sentance()
		self.update_entry_info()

	def delete_char(self):
		self.handle_key('\b')
		self.update_entry_info()

	def set_entry_info(self, text):
		self.einfo.set_text(text)
		
	def insert_symbol(self, s):
		before_text = self.entry.get_text()
		#self.insert_text(self.entry, s)
		self.insert_text(s)
		after_text = self.entry.get_text()
		runtime.manager.back_stage()
		
	def handle_key(self, keyname):
		#if keyname == config.Menu4 and self.right == _('DELETE'):
		#	self.delete_char()
		#	self.update_entry_info()
		#	return True
		if config.mmi_debug: 
			print '## keyname =', keyname
			print '## self.fixed_automata=', self.fixed_automata
		if keyname == 'CLR':
			if self.get_text() == '':
				runtime.manager.back_stage()
				return True
			self.delete_char()
			self.update_entry_info()
			return True
		elif keyname == config.Menu2:
			self.delete_char()
			self.update_entry_info()
			return True
		# KA: [20070831] hangul lvp-2000		
		elif keyname == config.Menu3 and not self.fixed_automata:
			if self.is_t9_add_word_mode():
				if config.mmi_debug: print 'is_t9_add_word_mode is True'
				return True
			if config.mmi_debug: 
				print '## org_idx=', self.automata_idx
			if setting.lang == 'Korean':	
				self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_hangul)	
				self.automata = config.automata_list_hangul[self.automata_idx]		
			else:		
				self.automata_idx = (self.automata_idx + 1) % len(config.automata_list)		
				self.automata = config.automata_list[self.automata_idx]	
			if config.mmi_debug: 
				print '## new idx=', self.automata_idx			
			self.automata_idx = utils.get_automata_idx(*self.automata)			
			if config.mmi_debug: 
				print '## self.automata=', self.automata, 'idx=', self.automata_idx
			self.set_automata(*self.automata)		
			return True
		# KA: [20070831] hangul lvp-2000	==	
	
		elif keyname == config.Menu2:
			self.reset_automata()
			from basemodel import Stage, SymbolSelectionStage
			if self.entry.ascii_mode_case0:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=0))
			elif self.entry.ascii_mode_case1:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=1))
			elif self.entry.ascii_mode_case2:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=2))
			elif self.entry.ascii_mode_case3:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=3))
			else:
				runtime.manager.stack_stage(SymbolSelectionStage(self, True))
				
			return self.entry.handle_key(keyname)
			
		elif keyname == config.Menu4:
			runtime.manager.back_stage()
			return True
# --- End of Adding

		if self.entry._automata.name() == 't9':
			if keyname == config.Menu2 and self.right == _('PREVIOUS'):
				automata = self.entry._automata
				automata.handle_previous()
				if automata.get_t9_objnum() == 1:
					self.set_right(_('DEL'))
				else:
					self.set_right(_('PREVIOUS'))

				if self.is_t9_add_word_mode():
					self.set_left(_('OK'))
				else:
					self.set_left(self.def_left)
				return True

			elif keyname == '*':
				self.entry._automata.handle_next()
				if self.entry._automata.get_t9_objnum() == 0:
					self.set_left(_('OK'))
				else:
					self.set_left(self.def_left)

				if self.entry._automata.get_t9_objnum() == 1:
					self.set_right(_('DEL'))
#ka...hangul 2007.01.25 
				elif self.entry._automata.get_t9_objnum() == 0:
					pass
# --- End of Adding
				else:
					self.set_right(_('PREVIOUS'))

				return True
		ret = self.entry.handle_key(keyname)
		if ret:
			self.update_entry_info()
		return ret

	def change_language(self):
		self.subtitle.text = self.subtitle.text

	def reset_automata(self):
		self.entry._automata.reset()

	def update_entry_info(self):
		if self.entry.get_max():
			#self.set_entry_info( '%d/%d' % (self.entry.length(), self.entry.get_max()) )
			self.set_entry_info( '%d/%d' % (self.entry.message_length_KT(), self.entry.get_max()) )
			
		if self.entry.length() == 0:
			self.set_right('')
		else:
			self.set_right(_('DEL'))


	def update_automata_icon_symbol(self):
		self.set_menu3(_('SYMBOL'))		
		self.automata_idx = self.get_automata_idx(*self.automata)
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]					
		self.set_automata(*self.automata)	
		from basemodel import SymbolSelectionStage
		runtime.manager.stack_stage(SymbolSelectionStage(self, True))
		
		print '#### UPDATE AUTOMATA ICON SYMBOL', self.automata_idx, self.automata 

	def get_automata_idx(self, name, casemode):
		print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i

class EntryStage2(Stage):
	def __init__(self, sub_label, title, left=_('OK'), right='', ismms=False, menu3='', menu4=_('BACK'), need_hangul=True):
		self.ui = EntryUI2(left, right, title, sub_label, ismms, menu3, menu4, need_hangul)
		self.set_fixed_automata(None, False)

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

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

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

	def set_fixed_automata(self, name, casemode):
		self.ui.set_fixed_automata(name, casemode)

	def t9_add_word(self, word):
		self.ui.entry.t9_add_word(word)
		self.ui.update_entry_info()

	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(NewProfNotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()

	def is_valid_email(self):
		t = self.ui.get_text()
		if t.find('@') >= 0 and t.find('.') >= 0:
			return True
		return False

	def activate_menu2(self):
		runtime.manager.back_stage()

	def handle_key(self, key):
		if key == config.Menu1 or key == 'OK':
#			if self.ui.is_t9_add_word_mode():
#				runtime.manager.stack_stage(T9AddWordStage(self))
#			else:
			self.ui.reset_automata()
			self.activate_menu1()
			return True
		elif key == config.Menu4:
			runtime.manager.back_stage()
			return True
		else:
			return self.ui.handle_key(key)
		return False

class ManualESSIDStage(EntryStage2):
	domonitor_forbidden = True
	def __init__(self):
		
		EntryStage2.__init__(self, _('SSID'), _('WIRELESS PROFILE'), need_hangul=False)
		self.ui.set_automata('multitap', 'lower')
		#self.set_fixed_automata( '123', 'lower')
		self.ui.set_max(32)
		self.flag = -1
		
		if wifi_profile_general.essid:
			self.ui.set_text(wifi_profile_general.essid)
			
	def get_automata_idx(self, name, casemode):
		#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i

	def handle_key(self, key):
		if key == config.Menu3:
			if config.mmi_debug: 
				print 'self.flag =', self.flag
				#print 'self.ui.list.entrys[self.ui.list.focus] = ', self.ui.list.entrys[self.ui.list.focus]
			if self.flag == 0:
				self.ui.set_automata('multitap', 'lower')
				#self.ui.update_automata_icon(self.ui.entry)
				self.ui.update_automata_icon()
				self.flag = 1
			elif self.flag == 1:
				self.ui.set_automata('123', False)
				#self.ui.update_automata_icon(self.ui.entry)
				self.ui.update_automata_icon()
				self.flag = 0
			else:
				# KA: [20070831] hangul lvp-2000
				# vpark 2006.08.28 automata	
				'''
				self.ui.automata_idx = utils.get_automata_idx(*self.ui.automata)
				if setting.lang == 'Korean':			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_hangul)	
					self.ui.automata = config.automata_list_hangul[self.ui.automata_idx]			
				else:			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list)	
					self.ui.automata = config.automata_list[self.ui.automata_idx]					
				'''
				print '### self.ui.automata', self.ui.automata
				self.ui.automata_idx = self.get_automata_idx(*self.ui.automata)
				self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
				self.ui.automata = config.automata_list_mult_num_symbol[self.ui.automata_idx]					

				if config.mmi_debug: 
					print '## self.ui.automata=', self.ui.automata
					print '## self.ui.automata[0]=', self.ui.automata[0]					
				
				if self.ui.automata[0] == 'symbol':
					self.ui.update_automata_icon_symbol()					
					self.re_draw = True
				else:
					self.ui.set_automata(*self.ui.automata)		
					#self.ui.update_automata_icon(self.ui.entry)
					self.ui.update_automata_icon()
				
				return True	
				# KA: [20070831] hangul lvp-2000 ==

		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			#rollback_profile_changes()
			runtime.manager.back_stage() 
			return True			
	
		return EntryStage2.handle_key(self, key)
		
	
	def activate_menu1(self):
		old_essid = wifi_profile_general.essid
		str_domain = self.ui.get_text()
		if len(str_domain) > 0:
			if old_essid != str_domain:
				status.profile_detail_changed = True
			wifi_profile_general.set_essid(str_domain)
			#wifi_profile_general.save() # need to remove
#			runtime.manager.change_stage(NewProfNotifyStage(_('Essid changed.'), uiconfig.baloon_wifi_icon))
			runtime.manager.change_stage(NewProfNotifyStage(_('SSID is changed'), uiconfig.baloon_wifi_icon))

		else:
			wifi_profile_general.set_essid(str_domain)
			#wifi_profile_general.save() # need to remove
			#runtime.manager.change_stage(NewProfNotifyStage(_('Essid deleted'), uiconfig.baloon_wifi_icon))	
			runtime.manager.change_stage(NewProfNotifyStage(_('SSID is deleted'), uiconfig.baloon_wifi_icon))

		return True

class ManualBSSIDStage(EntryStage):
	domonitor_forbidden = True
	# not used.
	def __init__(self):
		EntryStage.__init__(self, _('BSSID'), _('BSSID'))
		self.ui.set_automata('multitap', 'lower')
		self.ui.set_max(32)

		if wifi_profile_general.bssid:
			self.ui.set_text(wifi_profile_general.bssid)


	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			#rollback_profile_changes()
			runtime.manager.back_stage() 
			return True			
		return EntryStage.handle_key(self, key)	

		
	def activate_menu1(self):
		old_bssid = wifi_profile_general.bssid
		str_domain = self.ui.get_text()
		if len(str_domain) > 0:
			if old_bssid == str_domain:
				status.profile_detail_changed = True
			wifi_profile_general.set_bssid(str_domain)
			#wifi_profile_general.save() # need to remove
			#runtime.manager.change_stage(NewProfNotifyStage(_('Bssid changed.'), uiconfig.baloon_wifi_icon))
			runtime.manager.change_stage(NewProfNotifyStage(_('BSSID set'), uiconfig.baloon_wifi_icon))

		else:
			wifi_profile_general.set_bssid(str_domain)
			#wifi_profile_general.save() # need to remove			
			#runtime.manager.change_stage(NewProfNotifyStage(_('Bssid deleted'), uiconfig.baloon_wifi_icon))	
			runtime.manager.change_stage(NewProfNotifyStage(_('BSSID deleted'), uiconfig.baloon_wifi_icon))

		return True


class ManualBSSIDMacModeStage(Stage):
	domonitor_forbidden = True
	def __init__(self):

		self.mac_mode = False

		if wifi_profile_general.mac_mode_on == 'yes':
			self.mac_mode = True
		self.bssid = wifi_profile_general.bssid
		self.curfocus = 0
#		status.password_style = True

		self.ui = ManualBSSIDMacModeUI( _('OK'),'', _('WIRELESS PROFILE'), menu4= _('BACK'), mac_mode= self.mac_mode)
			
		self.ui.set_text(self.bssid)
		
	def destroy(self):
#		status.password_style = False
		Stage.destroy(self)	

	def show(self):
		self.ui.show()
		for ent in self.ui.list.entrys:
			ent.lostFocus()	
		self.ui.set_focus(self.curfocus)	
		self.ui.list.entrys[self.curfocus].showFocus()
		self.UpdateMenu2()

	def UpdateMenu2(self):
		print 'UPDATE MENU2', self.ui.list.focus
		if self.ui.list.focus == 1:
			self.ui.set_right(':')
		else:
			self.ui.set_right('')
			
	def isValidMac(self, mac):
		if len(mac) != 17:
			return False

		for i in mac:
			if '0123456789abcdefABCDEF:'.find(i) == -1:
				return False
				
		mlist = mac.split(':')

		if len(mlist) != 6:
			return False


		for item in mlist:
			if len(item) != 2:
				return False

		return True
			

	def handle_key(self,key):
		if key in (config.Menu1, 'OK') :
			print 'mac_mode:', self.ui.list.entrys[0].get_text()
			print 'bssid:', self.ui.list.entrys[1].get_text()

			macmode = self.ui.list.entrys[0].get_text()
			bssid =  self.ui.list.entrys[1].get_text()

			#print 'bssid --', len(bssid),  len(bssid.split(':'))
			if len(bssid) == 0 and macmode != _('Settings.'):
				pass
			elif not self.isValidMac(bssid):
				runtime.manager.stack_stage(NewProfNotifyStage(_('aa:bb:cc:dd:ee:ff format(combination of hex and :) required'), uiconfig.baloon_wifi_icon))
				return

			#if macmode == 'YES':
			if macmode == _('Settings.'):

				wifi_profile_general.mac_mode_on= 'yes'
				wifi_profile_general.bssid = bssid
				#wifi_profile_general.save()
				runtime.manager.change_stage(NewProfNotifyStage(_('BSSID set'), uiconfig.baloon_wifi_icon))

			else:
				wifi_profile_general.mac_mode_on= 'no'
				wifi_profile_general.bssid = bssid
				#wifi_profile_general.save()
				runtime.manager.change_stage(NewProfNotifyStage(_('BSSID disabled'), uiconfig.baloon_wifi_icon))
			return True	
		elif key in ('Up', 'Down'):
			ret = self.ui.handle_key(key)			
			for ent in self.ui.list.entrys:
				ent.lostFocus()				
			self.ui.list.entrys[self.ui.list.focus].showFocus()	
			self.UpdateMenu2()
		elif key in ('Left', 'Right'):
			ret = self.ui.handle_key(key)	
			return ret
#		elif key == config.Menu4 or key == config.Red:
#			runtime.manager.back_stage()			
#			return False

		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
			
		elif key == config.Menu4:
			#rollback_profile_changes()
			runtime.manager.back_stage() 
			return True			

		elif key == config.Menu2:
			if self.ui.list.focus == 1:
				self.ui.list.entrys[1].insert_unicode_text(unicode(':', 'utf-8'))
			# input ':'
		elif key == config.Menu3:
			self.ui.update_automata()
		elif key == 'CLR':	
			#self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			print 'FOCUS', self.ui.list.focus 
			if self.ui.list.focus == 1:
				if len(self.ui.list.entrys[self.ui.list.focus].get_text()) > 0:
					self.ui.list.entrys[self.ui.list.focus].backspace(1)
				else:
					runtime.manager.back_stage()
			else:
				runtime.manager.back_stage()
			return True	
		else:
			ret = self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			return ret

			

class ManualBSSIDMacModeUI(baseui.BaseUI):
	def __init__(self, left, right, title, menu3='123', menu4='', titleimage=None, icon=None, mac_mode=False):
		baseui.BaseUI.__init__(self, left, right, title, menu3, menu4)
		self.list = None	

		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 2

		self.lblkey = []
		self.keylist = []

		#choose_bit = ('YES', 'NO')
		choose_bit = (_('Settings.'), _('Disable'))
		
		lbl_group = controls.Label_Control( _('MAC MODE'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)

		if mac_mode:
			group = controls.ListBox_Control(choose_bit,0, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		
		else:
			group = controls.ListBox_Control(choose_bit,1, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((lbl_group,group))
		
		tlabel = controls.Label_Control('BSSID' , font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		tinput = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		tinput.set_max(64)
		self.frame.append((tlabel, tinput))

		unselbarpos = []
		self.set_list(self.frame, unselbarpos)
		
		self.set_automata('123', False)	
	
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = ManualBSSIDMacModeWidget(frame, unselbarpos)
		self.add(self.list)
		
	def set_text(self, str):
		self.list.entrys[1].set_text(str)

	def get_text(self):
		return self.list.entrys[1].get_text()
		
	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		#print 'ka...## call set focus'
		self.list.set_focus(focus)

	def update_automata(self):
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num)
		self.automata = config.automata_list_mult_num[self.automata_idx]	
		print 'update_automata', config.automata_list_mult_num
		print 'automata', self.automata
		self.set_automata(*config.automata_list_mult_num[self.automata_idx])
		
	def set_automata(self, name, casemode='lower'):
		self.list.entrys[1].set_automata(name, casemode)
		self.automata = name, casemode
		self.set_menu3()
		
	def set_menu3(self):
		print '### MENU3 set_text', self.automata

		if self.automata[0] == '123':		menu3 = '123'
		elif self.automata[0] == 'hangul':	menu3 = _('KOR')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'lower':			menu3 = _('abc')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'upper':			menu3 = _('ABC')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'first capital':	menu3 = _('Abc')
		else:						menu3 = _('SYMBOL')
		runtime.menu3.set_text(menu3)	
		
	def handle_key(self, key):	

		if key == 'Up':
			self.list.focus_up()			
			return True
		elif key == 'Down':
			self.list.focus_down()			
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			return ret
		# KA: [20080412] ==

import widget		
class ManualBSSIDMacModeWidget(widget.Widget):
	def __init__(self, frame, unselbarpos=[]):
		self.unselbarpos = unselbarpos
		import status
		widget.Widget.__init__(self)
		self.icon_columns = []
		self.scroll_bg = None
		self.scroll_ball = None

#		self.choose = [_('MAC MODE'), _('BSSID')]
		self.choose = [_('BSSID mode'), _('BSSID')]

#		self.choose = ( _('Set'), _('Number') + '1', _('Number') + '2')
		self.labels = []
		self.entrys = []
		for lst in frame:
			self.labels.append(lst[0])
			self.entrys.append(lst[1])
		
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		self.top_index = 0		
		self.focus = -1
		x = uiconfig.pb_entry_pos_x + 50 -20

		self.nrow = nrow = len(self.labels)
		if nrow == 0:		pos_y = []
		elif nrow == 1:	pos_y = uiconfig.pb_entry_pos_y1
		elif nrow == 2:	pos_y = uiconfig.pb_entry_pos_y2
		elif nrow == 3:	pos_y = uiconfig.pb_entry_pos_y3
		elif nrow == 4:	pos_y = uiconfig.pb_entry_pos_y4
		elif nrow == 5:	pos_y = uiconfig.pb_entry_pos_y5
		else:			pos_y = uiconfig.pb_entry_pos_y6
			
#		x = uiconfig.list_pos_x
		self.pos_y = pos_y
		
		i =0
		while i < len(self.labels):			
			self.children.append(self.labels[i])	
			self.children.append(self.entrys[i])			
			i += 1
			
		for i, y in enumerate(pos_y):	
			self.labels[i].set_position(x-130, y+16-uiconfig.input_font[1]/2-2)
			self.labels[i].set_text(self.choose[i])			
			self.labels[i].show()
			self.entrys[i].setPosition(x, y)
			self.entrys[i].show()
			
		if nrow > 6: # draw scroll arrow
			self.scroll_bg = utils.put_image('scroll_bg.png',(444,45),(4, 192))			
			self.scroll_bg.hide()
			self.scroll_ball = utils.put_image('scroll_ball.png',(444,47),(4,int(192/len(self.labels))))
			self.scroll_bg.hide()
			self.children.append(self.scroll_bg)
			self.children.append(self.scroll_ball)
		
		self.set_focus(0)
		
	def set_focus(self, focus):
		import status
		if self.nrow == 0:
			return

		if self.focus == -1:
			selected_olditem = False
		else:
			selected_olditem = True

		if focus < 0:
			focus = self.nrow + focus
			
		hi_index = focus - self.top_index
		
		if hi_index < 0 or len(self.pos_y) <= hi_index:
			if hi_index < 0:
				self.top_index += hi_index
			else:
				self.top_index += hi_index - len(uiconfig.list_pos_y6) + 1	
			i =0
			while i < len(self.labels):			
				self.labels[i].hide()
				self.entrys[i].hide()
				i += 1
			x = uiconfig.pb_entry_pos_x
			for i, y in enumerate(self.pos_y):	
				self.labels[i+self.top_index].set_position(uiconfig.input6p_x2, y+16-uiconfig.input_font[1]/2-2)
				self.labels[i+self.top_index].set_text(self.choose[i+self.top_index])
				self.labels[i+self.top_index].show()				
				self.entrys[i+self.top_index].setPosition(x, y)
				self.entrys[i+self.top_index].show()
				
		self.focus = focus
		
		if len(self.labels) > 6:
			self.scroll_ball.move(444,int(192/len(self.labels)) + self.focus *  int(192/len(self.labels)) + 47 - int(192/len(self.labels)) )	
	
	def focus_up(self):
		if self.focus > 0:
			self.set_focus(self.focus - 1)
		else:
			self.set_focus(self.nrow - 1)
	
	def focus_down(self):
		if self.focus < len(self.labels) - 1:
			self.set_focus(self.focus + 1)
		else:
			self.set_focus(0)
			
	def show(self):
		#self.set_focus(self.focus)
		widget.Widget.show(self)
		i =6
		while i < len(self.labels):
			self.labels[i].hide()
			self.entrys[i].hide()
			i += 1
			
	def hide(self):
		#self.remove_item_scroll_timer()
		widget.Widget.hide(self)

	def free(self):
		#self.remove_item_scroll_timer()
		widget.Widget.free(self)
	#-----------------------------

## SOIP ##

class SoIPBSSIDMacModeStage(Stage):
	domonitor_forbidden = True
	def __init__(self):

		self.mac_mode = False

		if wifi_profile_kt_default.mac_mode_on == 'yes':
			self.mac_mode = True
			self.old_mac_mode = True
		else:
			self.mac_mode = False
			self.old_mac_mode = False
		
		self.bssid = wifi_profile_kt_default.bssid
		self.old_bssid = wifi_profile_kt_default.bssid
		self.curfocus = 0
#		status.password_style = True

		self.ui = SoIPBSSIDMacModeUI( _('OK'),'', '', menu4= _('BACK'), mac_mode= self.mac_mode)
			
		self.ui.set_text(self.bssid)
		
	def destroy(self):
#		status.password_style = False
		Stage.destroy(self)	

	def show(self):
		self.ui.show()
		for ent in self.ui.list.entrys:
			ent.lostFocus()	
		self.ui.set_focus(self.curfocus)	
		self.ui.list.entrys[self.curfocus].showFocus()
		self.UpdateMenu2()

	def UpdateMenu2(self):
		print 'UPDATE MENU2', self.ui.list.focus
		if self.ui.list.focus == 1:
			self.ui.set_right(':')
		else:
			self.ui.set_right('')

	def isValidMac(self, mac):
		if len(mac) != 17:
			return False

		for i in mac:
			if '0123456789abcdefABCDEF:'.find(i) == -1:
				return False
				
		mlist = mac.split(':')

		if len(mlist) != 6:
			return False


		for item in mlist:
			if len(item) != 2:
				return False

		return True
					
	def handle_key(self,key):
		if key in (config.Menu1, 'OK') :
			print 'mac_mode:', self.ui.list.entrys[0].get_text()
			print 'bssid:', self.ui.list.entrys[1].get_text()
			macmode = self.ui.list.entrys[0].get_text()
			bssid =  self.ui.list.entrys[1].get_text()

			if len(bssid) == 0 and macmode != _('Settings.'):
				pass
			elif not self.isValidMac(bssid):
				runtime.manager.stack_stage(NewProfNotifyStage(_('aa:bb:cc:dd:ee:ff format(combination of hex and :) required'), uiconfig.baloon_wifi_icon))
				return

			if macmode == _('Settings.'): #'YES':
				wifi_profile_kt_default.mac_mode_on= 'yes'
			else:
				wifi_profile_kt_default.mac_mode_on= 'no'
			wifi_profile_kt_default.bssid = bssid
			wifi_profile_kt_default.save()

			if self.old_bssid != wifi_profile_kt_default.bssid or self.old_mac_mode != macmode:
				runtime.SoIP_changed = True
				
			#runtime.manager.change_stage(NewProfNotifyStage(_('Bssid changed.'), uiconfig.baloon_wifi_icon))
			runtime.manager.change_stage(NewProfNotifyStage(_('BSSID is changed'), uiconfig.baloon_wifi_icon))

		elif key in ('Up', 'Down'):
			ret = self.ui.handle_key(key)			
			for ent in self.ui.list.entrys:
				ent.lostFocus()				
			self.ui.list.entrys[self.ui.list.focus].showFocus()	
			self.UpdateMenu2()
		elif key in ('Left', 'Right'):
			ret = self.ui.handle_key(key)	
			return ret
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			#rollback_profile_changes()
			runtime.manager.back_stage() 
			return True	

		elif key == config.Menu2:
			if self.ui.list.focus == 1:
				self.ui.list.entrys[1].insert_unicode_text(unicode(':', 'utf-8'))
			# input ':'
		elif key == config.Menu3:
			self.ui.update_automata()
		elif key == 'CLR':	
			#self.ui.list.entrys[self.ui.list.focus].handle_key(key)

			print 'FOCUS', self.ui.list.focus 
			if self.ui.list.focus == 1:
				if len(self.ui.list.entrys[self.ui.list.focus].get_text()) > 0:
					self.ui.list.entrys[self.ui.list.focus].backspace(1)
				else:
					runtime.manager.back_stage()
			else:
				runtime.manager.back_stage()

		else:
			ret = self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			return ret

			

class SoIPBSSIDMacModeUI(baseui.BaseUI):
	def __init__(self, left, right, title, menu3='123', menu4='', titleimage=None, icon=None, mac_mode=False):
		baseui.BaseUI.__init__(self, left, right, '', menu3, menu4)
		self.list = None	

		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 2

		self.lblkey = []
		self.keylist = []

		#choose_bit = ('YES', 'NO')
		choose_bit = (_('Settings.'), _('Disable'))
			
		#lbl_group = controls.Label_Control( _('MAC MODE'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		lbl_group = controls.Label_Control(  _('BSSID mode'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)

		if mac_mode:
			group = controls.ListBox_Control(choose_bit,0, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		
		else:
			group = controls.ListBox_Control(choose_bit,1, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((lbl_group,group))
		
		tlabel = controls.Label_Control('BSSID' , font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		tinput = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		tinput.set_max(64)
		self.frame.append((tlabel, tinput))

		unselbarpos = []
		self.set_list(self.frame, unselbarpos)
		
		self.set_automata('123', False)	
	
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = SoIPBSSIDMacModeWidget(frame, unselbarpos)
		self.add(self.list)
		
	def set_text(self, str):
		self.list.entrys[1].set_text(str)

	def get_text(self):
		return self.list.entrys[1].get_text()
		
	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		#print 'ka...## call set focus'
		self.list.set_focus(focus)

	def update_automata(self):
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num)
		self.automata = config.automata_list_mult_num[self.automata_idx]	
		print 'update_automata', config.automata_list_mult_num
		print 'automata', self.automata
		self.set_automata(*config.automata_list_mult_num[self.automata_idx])
		
	def set_automata(self, name, casemode='lower'):
		self.list.entrys[1].set_automata(name, casemode)
		self.automata = name, casemode
		self.set_menu3()
		
	def set_menu3(self):
		print '### MENU3 set_text', self.automata

		if self.automata[0] == '123':		menu3 = '123'
		elif self.automata[0] == 'hangul':	menu3 = _('KOR')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'lower':			menu3 = _('abc')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'upper':			menu3 = _('ABC')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'first capital':	menu3 = _('Abc')
		else:						menu3 = _('SYMBOL')
		runtime.menu3.set_text(menu3)	
		
	def handle_key(self, key):	

		if key == 'Up':
			self.list.focus_up()			
			return True
		elif key == 'Down':
			self.list.focus_down()			
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			return ret
		# KA: [20080412] ==

import widget		
class SoIPBSSIDMacModeWidget(widget.Widget):
	def __init__(self, frame, unselbarpos=[]):
		self.unselbarpos = unselbarpos
		import status
		widget.Widget.__init__(self)
		self.icon_columns = []
		self.scroll_bg = None
		self.scroll_ball = None

		#self.choose = [_('MAC MODE'), _('BSSID')]
		self.choose = [_('BSSID mode'), _('BSSID')]


#		self.choose = ( _('Set'), _('Number') + '1', _('Number') + '2')
		self.labels = []
		self.entrys = []
		for lst in frame:
			self.labels.append(lst[0])
			self.entrys.append(lst[1])
		
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		self.top_index = 0		
		self.focus = -1
		x = uiconfig.pb_entry_pos_x + 50

		self.nrow = nrow = len(self.labels)
		if nrow == 0:		pos_y = []
		elif nrow == 1:	pos_y = uiconfig.pb_entry_pos_y1
		elif nrow == 2:	pos_y = uiconfig.pb_entry_pos_y2
		elif nrow == 3:	pos_y = uiconfig.pb_entry_pos_y3
		elif nrow == 4:	pos_y = uiconfig.pb_entry_pos_y4
		elif nrow == 5:	pos_y = uiconfig.pb_entry_pos_y5
		else:			pos_y = uiconfig.pb_entry_pos_y6
			
#		x = uiconfig.list_pos_x
		self.pos_y = pos_y
		
		i =0
		while i < len(self.labels):			
			self.children.append(self.labels[i])	
			self.children.append(self.entrys[i])			
			i += 1
			
		for i, y in enumerate(pos_y):	
			self.labels[i].set_position(x-130, y+16-uiconfig.input_font[1]/2-2)
			self.labels[i].set_text(self.choose[i])			
			self.labels[i].show()
			self.entrys[i].setPosition(x, y)
			self.entrys[i].show()
			
		if nrow > 6: # draw scroll arrow
			self.scroll_bg = utils.put_image('scroll_bg.png',(444,45),(4, 192))			
			self.scroll_bg.hide()
			self.scroll_ball = utils.put_image('scroll_ball.png',(444,47),(4,int(192/len(self.labels))))
			self.scroll_bg.hide()
			self.children.append(self.scroll_bg)
			self.children.append(self.scroll_ball)
		
		self.set_focus(0)
		
	def set_focus(self, focus):
		import status
		if self.nrow == 0:
			return

		if self.focus == -1:
			selected_olditem = False
		else:
			selected_olditem = True

		if focus < 0:
			focus = self.nrow + focus
			
		hi_index = focus - self.top_index
		
		if hi_index < 0 or len(self.pos_y) <= hi_index:
			if hi_index < 0:
				self.top_index += hi_index
			else:
				self.top_index += hi_index - len(uiconfig.list_pos_y6) + 1	
			i =0
			while i < len(self.labels):			
				self.labels[i].hide()
				self.entrys[i].hide()
				i += 1
			x = uiconfig.pb_entry_pos_x
			for i, y in enumerate(self.pos_y):	
				self.labels[i+self.top_index].set_position(uiconfig.input6p_x2, y+16-uiconfig.input_font[1]/2-2)
				self.labels[i+self.top_index].set_text(self.choose[i+self.top_index])
				self.labels[i+self.top_index].show()				
				self.entrys[i+self.top_index].setPosition(x, y)
				self.entrys[i+self.top_index].show()
				
		self.focus = focus
		
		if len(self.labels) > 6:
			self.scroll_ball.move(444,int(192/len(self.labels)) + self.focus *  int(192/len(self.labels)) + 47 - int(192/len(self.labels)) )	
	
	def focus_up(self):
		if self.focus > 0:
			self.set_focus(self.focus - 1)
		else:
			self.set_focus(self.nrow - 1)
	
	def focus_down(self):
		if self.focus < len(self.labels) - 1:
			self.set_focus(self.focus + 1)
		else:
			self.set_focus(0)
			
	def show(self):
		#self.set_focus(self.focus)
		widget.Widget.show(self)
		i =6
		while i < len(self.labels):
			self.labels[i].hide()
			self.entrys[i].hide()
			i += 1
			
	def hide(self):
		#self.remove_item_scroll_timer()
		widget.Widget.hide(self)

	def free(self):
		#self.remove_item_scroll_timer()
		widget.Widget.free(self)
	#---------------------------------
	# List Item 이 선택되었음	
class  PrevManualSecurityListStage(NotifyStage):
	#wireless
	domonitor_forbidden = True	
	duration = 500
	def __init__(self):
		set = wifi_profile_general.get_security_name()
		if set == 'OPEN':
			#message = _('Currently, you are using open mode')
			message = _('Security deactivated')
		elif set == 'WEP':
			#message = _('Currently, you are using WEP mode')
			message = _('WEP setting activated')
		elif set == 'WPA-PSK':
			#message = _('Currently, you are using WPA-PSK mode')
			message = _('WPA-PSK setting activated')
		else: # WPA2-PSK
			#message = _('Currently, you are using WPA2-PSK mode')
			message = _('WPA2-PSK setting activated')
		
		NotifyStage.__init__(self, message, uiconfig.baloon_phone_setting_icon, cb = self.next_cb, duration=1000)
		
	def next_cb(self):
		stage = ManualSecurityListStage
		runtime.manager.change_stage(stage)

		
class ManualSecurityListStage(ListStage):
	domonitor_forbidden = True
	icon= uiconfig.wifi_icon

	def __init__(self):
		self.title = _('WIRELESS PROFILE')
		#choice = _('Open mode'), _('WEP'), _('WPA-PSK'), _('WPA2-PSK')
		self.choice = _('No security'), _('WEP'), _('WPA-PSK'), _('WPA2-PSK')

		ListStage.__init__(self, self.choice)
		set = wifi_profile_general.get_security_name_simple()
		
		if set == 'OPEN':
			self.ui.set_focus(0)
		elif set == 'WEP':
			self.ui.set_focus(1)
		elif set == 'WPA-PSK':
			self.ui.set_focus(2)
		else: # WPA2-PSK
			self.ui.set_focus(3)
			
	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True			
		return ListStage.handle_key(self, key)
		
	def activate(self, index):
		if index == 0:
			if wifi_profile_general.encryption!='NONE' \
					or wifi_profile_general.authentication != 'NONE':
				status.profile_detail_changed = True
				
			wifi_profile_general.encryption='NONE'
			wifi_profile_general.authentication = 'NONE'
			#wifi_profile_general.save() # need to remove

			stage = WirelessManualConfFinStage
			runtime.manager.change_stage(stage)
		elif index == 1:
			stage = WEPSettingStage(None, is_manual = True)
			runtime.manager.stack_stage(stage)
		
		elif index == 2:
			stage = ManualWPAPSKSettingStage(wpa2=False)
			runtime.manager.stack_stage(stage)
		else: # index == 3
			stage = ManualWPAPSKSettingStage(wpa2=True)
			runtime.manager.stack_stage(stage)


def SearchingAp():
	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])

				info[5] = (str(rate)+'Mbps')
#WPA			
			# KA: [20080402] NEW WIFI AP
			#elif tline.find('WPA') >= 0:
			#	info[6] = 'wpa_ie'
# TKIP
#			elif tline.find('multicast') >= 0:
#				# 좌우 공백을 없앤 후
#				tline = tline.strip()
#				key, value = tline.split(':')
#				value = value[1:]
#				info.append(value)
# WPA-PSK
			elif tline.find('AKM') >= 0:
				# 좌우 공백을 없앤 후
				tline = tline.strip()
				key, value = tline.split(':')
				value = value[1:]
				info.append(value)
				
			elif tline.find('unicast') >= 0:
				# 좌우 공백을 없앤 후
				tline = tline.strip()
				key, value = tline.split(':')
				value = value[1:]
				if value == 'TKIP':
					info.append('TKIP')
				else:
					info.append('AES')
				#info.append(value)
			# KA: [20080402] NEW WIFI AP ==
		else:
		#if info[7] == '':
		#	info.pop()
		#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() == '' or wifi_info[z][1].strip()[0:4] == '\\x00' :
				del wifi_info[z]
				
		def get_power_level(pwr):
			val = abs(int(pwr))
			icon_idx=0
			if val == 0:				icon_idx=0
			elif 0 < val and val <= 55:	icon_idx=5
			elif 55 < val and val <= 65:	icon_idx=4
			elif 65 < val and val <= 75:	icon_idx=3
			elif 75 < val and val <= 85:	icon_idx=2
			else:					icon_idx=1
			return icon_idx
		def signalcmp(a1, a2):	
			return get_power_level(a2[3]) - get_power_level(a1[3]) 
		wifi_info.sort(signalcmp)
		
		return wifi_info

	try:
	#if 1:	
		# shchun : even if not wifi profile you can get into here. remove restriction
		# shchun : remove restart interface -- May 2nd --

#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)
		#print 'ka........scan_info=', scan_info
		if scan_info != []:
			cwifi = len(scan_info)
			lists = []
			for z in range(cwifi):
				'''
				if len(scan_info[z]) == 8: #길이가 8 -- WPA-PSK / WPA-PSK2
					if scan_info[z][7] == 'WPA-PSK':				
						list_value = scan_info[z][1] + '('+_('Channel')+': ' + scan_info[z][2] + ', ' + _('WPA-PSK') + ')'
					else:
						list_value = scan_info[z][1] + '('+_('Channel')+': ' + scan_info[z][2] + ', ' + _('WPA2-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] + ')'
				'''
				list_value = scan_info[z][1] 
				lists.append(list_value)
				
			return WirelessInfoStage(lists, scan_info)
		else:
			#return NewProfNotifyStage(_('No AP found.'), uiconfig.baloon_wifi_icon)
			return NewProfNotifyStage(_('Cannot find available AP'),  uiconfig.baloon_wifi_icon)

	#if 0:
	except:
		debugLogC('Wireless profile.exception')	
		#return NewProfNotifyStage(_('Wireless profile error.'), uiconfig.baloon_wifi_icon)
		return NewProfNotifyStage(_('Wireless profile error'), uiconfig.baloon_wifi_icon)
		

		
class  WirelessInfoStage(ListCalendarStage):
	#title = _('Scan wireless connection') #_('Wireless SCANNING')
	#titleimage=uiconfig.title_wireless_profile_setting
	domonitor_forbidden = True	
	title = _('WIRELESS PROFILE')
	#icon = uiconfig.wifi_icon
	def __init__(self, lists, wifi_info):
		#ListCalendarStage.__init__(self, lists, left=_('CONNECT'), right=_('DETAILS'), menu3=_('REFRESH'), num_col =False, x= uiconfig.scan_list_pos_x)
		ListCalendarStage.__init__(self, lists, left=_('CONNECT'), right=_('DETAILS'), menu3=_('REFRESH'),  x= uiconfig.scan_list_pos_x,title=self.title)
		
		self.wifi_info = wifi_info
		self.icon_cols = []
		self.refresh_lists()

	def refresh_lists(self):
		self.ui.remove_all_icon_columns()
		enc_icons = []
		channel_icons = []
		power_icons = []

		for i in range(len(self.wifi_info)):
			sel_info = self.wifi_info[i]	
			#print 'sel_info=', sel_info
			if len(sel_info) == 8: #길이가 8 -- WPA-PSK / WPA-PSK2
				if sel_info[7] == 'WPA-PSK':				
					enc_icons.append(uiconfig.list_icon_wpa_scan)
				else:
					enc_icons.append(uiconfig.list_icon_wpa2_scan)

			elif len(sel_info) == 10: #길이가 10 -- WPA-PSK-TKIP
				enc_icons.append(uiconfig.list_icon_wpa_scan)

			elif sel_info[4] == 'on':  # wep
				enc_icons.append(uiconfig.list_icon_wep_scan)
			else:
				enc_icons.append(None)

			if sel_info[2]:
				chn =  int(sel_info[2])
				#print 'channel no ', chn
				channel_icons.append(uiconfig.list_icon_channel_scan[chn-1])
			else:
				channel_icons.append(None)

			power_icons.append(self.get_power_icons(int(sel_info[3])))

		self.ui.create_icon_column( uiconfig.scan_list_enc_icon_x, enc_icons)
		self.ui.create_icon_column( uiconfig.scan_list_channel_icon_x, channel_icons)
		self.ui.create_icon_column( uiconfig.scan_list_power_icon_x, power_icons)
		#print enc_icons
		#print channel_icons
		#print power_icons
		
	def get_power_icons(self, pwr):
		val = abs(int(pwr))
		icon_idx=0
		if val == 0:				icon_idx=0
		elif 0 < val and val <= 55:	icon_idx=5
		elif 55 < val and val <= 65:	icon_idx=4
		elif 65 < val and val <= 75:	icon_idx=3
		elif 75 < val and val <= 85:	icon_idx=2
		else:					icon_idx=1

		return uiconfig.list_icon_wifipower_scan[icon_idx]


	def handle_key(self, key):
		index = self.ui.get_focus()
		if key in (config.Menu1, 'OK'):
			index = self.ui.get_focus()
			self.activate(index)
		elif key == config.Menu2:
			#stage = InfoShowStage(self.wifi_info[index], self.need_macmode(index))
			stage = InfoShowStage(self.wifi_info[index])
			
			runtime.manager.stack_stage(stage)
			return True
		elif key == config.Menu3:
			# refresh list
			stage = WirelessScanWaitStage
			runtime.manager.change_stage(stage)

			return True
		elif key == config.Menu4:
			# back_stage.
			runtime.manager.back_stage()

			return True
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.CLEAR:
			runtime.manager.back_stage() 
			return True			
		else:
			return ListCalendarStage.handle_key(self, key)

	def need_macmode(self, index):
		select_info = self.wifi_info[index]
		mac_mode = 'no'
		for z in range(len(self.wifi_info)):
			debugLogN('*index (%d) ssid (%s)'%(z, self.wifi_info[z][1]))
			if index != z and self.wifi_info[z][1] == select_info[1]:
				mac_mode = 'yes'
		debugLogN('need_macmode (%s)'%(mac_mode))
		return mac_mode
		
	def activate(self, index):
		sel_info = self.wifi_info[index]
		print 'WifiInfoStage.activate()', sel_info 

		if len(sel_info) == 10: #길이가 10 -- WPA-PSK-TKIP
			# WPA-PSK-TKIP
			print 'WPA-PSK configuration'
			stage = WPAPSKSettingStage(sel_info,mac_mode= self.need_macmode(index) )
			runtime.manager.stack_stage(stage)				
		elif len(sel_info) == 8:
			if sel_info[7] == 'WPA-PSK':
				print 'WPA-PSK configuration'
				stage = WPAPSKSettingStage(sel_info,mac_mode= self.need_macmode(index) )
				runtime.manager.stack_stage(stage)				
			elif sel_info[7] == 'WPA2-PSK':
				print 'WPA2-PSK configuration'
				stage = WPAPSKSettingStage(sel_info, wpa2=True,mac_mode=self.need_macmode(index) )
				runtime.manager.stack_stage(stage)	
			elif sel_info[7] == 'WPA':
				print 'WPA configuration'
				#runtime.manager.stack_stage(NewProfNotifyStage(_('WPA-1x is not supported'), uiconfig.baloon_wifi_icon))
				runtime.manager.stack_stage(NewProfNotifyStage(_('WPA-1X is not supported'), uiconfig.baloon_wifi_icon))

			elif sel_info[7] == 'WPA2':
				print 'WPA2 configuration'
				#runtime.manager.stack_stage(NotifyStage(_('WPA2-1x is not supported'), uiconfig.baloon_wifi_icon))			
				runtime.manager.stack_stage(NewProfNotifyStage(_('WPA2-1X is not supported'), uiconfig.baloon_wifi_icon))

 			else:
 				print 'Exception case : this should not happen', sel_info
				runtime.manager.stack_stage(NewProfNotifyStage(_('Wifi error'), uiconfig.baloon_wifi_icon))
 		elif sel_info[4] == 'on':
 			print 'WEP key configuration'
			stage = WEPSettingStage(sel_info,self.need_macmode(index) )
			runtime.manager.stack_stage(stage)
			
 		else:
			print 'Open mode configuration'
			
			if wifi_profile_general.encryption!='NONE' \
					or wifi_profile_general.authentication != 'NONE':
				status.profile_detail_changed = True
				
			wifi_profile_general.set_scaninfo(sel_info, self.need_macmode(index))
			wifi_profile_general.encryption='NONE'
			wifi_profile_general.authentication = 'NONE'

			#wifi_profile_general.save() # need to remove
			stage = WirelessConfFinStage
			runtime.manager.change_stage(stage)
 		

class InfoShowStage(Stage):
	domonitor_forbidden = True
	def __init__(self, lists, is_kt_ap=False):
		self.is_kt_ap = is_kt_ap
		self.ui = InfoShowUI(lists, is_kt_ap)
		self.wifi_info = lists
		print '   SELF.LIST:', lists

	def handle_key(self, key):
		# shchun : infomation view only. logic about net setting removed 
		if key == config.Menu4 or key == config.CLEAR: #Red:
			runtime.manager.back_stage()
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		else:
			return False
		return True


class DynInfoShowStage(InfoShowStage):
	domonitor_forbidden = True
	def __init__(self, lists, mode = 0, num = 1, is_kt_ap = 0):
		self.lists = lists
		self.mode = mode
		self.num = num
		self.is_kt_ap = is_kt_ap
		#InfoShowStage.__init__(self, lists, self.is_kt_ap)

		self.ui = InfoShowUI2(lists, is_kt_ap)

 		self.profile_timer = utils.Timer(3*1000, self.refresh_info)
		self.refresh_info()
		self.ui.set_left(_('Wireless info'))
		print '   SELF.LIST:', self.lists
	
	def handle_key(self, key):
		if key == config.Menu3:
			self.refresh_info()
			return True

		elif key in (config.Menu1, 'OK') :
			stage = NetInfoStage
			runtime.manager.change_stage(stage)

		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False	
			
		else:
			InfoShowStage.handle_key(self, key)
		
	def refresh_info(self):
		os.system('wlrssi')
		fp = open('/tmp/tmpRSSI')
		ap_sens  = fp.read()
		self.lists[3] = ap_sens.strip()

		#print 'LIST = ', self.lists

		if not self.ui:
			return False
		self.ui.destroy()
		self.ui=None
		self.ui = InfoShowUI2(self.lists, self.is_kt_ap)
		self.ui.set_left(_('Wireless info'))
		#self.small_title = _('refreshing by every 10 sec')
		self.small_title =_('Refreshed once per 3 sec')

		import widget
		#pos = uiconfig.large_window_title_pos
		pos = (78+20, 10) 
		
		font = uiconfig.large_window_title_font
		color = uiconfig.large_window_title_color
		stitle = widget.OutlineLabel(self.small_title,font,pos,color,align=uiconfig.ALIGN_LEFT)
		self.ui.add(stitle)	

		self.show()
		print 'refresh info!!!'
		return True
		
class NetInfoUI(baseui.LargeWindowUI):
	def __init__(self, status, mac, dhcp, ip, mask, gateway, dns1, dns2):
		baseui.LargeWindowUI.__init__(self, left=_('Wireless info'), menu4=_('BACK'), small_title=_('Wireless info'))
		self.status = status
		self.mac = mac
 		self.dhcp = dhcp
		self.ip = ip
		self.mask = mask
		self.gateway = gateway
		self.dns1 = dns1
		self.dns2 = dns2
		self.flist = True
		self.show_list()

	def show_list(self):

		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
#		t.text= _('Status: ') + self.status
#		po does not work, so used uniconfig
		t.text= _('Connection status') + self.status
		t.pos = uiconfig.networkdetail_text_pos[0]
		self.add(t)
	
		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('MAC: ') + self.mac
		t.pos = uiconfig.networkdetail_text_pos[1]
		self.add(t)
		
		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('DHCP: ') + self.dhcp
		t.pos = uiconfig.networkdetail_text_pos[2]
		self.add(t)

		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('IP address: ') + self.ip
		t.pos = uiconfig.networkdetail_text_pos[3]
		self.add(t)

		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('Subnet mask: ') + self.mask
		t.pos = uiconfig.networkdetail_text_pos[4]
		self.add(t)

		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('Gateway: ') + self.gateway
		t.pos = uiconfig.networkdetail_text_pos[5]
		self.add(t)

		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('DNS1: ') + self.dns1
		t.pos = uiconfig.networkdetail_text_pos[6]
		self.add(t)

		t = runtime.evas.text()
		t.font=uiconfig.details_font
		t.color=uiconfig.swver_details_color
		t.text= _('DNS2: ') + self.dns2
		t.pos = uiconfig.networkdetail_text_pos[7]
		self.add(t)

	def set_list(self, booln):
		self.hide()
		baseui.LargeWindowUI.__init__(self, '', _('BACK'), _('DETAILS'), _('DETAILS'))
		self.flist = booln
		self.show_list()
		self.show()


class NetInfoStage(Stage):
	domonitor_forbidden = True
	# shchun: from phonesetting. I added new copy in order to avoid possible conflict with admin coders. :>
	def __init__(self):

		cur_profile = wifi_profile
		msg_na = _('Not available')
		msg_status = _('Not connected') #_('disconnected')
 
		network_info = utils.get_address('wlan')
		if runtime.peek_wifilink():
			msg_status = _('WIFI Connection') # _('wireless connected')
		
		if network_info:				msg_mac = network_info[0][0]
		else:						msg_mac = msg_na

		if cur_profile.get_dhcp() == 1:	msg_dhcp = _('Yes')
		else:						msg_dhcp = _('No')

		if cur_profile.ipaddress:		msg_ipaddress = cur_profile.ipaddress
		else:						msg_ipaddress = msg_na

		if cur_profile.netmask:			msg_netmask = cur_profile.netmask
		else:						msg_netmask = msg_na

		if cur_profile.gateway:			msg_gateway = cur_profile.gateway
		else:						msg_gateway = msg_na

		# KA: [20080415]
		#if cur_profile.get_dhcp() == 1:
		#	msg_dns = dns_profile.dhcp_dns1
		#	msg_dns2 = dns_profile.dhcp_dns2
		#else:
		#	msg_dns = dns_profile.dns1
		#	msg_dns2 = dns_profile.dns2
		fp = open(config.dns_file, 'r')
		msg_dns = msg_dns2 = ''
		for z in fp.readlines():
			tmp_dns = z.split(' ')
			if tmp_dns[0] == 'nameserver':
				if msg_dns == '':
					msg_dns = tmp_dns[1].split()[0]
				else:
					msg_dns2 = tmp_dns[1].split()[0]
		fp.close()
		# KA: [20080415] ==

		if not msg_dns :
			msg_dns = msg_na
		if not msg_dns2 :
			msg_dns2 = msg_na

		if msg_dhcp == _('Yes'):
			try:
				get_prf = profile.get_profile()
				if get_prf == 1 and os.path.exists('/tmp/dhcpcd-eth0.info') == False:
					msg_ipaddress = msg_na
					msg_netmask = msg_na
					msg_gateway = msg_na
					msg_dns = msg_na
					msg_dns2 = msg_na
				elif get_prf == 2 and os.path.exists('/tmp/dhcpcd-wlan0.info') == False:
					msg_ipaddress = msg_na
					msg_netmask = msg_na
					msg_gateway = msg_na
					msg_dns = msg_na
					msg_dns2 = msg_na
				else:
					if get_prf == 1:
						fp = open('/tmp/dhcpcd-eth0.info')
					else:
						fp = open('/tmp/dhcpcd-wlan0.info')
					dhcpinfo = fp.readlines()

					for z in dhcpinfo:						
						if z.find('#') != -1:
							continue

						key, value = z.split('=')
						key = key.strip()

						if key == 'IPADDR':
							msg_ipaddress = value.strip()
						elif key == 'INTERFACE':
							value = value.replace("'",'')
							interface = value.strip()
						elif key == 'NETMASK':
							msg_netmask = value.strip()
						elif key == 'GATEWAY':
							msg_gateway = value.strip()

			except:
				print '!!! warning exception !!!'
				pass
				#print '/tmp/dhcpcd-eth0.info or /tmp/dhcpcd-wlan0.info not found'

		self.ui = NetInfoUI( msg_status, msg_mac, msg_dhcp, msg_ipaddress, msg_netmask, msg_gateway, msg_dns, msg_dns2)
		#self.ui.set_right(_('BACK'))
		self.ui.set_left(_('Wireless info'))

	def handle_key(self, key):
		if key == config.Menu4 or key == config.CLEAR: # config.Red:
			runtime.manager.back_stage()
			return True

		elif key in (config.Menu1, 'OK') :
			import profile, newprof
			is_kt_ap = False
			print '###' ,profile.wifi_profile._name, profile.wifi_profile.essid
			#if profile.wifi_profile.essid == 'KT_SoIP':
			if profile.wifi_profile._name == 'MegaAP':
				is_kt_ap = True
			stage = newprof.DynInfoShowStage(profile.wifi_profile.get_wifi(), is_kt_ap=is_kt_ap)
			runtime.manager.change_stage(stage)
			return True
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False

		else:
			return False

class InfoShowUI(baseui.LargeWindowMessageUI):
	def __init__(self, lists, is_kt_ap):
		self.lists = lists

		baseui.LargeWindowMessageUI.__init__(self, '', '', '', small_title=_('DETAILS'))

		baseui.BaseUI.set_menu4(self, _('BACK'))
		if not is_kt_ap:
			lt = runtime.evas.text(text=_('SSID:')+ ' ' + self.lists[1], font=uiconfig.details_font, pos=(20+60+20,60+20), color=uiconfig.list_text_color)
			self.add(lt)
		lt = runtime.evas.text(text=_('BSSID:')+ ' ' + self.lists[0], font=uiconfig.details_font, pos=(20+60+20,80+20), color=uiconfig.list_text_color)
		self.add(lt)
		#lt = runtime.evas.text(text=_('Channel ID:')+ ' ' + self.lists[2], font=uiconfig.details_font, pos=(20+60+20,100+20), 	color=uiconfig.list_text_color)
		lt = runtime.evas.text(text=_('Channel:')+ ' ' + self.lists[2], font=uiconfig.details_font, pos=(20+60+20,100+20), 	color=uiconfig.list_text_color)
		
		self.add(lt)
		#lt = runtime.evas.text(text=_('Signal level:')+ ' ' + self.lists[3], font=uiconfig.details_font, pos=(20+60+20,120+20), color=uiconfig.list_text_color)
		lt = runtime.evas.text(text=_('RSSI:')+ ' ' + self.lists[3] + 'dBm', font=uiconfig.details_font, pos=(20+60+20,120+20), color=uiconfig.list_text_color)
		self.add(lt)

		if not is_kt_ap:
			#lt = runtime.evas.text(text=_('Security:')+ ' ' + self.lists[4], font=uiconfig.details_font, pos=(20+60+20,140+20), color=uiconfig.list_text_color)
			lt = runtime.evas.text(text=_('Security:')+ ' ' + self.getSecurityName(), font=uiconfig.details_font, pos=(20+60+20,140+20), color=uiconfig.list_text_color)
			self.add(lt)
			#lt = runtime.evas.text(text=_('Bit rate:')+ ' ' + self.lists[5], font=uiconfig.details_font, pos=(20+60+20,160+20), color=uiconfig.list_text_color)
			lt = runtime.evas.text(text=_('Speed:')+ ' ' + self.lists[5], font=uiconfig.details_font, pos=(20+60+20,160+20), color=uiconfig.list_text_color)
			self.add(lt)

	def getSecurityName(self):
		sel_info = self.lists
		name = ''
		
		if len(sel_info) == 10: #길이가 10 -- WPA-PSK / WPA-PSK2
		#if len(sel_info) == 12: #길이가 10 -- WPA-PSK / WPA-PSK2		
			# WPA-PSK-TKIP
			name = 'WPA-PSK, TKIP'
		elif len(sel_info) == 8:
		#elif len(sel_info) == 9:
			#sel_info[6] == TKIP, selinfo[8] == TKIP 
			if sel_info[7] == 'WPA-PSK':
				name = 'WPA-PSK'				
				if sel_info[6] == 'TKIP':
					name = name + ', TKIP'
				else:
					name = name + ', AES'
				
			elif sel_info[7] == 'WPA2-PSK':
				name = 'WPA2-PSK'
				if sel_info[6] == 'TKIP':
					name = name + ', TKIP'
				else:
					name = name + ', AES'
					
			elif sel_info[7] == 'WPA':
				name = 'WPA'
			elif sel_info[7] == 'WPA2':
				name = 'WPA2'
 			else:
				# exception :this could not happen
				name = 'WPA'
 		elif sel_info[4] == 'on':
			name = 'WEP'
 		else:
			#name = 'OPEN'
			name = _('No security')
		return name

class InfoShowUI2(baseui.LargeWindowMessageUI):
	# purpose : dyn show...
	def __init__(self, lists, is_kt_ap):
		self.lists = lists

		#baseui.LargeWindowMessageUI.__init__(self, _('NEXT'), '',  '', small_title=_('DETAILS')) #'')
		#baseui.LargeWindowMessageUI.__init__(self, _('Wireless info'), '',  '', small_title=_('DETAILS')) #'')
		baseui.LargeWindowMessageUI.__init__(self, _('Wireless info'), '',  '', small_title=_('Wireless info')) #'')
		
		baseui.BaseUI.set_menu4(self, _('BACK'))
		if not is_kt_ap:
			lt = runtime.evas.text(text=_('SSID:')+ ' ' + self.lists[1], font=uiconfig.details_font, pos=(20+60+20,60+20), color=uiconfig.list_text_color)
			self.add(lt)
		else:
			lt = runtime.evas.text(text=_('SSID:')+ ' ' + _('Unknown'), font=uiconfig.details_font, pos=(20+60+20,60+20), color=uiconfig.list_text_color)
			self.add(lt)
		
		lt = runtime.evas.text(text=_('BSSID:')+ ' ' + self.lists[0], font=uiconfig.details_font, pos=(20+60+20,80+20), color=uiconfig.list_text_color)
		self.add(lt)
		#lt = runtime.evas.text(text=_('Channel ID:')+ ' ' + self.lists[2], font=uiconfig.details_font, pos=(20+60+20,100+20), 	color=uiconfig.list_text_color)
		lt = runtime.evas.text(text=_('Channel:')+ ' ' + self.lists[2], font=uiconfig.details_font, pos=(20+60+20,100+20), 	color=uiconfig.list_text_color)
		self.add(lt)
		#lt = runtime.evas.text(text=_('Signal level:')+ ' ' + self.lists[3], font=uiconfig.details_font, pos=(20+60+20,120+20), color=uiconfig.list_text_color)
		lt = runtime.evas.text(text=_('RSSI:')+ ' ' + self.lists[3] + 'dBm', font=uiconfig.details_font, pos=(20+60+20,120+20), color=uiconfig.list_text_color)
		self.add(lt)

		print 'INFO SHOW UI 2', wifi_profile_general.get_security_name()
		if not is_kt_ap:
			#lt = runtime.evas.text(text=_('Security:')+ ' ' + self.lists[4], font=uiconfig.details_font,
			lt = runtime.evas.text(text=_('Security:')+ ' ' + wifi_profile_general.get_security_name(), font=uiconfig.details_font, pos=(20+60+20,140+20), color=uiconfig.list_text_color)
			self.add(lt)
			#lt = runtime.evas.text(text=_('Speed')+ ' ' + self.lists[5], font=uiconfig.details_font, pos=(20+60+20,160+20), color=uiconfig.list_text_color)
			lt = runtime.evas.text(text=_('Speed:')+ ' ' + self.GetWifiType(self.lists[5]), font=uiconfig.details_font, pos=(20+60+20,160+20), color=uiconfig.list_text_color)
			self.add(lt)
		else:
			lt = runtime.evas.text(text=_('Security:')+ ' ' + _('Unknown'), font=uiconfig.details_font, pos=(20+60+20,140+20), color=uiconfig.list_text_color)
			self.add(lt)
			#lt = runtime.evas.text(text=_('Speed')+ ' ' + self.lists[5], font=uiconfig.details_font, pos=(20+60+20,160+20), color=uiconfig.list_text_color)
			lt = runtime.evas.text(text=_('Speed:')+ ' ' + self.GetWifiType(self.lists[5]), font=uiconfig.details_font, pos=(20+60+20,160+20), color=uiconfig.list_text_color)
			self.add(lt)
		
	def GetWifiType(self, str):
		try:
			ival = int(str.replace('Mbps', ''))

			if ival > 12:
				return '802.11g (54 Mbps)'
			else:
				return '802.11b (11 Mbps)'
		except:
			return ''

class  WirelessConfFinStage(NotifyStage):
	domonitor_forbidden = True
	# finishing wireless configuration and going next step(IP setting)
	duration = 1000
	def __init__(self):
		#NotifyStage.__init__(self, _('Please wait...'), uiconfig.baloon_wifi_icon, duration=1000, cb = self.next_cb)
		NotifyStage.__init__(self, _('Please wait...'), uiconfig.baloon_wifi_icon, duration=1000, cb = self.next_cb)

	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True			
		return NotifyStage.handle_key(self, key)		
		
	def next_cb(self):
		setting.megaAPEnabled = 0
 		setting._save()
 		
		print 'change to ip address setting'
		#runtime.manager.back_stage('setting stage')
		stage = IPSettingStage(manual=False)
		runtime.manager.change_stage(stage)


class  WirelessManualConfFinStage(NotifyStage):
	domonitor_forbidden = True
	# finishing wireless configuration and going next step(IP setting)
	duration = 1000
	def __init__(self):
		NotifyStage.__init__(self, _('Saved'), uiconfig.baloon_wifi_icon, duration=1000, cb = self.next_cb)

	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True			
		return NotifyStage.handle_key(self, key)	
		
	def next_cb(self):
		print 'change to ip address setting'
		runtime.manager.back_stage('wireless manual config')

		
class WEPSettingStage(Stage):
	domonitor_forbidden = True
	def __init__(self, sel_info, mac_mode='no', is_manual=False):
		self.apinfo = sel_info
		self.mac_mode = mac_mode
		self.weptype = 0
#		status.password_style = True
		self.is_manual = is_manual
		self.weptype = 0
		
		if wifi_profile_general.encryption == 'WEP64BIT':
			self.weptype = 0
			self.wepkeyno =  wifi_profile_general.wepkeyno_64
		else:
			self.weptype = 1
			self.wepkeyno = wifi_profile_general.wepkeyno_128

		self.wepkeyno = int(self.wepkeyno)
		print '### wepkeyno', self.wepkeyno
		self.ui = WEPSettingUI( _('OK'),'', '', menu4= _('BACK'), weptype =self.weptype, wepkeyno=self.wepkeyno)
		#self.ui.set_fixed_automata(self.ui.list.entrys[0],None, False)		
		
		self.onWepTypeChangedFillValue()
		self.ui.set_focus(0)
		self.curfocus = 0

		self.automata_idx = 2
		self.flag = -1
		
	def destroy(self):
#		status.password_style = False
		Stage.destroy(self)

	def onWepTypeChanged(self):
		if self.ui.get_focus() != 0:
			print 'onWepTypeChanged: return!! focus should be 0'
			return
		if self.ui.list.entrys[0].get_text() == '64bit':
			self.ui.list.entrys[1].set_max(10)
			self.ui.list.entrys[2].set_max(10)
			self.ui.list.entrys[3].set_max(10)
			self.ui.list.entrys[4].set_max(10)
			
		else: #'WEP128BIT' 'NONE'
			self.ui.list.entrys[1].set_max(26)
			self.ui.list.entrys[2].set_max(26)
			self.ui.list.entrys[3].set_max(26)
			self.ui.list.entrys[4].set_max(26)
			
		self.ui.list.entrys[1].set_text('')
		self.ui.list.entrys[2].set_text('')
		self.ui.list.entrys[3].set_text('')
		self.ui.list.entrys[4].set_text('')

		for ent in self.ui.list.entrys:
			ent.lostFocus()
		self.ui.list.entrys[0].showFocus()

		
	def onWepTypeChangedFillValue(self):
		if self.ui.get_focus() != 0:
			print 'onWepTypeChanged: return!! focus should be 0'
			return
		if self.ui.list.entrys[0].get_text() == '64bit':
			keyval = wifi_profile_general.wepkey1_64
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[1].set_text(keyval)
			self.ui.list.entrys[1].set_max(10)

			keyval = wifi_profile_general.wepkey2_64
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[2].set_text(keyval)
			self.ui.list.entrys[2].set_max(10)

			keyval = wifi_profile_general.wepkey3_64
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[3].set_text(keyval)
			self.ui.list.entrys[3].set_max(10)

			keyval = wifi_profile_general.wepkey4_64
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[4].set_text(keyval)
			self.ui.list.entrys[4].set_max(10)
			
		else: #'WEP128BIT' 'NONE'
			keyval = wifi_profile_general.wepkey1_128
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[1].set_text(keyval)
			self.ui.list.entrys[1].set_max(26)

			keyval = wifi_profile_general.wepkey2_128
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[2].set_text(keyval)
			self.ui.list.entrys[2].set_max(26)
			
			keyval = wifi_profile_general.wepkey3_128
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[3].set_text(keyval)
			self.ui.list.entrys[3].set_max(26)

			keyval = wifi_profile_general.wepkey4_128
			if keyval[:2] == '0x':
				keyval = keyval[2:]
			self.ui.list.entrys[4].set_text(keyval)
			self.ui.list.entrys[4].set_max(26)
		for ent in self.ui.list.entrys:
			ent.lostFocus()
		self.ui.list.entrys[0].showFocus()
		
	def update_automata(self):

		#print '### update_automata', self.ui.list.focus
		if self.ui.list.focus not in (1, 2, 3, 4):
			runtime.menu3.set_text('')
			return
		if self.ui.list.focus == 1:
			self.ui.set_fixed_automata(self.ui.list.entrys[1],'123', False)
		elif self.ui.list.focus == 2:
			self.ui.set_fixed_automata(self.ui.list.entrys[2],'123', False)	
		elif self.ui.list.focus == 3:
			self.ui.set_fixed_automata(self.ui.list.entrys[3],'123', False)	
		elif self.ui.list.focus == 4:
			self.ui.set_fixed_automata(self.ui.list.entrys[4],'123', False)	
		
		self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus],*self.ui.automata)
		self.set_menu3()	

	def get_automata_idx(self, name, casemode):
		#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i


	def set_menu3(self):
		try:
			if self.ui.automata[0] == '123':		menu3 = '123'
			elif self.ui.automata[0] == 'hangul':	menu3 = _('KOR')
			elif self.ui.automata[0] == 'multitap' and self.ui.automata[1] == 'lower':			menu3 = _('abc')
			elif self.ui.automata[0] == 'multitap' and self.ui.automata[1] == 'upper':			menu3 = _('ABC')
			elif self.ui.automata[0] == 'multitap' and self.ui.automata[1] == 'first capital':	menu3 = _('Abc')
			else:							menu3 = _('SYMBOL')
			runtime.menu3.set_text(menu3)	
			
		except:
			print 'EXCEPT: WEPSettingStage - set_menu3'
			runtime.menu3.set_text('')
			
	def show(self):
		self.ui.show()
		for ent in self.ui.list.entrys:
			ent.lostFocus()			
		self.ui.set_focus(self.curfocus)
		self.ui.list.entrys[self.curfocus].showFocus()	
		self.set_menu3()	
		
	def filter_keyval(self, keyval, is_128bit=True):
		iserror = False

		lval = len(keyval)
		if keyval == '':
			return keyval
		
		if is_128bit:
			if lval == 28: # for 28 char, string starts with '0x' is allowed, only. 
				if keyval[:2].lower() != '0x':
					#runtime.manager.stack_stage(NewProfNotifyStage(_('Input valid characters. You can input 26 hexadecimal characters or 13 alphanumeric characters'), uiconfig.baloon_wifi_icon))
					runtime.manager.stack_stage(NewProfNotifyStage(_('26 chars of hex string or 13 chars of ascii string required'), uiconfig.baloon_wifi_icon))
					return None
				
			elif lval == 26: # for 26 char, hex value is allowed, only.
				for i in keyval:
					if '0123456789abcdefABCDEF'.find(i) == -1:
						#runtime.manager.stack_stage(NewProfNotifyStage(_('Input valid characters. If you want input 26 characters, You must input hexadecimal characters.'), uiconfig.baloon_wifi_icon))						runtime.manager.stack_stage(NotifyStage(_('Input valid characters. If you want input 26 characters, You must input hexadecimal characters.'), uiconfig.baloon_wifi_icon))
						runtime.manager.stack_stage(NewProfNotifyStage(_('If you want to input hex string, 26 chars required.'), uiconfig.baloon_wifi_icon))
						return None
				keyval = '0x' + keyval
				lval = len(keyval)

			elif lval == 13: # for 13 char, ascii string is allowed, only.
				pass
			else:
				#runtime.manager.stack_stage(NewProfNotifyStage(_('Input valid characters. You can input 26 hexadecimal characters or 13 alphanumeric characters'), uiconfig.baloon_wifi_icon))
				runtime.manager.stack_stage(NewProfNotifyStage(_('26 chars of hex string or 13 chars of ascii string required'), uiconfig.baloon_wifi_icon))
				return None
			return keyval

		else: # 64bit
			if lval == 12: # for 12 char, string starts with '0x' is allowed, only. 
				if keyval[:2].lower() != '0x':
					#runtime.manager.stack_stage(NewProfNotifyStage(_('Input valid characters. You can input 10 hexadecimal characters or 5 alphanumeric characters'), uiconfig.baloon_wifi_icon))
					runtime.manager.stack_stage(NewProfNotifyStage(_('10 chars of hex string or 5 chars of ascii string required'), uiconfig.baloon_wifi_icon))
					return None
				
			elif lval == 10: # for 10 char, hex value is allowed, only.
				for i in keyval:
					if '0123456789abcdefABCDEF'.find(i) == -1:
						#runtime.manager.stack_stage(NewProfNotifyStage(_('Input valid characters. If you want input 10 characters, You must input hexadecimal characters.'), uiconfig.baloon_wifi_icon))
						runtime.manager.stack_stage(NewProfNotifyStage(_('If you want to input hex string, 10 chars required.'), uiconfig.baloon_wifi_icon))
						return None
				keyval = '0x' + keyval
				lval = len(keyval)

			elif lval == 5: # for 5 char, ascii string is allowed, only.
				pass
			else:
				#runtime.manager.stack_stage(NewProfNotifyStage(_('Input valid characters. You can input 10 hexadecimal characters or 5 alphanumeric characters'), uiconfig.baloon_wifi_icon))
				runtime.manager.stack_stage(NewProfNotifyStage(_('10 chars of hex string or 5 chars of ascii string required'), uiconfig.baloon_wifi_icon))
				return None
			return keyval
		
	
	def handle_key(self, key):
		# shchun : infomation view only. logic about net setting removed 
		if key in (config.Menu1, 'OK') :
			#print self.ui.list.entrys[0].get_text()
			#print self.ui.list.entrys[1].get_text()
			#print self.ui.list.entrys[2].get_text()
			#print self.ui.list.entrys[3].get_text()
			#print self.ui.list.entrys[4].get_text()
			#print self.ui.list.entrys[5].get_text()

			if self.ui.list.entrys[0].get_text() == '64bit':
				#print '### 64bit Key'
				if wifi_profile_general.encryption != 'WEP64BIT':
					status.profile_detail_changed = True
				wifi_profile_general.encryption = 'WEP64BIT'
				kval = [0,0,0,0]
				
				kval[0] =  self.filter_keyval(self.ui.list.entrys[1].get_text(), is_128bit=False)
				if kval[0] != None:
					if wifi_profile_general.wepkey1_64 != kval[0]:
						status.profile_detail_changed = True
				
					wifi_profile_general.wepkey1_64 = kval[0]
				else:
					self.curfocus = 1
					return
				#print '### Set Key 1'
				
				kval[1] =  self.filter_keyval(self.ui.list.entrys[2].get_text(), is_128bit=False)
				if kval[1] != None:
					if wifi_profile_general.wepkey2_64 != kval[1]:
						status.profile_detail_changed = True				

					wifi_profile_general.wepkey2_64 = kval[1]
				else:
					self.curfocus = 2
					return
				#print '### Set Key 2'
				
				kval[2] =  self.filter_keyval(self.ui.list.entrys[3].get_text(), is_128bit=False)
				if kval[2] != None:
					if wifi_profile_general.wepkey3_64 != kval[2]:
						status.profile_detail_changed = True				

					wifi_profile_general.wepkey3_64 = kval[2]
				else:
					self.curfocus = 3
					return
				#print '### Set Key 3'
				
				kval[3] =  self.filter_keyval(self.ui.list.entrys[4].get_text(), is_128bit=False)
				if kval[3] != None:
					if wifi_profile_general.wepkey4_64 != kval[3]:
						status.profile_detail_changed = True				
						
					wifi_profile_general.wepkey4_64 = kval[3]
				else:
					self.curfocus = 4
					return
				#print '### Set Key 4'

				print 'Keysl ==', kval
				idx = self.ui.list.entrys[5].get_text()
				ival = int(idx)
				if not kval[ival-1]:
					self.curfocus = ival
					#runtime.manager.stack_stage(NewProfNotifyStage(_('Key')+ idx +_('should not be empty. key selected by keyindex must be filled'), uiconfig.baloon_wifi_icon))	
					runtime.manager.stack_stage(NewProfNotifyStage(_('Key')+ idx + _(': You shuould fill selected key value'), uiconfig.baloon_wifi_icon))	
					return
				if wifi_profile_general.wepkeyno_64 != idx:
						status.profile_detail_changed = True				
						
				wifi_profile_general.wepkeyno_64 = idx
				#print '64bit Key set success'

			else:
				#print '### 128 bit Key'
				if wifi_profile_general.encryption != 'WEP128BIT':
					status.profile_detail_changed = True
				wifi_profile_general.encryption = 'WEP128BIT'
				kval = [0,0,0,0]
				
				kval[0] =  self.filter_keyval(self.ui.list.entrys[1].get_text(), is_128bit=True)
				if kval[0] != None:
					if wifi_profile_general.wepkey1_128 != kval[0]:
						status.profile_detail_changed = True				
				
					wifi_profile_general.wepkey1_128 = kval[0]
				else:
					self.curfocus = 1
					return
				#print '### Set Key 1'
				
				kval[1] =  self.filter_keyval(self.ui.list.entrys[2].get_text(), is_128bit=True)
				if kval[1] != None:
					if wifi_profile_general.wepkey2_128 != kval[1]:
						status.profile_detail_changed = True	
						
					wifi_profile_general.wepkey2_128 = kval[1]
				else:
					self.curfocus = 2
					return
				#print '### Set Key 2'
				
				kval[2] =  self.filter_keyval(self.ui.list.entrys[3].get_text(), is_128bit=True)
				if kval[2] != None:
					if wifi_profile_general.wepkey3_128 != kval[2]:
						status.profile_detail_changed = True	
						
					wifi_profile_general.wepkey3_128 = kval[2]
				else:
					self.curfocus = 3
					return
				#print '### Set Key 3'
				
				kval[3] =  self.filter_keyval(self.ui.list.entrys[4].get_text(), is_128bit=True)
				if kval[3] != None:
					if wifi_profile_general.wepkey4_128 != kval[3]:
						status.profile_detail_changed = True	

					wifi_profile_general.wepkey4_128 = kval[3]
				else:
					self.curfocus = 4
					return
				#print '### Set Key 4'
				
				print 'Keysl ==', kval
				idx = self.ui.list.entrys[5].get_text()
				ival = int(idx)
				if not kval[ival-1]:
					self.curfocus = ival
					#runtime.manager.stack_stage(NewProfNotifyStage(_('Key')+ idx +_('should not be empty. key selected by keyindex must be filled'), uiconfig.baloon_wifi_icon))	
					runtime.manager.stack_stage(NewProfNotifyStage(_('Key')+ idx + _(': You shuould fill selected key value'), uiconfig.baloon_wifi_icon))	
					return
				if wifi_profile_general.wepkeyno_128 != idx:
						status.profile_detail_changed = True	
						
				wifi_profile_general.wepkeyno_128 = idx
				#print '128bit Key set success'
			#wifi_profile_general.save()  # no use
			if self.apinfo:
				wifi_profile_general.set_scaninfo(self.apinfo, self.mac_mode)
			wifi_profile_general.authentication = 'OPEN'
			#wifi_profile_general.save()   # need to remove
			#WirelessManualConfFinStage
			if self.is_manual:
				stage = WirelessManualConfFinStage
			else:
 				stage = WirelessConfFinStage
			runtime.manager.change_stage(stage)
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True
			
			return False
#		elif key == config.Menu3:
#			if self.ui.list.focus in (1,2,3,4):	
#				#debugLogC('###menu3 before', self.automata_idx , self.ui.automata)
#				#self.ui.automata_idx = (self.ui.automata_idx) % len(config.automata_list_mult_num)
#				#self.ui.automata = config.automata_list_mult_num[self.ui.automata_idx]		
#				#self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus],*self.ui.automata)
#				self.automata_idx = (self.automata_idx+1) % len(config.automata_list_mult_num)
#				self.ui.automata = config.automata_list_mult_num[self.automata_idx]		
#				self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus],*self.ui.automata)
#				#debugLogC('###menu3 after', self.automata_idx , self.ui.automata)
#				self.set_menu3()

		elif key == config.Menu3:
			if self.ui.list.focus not in (1, 2, 3, 4):
				return True

			self.curfocus = self.ui.list.focus
			
			if config.mmi_debug: 
				print 'self.flag =', self.flag
				print 'self.ui.list.focus=',self.ui.list.focus
				#print 'self.ui.list.entrys[self.ui.list.focus] = ', self.ui.list.entrys[self.ui.list.focus]
			if self.flag == 0:
				self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus], 'multitap', 'lower')
				self.ui.update_automata_icon(self.ui.list.entrys[self.list.focus])
				self.flag = 1
			elif self.flag == 1:
				self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus], '123', False)
				self.ui.update_automata_icon(self.ui.list.entrys[self.list.focus])
				self.flag = 0
			else:
				# KA: [20070831] hangul lvp-2000
				# vpark 2006.08.28 automata	
				'''
				self.ui.automata_idx = utils.get_automata_idx(*self.ui.automata)
				if setting.lang == 'Korean':			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_hangul)	
					self.ui.automata = config.automata_list_hangul[self.ui.automata_idx]			
				else:			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list)	
					self.ui.automata = config.automata_list[self.ui.automata_idx]					
				'''

				self.ui.automata_idx = self.get_automata_idx(*self.ui.automata)
				self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
				self.ui.automata = config.automata_list_mult_num_symbol[self.ui.automata_idx]					

				if config.mmi_debug: 
					print '## self.ui.automata=', self.ui.automata
					print '## self.ui.automata[0]=', self.ui.automata[0]					
				
				if self.ui.automata[0] == 'symbol':
					self.ui.update_automata_icon_symbol()					
					self.re_draw = True
				else:
					self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus], *self.ui.automata)		
					self.ui.update_automata_icon(self.ui.list.entrys[self.ui.list.focus])
				
				return True	
				# KA: [20070831] hangul lvp-2000 ==

			
		elif key in ('Up', 'Down'):
			ret = self.ui.handle_key(key)			
			for ent in self.ui.list.entrys:
				ent.lostFocus()				
			self.ui.list.entrys[self.ui.list.focus].showFocus()	
			self.update_automata()
		elif key in ('Left', 'Right'):
			ret = self.ui.handle_key(key)
			self.onWepTypeChanged()
			return ret
		elif key == 'CLR':	
			#self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			print 'FOCUS', self.ui.list.focus 
			if self.ui.list.focus in (1,2,3,4):
				if len(self.ui.list.entrys[self.ui.list.focus].get_text()) > 0:
					self.ui.list.entrys[self.ui.list.focus].backspace(1)
				else:
					runtime.manager.back_stage()
			else:
				runtime.manager.back_stage()

		else:
			ret = self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			return ret			
		return True
		
class WEPSettingUI(baseui.BaseUI): # ListUI
	show_bg_depth = True
	def __init__(self, left, right, title, menu3='', menu4='', titleimage=None, icon=None, weptype=1, wepkeyno=0):		
		baseui.BaseUI.__init__(self, left, right, _('WIRELESS PROFILE'), menu3, menu4)
		self.list = None
		self.display_idx = 0
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		self.lblkey = []
		self.keylist = []

		choose_bit = ('64bit', '128bit')
		#lbl_group = controls.Label_Control( _('Set'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		lbl_group = controls.Label_Control( _('Settings.'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)

		group = controls.ListBox_Control(choose_bit,weptype, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((lbl_group,group))
		
		for i in range(4):
			#tlabel = controls.Label_Control('Key #%d'%i , font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
			tlabel = controls.Label_Control(_('Key %d')%i , font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
			tinput = controls.Input_Control(pos = (0,0), size=uiconfig.wep_entry_size)
			tinput.set_max(28)
			self.lblkey.append(tlabel)
			self.keylist.append(tinput)
			self.frame.append((tlabel, tinput))

		choose_key = ('1', '2', '3', '4')
		#self.lblkeyidx = controls.Label_Control('Key index', font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.lblkeyidx = controls.Label_Control(_('Key index'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.keyidx = 	controls.ListBox_Control(choose_key,wepkeyno-1, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((self.lblkeyidx, self.keyidx))
		unselbarpos = []
		self.set_list(self.frame, unselbarpos)

		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		self.set_fixed_automata(self.list.entrys[1], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[2], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[3], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[4], '123', 'lower')

		if self.list.focus in (1,2,3,4):
			self.update_automata_icon(self.list.entrys[self.list.focus])
			
	def find_pos(self,values,list):
		i = 0		
		for chk in list:
			if str(chk).lower() == str(values).lower():
				return i
			else:
				i = i + 1
		return 0
		
	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def update_automata_icon(self,entry):
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if config.mmi_debug: 
			print 'UserInfo:name=',name,',casemode=',casemode
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'symbol':	menu3 = _('SYMBOL')
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
		if name =='symbol': # 'CHECKME:  when it runs
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))

	def update_automata_icon_symbol(self):
		self.set_menu3(_('SYMBOL'))		
		self.automata_idx = self.get_automata_idx(*self.automata)
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]					
		self.set_automata(self.list.entrys[self.list.focus], *self.automata)	
		from basemodel import SymbolSelectionStage
		runtime.manager.stack_stage(SymbolSelectionStage(self, True))
		
	def get_current_names(self,image_list):		
		names = []
		for lst in image_list:
			name = lst
			dot = name.rfind('.')
			if dot >= 0:
				name = name[:dot]
			names.append(name)
		return names	
		
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = WEPSettingWidget(frame, unselbarpos)
		self.add(self.list)

	def update_lists(self, frame, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)		
		self.add(self.list)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		#pass
		return self.list.set_focus(focus)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def handle_key(self, key):		
		if key == 'Up':
			self.list.focus_up()			
			return True
		elif key == 'Down':
			self.list.focus_down()			
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			if self.list.focus not in (1, 7, 8, 9, 10):
				return ret
			current_dir_index = self.list.entrys[self.list.focus].index

			return ret
		# KA: [20080412] ==
		return False

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()		
		baseui.BaseUI.destroy(self)

	def hide(self):
		baseui.BaseUI.hide(self)
		
	def show(self):
		#if self.automata_icon: self.automata_icon.show()
		baseui.BaseUI.show(self)

	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):		
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		self.automata = name, casemode
		self.automata_idx = utils.get_automata_idx(*self.automata)
		
	def get_text(self):
		focus = self.get_focus()
		return self.list.entrys[focus].get_text()
		#return self.entry.get_text()

	def get_automata_idx(self, name, casemode):
		print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i

	def insert_text(self, entry, text):
		entry.insert_unicode_text(unicode(text, 'utf-8'))
		entry._automata.check_start_of_sentance()
		
	def insert_symbol(self, s):
		before_text = self.list.entrys[self.list.focus].get_text()
		self.insert_text(self.list.entrys[self.list.focus], s)
		after_text = self.list.entrys[self.list.focus].get_text()
		runtime.manager.back_stage()
		

import widget
class WEPSettingWidget(widget.Widget):
	def __init__(self, frame, unselbarpos=[]):
		self.unselbarpos = unselbarpos
		import status
		widget.Widget.__init__(self)
		self.icon_columns = []
		self.scroll_bg = None
		self.scroll_ball = None
		
		self.choose = []
		#self.choose.append( _('WEP TYPE'))
		self.choose.append(_('WEP type'))
		
		for i in range(4):
			self.choose.append(_('Key') + str(i+1) )
		#self.choose.append( _('Key idx'))
		self.choose.append( _('Key index'))
		
		self.labels = []
		self.entrys = []
		for lst in frame:
			self.labels.append(lst[0])
			self.entrys.append(lst[1])
		
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		self.top_index = 0		
		self.focus = -1
		x = uiconfig.pb_entry_pos_x

		self.nrow = nrow = len(self.labels)
		if nrow == 0:		pos_y = []
		elif nrow == 1:	pos_y = uiconfig.pb_entry_pos_y1
		elif nrow == 2:	pos_y = uiconfig.pb_entry_pos_y2
		elif nrow == 3:	pos_y = uiconfig.pb_entry_pos_y3
		elif nrow == 4:	pos_y = uiconfig.pb_entry_pos_y4
		elif nrow == 5:	pos_y = uiconfig.pb_entry_pos_y5
		else:			pos_y = uiconfig.pb_entry_pos_y6
			
#		x = uiconfig.list_pos_x
		self.pos_y = pos_y
		
		i =0
		while i < len(self.labels):			
			self.children.append(self.labels[i])	
			self.children.append(self.entrys[i])			
			i += 1
		
		for i, y in enumerate(pos_y):	
			self.labels[i].set_position(uiconfig.input6p_x2, y+16-uiconfig.input_font[1]/2-2)
			self.labels[i].set_text(self.choose[i])			
			self.labels[i].show()
			self.entrys[i].setPosition(x, y)
			self.entrys[i].show()
			
		if nrow > 6: # draw scroll arrow
			self.scroll_bg = utils.put_image('scroll_bg.png',(444,45),(4, 192))			
			self.scroll_bg.hide()
			self.scroll_ball = utils.put_image('scroll_ball.png',(444,47),(4,int(192/len(self.labels))))
			self.scroll_bg.hide()
			self.children.append(self.scroll_bg)
			self.children.append(self.scroll_ball)
		
		self.set_focus(0)
	def set_focus(self, focus):

		import status
		if self.nrow == 0:
			return

		if self.focus == -1:
			selected_olditem = False
		else:
			selected_olditem = True

		if focus < 0:
			focus = self.nrow + focus
			
		hi_index = focus - self.top_index
		
		if hi_index < 0 or len(self.pos_y) <= hi_index:
			if hi_index < 0:
				self.top_index += hi_index
			else:
				self.top_index += hi_index - len(uiconfig.list_pos_y6) + 1	
			i =0
			while i < len(self.labels):			
				self.labels[i].hide()
				self.entrys[i].hide()
				i += 1
				
			x = uiconfig.pb_entry_pos_x
			for i, y in enumerate(self.pos_y):	
				self.labels[i+self.top_index].set_position(uiconfig.input6p_x2, y+16-uiconfig.input_font[1]/2-2)
				self.labels[i+self.top_index].set_text(self.choose[i+self.top_index])
				self.labels[i+self.top_index].show()				
				self.entrys[i+self.top_index].setPosition(x, y)
				self.entrys[i+self.top_index].show()
				
		self.focus = focus
		
		if len(self.labels) > 6:
			self.scroll_ball.move(444,int(192/len(self.labels)) + self.focus *  int(192/len(self.labels)) + 47 - int(192/len(self.labels)) )	
	
	def focus_up(self):

		
		if self.focus > 0:
			self.set_focus(self.focus - 1)
		else:
			self.set_focus(self.nrow - 1)
	
	def focus_down(self):

		
		if self.focus < len(self.labels) - 1:
			self.set_focus(self.focus + 1)
		else:
			self.set_focus(0)
			
	def show(self):
		#self.set_focus(self.focus)
		print 'WEPSettingStage.show()'
		widget.Widget.show(self)
		i =6
		while i < len(self.labels):
			self.labels[i].hide()
			self.entrys[i].hide()
			i += 1
	def hide(self):
		#self.remove_item_scroll_timer()
		widget.Widget.hide(self)

	def free(self):
		#self.remove_item_scroll_timer()
		widget.Widget.free(self)


class ManualWPAPSKSettingStage(Stage):
	domonitor_forbidden = True
	def __init__(self, mac_mode= 'no', wpa2=False):
		self.wpa2 = wpa2
		self.mac_mode = mac_mode
		self.curfocus = 0
#		status.password_style = True
		self.enctype = wifi_profile_general.encryption
		self.flag = -1

		is_tkip=False

		#if not self.wpa2:
		if wifi_profile_general.encryption == 'TKIP':
			is_tkip = True

		self.ui = ManualWPAPSKSettingUI( _('OK'),'', '', menu4= _('BACK'), iswpa2=wpa2, istkip=is_tkip)

		if self.wpa2:
			if self.enctype == 'TKIP':
				keyval = wifi_profile_general.wpa2_psk_tkip
			else:
				keyval = wifi_profile_general.wpa2_psk_ccmp
		else:
			if self.enctype == 'TKIP':
				keyval = wifi_profile_general.wpa_psk_tkip
			else:
				keyval = wifi_profile_general.wpa_psk_aes
		if len(keyval) == 66 and keyval[:2] == '0x':
			keyval = keyval[2:]
			
		self.ui.set_text(keyval)

	
	def get_automata_idx(self, name, casemode):
		#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i
		
	def destroy(self):
#		status.password_style = False
		Stage.destroy(self)	

	def show(self):
		self.ui.show()
		for ent in self.ui.list.entrys:
			ent.lostFocus()	
		self.ui.set_focus(self.curfocus)	
		self.ui.list.entrys[self.curfocus].showFocus()	 
		self.ui.set_menu3_2()
		
	def handle_key(self,key):
		if key in (config.Menu1, 'OK') :
			print 'keytype:', self.ui.list.entrys[0].get_text()
			print 'key:', self.ui.list.entrys[1].get_text()

			keytype = self.ui.list.entrys[0].get_text()
			keyval = self.ui.list.entrys[1].get_text()
			if len(keyval) == 64:
				for i in keyval:
					if '0123456789abcdefABCDEF'.find(i) == -1:

						#runtime.manager.stack_stage(NewProfNotifyStage(_('Invalid input value.')+'\n'+_('When you input 64 char. You must use hexadecimal input value'), uiconfig.baloon_wifi_icon))
						runtime.manager.stack_stage(NewProfNotifyStage(_('If you want to input hex string, 64 chars required.'), uiconfig.baloon_wifi_icon))
						return None
				keyval = '0x' + keyval
				

			elif 7 < len(keyval) < 64:
				pass
				
			else:
				
				#runtime.manager.stack_stage(NewProfNotifyStage(_('wpa key length error. Key length must be same or longer than 8 characters and same or shorter than 64 bit'), uiconfig.baloon_wifi_icon))
				runtime.manager.stack_stage(NewProfNotifyStage(_('You should input equal or less than 64 chars and more than 8 chars'), uiconfig.baloon_wifi_icon))
				return
			if self.wpa2:
				if wifi_profile_general.authentication != 'WPA2-PSK':
					status.profile_detail_changed = True				
				wifi_profile_general.authentication = 'WPA2-PSK'
				if keytype== 'TKIP':
					if wifi_profile_general.encryption !='TKIP' \
							or wifi_profile_general.wpa2_psk_tkip!=keyval:	
						status.profile_detail_changed = True

					wifi_profile_general.encryption='TKIP'
					wifi_profile_general.wpa2_psk_tkip=keyval
					
				else:
					if wifi_profile_general.encryption !='AES' \
							or wifi_profile_general.wpa2_psk_ccmp!=keyval:	
						status.profile_detail_changed = True
						
					wifi_profile_general.encryption='AES'
					wifi_profile_general.wpa2_psk_ccmp=keyval
			else:
				if wifi_profile_general.authentication != 'WPA-PSK':
					status.profile_detail_changed = True
					
				wifi_profile_general.authentication = 'WPA-PSK'
				if keytype== 'TKIP':
					if wifi_profile_general.encryption !='TKIP' \
							or wifi_profile_general.wpa_psk_tkip!=keyval:	
						status.profile_detail_changed = True
				
					wifi_profile_general.encryption='TKIP'
					wifi_profile_general.wpa_psk_tkip=keyval	
				else: #AES
					if wifi_profile_general.encryption !='AES' \
							or wifi_profile_general.wpa_psk_aes!=keyval:	
						status.profile_detail_changed = True
				
					wifi_profile_general.encryption='AES'
					wifi_profile_general.wpa_psk_aes=keyval	

			#wifi_profile_general.save() # need to remove	
			stage = WirelessManualConfFinStage
			runtime.manager.change_stage(stage)
		
		elif key in ('Up', 'Down'):
			ret = self.ui.handle_key(key)			
			for ent in self.ui.list.entrys:
				ent.lostFocus()				
			self.ui.list.entrys[self.ui.list.focus].showFocus()	

		elif key in ('Left', 'Right'):
			ret = self.ui.handle_key(key)	
			return ret
#		elif key == config.Menu4 or key == config.Red:
#			runtime.manager.back_stage()
			
			return False
#		elif key == config.Menu3:
#			self.ui.update_automata()

		elif key == config.Menu3:
			if self.ui.list.focus == 0:
				return True

			self.curfocus = self.ui.list.focus
			
			if config.mmi_debug: 
				print 'self.flag =', self.flag
				print 'self.ui.list.focus=',self.ui.list.focus
				#print 'self.ui.list.entrys[self.ui.list.focus] = ', self.ui.list.entrys[self.ui.list.focus]
			if self.flag == 0:
				self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus], 'multitap', 'lower')
				self.ui.update_automata_icon(self.ui.list.entrys[self.list.focus])
				self.flag = 1
			elif self.flag == 1:
				self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus], '123', False)
				self.ui.update_automata_icon(self.ui.list.entrys[self.list.focus])
				self.flag = 0
			else:
				# KA: [20070831] hangul lvp-2000
				# vpark 2006.08.28 automata	
				'''
				self.ui.automata_idx = utils.get_automata_idx(*self.ui.automata)
				if setting.lang == 'Korean':			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_hangul)	
					self.ui.automata = config.automata_list_hangul[self.ui.automata_idx]			
				else:			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list)	
					self.ui.automata = config.automata_list[self.ui.automata_idx]					
				'''

				self.ui.automata_idx = self.get_automata_idx(*self.ui.automata)
				self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
				self.ui.automata = config.automata_list_mult_num_symbol[self.ui.automata_idx]					

				if config.mmi_debug: 
					print '## self.ui.automata=', self.ui.automata
					print '## self.ui.automata[0]=', self.ui.automata[0]					
				
				if self.ui.automata[0] == 'symbol':
					self.ui.update_automata_icon_symbol()					
					self.re_draw = True
				else:
					self.ui.set_automata(self.ui.list.entrys[self.ui.list.focus], *self.ui.automata)		
					self.ui.update_automata_icon(self.ui.list.entrys[self.ui.list.focus])
				
				return True	
				# KA: [20070831] hangul lvp-2000 ==

		elif key == 'CLR':	
			#self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			print 'FOCUS', self.ui.list.focus 
			if self.ui.list.focus == 1:
				if len(self.ui.list.entrys[self.ui.list.focus].get_text()) > 0:
					self.ui.list.entrys[self.ui.list.focus].backspace(1)
				else:
					runtime.manager.back_stage()
			else:
				runtime.manager.back_stage()
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True
		
		else:
			ret = self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			return ret

			
class WPAPSKSettingStage(Stage):
	domonitor_forbidden = True
	def __init__(self, sel_info, mac_mode= 'no', wpa2=False):
		self.apinfo = sel_info
		self.wpa2 = wpa2
		self.mac_mode = mac_mode
		self.enctype = self.apinfo[6]
#		status.password_style = True
		
		self.ui = WPAPSKSettingUI( _('OK'),'', '', menu4= _('BACK'), iswpa2=wpa2)
		if self.wpa2:
			if self.enctype == 'TKIP':
				keyval = wifi_profile_general.wpa2_psk_tkip
			else:
				keyval = wifi_profile_general.wpa2_psk_ccmp
		else:
			if self.enctype == 'TKIP':
				keyval = wifi_profile_general.wpa_psk_tkip
			else:
				keyval = wifi_profile_general.wpa_psk_aes
			
		if len(keyval) == 66 and keyval[:2] == '0x':
			keyval = keyval[2:]
		
		self.ui.set_text(keyval)
		self.flag = -1
		
	def destroy(self):
#		status.password_style = False
		Stage.destroy(self)

	def get_automata_idx(self, name, casemode):
		#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				#print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i
		
	def handle_key(self, key):
		# shchun : infomation view only. logic about net setting removed 
		if key in (config.Menu1, 'OK') :
			keyval = self.ui.get_text()
			if len(keyval) == 64:
				for i in keyval:
					if '0123456789abcdefABCDEF'.find(i) == -1:
						#runtime.manager.stack_stage(NewProfNotifyStage(_('Invalid input value.')+'\n'+_('When you input 64 char. You must use hexadecimal input value'), uiconfig.baloon_wifi_icon))
						runtime.manager.stack_stage(NewProfNotifyStage(_('If you want to input hex string, 64 chars required.'), uiconfig.baloon_wifi_icon))
						return True
				keyval = '0x' + keyval
				

			elif 7 < len(keyval) < 64:
				pass
				
			else:
				#runtime.manager.stack_stage(NewProfNotifyStage(_('wpa key length error. Key length must be same or longer than 8 characters and same or shorter than 64 bit'), uiconfig.baloon_wifi_icon))
				runtime.manager.stack_stage(NewProfNotifyStage(_('You should input equal or less than 64 chars and more than 8 chars'), uiconfig.baloon_wifi_icon))
				return True

			if self.wpa2:
				if wifi_profile_general.authentication != 'WPA2-PSK':
					status.profile_detail_changed = True
					
				wifi_profile_general.authentication = 'WPA2-PSK'					
				if self.enctype == 'TKIP':
					if wifi_profile_general.encryption !='TKIP' \
							or wifi_profile_general.wpa2_psk_tkip!=keyval:	
						status.profile_detail_changed = True
						
					wifi_profile_general.encryption='TKIP'
					wifi_profile_general.wpa2_psk_tkip=keyval

				else: #AES
					if wifi_profile_general.encryption !='AES' \
							or wifi_profile_general.wpa2_psk_ccmp !=keyval:	
						status.profile_detail_changed = True
			
					wifi_profile_general.encryption='AES'
					wifi_profile_general.wpa2_psk_ccmp=keyval
			else:
				if wifi_profile_general.authentication != 'WPA-PSK':
					status.profile_detail_changed = True

				wifi_profile_general.authentication = 'WPA-PSK'
				if self.enctype == 'TKIP':
					if wifi_profile_general.encryption !='TKIP' \
							or wifi_profile_general.wpa_psk_tkip!=keyval:	
						status.profile_detail_changed = True
					wifi_profile_general.encryption='TKIP'
					wifi_profile_general.wpa_psk_tkip=keyval	
				else: #AES
					if wifi_profile_general.encryption !='AES' \
							or wifi_profile_general.wpa_psk_aes!=keyval:	
						status.profile_detail_changed = True
				
					wifi_profile_general.encryption='AES'
					wifi_profile_general.wpa_psk_aes=keyval	
			if self.apinfo:
				wifi_profile_general.set_scaninfo(self.apinfo, self.mac_mode)
				
			stage = WirelessConfFinStage
			runtime.manager.change_stage(stage)
#		elif key == config.Menu4 or key == config.Red:
#			runtime.manager.back_stage()
			
			return False
		#elif key == config.Menu3:
		#	self.ui.update_automata()
		#	return True
		elif key == config.Menu3:
			if config.mmi_debug: 
				print 'self.flag =', self.flag
				#print 'self.ui.list.entrys[self.ui.list.focus] = ', self.ui.list.entrys[self.ui.list.focus]
			if self.flag == 0:
				self.ui.set_automata('multitap', 'lower')
				self.ui.update_automata_icon(self.ui.entry)
				self.flag = 1
			elif self.flag == 1:
				self.ui.set_automata('123', False)
				self.ui.update_automata_icon(self.ui.entry)
				self.flag = 0
			else:
				# KA: [20070831] hangul lvp-2000
				# vpark 2006.08.28 automata	
				'''
				self.ui.automata_idx = utils.get_automata_idx(*self.ui.automata)
				if setting.lang == 'Korean':			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_hangul)	
					self.ui.automata = config.automata_list_hangul[self.ui.automata_idx]			
				else:			
					self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list)	
					self.ui.automata = config.automata_list[self.ui.automata_idx]					
				'''

				self.ui.automata_idx = self.get_automata_idx(*self.ui.automata)
				self.ui.automata_idx = (self.ui.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
				self.ui.automata = config.automata_list_mult_num_symbol[self.ui.automata_idx]					

				if config.mmi_debug: 
					print '## self.ui.automata=', self.ui.automata
					print '## self.ui.automata[0]=', self.ui.automata[0]					
				
				if self.ui.automata[0] == 'symbol':
					self.ui.update_automata_icon_symbol()					
					self.re_draw = True
				else:
					self.ui.set_automata(*self.ui.automata)		
					self.ui.update_automata_icon(self.ui.entry)
				
				return True	
				# KA: [20070831] hangul lvp-2000 ==
		

		elif key == config.CLEAR:
			#self.ui.entry.handle_key(key)
			if len(self.ui.entry.get_text()) > 0:
				self.ui.entry.backspace(1)
				return True		
			else:
				runtime.manager.back_stage() 
				return True			
			
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True
			
		else:
			ret = self.ui.entry.handle_key(key)
			return ret			
		return True

class ManualWPAPSKSettingUI(baseui.BaseUI):
	def __init__(self, left, right, title, menu3='123', menu4='', titleimage=None, icon=None, iswpa2=False, istkip=True):
		baseui.BaseUI.__init__(self, left, right, _('WIRELESS PROFILE'), menu3, menu4)
		self.list = None	

		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 2

		self.lblkey = []
		self.keylist = []
		self.wpa2 = iswpa2

		if self.wpa2:
			#choose_bit = ('TKIP+AES', 'AES')
			choose_bit = ('TKIP', 'AES')
		else:
			choose_bit = ('TKIP', 'AES')

		lbl_group = controls.Label_Control( _('Encryption'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)

		#if not istkip and not self.wpa2:
		if not istkip:
			group = controls.ListBox_Control(choose_bit,1, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		else:
			group = controls.ListBox_Control(choose_bit,0, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((lbl_group,group))
		
		tlabel = controls.Label_Control(_('Key') , font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		tinput = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		tinput.set_max(64)
		self.frame.append((tlabel, tinput))

		unselbarpos = []
		self.set_list(self.frame, unselbarpos)
		
		#self.set_automata('123', False)	
		#
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		self.set_fixed_automata(self.list.entrys[1], '123', 'lower')
		self.update_automata_icon(self.list.entrys[1])
	
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = ManualWPAPSKSettingWidget(frame, unselbarpos)
		self.add(self.list)
		
	def set_text(self, str):
		self.list.entrys[1].set_text(str)

	def get_text(self):
		return self.list.entrys[1].get_text()
		
	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		#print 'ka...## call set focus'
		self.list.set_focus(focus)

	def update_automata(self):
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num)
		self.automata = config.automata_list_mult_num[self.automata_idx]	
		print 'update_automata', config.automata_list_mult_num
		print 'automata', self.automata
		print '#### UPDATE AUTOMATA =>', self.automata_idx, self.automata 

		self.set_automata(*config.automata_list_mult_num[self.automata_idx])
		
	def set_automata(self, name, casemode='lower'):
		self.list.entrys[1].set_automata(name, casemode)
		self.automata = name, casemode
		self.set_menu3_2()
		
	def set_menu3_2(self):
		print '### MENU3 set_text', self.automata

		if self.automata[0] == '123':			menu3 = '123'
		elif self.automata[0] == 'hangul':		menu3 = _('KOR')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'lower':			menu3 = _('abc')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'upper':			menu3 = _('ABC')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'first capital':	menu3 = _('Abc')
		else:							menu3 = _('SYMBOL')
		runtime.menu3.set_text(menu3)	
		
	def handle_key(self, key):	

		if key == 'Up':
			self.list.focus_up()			
			return True
		elif key == 'Down':
			self.list.focus_down()			
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			return ret
		# KA: [20080412] ==


	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def update_automata_icon(self,entry):
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if config.mmi_debug: 
			print 'UserInfo:name=',name,',casemode=',casemode
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'symbol':	menu3 = _('SYMBOL')
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
		if name =='symbol': # 'CHECKME:  when it runs
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))

	def update_automata_icon_symbol(self):
		self.set_menu3(_('SYMBOL'))		
		self.automata_idx = self.get_automata_idx(*self.automata)
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]					
		self.set_automata(self.list.entrys[self.list.focus], *self.automata)	
		from basemodel import SymbolSelectionStage
		runtime.manager.stack_stage(SymbolSelectionStage(self, True))

	def delete_char(self):
		self.handle_key('\b')

	def get_text(self):
		return self.list.entrys[self.list.focus].get_text()

	def insert_text(self, entry, text):
		entry.insert_unicode_text(unicode(text, 'utf-8'))
		entry._automata.check_start_of_sentance()

	def insert_symbol(self, s):
		before_text = self.list.entrys[self.list.focus].get_text()
		self.insert_text(self.list.entrys[self.list.focus], s)
		after_text = self.list.entrys[self.list.focus].get_text()
		runtime.manager.back_stage()

	def get_automata_idx(self, name, casemode):
		print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i


class ManualWPAPSKSettingWidget(widget.Widget):
	def __init__(self, frame, unselbarpos=[]):
		self.unselbarpos = unselbarpos
		import status
		widget.Widget.__init__(self)
		self.icon_columns = []
		self.scroll_bg = None
		self.scroll_ball = None

		self.choose = [_('Encryption'), _('Key')]

#		self.choose = ( _('Set'), _('Number') + '1', _('Number') + '2')
		self.labels = []
		self.entrys = []
		for lst in frame:
			self.labels.append(lst[0])
			self.entrys.append(lst[1])
		
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		self.top_index = 0		
		self.focus = -1
		x = uiconfig.pb_entry_pos_x + 50

		self.nrow = nrow = len(self.labels)
		if nrow == 0:		pos_y = []
		elif nrow == 1:	pos_y = uiconfig.pb_entry_pos_y1
		elif nrow == 2:	pos_y = uiconfig.pb_entry_pos_y2
		elif nrow == 3:	pos_y = uiconfig.pb_entry_pos_y3
		elif nrow == 4:	pos_y = uiconfig.pb_entry_pos_y4
		elif nrow == 5:	pos_y = uiconfig.pb_entry_pos_y5
		else:			pos_y = uiconfig.pb_entry_pos_y6
			
#		x = uiconfig.list_pos_x
		self.pos_y = pos_y
		
		i =0
		while i < len(self.labels):			
			self.children.append(self.labels[i])	
			self.children.append(self.entrys[i])			
			i += 1
			
		for i, y in enumerate(pos_y):	
			self.labels[i].set_position(x-130, y+16-uiconfig.input_font[1]/2-2)
			self.labels[i].set_text(self.choose[i])			
			self.labels[i].show()
			self.entrys[i].setPosition(x, y)
			self.entrys[i].show()
			
		if nrow > 6: # draw scroll arrow
			self.scroll_bg = utils.put_image('scroll_bg.png',(444,45),(4, 192))			
			self.scroll_bg.hide()
			self.scroll_ball = utils.put_image('scroll_ball.png',(444,47),(4,int(192/len(self.labels))))
			self.scroll_bg.hide()
			self.children.append(self.scroll_bg)
			self.children.append(self.scroll_ball)
		
		self.set_focus(0)
		
	def set_focus(self, focus):
		import status
		if self.nrow == 0:
			return

		if self.focus == -1:
			selected_olditem = False
		else:
			selected_olditem = True

		if focus < 0:
			focus = self.nrow + focus
			
		hi_index = focus - self.top_index
		
		if hi_index < 0 or len(self.pos_y) <= hi_index:
			if hi_index < 0:
				self.top_index += hi_index
			else:
				self.top_index += hi_index - len(uiconfig.list_pos_y6) + 1	
			i =0
			while i < len(self.labels):			
				self.labels[i].hide()
				self.entrys[i].hide()
				i += 1
			x = uiconfig.pb_entry_pos_x
			for i, y in enumerate(self.pos_y):	
				self.labels[i+self.top_index].set_position(uiconfig.input6p_x2, y+16-uiconfig.input_font[1]/2-2)
				self.labels[i+self.top_index].set_text(self.choose[i+self.top_index])
				self.labels[i+self.top_index].show()				
				self.entrys[i+self.top_index].setPosition(x, y)
				self.entrys[i+self.top_index].show()
				
		self.focus = focus
		
		if len(self.labels) > 6:
			self.scroll_ball.move(444,int(192/len(self.labels)) + self.focus *  int(192/len(self.labels)) + 47 - int(192/len(self.labels)) )	
	
	def focus_up(self):
		if self.focus > 0:
			self.set_focus(self.focus - 1)
		else:
			self.set_focus(self.nrow - 1)
	
	def focus_down(self):
		if self.focus < len(self.labels) - 1:
			self.set_focus(self.focus + 1)
		else:
			self.set_focus(0)
			
	def show(self):
		#self.set_focus(self.focus)
		widget.Widget.show(self)
		i =6
		while i < len(self.labels):
			self.labels[i].hide()
			self.entrys[i].hide()
			i += 1
			
	def hide(self):
		#self.remove_item_scroll_timer()
		widget.Widget.hide(self)

	def free(self):
		#self.remove_item_scroll_timer()
		widget.Widget.free(self)
	#---------------------------------
	# List Item 이 선택되었음	
	

class WPAPSKSettingUI(baseui.BaseUI):
	def __init__(self, left, right, title, menu3='123', menu4='', titleimage=None, icon=None, iswpa2=False):		
		baseui.BaseUI.__init__(self, left, right, _('WIRELESS PROFILE'), menu3, menu4)
		self.digits = ''

		if iswpa2:
			labletext = 'WPA2 Key'
		else:
			labletext = 'WPA Key'
		
		prefix_label = runtime.evas.text(text=labletext,font=uiconfig.pw_prefix_font, color = uiconfig.list_text_color)
		prefix_label.pos = uiconfig.wpa_label_pos
		self.add(prefix_label)

		self.automata_idx = 2
		self.automata = ('123', False)
		self.fixed_automata = False
		self.automata_icon = None

		import entry
		self.entry = entry.Entry((uiconfig.wpa_edit_pos), (uiconfig.wpa_edit_size))
		
		self.entry.set_max(64)
		#self.set_automata('123', False)
		
		self.add(self.entry)

		self.fixed_automata = False
		self.automata_icon = None
		#self.automata_idx = 0

		self.set_fixed_automata( '123', 'lower')
		#self.update_automata_icon(self.entry)
		
	def set_text(self, str):
		self.entry.set_text(str)

	def get_text(self):
		return self.entry.get_text()

	def update_automata(self):
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num_symbol)
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]				
		#self.set_automata(*config.automata_list_mult_num[self.automata_idx])\
		print '#### UPDATE AUTOMATA =>', self.automata_idx, self.automata 

		self.set_automata(*config.automata_list_mult_num_symbol[self.automata_idx])

		
	def set_automata(self, name, casemode='lower'):
		self.entry.set_automata(name, casemode)
		self.automata = name, casemode
		#self.set_menu3()
		self.update_automata_icon(self.entry)
		
#	def set_menu3(self):
#		print '### MENU3 set_text', self.automata
#
#		if self.automata[0] == '123':			menu3 = '123'
#		elif self.automata[0] == 'hangul':		menu3 = _('KOR')
#		elif self.automata[0] == 'multitap' and self.automata[1] == 'lower':			menu3 = _('abc')
#		elif self.automata[0] == 'multitap' and self.automata[1] == 'upper':			menu3 = _('ABC')
#		elif self.automata[0] == 'multitap' and self.automata[1] == 'first capital':	menu3 = _('Abc')
#		else:							menu3 = _('SYMBOL')
#
#
#		if self.automata[0] =='symbol': # 'CHECKME:  when it runs
#			from basemodel import SymbolSelectionStage
#			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
#			self.automata_idx = 3
#		
#		runtime.menu3.set_text(menu3)
		
	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(*utils.get_def_automata())

#	def set_automata(self,entry, name, casemode='lower'):
#		
#		print '#### SET AUTOMATA', self.automata_idx, self.automata 
#		entry.set_automata(name, casemode)
#		if name != 'multitap_addword':
#			self.automata_idx = utils.get_automata_idx(name,casemode)
#		self.automata = name, casemode
#
#		self.update_automata_icon(entry)

	def update_automata_icon(self,entry):
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if config.mmi_debug: 
			print 'UserInfo:name=',name,',casemode=',casemode
		print '####update_automata_icon UserInfo:name=',name,',casemode=',casemode	
		menu3 = ''
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'symbol':	menu3 = _('SYMBOL')
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
		if name =='symbol': # 'CHECKME:  when it runs
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
		print '#### UPDATE AUTOMATA ICON', self.automata_idx, self.automata 
		
	def update_automata_icon_symbol(self):
		self.set_menu3(_('SYMBOL'))		
		self.automata_idx = self.get_automata_idx(*self.automata)
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]					
		self.set_automata(*self.automata)	
		from basemodel import SymbolSelectionStage
		runtime.manager.stack_stage(SymbolSelectionStage(self, True))
		
		print '#### UPDATE AUTOMATA ICON SYMBOL', self.automata_idx, self.automata 

	def delete_char(self):
		self.handle_key('\b')

	def get_text(self):
		return self.entry.get_text()

	def insert_text(self, entry, text):
		entry.insert_unicode_text(unicode(text, 'utf-8'))
		entry._automata.check_start_of_sentance()

	def insert_symbol(self, s):
		before_text = self.entry.get_text()
		self.insert_text(self.entry, s)
		after_text = self.entry.get_text()
		runtime.manager.back_stage()

	def get_automata_idx(self, name, casemode):
		print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i

class  PrevIPSettingStage(NotifyStage):
	domonitor_forbidden = True
	#wireless
	duration = 500
	def __init__(self):
		prof = profile.get_profile()
		if wifi_profile_general.get_dhcp(): # LAN
			message = _('Currently, you are using dhcp')
		else: #prof == 2: # Wi-Fi
			message = _('Currently, you are using static')
		
		NotifyStage.__init__(self, message, uiconfig.baloon_phone_setting_icon, cb = self.next_cb, duration=1000)
	
	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True			
		return NotifyStage.handle_key(self, key)	
				
	def next_cb(self):
		stage = IPSettingStage
		runtime.manager.change_stage(stage)

class IPSettingStage(ListStage):
	domonitor_forbidden = True
	icon= uiconfig.wired_profile_icon
	
	def __init__(self, wireless=True, manual=True):
		self.wireless = wireless
		self.manual = manual
		self.choice = _('Dynamic IP(DHCP)'), _('Fixed IP(Static)')
		
		if self.wireless:
			#self.titleimage=uiconfig.title_wireless_profile_setting
			self.title = _('WIRELESS PROFILE')
		else:
			#self.titleimage=uiconfig.title_wired_profile_setting		
			self.title = _('WIRED PROFILE')
		ListStage.__init__(self, self.choice, title=self.title, left=_('SELECT'), right='', menu4=_('BACK'))

		if self.wireless:
			if wifi_profile_general.get_dhcp(): # LAN
				self.ui.set_focus(0)
			else:
				self.ui.set_focus(1)

		else:
			if lan_profile.get_dhcp(): # LAN
				self.ui.set_focus(0)
			else:
				self.ui.set_focus(1)
				
	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
			
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True	

		else:
			ListStage.handle_key(self, key)
			
	def activate(self, index):
		if index == 0:
			status.profile_detail_changed = True
			
			if self.wireless:
				wifi_profile_general.set_dhcp(True)
				#wifi_profile_general.save() # need to remove
			else:
				lan_profile.set_dhcp(True)
				#lan_profile.save()
				
			if self.wireless and self.manual:
				stage = WirelessManualConfFinStage
				runtime.manager.stack_stage(stage)
				return
			elif 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:
				stage=ApplyNetworkSettingStage(self.wireless)
				runtime.manager.stack_stage(stage)

		elif index == 1:
			stage=IPStaticSettingStage(self.wireless, self.manual)
			runtime.manager.stack_stage(stage)
			
class IPStaticSettingStage(Stage):
	domonitor_forbidden = True
	#titleimage=uiconfig.title_wired_profile_setting
	def __init__(self, wireless=False, manual=True):
		self.wireless = wireless
		self.manual = manual
		
		self.curfocus = 0
		enabled = False
		if setting.in_restrict == 1:
			enabled = True
		if self.wireless:
			#self.titleimage=uiconfig.title_wireless_profile_setting
			title = _('WIRELESS PROFILE')
		else:
			#self.titleimage=uiconfig.title_wired_profile_setting		
			title = _('WIRED PROFILE')
			
		self.ui = IPStaticSettingUI(_('SELECT'),'', title, '',_('BACK'),arg_enabled= enabled)
		if self.wireless:
			self.ui.list.entrys[0].set_text(wifi_profile_general.ipaddress)
			self.ui.list.entrys[1].set_text(wifi_profile_general.netmask)
			self.ui.list.entrys[2].set_text(wifi_profile_general.gateway)
		else:
			self.ui.list.entrys[0].set_text(lan_profile.ipaddress)
			self.ui.list.entrys[1].set_text(lan_profile.netmask)
			self.ui.list.entrys[2].set_text(lan_profile.gateway)

		self.ui.list.entrys[3].set_text(dns_profile.dns1)
		self.ui.list.entrys[4].set_text(dns_profile.dns2)
		self.UpdateMenu2()
		
	def show(self):
		self.ui.show()
		for ent in self.ui.list.entrys:
			ent.lostFocus()	
		self.ui.set_focus(self.curfocus)	
		self.ui.list.entrys[self.curfocus].showFocus()	

	def UpdateMenu2(self):
		self.ui.set_right('.')
			
	def filter_ipval(self, str_ip):
		iserror = False
		ipadd = str_ip.split('.') #coming number > 255
		
		if len(ipadd) == 4:
			for z in range(len(ipadd)):
				if not ipadd[z]:
					iserror = True
					break
				if int(ipadd[z].strip())>255:
					iserror = True
					break
		else:
			iserror = True

		if iserror:
			return None
			
		for z in range(len(ipadd)):
			ipadd[z] = int(ipadd[z].strip())
		str_ip = '%d.%d.%d.%d' % (ipadd[0], ipadd[1], ipadd[2], ipadd[3])
		print 'filtered ip' , str_ip
		
		return str_ip
		
	def handle_key(self,key):
		if key == config.Menu4:
			runtime.manager.back_stage()
		elif key in (config.Menu1, 'OK') :
			#print 'ipaddr:', self.ui.list.entrys[0].get_text()
			#print 'gateway:', self.ui.list.entrys[1].get_text()
			#print 'netmask:', self.ui.list.entrys[2].get_text()
			#print 'dns1:', self.ui.list.entrys[3].get_text()
			#print 'dns2:', self.ui.list.entrys[4].get_text()

			t_ipaddress = t_gateway = t_netmask = None
			t_dns1 = t_dns2 = None

			val = self.filter_ipval(self.ui.list.entrys[0].get_text())
			if val:
				t_ipaddress = val
			else:
				runtime.manager.stack_stage(NewProfNotifyStage(_('ipaddress format error'), uiconfig.baloon_setting_system_network_icon))
				self.curfocus = 0
				return
			
			val = self.filter_ipval(self.ui.list.entrys[1].get_text())
			if val:

				if utils.isValidNetmask(val):
					t_netmask = val
				else:
					runtime.manager.stack_stage(NewProfNotifyStage( _('netmask format error') + '.', uiconfig.baloon_setting_system_network_icon))
					self.curfocus = 1
					return
			else:
				runtime.manager.stack_stage(NewProfNotifyStage( _('netmask format error'), uiconfig.baloon_setting_system_network_icon))
				self.curfocus = 1
				return
				
			val = self.filter_ipval(self.ui.list.entrys[2].get_text())
			if val:
				t_gateway =val
			else:
				runtime.manager.stack_stage(NewProfNotifyStage(_('gateway format error'), uiconfig.baloon_setting_system_network_icon))
				self.curfocus = 2
				return

			if len(self.ui.list.entrys[3].get_text()) == 0 and self.ui.list.entrys[4].get_text() == 0:
				runtime.manager.stack_stage(NewProfNotifyStage( _('you should input at least one dns server'), uiconfig.baloon_setting_system_network_icon))
				self.curfocus = 3
				return
			
			val = self.filter_ipval(self.ui.list.entrys[3].get_text())
			if val:
				t_dns1 = val
			else:
				if len(self.ui.list.entrys[3].get_text()) > 0:
					runtime.manager.stack_stage(NewProfNotifyStage(_('dns1 format error'), uiconfig.baloon_setting_system_network_icon))
					self.curfocus = 3
					return
				
			val = self.filter_ipval(self.ui.list.entrys[4].get_text())
			if val:
				t_dns2 = val
			else:
				if len(self.ui.list.entrys[4].get_text()) > 0:
					runtime.manager.stack_stage(NewProfNotifyStage(_('dns2 format error'), uiconfig.baloon_setting_system_network_icon))
					self.curfocus = 4
					return

			if len(t_dns1) > 0 and len(t_ipaddress) > 0:
				#print 'IPADDR private?', utils.isPrivateIP(t_ipaddress)
				#print 'DNS private', utils.isPrivateIP(t_dns1)
				if utils.isPrivateIP(t_dns1) and not utils.isPrivateIP(t_ipaddress):
					runtime.manager.stack_stage(NewProfNotifyStage(_('IP address is in pubic IP range while DNS1 is in private IP, Please check.'), uiconfig.baloon_setting_system_network_icon))
					self.curfocus = 3
					return

			if utils.isIPaddrEqBroadcast(t_ipaddress, t_netmask) :
				runtime.manager.stack_stage(NewProfNotifyStage(_('IP address is broadcast address, please double check'), uiconfig.baloon_setting_system_network_icon))
				self.curfocus = 0
				return

			if not utils.isGatewayInSubnet(t_ipaddress, t_gateway, t_netmask):
				runtime.manager.stack_stage(NewProfNotifyStage(_('Gateway is not located same subnet'), uiconfig.baloon_setting_system_network_icon))
				self.curfocus = 2
				return


			if self.wireless:
				if wifi_profile_general.get_dhcp():
					status.profile_detail_changed = True
				wifi_profile_general.set_dhcp(False)
				
				if wifi_profile_general.ipaddress !=  t_ipaddress:
					status.profile_detail_changed = True
				wifi_profile_general.set_ipaddress(t_ipaddress)

				if wifi_profile_general.gateway !=  t_gateway:
					status.profile_detail_changed = True
				wifi_profile_general.set_gateway(t_gateway)

				if wifi_profile_general.netmask !=  t_netmask:
					status.profile_detail_changed = True
				wifi_profile_general.set_netmask(t_netmask)
				
				#wifi_profile_general.save() # need to remove
			else:
				if lan_profile.get_dhcp():
					status.profile_detail_changed = True
				lan_profile.set_dhcp(False)
				
				if lan_profile.ipaddress !=  t_ipaddress:
					status.profile_detail_changed = True
				lan_profile.set_ipaddress(t_ipaddress)

				if lan_profile.gateway !=  t_gateway:
					status.profile_detail_changed = True
				lan_profile.set_gateway(t_gateway)

				if lan_profile.netmask !=  t_netmask:
					status.profile_detail_changed = True
				lan_profile.set_netmask(t_netmask)
				#lan_profile.save()

			if t_dns1:
				if dns_profile.dns1 != t_dns1:
					status.profile_detail_changed = True
				dns_profile.set_dns1(t_dns1)
			if t_dns2:

				if dns_profile.dns2 != t_dns2:
					status.profile_detail_changed = True
				dns_profile.set_dns2(t_dns2)
			dns_profile.save()

			if self.wireless and self.manual:
				stage = WirelessManualConfFinStage
				runtime.manager.stack_stage(stage)
			elif 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:
				stage=ApplyNetworkSettingStage(self.wireless)
				runtime.manager.stack_stage(stage)
			
		elif key in ('Up', 'Down'):
			ret = self.ui.handle_key(key)			
			for ent in self.ui.list.entrys:
				ent.lostFocus()				
			self.ui.list.entrys[self.ui.list.focus].showFocus()	
		elif key in ('Left', 'Right'):
			ret = self.ui.handle_key(key)	
			return ret
			
		elif key == config.Menu2:
			self.ui.list.entrys[self.ui.list.focus].insert_unicode_text(unicode('.', 'utf-8'))
			return True
		elif key == 'CLR':
			#self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			print 'FOCUS', self.ui.list.focus 
			if self.ui.list.focus in (0,1,2,3,4):
				if len(self.ui.list.entrys[self.ui.list.focus].get_text()) > 0:
					self.ui.list.entrys[self.ui.list.focus].backspace(1)
				else:
					runtime.manager.back_stage()
			else:
				runtime.manager.back_stage()
				
		elif key in (config.Red, config.Green, config.OffHook, config.Video):
			rollback_profile_changes()
			return False
		elif key == config.Menu4:
			runtime.manager.back_stage() 
			return True

		else:
			ret = self.ui.list.entrys[self.ui.list.focus].handle_key(key)
			return ret

import controls
class IPStaticSettingUI(baseui.BaseUI): # ListUI
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4, titleimage=None, icon=None, arg_enabled=False):
	
		baseui.BaseUI.__init__(self, left, right, title, menu3, menu4)
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		self.list = None
		self.display_idx = 0

		listidx = 1
		if arg_enabled:
			listidx = 0

		print 'LIST IDX', listidx, arg_enabled
		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		choose = [ _('Enable'), _('Disable') ]
		#ind_group = self.find_pos(item[1],choose)

		# IP ADDRESS
		self.lbl_ipaddr = controls.Label_Control( _('IP Address'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.txt_ipaddr = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		self.txt_ipaddr.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((self.lbl_ipaddr, self.txt_ipaddr))

		# SUB MASK
		self.lbl_submask = controls.Label_Control( _('Submask'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.txt_submask = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		self.txt_submask.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((self.lbl_submask, self.txt_submask))

		# GATEWAY IP
		self.lbl_gateway = controls.Label_Control( _('Gateway'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.txt_gateway = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		self.txt_gateway.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((self.lbl_gateway, self.txt_gateway))

		# DNS1
		self.lbl_dns1 = controls.Label_Control( _('Dns1'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.txt_dns1 = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		self.txt_dns1.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((self.lbl_dns1, self.txt_dns1))

		# DNS2
		self.lbl_dns2 = controls.Label_Control( _('Dns2'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.txt_dns2 = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)
		self.txt_dns2.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((self.lbl_dns2, self.txt_dns2))

		unselbarpos = []
		self.set_list(self.frame, unselbarpos)
		
		for i in range(5):
			self.set_fixed_automata(self.list.entrys[i],'ip', False)	
	
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = IPStaticSettingWidget(frame, unselbarpos)
		self.add(self.list)
		
	def update_lists(self, labels, unselbarpos=[]):
		
		print '### IncomingRestrictUI. update_lists'
		self.list.free()
		self.widgets.remove(self.list)		
		self.add(self.list)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		#print 'ka...## call set focus'
		self.list.set_focus(focus)
		
	def set_text(self, n, text):
		
		self.list.set_text(n, text)
	
	def change_language(self):
		self.list.change_language()
		baseui.BaseUI.change_language(self)

	def handle_key(self, key):	
		if key == 'Up':
			self.list.focus_up()			
			return True
		elif key == 'Down':
			self.list.focus_down()			
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			return ret
		# KA: [20080412] ==
		
		return False

	def destroy(self):
		
		if self.automata_icon: self.automata_icon.free()		
		baseui.BaseUI.destroy(self)

	def show(self):
		if self.automata_icon: self.automata_icon.show()
		baseui.BaseUI.show(self)
	
	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def update_automata_icon(self,entry):
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if name == '123':		menu3 = '123'
# ka...hangul add 2007.01.23
		elif name == 'hangul':	menu3 = 'KOR'
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
	def get_text(self):
		return self.entry.get_text()	

import widget
class IPStaticSettingWidget(widget.Widget):
	def __init__(self, frame, unselbarpos=[]):
		self.unselbarpos = unselbarpos
		import status
		widget.Widget.__init__(self)
		self.icon_columns = []
		self.scroll_bg = None
		self.scroll_ball = None

		self.choose = [_('IP address'),  _('Subnet mask'), _('Gateway'), _('DNS1'), _('DNS2')]

#		self.choose = ( _('Set'), _('Number') + '1', _('Number') + '2')
		self.labels = []
		self.entrys = []
		for lst in frame:
			self.labels.append(lst[0])
			self.entrys.append(lst[1])
		
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		self.top_index = 0		
		self.focus = -1
		x = uiconfig.pb_entry_pos_x + 50

		self.nrow = nrow = len(self.labels)
		if nrow == 0:		pos_y = []
		elif nrow == 1:	pos_y = uiconfig.pb_entry_pos_y1
		elif nrow == 2:	pos_y = uiconfig.pb_entry_pos_y2
		elif nrow == 3:	pos_y = uiconfig.pb_entry_pos_y3
		elif nrow == 4:	pos_y = uiconfig.pb_entry_pos_y4
		elif nrow == 5:	pos_y = uiconfig.pb_entry_pos_y5
		else:			pos_y = uiconfig.pb_entry_pos_y6
			
#		x = uiconfig.list_pos_x
		self.pos_y = pos_y
		
		i =0
		while i < len(self.labels):			
			self.children.append(self.labels[i])	
			self.children.append(self.entrys[i])			
			i += 1
			
		for i, y in enumerate(pos_y):	
			self.labels[i].set_position(x-130, y+16-uiconfig.input_font[1]/2-2)
			self.labels[i].set_text(self.choose[i])			
			self.labels[i].show()
			self.entrys[i].setPosition(x, y)
			self.entrys[i].show()
			
		if nrow > 6: # draw scroll arrow
			self.scroll_bg = utils.put_image('scroll_bg.png',(444,45),(4, 192))			
			self.scroll_bg.hide()
			self.scroll_ball = utils.put_image('scroll_ball.png',(444,47),(4,int(192/len(self.labels))))
			self.scroll_bg.hide()
			self.children.append(self.scroll_bg)
			self.children.append(self.scroll_ball)
		
		self.set_focus(0)
		
	def set_focus(self, focus):
		import status
		if self.nrow == 0:
			return

		if self.focus == -1:
			selected_olditem = False
		else:
			selected_olditem = True

		if focus < 0:
			focus = self.nrow + focus
			
		hi_index = focus - self.top_index
		
		if hi_index < 0 or len(self.pos_y) <= hi_index:
			if hi_index < 0:
				self.top_index += hi_index
			else:
				self.top_index += hi_index - len(uiconfig.list_pos_y6) + 1	
			i =0
			while i < len(self.labels):			
				self.labels[i].hide()
				self.entrys[i].hide()
				i += 1
			x = uiconfig.pb_entry_pos_x
			for i, y in enumerate(self.pos_y):	
				self.labels[i+self.top_index].set_position(uiconfig.input6p_x2, y+16-uiconfig.input_font[1]/2-2)
				self.labels[i+self.top_index].set_text(self.choose[i+self.top_index])
				self.labels[i+self.top_index].show()				
				self.entrys[i+self.top_index].setPosition(x, y)
				self.entrys[i+self.top_index].show()
				
		self.focus = focus
		
		if len(self.labels) > 6:
			self.scroll_ball.move(444,int(192/len(self.labels)) + self.focus *  int(192/len(self.labels)) + 47 - int(192/len(self.labels)) )	
	
	def focus_up(self):
		if self.focus > 0:
			self.set_focus(self.focus - 1)
		else:
			self.set_focus(self.nrow - 1)
	
	def focus_down(self):
		if self.focus < len(self.labels) - 1:
			self.set_focus(self.focus + 1)
		else:
			self.set_focus(0)
			
	def show(self):
		#self.set_focus(self.focus)
		widget.Widget.show(self)
		i =6
		while i < len(self.labels):
			self.labels[i].hide()
			self.entrys[i].hide()
			i += 1
			
	def hide(self):
		#self.remove_item_scroll_timer()
		widget.Widget.hide(self)

	def free(self):
		#self.remove_item_scroll_timer()
		widget.Widget.free(self)
	#---------------------------------
	# List Item 이 선택되었음	


class  ApplyNetworkSettingStage(NewProfNotifyStage):
	domonitor_forbidden = True
	# set profile (wifi, lan)
	# restart interface...
	duration = 1000
	def __init__(self, wireless=False):
		self.wireless = wireless
		print 'ApplyNetworkSettingStage.__init__ wireless = ', wireless
		
		if wireless: # Wifi
			profile.set_profile(2)
			wifi_profile_general.save()	# commit
			self._icon = uiconfig.baloon_setting_system_network_wireless_icon
		else: #self.profile == 1: # LAN
			profile.set_profile(1)
			lan_profile.save()
			self._icon = uiconfig.baloon_setting_system_network_icon
		dns_profile.save()
		profile.save()

		# by default : wireless.cfg refers custom setting.
		os.system('cp /usr/etc/wireless_general.cfg /usr/etc/wireless.cfg')			

		status.profile_detail_changed = False
		
		# stopping all the interface
		#os.system('/usr/local/bin/eth0_stop')
		#os.system('/usr/local/bin/wlstop')

		NewProfNotifyStage.__init__(self, _('Applying IP configuration'), uiconfig.baloon_wifi_icon, self.end_cb, duration=500)
	
	def end_cb(self):
		stage = NewProfNotifyStage( _('The phone will be reboot shortly'), uiconfig.baloon_setting_system_reset_icon, reset_cb_1, noexit=True)
		runtime.manager.stack_stage(stage)

	def handle_key(self, key):
		if key in (config.Red, config.Green, config.OffHook, config.Video) and  self.noexit:
			print 'skip key'
			return True

		else:
			return NewProfNotifyStage.handle_key(self, key)
			
					
class  DoneNetworkSettingStage(NotifyStage):
	domonitor_forbidden = True
	duration = 3000
	def __init__(self):
		# TODO : add applying code of megaap parameters.
		NotifyStage.__init__(self, _('Network setting finished'), uiconfig.baloon_wifi_icon, cb = self.next_cb)

	def next_cb(self):
		print 'change to ip address setting'
		runtime.manager.back_stage('setting stage')

class  MegaApApplyStage(NotifyStage):
	domonitor_forbidden = True
	duration = 3000
	def __init__(self, apinfo):
		# TODO : add applying code of megaap parameters.
		NotifyStage.__init__(self, _('Applying IP configuration'), uiconfig.baloon_wifi_icon, cb = self.next_cb)

	def next_cb(self):
		print 'change to ip address setting'
		runtime.manager.back_stage('setting stage')