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

📄 usimedit.pas

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

procedure TfrmContactsSMEdit.ListNumbersCompareNodes(Sender: TBaseVirtualTree;
  Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
  SIM1, SIM2: PSIMData;
begin
  SIM1 := Sender.GetNodeData(Node1);
  SIM2 := Sender.GetNodeData(Node2);

  if Column = 0 then begin
    if SIM1.position > SIM2.position then
      Result := 1
    else
      if SIM1.position < SIM2.position then
        Result := -1
      else
        Result := 0;  
  end
  else if Column = 1 then Result := WideCompareStr(SIM1.cname, SIM2.cname)
  else if Column = 2 then Result := WideCompareStr(SIM1.pnumb, SIM2.pnumb);
end;

procedure TfrmContactsSMEdit.ListNumbersGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  SIM: PSIMData;
begin
  if Column = 0 then begin
    if (Kind = ikNormal) or (Kind = ikSelected) then begin
      SIM := Sender.GetNodeData(Node);
      ImageIndex := SIM.imageindex;
    end
    else ImageIndex := -1;
  end;
end;

procedure TfrmContactsSMEdit.ListNumbersGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
  SIM: PSIMData;
begin
  SIM := Sender.GetNodeData(Node);

  if Column = 0 then CellText := IntToStr(SIM.position)
  else if Column = 1 then CellText := SIM.cname
  else if Column = 2 then CellText := SIM.pnumb
  else if Column = 3 then begin
    CellText := '';
    if SIM.ptype = 'M' then CellText := _('Cell');
    if SIM.ptype = 'W' then CellText := _('Work');
    if SIM.ptype = 'H' then CellText := _('Home');
    if SIM.ptype = 'O' then CellText := _('Other');
    if SIM.ptype = 'F' then CellText := _('Fax');
  end
  else if Column = 4 then begin
    CellText := '';
    case SIM.imageindex of
      0: CellText := _('New contact');
      1: CellText := _('Modified contact');
      2: CellText := _('Deleted contact');
      3: CellText := '';
    end;
  end;
end;

procedure TfrmContactsSMEdit.ListNumbersHeaderClick(Sender: TVTHeader;
  Column: TColumnIndex; Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  if Button = mbLeft then begin
    if Column = Sender.SortColumn then begin
      if Sender.SortDirection = sdDescending then
        Sender.SortDirection := sdAscending
      else
        Sender.SortDirection := sdDescending;
    end
    else
      Sender.SortColumn := Column;
    ListNumbers.Sort(nil, ListNumbers.Header.SortColumn, ListNumbers.Header.SortDirection);
  end;
end;

procedure TfrmContactsSMEdit.btnEDITClick(Sender: TObject);
var
  Node :PVirtualNode;
begin
  Node := ListNumbers.FocusedNode;
  if Node <> nil then begin
    SelContact := ListNumbers.GetNodeData(Node);
    DoEdit;
  end;
end;

procedure TfrmContactsSMEdit.PopupMenu1Popup(Sender: TObject);
begin
  Properties1.Enabled := ListNumbers.SelectedCount = 1;
  DownloadEntirePhonebook1.Enabled := Form1.FConnected and not Form1.FObex.Connected;
  CopySelectedToPhone1.Enabled := ListNumbers.SelectedCount <> 0;
end;

function TfrmContactsSMEdit.DoEdit(AsNew: boolean; NewNumber: string): boolean;
var
  Node: PVirtualNode;
begin
  Result := False;
  with TfrmEditContact.Create(nil) do
  try
    FillChar(FContact,SizeOf(FContact),0);
    IsNew := AsNew or (Selcontact = nil);
    // set restrictions
    MaxFullNameLen :=  FMaxNameLen;
    txtName.MaxLength := FMaxNameLen;
    txtCell.MaxLength := FMaxTellen;
    // update FContact (see TContactData in uSyncPhonebook)
    if IsNew then begin
      FContact.cell := NewNumber;
    end
    else begin
      { Set contact name and surname }
      SetContactFullName(@FContact,Selcontact^.cname);
      FContact.LUID := Selcontact^.LUID;
      FContact.CDID := Selcontact^.CDID;
      { Set number according to phone type }
      if Selcontact^.pnumb <> '' then
        if Selcontact^.ptype = '' then
          FContact.home := Selcontact^.pnumb // if no number type specified, use home one (see bellow)
        else
          case Selcontact^.ptype[1] of
            'M': FContact.cell  := Selcontact^.pnumb;
            'W': FContact.work  := Selcontact^.pnumb;
            'H': FContact.home  := Selcontact^.pnumb;
            'F': FContact.fax   := Selcontact^.pnumb;
            'O': FContact.other := Selcontact^.pnumb;
          end;
    end;
    contact := FContact;
    UseSIMMode := True;
    // edit contact as a SIM entry  
    if ShowModal = mrOk then begin
      if Modified then with ListNumbers do begin
        // apply total updates
        BeginUpdate;
        try
          if IsNew then begin // create new node
            Node := AddChild(nil);
            Selcontact := ListNumbers.GetNodeData(Node);
            // new node, update IDs
            Selcontact^.LUID := '';
            Selcontact^.CDID := NewGUID;
            contact.LUID := '';
            contact.CDID := Selcontact^.CDID;
          end
          else
            Node := nil;

          { copy all data }
          FContact := contact;
          Selcontact^.cname := FContact.name;
          if FContact.surname <> '' then
            Selcontact^.cname := Selcontact^.cname + ' ' + FContact.surname;

          { get new number }
          if IsNew then begin
            if FContact.cell <> '' then begin
              Selcontact^.pnumb := FContact.cell;
              Selcontact^.ptype := 'M'; // do not localize
            end;
            if FContact.work <> '' then begin
              Selcontact^.pnumb := FContact.work;
              Selcontact^.ptype := 'W'; // do not localize
            end;
            if FContact.home <> '' then begin
              Selcontact^.pnumb := FContact.home;
              Selcontact^.ptype := 'H'; // do not localize
            end;
            if FContact.fax <> '' then begin
              Selcontact^.pnumb := FContact.fax;
              Selcontact^.ptype := 'F'; // do not localize
            end;
            if FContact.other <> '' then begin
              Selcontact^.pnumb := FContact.other;
              Selcontact^.ptype := 'O'; // do not localize
            end;
          end
          else
            if Selcontact^.ptype = '' then begin
              Selcontact^.pnumb := FContact.home; // if no number type specified, use home one (see above)
              Selcontact^.ptype := 'H';
            end
            else
              case Selcontact^.ptype[1] of
                'M': Selcontact^.pnumb := FContact.cell;
                'W': Selcontact^.pnumb := FContact.work;
                'H': Selcontact^.pnumb := FContact.home;
                'F': Selcontact^.pnumb := FContact.fax;
                'O': Selcontact^.pnumb := FContact.other;
              end;

          if IsNew then begin
            Selcontact^.imageindex := 0;
            // find free position
            Selcontact^.position := FindFreePos;
            if Selcontact^.position = -1 then begin
              DeleteNode(Node);
              MessageDlgW(_('No free position available'),mtError,MB_OK);
              Abort;
            end
            else
              Result := True;
          end
          else
            if Selcontact^.imageindex <> 0 then begin // mark as modified
              Selcontact^.imageindex := 1;
              Result := True;
            end;
        finally
          EndUpdate;
        end;
        UpdatePhonebook;
      end;
      if customModified then begin
        { save call notes to DB }
        SetContactNotes(@contact,ContactNotes);
        // no need to call UpdatePhonebook here
        Result := True;
      end;
    end;
  finally
    Free;
  end;
  ListNumbers.Sort(nil, ListNumbers.Header.SortColumn, ListNumbers.Header.SortDirection);
end;

procedure TfrmContactsSMEdit.NewPerson1Click(Sender: TObject);
begin
  if ListNumbers.RootNodeCount < FMaxNumbers then
    DoEdit(True)
  else
    MessageDlgW(_('No more space in memory! New contact can not be created.'), mtError, MB_OK);
end;

procedure TfrmContactsSMEdit.UpdateChanged1Click(Sender: TObject);
begin
  cbForce.Checked := False;
  btnUpdateSIM.Click;
end;

procedure TfrmContactsSMEdit.UpdateAllRecords1Click(Sender: TObject);
begin
  cbForce.Checked := True;
  btnUpdateSIM.Click;
end;

function TfrmContactsSMEdit.FindFreePos(NodeData: TStrings): integer;
var
  Node :PVirtualNode;
  Item: PSIMData;
  i,Pos,ItemPos: integer;
  found: boolean;
begin
  { if NodeData is NIL then search in current view }  
  Pos := 1;
  if Assigned(NodeData) then begin
    while Pos <= NodeData.Count do begin
      found := false;
      for i := 0 to NodeData.Count-1 do begin
        // item format: "name, numer, pos, state, guid, luid" 
        ItemPos := StrToInt(GetToken(NodeData[i],2));
        if ItemPos = Pos then begin
          found := true;
          break;
        end;
      end;
      if not found then break;
      Pos := Pos + 1;
    end;
  end
  else begin
    while cardinal(Pos) <= FMaxNumbers do begin
      found := false;
      Node := ListNumbers.GetFirst;
      while Assigned(Node) do
      try
        item := ListNumbers.GetNodeData(Node);
        if item.position = Pos then begin
          found := true;
          break;
        end;
      finally
        Node := ListNumbers.GetNext(Node);
      end;
      if not found then break;
      Pos := Pos + 1;
    end;
  end;
  if cardinal(Pos) <= FMaxNumbers then Result := Pos else Result := -1;
end;

procedure TfrmContactsSMEdit.UpdateContactsPosition1Click(Sender: TObject);
var
  Pos: Integer;
  Item: PSIMData;
  Node: PVirtualNode;
begin
  if MessageDlgW(_('Sorting contacts will replace all contacts position. Are you sure?'),
    mtConfirmation, MB_YESNO or MB_DEFBUTTON2) <> ID_YES then exit;
  Pos := 1;
  try
    Node := ListNumbers.GetFirst;
    while Node <> nil do
    try
      item := ListNumbers.GetNodeData(Node);
      if item.position <> Pos then begin
        item.position := Pos;
        item.imageindex := 1; // mark as modified
      end;
      inc(Pos);
    finally
      Node := ListNumbers.GetNext(Node);
    end;
  finally
    ListNumbers.Sort(nil, ListNumbers.Header.SortColumn, ListNumbers.Header.SortDirection);
    UpdatePhonebook;
  end;  
end;

function TfrmContactsSMEdit.IsMEMode: boolean;
begin
  Result := False; // was... FExplore = Form1.FNodeContactsME;
end;

procedure TfrmContactsSMEdit.UpdatePhonebook;
begin
  if IsMEMode then
    Form1.UpdateMEPhonebook
  else
    Form1.UpdateSMPhonebook;
end;

function TfrmContactsSMEdit.IsRendered: boolean;
begin
  { Do we have rendered data from currently selected Eplorer node? (ME or SM) }
  //Result := FRendered and (IsMEMode = (Form1.Explorer.Selected = Form1.FNodeContactsME));
  Result := FRendered;
end;

procedure TfrmContactsSMEdit.CheckForChanges;
var
  Modified: boolean;
  Contact: PSIMData;
  Node :PVirtualNode;
begin
  Modified := False;
  Node := ListNumbers.GetFirst;
  while Node <> nil do
  try
    Contact := ListNumbers.GetNodeData(Node);
    if Contact^.imageindex <> 3 then begin
      Modified := True;
      break;
    end;
  finally
    Node := ListNumbers.GetNext(Node);
  end;
  if Modified then UpdateChanged1.Click;
end;

procedure TfrmContactsSMEdit.ListNumbersIncrementalSearch(
  Sender: TBaseVirtualTree; Node: PVirtualNode;
  const SearchText: WideString; var Result: Integer);
var
  SIM: PSIMData;
  Text: WideString;
begin
  SIM := Sender.GetNodeData(Node);
  Text := Copy(SIM.cname,1,Length(SearchText));
  Result := WideCompareText(SearchText,Text);
end;

procedure TfrmContactsSMEdit.ImportContacts1Click(Sender: TObject);
var
  i,j,adds,mods: integer;
  Node: PVirtualNode;
  AContact: TContactData;
  PContact: PContactData;
  contact: PSIMData;
  sl: TStringList;
  F,N,T: WideString;
  Modified: boolean;
  dlg: TfrmConnect;
  VCard: TVCard;
begin
  if not OpenDialog1.Execute then exit;
  Update;
  PContact := @AContact;
  dlg := GetProgressDialog;
  VCard := TVCard.Create;
  try
    if Form1.CanShowProgress then
      dlg.ShowProgress(Form1.FProgressLongOnly);
    dlg.Initialize(OpenDialog1.Files.Count,_('Importing SIM contacts'));

    Form1.Status(_('Importing contacts...'));
    //SyncLog(_('Import started'));

    adds := 0; mods := 0;
    //ListContacts.BeginUpdate;
    sl := TStringList.Create;
    try
      for i := 0 to OpenDialog1.Files.Count-1 do begin
        sl.LoadFromFile(OpenDialog1.Files[i]);
        dlg.IncProgress(1);
        VCard.Clear;
        VCard.Raw := sl;
        vCard2Contact(VCard,PContact);
        F := GetvCardFullName(VCard);
        { Process all contact numbers }
        for j := 1 to 4 do begin
          case j of
            1: N := PContact^.cell;
            2: N := PContact^.work;
            3: N := PContact^.home;
            4: N := PContact^.other;
          end;
          if N = '' then continue;
          T := GetContactPhoneType(PContact,N);
          Modified := False;
          // ask to replace old record, if present
          if FindContact(F,T,contact) then begin
            { TODO: Add dialog with replace details }
            if T <> 'O' then // do not owerwrite Other type, but create a new record instead  // do not localize
              // (TODO: add wizard here) 
              case MessageDlgW(
                WideFormat(_('Contact %s already exists. Do you want to replace its current number [%s] with imported number [%s] ?'+

⌨️ 快捷键说明

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