{*****************************************************************************
 *
 *  FMFolder.pas - Folder form  (28-July-1998)
 *
 *  Copyright (c) 1998-99 Michael Haller
 *
 *  Author:     Michael Haller
 *  E-mail:     michael@discountdrive.com
 *  Homepage:   http://www.discountdrive.com/sunrise
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation;
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 *
 *----------------------------------------------------------------------------
 *
 *  Revision history:
 *
 *     DATE     REV                 DESCRIPTION
 *  ----------- --- ----------------------------------------------------------
 *
 *****************************************************************************}

unit FMFolder;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  GradForm,
  StdCtrls, ExtCtrls, ComCtrls, PXStuff, FileCtrl;

type
  TFolderForm = class(TdfsGradientForm)
    Panel1: TPanel;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Button1: TButton;
    Button2: TButton;
    Label16: TLabel;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Bevel1: TBevel;
    Edit2: TEdit;
    Bevel5: TBevel;
    Button3: TButton;
    Panel2: TPanel;
    Image1: TImage;
    Image2: TImage;
    Label4: TLabel;
    Label20: TLabel;
    Label23: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    procedure Button1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
    Folder: string;
  public
    { Public declarations }
    procedure LoadFolderData(Data: PFolderData);
    procedure SaveFolderData(var Data: PFolderData);
  end;

var
  FolderForm: TFolderForm;

implementation

{$R *.DFM}

uses
  Main;

procedure TFolderForm.LoadFolderData(Data: PFolderData);
begin
  RadioButton1.Checked := True;
  Edit1.Text := Data^.Name;
  Edit2.Text := Data^.Filter;
  RadioButton2.Checked := Data^.Outbox;
  RadioButton3.Checked := Data^.Inbox;
  RadioButton4.Checked := Data^.Drafts;
  Folder := Data^.Path;
  CheckBox1Click(Self);
end;

procedure TFolderForm.SaveFolderData(var Data: PFolderData);
begin
  Data^.Name := Edit1.Text;
  Data^.Filter := Edit2.Text;
  Data^.OutBox := RadioButton2.Checked;
  Data^.InBox := RadioButton3.Checked;
  Data^.Drafts := RadioButton4.Checked;
  Data^.Path := GetParentFolder(Folder) + Edit1.Text + '\';
end;

procedure TFolderForm.Button1Click(Sender: TObject);
var
  S: string;
  I: Integer;
begin
  for I := 1 to Length(Edit1.Text) do
    if Edit1.Text[I] in ['\', '/', '<', '>', ':', '?', '*', '"', '|', #19] then
    begin
      MessageDlg(GetMessageString(44), mtWarning, [mbOK], 0);
      Exit;
    end;
  S := GetParentFolder(Folder) + Edit1.Text + '\';
  if LowerCase(Folder) <> LowerCase(S) then
    if DirectoryExists(S) then begin
      MessageDlg(Format(GetMessageString(50), [Edit1.Text]), mtWarning,
        [mbOK], 0);
      Exit;
    end;
  ModalResult := mrOK;
end;

procedure TFolderForm.CheckBox1Click(Sender: TObject);
var
  S: string;
begin
  S := GetMessageString(51);       //过滤器只可能用在收件箱.
  if RadioButton3.Checked then begin
    if Edit2.Text = S then
      Edit2.Text := '';
    Edit2.Enabled := True;
    Label20.Enabled := True;
    Label23.Enabled := True;
  end
  else begin
    Edit2.Text := S;
    Edit2.Enabled := False;
    Label20.Enabled := False;
    Label23.Enabled := False;
  end;
end;

procedure TFolderForm.FormCreate(Sender: TObject);
begin
  Image1.Picture.Bitmap := MainForm.Image5.Picture.Bitmap;
  Label4.Font.Color := lblFontColor;
end;

procedure TFolderForm.Button3Click(Sender: TObject);
begin
  Application.HelpContext(11);
end;

initialization
  PMRegistry.AddCustomClass(TFolderForm, 'TFolderForm');

end.

