source: trunk/Forms/FormCompare.pas

Last change on this file was 181, checked in by chronos, 3 months ago
  • Added: Windows installer for version 1.5.0.
  • Modified: Version 1.5.0 related updates.
  • Modified: Trunk pushed to 1.6.0 alfa version.
File size: 5.5 KB
Line 
1unit FormCompare;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, DataFile,
7 VCardFile, VCard, Common, RegistryEx, FormEx;
8
9type
10
11 { TFormCompare }
12
13 TFormCompare = class(TFormEx)
14 ButtonBrowse: TButton;
15 ButtonCancel: TButton;
16 ButtonCompare: TButton;
17 CheckBoxNormalizePhoneNumbers: TCheckBox;
18 CheckBoxRemoveExactDuplicates: TCheckBox;
19 CheckBoxSortContacts: TCheckBox;
20 CheckBoxWithoutPhotos: TCheckBox;
21 EditAnotherFile: TEdit;
22 Label1: TLabel;
23 OpenDialog1: TOpenDialog;
24 ScrollBox1: TScrollBox;
25 procedure ButtonBrowseClick(Sender: TObject);
26 procedure ButtonCompareClick(Sender: TObject);
27 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
28 procedure FormCreate(Sender: TObject);
29 procedure FormDestroy(Sender: TObject);
30 procedure FormShow(Sender: TObject);
31 private
32 LeftVCard: TVCardFile;
33 RightVCard: TVCardFile;
34 procedure CompareInternal;
35 procedure CompareExternal;
36 procedure LoadConfig;
37 procedure SaveConfig;
38 end;
39
40
41implementation
42
43{$R *.lfm}
44
45uses
46 Core, FormCompareSideBySide, VCardProcessor;
47
48resourcestring
49 SCompareToolNotFound = 'Compare tool ''%s'' not found. Select valid compare tool in the application settings.';
50
51{ TFormCompare }
52
53procedure TFormCompare.FormCreate(Sender: TObject);
54begin
55 LeftVCard := TVCardFile.Create(nil);
56 RightVCard := TVCardFile.Create(nil);
57end;
58
59procedure TFormCompare.FormDestroy(Sender: TObject);
60begin
61 FreeAndNil(LeftVCard);
62 FreeAndNil(RightVCard);
63end;
64
65procedure TFormCompare.FormClose(Sender: TObject; var CloseAction: TCloseAction
66 );
67begin
68 SaveConfig;
69end;
70
71procedure TFormCompare.ButtonCompareClick(Sender: TObject);
72var
73 VCardProcessor: TVCardProcessor;
74begin
75 LeftVCard.Assign(TVCardFile(Core.Core.DataFile));
76 RightVCard.LoadFromFile(EditAnotherFile.Text);
77
78 VCardProcessor := TVCardProcessor.Create(nil);
79 with VCardProcessor do
80 try
81 DefaultPhoneCountryCode := Core.Core.DefaultPhoneCountryCode;
82 RemovePhotos := CheckBoxWithoutPhotos.Checked;
83 RemovePhoneSpaces := CheckBoxNormalizePhoneNumbers.Checked;
84 AddDefaultPhoneCountryPrefix := CheckBoxNormalizePhoneNumbers.Checked;
85 RemoveExactDuplicates := CheckBoxRemoveExactDuplicates.Checked;
86 Order := CheckBoxSortContacts.Checked;
87 Process(LeftVCard.VCard);
88 Process(RightVCard.VCard);
89 finally
90 Free;
91 end;
92
93 CompareExternal;
94end;
95
96procedure TFormCompare.ButtonBrowseClick(Sender: TObject);
97var
98 TempFile: TDataFile;
99begin
100 TempFile := Core.Core.DefaultDataFileClass.Create(nil);
101 try
102 OpenDialog1.Filter := TempFile.GetFileFilter;
103 finally
104 TempFile.Free;
105 end;
106
107 OpenDialog1.DefaultExt := '';
108 OpenDialog1.InitialDir := ExtractFileDir(EditAnotherFile.Text);
109 OpenDialog1.FileName := ExtractFileName(EditAnotherFile.Text);
110 OpenDialog1.Options := OpenDialog1.Options - [ofAllowMultiSelect];
111 if OpenDialog1.Execute then begin
112 EditAnotherFile.Text := OpenDialog1.FileName;
113 end;
114end;
115
116procedure TFormCompare.FormShow(Sender: TObject);
117begin
118 LoadConfig;
119end;
120
121procedure TFormCompare.CompareInternal;
122var
123 TempFileName: string;
124begin
125 with TFormCompareSideBySide.Create(nil) do
126 try
127 TempFileName := Core.Core.GetTempDir +
128 DirectorySeparator + 'Compare' + VCardFileExt;
129 ForceDirectories(ExtractFileDir(TempFileName));
130 TVCardFile(Core.Core.DataFile).SaveToFile(TempFileName);
131 LoadFileLeft(TempFileName);
132 LoadFileRight(EditAnotherFile.Text);
133 ShowModal;
134 finally
135 Free;
136 end;
137end;
138
139procedure CompareText(TextLeft, TextRight: string; FileNameLeft: string = 'FileLeft.txt';
140 FileNameRight: string = 'FileRight.txt');
141var
142 TempFileRight: string;
143 TempFileLeft: string;
144begin
145 if not DirectoryExists(Core.Core.GetTempDir) then
146 CreateDir(Core.Core.GetTempDir);
147 TempFileLeft := Core.Core.GetTempDir + DirectorySeparator + FileNameLeft;
148 TempFileRight := Core.Core.GetTempDir + DirectorySeparator + FileNameRight;
149 SaveStringToFile(TextLeft, TempFileLeft);
150 SaveStringToFile(TextRight, TempFileRight);
151 if FileExists(Core.Core.CompareTool) then
152 ExecuteProgram(Core.Core.CompareTool, [TempFileLeft, TempFileRight], [])
153 else ShowMessage(Format(SCompareToolNotFound, [Core.Core.CompareTool]));
154end;
155
156procedure TFormCompare.CompareExternal;
157begin
158 CompareText(LeftVCard.VCard.AsString, RightVCard.VCard.AsString,
159 ExtractFileName(LeftVCard.FileName), ExtractFileName(EditAnotherFile.Text));
160end;
161
162procedure TFormCompare.LoadConfig;
163begin
164 with TRegistryEx.Create do
165 try
166 CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
167 EditAnotherFile.Text := ReadStringWithDefault('LastCompareFileName', '');
168 CheckBoxWithoutPhotos.Checked := ReadBoolWithDefault('WithoutPhotos', True);
169 CheckBoxSortContacts.Checked := ReadBoolWithDefault('SortContacts', True);
170 CheckBoxNormalizePhoneNumbers.Checked := ReadBoolWithDefault('NormalizePhoneNumbers', True);
171 CheckBoxRemoveExactDuplicates.Checked := ReadBoolWithDefault('RemoveExactDuplicates', True);
172 finally
173 Free;
174 end;
175end;
176
177procedure TFormCompare.SaveConfig;
178begin
179 with TRegistryEx.Create do
180 try
181 CurrentContext := Core.Core.ApplicationInfo1.GetRegistryContext;
182 WriteString('LastCompareFileName', EditAnotherFile.Text);
183 WriteBool('WithoutPhotos', CheckBoxWithoutPhotos.Checked);
184 WriteBool('SortContacts', CheckBoxSortContacts.Checked);
185 WriteBool('NormalizePhoneNumbers', CheckBoxNormalizePhoneNumbers.Checked);
186 WriteBool('RemoveExactDuplicates', CheckBoxRemoveExactDuplicates.Checked);
187 finally
188 Free;
189 end;
190end;
191
192end.
193
Note: See TracBrowser for help on using the repository browser.