⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ucontactsync.pas

📁 FMA is a free1 powerful phone editing tool allowing users to easily manage all of the personal data
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{ TContactSource }

constructor TContactSource.Create;
begin
  inherited;

  FContacts := TContacts.Create;
  FConfirmActions := [caAdd, caUpdate, caDelete]; 
end;

function TContactSource.DeformatPhoneNumber(PhoneNumber: String): String;
const ValidChars = ['*', '#', '+', '0'..'9', 'p']; // do not localize
var I: Integer;
begin
  Result := '';
  for I := 1 to Length(PhoneNumber) do
    if PhoneNumber[I] in ValidChars then
      Result := Result + PhoneNumber[I];
end;

destructor TContactSource.Destroy;
begin
  FContacts.Free;

  inherited;
end;

function TContactSource.Find(SyncID: Cardinal): TContact;
begin
  Result := FContacts.FindBySyncID(SyncID);
end;

procedure TContactSource.Unlink(Contact: TContact);
begin
  if Assigned(Contact.LinkedContact) then begin
    Contact.LinkedContact.LinkedContact := nil;
    Contact.LinkedContact := nil;
  end;
end;

{ TContacts }

function TContacts.Add(Item: TContact): Integer;
begin
  Result := FList.Add(Item);
end;

procedure TContacts.Clear;
begin
  FList.Clear;
end;

constructor TContacts.Create;
begin
  inherited;

  FList := TObjectList.Create;
end;

procedure TContacts.Delete(Index: Integer);
begin
  FList.Delete(Index);
end;

destructor TContacts.Destroy;
begin
  FList.Free;

  inherited;
end;

function TContacts.GetItem(Index: Integer): TContact;
begin
  Result := FList[Index] as TContact;
end;

function TContacts.GetCount: Integer;
begin
  Result := FList.Count;
end;

function TContacts.IndexOf(Item: TContact): Integer;
begin
  Result := FList.IndexOf(Item);
end;

procedure TContacts.PutItem(Index: Integer; const Value: TContact);
begin
  FList[Index] := Value;
end;

procedure TContacts.Remove(Item: TContact);
begin
  FList.Remove(Item);
end;

function TContacts.FindByID(ID: Variant): TContact;
var I: Integer;
begin
  Result := nil;

  for I := 0 to Count - 1 do
    if Items[I].ID = ID then begin
      Result := Items[I];
      Break;
    end;
end;

function TContacts.FindBySyncID(SyncID: Cardinal): TContact;
var I: Integer;
begin
  Result := nil;

  for I := 0 to Count - 1 do
    if Items[I].SyncID = SyncID then begin
      Result := Items[I];
      Break;
    end;
end;

{ TBaseContact }

function TBaseContact.GetFullName: WideString;
begin
  Result := FName;
  if FSurName <> '' then
    if Result <> '' then
      Result := Result + ' ' + FSurName
    else
      Result := FSurName;
end;

{ TPossibleLinks }

constructor TPossibleLinks.Create;
begin
  inherited;

  FList := TObjectList.Create;
end;

destructor TPossibleLinks.Destroy;
begin
  FList.Free;

  inherited;
end;

function TPossibleLinks.Add(Contact: TContact; Score: Integer): Integer;
var PossibleLink: TPossibleLink;
begin
  PossibleLink := TPossibleLink.Create;
  PossibleLink.Contact := Contact;
  PossibleLink.Score := Score;


  Result := FList.Add(PossibleLink);
end;

procedure TPossibleLinks.Clear;
begin
  FList.Clear;
end;

procedure TPossibleLinks.Delete(Index: Integer);
begin
  FList.Delete(Index);
end;

function TPossibleLinks.GetCount: Integer;
begin
  Result := FList.Count;
end;

function TPossibleLinks.GetItem(Index: Integer): TPossibleLink;
begin
  Result := FList[Index] as TPossibleLink;
end;

function TPossibleLinks.IndexOf(Item: TPossibleLink): Integer;
begin
  Result := FList.IndexOf(Item);
end;

procedure TPossibleLinks.PutItem(Index: Integer; const Value: TPossibleLink);
begin
  FList[Index] := Value;
end;

procedure TPossibleLinks.Remove(Item: TPossibleLink);
begin
  FList.Remove(Item);
end;

function PossibleLinksSortCompare(Item1, Item2: Pointer): Integer;
var Score1, Score2: Integer;
begin
  Score1 := TPossibleLink(Item1).Score;
  Score2 := TPossibleLink(Item2).Score;

  if Score1= Score2 then
    Result := 0
  else if Score1 < Score2 then
    Result := 1
  else
    Result := -1;
end;

procedure TPossibleLinks.Sort;
begin
  FList.Sort(PossibleLinksSortCompare);
end;

{ TContactFieldMapper }

constructor TContactFieldMapper.Create;
begin
  inherited;

  FMappedFields := TStringList.Create;
  FFields := TStringList.Create;
  FStandardFields := TStringList.Create;

  LoadStandardFields;
end;

destructor TContactFieldMapper.Destroy;
begin
  FMappedFields.Free;
  FFields.Free;
  FStandardFields.Free;

  inherited;
end;

function TContactFieldMapper.GetBirthday: TDateTime;
begin
  Result := MappedValue['Birthday'];
end;

function TContactFieldMapper.GetCellPhone: WideString;
begin
  Result := MappedValue['CellPhone'];
end;

function TContactFieldMapper.GetCity: WideString;
begin
  Result := MappedValue['City'];
end;

function TContactFieldMapper.GetCountry: WideString;
begin
  Result := MappedValue['Country'];
end;

function TContactFieldMapper.GetEMail: WideString;
begin
  Result := MappedValue['EMail'];
end;

function TContactFieldMapper.GetFaxPhone: WideString;
begin
  Result := MappedValue['FaxPhone'];
end;

function TContactFieldMapper.GetHomePhone: WideString;
begin
  Result := MappedValue['HomePhone'];
end;

function TContactFieldMapper.GetMappedField(Field: String): String;
begin
  Result := FMappedFields.Values[Field];
  if Result = '' then
    { If not match found, use direct name mapping }
    Result := Field;
end;

function TContactFieldMapper.GetMappedValue(Field: String): Variant;
begin
  Result := VariantValue[MappedField[Field]];
end;

function TContactFieldMapper.GetName: WideString;
begin
  Result := MappedValue['Name'];
end;

function TContactFieldMapper.GetOrganization: WideString;
begin
  Result := MappedValue['Organization'];
end;

function TContactFieldMapper.GetOtherPhone: WideString;
begin
  Result := MappedValue['OtherPhone'];
end;

function TContactFieldMapper.GetPostalCode: WideString;
begin
  Result := MappedValue['PostalCode'];
end;

function TContactFieldMapper.GetRegion: WideString;
begin
  Result := MappedValue['Region'];
end;

function TContactFieldMapper.GetStreet: WideString;
begin
  Result := MappedValue['Street'];
end;

function TContactFieldMapper.GetSurName: WideString;
begin
  Result := MappedValue['SurName'];
end;

function TContactFieldMapper.GetTitle: WideString;
begin
  Result := MappedValue['Title'];
end;

function TContactFieldMapper.GetWorkPhone: WideString;
begin
  Result := MappedValue['WorkPhone'];
end;

procedure TContactFieldMapper.LoadStandardFields;
begin

  { REFFERENCE !!!

    TFMAContactFieldMapper.Create;
    TContactFieldMapper.LoadStandardFields;
    TOutlookContactSource.Read/Write();
  }

  FStandardFields.Add('Title');
  FStandardFields.Add('Name');
  FStandardFields.Add('SurName');
  FStandardFields.Add('Organization');
  FStandardFields.Add('EMail');
  FStandardFields.Add('HomePhone');
  FStandardFields.Add('WorkPhone');
  FStandardFields.Add('CellPhone');
  FStandardFields.Add('FaxPhone');
  FStandardFields.Add('OtherPhone');
  FStandardFields.Add('Street');
  FStandardFields.Add('City');
  FStandardFields.Add('Region');
  FStandardFields.Add('PostalCode');
  FStandardFields.Add('Country');
  {
  Fields.Add('WorkStreet');
  Fields.Add('WorkCity');
  Fields.Add('WorkRegion');
  Fields.Add('WorkPostalCode');
  Fields.Add('WorkCountry');
  }
  FStandardFields.Add('Birthday');
end;

procedure TContactFieldMapper.SetBirthday(const Value: TDateTime);
begin
  MappedValue['Birthday'] := Value;
end;

procedure TContactFieldMapper.SetCellPhone(const Value: WideString);
begin
  MappedValue['CellPhone'] := Value;
end;

procedure TContactFieldMapper.SetCity(const Value: WideString);
begin
  MappedValue['City'] := Value;
end;

procedure TContactFieldMapper.SetCountry(const Value: WideString);
begin
  MappedValue['Country'] := Value;
end;

procedure TContactFieldMapper.SetEMail(const Value: WideString);
begin
  MappedValue['EMail'] := Value;
end;

procedure TContactFieldMapper.SetFaxPhone(const Value: WideString);
begin
  MappedValue['FaxPhone'] := Value;
end;

procedure TContactFieldMapper.SetFields(const Value: TStrings);
begin
  FFields.Assign(Value);
end;

procedure TContactFieldMapper.SetHomePhone(const Value: WideString);
begin
  MappedValue['HomePhone'] := Value;
end;

procedure TContactFieldMapper.SetMappedFields(const Value: TStrings);
begin
  FMappedFields.Assign(Value);
end;

procedure TContactFieldMapper.SetMappedValue(Field: String; const AValue: Variant);
begin
  VariantValue[MappedField[Field]] := AValue;
end;

procedure TContactFieldMapper.SetName(const Value: WideString);
begin
  MappedValue['Name'] := Value;
end;

procedure TContactFieldMapper.SetOrganization(const Value: WideString);
begin
  MappedValue['Organization'] := Value;
end;

procedure TContactFieldMapper.SetOtherPhone(const Value: WideString);
begin
  MappedValue['OtherPhone'] := Value;
end;

procedure TContactFieldMapper.SetPostalCode(const Value: WideString);
begin
  MappedValue['PostalCode'] := Value;
end;

procedure TContactFieldMapper.SetRegion(const Value: WideString);
begin
  MappedValue['Region'] := Value;
end;

procedure TContactFieldMapper.SetStreet(const Value: WideString);
begin
  MappedValue['Street'] := Value;
end;

procedure TContactFieldMapper.SetSurName(const Value: WideString);
begin
  MappedValue['SurName'] := Value;
end;

procedure TContactFieldMapper.SetTitle(const Value: WideString);
begin
  MappedValue['Title'] := Value;
end;

procedure TContactFieldMapper.SetWorkPhone(const Value: WideString);
begin
  MappedValue['WorkPhone'] := Value;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -