{**************************
播放器 script Ver1.0 by snowfox
History:
  2006-05-29: + create this file
**************************}
const spacei=53;
var
  i: Integer;
  
  ts1:TTabSheet;
  lblPlayer,lblPlayerPath,lblPlayerPath1,lblPlayerPath2:TLabel;
  cbbPlayer:TComboBox;
  edtPath,edtPath1,edtPath2:TEdit;
  btnSelPath,btnSelPath1,btnSelPath2: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;
    s:=ReadString('Item3','Command','');
	  if s='' then 
	    edtPath1.text:=SkinQQPathEXE
	    else  //<!Run=C:\Program Files\Tencent\QQ\QQ.exe>
            edtPath1.text:=copy(s,7,Length(s)-7);
	  s:=ReadString('Item4','Command','');
	  if s='' then 
	    edtPath2.text:=SkinMSNPathEXE 
	    else 
	    edtPath2.text:=copy(s,7,Length(s)-7);
  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:=true;

	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 
    WriteString('system','MediaPlayerPath',edtPath.text);
    WriteString('system','MediaPlayer',aPlayer);
  finally
    inifn.free;
  end;
   inifn:=TIniFile.create(SkinFileName);
  with inifn do
  try
    //default ini
    WriteString('Item3','Command','<!Run='+edtPath1.text+'>');
    WriteString('Item4','Command','<!Run='+edtPath2.text+'>');
 
    InitSkin;  
  finally
    inifn.free;
  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;
  //---------------------
  //QQ地址
  lblPlayerPath1:=TLabel.create(self);
  with lblPlayerPath1 do
    begin
    parent:=ts1;
    left:=16; top:=72+spacei; width:=96;
    caption:='QQ执行文件：';
    end;
  btnSelPath1:=TButton.create(self);
  with btnSelPath1 do
  begin
    parent:=ts1;
    left:=224; top:=64+spacei; width:=112; height:=23;
    caption:='选择执行文件...';
    OnClick:=@btnSelPathClick1;
  end;
  edtPath1:=TEdit.create(self);
  with edtPath1 do
  begin
    parent:=ts1;
    left:=16; top:=88+spacei; width:=321;
  end;
  //---------------------
    //MSN地址
  lblPlayerPath2:=TLabel.create(self);
  with lblPlayerPath2 do
    begin
    parent:=ts1;
    left:=16; top:=72+2*spacei; width:=96;
    caption:='MSN执行文件：';
    end;
  btnSelPath2:=TButton.create(self);
  with btnSelPath2 do
  begin
    parent:=ts1;
    left:=224; top:=64+2*spacei; width:=112; height:=23;
    caption:='选择执行文件...';
    OnClick:=@btnSelPathClick2;
  end;
  edtPath2:=TEdit.create(self);
  with edtPath2 do
  begin
    parent:=ts1;
    left:=16; top:=88+2*spacei; 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 btnSelPathClick1(Sender:TObject);
var
  dlgopen:TOpenDialog;
begin
  dlgOpen:=TOpenDialog.Create(self);
  try
    dlgOpen.Filter:='Exe Files|*.exe';
    dlgOpen.FileName:=edtPath1.text;
    if dlgOpen.Execute then
      edtPath1.text:=dlgOpen.FileName;
  finally
    dlgOpen.free;
  end;
end;

procedure btnSelPathClick2(Sender:TObject);
var
  dlgopen:TOpenDialog;
begin
  dlgOpen:=TOpenDialog.Create(self);
  try
    dlgOpen.Filter:='Exe Files|*.exe';
    dlgOpen.FileName:=edtPath2.text;
    if dlgOpen.Execute then
      edtPath2.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.