Changeset 152 for trunk


Ignore:
Timestamp:
Jun 6, 2023, 5:05:18 PM (19 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.
Location:
trunk
Files:
4 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Core.lfm

    r149 r152  
    296296      Caption = 'Remove exact duplicates'
    297297      OnExecute = ARemoveExactDuplicatesExecute
     298    end
     299    object ANormalize: TAction
     300      Caption = 'Normalize'
     301      OnExecute = ANormalizeExecute
    298302    end
    299303  end
  • trunk/Core.lrj

    r149 r152  
    1919{"hash":109897550,"name":"tcore.afilecompare.caption","sourcebytes":[67,111,109,112,97,114,101,46,46,46],"value":"Compare..."},
    2020{"hash":78724163,"name":"tcore.aremoveexactduplicates.caption","sourcebytes":[82,101,109,111,118,101,32,101,120,97,99,116,32,100,117,112,108,105,99,97,116,101,115],"value":"Remove exact duplicates"},
     21{"hash":154699365,"name":"tcore.anormalize.caption","sourcebytes":[78,111,114,109,97,108,105,122,101],"value":"Normalize"},
    2122{"hash":218146437,"name":"tcore.opendialog1.title","sourcebytes":[79,112,101,110,32,101,120,105,115,116,105,110,103,32,102,105,108,101],"value":"Open existing file"},
    2223{"hash":159035875,"name":"tcore.savedialog1.title","sourcebytes":[83,97,118,101,32,102,105,108,101,32,97,115],"value":"Save file as"},
  • trunk/Core.pas

    r151 r152  
    1616    AAbout: TAction;
    1717    AboutDialog1: TAboutDialog;
     18    ANormalize: TAction;
    1819    ARemoveExactDuplicates: TAction;
    1920    AFileCompare: TAction;
     
    6061    procedure AGenerateExecute(Sender: TObject);
    6162    procedure AHomePageExecute(Sender: TObject);
     63    procedure ANormalizeExecute(Sender: TObject);
    6264    procedure ARemoveExactDuplicatesExecute(Sender: TObject);
    6365    procedure ASettingsExecute(Sender: TObject);
     
    102104    ToolbarVisible: Boolean;
    103105    DefaultVcardVersion: string;
    104     DefaultPhoneCountryPrefix: string;
     106    DefaultPhoneCountryCode: string;
     107    DefaultInternationalCallPrefix: string;
    105108    CompareTool: string;
    106109    function GetProfileImage: TImage;
     
    126129
    127130uses
    128   FormMain, FormSettings, FormFindDuplicity, FormCompare, TestCase,
     131  FormMain, FormSettings, FormFindDuplicity, FormCompare, TestCase, FormNormalize,
    129132  FormGenerate, FormError, FormFind, FormTest, FormSource, FormCompareSideBySide,
    130133  TestCases;
     
    285288end;
    286289
     290procedure TCore.ANormalizeExecute(Sender: TObject);
     291var
     292  FormNormalize: TFormNormalize;
     293begin
     294  FormNormalize := TFormNormalize.Create(nil);
     295  try
     296    FormNormalize.ShowModal;
     297  finally
     298    FreeAndNil(FormNormalize);
     299  end;
     300end;
     301
    287302procedure TCore.ARemoveExactDuplicatesExecute(Sender: TObject);
    288303var
     
    540555    LastQrCodeFileName := ReadStringWithDefault('LastQrCodeFileName', '');
    541556    CompareTool := ReadStringWithDefault('CompareTool', GetDefaultCompareTool);
    542     DefaultPhoneCountryPrefix := ReadStringWithDefault('DefaultPhoneCountryPrefix', DefaultPhoneCountryPrefix);
     557    DefaultPhoneCountryCode := ReadStringWithDefault('DefaultPhoneCountryPrefix', DefaultPhoneCountryCode);
     558    DefaultInternationalCallPrefix := ReadStringWithDefault('DefaultInternationalCallPrefix', DefaultInternationalCallPrefix);
    543559  finally
    544560    Free;
     
    568584    WriteString('LastQrCodeFileName', LastQrCodeFileName);
    569585    WriteString('CompareTool', CompareTool);
    570     WriteString('DefaultPhoneCountryPrefix', DefaultPhoneCountryPrefix);
     586    WriteString('DefaultPhoneCountryPrefix', DefaultPhoneCountryCode);
     587    WriteString('DefaultInternationalCallPrefix', DefaultInternationalCallPrefix);
    571588  finally
    572589    Free;
  • 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
  • trunk/Forms/FormFindDuplicity.lfm

    r149 r152  
    1212  OnDestroy = FormDestroy
    1313  OnShow = FormShow
    14   LCLVersion = '2.2.0.4'
     14  LCLVersion = '2.2.6.0'
    1515  object ListView1: TListView
    1616    Left = 5
     
    5555    TabOrder = 1
    5656    object ComboBoxField: TComboBox
    57       Left = 160
    58       Height = 41
    59       Top = 16
     57      Left = 192
     58      Height = 42
     59      Top = 14
    6060      Width = 326
    6161      ItemHeight = 0
     
    7171      Width = 135
    7272      Caption = 'By contact field:'
     73      ParentColor = False
    7374      ParentFont = False
    7475    end
    7576    object ButtonMerge: TButton
    76       Left = 496
     77      Left = 528
    7778      Height = 38
    7879      Top = 14
  • trunk/Forms/FormFindDuplicity.pas

    r149 r152  
    55uses
    66  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    7   ExtCtrls, StdCtrls, ActnList, Menus, VCard, Generics.Collections,
     7  ExtCtrls, StdCtrls, ActnList, Menus, VCard, Generics.Collections, RegistryEx,
    88  Generics.Defaults;
    99
     
    189189    Form.Contacts := TContacts.Create(False);
    190190    Form.Contacts.ParentVCard := Contacts.ParentVCard;
     191    Form.Context := TRegistryContext.Create(Core.Core.ApplicationInfo1.RegistryRoot,
     192      Core.Core.ApplicationInfo1.RegistryKey + '\ContactsColumns');
    191193    with TFoundItem(ListView1.Selected.Data) do
    192194      for I := 0 to Contacts.Count - 1 do
  • trunk/Forms/FormMain.lfm

    r149 r152  
    190190        Caption = '-'
    191191      end
     192      object MenuItem14: TMenuItem
     193        Action = Core.ANormalize
     194      end
    192195      object MenuItem13: TMenuItem
    193196        Action = Core.ARemoveExactDuplicates
  • trunk/Forms/FormMain.pas

    r150 r152  
    1919    MenuItem12: TMenuItem;
    2020    MenuItem13: TMenuItem;
     21    MenuItem14: TMenuItem;
    2122    MenuItemColumns: TMenuItem;
    2223    MenuItem3: TMenuItem;
  • trunk/Forms/FormSettings.lfm

    r151 r152  
    11object FormSettings: TFormSettings
    22  Left = 798
    3   Height = 521
     3  Height = 613
    44  Top = 204
    55  Width = 857
    66  Caption = 'Settings'
    7   ClientHeight = 521
     7  ClientHeight = 613
    88  ClientWidth = 857
    99  Constraints.MinHeight = 404
     
    1818    Left = 731
    1919    Height = 37
    20     Top = 468
     20    Top = 560
    2121    Width = 113
    2222    Anchors = [akRight, akBottom]
     
    3030    Left = 587
    3131    Height = 37
    32     Top = 468
     32    Top = 560
    3333    Width = 113
    3434    Anchors = [akRight, akBottom]
     
    4040  object ScrollBox1: TScrollBox
    4141    Left = 8
    42     Height = 448
     42    Height = 540
    4343    Top = 8
    4444    Width = 845
    4545    HorzScrollBar.Page = 504
    46     VertScrollBar.Page = 427
     46    VertScrollBar.Page = 475
    4747    Anchors = [akTop, akLeft, akRight, akBottom]
    48     ClientHeight = 446
     48    ClientHeight = 538
    4949    ClientWidth = 843
    5050    TabOrder = 2
     
    195195    end
    196196    object EditDefaultPhoneCountryPrefix: TEdit
    197       Left = 296
     197      Left = 312
    198198      Height = 43
    199199      Top = 384
     
    201201      TabOrder = 9
    202202    end
     203    object Label7: TLabel
     204      Left = 23
     205      Height = 26
     206      Top = 440
     207      Width = 267
     208      Caption = 'Default international call prefix:'
     209      ParentColor = False
     210    end
     211    object EditDefaultInternationalCallPrefix: TEdit
     212      Left = 312
     213      Height = 43
     214      Top = 432
     215      Width = 144
     216      TabOrder = 10
     217    end
    203218  end
    204219  object OpenDialog1: TOpenDialog
  • trunk/Forms/FormSettings.lrj

    r151 r152  
    1212{"hash":220155194,"name":"tformsettings.label5.caption","sourcebytes":[67,111,109,112,97,114,101,32,116,111,111,108,58],"value":"Compare tool:"},
    1313{"hash":77164181,"name":"tformsettings.buttonbrowse.caption","sourcebytes":[66,114,111,119,115,101],"value":"Browse"},
    14 {"hash":99356634,"name":"tformsettings.label6.caption","sourcebytes":[68,101,102,97,117,108,116,32,112,104,111,110,101,32,99,111,117,110,116,114,121,32,112,114,101,102,105,120,58],"value":"Default phone country prefix:"}
     14{"hash":99356634,"name":"tformsettings.label6.caption","sourcebytes":[68,101,102,97,117,108,116,32,112,104,111,110,101,32,99,111,117,110,116,114,121,32,112,114,101,102,105,120,58],"value":"Default phone country prefix:"},
     15{"hash":112394474,"name":"tformsettings.label7.caption","sourcebytes":[68,101,102,97,117,108,116,32,105,110,116,101,114,110,97,116,105,111,110,97,108,32,99,97,108,108,32,112,114,101,102,105,120,58],"value":"Default international call prefix:"}
    1516]}
  • trunk/Forms/FormSettings.pas

    r151 r152  
    2020    ComboBoxTheme: TComboBox;
    2121    EditCompareTool: TEdit;
     22    EditDefaultInternationalCallPrefix: TEdit;
    2223    EditDefaultVcardVersion: TEdit;
    2324    EditDefaultPhoneCountryPrefix: TEdit;
     
    2930    Label5: TLabel;
    3031    Label6: TLabel;
     32    Label7: TLabel;
    3133    LabelDPI: TLabel;
    3234    OpenDialog1: TOpenDialog;
     
    119121    EditMapUrl.Text := MapUrl;
    120122    EditCompareTool.Text := CompareTool;
    121     EditDefaultPhoneCountryPrefix.Text := DefaultPhoneCountryPrefix;
     123    EditDefaultPhoneCountryPrefix.Text := DefaultPhoneCountryCode;
     124    EditDefaultInternationalCallPrefix.Text := DefaultInternationalCallPrefix;
    122125  end;
    123126  UpdateInterface;
     
    133136    MapUrl := EditMapUrl.Text;
    134137    CompareTool := EditCompareTool.Text;
    135     DefaultPhoneCountryPrefix := EditDefaultPhoneCountryPrefix.Text;
     138    DefaultPhoneCountryCode := EditDefaultPhoneCountryPrefix.Text;
     139    DefaultInternationalCallPrefix := EditDefaultInternationalCallPrefix.Text;
    136140  end;
    137141end;
  • trunk/Languages/vCardStudio.cs.po

    r151 r152  
    222222msgstr "Domovská stránka"
    223223
     224#: tcore.anormalize.caption
     225msgctxt "tcore.anormalize.caption"
     226msgid "Normalize"
     227msgstr "Normalizovat"
     228
    224229#: tcore.applicationinfo1.description
    225230msgid "vCard files management tool"
     
    329334#: tformcompare.checkboxnormalizephonenumbers.caption
    330335msgid "Normalize phone numbers"
    331 msgstr "Normalizovat telefonní čísla:"
     336msgstr "Normalizovat telefonní čísla"
    332337
    333338#: tformcompare.checkboxremoveexactduplicates.caption
     
    11181123msgstr "Poslední:"
    11191124
     1125#: tformnormalize.buttoncancel.caption
     1126msgctxt "tformnormalize.buttoncancel.caption"
     1127msgid "Cancel"
     1128msgstr "Zrušit"
     1129
     1130#: tformnormalize.buttonprocess.caption
     1131msgid "Process"
     1132msgstr "Zpracovat"
     1133
     1134#: tformnormalize.caption
     1135msgctxt "tformnormalize.caption"
     1136msgid "Normalize"
     1137msgstr "Normalizovat"
     1138
     1139#: tformnormalize.checkboxaddphoneprefix.caption
     1140msgid "Add default country phone prefix"
     1141msgstr "Přidat výchozí telefonní předvolba země"
     1142
     1143#: tformnormalize.checkboxconvertinternationacallprefixtocountrycode.caption
     1144msgid "Convert international call prefix to country code"
     1145msgstr "Převést mezinárodní volací předvolbu na kód země"
     1146
     1147#: tformnormalize.checkboxremoveexactduplicates.caption
     1148msgctxt "tformnormalize.checkboxremoveexactduplicates.caption"
     1149msgid "Remove exact duplicates"
     1150msgstr "Odstranit přesné duplikáty"
     1151
     1152#: tformnormalize.checkboxremovephonespaces.caption
     1153msgid "Remove spaces in phone numbers"
     1154msgstr "Odstranit mezery z telefonních čísel"
     1155
     1156#: tformnormalize.checkboxremovephotos.caption
     1157msgid "Remove photos"
     1158msgstr "Odstranit fotky"
     1159
    11201160#: tformproperties.aadd.caption
    11211161msgctxt "tformproperties.aadd.caption"
     
    12511291msgstr "Výchozí telefonní prefix země:"
    12521292
     1293#: tformsettings.label7.caption
     1294msgid "Default international call prefix:"
     1295msgstr "Výchozí mezinárodní volací předvolba:"
     1296
    12531297#: tformsettings.labeldpi.caption
    12541298msgid "DPI:"
  • trunk/Languages/vCardStudio.pot

    r151 r152  
    212212msgstr ""
    213213
     214#: tcore.anormalize.caption
     215msgctxt "tcore.anormalize.caption"
     216msgid "Normalize"
     217msgstr ""
     218
    214219#: tcore.applicationinfo1.description
    215220msgid "vCard files management tool"
     
    11081113msgstr ""
    11091114
     1115#: tformnormalize.buttoncancel.caption
     1116msgctxt "tformnormalize.buttoncancel.caption"
     1117msgid "Cancel"
     1118msgstr ""
     1119
     1120#: tformnormalize.buttonprocess.caption
     1121msgid "Process"
     1122msgstr ""
     1123
     1124#: tformnormalize.caption
     1125msgctxt "tformnormalize.caption"
     1126msgid "Normalize"
     1127msgstr ""
     1128
     1129#: tformnormalize.checkboxaddphoneprefix.caption
     1130msgid "Add default country phone prefix"
     1131msgstr ""
     1132
     1133#: tformnormalize.checkboxconvertinternationacallprefixtocountrycode.caption
     1134msgid "Convert international call prefix to country code"
     1135msgstr ""
     1136
     1137#: tformnormalize.checkboxremoveexactduplicates.caption
     1138msgctxt "tformnormalize.checkboxremoveexactduplicates.caption"
     1139msgid "Remove exact duplicates"
     1140msgstr ""
     1141
     1142#: tformnormalize.checkboxremovephonespaces.caption
     1143msgid "Remove spaces in phone numbers"
     1144msgstr ""
     1145
     1146#: tformnormalize.checkboxremovephotos.caption
     1147msgid "Remove photos"
     1148msgstr ""
     1149
    11101150#: tformproperties.aadd.caption
    11111151msgctxt "tformproperties.aadd.caption"
     
    12411281msgstr ""
    12421282
     1283#: tformsettings.label7.caption
     1284msgid "Default international call prefix:"
     1285msgstr ""
     1286
    12431287#: tformsettings.labeldpi.caption
    12441288msgid "DPI:"
  • trunk/Languages/vCardStudio.sv.po

    r151 r152  
    223223msgstr "Hemsida"
    224224
     225#: tcore.anormalize.caption
     226msgctxt "tcore.anormalize.caption"
     227msgid "Normalize"
     228msgstr ""
     229
    225230#: tcore.applicationinfo1.description
    226231msgid "vCard files management tool"
     
    11461151msgstr ""
    11471152
     1153#: tformnormalize.buttoncancel.caption
     1154#, fuzzy
     1155msgctxt "tformnormalize.buttoncancel.caption"
     1156msgid "Cancel"
     1157msgstr "Avbryt"
     1158
     1159#: tformnormalize.buttonprocess.caption
     1160msgid "Process"
     1161msgstr ""
     1162
     1163#: tformnormalize.caption
     1164msgctxt "tformnormalize.caption"
     1165msgid "Normalize"
     1166msgstr ""
     1167
     1168#: tformnormalize.checkboxaddphoneprefix.caption
     1169msgid "Add default country phone prefix"
     1170msgstr ""
     1171
     1172#: tformnormalize.checkboxconvertinternationacallprefixtocountrycode.caption
     1173msgid "Convert international call prefix to country code"
     1174msgstr ""
     1175
     1176#: tformnormalize.checkboxremoveexactduplicates.caption
     1177msgctxt "tformnormalize.checkboxremoveexactduplicates.caption"
     1178msgid "Remove exact duplicates"
     1179msgstr ""
     1180
     1181#: tformnormalize.checkboxremovephonespaces.caption
     1182msgid "Remove spaces in phone numbers"
     1183msgstr ""
     1184
     1185#: tformnormalize.checkboxremovephotos.caption
     1186msgid "Remove photos"
     1187msgstr ""
     1188
    11481189#: tformproperties.aadd.caption
    11491190#, fuzzy
     
    12881329msgstr ""
    12891330
     1331#: tformsettings.label7.caption
     1332msgid "Default international call prefix:"
     1333msgstr ""
     1334
    12901335#: tformsettings.labeldpi.caption
    12911336msgid "DPI:"
  • trunk/Packages/VCard/VCard.lpk

    r148 r152  
    5757        <UnitName Value="VCardPackage"/>
    5858      </Item>
     59      <Item>
     60        <Filename Value="VCardProcessor.pas"/>
     61        <UnitName Value="VCardProcessor"/>
     62      </Item>
    5963    </Files>
    6064    <i18n>
  • trunk/Packages/VCard/VCard.pas

    r151 r152  
    12981298var
    12991299  I: Integer;
     1300  ContactProperty: TContactProperty;
    13001301begin
    13011302  inherited Sort(TComparer<TContact>.Construct(CompareContactFullName));
    1302   for I := 0 to Count - 1 do
     1303  for I := 0 to Count - 1 do begin
    13031304    Items[I].Properties.Sort(TComparer<TContactProperty>.Construct(ComparePropertyName));
     1305
     1306    // Make sure VERSION is first property
     1307    ContactProperty := Items[I].Properties.GetByName('VERSION');
     1308    if Assigned(ContactProperty) then begin
     1309      Items[I].Properties.Move(Items[I].Properties.IndexOf(ContactProperty), 0);
     1310    end;
     1311  end;
    13041312end;
    13051313
     
    17911799  LinePrefix: string;
    17921800  CutLength: Integer;
     1801  Cut: Boolean;
    17931802begin
    17941803  with Output do begin
     
    18141823        LineIndex := 0;
    18151824        LinePrefix := '';
     1825        Cut := False;
    18161826        while True do begin
    18171827          if UTF8Length(OutText) > ParentVCard.MaxLineLength then begin
     1828            Cut := True;
    18181829            CutLength := ParentVCard.MaxLineLength;
    18191830            if Encoding = veQuotedPrintable then begin
     
    18371848          end else begin
    18381849            Add(LinePrefix + OutText);
     1850            if Cut then Add('');
    18391851            Break;
    18401852          end;
  • trunk/Packages/VCard/VCardPackage.pas

    r148 r152  
    99
    1010uses
    11   VCard, QuotedPrintable, ContactImage, LazarusPackageIntf;
     11  VCard, QuotedPrintable, ContactImage, VCardProcessor, LazarusPackageIntf;
    1212
    1313implementation
  • trunk/Test.pas

    r149 r152  
    44
    55uses
    6   Classes, SysUtils, VCard, TestCase;
     6  Classes, SysUtils, VCard, VCardProcessor, TestCase;
    77
    88type
     
    2929  end;
    3030
     31  { TTestCaseVCardProcessor }
     32
     33  TTestCaseVCardProcessor = class(TTestCase)
     34    Input: string;
     35    Output: string;
     36    Processor: TVCardProcessor;
     37    procedure Run; override;
     38    constructor Create; override;
     39    destructor Destroy; override;
     40  end;
     41
    3142
    3243implementation
     
    3849  SExpected = 'Expected:';
    3950  SOutput = 'Output:';
     51
     52{ TTestCaseVCardProcessor }
     53
     54procedure TTestCaseVCardProcessor.Run;
     55var
     56  Lines: TStringList;
     57begin
     58  Lines := TStringList.Create;
     59  try
     60    with TVCardFile.Create(nil) do
     61    try
     62      Lines.Text := Input;
     63      VCard.LoadFromStrings(Lines);
     64
     65      Processor.Process(VCard);
     66
     67      Lines.Text := '';
     68      VCard.SaveToStrings(Lines);
     69      Evaluate(Lines.Text = Output);
     70      Log := SExpected + LineEnding +
     71        '"' + Output + '"' + LineEnding + LineEnding +
     72        SOutput + LineEnding +
     73        '"' + Lines.Text + '"';
     74    finally
     75      Free;
     76    end;
     77  finally
     78    Lines.Free;
     79  end;
     80end;
     81
     82constructor TTestCaseVCardProcessor.Create;
     83begin
     84  inherited;
     85  Processor := TVCardProcessor.Create(nil);
     86end;
     87
     88destructor TTestCaseVCardProcessor.Destroy;
     89begin
     90  FreeAndNil(Processor);
     91  inherited;
     92end;
    4093
    4194{ TTestCaseCheckProperty }
  • trunk/TestCases.pas

    r151 r152  
    3939      Input := BeginEnd(
    4040        'NOTE:This is some long test which is really multi-lined each line is on dif' + VCardLineEnding +
    41         ' ferent line so it is on multiple lines.' + VCardLineEnding);
     41        ' ferent line so it is on multiple lines.' + VCardLineEnding +
     42        VCardLineEnding);
    4243      Output := Input;
    4344    end;
     
    5556      Input := BeginEnd(
    5657        'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=ADJm=C3=A9n=' + VCardLineEnding +
    57         'o=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding);
     58        'o=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding +
     59        VCardLineEnding);
    5860      Output := Input;
    5961    end;
     
    7678      Input := BeginEnd(
    7779        'FN;ENCODING=BASE64:U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIFNvbWUgdmVyeSBsb25nIHN0cmlu' + VCardLineEnding +
    78         ' ZyBTb21lIHZlcnkgbG9uZyBzdHJpbmcgU29tZSB2ZXJ5IGxvbmcgc3RyaW5n' + VCardLineEnding);
     80        ' ZyBTb21lIHZlcnkgbG9uZyBzdHJpbmcgU29tZSB2ZXJ5IGxvbmcgc3RyaW5n' + VCardLineEnding +
     81        VCardLineEnding);
    7982      Output := Input;
    8083    end;
     
    182185    end;
    183186
     187    with TTestCaseVCardProcessor(AddNew('VCardProcessor - Remove exact duplicates', TTestCaseVCardProcessor)) do begin
     188      Processor.RemoveExactDuplicates := True;
     189      Input := BeginEnd(
     190        'N:Surname;Name' + VCardLineEnding +
     191        'FN:Name Surname' + VCardLineEnding) +
     192        BeginEnd(
     193        'N:Surname2;Name2' + VCardLineEnding +
     194        'FN:Name2 Surname2' + VCardLineEnding) +
     195        BeginEnd(
     196        'N:Surname;Name' + VCardLineEnding +
     197        'FN:Name Surname' + VCardLineEnding) +
     198        BeginEnd(
     199        'N:Surname;Name' + VCardLineEnding +
     200        'FN:Name Surname' + VCardLineEnding +
     201        'NOTE:Note' + VCardLineEnding) +
     202        BeginEnd(
     203        'N:Surname;Name' + VCardLineEnding +
     204        'FN:Name Surname' + VCardLineEnding);
     205      Output := BeginEnd(
     206        'N:Surname;Name' + VCardLineEnding +
     207        'FN:Name Surname' + VCardLineEnding) +
     208        BeginEnd(
     209        'N:Surname2;Name2' + VCardLineEnding +
     210        'FN:Name2 Surname2' + VCardLineEnding) +
     211        BeginEnd(
     212        'N:Surname;Name' + VCardLineEnding +
     213        'FN:Name Surname' + VCardLineEnding +
     214        'NOTE:Note' + VCardLineEnding);
     215    end;
     216    with TTestCaseVCardProcessor(AddNew('VCardProcessor - Remove phone spaces', TTestCaseVCardProcessor)) do begin
     217      Processor.RemovePhoneSpaces := True;
     218      Input := BeginEnd('TEL: 123 456 789 ' + VCardLineEnding) +
     219        BeginEnd('TEL;CELL:919 191 919' + VCardLineEnding);
     220      Output := BeginEnd('TEL:123456789' + VCardLineEnding) +
     221        BeginEnd('TEL;CELL:919191919' + VCardLineEnding);
     222    end;
     223    with TTestCaseVCardProcessor(AddNew('VCardProcessor - Remove photos', TTestCaseVCardProcessor)) do begin
     224      Processor.RemovePhotos := True;
     225      Input := BeginEnd('N:Surname;Name' + VCardLineEnding +
     226        'FN:Name Surname' + VCardLineEnding +
     227        'PHOTO:dadsa' + VCardLineEnding) +
     228        BeginEnd('N:Surname;Name' + VCardLineEnding +
     229        'FN:Name Surname' + VCardLineEnding +
     230        'PHOTO:dadsa' + VCardLineEnding +
     231        'PHOTO:adsadadsa' + VCardLineEnding);
     232      Output := BeginEnd('N:Surname;Name' + VCardLineEnding +
     233        'FN:Name Surname' + VCardLineEnding) +
     234        BeginEnd('N:Surname;Name' + VCardLineEnding +
     235        'FN:Name Surname' + VCardLineEnding);
     236    end;
     237    with TTestCaseVCardProcessor(AddNew('VCardProcessor - Order', TTestCaseVCardProcessor)) do begin
     238      Processor.Order := True;
     239      Input := BeginEnd('N:Surname2;Name2' + VCardLineEnding +
     240        'FN:Name2 Surname2' + VCardLineEnding) +
     241        BeginEnd('N:Surname1;Name1' + VCardLineEnding +
     242        'FN:Name1 Surname1' + VCardLineEnding) +
     243        BeginEnd('N:Surname3;Name3' + VCardLineEnding +
     244        'FN:Name3 Surname3' + VCardLineEnding);
     245      Output := BeginEnd('FN:Name1 Surname1' + VCardLineEnding +
     246        'N:Surname1;Name1' + VCardLineEnding) +
     247        BeginEnd('FN:Name2 Surname2' + VCardLineEnding +
     248        'N:Surname2;Name2'+ VCardLineEnding) +
     249        BeginEnd('FN:Name3 Surname3' + VCardLineEnding +
     250        'N:Surname3;Name3' + VCardLineEnding);
     251    end;
     252    with TTestCaseVCardProcessor(AddNew('VCardProcessor - Add phone country code', TTestCaseVCardProcessor)) do begin
     253      Processor.AddDefaultPhoneCountryPrefix := True;
     254      Processor.DefaultPhoneCountryCode := '+470';
     255      Processor.NonPrefixedPhoneLength := 9;
     256      Input := BeginEnd('TEL: 123 456 789 ' + VCardLineEnding) +
     257        BeginEnd('TEL;CELL:919 191 919' + VCardLineEnding) +
     258        BeginEnd('TEL;CELL:+421 919 191 919' + VCardLineEnding) +
     259        BeginEnd('TEL;CELL:*#1234' + VCardLineEnding);
     260      Output := BeginEnd('TEL:+470 123 456 789 ' + VCardLineEnding) +
     261        BeginEnd('TEL;CELL:+470919 191 919' + VCardLineEnding) +
     262        BeginEnd('TEL;CELL:+421 919 191 919' + VCardLineEnding) +
     263        BeginEnd('TEL;CELL:*#1234' + VCardLineEnding);
     264    end;
     265    with TTestCaseVCardProcessor(AddNew('VCardProcessor - Convert international call prefix to country code', TTestCaseVCardProcessor)) do begin
     266      Processor.ConvertInternationalCallPrefixToCountryCode := True;
     267      Processor.DefaultInternationalCallPrefix := '00420';
     268      Processor.DefaultPhoneCountryCode := '+470';
     269      Input := BeginEnd('TEL:00420123456789' + VCardLineEnding) +
     270        BeginEnd('TEL;CELL:00420 919 191 919 ' + VCardLineEnding) +
     271        BeginEnd('TEL;CELL:00421919191919' + VCardLineEnding);
     272      Output := BeginEnd('TEL:+470123456789' + VCardLineEnding) +
     273        BeginEnd('TEL;CELL:+470 919 191 919 ' + VCardLineEnding) +
     274        BeginEnd('TEL;CELL:00421919191919' + VCardLineEnding);
     275    end;
     276
    184277    with TTestCaseLoadSave(AddNew('Merge same cell phone', TTestCaseLoadSave)) do begin
    185278      Input := VCardBegin + MacLineEnding +
  • trunk/vCardStudio.lpi

    r151 r152  
    123123      </Item7>
    124124    </RequiredPackages>
    125     <Units Count="25">
     125    <Units Count="26">
    126126      <Unit0>
    127127        <Filename Value="vCardStudio.lpr"/>
     
    281281        <ResourceBaseClass Value="Form"/>
    282282      </Unit24>
     283      <Unit25>
     284        <Filename Value="Forms\FormNormalize.pas"/>
     285        <IsPartOfProject Value="True"/>
     286        <ComponentName Value="FormNormalize"/>
     287        <HasResources Value="True"/>
     288        <ResourceBaseClass Value="Form"/>
     289      </Unit25>
    283290    </Units>
    284291  </ProjectOptions>
  • trunk/vCardStudio.lpr

    r151 r152  
    77  Interfaces, // this includes the LCL widgetset
    88  Forms, FormMain, Core, Diff, SysUtils, FormCompareSideBySide, TestCases,
    9   VCardFile, FormColumns, FormCompare;
     9  VCardFile, FormColumns, FormCompare, FormNormalize;
    1010
    1111{$R *.res}
Note: See TracChangeset for help on using the changeset viewer.