-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcastle_userinfo.pas
582 lines (512 loc) · 14.6 KB
/
castle_userinfo.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
unit castle_userinfo;
interface
uses
Windows,
Messages,
SysUtils,
ExtCtrls,
Graphics,
StdCtrls,
Controls,
ComCtrls,
Forms,
gifimage,
Threads,
Classes,
ShellApi,
Buttons,
JPeg,
Menus,
ClipBrd,
VirtualTrees,
castle_interface,
OleCtrls,
SHDocVw_TLB,
EmbeddedWB;
const
LC = 'Îáíîâëåíèå';
LC1 = 'Ïðîñìîòð ëè÷íîãî äåëà çàêëþ÷åííîãî';
type
TInfoThread = class;
TChirThread = class;
TfrmUserInfo = class(TForm)
PageControl: TPageControl;
tsDelo: TTabSheet;
tsMemo: TTabSheet;
eICQ: TEdit;
eInfo: TMemo;
eMemo: TMemo;
Panel1: TPanel;
btnClose: TButton;
Panel2: TPanel;
Image1: TImage;
lName: TLabel;
Label2: TLabel;
Label4: TLabel;
Label5: TLabel;
btnRefresh: TButton;
btnSave: TButton;
tsSetup: TTabSheet;
Label1: TLabel;
Label6: TLabel;
cbRecvText: TCheckBox;
eNickColor: TEdit;
eTextColor: TEdit;
Timer: TTimer;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
TabSheet1: TTabSheet;
lvHistory: TVirtualStringTree;
chat_irk_ru: TTabSheet;
eNick: TEdit;
Label7: TLabel;
Label8: TLabel;
eEmail: TEdit;
Label9: TLabel;
Label10: TLabel;
eWeb: TEdit;
eCICQ: TEdit;
eSity: TEdit;
eName: TEdit;
Label11: TLabel;
Label14: TLabel;
mInfo: TMemo;
Panel3: TPanel;
ch_image: TImage;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnCloseClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
procedure btnRefreshClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure UrlStrMouseEnter(Sender: TObject);
procedure UrlStrMouseLeave(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PageControlChange(Sender: TObject);
procedure lvHistoryInfoTip(Sender: TObject; Item: TListItem; var InfoTip: string);
procedure FormShow(Sender: TObject);
procedure lvHistoryGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure lvHistoryPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
procedure CreateParams(var Params: TCreateParams); override;
procedure chat_irk_ruShow(Sender: TObject);
procedure ShowChirInfo(UserName: string);
procedure eEmailDblClick(Sender: TObject);
procedure eWebDblClick(Sender: TObject);
private
t, x, z, y: Integer;
InfoThread: TInfoThread;
ChirThread: TChirThread;
historyParced: Boolean;
procedure ParceHistory;
public
User: TChatUser;
end;
TInfoThread = class(TSockMsgThread)
fId,
fICQ,
fInfo: string;
fParent: TfrmUserInfo;
procedure PostData;
procedure DoExecute; override;
constructor Create(ParentH: TfrmUserInfo; Id: string; ProxyAuth, ProxyAddr, ProxyPort: string);
end;
TChirInfo = packed record
cNick: string;
cFoto: string;
cEmail: string;
cWeb: string;
cICQ: string;
cName: string;
cSity: string;
cInfo: string;
end;
TValue = record
Tag: string;
Value: string;
end;
TChirThread = class(TSockMsgThread)
fName: string;
fParent: TfrmUserInfo;
ChirInfo: TChirInfo;
procedure PostData;
procedure DoExecute; override;
constructor Create(ParentH: TfrmUserInfo; UserName: string; ProxyAuth, ProxyAddr, ProxyPort: string);
end;
PArchiveData = ^TArchiveData;
TArchiveData = record
Data: Pointer;
end;
implementation
uses
castle_utils,
main,
Math;
{$R *.dfm}
////////////////////////////////////////////////////////////////////////////////
procedure TCHIRThread.PostData;
begin
with fParent do
begin
Timer.Enabled := False;
Label2.Caption := LC1;
Label2.Font.Color := clWindowText;
btnRefresh.Enabled := True;
ShowChirInfo(fName);
end;
end;
procedure TCHIRThread.DoExecute;
var
person: string;
fotoName: string;
foto: string;
zStream: TFileStream;
function GetTag: TValue;
var
i, z: Integer;
begin
i := Pos('#', person);
z := Pos(':', person);
Result.Tag := copy(person, i + 1, z - 2);
Delete(person, i, z);
i := Pos('#', person);
if i = 0 then i := length(person) + 2;
Result.Value := Trim(copy(person, 1, i - 2));
Delete(person, 1, i - 1);
end;
procedure ParceUserData;
var
Rec: TValue;
begin
while pos('#', person) > 0 do
begin
Rec := GetTag;
if Rec.Tag = 'NICK' then ChirInfo.cNick := Rec.Value else
if Rec.Tag = 'FOTO' then ChirInfo.cFoto := Rec.Value else
if Rec.Tag = 'MAIL' then ChirInfo.cEmail := Rec.Value else
if Rec.Tag = 'URL' then ChirInfo.cWeb := Rec.Value else
if Rec.Tag = 'ICQ' then ChirInfo.cICQ := Rec.Value else
if Rec.Tag = 'NAME' then ChirInfo.cName := Rec.Value else
if Rec.Tag = 'CITY' then ChirInfo.cSity := Rec.Value else
if Rec.Tag = 'TEXT' then ChirInfo.cInfo := (Rec.Value);
end;
end;
begin
person := GetPage('GET', 'http://chat.irk.ru/gallery/person/' + fName + '.txt', '', '', '');
if (Pos('200 OK', person) > 0) and (DirectoryExists(LocalDir + '\chir\') or CreateDir(LocalDir + '\chir\')) then
begin
person := CutHTTP(person);
ParceUserData;
try
zStream := TFileStream.Create(LocalDir + '\chir\' + fName + '.dat', fmCreate or fmOpenWrite);
zStream.Write(BinaryHeader, BinaryHeaderLength);
WriteStr(zStream, ChirInfo.cNick);
WriteStr(zStream, ChirInfo.cEmail);
WriteStr(zStream, ChirInfo.cWeb);
WriteStr(zStream, ChirInfo.cICQ);
WriteStr(zStream, ChirInfo.cName);
WriteStr(zStream, ChirInfo.cSity);
WriteStr(zStream, ChirInfo.cInfo);
FreeAndNil(zStream);
except
end;
fotoName := ChirInfo.cFoto;
if not FileExists(LocalDir + '\chir\' + fName + '.jpg') then
begin
foto := GetPage('GET', 'http://chat.irk.ru/gallery/foto/' + fotoName, '', '', '');
if (Pos('200 OK', foto) > 0) then
begin
foto := CutHTTP(foto);
StringToFile(foto, LocalDir + '\chir\' + fName + '.jpg');
end;
end;
end;
Synchronize(PostData);
end;
constructor TCHIRThread.Create(ParentH: TfrmUserInfo; UserName: string; ProxyAuth, ProxyAddr, ProxyPort: string);
begin
fName := WebNames.GetLink(UserName);
fParent := ParentH;
inherited Create(fParent.Handle, ChatVersion, ProxyAuth, ProxyAddr, ProxyPort);
end;
////////////////////////////////////////////////////////////////////////////////
procedure TfrmUserInfo.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
ExStyle := ExStyle or WS_EX_APPWINDOW;
end;
end;
procedure TfrmUserInfo.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if Assigned(InfoThread) then
begin
InfoThread.Terminate;
InfoThread.WaitFor;
FreeAndNil(InfoThread);
end;
User.InfoForm := nil;
Action := caFree;
end;
procedure TfrmUserInfo.btnCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmUserInfo.btnSaveClick(Sender: TObject);
begin
if User <> nil then
with TChatUser(User) do
begin
ICQ := eICQ.Text;
Info := eInfo.Text;
Comment := eMemo.Text;
DefNickColor := eNickColor.Text;
DefTextColor := eTextColor.Text;
RecvText := cbRecvText.Checked;
end;
Close;
end;
procedure TfrmUserInfo.TimerTimer(Sender: TObject);
function GetCChars(Count: Integer): string;
var
gg: Integer;
begin
for gg := 0 to Count do
Result := Result + '.';
end;
var
tdot: string;
begin
if t = 1 then Inc(x, -10) else Inc(x, 10);
if x = 255 then t := 1;
if x = 20 then t := 2;
if y = 1 then Inc(z, -1) else Inc(z);
if z = 15 then y := 1;
if z = 0 then y := 2;
Label2.Font.Color := RGB(x, x, x);
tdot := GetCChars(z);
Label2.Caption := tdot + LC + tdot;
end;
procedure TInfoThread.PostData;
begin
with fParent do
begin
eICQ.Text := fICQ;
eInfo.Text := fInfo;
Timer.Enabled := False;
Label2.Caption := LC1;
Label2.Font.Color := clWindowText;
btnRefresh.Enabled := True;
end;
end;
procedure TInfoThread.DoExecute;
var
s, icq, info: string;
i: Integer;
begin
s := GetPage('GET', ChatHost + '/cgi-bin/castle_if/tools/info.pl?action=show_user&user=' + fId, '', '', '');
// StringToFile(s, ProfileDir + '\UserInfo.svs');
i := Pos('UIN:</b> ', s);
Delete(s, 1, i + 8);
i := Pos('<br>', s);
icq := Copy(s, 1, i - 1);
i := Pos('Info:</b> ', s);
Delete(s, 1, i + 9);
i := Pos('</p>', s);
info := Copy(s, 1, i - 2);
while Pos(' ', info) > 0 do
info := StringReplace(info, ' ', ' ', [rfReplaceAll, rfIgnoreCase]);
info := StringReplace(info, #$0A, '', [rfReplaceAll, rfIgnoreCase]);
if Length(icq) < 1 then icq := '(íåèçâåñòíî)';
if Length(info) < 1 then info := '(íåèçâåñòíî)';
fICQ := icq;
fInfo := info;
Synchronize(PostData);
Terminate;
end;
constructor TInfoThread.Create(ParentH: TfrmUserInfo; Id: string; ProxyAuth, ProxyAddr, ProxyPort: string);
begin
fId := Id;
fParent := ParentH;
inherited Create(fParent.Handle, ChatVersion, ProxyAuth, ProxyAddr, ProxyPort);
end;
procedure TfrmUserInfo.btnRefreshClick(Sender: TObject);
begin
btnRefresh.Enabled := False;
Label2.Caption := LC;
z := 0;
y := z;
x := y;
t := 2;
y := t;
Timer.Enabled := True;
if PageControl.ActivePageIndex = 0 then
InfoThread := TInfoThread.Create(Self, User.id, ChatThread.Proxy_Auth, ChatThread.Proxy_Addr, ChatThread.Proxy_Port) else
if PageControl.ActivePageIndex = 4 then
ChirThread := TChirThread.Create(Self, User.UserName, ChatThread.Proxy_Auth, ChatThread.Proxy_Addr, ChatThread.Proxy_Port) else
end;
procedure TfrmUserInfo.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
vk_escape: Close;
vk_f5: btnRefreshClick(Sender);
vk_f2: btnSaveClick(Sender);
end;
end;
procedure TfrmUserInfo.UrlStrMouseEnter(Sender: TObject);
begin
if TLabel(Sender).Enabled then
TLabel(Sender).Font.Style := TLabel(Sender).Font.Style + [fsUnderline];
end;
procedure TfrmUserInfo.UrlStrMouseLeave(Sender: TObject);
begin
if TLabel(Sender).Enabled then
TLabel(Sender).Font.Style := TLabel(Sender).Font.Style - [fsUnderline];
end;
procedure TfrmUserInfo.FormCreate(Sender: TObject);
begin
historyParced := False;
end;
procedure TfrmUserInfo.ParceHistory;
var
tmpList: TList;
i: Integer;
Node: PVirtualNode;
Data: PArchiveData;
begin
tmpList := TList.Create;
ChatLog.GetMessagetFor(tmpList, TChatUser(User).UserName);
for i := 0 to tmpList.Count - 1 do
if (i + 1 < tmpList.Count - 1) then
if (TChatText(tmpList[i]).TextType = ttBegin) and (TChatText(tmpList[i]).TextType = TChatText(tmpList[i + 1]).TextType) then
tmpList.Delete(i);
lvHistory.NodeDataSize := SizeOf(Pointer);
for i := 0 to tmpList.Count - 1 do
with TChatText(tmpList[i]) do
begin
Node := lvHistory.AddChild(nil);
Data := lvHistory.GetNodeData(Node);
Data.Data := tmpList[i];
Application.ProcessMessages;
end;
FreeAndNil(tmpList);
historyParced := True;
end;
procedure TfrmUserInfo.PageControlChange(Sender: TObject);
begin
if not historyParced then
if PageControl.ActivePageIndex = 3 then
begin
lvHistory.BeginUpdate;
ParceHistory;
lvHistory.EndUpdate;
end;
if (PageControl.ActivePageIndex = 0) or (PageControl.ActivePageIndex = 4) then
btnRefresh.Enabled := True else
btnRefresh.Enabled := False;
end;
procedure TfrmUserInfo.lvHistoryInfoTip(Sender: TObject; Item: TListItem;
var InfoTip: string);
begin
with TChatText(Item.Data) do
InfoTip :=
'Îò: ' + FromNick + #13#10 +
'Äëÿ: ' + ToNick + #13#10 +
'Äàòà:' + DateTimeToStr(fDate);
end;
procedure TfrmUserInfo.FormShow(Sender: TObject);
var
ff: string;
begin
ff := ExtractFilePath(ParamStr(0)) + 'avatars\' + TChatUser(User).Id + '.gif';
if FileExists(ff) then
with TGIFImage.Create do
try
LoadFromFile(ff);
Transparent := True;
Image1.Picture.Bitmap.Assign(Bitmap);
Free;
except
Free;
end;
if not WebNames.InArray(User.UserName) then chat_irk_ru.TabVisible := False;
end;
procedure TfrmUserInfo.lvHistoryGetText(Sender: TBaseVirtualTree;
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
var CellText: WideString);
var
Data: PArchiveData;
begin
Data := Sender.GetNodeData(Node);
case Column of
0: CellText := TChatText(Data.Data).FromNick;
1: CellText := TChatText(Data.Data).ToNick;
2: CellText := TChatText(Data.Data).Text;
end;
end;
procedure TfrmUserInfo.lvHistoryPaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
var
Data: PArchiveData;
begin
Data := Sender.GetNodeData(Node);
case TChatText(Data.Data).TextType of
ttPrivate:
begin
TargetCanvas.Font.Style := [fsBold];
TargetCanvas.Font.Color := clRed;
end;
ttStrajIn,
ttStrajOut:
begin
TargetCanvas.Font.Style := [fsUnderline];
TargetCanvas.Font.Color := clGray;
end;
ttBegin: TargetCanvas.Font.Color := clBlue;
ttChat:
if TChatText(Data.Data).ToNick = ChatUserName then TargetCanvas.Font.Color := clRed else
if TChatText(Data.Data).FromNick = ChatUserName then TargetCanvas.Font.Color := clNavy;
end;
end;
procedure TfrmUserInfo.chat_irk_ruShow(Sender: TObject);
begin
ShowChirInfo(WebNames.GetLink(User.UserName));
end;
procedure TfrmUserInfo.ShowChirInfo(UserName: string);
var
zStream: TFileStream;
s: string;
begin
if FileExists(LocalDir + '\chir\' + UserName + '.jpg') then
ch_image.Picture.LoadFromFile(LocalDir + '\chir\' + UserName + '.jpg');
if FileExists(LocalDir + '\chir\' + UserName + '.dat') then
try
zStream := TFileStream.Create(LocalDir + '\chir\' + UserName + '.dat', fmOpenRead);
SetLength(s, BinaryHeaderLength);
zStream.Read(s[1], BinaryHeaderLength);
if s = BinaryHeader then
begin
eNick.Text := ReadStr(zStream);
eEmail.Text := ReadStr(zStream);
eWeb.Text := ReadStr(zStream);
eCICQ.Text := ReadStr(zStream);
eName.Text := ReadStr(zStream);
eSity.Text := ReadStr(zStream);
mInfo.Text := ReadStr(zStream);
end;
FreeAndNil(zStream);
except
end;
end;
procedure TfrmUserInfo.eEmailDblClick(Sender: TObject);
begin
ShellExecute(0, 'open', PChar('mailto:' + eEmail.Text), '', '', SW_SHOWNORMAL);
end;
procedure TfrmUserInfo.eWebDblClick(Sender: TObject);
begin
ShellExecute(0, 'open', PChar(eWeb.Text), '', '', SW_SHOWNORMAL);
end;
end.