Changeset 14 for trunk/UContact.pas


Ignore:
Timestamp:
Feb 4, 2018, 2:01:05 PM (6 years ago)
Author:
chronos
Message:
  • Added: New File menu action Merge. It can merge multiple vcard files and update values for items with same full name.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r12 r14  
    1515  TDataType = (dtString, dtInteger, dtDate, dtDateTime, dtImage);
    1616
    17   TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName, cfTelPrefCell,
    18     cfTelCell, cfTelHome, cfTelHome2, cfTelWork, cfTitle, cfOrganization,
    19     cfAddress, cfNote);
     17  TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName, cfTitleBefore,
     18    cfTitleAfter, cfFullName, cfTelPrefCell,
     19    cfTelCell, cfTelHome, cfTelHome2, cfTelWork, cfTelVoip,
     20    cfTelPrefWorkVoice, cfTelPrefHomeVoice, cfTelHomeVoice, cfTelWorkVoice,
     21    cfEmailHome, cfEmailInternet, cfNickName, cfNote, cfRole, cfTitle,
     22    cfCategories, cfOrganization, cfAdrHome, cfHomeAddressStreet,
     23    cfHomeAddressCity, cfHomeAddressCountry, cfXTimesContacted,
     24    cfXLastTimeContacted, cfPhoto, cfXJabber);
    2025
    2126  TContactField = class
     
    7378    Photo: string;
    7479    XJabber: string;
     80    procedure Assign(Source: TContact);
     81    function UpdateFrom(Source: TContact): Boolean;
    7582    property Fields[Index: TContactFieldIndex]: string read GetField write SetField;
    7683  end;
     84
     85  { TContacts }
    7786
    7887  TContacts = class(TObjectList)
    7988    ContactsFile: TContactsFile;
     89    function Search(FullName: string): TContact;
    8090  end;
    8191
     
    106116  SVCardFile = 'vCard file';
    107117  SUnknownCommand = 'Unknown command: %s';
     118  SUnsupportedContactFieldsIndex = 'Unsupported contact field index';
     119
     120{ TContacts }
     121
     122function TContacts.Search(FullName: string): TContact;
     123var
     124  Contact: TContact;
     125begin
     126  Result := nil;
     127  for Contact in Self do
     128    if Contact.FullName = FullName then begin
     129      Result := Contact;
     130      Break;
     131    end;
     132end;
    108133
    109134{ TContactFields }
     
    127152    cfMiddleName: Result := MiddleName;
    128153    cfLastName: Result := LastName;
     154    cfTitleBefore: Result := TitleBefore;
     155    cfTitleAfter: Result := TitleAfter;
     156    cfFullName: Result := FullName;
    129157    cfTelPrefCell: Result := TelPrefCell;
    130158    cfTelCell: Result := TelCell;
     
    132160    cfTelHome2: Result := TelHome2;
    133161    cfTelWork: Result := TelWork;
     162    cfTelVoip: Result := TelVoip;
     163    cfTelPrefWorkVoice: Result := TelPrefWorkVoice;
     164    cfTelPrefHomeVoice: Result := TelPrefHomeVoice;
     165    cfTelHomeVoice: Result := TelHomeVoice;
     166    cfTelWorkVoice: Result := TelWorkVoice;
     167    cfEmailHome: Result := EmailHome;
     168    cfEmailInternet: Result := EmailInternet;
     169    cfNickName: Result := NickName;
     170    cfNote: Result := Note;
     171    cfRole: Result := Role;
    134172    cfTitle: Result := Title;
     173    cfCategories: Result := Categories;
    135174    cfOrganization: Result := Organization;
    136     cfAddress: Result := AdrHome;
    137     cfNote: Result := Note;
     175    cfAdrHome: Result := AdrHome;
     176    cfHomeAddressStreet: Result := HomeAddressStreet;
     177    cfHomeAddressCity: Result := HomeAddressCity;
     178    cfHomeAddressCountry: Result := HomeAddressCountry;
     179    cfXTimesContacted: Result := XTimesContacted;
     180    cfXLastTimeContacted: Result := XLastTimeContacted;
     181    cfPhoto: Result := Photo;
     182    cfXJabber: Result := XJabber;
     183    else raise Exception.Create(SUnsupportedContactFieldsIndex);
    138184  end;
    139185end;
     
    145191    cfMiddleName: MiddleName := AValue;
    146192    cfLastName: LastName := AValue;
     193    cfTitleBefore: TitleBefore := AValue;
     194    cfTitleAfter: TitleAfter := AValue;
     195    cfFullName: FullName := AValue;
    147196    cfTelPrefCell: TelPrefCell := AValue;
    148197    cfTelCell: TelCell := AValue;
     
    150199    cfTelHome2: TelHome2 := AValue;
    151200    cfTelWork: TelWork := AValue;
     201    cfTelVoip: TelVoip := AValue;
     202    cfTelPrefWorkVoice: TelPrefWorkVoice := AValue;
     203    cfTelPrefHomeVoice: TelPrefHomeVoice := AValue;
     204    cfTelHomeVoice: TelHomeVoice := AValue;
     205    cfTelWorkVoice: TelWorkVoice := AValue;
     206    cfEmailHome: EmailHome := AValue;
     207    cfEmailInternet: EmailInternet := AValue;
     208    cfNickName: NickName := AValue;
     209    cfNote: Note := AValue;
     210    cfRole: Role := AValue;
    152211    cfTitle: Title := AValue;
     212    cfCategories: Categories := AValue;
    153213    cfOrganization: Organization := AValue;
    154     cfAddress: AdrHome := AValue;
    155     cfNote: Note := AValue;
     214    cfAdrHome: AdrHome := AValue;
     215    cfHomeAddressStreet: HomeAddressStreet := AValue;
     216    cfHomeAddressCity: HomeAddressCity := AValue;
     217    cfHomeAddressCountry: HomeAddressCountry := AValue;
     218    cfXTimesContacted: XTimesContacted := AValue;
     219    cfXLastTimeContacted: XLastTimeContacted := AValue;
     220    cfPhoto: Photo := AValue;
     221    cfXJabber: XJabber := AValue;
     222    else raise Exception.Create(SUnsupportedContactFieldsIndex);
     223  end;
     224end;
     225
     226procedure TContact.Assign(Source: TContact);
     227begin
     228  Version := Source.Version;
     229  FirstName := Source.FirstName;
     230  MiddleName := Source.MiddleName;
     231  LastName := Source.LastName;
     232  TitleBefore := Source.TitleBefore;
     233  TitleAfter := Source.TitleAfter;
     234  FullName := Source.FullName;
     235  TelPrefCell := Source.TelPrefCell;
     236  TelCell := Source.TelCell;
     237  TelHome := Source.TelHome;
     238  TelHome2 := Source.TelHome2;
     239  TelWork := Source.TelWork;
     240  TelVoip := Source.TelVoip;
     241  TelPrefWorkVoice := Source.TelPrefWorkVoice;
     242  TelPrefHomeVoice := Source.TelPrefHomeVoice;
     243  TelHomeVoice := Source.TelHomeVoice;
     244  TelWorkVoice := Source.TelWorkVoice;
     245  EmailHome := Source.EmailHome;
     246  EmailInternet := Source.EmailInternet;
     247  NickName := Source.NickName;
     248  Note := Source.Note;
     249  Role := Source.Role;
     250  Title := Source.Title;
     251  Categories := Source.Categories;
     252  Organization := Source.Organization;
     253  AdrHome := Source.AdrHome;
     254  HomeAddressStreet := Source.HomeAddressStreet;
     255  HomeAddressCity := Source.HomeAddressCity;
     256  HomeAddressCountry := Source.HomeAddressCountry;
     257  XTimesContacted := Source.XTimesContacted;
     258  XLastTimeContacted := Source.XLastTimeContacted;
     259  Photo := Source.Photo;
     260  XJabber := Source.XJabber;
     261end;
     262
     263function TContact.UpdateFrom(Source: TContact): Boolean;
     264var
     265  I: Integer;
     266begin
     267  Result := False;
     268  for I := 0 to Parent.Fields.Count - 1 do begin
     269    if (Source.Fields[TContactField(Parent.Fields[I]).Index] <> '') and
     270      (Source.Fields[TContactField(Parent.Fields[I]).Index] <>
     271      Fields[TContactField(Parent.Fields[I]).Index]) then begin
     272        Result := True;
     273        Fields[TContactField(Parent.Fields[I]).Index] := Source.Fields[TContactField(Parent.Fields[I]).Index];
     274      end;
    156275  end;
    157276end;
     
    176295    AddNew('Middle Name', cfMiddleName, dtString);
    177296    AddNew('Last Name', cfLastName, dtString);
     297    AddNew('Title Before', cfTitleBefore, dtString);
     298    AddNew('Title After', cfTitleAfter, dtString);
     299    AddNew('Full Name', cfFullName, dtString);
    178300    AddNew('Preferred cell phone', cfTelPrefCell, dtString);
    179301    AddNew('Cell phone', cfTelCell, dtString);
     
    181303    AddNew('Home phone 2', cfTelHome2, dtString);
    182304    AddNew('Home work', cfTelWork, dtString);
     305    AddNew('Tel Voip', cfTelVoip, dtString);
     306    AddNew('Tel Pref Work Voice', cfTelPrefWorkVoice, dtString);
     307    AddNew('Tel Pref Home Voice', cfTelPrefHomeVoice, dtString);
     308    AddNew('Tel Home Voice', cfTelHomeVoice, dtString);
     309    AddNew('Tel Work Voice', cfTelWorkVoice, dtString);
     310    AddNew('Email Home', cfEmailHome, dtString);
     311    AddNew('Email Internet', cfEmailInternet, dtString);
     312    AddNew('Nick Name', cfNickName, dtString);
     313    AddNew('Note', cfNote, dtString);
     314    AddNew('Role', cfRole, dtString);
    183315    AddNew('Title', cfTitle, dtString);
     316    AddNew('Categories', cfCategories, dtString);
    184317    AddNew('Organization', cfOrganization, dtString);
    185     AddNew('Address', cfAddress, dtString);
    186     AddNew('Note', cfNote, dtString);
     318    AddNew('Home Address', cfAdrHome, dtString);
     319    AddNew('Home Address Street', cfHomeAddressStreet, dtString);
     320    AddNew('Home Address City', cfHomeAddressCity, dtString);
     321    AddNew('Home Address Country', cfHomeAddressCountry, dtString);
     322    AddNew('Times Contacted', cfXTimesContacted, dtString);
     323    AddNew('Last Time Contacted', cfXLastTimeContacted, dtString);
     324    AddNew('Photo', cfPhoto, dtString);
     325    AddNew('Jabber', cfXJabber, dtString);
    187326  end;
    188327end;
Note: See TracChangeset for help on using the changeset viewer.