var DEBUG=false;
var Log=function(param){
if(!DEBUG)return;
console.log(param);};
var PRODUCT_ID="0387878700140065";
var PROD_ID_MHCID_LOGIN="0387878700000068";
var PROD_ID_MHCID_ERROR="0387878700000069";
var PROD_ID_FRIENDS="0387878700000071";
const MAX_WIDTH=1920;
const MAX_HEIGHT=1080;
const COLOR_MASK=[0,0,0,180];
const APPLI_ID_MESSAGE="MESSAGE";
const APPLI_ID_VIDEO="CLOUD_VIDEO";
const APPLI_ID_PHOTO="CLOUD_PHOTO";
const APPLI_ID_NOTE="CLOUD_NOTE";
const ADT_ID_MESSAGE=APPLI_ID_MESSAGE+"-MSG";
const ADT_ID_VIDEO=APPLI_ID_VIDEO+"-THUMBNAIL";
const ADT_ID_PHOTO=APPLI_ID_PHOTO+"-THUMBNAIL";
const ADT_ID_NOTE=APPLI_ID_NOTE+"-MEMO";
const TIMEOUT_S=2*60*1000;const TIMEOUT_L=10*60*1000;const ERRTEXT_TOKEN_EXPIRED="EXPIRATIONEXPIREEXPIRATIONEXPIRE";
const ERRCODE_TOKEN_EXPIRED=401;
const ERRCODE_ACCOUNT_REMOVED=461;
const APPLI_TABLE={};
(function(){
APPLI_TABLE[APPLI_ID_VIDEO]="0387878700140029";
APPLI_TABLE[APPLI_ID_PHOTO]="0387878700140010";
APPLI_TABLE[APPLI_ID_NOTE]="0387878700140066";})();


var DEVICE_ITEM_WIDTH=600;
var DEVICE_ITEM_HEIGHT=80;
var DEVICE_TITLE_HEIGHT=DEVICE_ITEM_HEIGHT-20;
var USB_ICON_WIDTH=30;
var USB_ICON_HEIGHT=55;
var SD_ICON_WIDTH=35;
var SD_ICON_HEIGHT=50;
var MAX_FILE_NO=999;
var EXPORT_VIDEO_NAME="VIDEO";
var EXPORT_VIDEO_EXTENSION=".mp4";
var EXPORT_PHOTO_NAME="PHOTO";
var EXPORT_PHOTO_EXTENSION=".jpg";
var is_disclaimer_updated=false;
var friends_path=APPLI_PATH+PROD_ID_FRIENDS+"/gadget/";
var FREE_FUNC=function(){
if(!this.components||this.components.length==0)
return;
for(var i=0;i<this.components.length;i++){
if(this.components[i] instanceof gtext||this.components[i] instanceof gtextbox)
setf_text(this.components[i],"");
else if(this.components[i] instanceof gimage)
this.components[i].src="";
else if(typeof this.components[i].free=="function")
this.components[i].free();
else if(typeof this.components[i]._free=="function")
this.components[i]._free();}
this.components.splice(0,this.components.length);};
var user_profile_mgr={};
user_profile_mgr._uprofile_list=null;
user_profile_mgr._cur_user=null;
user_profile_mgr.getUserProfileList=function(){
if(user_profile_mgr._uprofile_list)
return user_profile_mgr._uprofile_list;
var uprofile_list=[];
if(system.user_profile&&system.user_profile.supported){
try{
var uprofile=system.user_profile.get({mhc:{}});
if(uprofile&&uprofile.mhc&&uprofile.mhc.all){
uprofile_list=uprofile.mhc.all;}
}catch(e){
perror(e);}
}
return uprofile_list;};
user_profile_mgr.getUserProfileListNum=function(){
var uprof_list=this.getUserProfileList();
var uprof_num=uprof_list.indexOf(null);
return (-1<uprof_num)?uprof_num:uprof_list.length;};
user_profile_mgr.getUserProfile=function(id){
var uprofile={};
if(!system.user_profile||!system.user_profile.supported)
return uprofile;
try{
var _uprofile=system.user_profile.get({mhc:{id:id}});
if(_uprofile&&_uprofile.mhc){
uprofile=_uprofile;}
}catch(e){
perror(e);}
return uprofile;};
user_profile_mgr.getUserAuthTokenByMHCUserKey=function(user_key){
var user_auth_token="";
if(!isString(user_key)||user_key.length<=0)
return user_auth_token;
var uprof_list=user_profile_mgr.getUserProfileList();
var uprof_list_len=uprof_list.indexOf(null);
if(uprof_list_len==-1)
uprof_list_len=uprof_list.length;
for(var i=0;i<uprof_list_len;i++){
var uprof=user_profile_mgr.getUserProfile(uprof_list[i]);
if(!uprof||!uprof.mhc)continue;
if(uprof.mhc.mhc_userkey==user_key){
user_auth_token=uprof.mhc.mhc_authtoken;
break;}
};
return user_auth_token;};
user_profile_mgr.setCurrentUserProfileByUserID=function(id){
if(!isNumber(id))return false;
var trg_prof=this.getUserProfile(id);
if(trg_prof&&trg_prof.mhc&&isNumber(trg_prof.mhc.id)&&trg_prof.mhc.id==id){
this._cur_user=trg_prof;
return true;}
return false;};
user_profile_mgr.getCurrentUserProfile=function(){
if(!this._cur_user)
this._cur_user=this.getUserProfile(null);
return this._cur_user;};
user_profile_mgr.getCurrentUserID=function(){
var profile=this.getCurrentUserProfile();
if(profile&&profile.mhc&&isNumber(profile.mhc.id))
return profile.mhc.id;
return null;};
user_profile_mgr.getCurrentUserMHCUserkey=function(){
var profile=this.getCurrentUserProfile();
if(profile&&profile.mhc&&profile.mhc.mhc_userkey)
return profile.mhc.mhc_userkey;
return null;};
user_profile_mgr.getCurrentUserAuthToken=function(){
var profile=this.getCurrentUserProfile();
if(profile&&profile.mhc&&profile.mhc.mhc_userkey)
return profile.mhc.mhc_authtoken;
return null;};
user_profile_mgr.getCurrentUserMHCIcon=function(){
var profile=this.getCurrentUserProfile();
if(profile&&profile.mhc&&profile.mhc.mhc_icon)
return profile.mhc.mhc_icon;
return null;};
user_profile_mgr.isExistCurrentUserProfile=function(){
var profile=this.getCurrentUserProfile();
if(profile&&profile.mhc&&isNumber(profile.mhc.id))
return (profile.mhc.id>=0);
return false;};
user_profile_mgr.checkTokenExpired=function(token){
token=isString(token)?token:this.getCurrentUserAuthToken();
if(!token)return true;
return (token==ERRTEXT_TOKEN_EXPIRED);};
user_profile_mgr.getMultiuserSupported=function(){
if(system.user_profile&&system.user_profile.supported){
try{
var profile=system.user_profile.get({mhc:{}});
if(profile&&profile.mhc&&isBoolean(profile.mhc.multiuser_supported))
return profile.mhc.multiuser_supported;}catch(e){
perror(e);}
}
return false;};
var friend_list_mgr={};
friend_list_mgr._genFriendList=function(){
var auth_token=user_profile_mgr.getCurrentUserAuthToken();
if(!auth_token)
auth_token="";
return new pkg_friends.FriendList(auth_token);};
friend_list_mgr.init=function(){
this._friend_list=null;
this._friend_list=this._genFriendList();};
friend_list_mgr.getFriendList=function(){
return this._friend_list;};
friend_list_mgr.updateToken=function(){
this.init();};
var mus_badge_mgr={};
mus_badge_mgr._badge_list=[];
mus_badge_mgr._adt_id_list=[ADT_ID_MESSAGE];
mus_badge_mgr._requested_new_badge=false;
mus_badge_mgr.notified=false;
mus_badge_mgr.init=function(){
this._badge_list=[];
var prof_id_num=user_profile_mgr.getUserProfileListNum();
for(var i=0;i<prof_id_num;i++)
this._badge_list.push(null);};
mus_badge_mgr.updateNewBadgeView=function(){
if(!user_profile_mgr.getMultiuserSupported())return;var prof_id_list=user_profile_mgr.getUserProfileList();
var prof_id_num=user_profile_mgr.getUserProfileListNum();
for(var i=0;i<prof_id_num;i++){
var view=false;
if(isBoolean(this._badge_list[i])&&this._badge_list[i]){
view=true;}
MultiUserSelection.new_badge_view(prof_id_list[i],view);};
force_redraw();};
mus_badge_mgr.changeNewBadgeView=function(prof_id,view){
Log(" >> mus_badge_mgr.changeNewBadgeView  prof_id : "+prof_id+", view : "+view);
if(!isNumber(prof_id)||!isBoolean(view))return;
var prof_id_list=user_profile_mgr.getUserProfileList();
var prof_id_pos=prof_id_list.indexOf(prof_id);
if(prof_id_pos==-1)return;
this._badge_list[prof_id_pos]=view;
this.updateNewBadgeView();};
mus_badge_mgr.doRequestNewBadge=function(){
var self=this;
if(this._requested_new_badge)return;this._requested_mus_new_badge=true;
var prof_list=MultiUserSelection.get_all_user_info();
var token_list=[];
prof_list.forEach(function(v){
var authtoken=ERRTEXT_TOKEN_EXPIRED;if(isString(v.mhc_userkey)&&isString(v.mhc_authtoken))
authtoken=v.mhc_authtoken;
token_list.push(authtoken);});
var get_dcm_cb=function(result,errcode,server_time){
if(!result||errcode!=200){
console.log(" >> getDataCountMulti error...  errcode : "+errcode);
self._requested_new_badge=false;return;}
for(var i=0;i<token_list.length;i++){
var view=false;
var adt_res=result[token_list[i]];
if(adt_res&&isNumber(adt_res[self._adt_id_list[0]])
&&adt_res[self._adt_id_list[0]]>0){
view=true;}
if(!isBoolean(self._badge_list[i]))
self._badge_list[i]=view;}
self.updateNewBadgeView();};
getDataCountMulti({token_list:token_list,adt_id_list:this._adt_id_list,
count_type:0,direction:0,cb:get_dcm_cb});};
mus_badge_mgr.setHSMessageBadge=function(){
if(this.notified)return;
if(this._badge_list.length<=0)return;
var badge_view=0;
if(this._badge_list.indexOf(true)!=-1){
badge_view=1;}else {
if(this._badge_list.indexOf(null)!=-1){
return;}
}
var badge_list=[null,null,null,badge_view,null,null];
try{
HOME.toolbar.setBadge(badge_list);}catch(e){
perror(e);}
};
function getCloneObj(src_obj){
var ret_obj=new Object();
if(typeof(src_obj)=='object'){
if(Binary&&src_obj instanceof Binary){ret_obj=src_obj;}else if(typeof(src_obj.length)=='number'){ret_obj=new Array();}
for(var attr in src_obj){
if(typeof(src_obj[attr])=='object'){
ret_obj[attr]=getCloneObj(src_obj[attr]);}else if(typeof(src_obj[attr])=='string'){ret_obj[attr]=src_obj[attr];}else if(typeof(src_obj[attr])=='number'){ret_obj[attr]=src_obj[attr];}else if(typeof(src_obj[attr])=='boolean'){((src_obj[attr]==true)?ret_obj[attr]=true:ret_obj[attr]=false);}else {ret_obj[attr]=src_obj[attr];}
}
}else {
ret_obj=src_obj;}
return ret_obj;}
function getLabelFitFontSize(obj,text,max_fsize,min_fsize){
var fsize=max_fsize||36;
if(typeof min_fsize!="number")min_fsize=fsize-10;
var dummy_tbox=new gtextbox({
width:obj.width,height:obj.height,font_size:fsize
});
var real_label_h=get_text_font_height(dummy_tbox,text);
if(dummy_tbox.height<real_label_h){
while(dummy_tbox.height<real_label_h){
if(fsize<=min_fsize)
break;
fsize-=2;
dummy_tbox.font_size=fsize;
real_label_h=get_text_font_height(dummy_tbox,text);}
}
return fsize;};
var getLastDateInCloudData=function(pdata){
var last_date="";
if(pdata&&pdata.create_date){
last_date=pdata.last_write_date?pdata.last_write_date:pdata.create_date;}
return last_date;};
function isFunction(obj){
return (typeof obj=="function");};
function isBoolean(obj){
return (typeof obj=="boolean");};
function perror(e){
console.log("[JS error] "+e.fileName+":"+e.lineNumber+": "+e.name+": "+e.message);};
function convertArrayToJson(text_array){
var target="{[";
for(var i=0;i<text_array.length;i++){
var val=text_array[i];
val=val.replace(/\\/g,"\\\\");
val=val.replace(/\"/g,"\\\"");
val=val.replace(/\n/g," ");
val=val.replace(/\r/g," ");
val=val.replace(/\t/g,"\\\t");
val=val.replace(/\'/g,"\\\'");
target+="\""+val+"\", ";}
target+="]}";
return target;}
var path=APPLI_PATH+PRODUCT_ID+"/gadget/";
var MSG=load_pkg_lang(path+"lang",PRODUCT_ID);
var pkg_gadget_util="gadget_util_"+PRODUCT_ID;
add_package_load_path(pkg_gadget_util,APPLI_PATH+PRODUCT_ID+"/gadget/gadget_util.js");
require(pkg_gadget_util);
provide(pkg_gadget_util);
var cloudGadget=new _GLOBAL_[pkg_gadget_util].CloudGadget("MESSAGE");
add_package_load_path("pkg_friends",friends_path+"pkg_friends.js");
discard_package("pkg_friends");
require("pkg_friends");
var enable_keyhook=true;
var set_cursor=function(sobj,cobj){
var old=sobj.cursor;
if(old==cobj)return;
if(old){
if(old.leave_focus)old.leave_focus(old);
old.in_cursor=false;
old.toggle_cursor=false;}
if(cobj){
if(cobj.enter_focus)cobj.enter_focus(cobj);
cobj.in_cursor=true;}
sobj.cursor=cobj;};
function MoveTo(param){
delete_timer(this);
if(param.func)param.func(this);
this.tmp={};
this.endpos={};
this.tmp.RATE=0.6;
this.tmp.max_count=param.count?param.count:9;
if(param.rate){
this.tmp.RATE=param.rate;}
if(param.count)this.tmp.max_count=param.count;
this.endpos.x=param.x;
this.endpos.y=param.y;
this.endpos.z=param.z;
this.tmp.dx=param.x-this.translate[0];
this.tmp.dy=param.y-this.translate[1];
this.tmp.dz=param.z-this.translate[2];
this.translate[0]+=this.tmp.dx*this.tmp.RATE;
this.translate[1]+=this.tmp.dy*this.tmp.RATE;
this.translate[2]+=this.tmp.dz*this.tmp.RATE;
if(!param.angle)param.angle=0;
this.tmp.da=param.angle-this.rotation[0];
this.rotation[0]+=this.tmp.da*this.tmp.RATE

force_redraw();
append_timer(this,40,function (obj,count){
obj.tmp.dx=param.x-obj.translate[0];
obj.tmp.dy=param.y-obj.translate[1];
obj.tmp.dz=param.z-obj.translate[2];
obj.translate[0]+=Math.floor(obj.tmp.dx*obj.tmp.RATE);
obj.translate[1]+=Math.floor(obj.tmp.dy*obj.tmp.RATE);
obj.translate[2]+=Math.floor(obj.tmp.dz*obj.tmp.RATE);
obj.tmp.da=param.angle-obj.rotation[0];
obj.rotation[0]+=obj.tmp.da*obj.tmp.RATE;
if(count>=obj.tmp.max_count){
delete_timer(obj);

obj.translate[0]=param.x;
obj.translate[1]=param.y;
obj.translate[2]=param.z;
obj.rotation[0]=param.angle;
if(typeof param.end_func=="function"){
param.end_func(obj);}
}
force_redraw();});}

function focus_moveto(pos,size,angle,speed,func){
if(!speed)speed=36;
focus.moveTo(pos,size,angle,Math.max(36,speed),func);};
var focus=new Focus();
focus.setSize(1920*2,1080*2);

function Preview(){
this.superClass=container;
this.superClass({});};
Preview.prototype=new container({});
Preview.prototype.init=function(json_data){};
Preview.prototype.destroy=function(){};
Preview.prototype.prepare=function(bool){};
Preview.prototype.activate=function(bool){};
Preview.prototype.focus_moveto=function(){};
Preview.prototype.setFocusMovetoFunc=function(func){
this.focus_moveto=isFunction(func)?func:function(){};};
Preview.prototype.setSaveEnableCB=function(func){
this.save_enable_cb=isFunction(func)?func:function(){};};
Preview.prototype.setLaunchEnableCB=function(func){
this.launch_enable_cb=isFunction(func)?func:function(){};};
Preview.prototype.setSaveEnable=function(bool){
if(isFunction(this.save_enable_cb))
this.save_enable_cb(bool);};
Preview.prototype.setLaunchEnable=function(bool){
if(isFunction(this.launch_enable_cb))
this.launch_enable_cb(bool);};
Preview.prototype.focus_moveto=function(){};
Preview.prototype.getNotExistMsg=function(product_id){
var msg="";
var gen_not_exist_msg=function(rep_str){
if(!isString(rep_str))
return "";;
return MSG("LT_CG_FILE_NOT_EXIST_1").replace("%s",rep_str)+"\n"+
MSG("LT_CG_FILE_NOT_EXIST_2").replace("%s",rep_str);};
switch(product_id){
case APPLI_TABLE[APPLI_ID_VIDEO]:
msg=gen_not_exist_msg(MSG("LT_HOME_GADGET_VIDEO_MESSAGE"));
break;
case APPLI_TABLE[APPLI_ID_PHOTO]:
msg=gen_not_exist_msg(MSG("LT_CG_THIS_PHOTO"));
break;}
return msg;};
Preview.prototype.getPlayErrorMsg=function(product_id){
var msg="";
switch(product_id){
case APPLI_TABLE[APPLI_ID_VIDEO]:
msg=MSG("LT_VM_VIDEO_FAIL");
break;
case APPLI_TABLE[APPLI_ID_PHOTO]:
msg=MSG("LT_CG_FAILED_TO_DISPLAY");
break;}
return msg;};
Preview.prototype.getMWErrorMsg=function(){
return MSG("LT_CG_FAILED_TO_DISPLAY");};

var _do_preview=function (preview_obj,method,arg_array){
try{
var ret_val=false;
if(!preview_obj)return ret_val;
var preview=preview_obj;
if(preview&&preview[method] instanceof Function){
try{
ret_val=preview[method].apply(preview,arg_array);}catch(e){
var dlog="[Preview]["+preview_obj.product_id+"] ";
dlog+=method+" method Error. line "+e.lineNumber+": ";
dlog+=e.name+": "+e.message;
console.log(dlog);}
};}catch(e){
console.log("[Error] "+e.message+"\n"+Error().stack);}
return ret_val;};
function make_digit(num){
var digit="";
if(num<0)return digit;
if(num<10){
digit="00";}else if(num>=10&&num<100){
digit="0";}
return digit+num.toString();};
var device_item=function(){
pkg_friends.SimpleItem.apply(this);
this.device="";
this.components=[
this.frame=new gbox({
width:DEVICE_ITEM_WIDTH,
height:DEVICE_ITEM_HEIGHT,
color:COL_BORDER_ONBASE
}),
this.bg=new gbox({
width:this.frame.width-2,
height:this.frame.height-2,
color:COL_BASE
}),
this.icon=new gimage({
width:30,height:55,
draw_type:DIRECT,
color:COL_TEXT_ONBASE
}),
this.label=new gtext({
width:DEVICE_ITEM_WIDTH/2,
align:CENTER,font_size:40,
omitter:"...",
color:COL_TEXT_ONBASE
})
];};
device_item.prototype=new pkg_friends.SimpleItem;
device_item.prototype.getWidth=function(){
return DEVICE_ITEM_WIDTH-2;};
device_item.prototype.getHeight=function(){
return DEVICE_ITEM_HEIGHT;};
device_item.prototype.free=FREE_FUNC;
device_item.prototype.setData=function(param){
if(!param)return;
this.frame.width=param.width||DEVICE_ITEM_WIDTH;
this.frame.height=param.height||DEVICE_ITEM_HEIGHT;
this.bg.width=this.frame.width-2;
this.bg.height=this.frame.height-2;
this.device_info=param.device_info||null;
if(this.device_info){
switch(this.device_info.type){
case this.device_info.TYPE_SD:
this.icon.width=SD_ICON_WIDTH;
this.icon.height=SD_ICON_HEIGHT;
this.icon.src=IMG_PATH+"sd.png";
setf_text(this.label,MSG("LT_SD_CARD"));
break;
case this.device_info.TYPE_USB:
this.icon.width=USB_ICON_WIDTH;
this.icon.height=USB_ICON_HEIGHT;
this.icon.src=IMG_PATH+"usb.png";
setf_text(this.label,this.device_info.product);
break;}
this.icon.translate[0]=-this.frame.width/4-50;}
};
device_item.prototype.action=function(){
DeviceManager.write_device(this.device_info);};
var DeviceList=new pkg_friends.VList(focus_moveto,device_item);
DeviceList.show=function(param){
if(!param)return;
var device_list=param.device_list||[];
var list_data=[];
for(var i=0;i<device_list.length;i++){
list_data.push({
width:DEVICE_ITEM_WIDTH,
height:DEVICE_ITEM_HEIGHT,
device_info:device_list[i],
});}
var title_pos=param.title_pos||[0,0,0];
this.all_height=Math.min(list_data.length*DEVICE_ITEM_HEIGHT,760);
this.setSize(DEVICE_ITEM_WIDTH,this.all_height);
this.setItemMargin(0);
this.setDataList(list_data);
if(param.set_title_pos){
param.set_title_pos([0,this.all_height/2+DEVICE_TITLE_HEIGHT/2,0]);}
};
DeviceList.hide=function(){
this.free();};
DeviceList.free=FREE_FUNC;
DeviceList.enter_focus=function(){
this.onFocus(true);};
DeviceList.leave_focus=function(){
};
var DeviceManager=new container({});
DeviceManager.create=function(param){
if(this.components.length>0)return;
param=param||{};
this.return_btn_cont_cb=isFunction(param.return_btn_cont_cb)?param.return_btn_cont_cb:function(){};
this.confirm=Confirm;
this.loading=Loading;
this.index=0;
this.http_req=0;
this.export_content="";
this.visible_p=false;
this.bg_mask=new container({
visible_p:false,
components:[
new gbox({width:MAX_WIDTH,height:MAX_HEIGHT,color:[0,0,0,180]})
]
});
this.bg_mask.free=FREE_FUNC;
this.bg_mask.show=function(){
this.visible_p=true;};
this.bg_mask.hide=function(){
this.visible_p=false;};
this.title=new container({});
this.title.components=[
this.frame=new gbox({
width:DEVICE_ITEM_WIDTH,
height:DEVICE_TITLE_HEIGHT,
color:COL_BORDER_ONBASE
}),
this.bg=new gbox({
width:this.frame.width-2,
height:this.frame.height-2,
color:COL_BASE
}),
this.label=new gtext({
width:DEVICE_ITEM_WIDTH-DEVICE_ITEM_WIDTH/4,
align:CENTER,font_size:40,
text:MSG("LT_DEVICE_SELECT"),
color:COL_TEXT_ONBASE
})
];
change_font_size(this.label);
this.components=[
this.title,
this.device_list=DeviceList
];};
DeviceManager.free=FREE_FUNC;
DeviceManager.get_device_list=function(){
var devices=[];
var sd_disk=ebus.storage.get_sd_disk();
var usb_disk=ebus.storage.get_usb_disk();

devices=devices.concat(sd_disk);
devices=devices.concat(usb_disk);
var verified_devices=[];
for(var i=0;i<devices.length;i++){
try{
if(new File(devices[i].path).exists)
verified_devices.push(devices[i]);}catch(e){
continue;}
}
return verified_devices;};
DeviceManager.set_title_pos=function(pos){
if(!pos)return;
this.title.translate=pos;};
DeviceManager.show=function(content_info){
if(!content_info)return;
if(!isString(content_info.appli_id)||content_info.appli_id.length==0)return;
var device_list=this.get_device_list();
var self=this;
if(device_list.length>0){
this.export_content=content_info;
this.device_list.show({
device_list:device_list,
set_title_pos:function(position){
self.set_title_pos(position);}
});
this.bg_mask.show();
set_cursor(this,this.device_list);
this.visible_p=true;}else {
this.hide();
this.showConfirm(MSG("LT_PH_NO_MEDIA"));}
};
DeviceManager.hide=function(){
this.bg_mask.hide();
this.visible_p=false;
this.device_list.free();
set_cursor(this,null);};
DeviceManager.check_capacity=function(device,file){
var capa_over=false;
if(device.avail_size==0){
capa_over=true;}else {
var byte_avail=device.avail_size*1000*1000;
if(byte_avail<file.length){
capa_over=true;}
}
return capa_over;};
DeviceManager.get_data=function(param){
if(!param||!param.device||!param.appli_id)return;
var self=this;
this.loading.setShow(true,null,function(){
if(self.http_req)cancel_http_request(self.http_req);
this.setShow(false);
self.http_req=0;
self.return_btn_cont_cb();});
if(this.http_req)cancel_http_request(this.http_req);
var path=param.path||"";
var device=param.device;
var export_name="";
var export_extension="";
switch(param.appli_id){
case APPLI_TABLE[APPLI_ID_PHOTO]:export_name=EXPORT_PHOTO_NAME;
export_extension=EXPORT_PHOTO_EXTENSION;
break;
default:export_name=EXPORT_VIDEO_NAME;
export_extension=EXPORT_VIDEO_EXTENSION;}
this.http_req=http_request({
timeout:TIMEOUT_L,
method:"GET",
url:param.path,
sync:false,
onload:function(status,header,body){
self.http_req=0;
if(status==200){
var write_device=new File(device.path);
if(!write_device.exists){
self.showConfirm(MSG("LT_VM_NO_EXT_FOUND"));}else if(device.is_write_protected()){
self.showConfirm(MSG("LT_CG_REC_ERR_SDCARD_LOCKED"));}else if(self.check_capacity(device,body)){
self.showConfirm(MSG("LT_VM_NO_CAPACITY"));}else if(!write_device.canWrite){
self.showConfirm(MSG("LT_VM_SAVE_FAIL"));}else {
var write_folder="";
if(device.type==device.TYPE_SD){
write_folder=write_device.path+"/";}else {
write_folder=write_device.path;}
var file_index=0;
var file_number=make_digit(file_index);
var file_name=export_name+file_number+export_extension;
var write_file=new File(write_folder+file_name);
while(write_file.exists){
file_index++;
file_number=make_digit(file_index);
file_name=export_name+file_number+export_extension;
write_file=new File(write_folder+file_name);}
if(file_index>MAX_FILE_NO){
self.showConfirm(MSG("LT_VM_SAVE_FAIL"));}else {
try{
write_file.open("write,create","binary");
try{
write_file.write(body);
write_file.close();
self.showConfirm(MSG("LT_VM_COMP_SAVE")+"\n\n"+file_name);}catch(e){
write_file.close();
if(write_file.exists)write_file.remove();
self.showConfirm(MSG("LT_VM_SAVE_FAIL"));}
}catch(e){
self.showConfirm(MSG("LT_VM_SAVE_FAIL"));}
}
}
}else {
self.showConfirm(MSG("LT_VM_SAVE_FAIL"));}
self.loading.setShow(false);}
});
set_cursor(this,this.loading);};
DeviceManager.write_device=function(device_info){
if(!device_info)return;
this.hide();
this.get_data({
path:this.export_content.stream,
appli_id:this.export_content.appli_id,
device:device_info
});};
DeviceManager.showConfirm=function(msg){
msg=isString(msg)?msg:"";
var self=this;
this.confirm.show({
type:Confirm.TYPE_OK,text:msg,
ok_cb:function(){self.return_btn_cont_cb();}
});
set_cursor(this,this.confirm);};
DeviceManager.enter_focus=function(){};
DeviceManager.leave_focus=function(){};
DeviceManager.key_hook=function(up_down,key){
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_RETURN:
this.hide();
this.return_btn_cont_cb();
return true;}
return false;};
var MUS_settings={
WIDTH:1920,HEIGHT:1080,
DEFAULT_ICON_WIDTH:62,DEFAULT_ICON_HEIGHT:62,
CURRENT_ICON_WIDTH:84,CURRENT_ICON_HEIGHT:84,
TOP_INTERVAL:98,TOP_POS_Y:480,
CENTER_ICON_WIDTH:110,CENTER_ICON_HEIGHT:110,
CENTER_CURRENT_WIDTH:132,CENTER_CURRENT_HEIGHT:132,
CENTER_INTERVAL:185,
POPUP_HEIGHT:280,
CENTER_POS_Y:50,LIST_MAX_COUNT:6,
EXPAN_SCALE:0.33,SCALE_UNIT:10,
APPEAR_ALPHA:85,VANISH_ALPHA:51,
PROFILE_ADD:"ADD",
PROFILE_EDIT:"EDIT",
PROFILE_CREATE:"USER_CREATE",
LT_FUNC:null,
SETUPUSR_LAUNCH_FOCUS_MHC:6
};
var MUS_FREE=function(){
if(!this.components||this.components.length==0)
return;
for(var i=0;i<this.components.length;i++){
if(this.components[i] instanceof gtext||this.components[i] instanceof gtextbox)
setf_text(this.components[i],"");
else if(this.components[i] instanceof gimage)
this.components[i].src="";
else if(typeof this.components[i].free=="function")
this.components[i].free();}
this.components.splice(0,this.components.length);};
var MUS_user_icon=function(param){
this.select_action=null;
this.return_action=null;
this.user_info=param.info||{};
this.components=[
this.frame=new gimage({
width:MUS_settings.CURRENT_ICON_WIDTH+4,
height:MUS_settings.CURRENT_ICON_HEIGHT+4,
draw_type:DIRECT,
src:IMG_PATH+"current_user_bg.png",
}),
this.focus=new gimage({
width:param.width||MUS_settings.DEFAULT_ICON_WIDTH,
height:param.height||MUS_settings.DEFAULT_ICON_HEIGHT,
draw_type:DIRECT,
src:param.focus_icon||"",
visible_p:false,blend:true
}),
this.user_icon=new gimage({
width:param.width||MUS_settings.DEFAULT_ICON_WIDTH,
height:param.height||MUS_settings.DEFAULT_ICON_HEIGHT,
draw_type:DIRECT,blend:true,
src:param.icon||"",
}),
this.new_badge=new gimage({
width:25,height:25,
draw_type:DIRECT,
src:IMG_PATH+"badge_r_small.png",
translate:[MUS_settings.DEFAULT_ICON_WIDTH/2,MUS_settings.DEFAULT_ICON_HEIGHT/2,0],
visible_p:false
}),
this.name=new gtext({
width:MUS_settings.DEFAULT_ICON_WIDTH,
align:CENTER,font_size:25,
omitter:"...",
text:param.name||"",
})
];};
MUS_user_icon.prototype=new container({});
MUS_user_icon.prototype.free=MUS_FREE;
MUS_user_icon.prototype.set_pos=function(pos){
this.translate=pos||[0,0,0];};
MUS_user_icon.prototype.setData=function(param){
this.name.width=param.name_width;
this.name.translate=param.name_pos||[0,0,0];
setf_text(this.name,this.name.text);
this.init_name_color=param.name_color;
this.name.color=this.init_name_color.slice();
this.name.color[3]=0;
this.user_icon.width=param.icon_w||MUS_settings.CENTER_ICON_WIDTH;
this.user_icon.height=param.icon_h||MUS_settings.CENTER_ICON_HEIGHT;
this.user_icon.color=param.icon_color;
this.frame.width=param.frame_w||this.user_icon.width+6;
this.frame.height=param.frame_h||this.user_icon.height+6;
this.frame.color=param.frame_color;
this.focus.color=param.focus_color.slice();
this.focus.color[3]=0;
var frame_view=param.frame_view||false;
if(frame_view){
this.focus.width=param.focus_width||this.frame.width+Math.floor(this.frame.width*MUS_settings.EXPAN_SCALE);
this.focus.height=param.focus_height||this.frame.height+Math.floor(this.frame.height*MUS_settings.EXPAN_SCALE);}else {
this.focus.width=param.focus_width||this.user_icon.width+Math.floor(this.user_icon.width*MUS_settings.EXPAN_SCALE);
this.focus.height=param.focus_height||this.user_icon.height+Math.floor(this.user_icon.height*MUS_settings.EXPAN_SCALE);}
this.frame_view(frame_view);
this.select_action=param.select_action||function(){};
this.return_action=param.return_action||function(){};};
MUS_user_icon.prototype.frame_view=function(bool){
this.frame.visible_p=bool;};
MUS_user_icon.prototype.zoom_focus=function(){
if(this.frame.visible_p){
this.focus.width=this.frame.width+Math.floor(this.frame.width*MUS_settings.EXPAN_SCALE);
this.focus.height=this.frame.height+Math.floor(this.frame.height*MUS_settings.EXPAN_SCALE);}else {
this.focus.width=this.user_icon.width+Math.floor(this.user_icon.width*MUS_settings.EXPAN_SCALE);
this.focus.height=this.user_icon.height+Math.floor(this.user_icon.height*MUS_settings.EXPAN_SCALE);}
};
MUS_user_icon.prototype.reduce_focus=function(){
this.focus.width=this.user_icon.width+Math.floor(this.user_icon.width*MUS_settings.EXPAN_SCALE);
this.focus.height=this.user_icon.height+Math.floor(this.user_icon.height*MUS_settings.EXPAN_SCALE);};
MUS_user_icon.prototype.new_badge_view=function(bool){
if(bool){
this.new_badge.visible_p=true;}else {
this.new_badge.visible_p=false;}
this.set_badge_pos();};
MUS_user_icon.prototype.set_badge_pos=function(){
this.new_badge.translate=[this.user_icon.width/2,this.user_icon.height/2,0];};
MUS_user_icon.prototype.onFocus=function(){
this.focus.visible_p=true;
this.name.color=this.init_name_color.slice();
this.name.color[3]=0;
delete_timer(this);
append_timer(this,40,function(obj,count){
obj.focus.color[3]+=MUS_settings.APPEAR_ALPHA;
obj.name.color[3]+=MUS_settings.APPEAR_ALPHA;
if(obj.focus.color[3]>=255){
obj.focus.color[3]=255;
obj.name.color=obj.init_name_color;
obj.name.visible_p=true;
delete_timer(obj);}
force_redraw();});
force_redraw();};
MUS_user_icon.prototype.offFocus=function(){
this.name.visible_p=true;
this.name.color=this.init_name_color.slice();
delete_timer(this);
append_timer(this,40,function(obj,count){
obj.focus.color[3]-=MUS_settings.VANISH_ALPHA;
obj.name.color[3]-=MUS_settings.VANISH_ALPHA;
if(obj.focus.color[3]<=0){
obj.focus.color[3]=0;
obj.name.color=obj.init_name_color;
obj.name.visible_p=false;
delete_timer(obj);}
force_redraw();});
force_redraw();};
MUS_user_icon.prototype.select=function(w,h){
var self=this;
delete_timer(this.user_icon);
append_timer(this.user_icon,40,function(obj,count){
obj.width+=Math.floor((obj.width-MUS_settings.SCALE_UNIT)/8);
obj.height+=Math.floor((obj.height-MUS_settings.SCALE_UNIT)/8);
self.zoom_focus();
if(obj.width>=w||obj.height>=h){
obj.width=w;
obj.height=h;
self.frame_view(true);
self.zoom_focus();
self.set_badge_pos();
delete_timer(obj);}
force_redraw();});};
MUS_user_icon.prototype.un_select=function(w,h){
var self=this;
this.frame_view(false);
delete_timer(this.user_icon);
append_timer(this.user_icon,40,function(obj,count){
obj.width-=Math.floor((obj.width-MUS_settings.SCALE_UNIT)/8);
obj.height-=Math.floor((obj.height-MUS_settings.SCALE_UNIT)/8);
if(obj.width<=w||obj.height<=h){
obj.width=w;
obj.height=h;
self.reduce_focus();
self.set_badge_pos();
delete_timer(obj);}
force_redraw();});};
MUS_user_icon.prototype.enter_focus=function(){
this.onFocus();};
MUS_user_icon.prototype.leave_focus=function(){
this.offFocus();};
MUS_user_icon.prototype.key_hook=function(up_down,key){
if(up_down!=KEY_PRESS)return true;
switch(key){
case TXK_ENTER:
this.select_action(this.user_info);
return true;
case TXK_RETURN:
this.return_action();
return true;};
return false;};
var MUS_setting_item=function(param){
if(!param)return;
this.max_width=600;
this.width=param.width||160;
this.height=param.height||60;
this.translate=param.translate||[0,0,0];
this.components=[
this.frame=new gbox({
width:this.width,
height:this.height,
color:COL_POP_BORDER
}),
this.bg=new gbox({
width:this.frame.width-2,
height:this.frame.height-2,
color:COL_POP
}),
this.label=new gtext({
width:this.frame.width-10,
align:CENTER,font_size:32,
color:COL_TEXT_ONBASE,
text:param.text||"",
})
];
this.action=param.action||function(){};
this.width=get_text_width(this.label,this.label.text)+60;};
MUS_setting_item.prototype=new container({});
MUS_setting_item.prototype.free=MUS_FREE;
MUS_setting_item.prototype.set_position=function(pos){
if(pos)this.translate=pos;};
MUS_setting_item.prototype.setSize=function(w){
this.width=(w<this.max_width)?w:this.max_width;
this.frame.width=this.width;
this.frame.height=this.height;
this.bg.width=this.frame.width-2;
this.bg.height=this.frame.height-2;
this.label.width=this.frame.width-60;
var label_font=change_font_size(this.label);
this.label.font_size=label_font;
setf_text(this.label,this.label.text);};
var MUS_setting_list=new container({});
MUS_setting_list.create=function(){
var width=200;
var height=60;
var self=this;
this.index=0;
this.current_user=null;
this.visible_p=false;
this.before_action=function(){return false};
this.edit=new MUS_setting_item({
width:width,height:height,
text:MUS_settings.LT_FUNC("LT_CG_EDIT_USER"),
action:function(){
if(!self.before_action(MUS_settings.PROFILE_EDIT)){
if(self.current_user&&isNumber(self.current_user.id)){
var args="-U"+" "+self.current_user.id+" "+"-f"+" "+MUS_settings.SETUPUSR_LAUNCH_FOCUS_MHC;
apputil.launch_apl(SETUPUSER_APPS,args);}
}
}
});
this.add=new MUS_setting_item({
width:width,height:height,
text:MUS_settings.LT_FUNC("LT_CG_ADD_USER"),
action:function(){
if(!self.before_action(MUS_settings.PROFILE_ADD)){
apputil.launch_apl(SETUPUSER_APPS,"-C");}
}
});
this.width_adjustment();};
MUS_setting_list.free=MUS_FREE;
MUS_setting_list.hide=function(){
MultiUserSelection.on_setting_focus();};
MUS_setting_list.adjustment=function(){
var pos_y=this.edit.translate[0]-this.edit.height;
for(var i=0;i<this.components.length;i++){
this.components[i].set_position([0,pos_y*i,0]);};};
MUS_setting_list.set_current_user=function(current_user){
this.current_user=current_user||null;};
MUS_setting_list.all_show=function(){
this.components=[this.edit,this.add];
this.adjustment();};
MUS_setting_list.edit_show=function(){
this.components=[this.edit];
this.adjustment();};
MUS_setting_list.add_show=function(){
this.components=[this.add];
this.adjustment();};
MUS_setting_list.get_list_width=function(){
var longer=(this.add.width>this.edit.width)?this.add.width:this.edit.width;
return longer;};
MUS_setting_list.width_adjustment=function(){
var width=this.get_list_width();
this.edit.setSize(width);
this.add.setSize(width);};
MUS_setting_list.set_translate=function(translate){
if(translate)this.translate=translate;};
MUS_setting_list.set_before_action=function(action){
this.before_action=action||function(){return false};};
MUS_setting_list.enter_action=function(){
this.components[this.index].action();};
MUS_setting_list.focus_move=function(){
var pos=[this.translate[0],this.translate[1]+this.components[this.index].translate[1],0]
var size=[this.components[this.index].width,this.components[this.index].height];
focus.moveTo(pos,size,0,20,function(){});};
MUS_setting_list.enter_focus=function(){
focus.setShow(true);
this.visible_p=true;
this.focus_move();};
MUS_setting_list.leave_focus=function(){
focus.setShow(false);
this.index=0;
this.current_user=null;
this.visible_p=false;};
MUS_setting_list.key_hook=function(up_down,key){
if(up_down!=KEY_PRESS)return true;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_LEFT:
case TXK_RIGHT:
return true;
case TXK_UP:
if(this.index-1>=0){
this.index--;
this.focus_move();}
return true;
case TXK_DOWN:
if(this.index+1<this.components.length){
this.index++;
this.focus_move();}
return true;
case TXK_ENTER:
this.enter_action();
return true;
case TXK_RETURN:
this.hide();
return true;}
return false;};
var MUS_create_user=new container({});
MUS_create_user.create=function(){
this.TEXT_MAX_WIDTH=600;
this.translate=[0,492,0];
this.before_action=function(){return false};
this.components=[
this.dummy_icon=new gimage({
width:50,height:50,
draw_type:DIRECT,
src:IMG_PATH+"filer_prepare.png",
}),
this.create_text=new gtext({
width:this.TEXT_MAX_WIDTH,
font_size:45,translate:[0,2,0],
text:MUS_settings.LT_FUNC("LT_CG_CREATE_USER")
})
];
this.set_position();};
MUS_create_user.free=MUS_FREE;
MUS_create_user.set_position=function(){
var text_width=get_text_width(this.create_text,this.create_text.text);
if(text_width>this.TEXT_MAX_WIDTH){
this.create_text.font_size=getFontSizeOfText(this.create_text,this.create_text.text,20);}else {
this.create_text.width=text_width;}
setf_text(this.create_text,this.create_text.text);
this.create_text.translate[0]=MUS_settings.WIDTH/2-this.create_text.width/2-45;
this.dummy_icon.translate[0]=this.create_text.translate[0]-this.create_text.width/2-50;};
MUS_create_user.set_before_action=function(action){
this.before_action=action||function(){return false};};
MUS_create_user.set_text_color=function(color){
this.create_text.color=color||COL_TEXT_ONBASE;};
MUS_create_user.enter_focus=function(){
var text_width=get_text_width(this.create_text,this.create_text.text);
if(text_width>this.TEXT_MAX_WIDTH)text_width=this.TEXT_MAX_WIDTH;
var to_pos=[this.dummy_icon.translate[0]+40+text_width/2-this.dummy_icon.width/2,this.translate[1],0];
var to_size=[this.dummy_icon.width+text_width+80,74];
focus.moveTo(to_pos,to_size,0,20,function(){});};
MUS_create_user.leave_focus=function(){
};
MUS_create_user.key_hook=function(up_down,key){
if(up_down!=KEY_PRESS)return true;
switch(key){
case TXK_ENTER:
if(!this.before_action(MUS_settings.PROFILE_CREATE)){
apputil.launch_apl(SETUPUSER_APPS,"-C");}
return true;};
return false;};
var MultiUserSelection=new container({});
MultiUserSelection.create=function(translation_func){
this.CURRENT_USER_BG_BLUE=[0x3b,0xad,0xff,0xff];
this.CENTER_NICKNAME_WIDTH=300;
this.TOP_NICKNAME_WIDTH=200;
this.visible_p=false;
this.index=0;
this.current=-1;
this.center_view=false;
this.no_id_flag=false;
this.icon_list=new container({});
this.popup_bg=new Confirmpanel(null,[],focus_moveto);
this.popup_bg.setTranslate(0,50,0);
this.setting_list=MUS_setting_list;
this.create_user=MUS_create_user;
this._sobj=null;
this.components=[
this.shade=new gbox({
width:MUS_settings.WIDTH,height:MUS_settings.HEIGHT,
color:[0,0,0,180],
visible_p:false
}),
this.popup_bg,
this.icon_list,
this.setting_list,
this.create_user
];
MUS_settings.LT_FUNC=translation_func||function(){return ""};
this.user_list=this.get_all_user_info();
if(this.user_list.length>0){
this.setting_list.create();
for(var i=0;i<this.user_list.length;i++){
this.icon_list.components.push(
new MUS_user_icon({
info:this.user_list[i],
focus_icon:IMG_PATH+"circle_focus.png",
icon:this.user_list[i].icon,
width:MUS_settings.DEFAULT_ICON_WIDTH,
height:MUS_settings.DEFAULT_ICON_HEIGHT,
name:this.user_list[i].name,
})
);};
this.icon_list.components.push(
new MUS_user_icon({
info:null,
focus_icon:IMG_PATH+"mus_setting_focus.png",
icon:IMG_PATH+"mus_setting.png",
width:69,height:53,
name:MUS_settings.LT_FUNC("LT_CL_SETTING")
})
);}else {
this.no_id_flag=true;
this.create_user.create();}
};
MultiUserSelection.destroy=function(){
this.list_free();
this.setting_list.free();
this.free();};
MultiUserSelection.free=MUS_FREE;
MultiUserSelection.list_free=function(){
for(var i=0;i<this.icon_list.components.length;i++){
this.icon_list.components[i].free();}
};
MultiUserSelection.get_all_profile_id=function(){
var all_id=[];
try{
var profile=system.user_profile.get({});
if(profile&&profile.mhc&&profile.mhc.all){
all_id=profile.mhc.all;}
}catch(e){
console.log(e);}
return all_id;};
MultiUserSelection.get_all_user_info=function(){
if(!system.user_profile||!system.user_profile.supported)return;
var user_list=[];
var all_id=this.get_all_profile_id();
try{
for(var i=0;i<all_id.length;i++){
if(isNumber(all_id[i])){
var profile=system.user_profile.get({mhc:{id:all_id[i]}});
if(profile&&profile.mhc)user_list.push(profile.mhc);}
}
}catch(e){
console.log(e);}
return user_list;};
MultiUserSelection.set_visible=function(visible){
if(visible!=this.visible_p)this.visible_p=visible;};
MultiUserSelection.is_visible=function(){
return this.visible_p;};
MultiUserSelection.is_center=function(){
return this.center_view;};
MultiUserSelection.setShow=function(param){
if(!param)return;
var view=param.view||false;
if(view){
var self=this;
var select_action=param.select_action||function(){};
var return_action=param.return_action||function(){};
var setting_action=param.setting_action||function(){return false};
var current_user=param.current_user||null;
var user_count=this.user_list.length;
var name_color=param.name_color||COL_TEXT_ONBASE;
var setting_icon_color=param.setting_icon_color||COL_ICON_ONBASE;
var current_user_bg_color=param.current_user_bg_color||COL_POINT_ONBASE;
this.center_view=param.center||false;
if(user_count>0){
if(this.center_view){
this.shade.visible_p=true;
var cont_width=(this.icon_list.components.length-1)*MUS_settings.CENTER_INTERVAL+MUS_settings.CENTER_ICON_WIDTH;
var init_x=-cont_width/2+MUS_settings.CENTER_ICON_WIDTH/2;
for(var i=0;i<user_count;i++){
var icon_w=MUS_settings.CENTER_ICON_WIDTH;
var icon_h=MUS_settings.CENTER_ICON_HEIGHT;
var frame_view=false;
if(current_user&&isNumber(current_user.id)&&current_user.id==this.user_list[i].id){
icon_w=MUS_settings.CENTER_CURRENT_WIDTH;
icon_h=MUS_settings.CENTER_CURRENT_HEIGHT;
frame_view=true;
this.current=i;}
this.icon_list.components[i].setData({
name_width:param.name_width||this.CENTER_NICKNAME_WIDTH,
name_pos:[0,-90,0],name_color:name_color,
icon_w:icon_w,icon_h:icon_h,icon_color:[255,255,255,255],
frame_w:MUS_settings.CENTER_CURRENT_WIDTH+6,
frame_h:MUS_settings.CENTER_CURRENT_HEIGHT+6,
frame_color:current_user_bg_color,
frame_view:frame_view,
focus_color:COL_FCS,
select_action:function(info){
select_action(info,function(){self.icon_select()});},
return_action:return_action,
});}
this.icon_list.components[user_count].setData({
name_width:param.name_width||this.CENTER_NICKNAME_WIDTH,
name_pos:[0,-90,0],name_color:name_color,
icon_w:138,icon_h:106,icon_color:setting_icon_color,
focus_width:138,focus_height:106,
frame_color:[255,255,255,0],
focus_color:[255,255,255,0],
select_action:function(){
self.setting_show();},
return_action:return_action,
});
for(var i=0;i<this.icon_list.components.length;i++){
this.icon_list.components[i].set_pos([init_x+(i*MUS_settings.CENTER_INTERVAL),MUS_settings.CENTER_POS_Y,0]);}
var set_icon_pos=this.icon_list.components[user_count].translate;
this.setting_list.translate=[set_icon_pos[0],set_icon_pos[1]-MUS_settings.CENTER_ICON_HEIGHT,0];
var popup_width=user_count*MUS_settings.CENTER_INTERVAL+MUS_settings.CENTER_INTERVAL*2;
this.popup_bg.setSize(popup_width,MUS_settings.POPUP_HEIGHT);
this.popup_bg.setShow(true);}else {
this.shade.visible_p=false;
for(var i=0;i<user_count;i++){
var icon_w=MUS_settings.DEFAULT_ICON_WIDTH;
var icon_h=MUS_settings.DEFAULT_ICON_HEIGHT;
var frame_view=false;
if(current_user&&isNumber(current_user.id)&&current_user.id==this.user_list[i].id){
icon_w=MUS_settings.CURRENT_ICON_WIDTH;
icon_h=MUS_settings.CURRENT_ICON_HEIGHT;
frame_view=true;
this.current=i;};
this.icon_list.components[i].setData({
name_width:param.name_width||this.TOP_NICKNAME_WIDTH,
name_pos:[0,-65,0],name_color:name_color,
icon_w:icon_w,icon_h:icon_h,icon_color:[255,255,255,255],
frame_w:MUS_settings.CURRENT_ICON_WIDTH+6,
frame_h:MUS_settings.CURRENT_ICON_HEIGHT+6,
frame_color:current_user_bg_color,
frame_view:frame_view,
focus_color:COL_FCS,
select_action:function(info){
select_action(info,function(){self.icon_select()});},
return_action:return_action,
});}
this.icon_list.components[user_count].setData({
name_width:param.name_width||this.TOP_NICKNAME_WIDTH,
name_pos:[0,-65,0],name_color:name_color,
icon_w:69,icon_h:53,icon_color:setting_icon_color,
focus_width:69,focus_height:53,
frame_color:[255,255,255,0],
focus_color:[255,255,255,0],
select_action:function(){
self.setting_show();},
return_action:return_action,
});
var align=MUS_settings.WIDTH/2-MUS_settings.DEFAULT_ICON_WIDTH-40;
var icon_len=this.icon_list.components.length;
for(var i=0;i<this.icon_list.components.length;i++){
var pos_x=align-((icon_len-1)-i)*MUS_settings.TOP_INTERVAL;
this.icon_list.components[i].set_pos([pos_x,MUS_settings.TOP_POS_Y,0]);};
var set_icon_pos=this.icon_list.components[icon_len-1].translate;
var set_span=MUS_settings.WIDTH/2-set_icon_pos[0]-10;
var list_width=this.setting_list.get_list_width();
var list_pos=Math.floor(set_icon_pos[0]-list_width/2+set_span);
this.setting_list.translate=[list_pos,set_icon_pos[1]-MUS_settings.DEFAULT_ICON_HEIGHT-20,0];
this.popup_bg.setShow(false);}
this.setting_list.set_before_action(setting_action);}else {
this.create_user.set_before_action(setting_action);
this.create_user.set_text_color(name_color);}
this.visible_p=true;}else {
this.visible_p=false;}
};
MultiUserSelection.on_setting_focus=function(){
set_cursor(this._sobj,this);
this.index=this.icon_list.components.length-1;
this.move_focus();};
MultiUserSelection.onFocus=function(_sobj){
if(!_sobj)return;
this._sobj=_sobj;
if(this.no_id_flag){
set_cursor(this._sobj,this.create_user);}else {
focus.setShow(false);
if(this.current>=0){
this.index=this.current;}
set_cursor(this._sobj,this);
this.move_focus();}
};
MultiUserSelection.move_focus=function(reduce_idx){
set_cursor(this,this.icon_list.components[this.index]);};
MultiUserSelection.icon_select=function(){
if(this.index==this.current)return;
if(this.current>=0){
var reduce_w=MUS_settings.DEFAULT_ICON_WIDTH;
var reduce_h=MUS_settings.DEFAULT_ICON_HEIGHT;
if(this.center_view){
reduce_w=MUS_settings.CENTER_ICON_WIDTH;
reduce_h=MUS_settings.CENTER_ICON_HEIGHT;}
this.icon_list.components[this.current].un_select(reduce_w,reduce_h);}
var zoom_w=MUS_settings.CURRENT_ICON_WIDTH;
var zoom_h=MUS_settings.CURRENT_ICON_HEIGHT;
if(this.center_view){
zoom_w=MUS_settings.CENTER_CURRENT_WIDTH;
zoom_h=MUS_settings.CENTER_CURRENT_HEIGHT;}
this.icon_list.components[this.index].select(zoom_w,zoom_h);
this.current=this.index;};
MultiUserSelection.setting_show=function(){
if(this.user_list.length<MUS_settings.LIST_MAX_COUNT){
if(this.current>=0){
this.setting_list.set_current_user(this.user_list[this.current]);
this.setting_list.all_show();
set_cursor(this,null);}else {
this.setting_list.add_show();
set_cursor(this,null);}
set_cursor(this,this.setting_list);}else {
if(this.current>=0){
this.setting_list.set_current_user(this.user_list[this.current]);
this.setting_list.edit_show();
set_cursor(this,null);
set_cursor(this,this.setting_list);}
}
}
MultiUserSelection.new_badge_view=function(profile_id,view){
for(var i=0;i<this.icon_list.components.length;i++){
var user_info=this.icon_list.components[i].user_info;
if(user_info&&isNumber(user_info.id)&&user_info.id==profile_id){
this.icon_list.components[i].new_badge_view(view);
return;}
}
};
MultiUserSelection.enter_focus=function(){
};
MultiUserSelection.leave_focus=function(){
focus.setShow(true);
this._sobj=null;
set_cursor(this,null);};
MultiUserSelection.key_hook=function(up_down,key){
if(up_down!=KEY_PRESS)return true;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_LEFT:
if(!this.cursor||this.index-1<0)return true;
this.index--;
var reduce_idx=this.index+1;
this.move_focus();
return true;
case TXK_RIGHT:
if(!this.cursor||this.index+1>this.icon_list.components.length-1)return true;
this.index++;
var reduce_idx=this.index-1;
this.move_focus();
return true;}
return false;};
var TitleArea=new container({});
TitleArea.init=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=param.width||0;
this.height=param.height||0;
this.enter_cb=isFunction(param.enter_cb)?param.enter_cb:function(){};

this.bg=new gbox({
width:this.width,height:this.height,color:COL_BASE
});
this.title=new gtext({
width:this.width-80,font_size:56,color:COL_TEXT_ONBASE,omitter:"..."
});
this.title.translate=[0,(this.height-this.title.font_size)/2-10,0];
this.account_view=new container({
visible_p:false,
components:[
this.user_icon=new gimage({
width:50,height:50,translate:[0,10,0],draw_type:DIRECT,
src:IMG_PATH+"filer_prepare.png"
}),
this.user=new gtext({
width:900,translate:[480,13,0],font_size:45,align:RIGHT,color:COL_TEXT_ONBASE,
text:MSG("LT_CG_SETUP_ACCOUNT")
})
]
});
var name_width=get_text_width(this.user,this.user.text);
this.user_icon.translate[0]=this.user.translate[0]+this.user.width/2-name_width-this.user_icon.width/2-30;
this.mus=MultiUserSelection;
this.components=[this.bg,this.title,this.account_view];};
TitleArea.enter_focus=function(){
if(user_profile_mgr.getMultiuserSupported()){
set_cursor(this,this.mus);
this.mus.onFocus(this);}else {
set_cursor(this,this.account_view);
this.moveFocus();}
};
TitleArea.leave_focus=function(){
set_cursor(this,null);};
TitleArea.setTitle=function(title){
if(!this.title)return;
if(typeof title=="string")
setf_text(this.title,title);};
TitleArea.setShowAccountView=function(bool){
if(user_profile_mgr.getMultiuserSupported())return;if(isBoolean(bool)&&this.account_view.visible_p!=bool)
this.account_view.visible_p=bool;};
TitleArea.isFocusEnable=function(){
if(user_profile_mgr.getMultiuserSupported())
return (this.mus.is_visible()&&!this.mus.is_center());
else
return this.account_view.visible_p;};
TitleArea.moveFocus=function(){
var name_width=get_text_width(this.user,this.user.text);
var to_size=[name_width+30+this.user_icon.width+this.user_icon.width/2+15,74];
var to_pos=[this.user_icon.translate[0]+30+name_width/2-15,this.translate[1]+10,0];
focus_moveto(to_pos,to_size);};
TitleArea.keyEnter=function (){
this.enter_cb();};
TitleArea.key_hook=function (up_down,key){
if(up_down!=KEY_PRESS)return false;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_ENTER:
return this.keyEnter();}
return false;};
function LabelRow(param){
this.superClass=container;
this.superClass({});
this.delete_img_path=path+"img/trash.png";
this.delete_param_onbase={w:35,h:37,color:COL_ICON_ONBASE};
this.delete_param_onpoint={w:49,h:52,color:COL_TEXT_ONBASE};};
LabelRow.prototype.create=function(param){
if(this.components.length>0)return;
param=param||{};

this.width=param.width||0;
this.height=param.height||100;
this.color=param.color||[255,255,255,255];
this.font_size=param.font_size||40;};
LabelRow.prototype._free=FREE_FUNC;
LabelRow.prototype.free=function(){
this._free();
if(this.item_list)
this.item_list.splice(0,this.item_list.length);
if(this._req_list){
for(var i=0;i<this._req_list.length;i++)
if(this._req_list[i])
cancel_http_request(this._req_list[i]);
this._req_list.splice(0,this._req_list.length);}
};
LabelRow.prototype.setData=function(param){
param=param||{};
this.span=isNumber(param.span)?param.span:20;
this.focus_table=param.focus_table||[];
this.data_list=param.data_list||[];
this.components=[];
this.item_list=[];
this._req_list=[];
var total_w=0;
for(var i=0;i<this.data_list.length;i++){
var data=this.data_list[i];
this._setDefaultToData(data);
var item=new container({});
item.free=FREE_FUNC;
switch(data.type){
case "Text":
case "TextBox":
case "From":
case "To":
case "Appli":
case "Message":
case "Delete":
case "Space":
if(isFunction(this["_genItem"+data.type])){
item.components=this["_genItem"+data.type](data);
item.type=data.type;}else {
console.log(" Error ...");}
break;};
item.width=data.width;
total_w+=item.width;
this.item_list.push(item);
this.components.push(item);}
total_w+=(this.components.length-1)*this.span;
this.width=total_w;
for(i=0;i<this.components.length;i++){var trg=this.components[i];
if(i==0){
trg.translate[0]=-(total_w-trg.width)/2;}else {
var base_x=this.components[i-1].translate[0];
trg.translate[0]=base_x+(this.components[i-1].width+trg.width)/2+this.span;}
}
};
LabelRow.prototype._setDefaultToData=function(data){
if(!data)return;
if(!isString(data.type)||(data.type.lenght<0))data.type="Text";
if(!isNumber(data.width))data.width=200;
if(!isNumber(data.height))data.height=100;
if(!isNumber(data.align))data.align=LEFT;
if(!isString(data.text)||(data.text.lenght<0))data.text="";
if(!isString(data.src)||(data.src.lenght<0))data.src="";
if(!isString(data.user_key)||(data.user_key.lenght<0))data.user_key="";
if(typeof data.data!="object")data.data={};};
LabelRow.prototype._genItemText=function(data){
var comp=[];
var text=new gtext({
width:data.width,color:this.color,text:data.text,
translate:[0,2,0],font_size:this.font_size,align:data.align
});
comp.push(text);
return comp;};
LabelRow.prototype._genItemTextBox=function(data){
var comp=[];
var text=data.text||"";
var tbox=new gtextbox({
width:data.width,height:Math.floor((this.font_size*1.23)*2),color:this.color,
translate:[0,2,0],align:CENTER,valign:MIDDLE,font_size:this.font_size,text:text
});
change_font_size_b(tbox);
var real_tbox_h=get_text_font_height(tbox,text);
comp.push(tbox);
return comp;};
LabelRow.prototype._genItemAppli=function(data){
var comp=[];
var icon_w=Math.floor(data.height/7*10);
var img=new gimage({width:icon_w,height:data.height,src:data.src});
comp.push(img);
return comp;};
LabelRow.prototype._genItemFrom=function(data){
var comp=[];
var icon_size=isNumber(data.icon_size)?data.icon_size:100;
var label_w=data.width-icon_size-20;
var label_h=Math.floor(data.height*0.3);
var label_pos_x=(data.width-label_w)/2;
var icon=new gimage({
width:icon_size,height:icon_size,src:data.src,
translate:[-(data.width-icon_size)/2,0,0]
});
icon.cb=function(img){
if(this instanceof gimage)this.src=img;};
var name=new gtext({
width:label_w,color:this.color,align:LEFT,
translate:[label_pos_x,label_h/2+4,0],font_size:label_h,omitter:"..."
});
name.cb=function(text){
if(this instanceof gtext)setf_text(this,text);};
var date=new gtext({
width:label_w,color:this.color,text:data.date,align:LEFT,
translate:[label_pos_x,-(label_h/2+4),0],font_size:label_h,omitter:"..."
});
if(data.user_key==user_profile_mgr.getCurrentUserMHCUserkey()){
var mhc_icon=user_profile_mgr.getCurrentUserMHCIcon();
if(mhc_icon){
icon.cb(mhc_icon);}
name.cb(MSG("LT_CG_YOU"));}else {
this._req_list[this._req_list.length]=friend_list_mgr.getFriendList().getUserData(
[data.user_key],
function(user_data_list){
if(!user_data_list||user_data_list.length<=0||!user_data_list[0].id){console.log(" >> user data request error...");}else {
icon.cb(user_data_list[0].face);
name.cb(user_data_list[0].nickname);}
}
);}
comp.push(icon,name,date);
return comp;};
LabelRow.prototype._genItemTo=function(data){
var comp=[];
var icon_size=isNumber(data.icon_size)?data.icon_size:100;
var label_w=data.width-icon_size-20;
var label_pos_x=(data.width-label_w)/2;
var icon=new gimage({
width:icon_size,height:icon_size,src:data.src,
translate:[-(data.width-icon_size)/2,0,0]
});
icon.cb=function(img){
if(this instanceof gimage)this.src=img;};
var name=new gtext({
width:label_w,color:this.color,align:LEFT,
translate:[label_pos_x,2,0],font_size:Math.floor(data.height*0.3),omitter:"..."
});
name.cb=function(text){
if(this instanceof gtext)setf_text(this,text);};
if(data.user_key==user_profile_mgr.getCurrentUserMHCUserkey()){
var mhc_icon=user_profile_mgr.getCurrentUserMHCIcon();
if(mhc_icon){
icon.cb(mhc_icon);}
name.cb(MSG("LT_CG_YOU"));}else {
this._req_list[this._req_list.length]=friend_list_mgr.getFriendList().getUserData(
[data.user_key],
function(user_data_list){
if(!user_data_list||user_data_list.length<=0||!user_data_list[0].id){console.log(" >> user data request error...");}else {
icon.cb(user_data_list[0].face);
name.cb(user_data_list[0].nickname);}
}
);}
comp.push(icon,name);
return comp;};
LabelRow.prototype._genItemMessage=function(data){
var comp=[];
var img;
var msg_arg=data.msg_arg||{};
var text=msg_arg.message||"";
if(MSG(msg_arg.message_label))
text=MSG(msg_arg.message_label);
var img_w=Math.floor(data.height/9*16);
if(isString(msg_arg.thumb_url)&&msg_arg.thumb_url.length>0){
img=new gimage({
width:img_w,height:data.height,dec_width:img_w,dec_height:data.height,
src:msg_arg.thumb_url,translate:[-(data.width-img_w)/2,0,0]
});
comp.push(img);}
var tbox_w=data.width-img_w-30;
var tbox_pos_x=(data.width-tbox_w)/2;
var tbox_min_fsize=(this.font_size>10)?this.font_size-10:this.font_size;
var tbox=new gtextbox({
width:tbox_w,height:Math.floor((this.font_size*1.23)*2),color:this.color,
translate:[tbox_pos_x,2,0],align:LEFT,valign:MIDDLE,font_size:this.font_size
});
var real_tbox_h=get_text_font_height(tbox,text);
if(tbox.height<real_tbox_h)
tbox.valign=TOP;
setf_text(tbox,text);
comp.push(tbox);
return comp;};
LabelRow.prototype._genItemDelete=function(data){
var comp=[];
var del=new gimage({
width:this.delete_param_onbase.w,height:this.delete_param_onbase.h,
src:this.delete_img_path,color:this.delete_param_onbase.color
});
this.del_obj=del;
comp.push(del);
return comp;};
LabelRow.prototype._genItemSpace=function(data){
var comp=[];
var space=new gbox({width:data.width,height:data.height,color:[0,0,0,0]});
comp.push(space);
return comp;};
LabelRow.prototype.getItemContByType=function(type){
if(isString(type)){
for(var i=0;i<this.item_list.length;i++){
if(this.item_list[i].type==type)
return this.item_list[i];}
}
return null;};
LabelRow.prototype.enterDeleteCol=function(){
if(!this.del_obj)return;
if(this.del_obj.width==this.delete_param_onpoint.w)return;
this.del_obj.width=this.delete_param_onpoint.w;
this.del_obj.height=this.delete_param_onpoint.h;
this.del_obj.color=this.delete_param_onpoint.color;
force_redraw();};
LabelRow.prototype.leaveDeleteCol=function(){
if(!this.del_obj)return;
if(this.del_obj.width==this.delete_param_onbase.w)return;
this.del_obj.width=this.delete_param_onbase.w;
this.del_obj.height=this.delete_param_onbase.h;
this.del_obj.color=this.delete_param_onbase.color;
force_redraw();};
LabelRow.prototype.getFocusInfo=function(col_index){
var info={pos:[0,0,0],size:[this.width,this.height]};
if(!this.focus_table)Log(" >> info : "+info.toSource());
if(!this.focus_table)return info;
if(this.focus_table.length>0
&&(typeof this.focus_table[col_index]=="number")){
var head_pos=(this.focus_table.slice(0,col_index)).reduce(function(a,b){return a+b;},0);
var trg_list=this.item_list.slice(head_pos,head_pos+this.focus_table[col_index]);
var total_w=0;
for(var i=0;i<trg_list.length;i++){
total_w+=trg_list[i].width;}
if(trg_list.length>0){
total_w+=(trg_list.length-1)*this.span;
info.pos=[
(trg_list[0].translate[0]-trg_list[0].width/2+total_w/2),
this.translate[1],
this.translate[2]
];
info.size=[total_w,this.height];}
}
return info;};
var LabelHeader=new container({});
LabelHeader.init=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=param.width||0;
this.height=param.height||0;

this.bg=new gbox({
width:this.width,height:this.height,color:COL_BASE_SUB
});
this.label=new LabelRow({});
this.label.create({
width:this.width,height:this.height,style:LabelRow.STYLE_HEADER,
color:COL_TEXT_ONBASE,font_size:30
});
this.label.setData({
span:0,
data_list:[
{type:"Text",width:358,align:CENTER,text:MSG("LT_CG_FROM")},
{type:"Space",width:414},
{type:"Text",width:1148,align:LEFT,text:MSG("LT_HOME_MESSAGES")}
]
});
this.components=[this.bg,this.label];};
function MsgRow(param){
this.superClass=container;
this.superClass({});
this.width=param.width||0;
this.height=param.row_h||0;
this.line_h=param.line_h||0;
this.preview=null;}
MsgRow.ROW_TYPE_DEFAULT=0;
MsgRow.ROW_TYPE_DISCLAIMER=1;
MsgRow.prototype.create=function(param){
if(this.components.length>0)return;
param=param||{};
this.focus_table=param.focus_table||[];
var inner_h=this.height-this.line_h;
this.upper_line=new gbox({
width:this.width,height:this.line_h,color:COL_BORDER_ONBASE,
translate:[0,-this.height/2,0]
});
this.label=new LabelRow({});
this.label.create({
width:this.width,height:this.height,color:COL_TEXT_ONBASE,font_size:36
});
this.components=[this.upper_line,this.label];};
MsgRow.prototype._free=FREE_FUNC;
MsgRow.prototype.free=function(){
this._free();};
MsgRow.prototype.enter_focus=function(){};MsgRow.prototype.leave_focus=function(){};MsgRow.prototype.setRowData=function(data_item){
if(!data_item)return;
if(this.preview){
_do_preview(this.preview,"destroy");
this.preview=null;}
var data=data_item.data;
switch(data.row_type){
case MsgRow.ROW_TYPE_DISCLAIMER:
this.setRowDataDisclaimer(data);
return;}
var msg_arg={};
try{
msg_arg=JSON.parse(data.text_data);}catch(e){
perror(e);}
if(!msg_arg){
msg_arg={};}
var launch_ad_id=msg_arg.application_data_id||"";
var launchAppli_id=APPLI_TABLE[msg_arg.application_id]||"";
var create_date=getLastDateInCloudData(data);
var inner_h=this.height-20;
var icon_size=inner_h;
this.label.setData({span:0,
focus_table:this.focus_table,
data_list:[
{type:"Space",width:42},
{type:"From",width:471,user_key:data.data_owner,
date:getFormattedDateString(create_date),icon_size:icon_size},
{type:"Space",width:10},
{type:"Appli",width:155,height:inner_h,
src:APPLI_PATH+launchAppli_id+"/icon.png"},{type:"Message",width:1068,height:inner_h,msg_arg:msg_arg},
{type:"Delete",width:102}
]
});
var preview_size=PreviewCont.getPreviewSize();
var preview_arg={
width:preview_size.w,height:preview_size.h,
product_id:launchAppli_id,application_data_id:launch_ad_id,
mhc_authtoken:user_profile_mgr.getCurrentUserAuthToken(),
msg_arg:msg_arg
};
this.preview=evaluate_file.apply(this,[launchAppli_id,"gadget/msg_preview.js"]);
if(this.preview){
_do_preview(this.preview,"init",[preview_arg]);
_do_preview(this.preview,"prepare",[true]);}
};
MsgRow.prototype.setRowDataNothing=function(){
Log(" >> MsgRow.prototype.setRowDataNothing");
this.label.setData({span:0,focus_table:this.focus_table,
data_list:[
{type:"Text",width:1848,text:MSG("LT_HOME_NO_MESSAGE"),align:CENTER}
]
});};
MsgRow.prototype.setRowDataDisclaimer=function(data){
this.label.setData({
span:0,focus_table:this.focus_table,
data_list:[
{type:"TextBox",width:1848,text:data.label}
]
});};
MsgRow.prototype.getPosY=function(){
return this.translate[1];};
MsgRow.prototype.setPosY=function(y){
if(typeof y=="number")
this.translate[1]=y;};
MsgRow.prototype.getPosY=function(){
return this.translate[1];};
MsgRow.prototype.leaveDeleteCol=function(){
this.label.leaveDeleteCol();};
MsgRow.prototype.enterDeleteCol=function(){
this.label.enterDeleteCol();};
MsgRow.prototype.getPreview=function(){
return this.preview;};
MsgRow.prototype.getFocusInfo=function(col_index){
var info={pos:[],size:[]};
var label_focus_info=this.label.getFocusInfo(col_index);
for(var i=0;i<this.translate.length;i++)
info.pos[i]=this.translate[i]+label_focus_info.pos[i];
info.size=label_focus_info.size;
return info;};
var MsgList=new container({});
MsgList.init=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=param.width||0;
this.height=param.height||0;
this.row_h=param.row_h||0;
this.focus_table=param.focus_table||[];
this.HEAD_POS=1;
this.FOOT_POS=Math.floor(this.height/ this.row_h); //7?
this.MAX_NUM=this.FOOT_POS+2;this.index=this.HEAD_POS;this.list=[];
this.data_pos=0;var pos_y=(this.height+this.row_h)/2;
for(var i=0;i<this.MAX_NUM;i++){
var row=new MsgRow(param);
row.create({focus_table:this.focus_table});
row.setPosY(pos_y);
pos_y=pos_y-this.row_h;
this.list.push(row);}
this.components=this.list;};
MsgList._free=FREE_FUNC;
MsgList.free=function(){
this._free();};
MsgList.enter_focus=function(){
set_cursor(this,this.list[this.index]);};
MsgList.leave_focus=function(){
set_cursor(this,null);};
MsgList.setList=function(data_list){
if(typeof data_list!="object"||data_list.length==0){this.data_list=[];
this.list[1].setRowDataNothing();
return;}
this.data_list=data_list;
for(var i=this.HEAD_POS;i<=(this.HEAD_POS+this.FOOT_POS);i++){
this.list[i].setRowData(this.data_list[i-1]);}
this.translate=[0,0,0];};
MsgList.deleteMsg=function(ad_id,to_user_key){
if(!ad_id||!to_user_key)return;
if(!this.data_list)return;
this.data_list=this.data_list.filter(function(element){
if(!element||!element.data)return false;
return !(element.data.application_data_id==ad_id
&&element.to_user_key==to_user_key);});};
MsgList.getFocusInfo=function (col_index){var info={pos:[],size:[]};
if(this.cursor){
var cur_focus_info=this.cursor.getFocusInfo(col_index);
for(var i=0;i<this.translate.length;i++)
info.pos[i]=this.translate[i]+cur_focus_info.pos[i];
info.size=cur_focus_info.size;}
return info;};
MsgList.getCurrentMsgData=function (){
var data;
if(this.data_list[this.data_pos]&&this.data_list[this.data_pos].data)
data=this.data_list[this.data_pos].data;
return data;};
MsgList.getCurrentMsgToUserKey=function (){
var to_user_key="";
if(this.data_list[this.data_pos]&&this.data_list[this.data_pos].to_user_key)
to_user_key=this.data_list[this.data_pos].to_user_key;
return to_user_key;};
MsgList.getCurrentMsgPreview=function (){
return this.list[this.index].getPreview();};
MsgList.enterDeleteColCurrentRow=function (){
this.list[this.index].enterDeleteCol();};
MsgList.leaveDeleteColCurrentRow=function (){
this.list[this.index].leaveDeleteCol();};
MsgList.scrollUp=function(){
Log(" >> MsgList.scrollUp");
this.translate[1]-=this.row_h;
var row=this.list.pop();
row.free();
row.create({focus_table:this.focus_table});
row.setRowData(this.data_list[this.data_pos-1]);
var row_pos_y=this.list[0].getPosY()+this.row_h;
row.setPosY(row_pos_y);
this.list.unshift(row);
force_redraw();};
MsgList.scrollDown=function(){
Log(" >> MsgList.scrollDown");
this.translate[1]+=this.row_h;
var row=this.list.shift();
row.free();
row.create({focus_table:this.focus_table});
row.setRowData(this.data_list[this.data_pos+1]);
var row_pos_y=this.list[this.list.length-1].getPosY()-this.row_h;
row.setPosY(row_pos_y);
this.list.push(row);
force_redraw();};
MsgList.keyUp=function(){
var ret=false;
if(!this.data_list)return ret;
if(0<this.data_pos){
this.leaveDeleteColCurrentRow();
this.index--;
this.data_pos--;
if(this.index<this.HEAD_POS){this.index=this.HEAD_POS;
this.scrollUp();}
set_cursor(this,this.list[this.index]);
ret=true;}
return ret;};
MsgList.keyDown=function(){
var ret=false;
if(!this.data_list)return ret;
if(this.data_pos<this.data_list.length-1){
this.leaveDeleteColCurrentRow();
this.index++;
this.data_pos++;
if(this.FOOT_POS<this.index){this.index=this.FOOT_POS;
this.scrollDown();}
set_cursor(this,this.list[this.index]);
ret=true;}
return ret;};
MsgList.key_hook=function (up_down,key){
if(up_down!=KEY_PRESS)return false;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_UP:
return this.keyUp();
case TXK_DOWN:
return this.keyDown();}
return false;};
var MsgCont=new container({});
MsgCont.init=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=param.width||0;
this.height=param.height||0;
this.set_info=param;
this.col_index=0;
this.col_focus_info={action:["select","delete"],table:[5,1]};
param.focus_table=this.col_focus_info.table;
this.select_msg_cb=param.select_msg_cb||function(){};

this.list=MsgList;
this.components=[this.list];};
MsgCont.enter_focus=function(){
set_cursor(this,this.list);
this.moveFocus();
if(this.col_focus_info.action[this.col_index]=="delete")
this.list.enterDeleteColCurrentRow();
else
this.list.leaveDeleteColCurrentRow();};
MsgCont.leave_focus=function(){
set_cursor(this,null);};
MsgCont.setList=function(data_list){
this.list.free();
this.list.init(this.set_info);
this.list.setList(data_list);};
MsgCont.clearList=function(){
this.col_index=0;
this.list.free();};
MsgCont.deleteListMsg=function(ad_id,to_user_key){this.list.deleteMsg(ad_id,to_user_key);
this.list.free();
this.list.init(this.set_info);
this.list.setList(this.list.data_list);};
MsgCont.moveFocus=function(){
if(!this.cursor)return;
var cur_focus_info=this.cursor.getFocusInfo(this.col_index);
var pos=[];
for(var i=0;i<this.translate.length;i++)
pos[i]=this.translate[i]+cur_focus_info.pos[i];
focus_moveto(pos,cur_focus_info.size);
};
MsgCont.keyLeft=function(){
var ret=false;
if(0<this.col_index){
this.col_index--;
this.moveFocus();
if(this.col_focus_info.action[this.col_index]=="delete")
this.list.enterDeleteColCurrentRow();
else
this.list.leaveDeleteColCurrentRow();
ret=true;}
return ret;};
MsgCont.keyRight=function(){
var ret=false;
if(this.col_index<this.col_focus_info.table.length-1){
this.col_index++;
this.moveFocus();
if(this.col_focus_info.action[this.col_index]=="delete")
this.list.enterDeleteColCurrentRow();
else
this.list.leaveDeleteColCurrentRow();
ret=true;}
return ret;};
MsgCont.keyEnter=function(){
var msg_info={};
var msg_data=this.list.getCurrentMsgData();
if(msg_data){
switch(msg_data.row_type){
case MsgRow.ROW_TYPE_DISCLAIMER:
msg_info.action="launch_disclaimer";
break;
default:
var msg_arg={};
try{
msg_arg=JSON.parse(msg_data.text_data);}catch(e){
perror(e);}
if(!msg_arg){
msg_arg={};}
var user_key=this.list.getCurrentMsgToUserKey();
msg_info.action=this.col_focus_info.action[this.col_index];
msg_info.user_auth_token=user_profile_mgr.getUserAuthTokenByMHCUserKey(user_key);
msg_info.to_user_key=user_key;
msg_info.ad_id=msg_data.application_data_id||"";
msg_info.launch_ad_id=msg_arg.application_data_id||"";
msg_info.launchAppli_id=APPLI_TABLE[msg_arg.application_id]||"";
msg_info.preview=this.list.getCurrentMsgPreview();
break;}
}
this.select_msg_cb(msg_info);
return true;};
MsgCont.key_hook=function (up_down,key){
if(up_down!=KEY_PRESS)return false;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
this.moveFocus();
switch(key){
case TXK_UP:
case TXK_DOWN:
if(this.col_focus_info.action[this.col_index]=="delete"){
this.list.enterDeleteColCurrentRow();}
break;}
return true;}
switch(key){
case TXK_LEFT:
return this.keyLeft();
case TXK_RIGHT:
return this.keyRight();
case TXK_ENTER:
return this.keyEnter();}
return false;};
function Button(param){
this.superClass=container;
this.superClass({});};
Button.prototype=new container({});
Button.prototype.create=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=isNumber(param.width)?param.width:0;
this.height=isNumber(param.height)?param.height:0;
this.translate=param.translate||[0,0,0];
this.visible_p=isBoolean(param.visible_p)?param.visible_p:true;
this.label_text=param.label||"";
this.enter_func=isFunction(param.enter_func)?param.enter_func:function(){};
this.bg_out=new gbox({width:this.width,height:this.height,color:COL_BTN_BORDER}),
this.bg_in=new gbox({width:this.width-4,height:this.height-4,color:COL_BTN}),
this.label=new gtextbox({
width:this.width,height:this.height,text:this.label_text,
align:CENTER,valign:MIDDLE,color:COL_TEXT_ONBASE,font_size:38
});
change_font_size_b(this.label);
this.components=[this.bg_out,this.bg_in,this.label];};
Button.prototype._free=FREE_FUNC;
Button.prototype.free=function(){
this._free();};
Button.prototype.enter_focus=function(){};Button.prototype.leave_focus=function(){};Button.prototype.getFocusInfo=function(){
var info={pos:this.translate,size:[this.width,this.height]};
return info;};
Button.prototype.keyEnter=function (){
this.enter_func();
return true;};
Button.prototype.setShow=function(bool){
if(isBoolean(bool)&&this.visible_p!=bool){
this.visible_p=bool;
force_redraw();}
};
Button.prototype.isShow=function(bool){
return this.visible_p;};
Button.prototype.key_hook=function (up_down,key){
switch(key){
case TXK_ENTER:
return this.keyEnter();}
return false;};
function ImageButton(param){
this.superClass=Button;
this.superClass({});};
ImageButton.prototype=new Button({});
ImageButton.prototype.create=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=isNumber(param.width)?param.width:0;
this.height=isNumber(param.height)?param.height:0;
this.img_w=(param.img&&isNumber(param.img.width))?param.img.width:this.width;
this.img_h=(param.img&&isNumber(param.img.height))?param.img.height:this.height;
this.img_src=(param.img&&isString(param.img.src))?param.img.src:"";
this.img_color=(param.img&&param.img.color)?param.img.color:[255,255,255,255];
this.translate=param.translate||[0,0,0];
this.visible_p=isBoolean(param.visible_p)?param.visible_p:true;
this.enter_func=isFunction(param.enter_func)?param.enter_func:function(){};
this.need_border=isBoolean(param.need_border)?param.need_border:false;
if(this.need_border){
this.bg_out=new gbox({width:this.width,height:this.height,color:COL_BTN_BORDER});
this.bg_in=new gbox({width:this.width-4,height:this.height-4,color:COL_BTN});
this.components.push(this.bg_out,this.bg_in);}
this.img=new gimage({
width:this.img_w,height:this.img_h,src:this.img_src||"",
color:this.img_color
});
this.components.push(this.img);};
ImageButton.prototype.setImage=function(src){
if(isString(src))
this.img.src=src;};
var PreviewBtnCont=new container({});
PreviewBtnCont.init=function(param){
if(this.components.length>0)return;
param=param||{};
this.width=isNumber(param.width)?param.width:0;
this.height=isNumber(param.height)?param.height:0;
this.translate=param.translate||[0,0,0];
this.return_cb=param.return_cb||function(){};
this.launch_appli_cb=param.launch_appli_cb||function(){};
this.save_cb=param.save_cb||function(){};
this.appli_id="";
this.index=0;
var btn_h=Math.floor(this.height*0.7);
var return_btn_w=300;
var return_btn_x=0;
this.return_btn=new Button();
this.return_btn.create({
width:300,height:btn_h,translate:[return_btn_x,0,0],
label:MSG("LT_PM_RETURN"),enter_func:this.return_cb
});
var appli_icon_w=160;
var appli_icon_h=Math.floor(appli_icon_w*0.7);
var appli_icon_x=(this.width-appli_icon_w)/2;
this.appli_icon=new ImageButton();
this.appli_icon.create({
width:appli_icon_w,height:appli_icon_h,translate:[appli_icon_x,0,0],
visible_p:false,enter_func:this.launch_appli_cb
});
var save_btn_w=200;
var save_btn_x=((appli_icon_x-appli_icon_w/2)+(return_btn_x+return_btn_w/2))/2;
this.save_btn=new ImageButton();
this.save_btn.create({
width:save_btn_w,height:btn_h,translate:[save_btn_x,0,0],
visible_p:false,need_border:true,enter_func:this.save_cb,
img:{
width:73,height:70,src:path+"img/save.png",color:COL_TEXT_ONBASE
}
});
this.focus_trgs=[this.return_btn,this.save_btn,this.appli_icon];
this.components=[this.return_btn,this.save_btn,this.appli_icon];};
PreviewBtnCont.enter_focus=function(){
set_cursor(this,this.focus_trgs[this.index]);};
PreviewBtnCont.leave_focus=function(){
set_cursor(this,null);};
PreviewBtnCont.reset=function(){
this.index=0;
this.save_btn.setShow(false);
this.appli_icon.setShow(false);};
PreviewBtnCont.setAppliID=function(appli_id){
this.appli_id=isString(appli_id)?appli_id:"";};
PreviewBtnCont.setSaveEnable=function(bool){
if(!isBoolean(bool)||this.save_btn.isShow()==bool)
return;
this.save_btn.setShow(bool);};
PreviewBtnCont.setLaunchEnable=function(bool){
if(!isBoolean(bool)||this.appli_icon.isShow()==bool)
return;
var icon_src="";
if(bool){if(this.appli_id)
icon_src=APPLI_PATH+this.appli_id+"/icon.png";}else {}
this.appli_icon.setImage(icon_src);
this.appli_icon.setShow(bool);};
PreviewBtnCont.getFocusInfo=function (col_index){var info={pos:[],size:[]};
if(this.cursor){
if(isFunction(this.cursor.getFocusInfo)){
var cursor_info=this.cursor.getFocusInfo();
for(var i=0;i<this.translate.length;i++)
info.pos[i]=this.translate[i]+cursor_info.pos[i];
info.size=cursor_info.size;}
}
return info;};
PreviewBtnCont.key_hook=function(up_down,key){
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
var ret=false;
switch(key){
case TXK_LEFT:
if(0<this.index){
var next_index=this.index;
for(var i=next_index-1;0<=i;i--){
if(this.focus_trgs[i].isShow()){
next_index=i;
break;}
}
if(this.index==next_index)
return ret;
this.index=next_index;
set_cursor(this,this.focus_trgs[this.index]);
ret=true;}
break;
case TXK_RIGHT:
if(this.index<this.focus_trgs.length-1){
var next_index=this.index;
for(var i=next_index+1;i<this.focus_trgs.length;i++){
if(this.focus_trgs[i].isShow()){
next_index=i;
break;}
}
if(this.index==next_index)
return ret;
this.index=next_index;
set_cursor(this,this.focus_trgs[this.index]);
ret=true;}
break;}
return ret;};
var PreviewCont=new container({visible_p:false});
PreviewCont.init=function(param){
if(this.components.length>0)return;
var self=this;
param=param||{};
this._msg_info=null;
this.width=isNumber(param.width)?param.width:0;
this.height=isNumber(param.height)?param.height:0;
this.inner_w=Math.floor(this.width*0.9);
this.inner_h=Math.floor(this.height*0.9);
this.return_cb=param.return_cb||function(){};
this.launch_appli_cb=param.launch_appli_cb||function(){};
this.padding=16;
var dm_return_btn_cont_cb=function(){
set_cursor(self,self.btn_cont);};
this.device_manager=DeviceManager;
this.device_manager.create({
return_btn_cont_cb:dm_return_btn_cont_cb
});
this.shade=new gbox({
width:MAX_WIDTH,height:MAX_HEIGHT,color:COLOR_MASK
}),
this.frame=new actor({
base_col:[COL_POP_BORDER,COL_POP_BORDER],
base_col_width:2,
bg_image:[
this.bg_c=new gbox({width:this.width-28,height:this.height-28,color:COL_POP_A})
]
});
var btn_cont_h=120;
var btn_cont_y=-(this.inner_h-btn_cont_h)/2;
this.btn_cont=PreviewBtnCont;
this.btn_cont.init({
width:this.inner_w,height:btn_cont_h,translate:[0,btn_cont_y,0],
return_cb:this.return_cb,
launch_appli_cb:function(){
self.launch_appli_cb(self._msg_info);},
save_cb:function(){
self.doSave();}
});
this.preview=new container({components:[]});
this.preview.width=this.inner_w;
this.preview.height=this.inner_h-btn_cont_h-20;
this.preview.translate=[0,(this.inner_h-this.preview.height)/2,0];
this.components=[this.shade,this.frame,this.preview,this.btn_cont,
this.device_manager];};
PreviewCont.enter_focus=function(){
set_cursor(this,this.btn_cont);
this.moveFocus();};
PreviewCont.leave_focus=function(){
set_cursor(this,null);};
PreviewCont.getPreviewSize=function(){
return {w:this.preview.width,h:this.preview.height};};
PreviewCont.setPreview=function(next_preview){
var old_preview=this.preview.preview_obj;
if(old_preview){
_do_preview(old_preview,"activate",[false]);}
var self=this;
this.preview.preview_obj=null;
this.preview.components=[];
if(!next_preview)
return;
var set_focus_moveto_func=function(pos,size){
if(!pos||!size)return;
var to_pos=[];
for(var i=0;i<pos.length;i++){
to_pos[i]=pos[i]+self.preview.translate[i]+self.translate[i];}
focus_moveto(to_pos,size);};
_do_preview(next_preview,"setFocusMovetoFunc",[set_focus_moveto_func]);
var set_save_enable_cb=function(bool){
self.btn_cont.setSaveEnable(bool);};
_do_preview(next_preview,"setSaveEnableCB",[set_save_enable_cb]);
var set_launch_enable_cb=function(bool){
self.btn_cont.setLaunchEnable(bool);};
_do_preview(next_preview,"setLaunchEnableCB",[set_launch_enable_cb]);
_do_preview(next_preview,"activate",[true]);
this.preview.preview_obj=next_preview;
this.preview.components=[next_preview];};
PreviewCont.setShow=function(bool,msg_info){
if(!isBoolean(bool))return;
if(this.visible_p==bool)return;
var preview_obj=null;
if(bool){if(msg_info&&msg_info.preview){
this._msg_info=msg_info;
preview_obj=msg_info.preview;
this.btn_cont.setAppliID(msg_info.launchAppli_id);}
}else {this.msg_info=null;
this.btn_cont.reset();}
this.setPreview(preview_obj);
this.visible_p=bool;
force_redraw();};
PreviewCont.doSave=function(){
var preview_obj=this.preview.preview_obj;
var content_url=_do_preview(preview_obj,"getContentUrl");
if(isString(content_url)&&content_url.length>0){
var appli_id=this._msg_info.launchAppli_id||"";
_do_preview(preview_obj,"stopVideo");this.device_manager.show({
stream:content_url,appli_id:appli_id
});
set_cursor(this,this.device_manager);}
};
PreviewCont.moveFocus=function(){
if(!this.cursor)return;
if(this.cursor!=this.btn_cont)return;
var cur_focus_info=this.cursor.getFocusInfo(this.col_index);
var pos=[];
for(var i=0;i<this.translate.length;i++)
pos[i]=this.translate[i]+cur_focus_info.pos[i];
focus_moveto(pos,cur_focus_info.size);};
PreviewCont.key_hook=function(up_down,key){
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
this.moveFocus();
return true;}
switch(key){
case TXK_UP:
if(this.cursor==this.btn_cont){
if(this.preview.preview_obj&&isFunction(this.preview.preview_obj.enter_focus)){
set_cursor(this,this.preview.preview_obj);}
}
break;
case TXK_DOWN:
if(this.cursor==this.preview.preview_obj){
set_cursor(this,this.btn_cont);
this.moveFocus();}
break;
case TXK_LEFT:
case TXK_RIGHT:
return true;
case TXK_RETURN:
this.return_cb();
return true;}
return true;};
var Confirm=new container({});
Confirm.TYPE_OK=0;
Confirm.TYPE_YES_NO=1;
Confirm._type_list=[Confirm.TYPE_OK,Confirm.TYPE_YES_NO];
Confirm.create=function(){
if(this.components.length>0)
return;
var self=this;
this.mask=new gbox({
color:COLOR_MASK,width:MAX_WIDTH,height:MAX_HEIGHT,visible_p:false
});
this.type=Confirm.TYPE_YES_NO;
this.panel=new Confirmpanel(
Confirmpanel.prototype.OPTION_TYPE_YES_NO,
[function(){self.yesFunc();},function(){self.noFunc();}],
focus_moveto
);
this.components=[this.mask,this.panel];};
Confirm.free=FREE_FUNC;
Confirm.show=function(param){
param=param||{};
var self=this;
if(isNumber(param.type)&&this.type!=param.type
&&Confirm._type_list.indexOf(param.type)!=-1){
this.type=param.type;
this.panel.free();
this.panel=null;
if(this.type==Confirm.TYPE_OK){
this.panel=new Confirmpanel(
Confirmpanel.prototype.OPTION_TYPE_OK,[function(){self.okFunc();}],focus_moveto
);}else if(this.type==Confirm.TYPE_YES_NO){
this.panel=new Confirmpanel(
Confirmpanel.prototype.OPTION_TYPE_YES_NO,
[function(){self.yesFunc();},function(){self.noFunc();}],
focus_moveto
);};
this.components=[this.mask,this.panel];}
this.panel.setMessageText(param.text||"");
this.panel.setSize(param.width||1080,param.height||420);
if(this.type==Confirm.TYPE_OK){
this.panel.setButtonLabel(param.ok_label||MSG("LT_OK"));
this.ok_cb=isFunction(param.ok_cb)?param.ok_cb:function(){};}else if(this.type==Confirm.TYPE_YES_NO){
this.panel.setButtonLabel(param.yes_label||MSG("LT_YES"),param.no_label||MSG("LT_NO"));
this.yes_cb=isFunction(param.yes_cb)?param.yes_cb:function(){};
this.no_cb=isFunction(param.no_cb)?param.no_cb:function(){};}
this.mask.visible_p=true;
this.panel.setShow(true);};
Confirm.hide=function(){
this.mask.visible_p=false;
this.panel.setShow(false);};
Confirm.enter_focus=function(){
set_cursor(this,this.panel);
this.panel.onFocus(true);
this.panel.setShow(true);};
Confirm.leave_focus=function(){
this.panel.setShow(false);
this.panel.onFocus(false);
set_cursor(this,null);};
Confirm.okFunc=function(){
this.hide();
this.ok_cb();};
Confirm.yesFunc=function(){
this.hide();
this.yes_cb();};
Confirm.noFunc=function(){
this.hide();
this.no_cb();};
Confirm.key_hook=function(up_down,key){
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_UP:
case TXK_DOWN:
case TXK_LEFT:
case TXK_RIGHT:
case TXK_RETURN:
return true;}
return false;};
var Loading=new container({visible_p:false});
Loading.create=function(){
var self=this;
this.cancel_cb=function(){};
this.components=[
this.shade=new gbox({
width:MAX_WIDTH,height:MAX_HEIGHT,color:COLOR_MASK
}),
this.shape_l=new gimage({
width:49,height:100,src:IMG_PATH+"shape_l.png",draw_type:DIRECT
}),
this.shape_c=new gimage({
width:1,height:100,src:IMG_PATH+"shape_c.png",draw_type:DIRECT
}),
this.shape_r=new gimage({
width:49,height:100,src:IMG_PATH+"shape_r.png",draw_type:DIRECT
}),
this.circle=new gimage({
width:73,height:70,src:IMG_PATH+"loading_circle_small.png",
color:[129,142,149,255],rotation:[0,0,0,1]
}),
this.load=new gtext({
width:500,translate:[35,0,0],font_size:40,align:CENTER,
})
];};
Loading.free=FREE_FUNC;
Loading.enter_focus=function(){};Loading.leave_focus=function(){};Loading.setPosition=function(){
var text_width=get_text_width(this.load,this.load.text);
var space=(this.load.text!="")?80:20;
var circle_x_bias=(this.load.text!="")?20:0;
this.shape_c.width=text_width+space;
this.shape_l.translate[0]=-this.shape_c.width/2-this.shape_l.width/2;
this.shape_r.translate[0]=this.shape_c.width/2+this.shape_r.width/2;
this.circle.translate[0]=this.load.translate[0]-text_width/2-this.circle.width/2-circle_x_bias;};
Loading.setShow=function(bool,label,cancel_cb){
var obj=this;
if(bool==true){
focus.setShow(false);
delete_timer(obj);
setf_text(this.load,isString(label)?label:"");
this.cancel_cb=isFunction(cancel_cb)?cancel_cb:function(){};
this.setPosition();
obj.visible_p=true;
append_timer(obj,100,function(obj,count){
obj.circle.rotation[0]=-(30*count)%360;
force_redraw();});}else{
delete_timer(obj);
obj.visible_p=false;
obj.circle.rotation=[0,0,0,1];
focus.setShow(true);}
};
Loading.isShow=function(){
return this.visible_p;};
Loading.setCancelCB=function(cb){
if(isFunction(cb))
this.cancel_cb=cb;};
Loading.key_hook=function(up_down,key){
switch(key){
case TXK_RETURN:
this.cancel_cb();
return true;}
return true;};
function setParent(child,parent,enable_focus){
child.parent=parent;
if(enable_focus){
child.focus={pos:[0,0,0],size:[child.width,child.height]};
child.focus.pos=child.translate.slice(0);var p=parent;
while(p){
child.focus.pos[0]+=p.translate[0];
child.focus.pos[1]+=p.translate[1];
child.focus.pos[2]+=p.translate[2];
p=p.parent;}
}
parent.components.push(child);}
function initMessageScreen(){
var base=new container({translate:[0,0,0],visible_p:false});
var self=base;
friend_list_mgr.init();
base.SETUP_CONFIRM_MODE_DEFAULT=0;
base.SETUP_CONFIRM_MODE_NO_ACCOUNT=1;
base.SETUP_CONFIRM_MODE_TOKEN_EXPIRED=2;
base.SETUP_CONFIRM_MODE_NO_USER=3;
base.SETUP_CONFIRM_MODE_LIST=[
base.SETUP_CONFIRM_MODE_DEFAULT,base.SETUP_CONFIRM_MODE_NO_ACCOUNT,
base.SETUP_CONFIRM_MODE_TOKEN_EXPIRED,base.SETUP_CONFIRM_MODE_NO_USER
];
base.index=1;
base.focus_trgs=[];
base.is_token_expired=false;
base._set_readed_trg_list=[];
base._set_readed_req_id=null;
base.bg=new gbox({width:MAX_WIDTH,height:MAX_HEIGHT,color:COL_BASE});
setParent(base.bg,base);
var name_enter_cb=function(){
launchMHCApl();};
base.title_area=TitleArea;
base.title_area.init({width:MAX_WIDTH,height:150,enter_cb:name_enter_cb});
base.title_area.translate=[0,(MAX_HEIGHT-base.title_area.height)/2,0];
base.title_area.setTitle(MSG("LT_HOME_MESSAGES"));
base.focus_trgs.push(base.title_area);
base.label_header=LabelHeader;
base.label_header.init({width:MAX_WIDTH,height:46});
base.label_header.translate=
[0,base.title_area.translate[1]-(base.title_area.height+base.label_header.height)/2,0];
var select_msg_cb=function(msg_info){
if(!msg_info)return;
switch(msg_info.action){
case "select":
self.selectMsg(msg_info);
break;
case "launch_disclaimer":
self.launchDisclaimer();
break;
case "delete":
self.deleteMsg(msg_info);
break;
default:
break;};};
base.msg_cont=MsgCont;
base.msg_cont.init({
width:MAX_WIDTH,
height:MAX_HEIGHT-(base.title_area.height+base.label_header.height),
row_h:118,line_h:2,
select_msg_cb:select_msg_cb
});
base.msg_cont.translate=[0,-(MAX_HEIGHT-base.msg_cont.height)/2,0];
base.focus_trgs.push(base.msg_cont);
var return_preview_cb=function(){
set_cursor(self,self.msg_cont);
self.preview_cont.setShow(false);};
var preview_launch_appli_cb=function(msg_info){
self.launchAppli(msg_info);};
base.preview_cont=PreviewCont;
base.preview_cont.init({
width:Math.floor(MAX_WIDTH*0.85),height:Math.floor(MAX_HEIGHT*0.85),
return_cb:return_preview_cb,launch_appli_cb:preview_launch_appli_cb
});
base.mus=MultiUserSelection;
base.mus.create(MSG);
base.confirm=Confirm;
base.confirm.create();
base.loading=Loading;
base.loading.create();
setParent(base.msg_cont,base);
setParent(base.label_header,base);
setParent(base.title_area,base);
setParent(base.mus,base);
setParent(base.preview_cont,base);
setParent(base.confirm,base);
setParent(base.loading,base);
base.enter_focus=function(){
if(this.loading.isShow())
set_cursor(this,this.loading);
else
set_cursor(this,this.focus_trgs[this.index]);};
base.leave_focus=function(){
set_cursor(this,null);};
base.setMsgCont=function(data_list){
this.msg_cont.setList(data_list);};
base.setDisclaimerMsgCont=function(){
var label=MSG("LT_CG_DISCLAIMER_MSG_1").replace("%s",MSG("LT_MHC2_TERMS_AND_CONDITIONS_1"))+"\n"+
MSG("LT_CG_DISCLAIMER_MSG_2");
switch(system.locale.language){
case "ja-JP":
label=label.replace(/my Home Cloud/g,"マイホームクラウド");
break;
case "fr-CA":
label=label.replace(/my Home Cloud/g,"Mon nuage personnel");
break;}
this.setMsgCont([{
data:{
row_type:MsgRow.ROW_TYPE_DISCLAIMER,label:label
}
}]);};
base.selectMsg=function(msg_info){
var product_id=msg_info.launchAppli_id;
switch(product_id){
case APPLI_TABLE[APPLI_ID_VIDEO]:
case APPLI_TABLE[APPLI_ID_PHOTO]:
case APPLI_TABLE[APPLI_ID_NOTE]:
this.preview_cont.setShow(true,msg_info);
set_cursor(this,this.preview_cont);
break;}
};
base.launchAppli=function(msg_info){
var product_id=msg_info.launchAppli_id;
if(!isString(product_id)||product_id.length==0)return;
var launch_ad_id=msg_info.launch_ad_id?msg_info.launch_ad_id.toString():"";
applink.setFrom("MESSAGE");
var arg=isString(launch_ad_id)||isNumber(launch_ad_id)?launch_ad_id:null;
if(user_profile_mgr.getMultiuserSupported()&&arg!=null){
arg=arg+" -U "+user_profile_mgr.getCurrentUserID();}
var rval=apputil.launch_apl(product_id,arg,"use_gwin");
applink.clear();};
base.launchDisclaimer=function(){
apputil.launch_disclaimer();
common_out_hook();};
base.deleteMsg=function(msg_info){
var back_msg_cont_cb=function(){
self.resetCursorToTrg(self.msg_cont);};
var delete_data_cb=function(errcode){
self.loading.setShow(false);
if(errcode==200){
Log(" >> Delete success!");
base.msg_cont.deleteListMsg(msg_info.ad_id,msg_info.to_user_key);
back_msg_cont_cb();}else {
console.log("Error ...");
self.confirm.show({
type:Confirm.TYPE_OK,text:MSG("LT_CG_FAILED_TO_DELETE"),
ok_cb:function(){
back_msg_cont_cb();}
});
set_cursor(self,self.confirm);}
};
var confirm_yes_cb=function(){
self.loading.setShow(true);
set_cursor(self,self.loading);
cloudGadget.setAuthorizedToken(msg_info.user_auth_token||"");
cloudGadget.deleteData(msg_info.ad_id,TIMEOUT_S,delete_data_cb);};
var confirm_no_cb=function(){
back_msg_cont_cb();};
this.confirm.show({
type:Confirm.TYPE_YES_NO,text:MSG("LT_CG_DELETE_MESSAGE"),
yes_cb:confirm_yes_cb,no_cb:confirm_no_cb
});
set_cursor(this,this.confirm);};
base.resetCursorToTrg=function(trg_obj){
for(var i=0;i<this.focus_trgs.length;i++){
if(this.focus_trgs[i]==trg_obj){
this.index=i;
set_cursor(this,this.focus_trgs[i]);}
}
};
base.doRequestMsgList=function(){
requestMessageList(function(errcode){
switch(errcode){
case ERRCODE_TOKEN_EXPIRED:self.is_token_expired=true;
self.title_area.setShowAccountView(true);
self.resetCursorToTrg(self.title_area);
break;
case ERRCODE_ACCOUNT_REMOVED:sc.is_token_expired=false;
self.title_area.setShowAccountView(true);
self.resetCursorToTrg(self.title_area);
break;
default:
self.resetCursorToTrg(self.msg_cont);
break;}
self.loading.setShow(false);});};
base.setReadedStatusToList=function(trg_list){
if(!trg_list||!trg_list.length)return;
self.cancelSetReadedStatusToList();
self._set_readed_trg_list=trg_list;
var pnt=0;
var req_cb=function(errcode,server_time){
Log(" >> req_cb : "+errcode);
self._set_readed_req_id=null;
if(errcode==401)
return;pnt++;
request();};
var request=function(){
var trg=self._set_readed_trg_list[pnt];
if(!trg)
return;if(trg.data&&!trg.data.is_read){
cloudGadget.setAuthorizedToken(user_profile_mgr.getUserAuthTokenByMHCUserKey(trg.to_user_key));
self._set_readed_req_id=
cloudGadget.setReadStatus(trg.data.application_data_id,true,TIMEOUT_S,req_cb);}else {req_cb(200,null);}
};
request();};
base.cancelSetReadedStatusToList=function(){
self._set_readed_trg_list=[];
if(isString(self._set_readed_req_id))
cloudGadget.cancelRequest(self._set_readed_req_id);
self._set_readed_req_id=null;};
base.switchUser=function(info,login_result){
self.msg_cont.clearList();self.cancelSetReadedStatusToList();
user_profile_mgr.setCurrentUserProfileByUserID(info.id);
friend_list_mgr.updateToken();
if(login_result){set_cursor(self,self.loading);
self.loading.setShow(true);
self.doRequestMsgList();}else {self.setMsgCont([]);
self.resetCursorToTrg(self.msg_cont);}
};
base.prepareMUS=function(){
if(!user_profile_mgr.getMultiuserSupported())return;
var cur_prof=user_profile_mgr.getCurrentUserProfile();
var select_action=function(info,animation){
var show_setup_confirm_func=function(mode){
self.showSetupConfirmHook({
profile_id:info.id,mode:mode,
no_cb:function(){
animation();
self.switchUser(info,false);}
});};
if(isString(info.mhc_userkey)&&isString(info.mhc_authtoken)){if(!user_profile_mgr.checkTokenExpired(info.mhc_authtoken)){animation();
self.switchUser(info,true);}else {self.is_token_expired=true;
show_setup_confirm_func(self.SETUP_CONFIRM_MODE_TOKEN_EXPIRED);}
}else {self.is_token_expired=false;
show_setup_confirm_func(self.SETUP_CONFIRM_MODE_NO_ACCOUNT);}
};
var return_action=function(){
common_out_hook();};
this.mus.setShow({
view:true,center:false,current_user:cur_prof.mhc,
select_action:select_action,return_action:return_action
});};
base.showSetupConfirmHook=function(param){
param=param||{};
var profile_id=isNumber(param.profile_id)?param.profile_id:null;
var mode=this.SETUP_CONFIRM_MODE_DEFAULT;
if((isNumber(param.mode)&&this.SETUP_CONFIRM_MODE_LIST.indexOf(param.mode)!=-1))
mode=param.mode;
var msg_text="";
switch(mode){
case this.SETUP_CONFIRM_MODE_NO_ACCOUNT:
msg_text=[MSG("LT_CG_SELECT_USER_NO_ACCOUNT_1"),
MSG("LT_CG_SELECT_USER_NO_ACCOUNT_2")].join("\n");
break;
case this.SETUP_CONFIRM_MODE_TOKEN_EXPIRED:
msg_text=[MSG("LT_CG_ACCOUNT_EXPIRE_1"),
MSG("LT_CG_ACCOUNT_EXPIRE_2"),
MSG("LT_CG_ACCOUNT_EXPIRE_3")].join("\n");
break;
case this.SETUP_CONFIRM_MODE_NO_USER:
msg_text=[MSG("LT_CG_CREATE_USER_NEEDED_1"),
MSG("LT_CG_CREATE_USER_NEEDED_2")].join("\n");
break;
case this.SETUP_CONFIRM_MODE_DEFAULT:
default:
msg_text=[MSG("LT_CG_COULD_YOU_SETUP_ACCOUNT_1"),
MSG("LT_CG_COULD_YOU_SETUP_ACCOUNT_2")].join("\n");}
var def_yes_cb=function(){
launchMHCApl(profile_id);
common_out_hook();};
var def_no_cb=function(){
common_out_hook();};
var yes_cb=isFunction(param.yes_cb)?param.yes_cb:def_yes_cb;
var no_cb=isFunction(param.no_cb)?param.no_cb:def_no_cb;
self.confirm.show({type:Confirm.TYPE_YES_NO,text:msg_text,
yes_label:MSG("LT_YES"),yes_cb:yes_cb,no_label:MSG("LT_NO"),no_cb:no_cb
});
set_cursor(self,self.confirm);};
base.keyUp=function(){
var ret=false;
if(0<this.index){
if(isFunction(this.focus_trgs[this.index-1].isFocusEnable)
&&!this.focus_trgs[this.index-1].isFocusEnable())
return ret;this.index--;
set_cursor(this,this.focus_trgs[this.index]);
ret=true;}
return ret;};
base.keyDown=function(){
var ret=false;
if(this.index<this.focus_trgs.length-1){
this.index++;
set_cursor(this,this.focus_trgs[this.index]);
ret=true;}
return ret;};
base.key_hook=function (up_down,key){
if(up_down!=KEY_PRESS)return false;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;}
switch(key){
case TXK_UP:
return this.keyUp();
case TXK_DOWN:
return this.keyDown();}
return false;};
base.inHook=function(obj){
focus.setShow(true);
base.visible_p=true;};
base.outHook=function(){
focus.setShow(false);
base.visible_p=false;};
return base;}
function messageNotificationFunc(stg,obj,type,str){
mus_badge_mgr.notified=true;
return false;};
function requestMessageList(cb){
var req_id=0;
if(!isFunction(cb))cb=function(){};
var to_user_key=user_profile_mgr.getCurrentUserMHCUserkey();
var token=user_profile_mgr.getCurrentUserAuthToken();
var sort_func=function(a,b){
var a_date=getLastDateInCloudData(a);
var b_date=getLastDateInCloudData(b);
if(!a_date||!b_date)return 0;
else if(a_date<b_date)return 1;
else return -1;};
var req_err_func=function(errcode){
console.log("Error : "+errcode+" ...");
sc.setMsgCont([]);
cb(errcode);};
if(!to_user_key&&!token){
req_err_func(-1);
return;}
var callback=function(data,errcode){
Log(" >>   callback  errcode : "+errcode);
var data_list=[];
if(errcode!=200){
req_err_func(errcode);
return;}
data.forEach(function(v){
if(isBoolean(v.is_owner)&&!v.is_owner)
data_list.push({to_user_key:to_user_key,data:v});});
data_list.sort(sort_func);
sc.setMsgCont(data_list.slice());
sc.setReadedStatusToList(data_list.slice());mus_badge_mgr.changeNewBadgeView(user_profile_mgr.getCurrentUserID(),false);
cb();};
cloudGadget.setAuthorizedToken(token);
req_id=cloudGadget.getDataList(ADT_ID_MESSAGE,false,TIMEOUT_S,callback);};
function getDataCountMulti(param){
param=param||{};
var cb=isFunction(param.cb)?param.cb:function(){};
var token_list=param.token_list&&isNumber(param.token_list.length)
?param.token_list:[];
var adt_id_list=param.adt_id_list&&isNumber(param.adt_id_list.length)
?param.adt_id_list:[];
var count_type=isNumber(param.count_type)?param.count_type:0;
var direction=isNumber(param.direction)?param.direction:0;
var req_id=cloudGadget.getDataCountMulti(token_list,adt_id_list,count_type,direction,TIMEOUT_S,cb);
if(isNumber(req_id)&&req_id<0){
console.log(" >> request error..... : "+req_id);
cb(null,-1);}
};
var sc=initMessageScreen();
function launchMHCApl(profile_id){
var launch_prod_id=PROD_ID_MHCID_LOGIN;if(sc.is_token_expired){
launch_prod_id=PROD_ID_MHCID_ERROR;}
var args=null;
if(isNumber(profile_id))
args="-T -s -R -l vmarket:uprofid="+profile_id;
Log(" >> args : "+args);
var rval=apputil.launch_apl(launch_prod_id,args,"use_gwin");};
var launch_check=function(cb){
Log(" >> ### launch check ###");
var check_cb=function(need_update){
Log(" >> ## need update : "+need_update);
set_cursor(sc,null);
switch(need_update){
case true:apputil.launch_nwdl();
cb(false,false);
break;
case false:if(isDisclaimerNeeded()){if(is_disclaimer_updated){cb(false,false);}else {sc.launchDisclaimer();}
}else {cb(true,true);}
break;
case null:
default:cb(false,true);}
};
apputil.latestCheck(check_cb);};
var in_hook=function(obj){
var bplayer=new BroadcastPlayer();
bplayer.set_browser_mode(BR_SRC_VS);
bplayer.disconnect();
addUserAgentHook("messageNotification",system.user_agent.NOTIFICATION,messageNotificationFunc);
var applink_arg=applink.get();
mus_badge_mgr.init();
sc.inHook(obj);
sc.loading.setShow(true,null,function(){common_out_hook();});
set_cursor(obj,sc);
obj.translate=[0,1080,1];
obj.moveTo=MoveTo;
if(isDisclaimerNeeded()&&getMarketInfo()!=false){
is_disclaimer_updated=true;}
var prepare_online_mode=function(){
sc.doRequestMsgList();};
var prepare_offline_mode=function(){
if(is_disclaimer_updated){
sc.setDisclaimerMsgCont();}else {
sc.setMsgCont([]);}
set_cursor(sc,sc.focus_trgs[sc.index]);
sc.loading.setShow(false);};
var check_cb=function(result,necessary_prepare_profile_area){
complete_on_stage(obj);
LogReport.report(LogReport.OPERATE_HS,"hs.messages",{action:"start",pos:"-1"});
if(is_china){prepare_offline_mode();
return;}
if(necessary_prepare_profile_area&&!user_profile_mgr.getMultiuserSupported()){
if(!user_profile_mgr.getCurrentUserMHCUserkey())
sc.title_area.setShowAccountView(true);}
if(result){mus_badge_mgr.doRequestNewBadge();
if(applink_arg.launch_from=="infobar"&&(isNumber(applink_arg.usrprof_id)||isString(applink_arg.usrprof_id))
&&applink_arg.usrprof_id!=user_profile_mgr.getCurrentUserID()){
user_profile_mgr.setCurrentUserProfileByUserID(applink_arg.usrprof_id);
friend_list_mgr.updateToken();}
Log(" >> ## user_profile_mgr.getMultiuserSupported() : "+user_profile_mgr.getMultiuserSupported());
if(user_profile_mgr.getMultiuserSupported()){Log(" >> multiuser phase");
Log(" >>   user_profile_mgr.getCurrentUserMHCUserkey() : "+user_profile_mgr.getCurrentUserMHCUserkey());
sc.prepareMUS();
if(user_profile_mgr.getUserProfileListNum()<=0){
prepare_offline_mode();
}else if(!user_profile_mgr.isExistCurrentUserProfile()){
prepare_offline_mode();
}else if(!user_profile_mgr.getCurrentUserMHCUserkey()){
sc.is_token_expired=false;
sc.loading.setShow(false);
sc.showSetupConfirmHook({
profile_id:user_profile_mgr.getCurrentUserID(),
mode:sc.SETUP_CONFIRM_MODE_NO_ACCOUNT,
no_cb:function(){prepare_offline_mode();}
});
}else if(user_profile_mgr.checkTokenExpired()){
sc.is_token_expired=true;
sc.loading.setShow(false);
sc.showSetupConfirmHook({
profile_id:user_profile_mgr.getCurrentUserID(),
mode:sc.SETUP_CONFIRM_MODE_TOKEN_EXPIRED,
no_cb:function(){prepare_offline_mode();}
});
}else {
prepare_online_mode();}
}else {if(!user_profile_mgr.getCurrentUserMHCUserkey()){prepare_offline_mode();}else {prepare_online_mode();}
}
}else {prepare_offline_mode();}
};
var timer_obj={};
append_timer(timer_obj,120,function(tobj,count){
delete_timer(tobj);
obj.moveTo({x:0,y:0,z:1,rate:0.3,count:12,end_func:function(){
launch_check(check_cb);}});});};
var out_hook=function(obj){
var bplayer=new BroadcastPlayer();
bplayer.connect(VideoDev,AudioDev);
bplayer.set_browser_mode(BR_SRC_DEFAULT);
delUserAgentHook("messageNotification");
mus_badge_mgr.setHSMessageBadge();
sc.outHook();
complete_off_stage(obj);
discard_stage("message");};
var common_out_hook=function(){
discard_stage("message");
on_stage("HOME");};
var sobj=stage({
symbol:"message",
in:[
{from:["default"],
hook:in_hook
}
],
out:[
{to:["default"],hook:out_hook}
],
components:[
sc,
focus,
],
key_hook:function(up_down,key){
switch(key){
case TXK_HOME:
case TXK_EXIT:
return false;}
if(up_down!=KEY_PRESS)return false;
if(this.cursor&&this.cursor.key_hook&&this.cursor.key_hook(up_down,key)){
return true;};
switch(key){
case TXK_RETURN:
common_out_hook();
return true;}
return false;},
});

