{**************************
Dashboard Clock OnSetting script Ver1.0 by snowfox
**************************}
var
  ts1:TTabSheet;
  lblbgColor,lblTitle,lblUrl:TLabel;
  cbbbgType:TComboBox;
  edtTitle,edtUrl:TEdit;
  //Tab1
  
  
//Init Skin form setting
procedure InitSetting;
var
	s:string;
	inifn:TIniFile;
	i:integer; 
	function GetNetTVUrl(names:string):string;
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPPlayiniFile);
                  lst:=TStringList.Create;
                    inifn1.ReadSections(lst);
                    if lst.Count>0 then
                      begin 
                      for j:=0 to lst.Count-1 do 
                        if lst[j]=names then
                        begin
                          wmpURL:=inifn1.ReadString(lst[j],'URL','mms://media1.tv.cn/home');
                          Break;
                        end;
                      end;
                  result:=wmpURL;
    finally
      lst.free;
      inifn1.free;
    end;
  end;
	procedure GetNetTVName;
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPPlayiniFile);
                  lst:=TStringList.Create;
                  cbbbgType.items.clear;
                    inifn1.ReadSections(lst);
                    if lst.Count>0 then
                      begin 
                      for j:=0 to lst.Count-1 do   
                        cbbbgType.Items.add(lst[j]);  
                      end; 
    finally
      lst.free;
      inifn1.free;
    end;
	end;
	
begin
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try 
     GetNetTVName;
     s:=ReadString('Item1','Item0','CCTV音乐');
     edtTitle.text:=s;
     s:=ReadString('Item1','Item0','CCTV音乐');
     edtUrl.text:=GetNetTVUrl(s);
     
      s:=ReadString('Item1','Item0','CCTV音乐');
      if s<>'' then
        begin
        i:=cbbbgType.Items.IndexOf(s);
      	if i>=0 then
      	  cbbbgType.itemindex:=i
      	else
        	cbbbgType.text:=s;
        end
        else
      	cbbbgType.itemindex:=0;
      	
     //ReadBool('Item1','Enable',true); 

     //ReadString('Item1','Colorize','#000000'); 
    
  finally
    inifn.free;
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
	s:string;
	inifn:TIniFile;
	i:integer;
	bColor,bTrans:Boolean;
	
  function SetNetTVUrl(names,urls:string):string;
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPPlayiniFile);
                  inifn1.WriteString(names,'URL',urls);
                  result:=wmpURL;
    finally 
      inifn1.free;
    end;
  end;
begin
  result:=true;
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try 
    WriteString('Item1','Item0',edtTitle.text);
    SetNetTVUrl(edtTitle.text,edtUrl.text); 
    
    //WriteBool('Item0','Enable',bColor);  
    //WriteString('Item1','Colorize',s);
          
    InitSkin; 
  finally
    inifn.free;
  end;
  
end;

//---界面设置---
procedure CreateTab1;
begin
  ts1:=TTabSheet.Create(pgc);
  ts1.PageControl:=pgc;
  ts1.Caption:='电视台设置';
  
  lblTitle:=TLabel.create(self);
  with lblTitle do
  begin
    parent:=ts1;
    left:=16; top:=16; width:=54;
    caption:='电视台名称：';
  end;
  edtTitle:=TEdit.create(self);
  with edtTitle do
  begin
    parent:=ts1;
    left:=80; top:=12; width:=257;
  end;
  lblUrl:=TLabel.create(self);
  with lblUrl do
  begin
    parent:=ts1;
    left:=16; top:=45; width:=54;
    caption:='电视台地址：';
  end;
  edtUrl:=TEdit.create(self);
  with edtUrl do
  begin
    parent:=ts1;
    left:=80; top:=41; width:=257;
  end;
  
  lblbgColor:=TLabel.create(self);
  with lblbgColor do
  begin
    parent:=ts1;
    left:=16; top:=74; width:=84;
    caption:='选择电视台：';
  end;
  cbbbgType:=TComboBox.create(self);
  with cbbbgType do
  begin
    parent:=ts1;
    left:=80; top:=70; width:=137;
    DropDownCount:=15; 
    //Items.Add('无');
    OnChange:=@cbbbgTypeChange;
    Style:=csDropDownList;
  end;
end;

procedure cbbbgTypeChange(Sender: TObject);
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPPlayiniFile);
                  lst:=TStringList.Create; 
                    inifn1.ReadSections(lst);
                    if lst.Count>0 then
                      begin 
                      for j:=0 to lst.Count-1 do   
                        begin
                        if lst[j]=cbbbgType.text then 
                          begin
                          edtTitle.text:=lst[j];
                          edtUrl.text:=inifn1.ReadString(lst[j],'URL','');
                          end; 
                        end; 
                      end; 
    finally
      lst.free;
      inifn1.free;
    end;
	end;
  
  

begin
  CreateTab1;
  InitSetting;
  
end.