var product_id="0387878700140052";
var app_name="weblink";
var path=APPLI_PATH+product_id+"/gadget/";
var BROWSER_PRODUCT_ID="0077777700140002";
var brw_js_path=APPLI_PATH+BROWSER_PRODUCT_ID+"/gadget/";
var CAPTURE_UPDATE_WAIT=0;
var CAPTURE_UPDATETIME_CHECK_WAIT=1;
var BROWSER_TOU_VERSION="1.0";
var COUNTRY_CODE=system.locale.country.substr(0,2);
var TOU_PATH=getHostName()+"/browser_info/term_of_use/";
var browser_get_version=function(){
var MAJOR_VERSION="1";
var file_name=TOU_PATH+MAJOR_VERSION+".json";
var result=null;
var request_handler=0;
try{
if(request_handler)cancel_http_request(request_handler);
request_handler=http_request({
url:file_name,
sync:true,
onload:function(status,header,body){
if(status==200){
var dt=eval("("+body+")");
if(dt!=null){
result=("version" in dt)?dt.version:null;}
}
}
});
request_handler=0;}catch(e){
console.log("Error get file");}
return result;}
var error_func=function(){
gadget.bookmark_img.src="";
gadget.bookmark_img_bk.src="";
gadget.anim_flag=false;
gadget.anim_cnt=0;
gadget.bookmark_img.hash=null;
gadget.bookmark_img.load_id=-1;
setf_text(gadget.bookmark_title,"");
gadget.default_app_logo.visible_p=true;
gadget.default_app_logo2.visible_p=true;
setf_text(gadget.bookmark_title,gadget.getTitle(BROWSER_PRODUCT_ID,"title"));}
var gadget=new Gadget();
gadget.init=function(){
this.anim_cnt=0;
this.capt_cnt=0;
this.anim_30_min=30*60*10;this.anim_1_min=60*10;this.capt_cnt_max=this.anim_1_min;
this.anim_flag=false;
this.capt_status=CAPTURE_UPDATETIME_CHECK_WAIT;
this.bookmark_img_bk=new gimage({translate:[0,0,-0.4],width:412,height:232,
draw_type:DIRECT,onload:function(){},});
this.bookmark_img=new gimage({translate:[0,0,-0.4],width:412,height:232,
draw_type:DIRECT,onload:function(){},});
this.bookmark_title_bk=new gbox({width:this.$width,height:40,color:[0,0,0,160],
translate:[0,-232*0.5+20,-0.3],
round_enable:false,round_width:8,round_height:8,});
this.bookmark_title=new gtext({translate:[0,-94,-0.2],width:400,
font_size:32,align:CENTER,omitter:"...",color:[255,255,255,255],});
this.default_app_logo=new gimage({width:160,height:112,translate:[-20,26,-0.1],visible_p:false,
src:APPLI_PATH+BROWSER_PRODUCT_ID+"/icon.png"});
this.default_app_logo2=new gimage({width:160,height:112,translate:[0,6,-0.2],visible_p:false,
src:APPLI_PATH+BROWSER_PRODUCT_ID+"/icon.png",
color:[255,255,255,100],});
this.components.push(this.bookmark_img_bk,this.bookmark_img,
this.default_app_logo2,this.default_app_logo,this.bookmark_title_bk,
this.bookmark_title);
this._activate(true);};
gadget.getTitle=function (product_id){
var title="";
http_request({url:APPLI_PATH+product_id+"/Info.plist",
sync:true,method:"GET",
onload:function(status,header,body){
try{
if(status==200){
try{
title=body.match(new RegExp("^title."+system.locale.language.substr(0,5)+"=(.*)$","m"))[1];}catch(ex_no_key){
try{
title=body.match(new RegExp("^title."+system.locale.language.substr(0,2)+"=(.*)$","m"))[1];}catch(ex_never_key){
try{
title=body.match(new RegExp("^title=(.*)$","m"))[1];}catch(ex_no_title){
console.log("[ERROR] No title in \"Info.plist\". Please check ID="+product_id);}
}
}
}else{
console.log("Cannot find \"Info.plist\" of ID");}
}catch(e){
console.log(e.message);}
}
});
return title;};
gadget.voicePlay=function(){
if(gadget.default_app_logo.visible_p){
VoicePlay(LANG("LT_HOME_NETWORK_APPLICATION")+". "+LANG("LT_VG_NOT_SUPPORTED"));}else{
VoicePlay(this._getTitle()+". "+gadget.bookmark_title.text);}
};
gadget.activate=function(bool){
var me=this;
append_timer(me,200,function (obj){
delete_timer(obj);
me._activate(bool);});}
gadget.get_nvram_data=function(){
try{
var tmp=apps_nvram_file.read({"filename":"Bookmark",
async:false,finished:function(){},product_id:"home"});
if(tmp){
tmp=sysutil.tconv.binary_to_string(tmp);
tmp=eval(tmp).bookmarkpanel;}else{
console.log(" nvram_file Bookmark No Data error");
error_func();}
}catch(e){
console.log(" nvram_file Bookmark error :Error = "+e.message);
error_func();}
var ret=false;
for(var i=0,max=tmp.length;i<max;i++){
if(tmp[i].id==this.bookmark_id){
this.times=tmp[i].times+"";
this.update_time=tmp[i].update_time;
this.title=tmp[i].title;
this.url=tmp[i].url;
ret=true;
break;}
}
return ret;}
gadget._activate=function(bool){
if(this._uniq_id.substring(0,16)==product_id){
this.bookmark_id=this._uniq_id.substring(16);
if(this.reload_check()!=true)return;
this.default_app_logo.visible_p=false;
this.default_app_logo2.visible_p=false;
this.anim_flag=false;
this.anim_cnt=0;
var ret=this.get_nvram_data();
var my_img=this.bookmark_img;
var finished_hook=function(stg,obj,ev,id,result,bin){
if(ev!=obj.READ_EV||result!=obj.NO_ERROR)return;
if(my_img.load_id!=id)return;
var hash=sysutil.hex.encode(sysutil.hash.generate(sysutil.hash.SHA1,bin));
if(my_img.hash!=hash){
my_img.src=bin;
my_img.hash=hash;}
bin.length=0;};
try{
my_img.load_id=apps_nvram_file.read({"filename":this.times,
async:true,finished:finished_hook,product_id:"home"});
setf_text(this.bookmark_title,this.title);
this.old_update_time=this.update_time;}catch(e){
ret=false;}
if(ret==false){
error_func();}
}else{
console.log(" product_id error");
error_func();}
}
gadget.reload_check=function(){
var ret=false;
var hit_flg=false;
if(typeof BROWSER.get_bookmark_data=="function"){
var data=BROWSER.get_bookmark_data().bookmarkpanel;
for(var i=0,max=data.length;i<max;i++){
if(data[i].id==this.bookmark_id){
if(data[i].update_time!=this.update_time){
ret=true;}else if(this.bookmark_img.src==""){
ret=true;}
hit_flg=true;
break;}
}
if(hit_flg==false){
if((this.bookmark_img.src!="")||
(this.default_app_logo.visible_p!=true)){
ret=true;}
}
}else{
ret=true;}
return ret;}
gadget.launchApl=function(locked_panel,report){
var transit=null;
BROWSER_TOU_VERSION=browser_get_version();
if(this.default_app_logo.visible_p==false){
var pre_check="yes";
if(system.mdl_cfg.with_browser_with_tv){
var tou_disp=false;
if(apps_nvram.read("TOU_DISP","home")!=null)
tou_disp=apps_nvram.read("TOU_DISP","home");
var tou_version="0.0";
if(apps_nvram.read("TOU_VER","home")!=null)
tou_version=apps_nvram.read("TOU_VER","home");
if((tou_disp)&&(BROWSER_TOU_VERSION<=tou_version)&&(BROWSER_TOU_VERSION!=null)){
pre_check="no";
if(SHOW_TVINFO){
var tv_x=(11+576/2)-1920/2;
var tv_y=1080/2-(9+324/2)+14;
var tv_height=324-27;
var tv_width=Math.floor(tv_height*16/9);}else {
var tv_x=(11+576/2)-1920/2;
var tv_y=1080/2-(9+324/2);
var tv_width=576;
var tv_height=324;}
if(system.mdl_cfg.with_bp_transit_effect){
transit={
uniq_id:this._uniq_id,
to:{x:tv_x,y:tv_y,width:tv_width,height:tv_height},
from_bookmark:{x:0,y:0,width:412,height:232},
to_bookmark:{x:280,y:-30,width:1280,height:945},
mode:BP_TRANSIT_TO_NAGARA,
bookmark_image:this.times+"_platinum",
};}
else{
transit=null;}
}
}
weblink.set({"launch_from":weblink.CODE.BOOKMARK,"url":this.url,"extra_data":pre_check});}
return apputil.launch_apl("0077777700140002",null,locked_panel,report,null,"platinum_main",transit);};


gadget.animation=function(count){
if(this.default_app_logo.visible_p==true)return;
this.capt_cnt++;
if(this.capt_cnt==this.capt_cnt_max){
this.capt_cnt=0;
if(this.capt_status==CAPTURE_UPDATE_WAIT){
var ret=this.get_nvram_data();
if(ret==false){
this.capt_cnt_max=this.anim_30_min;
this.capt_status=CAPTURE_UPDATETIME_CHECK_WAIT;
return;}
if(this.old_update_time!=this.update_time){
this.old_update_time=this.update_time;
this.anim_flag=true;
this.anim_cnt=0;
this.bookmark_img.color[3]=255;
var my_img=this.bookmark_img_bk;
var finished_hook=function(stg,obj,ev,id,result,bin){
if(ev!=obj.READ_EV||result!=obj.NO_ERROR)return;
if(my_img.load_id!=id)return;
var hash=sysutil.hex.encode(sysutil.hash.generate(sysutil.hash.SHA1,bin));
if(my_img.hash!=hash){
my_img.src=bin;
my_img.hash=hash;}
bin.length=0;};
try{
my_img.load_id=apps_nvram_file.read({"filename":this.times,
async:true,finished:finished_hook,product_id:"home"});}catch(e){
error_func();}
}
this.capt_cnt_max=this.anim_30_min;
this.capt_status=CAPTURE_UPDATETIME_CHECK_WAIT;}else{
this.capt_cnt_max=this.anim_1_min;
this.capt_status=CAPTURE_UPDATE_WAIT;
this.old_update_time=this.update_time;
BROWSER.get_bookmark_capture(this.bookmark_id,this.url);
}
}
if(this.anim_flag==true){
this.anim_cnt++;
if(this.anim_cnt<1){
this.bookmark_img.color[3]=this.bookmark_img.color[3]-8;}else if(this.anim_cnt==32){
this.bookmark_img.src=this.bookmark_img_bk.src;
this.bookmark_img.hash=this.bookmark_img_bk.hash;
this.bookmark_img.load_id=-1;
this.bookmark_img.color[3]=255;
if(this.bookmark_title.text!=this.title){
setf_text(this.bookmark_title,this.title);}
}else if(this.anim_cnt==33){
this.bookmark_img_bk.hash=null;
this.bookmark_img_bk.load_id=-1;
this.anim_flag=false;
this.anim_cnt=0;}
}

}
gadget.freeResource=function(bool){
if(bool){
this.bookmark_img.src="";
this.bookmark_img.hash=null;
this.bookmark_img.load_id=-1;
setf_text(this.bookmark_title,"");
this.default_app_logo.src="";
this.default_app_logo2.src="";}else{
this.activate(true);
this.default_app_logo.src=APPLI_PATH+BROWSER_PRODUCT_ID+"/icon.png";
this.default_app_logo2.src=APPLI_PATH+BROWSER_PRODUCT_ID+"/icon.png";}
};
gadget._getWeblinkTable=function (){
var table=null;
try{
table=apps_nvram_file.read({"filename":"Weblink_table",async:false,
finished:function(){},product_id:"home"});
if(table){
table=eval(sysutil.tconv.binary_to_string(table));}
}catch(e){
console.log("cannot get WeblinkTable data: Error = "+e.message);}
return table;}
gadget._getBookmarkFile=function (){
var bookmark=null;
try{
bookmark=apps_nvram_file.read({"filename":"Bookmark",async:false,
finished:function(){},product_id:"home"});
if(bookmark){
bookmark=eval(sysutil.tconv.binary_to_string(bookmark));}
}catch(e){
console.log("cannot get Bookmark data: Error = "+e.message);}
return bookmark;}
gadget._getTitleData=function (id){
var bookmark=this._getBookmarkFile();
if(bookmark){
var max=bookmark.bookmarkpanel.length;
for(var i=0;i<max;i++){
if(bookmark.bookmarkpanel[i].id==id.toString()){
return bookmark.bookmarkpanel[i].title;}
}
}
return null;}
gadget._getUrlData=function (id){
var table=this._getWeblinkTable();

if(table){
var len=table.weblink_table.length;
for(var i=0;i<len;i++){
if(table.weblink_table[i].id==id.toString()){
return table.weblink_table[i].url;}
}
}
return null;}
gadget.getGadgetData=function (){
var _id=this._uniq_id.substr(16,4);
var title=this._getTitleData(_id);
var url=this._getUrlData(_id);
if(title&&url){
var json={"title":title,
"url":url,
};
try{
json=JSON.stringify(json);
return json;}catch(e){
return "";}
}
return "";}
return gadget;
