Changeset 58 for trunk/UContact.pas
- Timestamp:
- Dec 8, 2021, 10:00:45 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r57 r58 13 13 TErrorEvent = procedure (Text: string; Line: Integer) of object; 14 14 15 TDataType = (dt String, dtInteger, dtDate, dtDateTime, dtImage, dtStringList);15 TDataType = (dtNone, dtString, dtInteger, dtDate, dtDateTime, dtImage, dtStringList); 16 16 17 17 TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName, cfTitleBefore, … … 28 28 cfWorkAddressPostalCode, cfWorkAddressRegion, cfWorkAddressPostOfficeBox, 29 29 cfXTimesContacted, cfXLastTimeContacted, cfPhoto, cfDayOfBirth, cfRevision, 30 cfVersion, cfAnniversary, 30 cfVersion, cfAnniversary, cfGender, 31 31 cfJabber, cfIcq, cfWindowsLive, cfGoogleTalk, cfAim, cfQq, cfYahoo, cfIrc, 32 cfSkype, cfMsn); 32 cfSkype, cfMsn, 33 cfTwitter, cfFacebook, cfInstagram, cfSnapchat, cfMatrix, cfYoutube, 34 cfPeerTube, cfLinkedIn, cfMastodon, cfMySpace, cfReddit); 35 36 TContactFields = class; 33 37 34 38 { TContactField } … … 42 46 ValueIndex: Integer; 43 47 DataType: TDataType; 48 Alternatives: TContactFields; 49 function AddAlternative(Name: string; Groups: array of string; NoGroups: 50 array of string): TContactField; 44 51 function GroupsContain(Name: string): Boolean; 45 52 function Match(ASysName: string; AGroups: TStringArray): Boolean; 53 constructor Create; 54 destructor Destroy; override; 46 55 end; 47 56 … … 51 60 function AddNew(Name: string; Groups: array of string; NoGroups: array of string; 52 61 Title: string; Index: TContactFieldIndex; DataType: 53 TDataType ; ValueIndex: Integer = -1): TContactField;62 TDataType = dtNone; ValueIndex: Integer = -1): TContactField; 54 63 function GetBySysName(SysName: string): TContactField; 55 64 function GetBySysNameGroups(SysName: string; Groups: TStringArray): TContactField; … … 101 110 Properties: TContactProperties; 102 111 Parent: TContactsFile; 103 function GetProperty(Index: TContactFieldIndex): TContactProperty; 112 function GetProperty(Field: TContactField): TContactProperty; overload; 113 function GetProperty(FieldIndex: TContactFieldIndex): TContactProperty; overload; 104 114 procedure Assign(Source: TContact); 105 115 function UpdateFrom(Source: TContact): Boolean; … … 222 232 SWebAddressHome = 'Web address home'; 223 233 SWebAddressWork = 'Web address work'; 234 SGender = 'Gender'; 235 // Chat 224 236 SMsn = 'MSN'; 225 237 SGoogleTalk = 'Google Talk'; … … 231 243 SYahoo = 'Yahoo!'; 232 244 SSkype = 'Skype'; 245 SMatrix = 'Matrix'; 246 // Social 247 STwitter = 'Twitter'; 248 SFacebook = 'Facebook'; 249 SInstagram = 'Instagram'; 250 SMastodon = 'Mastodon'; 251 SSnapchat = 'Snapchat'; 252 SLinkedIn = 'LinkedIn'; 253 SYouTube = 'YouTube'; 254 SPeerTube = 'PeerTube'; 255 SReddit = 'Reddit'; 256 SMySpace = 'MySpace'; 233 257 234 258 function GetNext(var Text: string; Separator: string): string; … … 256 280 257 281 { TContactField } 282 283 function TContactField.AddAlternative(Name: string; Groups: array of string; 284 NoGroups: array of string): TContactField; 285 begin 286 Result := Alternatives.AddNew(Name, Groups, NoGroups, Title, Index, DataType, ValueIndex); 287 end; 258 288 259 289 function TContactField.GroupsContain(Name: string): Boolean; … … 282 312 end; 283 313 end; 314 end; 315 316 constructor TContactField.Create; 317 begin 318 Alternatives := TContactFields.Create; 319 end; 320 321 destructor TContactField.Destroy; 322 begin 323 FreeAndNil(Alternatives); 324 inherited; 284 325 end; 285 326 … … 520 561 function TContactFields.AddNew(Name: string; Groups: array of string; 521 562 NoGroups: array of string; Title: string; Index: TContactFieldIndex; 522 DataType: TDataType ; ValueIndex: Integer = -1): TContactField;563 DataType: TDataType = dtNone; ValueIndex: Integer = -1): TContactField; 523 564 var 524 565 I: Integer; … … 567 608 var 568 609 I: Integer; 569 C: Integer; 570 begin 571 C := Count; 610 begin 572 611 I := 0; 573 612 while (I < Count) and (Items[I].Index <> Index) do Inc(I); … … 594 633 begin 595 634 if not Assigned(Parent) then raise Exception.Create(SContactHasNoParent); 596 Prop := GetProperty(Index); 597 if Assigned(Prop) then begin 598 Field := Parent.Fields.GetByIndex(Index); 599 if Field.ValueIndex <> -1 then begin 600 Result := Prop.ValueItem[Field.ValueIndex] 601 end else Result := Prop.Value; 602 end else Result := ''; 635 Field := Parent.Fields.GetByIndex(Index); 636 if Assigned(Field) then begin 637 Prop := GetProperty(Field); 638 if Assigned(Prop) then begin 639 Field := Parent.Fields.GetByIndex(Index); 640 if Field.ValueIndex <> -1 then begin 641 Result := Prop.ValueItem[Field.ValueIndex] 642 end else Result := Prop.Value; 643 end else Result := ''; 644 end else raise Exception.Create(SFieldIndexNotDefined); 603 645 end; 604 646 … … 612 654 Field := Parent.Fields.GetByIndex(Index); 613 655 if Assigned(Field) then begin 614 Prop := Properties.GetByNameGroups(Field.SysName, Field.Groups, Field.NoGroups);656 Prop := GetProperty(Field); 615 657 if (not Assigned(Prop)) and (AValue <> '') then begin 616 658 Prop := TContactProperty.Create; … … 633 675 end; 634 676 635 function TContact.GetProperty(Index: TContactFieldIndex): TContactProperty; 677 function TContact.GetProperty(Field: TContactField): TContactProperty; 678 var 679 I: Integer; 680 begin 681 Result := Properties.GetByNameGroups(Field.SysName, Field.Groups, Field.NoGroups); 682 I := 0; 683 while (not Assigned(Result)) and (I < Field.Alternatives.Count) do begin 684 Result := Properties.GetByNameGroups(Field.Alternatives[I].SysName, 685 Field.Alternatives[I].Groups, Field.Alternatives[I].NoGroups); 686 if Assigned(Result) then Break; 687 Inc(I); 688 end; 689 end; 690 691 function TContact.GetProperty(FieldIndex: TContactFieldIndex): TContactProperty; 636 692 var 637 693 Field: TContactField; 638 694 begin 639 695 if not Assigned(Parent) then raise Exception.Create(SContactHasNoParent); 640 Field := Parent.Fields.GetByIndex( Index);696 Field := Parent.Fields.GetByIndex(FieldIndex); 641 697 if Assigned(Field) then begin 642 Result := Properties.GetByNameGroups(Field.SysName, Field.Groups, Field.NoGroups);643 end else raise Exception.Create(SFieldIndexNotDefined);698 Result := GetProperty(Field); 699 end else Result := nil; 644 700 end; 645 701 … … 872 928 AddNew('EMAIL', ['WORK'], [], SWorkEmail, cfEmailWork, dtString); 873 929 AddNew('EMAIL', ['INTERNET'], [], SInternetEmail, cfEmailInternet, dtString); 874 AddNew('NICKNAME', [], [], SNickName, cfNickName, dtString); 930 with AddNew('NICKNAME', [], [], SNickName, cfNickName, dtString) do 931 AddAlternative('X-NICKNAME', [], []); 875 932 AddNew('NOTE', [], [], SNote, cfNote, dtString); 876 933 AddNew('ROLE', [], [], SRole, cfRole, dtString); … … 903 960 AddNew('URL', ['HOME'], [], SWebAddressHome, cfUrlHome, dtString); 904 961 AddNew('URL', ['WORK'], [], SWebAddressWork, cfUrlWork, dtString); 962 with AddNew('GENDER', [], [], SGender, cfGender, dtString) do 963 AddAlternative('X-CENTRUM-CZ-SEX', [], []); 964 // Chat 965 AddNew('X-MATRIX', [], [], SMatrix, cfMatrix, dtString); 905 966 AddNew('X-JABBER', [], [], SJabber, cfJabber, dtString); 906 967 AddNew('X-AIM', [], [], SAim, cfAim, dtString); 907 968 AddNew('X-Windows Live', [], [], SWindowsLive, cfWindowsLive, dtString); 908 969 AddNew('X-YAHOO', [], [], SYahoo, cfYahoo, dtString); 909 AddNew('X-SKYPE-USERNAME', [], [], SSkype, cfSkype, dtString); 970 with AddNew('X-SKYPE-USERNAME', [], [], SSkype, cfSkype, dtString) do begin 971 AddAlternative('X-SKYPE', [], []); 972 AddAlternative('X-CENTRUM-CZ-SKYPE', [], []); 973 end; 910 974 AddNew('X-QQ', [], [], SQq, cfQq, dtString); 911 975 AddNew('X-GOOGLE-TALK', [], [], SGoogleTalk, cfGoogleTalk, dtString); 912 AddNew('X-ICQ', [], [], SIcq, cfIcq, dtString); 976 with AddNew('X-ICQ', [], [], SIcq, cfIcq, dtString) do 977 AddAlternative('X-CENTRUM-CZ-ICQ', [], []); 913 978 AddNew('X-IRC', [], [], SIrc, cfIrc, dtString); 914 AddNew('X-MSN', [], [], SMsn, cfMsn, dtString); 979 with AddNew('X-MSN', [], [], SMsn, cfMsn, dtString) do 980 AddAlternative('X-CENTRUM-CZ-MSN', [], []); 981 // Social 982 with AddNew('X-TWITTER', [], [], STwitter, cfTwitter, dtString) do 983 AddAlternative('X-SOCIALPROFILE', ['TWITTER'], []); 984 with AddNew('X-FACEBOOK', [], [], SFacebook, cfFacebook, dtString) do 985 AddAlternative('X-SOCIALPROFILE', ['FACEBOOK'], []); 986 with AddNew('X-MASTODON', [], [], SMastodon, cfMastodon, dtString) do 987 AddAlternative('X-SOCIALPROFILE', ['MASTODON'], []); 988 with AddNew('X-YOUTUBE', [], [], SYouTube, cfYouTube, dtString) do 989 AddAlternative('X-SOCIALPROFILE', ['YOUTUBE'], []); 990 with AddNew('X-PEERTUBE', [], [], SPeerTube, cfPeerTube, dtString) do 991 AddAlternative('X-SOCIALPROFILE', ['PEERTUBE'], []); 992 with AddNew('X-LINKEDIN', [], [], SLinkedIn, cfLinkedIn, dtString) do 993 AddAlternative('X-SOCIALPROFILE', ['LINKEDIN'], []); 994 with AddNew('X-SNAPCHAT', [], [], SSnapchat, cfSnapchat, dtString) do 995 AddAlternative('X-SOCIALPROFILE', ['SNAPCHAT'], []); 996 with AddNew('X-INSTAGRAM', [], [], SInstagram, cfInstagram, dtString) do 997 AddAlternative('X-SOCIALPROFILE', ['INSTAGRAM'], []); 998 with AddNew('X-REDDIT', [], [], SReddit, cfReddit, dtString) do 999 AddAlternative('X-SOCIALPROFILE', ['REDDIT'], []); 1000 with AddNew('X-MYSPACE', [], [], SMySpace, cfMySpace, dtString) do 1001 AddAlternative('X-SOCIALPROFILE', ['MYSPACE'], []); 915 1002 end; 916 1003 end;
Note:
See TracChangeset
for help on using the changeset viewer.