var
  MaxSpeed:Int64;
  
//读取配置
procedure InitIni;
begin
  if System.Machine.Network.AvailableAdapterList.count>0 then 
    cbbList.items.text:=System.Machine.Network.AvailableAdapterList.text
  else
    cbbList.items.text:=System.Machine.Network.AdapterList.text;
  cbbList.text:=GetSetting('NetDevice',cbbList.items.strings[0]);
  MaxSpeed:=GetSettingInt('MaxSpeed',0);
  cbbNetType.ItemIndex:=GetSettingInt('NetType',0);
end;

//保存配置
procedure SaveIni;
begin
  SetSetting('NetDevice',cbbList.text);
  SetSettingInt('NetType',cbbNetType.ItemIndex);
  case cbbNetType.ItemIndex of
    1: MaxSpeed:=16*1024;  // 128K Modern
    2: MaxSpeed:=64*1024;  // 512K ADSL
    3: MaxSpeed:=128*1024; // 1M ADSL
    4: MaxSpeed:=192*1024; // 1.5M ADSL
    5: MaxSpeed:=256*1024; // 2M ADSL
    6: MaxSpeed:=512*1024; // 4M ADSL
  end;
  SetSettingInt('MaxSpeed',MaxSpeed);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  chkShowAllNetDevice.OnClick:='chkShowAllNetDeviceClick';
  cbbNetType.OnSelect:='cbbNetTypeSelect';
  Beginupdate;
  InitIni;
  Endupdate;
end;

//--- 按下设置窗口的确定按钮时，触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
begin
  result:=true;
  if Result then
    SaveIni;
end;

procedure chkShowAllNetDeviceClick(sender:TObject);
begin
  if chkShowAllNetDevice.checked then
    cbbList.items.text:=System.Machine.Network.AvailableAdapterList.text
  else
    cbbList.items.text:=System.Machine.Network.AdapterList.text;
end;

procedure cbbNetTypeSelect(sender:TObject);
var
  iMaxSpeed:Int64;
begin
  case TxspComboBox(sender).ItemIndex of
    0: iMaxSpeed:=0;        //Auto
    1: iMaxSpeed:=16*1024;  // 128K Modern
    2: iMaxSpeed:=64*1024;  // 512K ADSL
    3: iMaxSpeed:=128*1024; // 1M ADSL
    4: iMaxSpeed:=192*1024; // 1.5M ADSL
    5: iMaxSpeed:=256*1024; // 2M ADSL
    6: iMaxSpeed:=512*1024; // 4M ADSL
  end;
end;