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

📄 ueditcontact.pas

📁 FMA is a free1 powerful phone editing tool allowing users to easily manage all of the personal data
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  end;
  if Pos('"',s) <> 0 then begin
    if FUseSIMMode then begin
      MessageDlgW(_('Quotes are not allowed in SIM contact name.'), mtError, MB_OK);
      Abort;
    end;
  end;
  if Trim(txtDisplayAs.Text) = '' then
    txtDisplayAs.Text := s;
  { check numbers }
  TelCnt := PhonesCount;
  if FUseSIMMode and (TelCnt = 0) then begin
    MessageDlgW(_('You have to enter contact phone number.'), mtError, MB_OK);
    Abort;
  end;
  if FUseSIMMode and (TelCnt > 1) then begin
    MessageDlgW(_('You have to enter only one phone number.'), mtError, MB_OK);
    Abort;
  end;
  { check date }
  if BirthdayDeleteButton.Enabled and (txtBirthday.Date >= Now) then begin
    MessageDlgW(_('You have to enter valid birthday date.'), mtError, MB_OK);
    Abort;
  end;
end;

procedure TfrmEditContact.FillDisplayNameList;
var
  w,s: WideString;
  i: integer;
  IgnoreOrg: boolean;
begin
  IgnoreOrg := False;
  txtDisplayAs.Items.Clear;
  s := Trim(txtName.Text);
  if (s = '') and (Trim(txtOrganization.Text) <> '') then begin
    s := Trim(txtOrganization.Text);
    IgnoreOrg := True;
  end;
  if s <> '' then begin
    { Move surname in front }
    w := s;
    if not IgnoreOrg then begin
      i := Length(w);
      while (i >= 1) and (w[i] <> ' ') do dec(i);
      s := Copy(w,1,i-1);
      w := Copy(w,i+1,Length(w));
      if s <> '' then w := w + ', ' + Trim(s);
    end;
    { Fill list }
    txtDisplayAs.Items.Add(s);
    if not IgnoreOrg and (txtOrganization.Text <> '') then
      txtDisplayAs.Items.Add(txtName.Text + ' ' + txtOrganization.Text);
    if WideCompareText(w,s) <> 0 then begin
      txtDisplayAs.Items.Add(w);
      if not IgnoreOrg and (txtOrganization.Text <> '') then
        txtDisplayAs.Items.Add(w + ' ' + txtOrganization.Text);
    end;
    if not IgnoreOrg and (txtTitle.Text <> '') then begin
      txtDisplayAs.Items.Add(txtTitle.Text + ' ' + txtName.Text);
      if txtOrganization.Text <> '' then
        txtDisplayAs.Items.Add(txtTitle.Text + ' ' + txtName.Text + ' ' + txtOrganization.Text);
      if WideCompareText(w,txtName.Text) <> 0 then begin
        txtDisplayAs.Items.Add(txtTitle.Text + ' ' + w);
        if txtOrganization.Text <> '' then
          txtDisplayAs.Items.Add(txtTitle.Text + ' ' + w + ' ' + txtOrganization.Text);
      end;
    end;
  end;
end;

procedure TfrmEditContact.ShowFullName(Modified: WideString);
var
  s,w: WideString;
  i,j: integer;
begin
  s := Trim(txtName.Text);
  if (s = '') and (Trim(txtOrganization.Text) <> '') then s := Trim(txtOrganization.Text);
  if txtDisplayAs.Text = '' then
    txtDisplayAs.Text := s;
  { Update DisplayAs default patterns }
  w := txtDisplayAs.Text;
  i := txtDisplayAs.Items.IndexOf(w);
  { Remove any emptied field }
  if (FPrevChangeAs <> '') and (Modified = '') then begin
    j := Pos(' '+FPrevChangeAs,w);
    if j = 0 then
      j := Pos(FPrevChangeAs+' ',w);
    if j <> 0 then
      Delete(w,j,Length(FPrevChangeAs)+1);
  end;
  { Update predefined values }
  FillDisplayNameList;
  if i <> -1 then begin
    { Predefined value was used, so update it with new fields }
    j := txtDisplayAs.Items.IndexOf(w);
    if j <> -1 then
      { unused field has been changed or field is emptied }
      i := j;
    { do not remove next sanity check, its used when an used field is changed }
    if (i >= 0) and (i < txtDisplayAs.Items.Count) then
      { Set to new predefined value }
      txtDisplayAs.ItemIndex := i;
  end;
  { Update dialog caption }
  if s <> '' then
    if FUseOwnMode then
      Caption := WideFormat(_('Own Business Card - %s'),[s])
    else
      Caption := WideFormat(_('Contact - %s'),[s])
  else
    Caption := _('Contact');
  { Populate changes }
  txtDisplayAsChange(txtDisplayAs);
end;

procedure TfrmEditContact.txtChangeEditAs(Sender: TObject);
var
  w: WideString;
begin
  if not FLoadingData then begin
    w := (Sender as TTntEdit).Text;
    ShowFullName(w);
    FPrevChangeAs := w;
  end;
  DoSetModified;
end;

procedure TfrmEditContact.OnChangeAsEnter(Sender: TObject);
begin
  FPrevChangeAs := (Sender as TTntEdit).Text;
end;

procedure TfrmEditContact.LoadAndMergeWith(AContact: TContactData);
var
  w: WideString;
begin
  LoadContactData;
  txtTitle.Text := AContact.title;
  w := AContact.name;
  if AContact.surname <> '' then
    w := w + ' ' + AContact.surname; // do not use GetContactFullName here!
  txtName.Text := w;
  txtFileAs.Text := AContact.displayname;
  txtOrganization.Text := AContact.org;
  txtBirthday.Date := contact.Birthday;
  txtBirthdayChange(nil);
  txtHome.Text := AContact.home;
  txtWork.Text := AContact.work;
  txtCell.Text := AContact.cell;
  txtFax.Text := AContact.fax;
  txtOther.Text := AContact.other;
  txtURL.Text := AContact.homepage;
  FAddress := -1;
  FAddresses[0] := AContact.homeAddress;
  FAddresses[1] := AContact.workAddress;
  txtAddressType.ItemIndex := 0;
  txtAddressTypeChange(nil);
  if Form1.IsK610orBetter then // notes support for K610+ phones
    GetContactNotes(@AContact,MemoNotes.Lines);
  // - Do not copy displayname, it will be merged
  // txtDisplayAs.Text := AContact.displayname;
  // - Keep old GUID!
  // txtContactDataID.Text := GUIDToString(contact.CDID);
  // - Do not copy personalization!
  // cbDefaultNum.ItemIndex := AContact.DefaultIndex;
  // lblPicName.Caption := AContact.picture;
  // lblSndName.Caption := AContact.sound;
end;

procedure TfrmEditContact.UnlinkOutlookButtonClick(Sender: TObject);
var
  SynchronizeContacts: TSynchronizeContacts;
  Fullpath: String;
begin
  try
    Fullpath := Form1.GetProfilePath+'dat\'; // do not localize
    SynchronizeContacts := TSynchronizeContacts.Create;
    try
      SynchronizeContacts.FileName := Fullpath + 'ContactSync.xml'; // do not localize

      SynchronizeContacts.OnError := SyncContactsError;
      SynchronizeContacts.OnConfirm := SyncContactsConfirm;

      SynchronizeContacts.Unlink(Contact.CDID);
    finally
      SynchronizeContacts.Free;
    end;
  except
    on E: Exception do begin
      Log.AddSynchronizationMessageFmt(_('Error: Unlink aborted (%s: %s)'), [E.ClassName, E.Message], lsError);
      Form1.Status(Format(_('Error: Unlink aborted (%s: %s)'), [E.ClassName, E.Message]));
      MessageDlgW(Format(_('Error: Unlink aborted (%s: %s)'), [E.ClassName, E.Message]), mtError, MB_OK);
    end;
  end;
end;

procedure TfrmEditContact.SyncContactsError(Sender: TObject; const Message: String);
begin
  Log.AddSynchronizationMessageFmt(_('Error: Unlink aborted (%s)'), [Message], lsError);
  Form1.Status(Format(_('Error: Unlink aborted (%s)'), [Message]));
  MessageDlgW(Format(_('Error: Unlink aborted (%s)'), [Message]), mtError, MB_OK);
end;

procedure TfrmEditContact.SyncContactsConfirm(Sender: TObject; Contact: TContact;
    Action: TContactAction; const Description: WideString; var Confirmed: Boolean);
begin
  Confirmed := MessageDlgW(WideFormat(sContactSyncConfirm, [Description]), mtConfirmation, MB_YESNO) = ID_YES;
end;

procedure TfrmEditContact.btNotesClearClick(Sender: TObject);
begin
  MemoNotes.Clear;
  MemoNotesChange(nil);
end;

procedure TfrmEditContact.MemoNotesChange(Sender: TObject);
begin
  btNotesSave.Enabled := Trim(MemoNotes.Text) <> '';
  btNotesClear.Enabled := btNotesSave.Enabled;
  if not (FUseSIMMode or FUseOwnMode) and Form1.IsK610orBetter then
    Modified := True // notes support in K610+ phones...
  else
    customModified := True; // ...or notes are FMA setting
  ApplyButton.Enabled := True;
end;

procedure TfrmEditContact.btNotesSaveClick(Sender: TObject);
begin
  if SaveDialog1.FileName = '' then
    SaveDialog1.FileName := txtName.Text + '.txt'; // do not localize
  if SaveDialog1.Execute then
    MemoNotes.Lines.SaveToFile(SaveDialog1.FileName);
end;

procedure TfrmEditContact.Set_CustomImage(const Value: Boolean);
begin
  FCustomImage := Value;
  if not Value then
    SelImage.Bitmap.Assign(Form1.CommonBitmaps.Bitmap[0]);
end;

procedure TfrmEditContact.txtChange(Sender: TObject);
begin
  DoSetModified;
end;

procedure TfrmEditContact.CancelButtonClick(Sender: TObject);
begin
  if (not ApplyButton.Enabled and not Modified and (not IsNew or (PhonesCount = 0))) or
    (MessageDlgW(_('Discard current changes?'), mtConfirmation, MB_YESNO or MB_DEFBUTTON2) = ID_YES) then
    ModalResult := mrCancel;
end;

function TfrmEditContact.PhonesCount: integer;
begin
  Result := 0;
  if txtCell.Text <> ''  then inc(Result);
  if txtHome.Text <> ''  then inc(Result);
  if txtWork.Text <> ''  then inc(Result);
  if txtFax.Text <> ''   then inc(Result);
  if txtOther.Text <> '' then inc(Result);
end;

function TfrmEditContact.Get_Notes: TTntStrings;
begin
  Result := MemoNotes.Lines;
end;

procedure TfrmEditContact.txtAddressTypeChange(Sender: TObject);
begin
  FSwappingAdr := True;
  try
    if FAddress <> -1 then with FAddresses[FAddress] do begin
      Street := txtStreet.text;
      City := txtCity.text;
      Region := txtRegion.text;
      PostalCode := txtPostalCode.text;
      Country := txtCountry.text;
    end;
    FAddress := txtAddressType.ItemIndex;
    with FAddresses[FAddress] do begin
      txtStreet.Text := Street;
      txtCity.Text := City;
      txtRegion.Text := Region;
      txtPostalCode.Text := PostalCode;
      txtCountry.Text := Country;
    end;
  finally
    FSwappingAdr := False;
  end;
end;

procedure TfrmEditContact.FillInternetAdrs;
var
  sl: TTntStringList;
  i: integer;
  w: WideString;
begin
  txtURL.Text := contact.homepage;
  lvEmails.Clear;
  if contact.email <> '' then
    with lvEmails.Items.Add do begin
      Caption := contact.email;
      ImageIndex := 1;
    end;
  sl := TTntStringList.Create;
  try
    sl.Text := contact.moremails;
    for i := 0 to sl.Count-1 do begin
      w := Trim(sl[i]);
      if w <> '' then
        with lvEmails.Items.Add do begin
          Caption := w;
          ImageIndex := 0;
        end;
    end;
  finally
    sl.Free;
    lvEmailsSelectItem(lvEmails,nil,False);
  end;
end;

function TfrmEditContact.PrefEmailIndex: integer;
var
  i: integer;
begin
  Result := -1;
  for i := 0 to lvEmails.Items.Count-1 do
    if lvEmails.Items[i].ImageIndex = 1 then begin
      Result := i;
      break;
    end;
end;

procedure TfrmEditContact.DoEmailCheck(AMail: WideString);
var
  i: integer;
begin
  i := Pos('@',AMail);
  if (i < 2) or (i > Length(AMail)-2) then begin
    MessageDlgW(_('Incorrect e-mail address specified.'),mtError,MB_OK);
    Abort;
  end;
end;

procedure TfrmEditContact.MailPrefButtonClick(Sender: TObject);
var
  i: integer;
begin
  i := PrefEmailIndex;
  if i <> lvEmails.Selected.Index then begin
    lvEmails.Items[i].ImageIndex := 0;
    lvEmails.Selected.ImageIndex := 1;
    DoSetModified;
    MailPrefButton.Enabled := False;
  end;
end;

procedure TfrmEditContact.MailAddButtonClick(Sender: TObject);
var
  w: WideString;
  i: integer;
begin
  w := '';
  if WideInputQuery(_('Add E-mail'),_('E-mail:'),w) then begin
    DoEmailCheck(w);
    i := PrefEmailIndex;
    with lvEmails.Items.Add do begin
      Caption := w;
      if i = -1 then ImageIndex := 1 else ImageIndex := 0;
    end;
    DoSetModified;
    lvEmailsSelectItem(lvEmails,lvEmails.Selected,Assigned(lvEmails.Selected));
  end;
end;

procedure TfrmEditContact.MailEditButtonClick(Sender: TObject);
var
  w: WideString;
begin
  w := lvEmails.Selected.Caption;
  if WideInputQuery(_('Edit E-mail'),_('E-mail:'),w) then begin
    DoEmailCheck(w);
    lvEmails.Selected.Caption := w;
    DoSetModified;
  end;
end;

procedure TfrmEditContact.MailDelButtonClick(Sender: TObject);
var
  i: integer;
begin
  if MessageDlgW(WideFormat(_('Delete e-mail address "%s"?'),[lvEmails.Selected.Caption]),
    mtConfirmation, MB_YESNO or MB_DEFBUTTON2) = ID_YES then begin
    lvEmails.Selected.Delete;
    i := PrefEmailIndex;
    if (i = -1) and (lvEmails.Items.Count <> 0) then
      lvEmails.Items[0].ImageIndex := 1;
    DoSetModified;
    lvEmailsSelectItem(lvEmails,nil,False);
  end;
end;

procedure TfrmEditContact.lvEmailsSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
  { Allow multiple e-mails for K610+ phones }
  MailAddButton.Enabled := Form1.IsK610orBetter or (lvEmails.Items.Count = 0);
  MailPrefButton.Enabled := Selected and (lvEmails.Selected.ImageIndex <> 1);
  MailEditButton.Enabled := Selected;
  MailDelButton.Enabled := Selected;
end;

procedure TfrmEditContact.DoSetModified;
begin
  if not FSwappingAdr then begin
    ApplyButton.Enabled := not IsNew;
    Modified := True;
  end;
end;

procedure TfrmEditContact.FillPostalAdrs;
begin
  FAddress := -1;
  FAddresses[0] := contact.homeAddress;
  FAddresses[1] := contact.workAddress;
  txtAddressType.ItemIndex := 0;
  txtAddressType.Enabled := Form1.IsK610orBetter;
  txtAddressTypeChange(nil);
end;

procedure TfrmEditContact.lvEmailsDblClick(Sender: TObject);
begin
  if Assigned(lvEmails.Selected) then MailEditButton.Click;
end;

procedure TfrmEditContact.BirthdayDeleteButtonClick(Sender: TObject);
begin
  if MessageDlgW(_('Clear birthday setting?'),mtConfirmation,MB_YESNO or MB_DEFBUTTON2) = ID_YES then begin
    txtBirthday.Date := EmptyDate;
    txtBirthdayChange(nil);
  end;
end;

procedure TfrmEditContact.txtBirthdayChange(Sender: TObject);
begin
  BirthdayDeleteButton.Enabled := txtBirthday.Enabled and not IsEmptyDate(txtBirthday.Date);
  DoSetModified;
end;

procedure TfrmEditContact.PostalDeleteButtonClick(Sender: TObject);
begin
  if MessageDlgW(WideFormat(_('Delete %s postal address?'),[txtAddressType.Text]),
    mtConfirmation,MB_YESNO or MB_DEFBUTTON2) = ID_YES then begin
    txtStreet.Text := '';
    txtCity.Text := '';
    txtRegion.Text := '';
    txtPostalCode.Text := '';
    txtCountry.Text := '';
  end;
end;

procedure TfrmEditContact.NumbersHistoryButtonClick(Sender: TObject);
begin
  with TfrmPhoneHistory.Create(nil) do begin
    Numbers := FMoreNumbers;
    if (ShowModal = mrOk) and (WideCompareText(FMoreNumbers,Numbers) <> 0) then begin
      FMoreNumbers := Numbers;
      SetCustomModified;
    end;
  end;
end;

procedure TfrmEditContact.SetCustomModified;
begin
  ApplyButton.Enabled := not IsNew;
  customModified := True;
end;

end.

⌨️ 快捷键说明

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