Browse Source

Cleanup: form logic

Herman Schoenfeld 7 years ago
parent
commit
2430ed4088

+ 0 - 1
Units/Forms/UFRMLogs.pas

@@ -62,7 +62,6 @@ begin
     end;
   end;
   memoLogs.Lines.Add(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',Time)+s+IntToHex(ThreadID,8)+' ['+CT_LogType[Logtype]+'] <'+sender+'> '+logtext);
-  //
 end;
 
 end.

+ 10 - 27
Units/Forms/UFRMMessages.pas

@@ -25,8 +25,6 @@ type
     memoMessageToSend: TMemo;
     procedure bbSendAMessageClick(Sender: TObject);
     procedure FormActivate(Sender: TObject);
-    procedure FormCreate(Sender: TObject);
-    procedure FormDestroy(Sender: TObject);
   private
     FMessagesUnreadCount : Integer;
     { private declarations }
@@ -37,15 +35,21 @@ type
     Procedure OnNodeMessageEvent(NetConnection : TNetConnection; MessageData : TRawBytes);
   end;
 
-var
-  FRMMessages: TFRMMessages = nil;
-
 implementation
-uses UFRMSyncronizationDialog, UUserInterface;// after implementation!
+
+uses UUserInterface;
+
 {$R *.lfm}
 
 { TFRMMessages }
 
+procedure TFRMMessages.FormActivate(Sender: TObject);
+begin
+  UpdateAvailableConnections;
+  TUserInterface.MessagesNotificationText := '';
+end;
+
+
 procedure TFRMMessages.OnNodeMessageEvent(NetConnection: TNetConnection; MessageData: TRawBytes);
 Var s : String;
 begin
@@ -54,7 +58,6 @@ begin
     s := DateTimeToStr(now)+' Message received from '+NetConnection.ClientRemoteAddr;
     memoMessages.Lines.Add(DateTimeToStr(now)+' Message received from '+NetConnection.ClientRemoteAddr+' Length '+inttostr(Length(MessageData))+' bytes');
     memoMessages.Lines.Add('RECEIVED> '+MessageData);
-    //HS if FRMWallet.FAppParams.ParamByName[CT_PARAM_ShowModalMessages].GetAsBoolean(false) then begin
     if TUserInterface.AppParams.ParamByName[CT_PARAM_ShowModalMessages].GetAsBoolean(false) then begin
       s := DateTimeToStr(now)+' Message from '+NetConnection.ClientRemoteAddr+#10+
          'Length '+inttostr(length(MessageData))+' bytes'+#10+#10;
@@ -154,24 +157,4 @@ begin
     'Message: '+#10+m),PChar(Application.Title),MB_ICONINFORMATION+MB_OK);
 end;
 
-procedure TFRMMessages.FormActivate(Sender: TObject);
-begin
-  UpdateAvailableConnections;
-  //HS FNodeNotifyEvents.Node := TUserInterface.Node;
-  TUserInterface.MessagesNotificationText := '';
-end;
-
-procedure TFRMMessages.FormCreate(Sender: TObject);
-begin
-  //HS FNodeNotifyEvents := TNodeNotifyEvents.Create(Self);
-  //HS FNodeNotifyEvents.OnBlocksChanged := TUserInterface.Wallet.OnNewAccount; //TODO: may be need move this function
-  //HS FNodeNotifyEvents.OnNodeMessageEvent := OnNodeMessageEvent;
-end;
-
-procedure TFRMMessages.FormDestroy(Sender: TObject);
-begin
-  //HS FNodeNotifyEvents.Node := Nil;
-  //HS FreeAndNil(FNodeNotifyEvents);
-end;
-
 end.

+ 60 - 64
Units/Forms/UFRMNodes.pas

@@ -66,77 +66,73 @@ Var i : integer;
  strings, sNSC, sRS, sDisc : TStrings;
  hh,nn,ss,ms : Word;
 begin
-  Try
-    if Not TNetData.NetData.NetConnections.TryLockList(100,l) then exit;
-    try
-      strings := memoNetConnections.Lines;
-      sNSC := TStringList.Create;
-      sRS := TStringList.Create;
-      sDisc := TStringList.Create;
-      strings.BeginUpdate;
-      Try
-        for i := 0 to l.Count - 1 do begin
-          NC := l[i];
-          If NC.Client.BytesReceived>0 then begin
-            sClientApp := '['+IntToStr(NC.NetProtocolVersion.protocol_version)+'-'+IntToStr(NC.NetProtocolVersion.protocol_available)+'] '+NC.ClientAppVersion;
-          end else begin
-            sClientApp := '(no data)';
-          end;
+  if Not TNetData.NetData.NetConnections.TryLockList(100,l) then exit;
+  try
+    strings := memoNetConnections.Lines;
+    sNSC := TStringList.Create;
+    sRS := TStringList.Create;
+    sDisc := TStringList.Create;
+    strings.BeginUpdate;
+    Try
+      for i := 0 to l.Count - 1 do begin
+        NC := l[i];
+        If NC.Client.BytesReceived>0 then begin
+          sClientApp := '['+IntToStr(NC.NetProtocolVersion.protocol_version)+'-'+IntToStr(NC.NetProtocolVersion.protocol_available)+'] '+NC.ClientAppVersion;
+        end else begin
+          sClientApp := '(no data)';
+        end;
 
-          if NC.Connected then begin
-            if NC.Client.LastCommunicationTime>1000 then begin
-              DecodeTime(now - NC.Client.LastCommunicationTime,hh,nn,ss,ms);
-              if (hh=0) and (nn=0) And (ss<10) then begin
-                sLastConnTime := ' - Last comunication <10 sec.';
-              end else begin
-                sLastConnTime := Format(' - Last comunication %.2dm%.2ds',[(hh*60)+nn,ss]);
-              end;
-            end else begin
-              sLastConnTime := '';
-            end;
-            if NC is TNetServerClient then begin
-              sNSC.Add(Format('Client: IP:%s Block:%d Sent/Received:%d/%d Bytes - %s - Time offset %d - Active since %s %s',
-                [NC.ClientRemoteAddr,NC.RemoteOperationBlock.block,NC.Client.BytesSent,NC.Client.BytesReceived,sClientApp,NC.TimestampDiff,DateTimeElapsedTime(NC.CreatedTime),sLastConnTime]));
+        if NC.Connected then begin
+          if NC.Client.LastCommunicationTime>1000 then begin
+            DecodeTime(now - NC.Client.LastCommunicationTime,hh,nn,ss,ms);
+            if (hh=0) and (nn=0) And (ss<10) then begin
+              sLastConnTime := ' - Last comunication <10 sec.';
             end else begin
-              if NC.IsMyselfServer then sNSC.Add(Format('MySelf IP:%s Sent/Received:%d/%d Bytes - %s - Time offset %d - Active since %s %s',
-                [NC.ClientRemoteAddr,NC.Client.BytesSent,NC.Client.BytesReceived,sClientApp,NC.TimestampDiff,DateTimeElapsedTime(NC.CreatedTime),sLastConnTime]))
-              else begin
-                sRS.Add(Format('Remote Server: IP:%s Block:%d Sent/Received:%d/%d Bytes - %s - Time offset %d - Active since %s %s',
-                [NC.ClientRemoteAddr,NC.RemoteOperationBlock.block,NC.Client.BytesSent,NC.Client.BytesReceived,sClientApp,NC.TimestampDiff,DateTimeElapsedTime(NC.CreatedTime),sLastConnTime]));
-              end;
+              sLastConnTime := Format(' - Last comunication %.2dm%.2ds',[(hh*60)+nn,ss]);
             end;
           end else begin
-            if NC is TNetServerClient then begin
-              sDisc.Add(Format('Disconnected client: IP:%s - %s',[NC.ClientRemoteAddr,sClientApp]));
-            end else if NC.IsMyselfServer then begin
-              sDisc.Add(Format('Disconnected MySelf IP:%s - %s',[NC.ClientRemoteAddr,sClientApp]));
-            end else begin
-              sDisc.Add(Format('Disconnected Remote Server: IP:%s %s - %s',[NC.ClientRemoteAddr,CT_BooleanToString[NC.Connected],sClientApp]));
+            sLastConnTime := '';
+          end;
+          if NC is TNetServerClient then begin
+            sNSC.Add(Format('Client: IP:%s Block:%d Sent/Received:%d/%d Bytes - %s - Time offset %d - Active since %s %s',
+              [NC.ClientRemoteAddr,NC.RemoteOperationBlock.block,NC.Client.BytesSent,NC.Client.BytesReceived,sClientApp,NC.TimestampDiff,DateTimeElapsedTime(NC.CreatedTime),sLastConnTime]));
+          end else begin
+            if NC.IsMyselfServer then sNSC.Add(Format('MySelf IP:%s Sent/Received:%d/%d Bytes - %s - Time offset %d - Active since %s %s',
+              [NC.ClientRemoteAddr,NC.Client.BytesSent,NC.Client.BytesReceived,sClientApp,NC.TimestampDiff,DateTimeElapsedTime(NC.CreatedTime),sLastConnTime]))
+            else begin
+              sRS.Add(Format('Remote Server: IP:%s Block:%d Sent/Received:%d/%d Bytes - %s - Time offset %d - Active since %s %s',
+              [NC.ClientRemoteAddr,NC.RemoteOperationBlock.block,NC.Client.BytesSent,NC.Client.BytesReceived,sClientApp,NC.TimestampDiff,DateTimeElapsedTime(NC.CreatedTime),sLastConnTime]));
             end;
           end;
+        end else begin
+          if NC is TNetServerClient then begin
+            sDisc.Add(Format('Disconnected client: IP:%s - %s',[NC.ClientRemoteAddr,sClientApp]));
+          end else if NC.IsMyselfServer then begin
+            sDisc.Add(Format('Disconnected MySelf IP:%s - %s',[NC.ClientRemoteAddr,sClientApp]));
+          end else begin
+            sDisc.Add(Format('Disconnected Remote Server: IP:%s %s - %s',[NC.ClientRemoteAddr,CT_BooleanToString[NC.Connected],sClientApp]));
+          end;
         end;
-        strings.Clear;
-        strings.Add(Format('Connections Updated %s Clients:%d Servers:%d (valid servers:%d)',[DateTimeToStr(now),sNSC.Count,sRS.Count,TNetData.NetData.NetStatistics.ServersConnectionsWithResponse]));
-        strings.AddStrings(sRS);
-        strings.AddStrings(sNSC);
-        if sDisc.Count>0 then begin
-          strings.Add('');
-          strings.Add('Disconnected connections: '+Inttostr(sDisc.Count));
-          strings.AddStrings(sDisc);
-        end;
-      Finally
-        strings.EndUpdate;
-        sNSC.Free;
-        sRS.Free;
-        sDisc.Free;
-      End;
-      //CheckMining;
-    finally
-      TNetData.NetData.NetConnections.UnlockList;
-    end;
-  Finally
-    //FMustProcessNetConnectionUpdated := false;
-  End;
+      end;
+      strings.Clear;
+      strings.Add(Format('Connections Updated %s Clients:%d Servers:%d (valid servers:%d)',[DateTimeToStr(now),sNSC.Count,sRS.Count,TNetData.NetData.NetStatistics.ServersConnectionsWithResponse]));
+      strings.AddStrings(sRS);
+      strings.AddStrings(sNSC);
+      if sDisc.Count>0 then begin
+        strings.Add('');
+        strings.Add('Disconnected connections: '+Inttostr(sDisc.Count));
+        strings.AddStrings(sDisc);
+      end;
+    Finally
+      strings.EndUpdate;
+      sNSC.Free;
+      sRS.Free;
+      sDisc.Free;
+    End;
+    //CheckMining;
+  finally
+    TNetData.NetData.NetConnections.UnlockList;
+  end;
 end;
 
 procedure TFRMNodes.OnNetConnectionsUpdated;

+ 0 - 11
Units/Forms/UFRMWallet.pas

@@ -242,22 +242,11 @@ end;
 
 procedure TFRMWallet.miMessagesClick(Sender: TObject);
 begin
-  //HS
-  //// in memory for not exit program - Application.Exit - auto free mem not need control free manual for this send Self!
-  //if FRMMessages = nil then FRMMessages:=TFRMMessages.Create(Self);
-  //SetSubFormCoordinate(FRMMessages);
-  //FRMMessages.show;
   TUserInterface.ShowMessagesForm;
 end;
 
 procedure TFRMWallet.miSyncDialogClick(Sender:TObject);
 begin
-  //HS
-  // in memory for not exit program - Application.Exit - auto free mem not need control free manual for this send Self!
-  //if FRMSyncronizationDialog = nil then FRMSyncronizationDialog:=TFRMSyncronizationDialog.Create(Self);
-  //SetSubFormCoordinate(FRMSyncronizationDialog);
-  //FRMSyncronizationDialog.Visible:=not FRMSyncronizationDialog.Visible;
-
   TUserInterface.ShowSyncronizationDialog(Self);
 end;
 

+ 3 - 3
Units/Forms/UUserInterface.pas

@@ -76,7 +76,7 @@ type
       // Blockchain event handlers. TODO: refactor this out with TNotifyEvents
       // so forms that need these messages subscribe directly
       class procedure OnAccountsChanged(Sender: TObject);
-      class procedure OnNewAccount(Sender: TObject);
+      class procedure OnBlocksChanged(Sender: TObject);
       class procedure OnReceivedHelloMessage(Sender: TObject);
       class procedure OnNodeMessageEvent(NetConnection: TNetConnection; MessageData: TRawBytes);
       class procedure OnNetStatisticsChanged(Sender: TObject);
@@ -215,7 +215,7 @@ begin
 
     // Subscribe to Node events (TODO refactor with FNotifyEvents)
     FNodeNotifyEvents := TNodeNotifyEvents.Create(FWallet);
-    FNodeNotifyEvents.OnBlocksChanged := OnNewAccount;
+    FNodeNotifyEvents.OnBlocksChanged := OnBlocksChanged;
     FNodeNotifyEvents.OnNodeMessageEvent :=  OnNodeMessageEvent;
 
     // Start RPC server
@@ -940,7 +940,7 @@ begin
   end;
 end;
 
-class procedure TUserInterface.OnNewAccount(Sender: TObject);
+class procedure TUserInterface.OnBlocksChanged(Sender: TObject);
 begin
   FUILock.Acquire;
   try