ManageAliases.pas
上传用户:dh8233980
上传日期:2014-10-16
资源大小:1015k
文件大小:7k
- unit ManageAliases;
- (******************************************************************************)
- (* *)
- (* Hermes Manage Aliases Dialog Box *)
- (* Part of Hermes SMTP/POP3 Server. *)
- (* Copyright(C) 2000 by Alexander J. Fanti, All Rights Reserver Worldwide. *)
- (* *)
- (* Created January 13, 2000 by Alexander J. Fanti. See License.txt *)
- (* *)
- (* Used by: Main *)
- (* Uses: DataU1, AddEditAlias *)
- (* *)
- (* Description: This Modal dialog window allows the user to Add, Edit, Delete *)
- (* and Rename user aliases *)
- (* *)
- (* Revisions: 1/21/2000 AJF Commented *)
- (* *)
- (******************************************************************************)
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Menus, Buttons;
- type
- TfrmManageAliases = class(TForm)
- lstList: TListBox;
- btnDelete: TBitBtn;
- btnAdd: TBitBtn;
- btnEdit: TBitBtn;
- btnImport: TBitBtn;
- btnClose: TBitBtn;
- btnRename: TBitBtn;
- btnExport: TBitBtn;
- popupMenu: TPopupMenu;
- puAdd: TMenuItem;
- puEdit: TMenuItem;
- puDelete: TMenuItem;
- puRename: TMenuItem;
- N1: TMenuItem;
- puImport: TMenuItem;
- puExport: TMenuItem;
- procedure FormShow(Sender: TObject);
- procedure popupMenuPopup(Sender: TObject);
- procedure lstListClick(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- procedure btnEditClick(Sender: TObject);
- procedure btnDeleteClick(Sender: TObject);
- procedure btnRenameClick(Sender: TObject);
- procedure btnImportClick(Sender: TObject);
- procedure btnExportClick(Sender: TObject);
- procedure btnCloseClick(Sender: TObject);
- procedure lstListDblClick(Sender: TObject);
- private
- { Private declarations }
- procedure Add; // Add Alias
- procedure Edit; // Edit Alias
- procedure Delete; // Delete Alias
- procedure Rename; // Rename Alias
- procedure Import; // Import Alias
- procedure DoExport; // Export Alias
- procedure EnableUI; // Enable buttons and popum menus based on selections
- public
- { Public declarations }
- end;
- var
- frmManageAliases: TfrmManageAliases;
- implementation
- uses DataU1, AddEditAlias;
- {$R *.DFM}
- procedure TfrmManageAliases.FormShow(Sender: TObject);
- begin
- // Populate list with aliases
- INI.Alias_GetList(lstList.Items);
- // Enable buttons based on list selection
- EnableUI;
- end;
- procedure TfrmManageAliases.Add;
- begin
- // if they added an alias through the AddEditAlias Dialog...
- // then refresh the list of aliases
- if frmAddEditAlias.Add then INI.Alias_GetList(lstList.Items);
- end;
- procedure TfrmManageAliases.Edit;
- begin
- // if there's a selected alias, then let them edit it
- // through the AddEditAlias Dialog...
- // then refresh the list of aliases
- if lstList.ItemIndex > -1 then
- if frmAddEditAlias.Edit(lstList.Items[lstList.ItemIndex]) then
- INI.Alias_GetList(lstList.Items);
- end;
- procedure TfrmManageAliases.Delete;
- var
- x : Integer;
- begin
- // Ask if they really want to delete, cause it can't be un-done
- x := MessageDlg('Deleting alias(es) cannot be undone. Proceed?',
- mtConfirmation, [mbYes, mbNo], 0);
- if x = mrYes then begin
- // they really want to do it... for each selected alias...
- // call the delete function and refresh the alias list
- for x := 0 to lstList.Items.Count -1 do
- if lstList.Selected[x] then INI.Alias_Delete(lstList.Items[x]);
- INI.Alias_GetList(lstList.Items);
- end;
- end;
- procedure TfrmManageAliases.Rename;
- var
- OldAliasID, AliasUser, NewAliasID : String;
- begin
- // if there's an alias selected...
- if lstList.ItemIndex > -1 then
- INI.Alias_Parse(lstList.Items[lstList.ItemIndex], OldAliasID, AliasUser);
- NewAliasID := InputBox('Rename Alias', 'Enter New Alias Name', OldAliasID);
- if Pos(ALIASSEPERATOR, NewAliasID) = 0 then begin
- // and the new alias isn't the same as the old one...
- // then rename the alias and refresh the display
- if LowerCase(NewAliasID) <> LowerCase(OldAliasID) then begin
- if not INI.Alias_Rename(OldAliasID, NewAliasID) then
- ShowMessage('Error: Cound not re-name.' + #13 + #10 +
- 'Aliases must have a unique Name.')
- else
- INI.Alias_GetList(lstList.Items);
- end;
- end else begin
- ShowMessage('Alias cannot contain "' + ALIASSEPERATOR + '".');
- end;
- end;
- procedure TfrmManageAliases.Import;
- begin // Import Aliases
- ShowMessage('Feature not implemented yet...');
- // DEBUG
- // How should I import Aliases?
- end;
- procedure TfrmManageAliases.DoExport;
- begin // Export aliases
- ShowMessage('Feature not implemented yet...');
- // DEBUG
- // How should I export aliases?
- end;
- procedure TfrmManageAliases.EnableUI;
- begin
- // Enable buttons and menus based on list selection
- btnEdit.Enabled := lstList.SelCount = 1;
- btnDelete.Enabled := lstList.SelCount > 0;
- btnRename.Enabled := lstList.SelCount = 1;
- btnExport.Enabled := lstList.Items.Count > 0;
- puEdit.Enabled := lstList.SelCount = 1;
- puDelete.Enabled := lstList.SelCount > 0;
- puRename.Enabled := lstList.SelCount = 1;
- puExport.Enabled := lstList.Items.Count > 0;
- end;
- // Hook Buttond and menus up with functions for performing actions
- procedure TfrmManageAliases.btnAddClick(Sender: TObject);
- begin Add; end;
- procedure TfrmManageAliases.btnEditClick(Sender: TObject);
- begin Edit; end;
- procedure TfrmManageAliases.btnDeleteClick(Sender: TObject);
- begin Delete; end;
- procedure TfrmManageAliases.btnRenameClick(Sender: TObject);
- begin Rename; end;
- procedure TfrmManageAliases.btnImportClick(Sender: TObject);
- begin Import; end;
- procedure TfrmManageAliases.btnExportClick(Sender: TObject);
- begin DoExport; end;
- procedure TfrmManageAliases.lstListClick(Sender: TObject);
- begin EnableUI; end;
- procedure TfrmManageAliases.lstListDblClick(Sender: TObject);
- begin Edit; end;
- procedure TfrmManageAliases.popupMenuPopup(Sender: TObject);
- begin EnableUI; end;
- procedure TfrmManageAliases.btnCloseClick(Sender: TObject);
- begin Close; end;
- end.