unit PREFS;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, inifiles, ComCtrls;

type
  TPrefsBox = class(TForm)
    btOK: TButton;
    btESC: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    TabSheet5: TTabSheet;
    TabSheet6: TTabSheet;
    GroupBox1: TGroupBox;
    lbBitRate: TLabel;
    lbAllParam: TLabel;
    lbQuality: TLabel;
    eAllParam: TEdit;
    cbBitRate: TComboBox;
    cbQuality: TComboBox;
    cbConverter: TComboBox;
    GroupBox2: TGroupBox;
    lbAbzac: TLabel;
    lbMaxlen: TLabel;
    lbHugeLen: TLabel;
    eAbzac: TEdit;
    eMaxLen: TEdit;
    eHugeLen: TEdit;
    chkbRJust: TCheckBox;
    GroupBox3: TGroupBox;
    lbSeries: TLabel;
    eNB: TEdit;
    chkbChap: TCheckBox;
    GroupBox4: TGroupBox;
    lbFE1: TLabel;
    lbFE2: TLabel;
    eFE1: TEdit;
    eFE2: TEdit;
    GroupBox6: TGroupBox;
    lbFrag: TLabel;
    chkbStyle: TCheckBox;
    chkbPrev: TCheckBox;
    eNF: TEdit;
    chkbTags: TCheckBox;
    GroupBox5: TGroupBox;
    AutoCap: TCheckBox;
    AutoAloud: TCheckBox;
    AutoAloudP: TRadioButton;
    AutoAloudA: TRadioButton;
    lbRepeat: TLabel;
    eRepeat: TEdit;
    AutoRepl: TCheckBox;
    AutoParag: TCheckBox;
    chkbConvMinimize: TCheckBox;
    chkbAudioFromTop: TCheckBox;
    GroupBox7: TGroupBox;
    lbPicMargin: TLabel;
    ePicMargin: TEdit;
    chkbPicImport: TCheckBox;
    lbTime: TLabel;
    chkbAudioSplit: TCheckBox;
    chkbHeader: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure OKButtonClick(Sender: TObject);
    procedure ESCButtonClick(Sender: TObject);
    procedure CBChange(Sender: TObject);
    procedure AAChange(Sender: TObject);
    procedure ENBChange(Sender: TObject);
    procedure EditKeyPress(Sender: TObject; var Key: char);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  PrefsBox: TPrefsBox;

implementation

uses Unit1;

{$R *.dfm}


procedure TPrefsBox.FormCreate(Sender: TObject);
begin
  if Form1.AudioConverter = 0 then begin
    PrefsBox.cbQuality.Visible := True;
    PrefsBox.lbQuality.Visible := True;
  end else begin   {для OGG параметр "качество" отсутствует}
    PrefsBox.cbQuality.Visible := False;
    PrefsBox.lbQuality.Visible := False;
  end;
 if AutoAloud.Checked then begin
    AutoAloudP.Enabled := True;
    AutoAloudA.Enabled := True;
    lbRepeat.Enabled := True;
    eRepeat.Enabled := True;
  end else begin
    AutoAloudP.Enabled := False;
    AutoAloudA.Enabled := False;
    lbRepeat.Enabled := False;
    eRepeat.Enabled := False;
  end;
end;

procedure TPrefsBox.CBChange(Sender: TObject);
var
  p, q: string;
begin
  if cbConverter.ItemIndex = 0 then begin
    lbBitRate.Caption := 'Сжатие аудиофайла не производится!';
    cbBitRate.Visible := False;
    cbQuality.Visible := False;
    lbQuality.Visible := False;
    eAllParam.Visible := False;
    lbAllParam.Caption := 'НАИВЫСШЕЕ КАЧЕСТВО ЗВУЧАНИЯ. РАЗМЕРЫ АУДИОФАЙЛА БУДУТ ОЧЕНЬ ВЕЛИКИ';
    exit;
  end;
  if cbConverter.ItemIndex = 1 then begin
    lbBitRate.Caption := 'Битрейд!';
    cbBitRate.Visible := True;
    cbQuality.Visible := True;
    lbQuality.Visible := True;
    eAllParam.Visible := True;
    lbAllParam.Caption := 'Параметры в целом';
    q := '-b'+cbBitRate.Items[cbBitRate.ItemIndex];
    case cbQuality.ItemIndex of
      0: p := '-f';
      1: p := '';
      2: p := '-h';
    else
      p := '';
    end;
    eAllParam.Text := q+' '+p;
    exit;
  end;
  if cbConverter.ItemIndex = 2 then begin
    lbBitRate.Caption := 'Битрейд!';
    cbBitRate.Visible := True;
    cbQuality.Visible := False;
    lbQuality.Visible := False;
    eAllParam.Visible := True;
    lbAllParam.Caption := 'Параметры в целом';
    q := '-'+cbBitRate.Items[cbBitRate.ItemIndex];
    eAllParam.Text := q;
    exit;
  end;
  Form1.AudioConverter := cbConverter.ItemIndex;
end;

procedure TPrefsBox.AAChange(Sender: TObject);
begin
  if AutoAloud.Checked then begin
    AutoAloudP.Enabled := True;
    AutoAloudA.Enabled := True;
    lbRepeat.Enabled := True;
    eRepeat.Enabled := True;
  end else begin
    AutoAloudP.Enabled := False;
    AutoAloudA.Enabled := False;
    lbRepeat.Enabled := False;
    eRepeat.Enabled := False;
  end;
end;

procedure TPrefsBox.ENBChange(Sender: TObject);
var
  t: integer;
begin
    t := StrToIntDef(eNB.Text,0) div 720;
    if t < 45000 then lbTime.Caption := '~'+IntToStr(t)+' мин. звучания'
                 else lbTime.Caption := '~0 мин. звучания';
end;

procedure TPrefsBox.OKButtonClick(Sender: TObject);
var
  Ini: TIniFile;
begin
  Ini:=TiniFile.Create(extractfilepath(Application.ExeName)+'$.ini');
  Ini.WriteInteger('AudioConverter','ACNumber',cbConverter.ItemIndex);
  Ini.WriteInteger('AudioConverter','BRNumber',cbBitRate.ItemIndex);
  Ini.WriteInteger('AudioConverter','QNumber',cbQuality.ItemIndex);
  Ini.WriteString('AudioConverter','AllParam',eAllParam.Text);
  Ini.WriteBool('AudioConverter','ConverterMinimize',chkbConvMinimize.Checked);
  Ini.WriteBool('AudioConverter','AudioFromTop',chkbAudioFromTop.Checked);
  Ini.WriteString('LitText','Parag',eAbzac.Text);
  Ini.WriteString('LitText','MaxLen',eMaxLen.Text);
  Ini.WriteString('LitText','MaxHugeLen',eHugeLen.Text);
  Ini.WriteBool('LitText','RightJustify',chkbRJust.Checked);
  Ini.WriteString('Series','BytesInBlock',eNB.Text);
  Ini.WriteBool('Series','ChapHeadSencitive',chkbChap.Checked);
  Ini.WriteBool('Series','AudioSplit',chkbAudioSplit.Checked);
  Ini.WriteBool('Series','Header',chkbHeader.Checked);
  Ini.WriteString('FreshEye','Deep',eFE1.Text);
  Ini.WriteString('FreshEye','Similarity',eFE2.Text);
  Ini.WriteString('Others','BytesInFrag',eNF.Text);
  Ini.WriteBool('Others','IgnoreRules',chkbStyle.Checked);
  Ini.WriteBool('Others','IgnorePrev',chkbPrev.Checked);
  Ini.WriteBool('Others','IsXML',not chkbTags.Checked);
  Ini.WriteBool('Text','AutoCap',AutoCap.Checked);
  Ini.WriteBool('Text','AutoRepl',AutoRepl.Checked);
  Ini.WriteBool('Text','AutoParag',AutoParag.Checked);
  Ini.WriteBool('Text','AutoAloud',AutoAloud.Checked);
  Ini.WriteBool('Text','AutoAloudP',AutoAloudP.Checked);
  Ini.WriteBool('Text','AutoAloudA',AutoAloudA.Checked);
  Ini.WriteString('Text','AutoRepeat',eRepeat.Text);
  Ini.WriteString('Text','PicMargin',ePicMargin.Text);
  Ini.WriteBool('Text','PicImport',chkbPicImport.Checked);
  Ini.UpdateFile;
  Ini.Free;
  PrefsBox.Close;
end;

procedure TPrefsBox.EditKeyPress(Sender: TObject; var Key: char);
begin
  if not (Key in ['0'..'9',#8]) then Key := #0;
end;

procedure TPrefsBox.ESCButtonClick(Sender: TObject);
begin
  PrefsBox.Close;
end;

end.
