home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 11
/
Freelog011.iso
/
BestOf
/
PhoenixMail
/
Source
/
phoenix
/
FMAddress.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1999-02-07
|
21KB
|
659 lines
{*****************************************************************************
*
* FMAddress.pas - Address Book Form (20-August-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 FMAddress;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ComCtrls, FMEditAdr, ExtCtrls, Buttons, ParserSup, PXStuff,
ImgList, StdCtrls, ComboBoxEx, FMSelBook, EnhListView, ExtListView, Registry,
FMSearch, LangSup, IniFiles;
type
TAddressForm = class(TForm)
MainMenu1: TMainMenu;
Address1: TMenuItem;
New1: TMenuItem;
Delete1: TMenuItem;
N1: TMenuItem;
Edit1: TMenuItem;
PopupMenu1: TPopupMenu;
NewAddress1: TMenuItem;
DeleteAddress1: TMenuItem;
N2: TMenuItem;
EditAddress1: TMenuItem;
Panel1: TPanel;
Bevel1: TBevel;
StatusBar1: TStatusBar;
N3: TMenuItem;
MailtoAddresses1: TMenuItem;
Close1: TMenuItem;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
N4: TMenuItem;
MailtoAddresses2: TMenuItem;
File1: TMenuItem;
ImageList1: TImageList;
Search1: TMenuItem;
N5: TMenuItem;
SpeedButton6: TSpeedButton;
Book1: TMenuItem;
New2: TMenuItem;
Delete2: TMenuItem;
ComboBox1: TComboBoxEx;
SelectAllAddresses1: TMenuItem;
SelectAll1: TMenuItem;
N7: TMenuItem;
Rename1: TMenuItem;
SpeedButton10: TSpeedButton;
Movetoanotherbook1: TMenuItem;
ListView1: TExtListView;
N6: TMenuItem;
Image1: TImage;
Bevel2: TBevel;
Bevel3: TBevel;
Bevel4: TBevel;
Bevel5: TBevel;
Help1: TMenuItem;
Contents1: TMenuItem;
procedure New1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Edit1Click(Sender: TObject);
procedure Delete1Click(Sender: TObject);
procedure Close1Click(Sender: TObject);
procedure ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure MailtoAddresses1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Search1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure New2Click(Sender: TObject);
procedure Delete2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure SelectAllAddresses1Click(Sender: TObject);
procedure Rename1Click(Sender: TObject);
procedure Movetoanotherbook1Click(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ListView1DrawHeader(Control: TWinControl;
var ACanvas: TCanvas; Index: Integer; var ARect: TRect;
Selected: Boolean; var DefaultDrawing: Boolean);
procedure ListView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Contents1Click(Sender: TObject);
private
{ Private declarations }
MailOK: Boolean;
Filename: String;
function ToAddressFormat(I1: Integer; S1, S2, S3, S4, S5: String): String;
procedure FromAddressFormat(S: String; var I1: Integer; var S1, S2, S3, S4, S5: String);
procedure LoadAddressBook;
procedure SaveAddressBook;
public
{ Public declarations }
function GetSelAddresses: String;
function SetAddress(S: String): Boolean;
procedure SetMenusEnable;
procedure SetStatusBar;
end;
var
AddressForm: TAddressForm;
implementation
{$R *.DFM}
uses
Main;
var
F: Text;
procedure TAddressForm.SetStatusBar;
begin
StatusBar1.Panels[0].Text := Format(MainForm.ListBox1.Items[38], [IntToStr(ListView1.Items.Count), IntToStr(ListView1.SelCount)]);
end;
function TAddressForm.ToAddressFormat(I1: Integer; S1, S2, S3, S4, S5: String): String;
begin
Result := IntToStr(I1)+','+S1+','+S2+','+S3+','+S4+','+S5;
end;
procedure TAddressForm.FromAddressFormat(S: String; var I1: Integer; var S1, S2, S3, S4, S5: String);
var
I: Integer;
begin
I := Pos(',', S);
I1 := 0;
try
I1 := StrToInt(Copy(S, 1, I-1));
except end;
Delete(S, 1, I);
I := Pos(',', S);
S1 := Copy(S, 1, I-1);
Delete(S, 1, I);
I := Pos(',', S);
S2 := Copy(S, 1, I-1);
Delete(S, 1, I);
I := Pos(',', S);
S3 := Copy(S, 1, I-1);
Delete(S, 1, I);
I := Pos(',', S);
S4 := Copy(S, 1, I-1);
Delete(S, 1, I);
S5 := S;
end;
function TAddressForm.SetAddress(S: String): Boolean;
begin
if Combobox1.Items.Count = 0 then begin
MessageDlg(MainForm.ListBox1.Items[39], mtwarning, [mbOK], 0);
Result := False;
Exit;
end;
EditAdrForm := TEditAdrForm.Create(Self);
EditAdrForm.CheckUnique := True;
EditAdrForm.Caption := MainForm.ListBox1.Items[40];
EditAdrForm.ComboboxEx1.ItemIndex := 0;
EditAdrForm.ComboBox1.ItemIndex := Combobox1.ItemIndex;
EditAdrForm.Edit5.Text := ExtractEMailName(S);
EditAdrForm.Edit2.Text := ExtractEMailAddress(S);
if EditAdrForm.ShowModal = mrOK then begin
SaveAddressBook;
AssignFile(F, EditAdrForm.Combobox1.Values[EditAdrForm.Combobox1.ItemIndex]);
Append(F);
S := ToAddressFormat(EditAdrForm.ComboboxEx1.ItemIndex, EditAdrForm.Edit5.Text, EditAdrForm.Edit1.Text, EditAdrForm.Edit2.Text, EditAdrForm.Edit3.Text, EditAdrForm.Edit4.Text);
WriteLn(F, S);
CloseFile(F);
LoadAddressBook;
end;
EditAdrForm.Free;
Result := True;
end;
function TAddressForm.GetSelAddresses: String;
var
SL: TStringList;
I: Integer;
begin
SL := TStringList.Create;
for I := 0 to ListView1.Items.Count-1 do
if ListView1.Items[I].Selected then
SL.Add(ListView1.Items[I].SubItems[0]+' <'+ListView1.Items[I].SubItems[2]+'>');
Result := StringListToCommataString(SL, False);
SL.Free;
end;
procedure TAddressForm.LoadAddressBook;
var
Item: TListItem;
S, S1, S2, S3, S4, S5: String;
I1: Integer;
begin
if Filename = '' then Exit;
if FileExists(Filename) = False then Exit;
ListView1.BeginUpdate;
ListView1.Items.Clear;
AssignFile(F, Filename);
Reset(F);
ReadLn(F, S);
ReadLn(F, S); //two empty lines
while not EoF(F) do begin
ReadLn(F, S);
FromAddressFormat(S, I1, S1, S2, S3, S4, S5);
Item := ListView1.Items.Add;
Item.ImageIndex := I1;
Item.SubItems.Add(S1);
Item.SubItems.Add(S2);
Item.SubItems.Add(S3);
Item.SubItems.Add(S4);
Item.SubItems.Add(S5);
end;
CloseFile(F);
ListView1.Resort;
ListView1.EndUpdate;
end;
procedure TAddressForm.SaveAddressBook;
var
I: Integer;
S: String;
begin
if Filename = '' then Exit;
AssignFile(F, Filename);
Rewrite(F);
WriteLn(F, 'Phoenix Mail - Copyright 1998-99 Michael Haller');
WriteLn(F, 'Type,Description,Name,E-Mail,Phone,Address');
for I := 0 to ListView1.Items.Count-1 do begin
S := ToAddressFormat(ListView1.Items[I].ImageIndex, ListView1.Items[I].SubItems[0], ListView1.Items[I].SubItems[1], ListView1.Items[I].SubItems[2], ListView1.Items[I].SubItems[3], ListView1.Items[I].SubItems[4]);
WriteLn(F, S);
end;
CloseFile(F);
end;
procedure TAddressForm.SetMenusEnable;
begin
if Filename = '' then begin
ListView1.Items.Clear;
ListView1.Enabled := False;
Delete2.Enabled := False;
Address1.Enabled := False;
Rename1.Enabled := False;
SpeedButton1.Enabled := False;
SpeedButton6.Enabled := False;
end else begin
Rename1.Enabled := True;
ListView1.Enabled := True;
Delete2.Enabled := True;
Address1.Enabled := True;
SpeedButton1.Enabled := True;
SpeedButton6.Enabled := True;
end;
if (ListView1.Selected <> nil) and (Filename <> '') then begin
Delete1.Enabled := True;
Edit1.Enabled := True;
DeleteAddress1.Enabled := True;
MailToAddresses1.Enabled := True;
MailToAddresses2.Enabled := True;
SpeedButton4.Enabled := True;
SpeedButton5.Enabled := True;
if Combobox1.Items.Count > 1 then begin
SpeedButton10.Enabled := True;
Movetoanotherbook1.Enabled := True;
end;
end else begin
Delete1.Enabled := False;
Edit1.Enabled := False;
DeleteAddress1.Enabled := False;
MailToAddresses1.Enabled := False;
MailToAddresses2.Enabled := False;
SpeedButton4.Enabled := False;
SpeedButton5.Enabled := False;
Movetoanotherbook1.Enabled := False;
SpeedButton10.Enabled := False;
end;
if (Filename <> '') and (ListView1.SelCount = 1) and (ListView1.Selected <> nil) then begin
SpeedButton3.Enabled := True;
EditAddress1.Enabled := True;
end else begin
SpeedButton3.Enabled := False;
EditAddress1.Enabled := False;
end;
SetStatusBar;
end;
procedure TAddressForm.New1Click(Sender: TObject);
var
S: String;
begin
EditAdrForm := TEditAdrForm.Create(Self);
EditAdrForm.CheckUnique := True;
EditAdrForm.Caption := MainForm.ListBox1.Items[40];
EditAdrForm.ComboBox1.ItemIndex := Combobox1.ItemIndex;
EditAdrForm.ComboBoxEx1.ItemIndex := 0;
if EditAdrForm.ShowModal = mrOK then begin
SaveAddressBook;
AssignFile(F, EditAdrForm.Combobox1.Values[EditAdrForm.Combobox1.ItemIndex]);
Append(F);
S := ToAddressFormat(EditAdrForm.ComboBoxEx1.ItemIndex, EditAdrForm.Edit5.Text, EditAdrForm.Edit1.Text, EditAdrForm.Edit2.Text, EditAdrForm.Edit3.Text, EditAdrForm.Edit4.Text);
WriteLn(F, S);
CloseFile(F);
LoadAddressBook;
end;
EditAdrForm.Free;
ListView1.Resort;
end;
procedure TAddressForm.FormShow(Sender: TObject);
var
I: Integer;
begin
ListView1.Selected := nil;
for I := 0 to ListView1.Items.Count-1 do ListView1.Items[I].Selected := False;
SetMenusEnable;
MailOK := False;
if bFlatButtons then begin
Set3DButtons(True, Self);
Bevel2.Visible := True; Bevel3.Visible := True;
Bevel4.Visible := True; Bevel5.Visible := True;
end else begin
Set3DButtons(False, Self);
Bevel2.Visible := False; Bevel3.Visible := False;
Bevel4.Visible := False; Bevel5.Visible := False;
end;
end;
procedure TAddressForm.Edit1Click(Sender: TObject);
var
Item: TListItem;
begin
Item := ListView1.Selected;
if Item = nil then Exit;
EditAdrForm := TEditAdrForm.Create(Self);
EditAdrForm.CheckUnique := False;
EditAdrForm.ComboBox1.Enabled := False;
EditAdrForm.ComboBox1.ItemIndex := Combobox1.ItemIndex;
EditAdrForm.Label5.Enabled := False;
EditAdrForm.ComboboxEx1.ItemIndex := Item.ImageIndex;
EditAdrForm.Edit5.Text := Item.SubItems[0];
EditAdrForm.Edit1.Text := Item.SubItems[1];
EditAdrForm.Edit2.Text := Item.SubItems[2];
EditAdrForm.Edit3.Text := Item.SubItems[3];
EditAdrForm.Edit4.Text := Item.SubItems[4];
if EditAdrForm.ShowModal = mrOK then begin
Item.ImageIndex := EditAdrForm.ComboboxEx1.ItemIndex;
Item.SubItems[0] := EditAdrForm.Edit5.Text;
Item.SubItems[1] := EditAdrForm.Edit1.Text;
Item.SubItems[2] := EditAdrForm.Edit2.Text;
Item.SubItems[3] := EditAdrForm.Edit3.Text;
Item.SubItems[4] := EditAdrForm.Edit4.Text;
end;
EditAdrForm.Free;
end;
procedure TAddressForm.Delete1Click(Sender: TObject);
var
I: Integer;
label Jump1;
begin
Jump1:
for I := 0 to ListView1.Items.Count-1 do
if ListView1.Items[I].Selected then
if MessageDlg(Format(MainForm.ListBox1.Items[41], [ListView1.Items[I].SubItems[0]]), mtWarning, [mbYes, mbNo], 0) = mrYes then begin
ListView1.Items[I].Delete;
GoTo Jump1;
end;
end;
procedure TAddressForm.Close1Click(Sender: TObject);
begin
Close;
end;
procedure TAddressForm.ListView1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Ord(Key) = 46 then Delete1Click(Self);
end;
procedure TAddressForm.MailtoAddresses1Click(Sender: TObject);
begin
if ListView1.Selected = nil then Exit;
MailOK := True;
Close;
end;
procedure TAddressForm.FormCreate(Sender: TObject);
var
Found: Integer;
SearchRec: TSearchRec;
IniFile: TIniFile;
begin
ImageList1.ResourceLoad(rtBitmap, 'PX502', clFuchsia);
if bOfficeFonts then Font.Name := sOfficeFontName;
if bFlatButtons = False then begin
Set3DButtons(False, Self);
Bevel2.Visible := False;
Bevel3.Visible := False;
Bevel4.Visible := False;
Bevel5.Visible := False;
end;
Filename := '';
Found := FindFirst(sAddressBookFolder+'*.csv', faAnyFile, SearchRec);
while Found = 0 do begin
SetFileAttr(sAddressBookFolder+SearchRec.Name, False, True, False, False);
ComboBox1.Values.Add(sAddressBookFolder+SearchRec.Name);
Delete(SearchRec.Name, Length(SearchRec.Name)-3, 4);
Combobox1.Items.Add(SearchRec.Name);
ComboBox1.ImgIndexes.Add('5');
Found := FindNext(SearchRec);
Combobox1.ItemIndex := 0;
Filename := Combobox1.Values[0];
end;
FindClose(SearchRec);
// Form Position
IniFile := TIniFile.Create(sSettingsFile);
case IniFile.ReadInteger('Position', 'AddressState', 1) of
0, 1: begin
WindowState := wsNormal;
Width := IniFile.ReadInteger('Position', 'AddressWidth', Width);
Height := IniFile.ReadInteger('Position', 'AddressHeight', Height);
Top := IniFile.ReadInteger('Position', 'AddressTop', Top);
Left := IniFile.ReadInteger('Position', 'AddressLeft', Left);
end;
2: WindowState := wsMaximized;
end;
// ListView Order/Position
if MainForm.CheckBox1.Checked then begin
ListView1.AutoSortStyle := assSmart;
end;
ListView1.ReadSettingsFromIniFile('AddressList', IniFile);
LoadAddressBook;
SetMenusEnable;
AttachLanguageToForm(Self);
IniFile.Free;
end;
procedure TAddressForm.Search1Click(Sender: TObject);
begin
SearchForm := TSearchForm.Create(Self);
SearchForm.Method := 1;
SearchForm.ShowModal;
SearchForm.Free;
end;
procedure TAddressForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveAddressBook;
if MailOK then ModalResult := mrOK else ModalResult := mrCancel;
end;
procedure TAddressForm.New2Click(Sender: TObject);
var
S: String;
I: Integer;
begin
if InputQuery(MainForm.ListBox1.Items[42], MainForm.ListBox1.Items[43], S) then begin
for I := 1 to Length(S) do
if S[I] in ['\','/','<','>',':','?','*','"','|',#19] then begin
MessageDlg(MainForm.ListBox1.Items[44], mtError, [mbOK], 0);
Exit;
end;
SaveAddressBook;
Filename := sAddressBookFolder+S+'.csv';
ComboBox1.ImgIndexes.Add('5');
ComboBox1.Items.Add(S);
ComboBox1.Values.Add(sAddressBookFolder+S+'.csv');
ComboBox1.ItemIndex := Combobox1.Items.Count-1;
AssignFile(F, Filename);
Rewrite(F);
CloseFile(F);
LoadAddressBook;
SetMenusEnable;
end;
end;
procedure TAddressForm.Delete2Click(Sender: TObject);
var
I: Integer;
begin
if Filename = '' then Exit;
if MessageDlg(Format(MainForm.ListBox1.Items[45], [Combobox1.Items[ComboBox1.ItemIndex]]), mtWarning, [mbYes,mbNo],0) = mrYes then
if MessageDlg(Format(MainForm.ListBox1.Items[46], [Combobox1.Items[ComboBox1.ItemIndex]]), mtWarning, [mbYes,mbNo],0) = mrYes then begin
DeleteFile(Filename);
I := Combobox1.ItemIndex;
Filename := '';
ComboBox1.Items.Delete(I);
ComboBox1.Values.Delete(I);
ComboBox1.ImgIndexes.Delete(I);
if Combobox1.Items.Count = 0 then begin
Filename := '';
end else begin
ComboBox1.ItemIndex := 0;
Filename := ComboBox1.Values[ComboBox1.ItemIndex];
end;
Combobox1.Invalidate;
LoadAddressBook;
SetMenusEnable;
end;
end;
procedure TAddressForm.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.ItemIndex = -1 then begin
Filename := '';
Exit;
end;
SaveAddressBook;
Filename := ComboBox1.Values[ComboBox1.ItemIndex];
LoadAddressBook;
SetMenusEnable;
end;
procedure TAddressForm.SelectAllAddresses1Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to ListView1.Items.Count-1 do
ListView1.Items[I].Selected := True;
SetMenusEnable;
end;
procedure TAddressForm.Rename1Click(Sender: TObject);
var
S: String;
I, E: Integer;
begin
I := ComboBox1.ItemIndex;
if I = -1 then Exit;
SaveAddressBook;
S := ComboBox1.Items[I];
if InputQuery(MainForm.ListBox1.Items[47], MainForm.ListBox1.Items[43], S) then begin
for E := 1 to Length(S) do
if S[E] in ['\','/','<','>',':','?','*','"','|',#19] then begin
MessageDlg(MainForm.ListBox1.Items[44], mtError, [mbOK], 0);
Exit;
end;
RenameFile(Filename, sAddressBookFolder+S+'.csv');
Filename := sAddressBookFolder+S+'.csv';
ComboBox1.Items[I] := S;
ComboBox1.Values[I] := sAddressBookFolder+S+'.csv';
ComboBox1.ItemIndex := I;
ComboBox1.Invalidate;
end;
end;
procedure TAddressForm.Movetoanotherbook1Click(Sender: TObject);
var
S: String;
I, E: Integer;
begin
SelBookForm := TSelBookForm.Create(Self);
if SelBookForm.ShowModal = mrOK then begin
S := SelBookForm.Combobox1.Values[SelBookForm.ComboBox1.ItemIndex];
AssignFile(F, S);
Append(F);
E := ListView1.Items.Count-1;
I := 0;
while I <= E do begin
if ListView1.Items[I].Selected then begin
S := ToAddressFormat(ListView1.Items[I].ImageIndex, ListView1.Items[I].SubItems[0], ListView1.Items[I].SubItems[1], ListView1.Items[I].SubItems[2], ListView1.Items[I].SubItems[3], ListView1.Items[I].SubItems[4]);
WriteLn(F, S);
ListView1.Items[I].Delete;
Dec(E); Dec(I);
end;
Inc(I);
end;
CloseFile(F);
end;
SelBookForm.Free;
end;
procedure TAddressForm.PopupMenu1Popup(Sender: TObject);
begin
SetMenusEnable;
end;
procedure TAddressForm.FormDestroy(Sender: TObject);
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create(sSettingsFile);
// ListView
ListView1.WriteSettingsToIniFile('AddressList', IniFile);
// Form Position
if WindowState = wsNormal then begin
IniFile.WriteInteger('Position', 'AddressState', 1);
IniFile.WriteInteger('Position', 'AddressWidth', Width);
IniFile.WriteInteger('Position', 'AddressHeight', Height);
IniFile.WriteInteger('Position', 'AddressTop', Top);
IniFile.WriteInteger('Position', 'AddressLeft', Left);
end;
if WindowState = wsMaximized then IniFile.WriteInteger('Position', 'AddressState', 2);
IniFile.Free;
end;
procedure TAddressForm.ListView1DrawHeader(Control: TWinControl;
var ACanvas: TCanvas; Index: Integer; var ARect: TRect;
Selected: Boolean; var DefaultDrawing: Boolean);
begin
if Index = 0 then begin
DefaultDrawing := False;
ACanvas.BrushCopy(Rect(ARect.Left+2, ARect.Top, ARect.Left+18, ARect.Top+16), Image1.Picture.Bitmap, Rect(0, 0, 16, 16), clFuchsia);
end else
DefaultDrawing := True;
end;
procedure TAddressForm.ListView1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
SetMenusEnable;
SetStatusBar;
end;
procedure TAddressForm.Contents1Click(Sender: TObject);
begin
Application.HelpContext(9);
end;
end.