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

📄 usimedit.pas

📁 FMA is a free1 powerful phone editing tool allowing users to easily manage all of the personal data
💻 PAS
📖 第 1 页 / 共 4 页
字号:
                  sLinebreak+sLinebreak+
                  'Click Yes to replace number, or click No to add it as a New contact'),[F,contact^.pnumb,N]),
                mtConfirmation, MB_YESNOCANCEL or MB_DEFBUTTON2) of
                ID_YES: begin
                  //SyncLog(F + ' modified in FMA by Import.');
                  Modified := True;
                end;
                //mrNo: SyncLog(F + ' added in FMA by Import (as dublicate).');
                ID_CANCEL: Abort;
              end;
            //else SyncLog(F + ' added to FMA by Import.');
          end;
          //else SyncLog(F + ' added to FMA by Import.');
          if not Modified then begin
            Node := ListNumbers.AddChild(nil);
            contact := ListNumbers.GetNodeData(Node);
            contact^.position := FindFreePos;
            contact^.ptype := T;
          end;
          contact^.cname := F;
          contact^.pnumb := N;
          if Modified then begin
            contact^.imageindex := 1;
            inc(mods);
          end
          else begin
            contact^.imageindex := 0;
            inc(adds);
          end;
        end;
        ListNumbers.Update;
      end;
    finally
      sl.free;
      if (adds <> 0) or (mods <> 0) then begin
        //ListContacts.EndUpdate;
        ListNumbers.Sort(nil, ListNumbers.Header.SortColumn, ListNumbers.Header.SortDirection);
        Form1.UpdateSMPhonebook;
        Log.AddSynchronizationMessage('Imported '+IntToStr(adds+mods)+' item(s)... ('+
          IntToStr(adds)+' added, '+IntToStr(mods)+' modified)', lsDebug); // do not localize debug
      end;
    end;
  finally
    VCard.Free;
    FreeProgressDialog;
    //SyncLog(_('Import finished'));
    Form1.Status(_('Import complete.'));
  end;
end;

function TfrmContactsSMEdit.FindContact(FullName: WideString;
  var AContact: PSIMData): boolean;
var
  Node :PVirtualNode;
begin
  Result := False;
  Node := ListNumbers.GetFirst;
  while Node <> nil do
  try
    AContact := ListNumbers.GetNodeData(Node);
    if WideCompareText(FullName,AContact^.cname) = 0 then begin
      Result := True;
      break;
    end;
  finally
    Node := ListNumbers.GetNext(Node);
  end;
end;

function TfrmContactsSMEdit.FindContact(FullName: WideString;
  var ANode: PVirtualNode): boolean;
var
  Node :PVirtualNode;
  AContact: PSIMData;
begin
  Result := False;
  Node := ListNumbers.GetFirst;
  while Node <> nil do
  try
    AContact := ListNumbers.GetNodeData(Node);
    if WideCompareText(FullName,AContact^.cname) = 0 then begin
      ANode := Node;
      Result := True;
      break;
    end;
  finally
    Node := ListNumbers.GetNext(Node);
  end;
end;

function TfrmContactsSMEdit.FindContact(FullName, NumberType: WideString;
  var AContact: PSIMData): boolean;
var
  Node :PVirtualNode;
begin
  Result := False;
  Node := ListNumbers.GetFirst;
  while Node <> nil do
  try
    AContact := ListNumbers.GetNodeData(Node);
    if (WideCompareText(FullName,AContact^.cname) = 0) and
      (WideCompareText(NumberType,AContact^.ptype) = 0) then begin
      Result := True;
      break;
    end;
  finally
    Node := ListNumbers.GetNext(Node);
  end;
end;

procedure TfrmContactsSMEdit.ExportList(FileType: Integer; Filename: WideString);
var
  node: PVirtualNode;
  contact: PSIMData;
  AContact: TContactData;
  PContact: PContactData;
  sl: TStringList;
  str: WideString;
  VCard: TVCard;
  i: integer;
  s: string;
  XML: TXML;
  CurNodeName: string;
begin
  if FileType <> 1 then begin
    if MessageDlgW(_('FMA could Import only vCard contact exports. Do you still want to continue exporting?'),
      mtConfirmation, MB_YESNO or MB_DEFBUTTON2) <> ID_YES then
      exit;
  end;
  PContact := @AContact;
  case FileType of
    1:begin//vCard
        { TODO: export all records/numbers for a contact at once in a vCard file }
        VCard := TVCard.Create;
        sl := TStringList.Create;
        try
          with ListNumbers do begin
            node := GetFirst;
            if node <> nil then
            repeat
               try
                  if Selected[node] then begin
                     contact := GetNodeData(node);
                     FillChar(AContact,SizeOf(AContact),0);
                     SetContactFullName(PContact,contact^.cname);
                     if contact^.ptype = 'W' then PContact^.work := contact^.pnumb else // do not localize
                     if contact^.ptype = 'H' then PContact^.home := contact^.pnumb else // do not localize
                     if contact^.ptype = 'F' then PContact^.fax := contact^.pnumb else // do not localize
                     if contact^.ptype = 'O' then PContact^.other := contact^.pnumb else // do not localize
                       PContact^.cell := contact^.pnumb;
                     Contact2vCard(PContact,VCard);
                     sl.Clear;
                     sl.AddSTrings(VCard.Raw);
                     if ListNumbers.SelectedCount <> 1 then begin
                       str := contact^.ptype;
                       if str = 'O' then str := ''; // hide Other type
                       if str <> '' then str := ' ('+str+')';
                       str := Trim(contact^.cname) + str;
                       str := StringReplace(str,' ','-',[rfReplaceAll]);
                       str := WideChangeFileExt(FileName,'-'+str)+WideExtractFileExt(Filename);
                     end
                     else
                       str := Filename;
                     i := 0; s := str;
                     while WideFileExists(s) do begin
                       inc(i);
                       s := WideChangeFileExt(str,'') + ' (' + IntToStr(i) + ')' + WideExtractFileExt(str);
                     end;
                     sl.SaveToFile(s);
                  end;
               except
               end;
               node := GetNext(node);
            until node = nil;
          end;
        finally
          sl.Free;
          VCard.Free;
        end;
      end;
    2:begin//xml
        XML := TXML.Create();
        XML.TagName := 'fma_contacts'; // do not localize

        try
          with ListNumbers do
          begin
            node := GetFirst;
            if node <> nil then
            repeat
               try
                  if Selected[node] then
                  begin
                     contact := GetNodeData(node);
                     FillChar(AContact,SizeOf(AContact),0);
                     SetContactFullName(PContact,contact^.cname);

                     if contact^.ptype = 'W' then CurNodeName := 'work' else // do not localize
                     if contact^.ptype = 'H' then CurNodeName := 'home' else // do not localize
                     if contact^.ptype = 'F' then CurNodeName := 'fax' else // do not localize
                     if contact^.ptype = 'O' then CurNodeName := 'other' else // do not localize
                       CurNodeName := 'cell'; // do not localize

                     with XML.AddChild('contact') do // do not localize
                     begin
                      AddChild('name', HTMLEncode(WideStringToUTF8String(PContact^.name), False)); // do not localize
                      AddChild(CurNodeName, HTMLEncode(WideStringToUTF8String(contact^.pnumb), False));
                      AddChild('position', HTMLEncode(WideStringToUTF8String(IntToStr(contact^.position)), False)); // do not localize
                     end;
                  end;
               except
               end;
               node := GetNext(node);
            until node = nil;
          end;

          XML.Save(FileName);
        finally
          XML.Free();
        end;
      end;
    else
      raise Exception.Create(_('Not implemented yet'));
  end;
end;

procedure TfrmContactsSMEdit.DownloadEntirePhonebook1Click(Sender: TObject);
begin
  if MessageDlgW(_('Local Phonebook will be replaced with a fresh copy from the phone.'+sLinebreak+sLinebreak+
    'Any local changes will be lost. Do you wish to continue?'),
    mtConfirmation, MB_YESNO or MB_DEFBUTTON2) = ID_YES then begin
      ListNumbers.Clear;
      FullRefresh;
    end;
end;

procedure TfrmContactsSMEdit.ListNumbersKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_RETURN) and (ListNumbers.SelectedCount = 1) then
    btnEditClick(nil);
end;

procedure TfrmContactsSMEdit.FullRefresh;
begin
  Form1.ActionContactsDownload.Execute;
  UpdatePhonebook;
end;

procedure TfrmContactsSMEdit.FormStorage1SavePlacement(Sender: TObject);
var
  s: string;
  i: integer;
begin
  with ListNumbers.Header do begin
    s := IntToStr(SortColumn)+','+IntToStr(Ord(SortDirection));
    for i := 0 to Columns.Count-1 do
      s := s+','+IntToStr(Columns[i].Width)+','+IntToStr(Columns[i].Position);
  end;
  FormStorage1.StoredValue['ListHeader'] := s; // do not localize
end;

procedure TfrmContactsSMEdit.FormStorage1RestorePlacement(Sender: TObject);
var
  s: widestring;
  i: integer;
begin
  s := FormStorage1.StoredValue['ListHeader']; // do not localize
  if s <> '' then
    try
      with ListNumbers.Header do begin
        SortColumn := StrToInt(GetFirstToken(s));
        SortDirection := TSortDirection(StrToInt(GetFirstToken(s)));
        for i := 0 to Columns.Count-1 do begin
          Columns[i].Width := StrToInt(GetFirstToken(s));
          Columns[i].Position := StrToInt(GetFirstToken(s));
        end;
      end;
    except
    end;
end;

procedure TfrmContactsSMEdit.ListNumbersHeaderMouseUp(Sender: TVTHeader;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FormStorage1SavePlacement(nil);
end;

function TfrmContactsSMEdit.FindContact(Number: WideString): WideString;
var
  Node: PVirtualNode;
  contact: PSIMData;
begin
  Result := '';
  Node := ListNumbers.GetFirst;
  while Node <> nil do begin
    contact := ListNumbers.GetNodeData(Node);
    if CompareText(Form1.GetPartialNumber(Number),Form1.GetPartialNumber(contact.pnumb)) = 0 then begin
      Result := contact.cname;
      break;
    end;
    Node := ListNumbers.GetNext(Node);
  end;
end;

procedure TfrmContactsSMEdit.RenderGUIDs;
var
  contact: PSIMData;
  Node: PVirtualNode;
begin
  { Make sure all contacts' GUIDs are unique }
  Node := ListNumbers.GetFirst;
  while Node <> nil do begin
    contact := ListNumbers.GetNodeData(Node);
    repeat
      if IsUniqueGUID(contact) then break;
      contact.CDID := NewGUID;
    until False;
    Node := ListNumbers.GetNext(Node);
  end;
end;

function TfrmContactsSMEdit.IsUniqueGUID(who: PSIMData): boolean;
var
  Node: PVirtualNode;
  contact: PSIMData;
begin
  { Checks whether who contact has an unique GUID field }
  Result := True;
  Node := ListNumbers.GetFirst;
  while Node <> nil do begin
    contact := ListNumbers.GetNodeData(Node);
    if (contact <> who) and (GUIDToString(contact.CDID) = GUIDToString(who.CDID)) then begin
      Result := False;
      break;
    end;
    Node := ListNumbers.GetNext(Node);
  end;
end;

procedure TfrmContactsSMEdit.Modified1Click(Sender: TObject);
begin
  DoForceSelectedAs(1);
end;

procedure TfrmContactsSMEdit.CopySelectedToPhone1Click(Sender: TObject);
begin
  if Form1.IsIrmcSyncEnabled then
    CopySelectedToIRMC
  else
    CopySelectedToME;
end;

procedure TfrmContactsSMEdit.CopySelectedToIRMC;
var
  Item: PSIMData;
  Node,NewNode: PVirtualNode;
  Contact: PContactData;
  NewCnt,UpdCnt: cardinal;
  s,T,N: WideString;
  i,j,Answer: integer;
  procedure AddNumber(AName: WideString; ANumber: string);
  begin
    { If contact already exists? }
    if Form1.frmSyncPhonebook.FindContact(AName,contact) then begin
      { Check if the number already exists for that contact
      O := GetContactPhoneType(contact,s); // get type if number found in ME contact
      if O = '' then T := item.ptype
        else T := O;
      }
      T := item.ptype;
      {}
      if T = 'W' then N := contact^.work  else // do not localize
      if T = 'H' then N := contact^.home  else // do not localize
      if T = 'F' then N := contact^.fax   else // do not localize
      if T = 'O' then N := contact^.other else // do not localize
        N := contact^.cell; // Default to '' or 'M' phone type
      { Number position already filled in? }
      if N <> '' then
        if AnsiCompareStr(N,ANumber) <> 0 then begin
          CopyContactsConflict(Self,GetContactFullName(contact),
            _('Contact already exists in Phone Memory but has a different phone number specified.'),
            N,ANumber,_('Phone Memory'),_('SIM Memory'),Answer);
          case Answer of
            0: exit; // keep Phone one
            1: ; // copy SIM -> Phone
            else Abort;
          end;
          {
          case MessageDlgW(WideFormat(_('Contact "%s" already exists in Phone.')+sLinebreak+sLinebreak,[item.cname])+
            WideFormat(_('Do you want to replace [%s] with [%s]?'),[N,s]),
            mtConfirmation, MB_YESNOCANCEL or MB_DEFBUTTON2) of
            ID_NO: begin
              //inc(SkpCnt);
              exit;
            end;
            ID_CANCEL: Abort;
          end;
          }
        end
        else
          exit; // number found but is the same, so skip
      if T = 'W' then contact^.work := ANumber  else // do not localize
      if T = 'H' then contact^.home := ANumber  else // do not localize
      if T = 'F' then contact^.fax := ANumber   else // do not localize
      if T = 'O' then contact^.other := ANumber else // do not localize
        contact^.cell := ANumber;
      contact^.StateIndex := 1; // contact modified
      inc(UpdCnt);
    end
    else
    if Form1.frmSyncPhonebook.ListContacts.RootNodeCount < Form1.frmSyncPhonebook.FMaxRecME then begin
      NewNode := Form1.frmSyncPhonebook.ListContacts.AddChild(nil);
      contact := Form1.frmSyncPhonebook.ListContacts.GetNodeData(NewNode);
      FillChar(contact^,SizeOf(contact^),0);
      contact^.home := ANumber; // default number type is HOME
      contact^.StateIndex := 0; // new contact
      s := Copy(AName,1,Form1.frmSyncPhonebook.FMaxNameLen+byte(Pos(' ',AName) <> 0)); // sanity check name length
      j := Pos(', ',s);
      if j = 0 then begin
        j := Pos(' ',s);
        if j = 0 then
          contact^.name := s
        else begin
          contact^.name := Copy(s,1,j-1);
          contact^.surname := Copy(s,j+1,Length(s)-j);
        end;
      end
      else begin
        contact^.surname := Copy(s,1,j-1);
        contact^.name := Copy(s,j+2,Length(s)-j-1);
      end;
      inc(NewCnt);
    end
    else
      Abort;
  end;

⌨️ 快捷键说明

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