-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqLinks.pas
More file actions
192 lines (166 loc) · 4.08 KB
/
qLinks.pas
File metadata and controls
192 lines (166 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
unit qLinks;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ComCtrls;
type
TLinks = class(TForm)
Close: TButton;
Tree: TTreeView;
Expand: TButton;
Collapse: TButton;
procedure CloseClick(Sender: TObject);
Procedure MakeTree(Source : TStrings);
procedure CollapseClick(Sender: TObject);
procedure ExpandClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Links: TLinks;
implementation
Uses qIRCMain;
{$R *.DFM}
Type
TString = Class(TObject)
Private
fString : String;
Public
Constructor Create(AString : String);
property Text : String Read fString;
End;
Constructor TString.Create(AString : String);
Begin
Inherited Create;
fString := aString;
End;
procedure TLinks.CloseClick(Sender: TObject);
begin
Self.Release;
end;
Function GetFrag(Var S : String) : String;
Var
At : Integer;
Begin
At := Pos(' ',S);
If (At<>0) Then
Begin
Result := Copy(S,1,At-1);
Delete(S,1,At);
S:= TrimLeft(S);
End
Else
Begin
Result := S;
S := '';
End;
End;
Procedure TLinks.MakeTree(Source : TStrings);
Var
Loop : Integer;
InnerLoop : Integer;
Work : String;
Description : String;
Hop : String;
IP : String;
Host : String;
HostParent : String;
Str : String;
S : TStringList;
M : TMemoryStream;
Begin
Tree.Items.Clear;
If Source.Count=0 Then Exit;
S := TStringList.Create;
M := TMemoryStream.Create;
Try
For Loop := Source.Count-1 Downto 0 Do
Begin
Work := Source[Loop];
// Delete the leading :
Delete(Work,1,1);
GetFrag(Work); // Server
GetFrag(Work); // Code
GetFrag(Work); // Nick
Host := GetFrag(Work);
HostParent := GetFrag(Work);
// Delete the leading :
Delete(Work,1,1);
Hop := GetFrag(Work);
GetFrag(Work);
// IP is optional.
If (Copy(Work,1,1)='[') Then
Begin
IP := GetFrag(Work);
End
Else
begin
IP := '';
End;
If (Hop='') Or (Host='') Or (Work='') Then Continue;
Description := Work;
Str := Hop + ' '+Host + ' (' + Description;
If (IP <> '') Then
Str := Str + ' ' + IP;
Str := Str + ')';
S.AddObject(Str,TString.Create(HostParent));
End;
S.Sort;
For loop := 1 To S.Count-1 Do
Begin
HostParent := TString(S.Objects[Loop]).Text;
For InnerLoop := 0 TO Loop-1 Do
Begin
Work := S[InnerLoop];
GetFrag(Work);
Host := GetFrag(Work);
If (Host=HostParent) Then
Begin
S.Move(Loop,InnerLoop+1);
Break;
End;
End;
End;
For loop := 0 To S.Count-1 Do
Begin
S.Objects[Loop].Free;
Work := S[Loop];
S[Loop] := StringOfChar(#9,StrToIntDef(GetFrag(Work),0))+Work;
End;
S.SaveToStream(M);
M.Position := 0;
Tree.LoadFromStream(M);
Tree.SortType := stText;
If (Tree.Items.GetFirstNode<>Nil) Then
Begin
Tree.Items.GetFirstNode.Expand(True);
Tree.Selected := Tree.Items.GetFirstNode;
End;
Finally
M.Free;
S.Free;
End;
Self.Caption := 'Links - ' + IntToStr(Self.Tree.Items.Count)
+ ' servers';
end;
procedure TLinks.CollapseClick(Sender: TObject);
begin
Self.Tree.FullCollapse;
end;
procedure TLinks.ExpandClick(Sender: TObject);
begin
If (Tree.Items.GetFirstNode<>Nil) Then
Begin
Tree.Items.GetFirstNode.Expand(True);
Tree.Selected := Tree.Items.GetFirstNode;
End;
end;
procedure TLinks.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := False;
Self.Release;
end;
end.