source: branches/2/UNetworkTest.pas

Last change on this file was 1, checked in by george, 17 years ago

Přidáno: Verze 2.10 do vývojové větve 2.

  • Property svn:executable set to *
File size: 6.1 KB
Line 
1unit UNetworkTest;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, UPing, ComCtrls, StdCtrls, cUtils, cWinSock, Spin;
8
9type
10 TPingList = class(TThread)
11 private
12 { Private declarations }
13 protected
14 procedure Execute; override;
15 end;
16
17 TNetworkTest = class(TForm)
18 Button1: TButton;
19 ListView1: TListView;
20 Button2: TButton;
21 SpinEdit1: TSpinEdit;
22 Label1: TLabel;
23 ComboBox1: TComboBox;
24 procedure Button1Click(Sender: TObject);
25 procedure FormCreate(Sender: TObject);
26 procedure FormShow(Sender: TObject);
27 procedure Button2Click(Sender: TObject);
28 procedure CheckBox1Click(Sender: TObject);
29 procedure SpinEdit1Change(Sender: TObject);
30 procedure ComboBox1Change(Sender: TObject);
31 private
32 { Private declarations }
33 public
34 PingList: TPingList;
35 Devices: array of record
36 ID: Integer;
37 IP: string;
38 Name: string;
39 Place: string;
40 Parent: Integer;
41 Sort: Integer;
42 end;
43 LocalPCID: Integer;
44 procedure RefreshList;
45 function IndexByID(WantedID: Integer): Integer;
46 end;
47
48var
49 NetworkTest: TNetworkTest;
50
51implementation
52
53uses UMainWindow, ULocalization, USunriseChatCore;
54
55{$R *.dfm}
56
57procedure TNetworkTest.Button1Click(Sender: TObject);
58begin
59 Close;
60end;
61
62procedure TNetworkTest.FormCreate(Sender: TObject);
63
64var
65 Soubor: TextFile;
66 Row: string;
67
68function Parse: string;
69begin
70 Result:= Copy(Row,1,Pos(':',Row)-1);
71 Delete(Row,1,Length(Result)+1);
72end;
73
74begin
75 if MainWindow.OnTop then FormStyle:= fsStayOnTop else FormStyle:= fsNormal;
76 try
77 PingList:= TPingList.Create(True);
78 ChDir(ExtractFileDir(Application.ExeName));
79 AssignFile(Soubor,'Network.cfg');
80 Reset(Soubor);
81 SetLength(Devices,1);
82 while not Eof(Soubor) do begin
83 ReadLn(Soubor,Row);
84 SetLength(Devices,Length(Devices)+1);
85 with SunriseChatCore, Devices[High(Devices)] do begin
86 TryStrToInt(Parse,ID);
87 TryStrToInt(Parse,Parent);
88 Name:= Parse;
89 IP:= Parse;
90 if IP = NetworkInterfaces[NetworkInterfaceIndex].IPAddress then
91 LocalPCID:= ID;
92 Place:= Parse;
93 TryStrToInt(Row,Sort);
94 end;
95 end;
96 finally
97 CloseFile(Soubor);
98 SpinEdit1.Value:= MainWindow.PingTimeout;
99 end;
100end;
101
102procedure TNetworkTest.FormShow(Sender: TObject);
103begin
104 ComboBox1.Visible:= MainWindow.ServiceFunction;
105 RefreshList;
106 PingList.Resume;
107 with Localization do begin
108 Button2.Caption:= Item('PerformTest');
109 Button1.Caption:= Item('Close');
110 //CheckBox1.Caption:= Item('ShowAllHosts');
111 NetworkTest.Caption:= Item('NetworkTest');
112 ListView1.Columns[0].Caption:= Item('Host');
113 ListView1.Columns[1].Caption:= Item('IPAddress');
114 ListView1.Columns[2].Caption:= Item('Location');
115 ListView1.Columns[3].Caption:= Item('Status');
116 end;
117end;
118
119{ TPingList }
120
121procedure TPingList.Execute;
122var
123 I: Integer;
124begin
125 with NetworkTest do begin
126 ListView1.SetFocus;
127// ListView1.Items.BeginUpdate;
128 for I:= 0 to ListView1.Items.Count-1 do with ListView1.Items[I] do begin
129 Selected:= True;
130 Focused:= True;
131 if Ping(SubItems[0],MainWindow.PingTimeout) then SubItems[2]:= 'Ok' else SubItems[2]:= 'Nedostupný';
132 Focused:= False;
133 Selected:= False;
134 if Terminated then Break;
135 end;
136// ListView1.Items.EndUpdate;
137 Button2.Enabled:= True;
138 Button2.Caption:= Localization.Item('PerformTest');
139 ComboBox1.Enabled:= True;
140 end;
141end;
142
143procedure TNetworkTest.Button2Click(Sender: TObject);
144begin
145 with Localization do
146 if Button2.Caption = Item('PerformTest') then begin
147 Button2.Caption:= Item('Break');
148 ComboBox1.Enabled:= False;
149 ListView1.SetFocus;
150 PingList.Free;
151 PingList:= TPingList.Create(True);
152 PingList.Resume;
153 end else begin
154 PingList.Terminate;
155 Button2.Caption:= Item('PerformTest');
156 Button2.Enabled:= False;
157 end;
158end;
159
160procedure TNetworkTest.RefreshList;
161var
162 I: Integer;
163 Item: TListItem;
164begin
165 ListView1.Items.BeginUpdate;
166 ListView1.Items.Clear;
167 case ComboBox1.ItemIndex of
168 0: begin
169 // Show only devices between this computer and internet
170 I:= IndexByID(LocalPCID);
171 while I<>0 do with Devices[I] do begin
172 Item:= ListView1.Items.Add;
173 Item.Caption:= Name;
174 with Item.SubItems do begin
175 Add(IP);
176 Add(Place);
177 Add('');
178 end;
179 I:= IndexByID(Devices[I].Parent);
180 end;
181 end;
182 1: begin
183 // Show hosts
184 for I:= 1 to High(Devices) do with Devices[I] do
185 if Sort = 0 then
186 begin
187 Item:= ListView1.Items.Add;
188 Item.Caption:= Name;
189 with Item.SubItems do begin
190 Add(IP);
191 Add(Place);
192 Add('');
193 end;
194 end;
195 end;
196 2: begin
197 // Show only devices
198 for I:= 1 to High(Devices) do with Devices[I] do
199 if Sort = 1 then
200 begin
201 Item:= ListView1.Items.Add;
202 Item.Caption:= Name;
203 with Item.SubItems do begin
204 Add(IP);
205 Add(Place);
206 Add('');
207 end;
208 end;
209 end;
210 3: begin
211 // Show all items
212 for I:= 1 to High(Devices) do with Devices[I] do begin
213 Item:= ListView1.Items.Add;
214 Item.Caption:= Name;
215 with Item.SubItems do begin
216 Add(IP);
217 Add(Place);
218 Add('');
219 end;
220 end;
221 end;
222 end;
223 ListView1.Items.EndUpdate;
224 if ListView1.Items.Count > 4 then Height:= ListView1.Items.Count*14 + 97
225 else Height:= 4*14 + 97;
226 if Height > (Screen.Height-50) then Height:= (Screen.Height-50);
227end;
228
229procedure TNetworkTest.CheckBox1Click(Sender: TObject);
230begin
231 RefreshList;
232end;
233
234procedure TNetworkTest.SpinEdit1Change(Sender: TObject);
235begin
236 MainWindow.PingTimeout:= SpinEdit1.Value;
237end;
238
239procedure TNetworkTest.ComboBox1Change(Sender: TObject);
240begin
241 RefreshList;
242end;
243
244function TNetworkTest.IndexByID(WantedID: Integer): Integer;
245var
246 I: Integer;
247begin
248 for I:= 0 to High(Devices) do if Devices[I].ID = WantedID then Break;
249 Result:= I;
250end;
251
252end.
Note: See TracBrowser for help on using the repository browser.