Ignore:
Timestamp:
Jun 6, 2023, 5:05:18 PM (12 months ago)
Author:
chronos
Message:
  • Added: VCardProcessor class for processing contacts available from VCard package.
  • Added: Normalize menu action for normalization of contact property values.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/FormCompare.pas

    r151 r152  
    3434    procedure CompareExternal;
    3535    procedure LoadConfig;
    36     procedure RemoveExactDuplicates(Contacts: TContacts);
    37     procedure NormalizePhoneNumbers(Contacts: TContacts);
    38     procedure RemovePhotos(Contacts: TContacts);
    3936    procedure SaveConfig;
    4037  end;
     
    4643
    4744uses
    48   Core, FormCompareSideBySide;
     45  Core, FormCompareSideBySide, VCardProcessor;
    4946
    5047{ TFormCompare }
     
    7269
    7370procedure TFormCompare.ButtonCompareClick(Sender: TObject);
     71var
     72  VCardProcessor: TVCardProcessor;
    7473begin
    7574  LeftVCard.Assign(TVCardFile(Core.Core.DataFile));
    7675  RightVCard.LoadFromFile(EditAnotherFile.Text);
    7776
    78   if CheckBoxSortContacts.Checked then begin
    79     LeftVCard.VCard.Contacts.Sort;
    80     RightVCard.VCard.Contacts.Sort;
     77  VCardProcessor := TVCardProcessor.Create(nil);
     78  with VCardProcessor do
     79  try
     80    DefaultPhoneCountryCode := Core.Core.DefaultPhoneCountryCode;
     81    RemovePhotos := CheckBoxWithoutPhotos.Checked;
     82    RemovePhoneSpaces := CheckBoxNormalizePhoneNumbers.Checked;
     83    AddDefaultPhoneCountryPrefix := CheckBoxNormalizePhoneNumbers.Checked;
     84    RemoveExactDuplicates := CheckBoxRemoveExactDuplicates.Checked;
     85    Order := CheckBoxSortContacts.Checked;
     86  finally
     87    Free;
    8188  end;
    8289
    83   if CheckBoxWithoutPhotos.Checked then begin
    84     RemovePhotos(LeftVCard.VCard.Contacts);
    85     RemovePhotos(RightVCard.VCard.Contacts);
    86   end;
    87 
    88   if CheckBoxNormalizePhoneNumbers.Checked then begin
    89     NormalizePhoneNumbers(LeftVCard.VCard.Contacts);
    90     NormalizePhoneNumbers(RightVCard.VCard.Contacts);
    91   end;
    92 
    93   if CheckBoxRemoveExactDuplicates.Checked then begin
    94     RemoveExactDuplicates(LeftVCard.VCard.Contacts);
    95     RemoveExactDuplicates(RightVCard.VCard.Contacts);
    96   end;
     90  LeftVCard.VCard.Contacts.Sort;
     91  RightVCard.VCard.Contacts.Sort;
    9792
    9893  CompareExternal;
    99 end;
    100 
    101 procedure TFormCompare.RemovePhotos(Contacts: TContacts);
    102 var
    103   I: Integer;
    104   J: Integer;
    105   ContactProperties: TContactProperties;
    106 begin
    107   for I := 0 to Contacts.Count - 1 do
    108   with Contacts[I].Properties do begin
    109     ContactProperties := GetMultipleByName('PHOTO');
    110     for J := ContactProperties.Count - 1 downto 0 do
    111       Remove(ContactProperties[J]);
    112     ContactProperties.Free;
    113   end;
    114 end;
    115 
    116 procedure TFormCompare.NormalizePhoneNumbers(Contacts: TContacts);
    117 var
    118   I: Integer;
    119   J: Integer;
    120   ContactProperties: TContactProperties;
    121 begin
    122   for I := 0 to Contacts.Count - 1 do
    123   with Contacts[I].Properties do begin
    124     ContactProperties := GetMultipleByName('TEL');
    125     for J := 0 to ContactProperties.Count - 1 do begin
    126       ContactProperties[J].Value := StringReplace(ContactProperties[J].Value, ' ', '', [rfReplaceAll]);
    127       if not ContactProperties[J].Value.StartsWith('+') then
    128         ContactProperties[J].Value := Core.Core.DefaultPhoneCountryPrefix + ContactProperties[J].Value;
    129     end;
    130     ContactProperties.Free;
    131   end;
    13294end;
    13395
     
    212174end;
    213175
    214 procedure TFormCompare.RemoveExactDuplicates(Contacts: TContacts);
    215 var
    216   I: Integer;
    217 begin
    218   Contacts.RemoveExactDuplicates;
    219   for I := 0 to Contacts.Count - 1 do
    220     Contacts[I].Properties.RemoveExactDuplicates;
    221 end;
    222 
    223176procedure TFormCompare.SaveConfig;
    224177begin
Note: See TracChangeset for help on using the changeset viewer.