-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClientsFrame.pas
320 lines (276 loc) · 8.65 KB
/
ClientsFrame.pas
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
{ Ïðè èñïîëüçîâàíèè äàííûõ èñõîäíèêîâ èëè èõ ôðàãìåíòîâ, ññûëêà íà èñòî÷íèê
îáÿçàòåëüíà.
http://irchat.ru
TFrameClients - ñòðàíèöà ñïèñêà âñåõ çàêëàäîê, êëèåíòîâ, îòëàäî÷íîé èíôîðìàöèè.
}
unit ClientsFrame;
interface
uses
Forms, ImgList, Controls, ComCtrls, StdCtrls, ExtCtrls,
RVScroll, RichView, Classes, SysUtils, Misc, Core, ToolWin;
type
TFrameClients = class(TFrame)
tvClientsList: TTreeView;
MesText: TRichView;
panTop: TPanel;
Splitter1: TSplitter;
tbButtons: TToolBar;
tbtnRefresh: TToolButton;
tbtnConnect: TToolButton;
tbtnClear: TToolButton;
ToolButton4: TToolButton;
tbtnAddIRCClient: TToolButton;
tbtnAddIChatClient: TToolButton;
tbtnRemoveClient: TToolButton;
panRight: TPanel;
tbtnVScrollStop: TToolButton;
procedure tbtnRefreshClick(Sender: TObject);
procedure tbtnConnectClick(Sender: TObject);
procedure tvClientsListClick(Sender: TObject);
procedure tbtnAddIRCClientClick(Sender: TObject);
procedure tbtnRemoveClientClick(Sender: TObject);
procedure tbtnAddIChatClientClick(Sender: TObject);
procedure tbtnClearClick(Sender: TObject);
procedure tvClientsListDblClick(Sender: TObject);
procedure tbtnVScrollStopClick(Sender: TObject);
private
{ Private declarations }
LastPage: TChatPage;
LastParent: TWinControl;
procedure LoadLanguage();
procedure OnActivateHandler(Sender: TObject);
procedure OnDeactivateHandler(Sender: TObject);
procedure OnUpdateStyleHandler(Sender: TObject);
procedure AddClient(ClientName: string);
public
{ Public declarations }
Page: TChatPage;
constructor Create(APage: TChatPage); reintroduce;
procedure Refresh();
procedure ClearMesText();
procedure ToggleVScrollStop();
end;
implementation
uses Main;
type
TDataTreeNode = class(TTreeNode)
public
Client: TChatClient;
PageID: integer;
end;
{$R *.dfm}
constructor TFrameClients.Create(APage: TChatPage);
begin
inherited Create(APage.TabSheet);
self.Page:=APage;
APage.OnActivate:=OnActivateHandler;
APage.OnDeactivate:=OnDeactivateHandler;
APage.OnUpdateStyle:=OnUpdateStyleHandler;
MesText.Style:=Form1.MessStyle;
self.tvClientsList.Images:=Form1.ImageList16;
Refresh();
end;
procedure TFrameClients.Refresh();
var
i, n: integer;
tmpNode, tmpSubnode: TDataTreeNode;
Client: TChatClient;
PageInfo: TPageInfo;
procedure AddPageByID(ID: integer; AClient: TChatClient = nil);
begin
if Core.PagesManager.GetPageInfo(ID, PageInfo) then
begin
tmpSubnode:=TDataTreeNode.Create(tvClientsList.Items);
tmpSubnode.ImageIndex:=PageInfo.ImageIndex;
tmpSubnode.SelectedIndex:=PageInfo.ImageIndex;
tmpSubnode.PageID:=PageInfo.ID;
tmpSubnode.Client:=AClient;
tvClientsList.Items.AddNode(tmpSubnode, tmpNode, PageInfo.Caption, nil, naAddChild);
tmpSubnode.MakeVisible;
end;
end;
begin
self.tvClientsList.Items.Clear;
// äîáàâëÿåì âåðõîâíûé óçåë
tmpNode:=TDataTreeNode.Create(tvClientsList.Items);
//tmpNode:=tvClientsList.Items.Add(nil, 'RealChat');
tmpNode.ImageIndex:=0;
tmpNode.StateIndex:=6;
tvClientsList.Items.AddNode(tmpNode, nil, 'RealChat', nil, naAdd);
// Info page
AddPageByID(ciInfoPageID);
// Notes page
AddPageByID(ciNotesPageID);
// Files page
AddPageByID(ciFilesPageID);
// äîáàâëÿåì êëèåíòîâ
for i:=0 to ClientsManager.ClientsCount-1 do
begin
Client:=ClientsManager.GetClient(i);
//tmpNode:=tvClientsList.Items.Add(nil, 'Client');
tmpNode:=TDataTreeNode.Create(tvClientsList.Items);
tmpNode.Text:=Client.InfoConnection;
tmpNode.ImageIndex:=Client.InfoProtocolID;
tmpNode.SelectedIndex:=Client.InfoProtocolID;
tmpNode.StateIndex:=5;
tmpNode.Client:=Client;
if Client.Active then tmpNode.StateIndex:=6;
tvClientsList.Items.AddNode(tmpNode, nil, tmpNode.Text, nil, naAdd);
for n:=0 to Client.PagesIDCount-1 do
begin
AddPageByID(Client.PagesIDList[n], Client);
end;
end;
end;
procedure TFrameClients.tbtnRefreshClick(Sender: TObject);
begin
Refresh();
end;
procedure TFrameClients.tbtnConnectClick(Sender: TObject);
var
Client: TChatClient;
begin
if Assigned(tvClientsList.Selected) then
begin
Client:=TDataTreeNode(tvClientsList.Selected).Client;
if Assigned(Client) then Client.Connect();
end;
//Core.PagesManager.ActivatePage(PageID);
end;
procedure TFrameClients.tvClientsListClick(Sender: TObject);
var
PageID: integer;
ChatPage: TChatPage;
begin
if not Assigned(tvClientsList.Selected) then Exit;
if Assigned(LastPage) then LastPage.Frame.Parent:=LastParent;
LastPage:=nil;
PageID:=TDataTreeNode(tvClientsList.Selected).PageID;
ChatPage:=PagesManager.GetPage(PageID);
if Assigned(ChatPage) then
begin
if (ChatPage.Frame.Parent is TTabSheet) then
begin
MesText.Visible:=False;
LastPage:=ChatPage;
LastParent:=ChatPage.Frame.Parent;
ChatPage.Frame.Parent := panRight;
Core.PagesManager.ActivePageID:=PageID;
Exit;
end;
end;
MesText.Visible:=True;
//Core.PagesManager.ActivatePage(PageID);
end;
procedure TFrameClients.tvClientsListDblClick(Sender: TObject);
var
PageID: integer;
begin
if Assigned(tvClientsList.Selected) then
begin
PageID:=TDataTreeNode(tvClientsList.Selected).PageID;
Core.PagesManager.ActivatePage(PageID);
end;
end;
procedure TFrameClients.ClearMesText();
begin
MesText.Clear;
MesText.Format;
end;
procedure TFrameClients.OnActivateHandler(Sender: TObject);
begin
self.Refresh();
end;
procedure TFrameClients.OnDeactivateHandler(Sender: TObject);
begin
if Assigned(LastPage) then LastPage.Frame.Parent:=LastParent;
MesText.Visible:=True;
end;
procedure TFrameClients.AddClient(ClientName: string);
var
sl: TStringList;
IniName: string;
begin
IniName:=ClientName+IntToStr(Core.ClientsManager.ClientsCount)+'.ini';
Core.AddChatClient(ClientName, IniName);
sl:=MainConf.GetStrings('ChatClientsList');
sl.Add(ClientName+sl.NameValueSeparator+IniName);
MainConf['ChatClientsList']:=sl.Text;
self.Refresh();
end;
procedure TFrameClients.tbtnAddIRCClientClick(Sender: TObject);
begin
AddClient('IRC');
end;
procedure TFrameClients.tbtnAddIChatClientClick(Sender: TObject);
begin
AddClient('iChat');
end;
procedure TFrameClients.tbtnRemoveClientClick(Sender: TObject);
var
PageID, i: integer;
ChatClient: TChatClient;
sl: TStringList;
s: string;
begin
if not Assigned(tvClientsList.Selected) then Exit;
begin
//PageID:=TDataTreeNode(tvClientsList.Selected).PageID;
ChatClient:=TDataTreeNode(tvClientsList.Selected).Client;
if not Assigned(ChatClient) then Exit;
// Remove chat client record from MainConf clients list
sl:=MainConf.GetStrings('ChatClientsList');
s:=ChatClient.InfoProtocolName+sl.NameValueSeparator+ChatClient.InfoConfName;
i:=sl.IndexOf(s);
if i>=0 then sl.Delete(i);
MainConf['ChatClientsList']:=sl.Text;
Core.ClientsManager.RemoveClient(ChatClient);
{if Core.ClientsManager.GetClientByPageID(PageID, ChatClient) then
begin
Core.ClientsManager.RemoveClient(ChatClient);
end; }
end;
self.Refresh();
end;
procedure TFrameClients.LoadLanguage();
function GetStr(Name: string; s: string): string;
begin
result:=Core.LangIni.ReadString('StatusPage', Name, s);
end;
begin
if not Assigned(Core.LangIni) then Exit;
try
tbtnAddIChatClient.Hint:=GetStr('tbtnAddIChatClient.Hint', tbtnAddIChatClient.Hint);
tbtnAddIRCClient.Hint:=GetStr('tbtnAddIRCClient.Hint', tbtnAddIRCClient.Hint);
tbtnClear.Hint:=GetStr('tbtnClear.Hint', tbtnClear.Hint);
tbtnConnect.Hint:=GetStr('tbtnConnect.Hint', tbtnConnect.Hint);
tbtnRefresh.Hint:=GetStr('tbtnRefresh.Hint', tbtnRefresh.Hint);
tbtnRemoveClient.Hint:=GetStr('tbtnRemoveClient.Hint', tbtnRemoveClient.Hint);
finally
end;
end;
procedure TFrameClients.OnUpdateStyleHandler(Sender: TObject);
begin
LoadLanguage();
end;
procedure TFrameClients.tbtnClearClick(Sender: TObject);
begin
ClearMesText();
end;
procedure TFrameClients.ToggleVScrollStop();
begin
with MesText do
begin
if (rvoScrollToEnd in Options) then
Options := Options-[rvoScrollToEnd]
else
Options := Options+[rvoScrollToEnd];
//mFreezeScrolling.Checked := not (rvoScrollToEnd in Options);
tbtnVScrollStop.Down := not (rvoScrollToEnd in Options);
end;
end;
procedure TFrameClients.tbtnVScrollStopClick(Sender: TObject);
begin
ToggleVScrollStop();
end;
end.