Changeset 58 for trunk/UContact.pas


Ignore:
Timestamp:
Dec 8, 2021, 10:00:45 PM (3 years ago)
Author:
chronos
Message:
  • Added: Social tab in contact form.
  • Added: Allow to specify alternative property name for contact field definition to support various non-standard properties.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r57 r58  
    1313  TErrorEvent = procedure (Text: string; Line: Integer) of object;
    1414
    15   TDataType = (dtString, dtInteger, dtDate, dtDateTime, dtImage, dtStringList);
     15  TDataType = (dtNone, dtString, dtInteger, dtDate, dtDateTime, dtImage, dtStringList);
    1616
    1717  TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName, cfTitleBefore,
     
    2828    cfWorkAddressPostalCode, cfWorkAddressRegion, cfWorkAddressPostOfficeBox,
    2929    cfXTimesContacted, cfXLastTimeContacted, cfPhoto, cfDayOfBirth, cfRevision,
    30     cfVersion, cfAnniversary,
     30    cfVersion, cfAnniversary, cfGender,
    3131    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;
    3337
    3438  { TContactField }
     
    4246    ValueIndex: Integer;
    4347    DataType: TDataType;
     48    Alternatives: TContactFields;
     49    function AddAlternative(Name: string; Groups: array of string; NoGroups:
     50      array of string): TContactField;
    4451    function GroupsContain(Name: string): Boolean;
    4552    function Match(ASysName: string; AGroups: TStringArray): Boolean;
     53    constructor Create;
     54    destructor Destroy; override;
    4655  end;
    4756
     
    5160    function AddNew(Name: string; Groups: array of string; NoGroups: array of string;
    5261      Title: string; Index: TContactFieldIndex; DataType:
    53       TDataType; ValueIndex: Integer = -1): TContactField;
     62      TDataType = dtNone; ValueIndex: Integer = -1): TContactField;
    5463    function GetBySysName(SysName: string): TContactField;
    5564    function GetBySysNameGroups(SysName: string; Groups: TStringArray): TContactField;
     
    101110    Properties: TContactProperties;
    102111    Parent: TContactsFile;
    103     function GetProperty(Index: TContactFieldIndex): TContactProperty;
     112    function GetProperty(Field: TContactField): TContactProperty; overload;
     113    function GetProperty(FieldIndex: TContactFieldIndex): TContactProperty; overload;
    104114    procedure Assign(Source: TContact);
    105115    function UpdateFrom(Source: TContact): Boolean;
     
    222232  SWebAddressHome = 'Web address home';
    223233  SWebAddressWork = 'Web address work';
     234  SGender = 'Gender';
     235  // Chat
    224236  SMsn = 'MSN';
    225237  SGoogleTalk = 'Google Talk';
     
    231243  SYahoo = 'Yahoo!';
    232244  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';
    233257
    234258function GetNext(var Text: string; Separator: string): string;
     
    256280
    257281{ TContactField }
     282
     283function TContactField.AddAlternative(Name: string; Groups: array of string;
     284  NoGroups: array of string): TContactField;
     285begin
     286  Result := Alternatives.AddNew(Name, Groups, NoGroups, Title, Index, DataType, ValueIndex);
     287end;
    258288
    259289function TContactField.GroupsContain(Name: string): Boolean;
     
    282312    end;
    283313  end;
     314end;
     315
     316constructor TContactField.Create;
     317begin
     318  Alternatives := TContactFields.Create;
     319end;
     320
     321destructor TContactField.Destroy;
     322begin
     323  FreeAndNil(Alternatives);
     324  inherited;
    284325end;
    285326
     
    520561function TContactFields.AddNew(Name: string; Groups: array of string;
    521562  NoGroups: array of string; Title: string; Index: TContactFieldIndex;
    522   DataType: TDataType; ValueIndex: Integer = -1): TContactField;
     563  DataType: TDataType = dtNone; ValueIndex: Integer = -1): TContactField;
    523564var
    524565  I: Integer;
     
    567608var
    568609  I: Integer;
    569   C: Integer;
    570 begin
    571   C := Count;
     610begin
    572611  I := 0;
    573612  while (I < Count) and (Items[I].Index <> Index) do Inc(I);
     
    594633begin
    595634  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);
    603645end;
    604646
     
    612654  Field := Parent.Fields.GetByIndex(Index);
    613655  if Assigned(Field) then begin
    614     Prop := Properties.GetByNameGroups(Field.SysName, Field.Groups, Field.NoGroups);
     656    Prop := GetProperty(Field);
    615657    if (not Assigned(Prop)) and (AValue <> '') then begin
    616658      Prop := TContactProperty.Create;
     
    633675end;
    634676
    635 function TContact.GetProperty(Index: TContactFieldIndex): TContactProperty;
     677function TContact.GetProperty(Field: TContactField): TContactProperty;
     678var
     679  I: Integer;
     680begin
     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;
     689end;
     690
     691function TContact.GetProperty(FieldIndex: TContactFieldIndex): TContactProperty;
    636692var
    637693  Field: TContactField;
    638694begin
    639695  if not Assigned(Parent) then raise Exception.Create(SContactHasNoParent);
    640   Field := Parent.Fields.GetByIndex(Index);
     696  Field := Parent.Fields.GetByIndex(FieldIndex);
    641697  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;
    644700end;
    645701
     
    872928    AddNew('EMAIL', ['WORK'], [], SWorkEmail, cfEmailWork, dtString);
    873929    AddNew('EMAIL', ['INTERNET'], [], SInternetEmail, cfEmailInternet, dtString);
    874     AddNew('NICKNAME', [], [], SNickName, cfNickName, dtString);
     930    with AddNew('NICKNAME', [], [], SNickName, cfNickName, dtString) do
     931      AddAlternative('X-NICKNAME', [], []);
    875932    AddNew('NOTE', [], [], SNote, cfNote, dtString);
    876933    AddNew('ROLE', [], [], SRole, cfRole, dtString);
     
    903960    AddNew('URL', ['HOME'], [], SWebAddressHome, cfUrlHome, dtString);
    904961    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);
    905966    AddNew('X-JABBER', [], [], SJabber, cfJabber, dtString);
    906967    AddNew('X-AIM', [], [], SAim, cfAim, dtString);
    907968    AddNew('X-Windows Live', [], [], SWindowsLive, cfWindowsLive, dtString);
    908969    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;
    910974    AddNew('X-QQ', [], [], SQq, cfQq, dtString);
    911975    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', [], []);
    913978    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'], []);
    9151002  end;
    9161003end;
Note: See TracChangeset for help on using the changeset viewer.