📄 usimedit.pas
字号:
begin
if MessageDlgW(WideFormat(_('Confirm sending %d %s to Phone Memory?'),
[ListNumbers.SelectedCount,ngettext('contact','contacts',ListNumbers.SelectedCount)]),
mtConfirmation,MB_YESNO) <> ID_YES then
exit;
ResetConflictState;
Answer := 0;
NewCnt := 0;
UpdCnt := 0;
Form1.frmSyncPhonebook.ListContacts.BeginUpdate;
try
with ListNumbers do begin
Node := GetFirst;
while Assigned(Node) do begin
if Selected[Node] then
try
item := GetNodeData(Node);
{ Sanity check phone number length }
i := Form1.frmSyncPhonebook.FMaxTellen;
if Length(item.pnumb) < i then i := Length(item.pnumb);
s := Copy(item.pnumb,1+Length(item.pnumb)-i,i);
if s <> '' then AddNumber(item.cname,s);
except
if Form1.frmSyncPhonebook.ListContacts.RootNodeCount >= Form1.frmSyncPhonebook.FMaxRecME then break;
end;
Node := GetNext(Node);
end;
end;
finally
if (NewCnt <> 0) or (UpdCnt <> 0) then begin
with Form1.frmSyncPhonebook do begin
ListContacts.Sort(nil, ListContacts.Header.SortColumn, ListContacts.Header.SortDirection);
ListContacts.Update;
end;
Form1.UpdateMEPhonebook;
end
else
Form1.frmSyncPhonebook.ListContacts.Update;
Form1.Status(WideFormat(_('Copy to Phone: %d new, %d modified and %d items skipped'),
[NewCnt, UpdCnt, Cardinal(ListNumbers.SelectedCount) - NewCnt - UpdCnt]));
end;
end;
procedure TfrmContactsSMEdit.CopySelectedToME;
var
NewCnt,UpdCnt,SkpCnt,Answer: integer;
dl: TStrings;
node: PVirtualNode;
contact: PSIMData;
data1,data2: PFmaExplorerNode;
cname: WideString;
procedure AddNumber(AName,Kind: WideString; ANumber: string);
var
cnode,nnode: PVirtualNode;
i,j,image,FoundIndex,cpos: Integer;
utf8s: String;
begin
cpos := FindFreePos(dl);
if cpos = -1 then Abort;
FoundIndex := -1;
{ Try to locate contact }
cnode := Form1.FindExplorerChildNode(AName,Form1.FNodeContactsME);
if Assigned(cnode) then begin
if Kind = 'H' then image := 9 // do not localize
else if Kind = 'M' then image := 10 // do not localize
else if Kind = 'W' then image := 11 // do not localize
else if Kind = 'F' then image := 12 // do not localize
else image := 13;
{ Try to locate contact's number of the same kind }
nnode := Form1.ExplorerNew.GetFirstChild(cnode);
while Assigned(nnode) do begin
data1 := Form1.ExplorerNew.GetNodeData(nnode);
if data1.ImageIndex = image then begin
FoundIndex := data1.StateIndex;
break;
end;
nnode := Form1.ExplorerNew.GetNextSibling(nnode);
end;
if FoundIndex <> -1 then begin
if AnsiCompareStr(data1.Text,ANumber) <> 0 then begin
CopyContactsConflict(Self,data1.Text,
_('Contact already exists in Phone Memory but has a different phone number specified.'),
data1.Text,ANumber,_('Phone Memory'),_('SIM Memory'),Answer);
case Answer of
0: begin
inc(SkpCnt);
exit; // keep Phone one
end;
1: dl.Delete(FoundIndex); // copy SIM -> Phone
else Abort;
end;
{
case MessageDlgW(WideFormat(_('Contact "%s" already exists in Phone book.')+sLinebreak+sLinebreak,[AName])+
WideFormat(_('Do you want to replace [%s] with [%s]?'),[data1.Text,ANumber]),
mtConfirmation, MB_YESNOCANCEL or MB_DEFBUTTON2) of
ID_YES: dl.Delete(FoundIndex);
ID_NO: begin
inc(SkpCnt);
exit;
end;
ID_CANCEL: Abort;
end;
}
end
else begin
inc(SkpCnt);
exit; // number found but is the same, so exit
end;
end;
end;
{ Sanity check phone number length }
i := Form1.frmMEEdit.FMaxTelLen + byte(Pos('+',ANumber) <> 0);
j := Length(ANumber);
if j < i then i := j;
ANumber := Copy(ANumber,1+j-i,i);
{ Add to SIM database }
if Kind <> '' then Kind := '/' + Kind;
utf8s := UTF8Encode(WideQuoteStr(AName + Kind, True));
dl.Add(utf8s + ',' + WideStringToLongString(ANumber) + ',' + IntToStr(cpos) + ',1,' + // and mark (1) as modified
GUIDToString(NewGUID)+','); // No LUID
if FoundIndex = -1 then inc(NewCnt) else inc(UpdCnt);
end;
begin
if MessageDlgW(WideFormat(_('Confirm sending %d %s to Phone Memory?'),
[ListNumbers.SelectedCount,ngettext('contact','contacts',ListNumbers.SelectedCount)]),
mtConfirmation,MB_YESNO) <> ID_YES then
exit;
ResetConflictState;
Answer := 0;
NewCnt := 0;
UpdCnt := 0;
SkpCnt := 0;
data2 := Form1.ExplorerNew.GetNodeData(Form1.FNodeContactsME);
dl := TStrings(data2.Data); // destination
(*
if dl.Count <> 0 then
case MessageDlgW(_('Do you want to DELETE all Phone entries before copy? (No Undo)'),
mtConfirmation, MB_YESNOCANCEL or MB_DEFBUTTON2) of
ID_YES: begin
{ Clear SIM database }
dl.Clear;
Form1.ExplorerNew.DeleteChildren(Form1.FNodeContactsME);
end;
ID_CANCEL: exit;
end;
*)
try
with ListNumbers do begin
node := GetFirst;
while Assigned(Node) do begin
if Selected[node] then
try
contact := GetNodeData(node);
cname := contact^.cname;
cname := Copy(cname,1,Form1.frmMEEdit.FMaxNameLen);
if contact^.pnumb <> '' then AddNumber(cname,contact^.ptype,contact^.pnumb);
except
if Cardinal(dl.Count) >= Form1.frmMEEdit.FMaxNumbers then break;
end;
node := GetNext(node);
end;
end;
finally
if (NewCnt <> 0) or (UpdCnt <> 0) then begin
Form1.RenderContactList(Form1.FNodeContactsME);
{ Update view }
Form1.frmMEEdit.RenderData(Form1.FNodeContactsME);
end;
Form1.Status(WideFormat(_('Copy to Phone: %d new, %d modified and %d items skipped'),
[NewCnt, UpdCnt, SkpCnt]));
end;
end;
procedure TfrmContactsSMEdit.CopyContactsConflict(Sender: TObject;
ContactName: WideString; const Description: WideString; Phone0,
Phone1: string; const Item0Name, Item1Name: WideString;
var SelectedItem: Integer);
begin
if FConflictAnswer = 2 then begin // ask me?
frmPromptConflict := TfrmPromptConflict.Create(Self);
try
FConflictPhone0 := Phone0;
FConflictPhone1 := Phone1;
{ Default frmPromptConflict.ObjKind is 'contact' }
frmPromptConflict.ObjName := ContactName;
frmPromptConflict.Info := Description;
frmPromptConflict.Item0Name := Item0Name;
frmPromptConflict.Item1Name := Item1Name;
frmPromptConflict.SelectedItem := SelectedItem;
frmPromptConflict.OnViewChanges := OnConflictChanges;
frmPromptConflict.CanBeAborted := True;
if frmPromptConflict.ShowModal = mrOK then begin
SelectedItem := frmPromptConflict.SelectedItem;
if frmPromptConflict.cbDontAskAgain.Checked then begin
{ Use the same answer for all next conflicts }
FConflictAnswer := SelectedItem;
end;
end
else
SelectedItem := -1;
finally
frmPromptConflict.Free;
end;
end
else
SelectedItem := FConflictAnswer;
end;
procedure TfrmContactsSMEdit.OnConflictChanges(Sender: TObject;
const TargetName, Option1Name, Option2Name: WideString);
begin
with TfrmConflictChanges.Create(nil) do
try
Target := TargetName;
Option1 := Option1Name;
Option2 := Option2Name;
if AnsiCompareStr(FConflictPhone0,FConflictPhone1) <> 0 then
AddChange(_('Number'),FConflictPhone0,FConflictPhone1);
if ChangeCount <> 0 then ShowModal
else MessageDlgW(_('No changes found.'), mtInformation, MB_OK);
finally
Free;
end;
end;
procedure TfrmContactsSMEdit.ResetConflictState;
begin
FConflictAnswer := 2;
end;
procedure TfrmContactsSMEdit.DoForceSelectedAs(State: integer);
var
Item: PSIMData;
Node: PVirtualNode;
begin
ListNumbers.BeginUpdate;
Node := ListNumbers.GetFirst;
while Node <> nil do
try
if ListNumbers.Selected[Node] then begin
item := ListNumbers.GetNodeData(Node);
if item.imageindex <> 0 then item.imageindex := State;
end;
finally
Node := ListNumbers.GetNext(Node);
end;
ListNumbers.EndUpdate;
UpdatePhonebook;
end;
procedure TfrmContactsSMEdit.frmSyncPhonebookNewNoUndo1Click(
Sender: TObject);
begin
DoForceSelectedAs(0);
end;
procedure TfrmContactsSMEdit.UploadChangesToPhone(IsMEMode: boolean;
var ListNumbers: TVirtualStringTree; ModifiedCount, MaxNumbers, MaxNameLen: cardinal;
UploadAll: boolean);
var
PerformCleanup: boolean;
i,maxPos,numType: Integer;
cname, number: WideString;
w, buf: string;
Item: PSIMData;
Tmp,Node: PVirtualNode;
frmConnect: TfrmConnect;
target: string;
begin
{ WARNING! WARNING! WARNING!
This proc is called from both frmMEEdit and frmSMEdit -- check IsMEMode value }
Form1.RequestConnection;
if IsMEMode then
target := _('Phonebook')
else
target := _('SIM book');
PerformCleanup := ModifiedCount = ListNumbers.RootNodeCount;
Log.AddSynchronizationMessageFmt(_('Update %s started.'),[target]);
frmConnect := GetProgressDialog;
try
if Form1.CanShowProgress then
frmConnect.ShowProgress(Form1.FProgressLongOnly);
if ModifiedCount > 0 then
frmConnect.Initialize(ModifiedCount,WideFormat(_('Updating %s'),[target]))
else
frmConnect.SetDescr(WideFormat(_('Updating %s'),[target]));
Form1.Status(_('Uploading contacts...'));
maxPos := 0;
try
if IsMEMode then
Form1.TxAndWait('AT+CPBS="ME"') // do not localize
else
Form1.TxAndWait('AT+CPBS="SM"'); // do not localize
try
Node := ListNumbers.GetFirst;
while Assigned(Node) and not ThreadSafe.AbortDetected do
try
item := ListNumbers.GetNodeData(Node);
if (item.imageindex <> 3) or UploadAll then begin
numType := 129;
cname := item.cname;
Number := item.pnumb;
if maxPos <= item.position then maxPos := item.position;
buf := 'AT+CPBW=' + IntToStr(item.position); // do not localize
{ First clear the position -- needed for K610+ phones }
try
Form1.TxAndWait(buf);
except
end;
if Item.imageindex <> 2 then begin
// Upload to phone
if Number[1] = '+' then begin
Number := copy(Number, 2, Length(Number)-1);
numType := 145;
end;
if Form1.FUseUTF8 then w := UTF8Encode(cname) else w := cname;
{ Remove number type from SIM entries, added by previous FMA releases }
i := Length(w);
if (i > 2) and (w[i-1] = '/') and (Char(w[i]) in ['M','H','W','F','O']) then // do not localize
Delete(w,i-1,2);
{ SE Documentation Notes:
- If phone is the currently selected phonebook storage, <text> will be
interpreted as "first name" + white space + "last name" when stored in
the hierarchical phonebook. The phone number will be stored as of type
"other".
- When writing to SM, <text> shall be written as "last name" + comma +
white space + "first name" + "/" + <type_of_number>.
Example: "Smith, John/W"
<type_of_number> Description
"H" Home Default setting
"W" Work
"O" Other
"M" Mobile
"F" Fax
}
{ Format SIM card names as "Last, First" -- disabled
if not IsMEMode then begin
i := Pos(' ',w);
if i <> 0 then
w := WideTrim(WideCopy(w,i+1,Length(w)-i) + ', ' + WideCopy(w,1,i-1));
end;
}
{ Add number type }
if (Length(w) < (integer(MaxNameLen)-1)) and (item.ptype <> '') then
case item.ptype[1] of
'M': w := w + '/M'; // do not localize
'H': w := w + '/H'; // do not localize
'W': w := w + '/W'; // do not localize
'F': w := w + '/F'; // do not localize
'O': w := w + '/O'; // do not localize
end;
{ Next upload it }
buf := buf + ',"' + Number + '",' + IntToStr(numType) + ',"' + w + '"'; // do not localize
Form1.TxAndWait(buf);
Item.imageindex := 3; // mark as not modified
Log.AddSynchronizationMessageFmt(_('%s stored in %s by FMA.'),[cname, target], lsInformation);
end
else
// Delete (already done)
Log.AddSynchronizationMessageFmt(_('%s deleted in %s by FMA.'),[cname, target], lsInformation);
end;
finally
frmConnect.IncProgress(1);
if Item.imageindex = 2 then begin
Tmp := Node;
Node := ListNumbers.GetNext(Node);
ListNumbers.DeleteNode(Tmp);
end
else
Node := ListNumbers.GetNext(Node);
ListNumbers.Repaint;
end;
{ Ususaly happens when you rearrange contacts positions, i.e. modify all of them }
if PerformCleanup then
try
Form1.Status(_('Performing cleanup...'));
frmConnect.SetDescr(_('Performing cleanup'));
frmConnect.ClearMaxProgress;
Form1.SetTaskPercentage(0, MaxNumbers - Cardinal(maxPos));
for i := maxPos + 1 to MaxNumbers do
try
Form1.SetTaskPercentageInc;
buf := 'AT+CPBW=' + IntToStr(i); // do not localize
Form1.TxAndWait(buf);
except
end;
finally
Form1.SetTaskPercentage(-1);
end;
finally
{ This proc is called from both frmMEEdit and frmSMEdit }
if IsMEMode then
Form1.frmMEEdit.UpdatePhonebook
else
Form1.frmSMEdit.UpdatePhonebook;
end;
except
Form1.Status(_('Error updating memory'));
Log.AddSynchronizationMessageFmt(_('Update %s failed.'),[target], lsError);
end;
{ All Done }
if not ThreadSafe.AbortDetected then
Log.AddSynchronizationMessageFmt(_('Updating %s completed.'),[target])
else
Log.AddSynchronizationMessage(_('Update aborted by user.'));
finally
FreeProgressDialog;
end;
Form1.Status('');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -