from roxiadebug import *
 
 ##################################

#msg_D101_init = 'Ã³À½À¸·Î º»Ã¼°¡ »ç¿ëÁØºñ ÁßÀÔ´Ï´Ù.\nÀá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'
#msg_D101 = 'º»Ã¼°¡ »ç¿ëÁØºñ ÁßÀÔ´Ï´Ù.\nÀá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'
#msg_M101 = '·£¼± ¿¬°áÀ» È®ÀÎÇØ ÁÖ¼¼¿ä.'
#msg_M102 = '³×Æ®¿öÅ©¿¡ ¿¬°á ÁßÀÔ´Ï´Ù.\nÀá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'
#msg_M301 = 'DHCP IP ÇÒ´çÀ» ¹ÞÀ» ¼ö ¾ø½À´Ï´Ù.'
#msg_M302 = '°íÁ¤ IP ¼³Á¤À» È®ÀÎÇØ ÁÖ¼¼¿ä.'
#msg_M901 = 'ÀÏ½ÃÀûÀÎ ³×Æ®¿öÅ© Àå¾ÖÀÔ´Ï´Ù.'
#msg_W100 = '"%s"¿¡ Á¢¼Ó ÁßÀÔ´Ï´Ù.'
#msg_W100_mega = 'KTÀü¿ë AP¿¡ Á¢¼Ó ÁßÀÔ´Ï´Ù.'
#msg_W101 = '"%s" Á¢¼Ó¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W101_1 = 'KTÀü¿ë APÁ¢¼Ó¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W101_mega = '"%s"¿¡ Á¢¼ÓÇÒ ¼ö ¾ø½À´Ï´Ù.\nKTÀü¿ë AP¿¡ ¿¬°á ÇÏ½Ã°Ú½À´Ï±î?'
#msg_W101_gen = 'KTÀü¿ë AP¿¡ Á¢¼ÓÇÒ ¼ö ¾ø½À´Ï´Ù.\nº¸Á¶ÇÁ·ÎÆÄÀÏ¿¡ ¿¬°á ÇÏ½Ã°Ú½À´Ï±î?'
#msg_W101_scan = '"%s"¿¡ Á¢¼ÓÇÒ ¼ö ¾ø½À´Ï´Ù.\n¹«¼±·£ °Ë»öÀ» ÇÏ½Ã°Ú½À´Ï±î?'
#msg_W102 = '¹«¼± º¸¾ÈÅ° Àû¿ë¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W103 = 'IP¸¦ ¿äÃ» ÁßÀÔ´Ï´Ù.'
##msg_W104 = 'DHCP ¼³Á¤¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W104 = 'DHCP IP ÇÒ´çÀ» ¹ÞÀ» ¼ö ¾ø½À´Ï´Ù.\nÀç¿¬°áÀ» ½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W105 = '°íÁ¤ IP ¼³Á¤À» È®ÀÎÇØ ÁÖ¼¼¿ä.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W106 = 'ÀÏ½ÃÀûÀÎ ³×Æ®¿öÅ© Àå¾ÖÀÔ´Ï´Ù.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä'
#msg_W107 = 'IP ¼³Á¤»óÅÂ¸¦ È®ÀÎÇØ ÁÖ¼¼¿ä.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W106 = 'IP ¼³Á¤ »óÅÂ ¹× ³×Æ®¿öÅ© »óÅÂ¸¦ È®ÀÎ ¹Ù¶ø´Ï´Ù.\nÀç¿¬°áÀ» ½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W107 = 'IP ¼³Á¤ »óÅÂ ¹× ³×Æ®¿öÅ© »óÅÂ¸¦ È®ÀÎ ¹Ù¶ø´Ï´Ù.\nÀç¿¬°áÀ» ½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_W108 = '"%s"¿¡ Á¢¼Ó µÇ¾ú½À´Ï´Ù'
#msg_W108_mega = 'KTÀü¿ë AP¿¡ Á¢¼Ó µÇ¾ú½À´Ï´Ù'
#msg_W109 = '¹«¼± ³×Æ®¿öÅ©°¡ ²÷¾îÁ³½À´Ï´Ù.\n¹«¼± ³×Æ®¿öÅ©¸¦ °Ë»ö ÁßÀÔ´Ï´Ù.'
#msg_W110 = '³×Æ®¿öÅ© Àå¾Ö·Î ¼­¹ö¿ÍÀÇ ¿¬°áÀÌ\n²÷¾îÁ³½À´Ï´Ù. Àç¿¬°áÀ» ½ÃµµÇÕ´Ï´Ù.'
#msg_SR103 = '¼­¹ö¿¡ µî·Ï ÁßÀÔ´Ï´Ù.\nÀá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'#_('Registering.')+'\n'+_('Please wait for a moment.')
#msg_SR403 = '¼­¹ö¿¡ µî·ÏÇÒ ¼ö ¾ø½À´Ï´Ù.'
#msg_SR404 = 'ÀÎÅÍ³Ý ÀüÈ­¹øÈ£¸¦\nÈ®ÀÎÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.'
#msg_SR480 = '¼­¹ö¿¡ µî·ÏÇÒ ¼ö ¾ø½À´Ï´Ù.\nÀç½ÃµµÇÏ·Á¸é ÅëÈ­¹öÆ°À» ´©¸£¼¼¿ä.'
#msg_Wait = 'Àá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'

# English version
msg_D101_init = _('Preparing the first bootup.\nPlease wait a moment.')
msg_D101 = _('Initializing.\nPlease wait a moment.')
msg_M101 = _('Please check LAN connection.')
msg_M102 = _('Connecting network.\nPlease wait a moment.')
msg_M301 = _('DHCP Failed. Check the network and try again.')
msg_M302 = _('Please check static IP setting.')
msg_M901 = _('Cannot access network temporary.')
msg_W100 = _('making connection to %s')
msg_W100_mega = _('Associating to KT AP...')
msg_W101 = _('%s connection failed.\nPress CALL button to try again.')
msg_W101_1 = _('Association to KT AP failed.\nPress CALL button to try again.')
msg_W101_mega = _('Cannot associate to %s.\nUse KT AP instead?')
msg_W101_gen = _('Cannot associate to KT AP.\nUse auxiliary profile instead?')
msg_W101_scan = _('Cannot associate to %s.\nSearch Wireless AP?')
msg_W102 = _('Wireless security key authentication failed.\nPress CALL button to try again.')
msg_W103 = _('Acquiring IP address...')
#msg_W104 = _('DHCP failed.\nPress CALL button to try again.')
msg_W104 = _('DHCP failed.\nPress CALL button to try again.')
msg_W105 = _('Please check static IP setting.\nPress CALL button to try again.')
#msg_W106 = _('Cannot access network temporary.\nPress CALL button to try again.')
#msg_W107 = _('Please check IP setting.\nPress CALL button to try again.')
msg_W106 = _('Please check IP setting and network.\nPress CALL button to try again.')
msg_W107 = _('Please check IP setting and network.\nPress CALL button to try again.')
msg_W108 = _('associated to %s successfully')
msg_W108_mega = _('associated to KT AP successfully')
msg_W109 = _('Cannot find AP.\nSearching wireless AP...')
msg_W110 = _('Server connection failed.\n Connecting...')
msg_SR103 = _('Registering.\nPlease wait a moment.')#_('Registering.')+'\n'+_('Please wait for a moment.')
msg_SR403 = _('Cannot register to server.')
msg_SR404 = _('Please check the phone number.')
msg_SR480 = _('Cannot register to server.\nPress CALL button to try again.')
msg_Wait = _('Please wait a moment.')



pri_table=('D101','D102','D103','M101','M102','M201','M202','M301','M302','M901','V101', \
		'SR103','SR403','SR404','SR480','SR500','SS403','SS480','SS500','SS486','SS600', \
		'W100','W101','W102','W103','W104','W105','W106','W107','W108','W109','W110')

def get_pri(code):
	global pri_table
	for i in range(len(pri_table)):
		if pri_table[i] == code:
			debugLogN('\tget_pri: %s-%d'%(code, i))
			return i
	debugLogN('\tget_pri: %s-%d'%(code, -1))
	return -1

cur_errcode = ''
idlemsg_Timer = None
##################################

def euckr2utf8(message):
	try:
	 	result = ''
		result = unicode(message,'euc-kr').encode('utf-8')
		return result
	except:
		print 'euckr2utf8 error'
		return message
def utf82euckr(message):
	try:
	 	result = ''
		result = unicode(message,'utf-8').encode('euc-kr')
		return result
	except:
		print 'utf82euckr error'
		return message

def ErrorCode(code=None):
	roxia_trace('ErrorCode===', code)
	if code == '403':
		msg = msg_SR403
	elif code == 'M101':
		msg = msg_M101
	elif code == 'W109':
		msg = msg_W109
	elif code == 'W104':
		msg = msg_W109
	elif code == 'M301':
		msg = msg_W104
	elif code in ('404', '410'):
		msg = msg_SR404	
	elif code in ('400', '408','480', '487', '500', '503'):
		msg = msg_SR480		
	else:
		msg = msg_SR480	

	debugLogN('### ErrorCode: Mesg (%16s: %s)'%(code, msg))
	msg = euckr2utf8(msg)
		
	return msg
	
#def set_idle_errcode(code, prioritychk=False):
#	import utils
#	utils.send_VP_net_status_to_DCT(code)
#	set_idle_errmsg(eval('msg_' + code))

import runtime
def set_idle_errmsg(errmsg, code='', check_pri=False, delay_msec = 0, refresh=False):
	import utils
	global cur_errcode, idlemsg_Timer

	debugLogN('SET_IDLE_MSG(%s) check_pri(%d) delay(%d) refresh(%d): %16s'%(code, check_pri, delay_msec, refresh, utf82euckr(errmsg)))
	
	if check_pri and len(cur_errcode) > 0 and len(code) > 0 and get_pri(cur_errcode) > get_pri(code):
		# discard change..
		debugLogN('DISCARD!!! : SET_IDLE_MSG: %16s'%utf82euckr(errmsg))
		return
		
	def set_msg():
		debugLogN('set_idle_errmsg()')
		runtime.idle_errmsg = errmsg
		cur_errcode = code
		if refresh:
			debugLogN('set_idle_errmsg() - refreshed')
			runtime.manager.linkmonitor.update_idlemsg()	

	if delay_msec > 0:
		idlemsg_Timer = utils.Timer(delay_msec, set_msg)
	else:
		set_msg()
	
def get_idle_errmsg():
	debugLogN('\tGET_IDLE_MSG: %16s'%utf82euckr(runtime.idle_errmsg))
	return runtime.idle_errmsg


