procedure SelPath;
var
  s:string;
begin
  s:=edtPath.text;
  if SelectDirectory('请选择图片目录：',s) then
    edtpath.text:=s;
end;

//读取配置
procedure InitSetting;
begin
  cbbPlayStyle.ItemIndex:=GetSettingInt('PlayStyle',0);
  edtPath.text:=GetSetting('Path','');
  chkIncludeChildDir.checked:=GetSettingInt('IncludeChildDir',1)=1;
  edtInterval.text:=GetSetting('RefreshInterval','10');
  chkAutoChangeWallpaper.Checked:=GetSettingInt('AutoChangeWallpaper',0)=1;
end;

//保存配置
procedure SaveSetting;
begin
  SetSetting('PlayStyle',cbbPlayStyle.ItemIndex);
  if edtpath.text<>'' then
  begin
  	if copy(edtpath.text,length(edtpath.text),1)<>'\' then
  	  edtpath.text:=edtpath.text+'\';
  end;
  SetSetting('Path',edtPath.text);
  if chkIncludeChildDir.checked then
  	SetSettingInt('IncludeChildDir',1)
  else
  	SetSettingInt('IncludeChildDir',0);
  if chkAutoChangeWallpaper.checked then
    SetSettingInt('AutoChangeWallpaper',1)
  else
    SetSettingInt('AutoChangeWallpaper',0);
  SetSetting('RefreshInterval',edtInterval.text);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  xspfrm.beginupdate;
  InitSetting;
  xspfrm.endupdate;
end;

//--- Widget设置窗口关闭事件，当按下设置窗口的确定按钮时会触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult):boolean;
var
  i:integer;
begin
  result:=true;
  try
    i:=StrToInt(edtInterval.text);
    if i<=0 then raise('');
    SaveSetting;
  except
    showmsg('无效的刷新间隔时间！');
    result:=false;
  end;
end;

