{**************************
Dashboard Clock OnSetting script Ver1.0 by snowfox
**************************}
var
  ts1:TTabSheet;
  lblTitle,lblUrl,lblbgColor1,lblText,lblText1:TLabel;
  cbbbgType1:TComboBox;
  edtTitle,edtUrl:TEdit;
  //Tab1
  
  
//Init Skin form setting
procedure InitSetting;
var
	s:string;
	inifn:TIniFile;
	i:integer; 
	
	function GetNetworkUrl(names:string):string;
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPiniFile);
                  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://mms.cnr.cn/live1');
                          Break;
                        end;
                      end;
                  result:=wmpURL;
    finally
      lst.free;
      inifn1.free;
    end;
	end;
	
	procedure GetRadioName;
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPiniFile);
                  lst:=TStringList.Create;
                  cbbbgType1.items.clear;
                    inifn1.ReadSections(lst);
                    if lst.Count>0 then
                      begin 
                      for j:=0 to lst.Count-1 do   
                        cbbbgType1.Items.add(lst[j]);  
                      end; 
    finally
      lst.free;
      inifn1.free;
    end;
	end;
	
begin
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try 

     s:=ReadString('Item0','Text','中国之声');
     edtTitle.text:=s; 
     edtUrl.text:=GetNetworkUrl(s);
     
    GetRadioName; 
 
     s:=ReadString('Item0','Text','中国之声');
      if s<>'' then
        begin
        i:=cbbbgType1.Items.IndexOf(s);
      	if i>=0 then
      	  cbbbgType1.itemindex:=i
      	else
        	cbbbgType1.text:=s;
        end
        else
      	cbbbgType1.itemindex:=0;
      	
      	      	  
  finally
    inifn.free;
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
	s:string;
	inifn:TIniFile;
	i:integer;
	bColor,bTrans:Boolean;
	
	procedure SetNetworkUrl(names,urls:string);
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPiniFile);
                  lst:=TStringList.Create;
                  inifn1.ReadSections(lst); 
                    if pos(names,lst.text)<=0 then //说明没有此电台，需要添加
                      begin
                      inifn1.WriteString(names,'URL',urls);   
                      end;
                
    finally
      lst.free;
      inifn1.free;
    end;
	end;
	
begin
  result:=true;
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try 
    
    SetNetworkUrl(edtTitle.text,edtUrl.text);
    WriteString('Item0','Text',edtTitle.text);
            
    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;
   
  lblbgColor1:=TLabel.create(self);
  with lblbgColor1 do
  begin
    parent:=ts1;
    left:=16; top:=80; width:=200;
    caption:='从下面选台，或在上面新加电台：';
  end;
  cbbbgType1:=TComboBox.create(self);
  with cbbbgType1 do
  begin
    parent:=ts1;
    left:=16; top:=100; width:=200;
    DropDownCount:=15; 
    //Items.Add('无');
    OnChange:=@cbbbgTypeChange1;
    Style:=csDropDownList;
  end;
  
	lblText:=TLabel.create(self);
  with lblText do
  begin
    parent:=ts1;
    left:=16; top:=170; width:=200;
    caption:='提示：在收听时，CPU和内存占用将升高，这属于正常现象。';
  end;	  
  
  lblText1:=TLabel.create(self);
  with lblText1 do
  begin
    parent:=ts1;
    left:=16; top:=192; width:=200;
    caption:='网络收音机的收听质量，与网速快慢有关!';
  end;	 
  
  
end;

procedure cbbbgTypeChange1(Sender: TObject);
	var inifn1:TIniFile;
	    lst:TStrings;
	    wmpURL:string; j:integer;
	begin
	  try
                  inifn1:=TIniFile.Create(SkinWMPiniFile);
                  lst:=TStringList.Create; 
                    inifn1.ReadSections(lst);
                    if lst.Count>0 then
                      begin 
                      for j:=0 to lst.Count-1 do   
                        begin
                        if lst[j]=cbbbgType1.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.