📄 umsgview.pas
字号:
ResetAutoMarkAsReadTimer;
UpdatePropertiesStatus;
// we need to update actions (for drag&drop)
Form1.ActionSMSToFolder.Update;
pmListMsgPopup(nil);
end;
procedure TfrmMsgView.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Interval := 4000;
if ListMsg.SelectedCount <> 0 then
MarkasReadUnreadClick(MarkasRead1);
end;
procedure TfrmMsgView.MarkasReadUnreadClick(Sender: TObject);
begin
DoMarkMessages(TTntMenuItem(Sender).Tag <> 0);
end;
procedure TfrmMsgView.ListMsgDblClick(Sender: TObject);
begin
if Form1.ExplorerNew.FocusedNode = Form1.FNodeMsgDrafts then
SendMessage1Click(nil)
else
Properties1Click(nil);
end;
procedure TfrmMsgView.SendMessage1Click(Sender: TObject);
var
node: PVirtualNode;
item: PListData;
begin
if ListMsg.SelectedCount = 1 then begin
node := ListMsg.GetFirstSelected;
repeat
if ListMsg.Selected[node] then begin
item := ListMsg.GetNodeData(node);
Form1.ActionSMSNewMsg.Execute;
frmMessageContact.AddRecipient(item.from);
frmMessageContact.Memo.Text := '';
if IsLongSMSNode(node) then begin
if not frmMessageContact.btnLongSMS.Down then begin
frmMessageContact.btnLongSMS.Down := True;
frmMessageContact.btnLongSMS.Click;
end;
frmMessageContact.Memo.SelText := GetNodeLongText(node);
end
else
frmMessageContact.Memo.SelText := item.smsData.Text;
frmMessageContact.Memo.SelStart := Length(frmMessageContact.Memo.Text);
frmMessageContact.Memo.SetFocus;
{ Message is already in Drafts, so mark new message as not modified }
frmMessageContact.btnSave.Enabled := False;
break;
end;
node := ListMsg.GetNext(node);
until node = nil;
ListMsg.Update;
end;
end;
procedure TfrmMsgView.ImportTextMessages1Click(Sender: TObject);
var
ImpList: TStringList;
sl,dl: TStringList;
data: PFmaExplorerNode;
md: TFmaMessageData;
t,p,str: String;
i,j,Added,iBody,iDate,iState,iPDU,iNew: integer;
function IsMultilineBody(s: String): boolean;
var
i,j,l: integer;
begin
j := 0;
l := Length(s);
for i := 1 to l do
if s[i] = '"' then inc(j);
{ Quotes not closed or not all columns present? }
Result := (j mod 2 <> 0) or ((l <> 0) and (s[l] = ','));
end;
function PDUExists(aPDU: string): boolean;
var
i: integer;
sPDU: string;
begin
Result := False;
if sl.IndexOf(aPDU) <> -1 then
Result := True;
{
for i := 0 to sl.Count-1 do begin
sPDU := GetToken(sl[i], 5);
if AnsiCompareStr(aPDU,sPDU) = 0 then begin
Result := True;
break;
end;
end;
}
for i := 0 to dl.Count-1 do begin
sPDU := GetToken(dl[i], 5);
if AnsiCompareStr(aPDU,sPDU) = 0 then begin
Result := True;
break;
end;
end;
end;
begin
if (Form1.ExplorerNew.FocusedNode = nil) or not OpenDialog1.Execute then exit;
data := Form1.ExplorerNew.GetNodeData(Form1.ExplorerNew.FocusedNode);
sl := TStringList(data.Data);
Added := 0;
ImpList := TStringList.Create;
dl := TStringList.Create;
try
ImpList.LoadFromFile(OpenDialog1.FileName);
if ImpList.Count <= 1 then raise Exception.Create(_('Nothing to import'));
Form1.Status(_('Importing messages...'));
iBody := 0; iDate := 0; iState := 0; iPDU := 0; iNew := 0;
i := 0; str := '';
while i < ImpList.Count do begin
if Trim(ImpList[i]) <> '' then begin
str := str + ImpList[i];
if not IsMultilineBody(str) then begin
if iBody = 0 then begin // find fields mapping
for j := 0 to GetTokenCount(str)-1 do begin
{ Check ExportList() for details about header info:
"Subject","Body","From: (Name)","From: (Address)","From: (Type)","To: (Name)","To: (Address)","To: (Type)",
"Fma Date","Fma State","Fma PDU","Fma New" }
t := GetToken(str,j);
if AnsiCompareText(t,'Body') = 0 then iBody := j; // do not localize
if AnsiCompareText(t,'Fma Date') = 0 then iDate := j; // do not localize
if AnsiCompareText(t,'Fma State') = 0 then iState := j; // do not localize
if AnsiCompareText(t,'Fma PDU') = 0 then iPDU := j; // do not localize
if AnsiCompareText(t,'Fma IsNew') = 0 then iNew := j; // do not localize
end;
if (iBody = 0) or (iDate = 0) or (iState = 0) or (iPDU = 0) or (iNew = 0) then begin
MessageDlgW(_('Incorrect import file header!'),mtError,MB_OK);
Abort;
end;
end
else begin
t := '3,' + IntToStr(sl.Count + dl.Count + 1);
if StrToInt(GetToken(str,iState)) and $2000 <> 0 then // outgoing message
t := t + ',3,,,'
else
t := t + ',1,,,';
p := GetToken(str,iPDU);
t := t + p + ',"' + GetToken(str,iDate) + '",' + GetToken(str,iNew);
if Form1.FArchiveDublicates or not PDUExists(p) then begin
dl.Add(t);
inc(Added);
end;
end;
str := '';
end;
end;
inc(i);
end;
if Added <> 0 then begin
{ Add changes at once }
for i:=0 to dl.Count-1 do begin
md := TFmaMessageData.Create(dl[i]);
sl.AddObject(md.PDU, md);
end;
Form1.UpdateNewMessagesCounter(Form1.ExplorerNew.FocusedNode);
RenderListView(sl);
Log.AddSynchronizationMessage('Imported '+IntToStr(Added)+' item(s)...'); // do not localize debug
end;
finally
ImpList.Free;
dl.Free;
end;
Form1.Status(_('Import complete.'));
end;
procedure TfrmMsgView.Set_CustomImage(const Value: Boolean);
begin
if not Value and (FCustomImage <> Value) then
SelImage.Bitmap.Assign(Form1.CommonBitmaps.Bitmap[0]);
FCustomImage := Value;
end;
procedure TfrmMsgView.GetLongMsgData(Node: PVirtualNode; var ARef, ATot, An: Integer);
var
item: PListData;
begin
ARef := -1; ATot := -1; An := -1;
if Assigned(Node) then begin
item := ListMsg.GetNodeData(Node);
if Assigned(item) then begin
ARef := item.smsData.Reference;
ATot := item.smsData.Total;
An := item.smsData.MsgNum;
end;
end;
end;
function TfrmMsgView.GetNodeLongText(ANode: PVirtualNode): WideString;
var
sl: TTntStringList;
i: integer;
w: WideString;
begin
sl := TTntStringList.Create;
try
if Assigned(ANode) then
GetNodeLongList(ANode,sl);
w := '';
for i := 0 to sl.Count-1 do
w := w + sl[i];
Result := w;
finally
sl.Free;
end;
end;
function TfrmMsgView.GetNodeLongList(ANode: PVirtualNode;
var AList: TTntStringList): boolean;
var
Ref, ARef, Tot, ATot, An, FoundCount: Integer;
Node: PVirtualNode;
Up, Down: Integer;
GoDown, NoGoDown, NoGoUp: Boolean;
begin
Result := False;
{ This function will return a list of SMS parts where Objects property contains corresponding
Nodes (PVirtualNode) }
AList.Clear;
GetLongMsgData(ANode, Ref, Tot, An);
if Ref >= 0 then begin
with ListMsg do begin
FoundCount := 0;
NoGoDown := False;
NoGoUp := False;
Node := ANode;
Up := 0;
Down := 1;
while AList.Count < Tot do
AList.AddObject('',nil);
while Node <> nil do begin
GetLongMsgData(Node, ARef, ATot, An);
if (ARef = Ref) and (ATot = Tot) then begin
if (An > 0) and (An <= AList.Count) then begin
if not Assigned(AList.Objects[An-1]) then
Inc(FoundCount);
AList[An - 1] := PListData(GetNodeData(Node))^.smsData.Text;
AList.Objects[An - 1] := Pointer(Node); // keep track of the nodes containing Long SMS parts
if FoundCount = Tot then
Break;
end;
end;
GoDown := Down > 0;
if Down > 0 then
while (Down > 0) and (Node <> nil) do begin
Node := GetNext(Node);
Dec(Down);
Inc(Up);
end
else
while (Up > 0) and (Node <> nil) do begin
Node := GetPrevious(Node);
Dec(Up);
Inc(Down);
end;
if GoDown then
if (Node <> nil) and (Down = 0) then
Inc(Up)
else
if Node = nil then begin
Node := GetLast;
repeat
Node := GetPrevious(Node);
Dec(Up);
Inc(Down);
until (Up = 0) or (Node = nil);
NoGoDown := True;
end;
if not GoDown then
if (Node <> nil) and (Up = 0) then
Inc(Down)
else
if Node = nil then begin
Node := GetFirst;
repeat
Node := GetNext(Node);
Dec(Down);
Inc(Up);
until (Down = 0) or (Node = nil);
NoGoUp := True;
end;
if NoGoDown and NoGoUp then // All parts could not be found
Break;
if NoGoDown then begin
Up := 1;
Down := 0;
end;
if NoGoUp then begin
Down := 1;
Up := 0;
end;
end;
end;
Result := FoundCount = Tot;
end;
end;
function TfrmMsgView.IsLongSMSNode(ANode: PVirtualNode): boolean;
var
item: PListData;
begin
Result := False;
if not Assigned(ANode) then Exit;
item := ListMsg.GetNodeData(ANode);
if Assigned(item) then begin
Result := item.smsData.IsLong;
end;
end;
function TfrmMsgView.IsLongSMSFirstNode(ANode: PVirtualNode): boolean;
var
item: PListData;
begin
Result := False;
if not Assigned(ANode) then Exit;
item := ListMsg.GetNodeData(ANode);
if Assigned(item) then begin
Result := item.smsData.IsLongFirst;
end;
end;
function TfrmMsgView.FindSMS(APDU: string): PVirtualNode;
var
node: PVirtualNode;
item: PListData;
begin
Result := nil;
node := ListMsg.GetFirst;
while Assigned(node) do begin
item := ListMsg.GetNodeData(node);
if item.smsData.PDU = APDU then begin
Result := node;
break;
end;
node := ListMsg.GetNext(node);
end;
end;
procedure TfrmMsgView.ResetAutoMarkAsReadTimer;
begin
Timer1.Enabled := False;
Timer1.Enabled := (ListMsg.SelectedCount = 1) and PreviewPanel.Visible;
end;
procedure TfrmMsgView.FormStorage1SavePlacement(Sender: TObject);
var
s: string;
i: integer;
begin
Timer2.Enabled := False; // cancel search timer
with ListMsg.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 TfrmMsgView.FormStorage1RestorePlacement(Sender: TObject);
var
s: widestring;
i: integer;
begin
s := FormStorage1.StoredValue['ListHeader']; // do not localize
if s <> '' then
try
with ListMsg.Header do begin
SortColumn := StrToInt(GetFirstToken(s));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -