{**************************
播放器 script Ver1.0 by snowfox
History:
  2006-05-29: + create this file
**************************}
var
  i: Integer;
  
  ts1:TTabSheet;
  lblPlayer,lblPlayerPath:TLabel;
  cbbPlayer:TComboBox;
  edtPath:TEdit;
  btnSelPath:TButton;
  
//Init Skin form setting
procedure InitSetting;
var
	s:string;
	inifn:TIniFile;
begin
  inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try
    //Tab1
    s:=LowerCase(ReadString('system','MediaPlayer',''));
    if s='ttplayer' then  	cbbPlayer.ItemIndex:=0
    else if s='foobar' then	cbbPlayer.ItemIndex:=1
    else if s='winamp' then	cbbPlayer.ItemIndex:=2;
  finally
    inifn.free;
  end;

  inifn:=TIniFile.create(g_IniFile);
  with inifn do
  try
    //Tab1
    edtPath.text:=ReadString('system','MediaPlayerPath','');
    if s='' then
    begin
      s:=LowerCase(ReadString('system','MediaPlayer',''));
      if s='ttplayer' then  	cbbPlayer.ItemIndex:=0
      else if s='foobar' then	cbbPlayer.ItemIndex:=1
      else if s='winamp' then	cbbPlayer.ItemIndex:=2;
    end;
	  edtPath.text:=ReadString('system',s+'Path','');
  finally
    inifn.free;
  end;
end;

//save Skin form setting
function SaveSetting:boolean;
var
	s,aPlayer:string;
	inifn:TIniFile;
	i:integer;
	isChange:boolean;
begin
  result:=false;

	if cbbPlayer.ItemIndex=0 then      aPlayer:='ttplayer'
	else if cbbPlayer.ItemIndex=1 then aPlayer:='foobar'
	else if cbbPlayer.ItemIndex=2 then aPlayer:='winamp'
	else aPlayer:='';
  inifn:=TIniFile.create(g_IniFile);
  with inifn do
  try
    //default ini
    s:=ReadString('system','MediaPlayer','');
    if (s='') and (ReadString('system','MediaPlayer','')<>aPlayer) then
    begin
  		WriteString('system','MediaPlayer',aPlayer);
			isChange:=true;
    end;
    
    //save path
    if (aPlayer<>'') and (edtPath.text<>'') then
      WriteString('system',aPlayer+'Path',edtPath.text);

  finally
    inifn.free;
  end;
  
  //skin ini
  if s<>'' then
  begin
    inifn:=TIniFile.create(SkinFileName);
    with inifn do
    try
  		if ReadString('system','MediaPlayer','')<>aPlayer then
  		begin
  			WriteString('system','MediaPlayer',aPlayer);
				isChange:=true;
			end;
    finally
      inifn.free;
    end;
  end;
  
  if isChange then
  begin
  	result:=true;
    InitSkin; 
  end;
end;

procedure CreateTab1;
begin
  //--- Tab 1 ---
  ts1:=TTabSheet.Create(pgc);
  ts1.PageControl:=pgc;
  ts1.Caption:='播放器设置';
  
	lblPlayer:=TLabel.create(self);
	with lblPlayer do
	begin
    parent:=ts1;
    left:=16; top:=16; width:=100;
    caption:='请选择默认的播放器：';
	end;
	cbbPlayer:=TComboBox.create(self);
	with cbbPlayer do
	begin
	  parent:=ts1;
	  left:=16; top:=32; width:=321;
    Style:=csDropDownList;
    Items.add('千千静听');
    Items.add('Foobar');
    Items.add('Winamp');
    ItemIndex:=0;
    OnChange:=@cbbPlayerChange;
	end;

	lblPlayerPath:=TLabel.create(self);
	with lblPlayerPath do
	begin
    parent:=ts1;
    left:=16; top:=72; width:=96;
    caption:='播放器执行文件：';
	end;
  btnSelPath:=TButton.create(self);
  with btnSelPath do
  begin
    parent:=ts1;
    left:=224; top:=64; width:=112; height:=23;
    caption:='选择执行文件...';
    OnClick:=@btnSelPathClick;
  end;
  edtPath:=TEdit.create(self);
  with edtPath do
  begin
    parent:=ts1;
    left:=16; top:=88; width:=321;
  end;
end;

procedure btnSelPathClick(Sender:TObject);
var
  dlgopen:TOpenDialog;
begin
  dlgOpen:=TOpenDialog.Create(self);
  try
    dlgOpen.Filter:='Exe Files|*.exe';
    dlgOpen.FileName:=edtPath.text;
    if dlgOpen.Execute then
      edtPath.text:=dlgOpen.FileName;
  finally
    dlgOpen.free;
  end;
end;

procedure cbbPlayerChange(Sender:TObject);
var
	s:string;
	inifn:TIniFile;
begin
  inifn:=TIniFile.create(g_IniFile);
  with inifn do
  try
    //Tab1
 		if cbbPlayer.ItemIndex=0 then      s:='ttplayer'
 		else if cbbPlayer.ItemIndex=1 then s:='foobar'
 		else if cbbPlayer.ItemIndex=2 then s:='winamp'
 		else s:='';
 		edtPath.text:=ReadString('system',s+'Path','');
 		if edtPath.text='' then
	  case cbbPlayer.ItemIndex of
	    0://TTPlayer
	      if FileExists('C:\Program Files\TTPlayer\TTPlayer.exe') then
	        edtPath.text:='C:\Program Files\TTPlayer\TTPlayer.exe';
	    1://Foobar
	      if FileExists('C:\Program Files\Foobar\Foobar2000.exe') then
	        edtPath.text:='C:\Program Files\Foobar\Foobar2000.exe';
	    2://Winamp
	      if FileExists('C:\Program Files\WinAmp\WinAmp.exe') then
	        edtPath.text:='C:\Program Files\WinAmp\WinAmp.exe';
 		end;
 finally
    inifn.free;
  end;
end;

begin
  CreateTab1;
  InitSetting;
  
end.